# Maintainer: <fero dot kiraly at gmail.com>

pkgname=pd-extended
pkgver=0.43.4
pkgrel=1
pkgdesc="PureData Extended 0.43-4 version"
url="http://puredata.info/"
arch=('i686' 'x86_64' )
license=('BSD')
depends=('libdc1394' 'desktop-file-utils' 'libiec61883' 'fftw' \
'jack' 'tk' 'freeglut' 'libquicktime' 'libdv' 'gsl' 'imagemagick' \
'ftgl' 'libgl' 'hicolor-icon-theme' 'lua51')
makedepends=('dssi' 'git' 'libv4l' 'tcllib' 'subversion' 'swig' 'automake' 'curl')
conflicts=('pdp' 'zexy' 'puredata')
provides=( 'pd-extended' 'pd-gem' 'pdp' 'zexy')
optdepends=('puredata-utils' 'pd-vanilla')
replaces=(pd-extended)
backup=()
options=('!makeflags' '!libtool')
install=pd-extended.install
source=('change_gem_configure_file.patch' 's_inter.c.patch' 'tclpd.Makefile.patch' 'makefile.am.patch')
md5sums=('63a36c51706eaed98611aa4b4bb6ed0d' '8b748d09e8bdf04540ba579d0a6b5318' '463de23166cef2dcf6c7f6989e636213' '5938b12a232004de15f5a383f95cedca' )





build() {
unset CFLAGS
unset LDFLAGS
unset INCLUDES

#
#downloading pd-extended----------------------------------------------------------
#
msg "Begin SVN checkout for pd-extended 0.43.4"
cd $srcdir
svn checkout https://pure-data.svn.sourceforge.net/svnroot/pure-data/branches/pd-extended/0.43 $pkgname
msg "SVN checkout done or server timeout"



cd ..


#FIXES -----------------------------------------------------------------------------
# fix #1 lua
#patch $srcdir/$pkgname/externals/loaders/pdlua/src/Makefile ./repair_lua_lib_number.patch
#fix #2 -- GEM configure.ac
patch $srcdir/$pkgname/externals/Gem/configure.ac ./change_gem_configure_file.patch
#fix #3 -- repair wish8.6 (for tcl8.6)
patch $srcdir/$pkgname/pd/src/s_inter.c ./s_inter.c.patch
#fix #4 -- repair version of tcl (8.6)
patch $srcdir/$pkgname/externals/loaders/tclpd/Makefile ./tclpd.Makefile.patch
#fix #5 -- repair binary name to pd-extended (from pd)
#patch $srcdir/$pkgname/packages/Makefile ./program_name.patch
patch $srcdir/$pkgname/pd/src/Makefile.am ./makefile.am.patch

# 64 bit archutecure----------------------------------------------------------------
if [ "$CARCH" = "x86_64" ]; then
# fix -fPIC issue in PDP
sed -e "s|CFLAGS =|CFLAGS = -fPIC|" \
-i $srcdir/$pkgname/externals/pdp/opengl/Makefile.config || return 1
# fix -fPIC issue in pddp
sed -e "s|DEFINES =|DEFINES = -fPIC|" \
-i $srcdir/$pkgname/externals/miXed/Makefile.common || return 1
# setting additional variable
FPIC_FLAG="-fPIC"
else FPIC_FLAG=""
fi


#MAKE --------------------------------------------------------------------------
cd "$srcdir/$pkgname/packages/linux_make" || return 1

make BUILDLAYOUT_DIR=$srcdir/$pkgname/packages \
GEM_EXTRA_CXXFLAGS="$FPIC_FLAG" \
prefix=/usr \
install || return 1

}


package() {

cp -urv $srcdir/$pkgname/packages/linux_make/build/usr $pkgdir/
mv $pkgdir/usr/share/man/man1/pd.1 $pkgdir/usr/share/man/man1/pdextended.1
rm $pkgdir/usr/share/man/man1/pdreceive.1
rm $pkgdir/usr/share/man/man1/pdsend.1
rm $pkgdir/usr/include/m_pd.h
rm $pkgdir/usr/bin/pd-gui.tcl
cd $srcdir/$pkgname/

# PD License
install -Dm644 pd/LICENSE.txt $pkgdir/usr/share/licenses/pd-extended/LICENSE.txt
cd packages/
install -p linux_make/default.pdextended $pkgdir/usr/lib/pd-extended/

# Gnome menu support
install -d $pkgdir/usr/share/icons/hicolor/128x128/apps
install -p -m0644 linux_make/pd-extended.png $pkgdir/usr/share/icons/hicolor/128x128/apps/
install -d $pkgdir/usr/share/icons/hicolor/48x48/apps
install -p -m0644 linux_make/48x48/pd-extended.png $pkgdir/usr/share/icons/hicolor/48x48/apps/pd-extended.png
install -d $pkgdir/usr/share/applications/
install -p linux_make/pd-extended.desktop $pkgdir/usr/share/applications/

# mime
install -d $pkgdir/usr/share/mime/packages/
install -p linux_make/pd-extended.xml $pkgdir/usr/share/mime/packages/
install -d $pkgdir/usr/share/icons/hicolor/128x128/mimetypes
install -p linux_make/text-x-puredata.png $pkgdir/usr/share/icons/hicolor/128x128/mimetypes

# files for /etc
cd "$srcdir/$pkgname"

install -d $pkgdir/etc/bash_completion.d/
install -p scripts/bash_completion/pd $pkgdir/etc/bash_completion.d
# emacs mode for .pd files
install -d $pkgdir/usr/share/emacs/site-lisp/
install -p scripts/pd-mode.el $pkgdir/usr/share/emacs/site-lisp/
# Pd-related scripts
install -p scripts/pd-diff $pkgdir/usr/bin/
install -p scripts/config-switcher.sh $pkgdir/usr/bin/


}

# vim:set ts=2 sw=2 et: