### this file is sourced not run
PKGVER=1.42
PKGBUILD=2
PKGARCH=x86_64

# source: james
TARBALL=psip-2023-07-13.tar.bz2
MD5SUM=1da41b17e4ccaa37594aebb2205e46f5
SRC_URL=http://distro.ibiblio.org/fatdog/source/900/$TARBALL
BUNDLE=

OSXCART_VER=1.2.0
OSXCART_TARBALL=osxcart-$OSXCART_VER.tar.xz
OSXCART_MD5SUM=cf0d71d5917e30940909f72c9260c820
OSXCART_SRC=https://github.com/ptomato/osxcart/releases/download/1.2.0/$OSXCART_TARBALL

# note: version 2.4 only works with openssl 1.0. It doesn't work with anything newer.
PJSIP_VER=2.4
#PJSIP_MD5SUM=39629ca3fcedbdc7dbd8c5a707060095 # old tar.bz2 tarball, no longer exist
PJSIP_MD5SUM=7fafa3ed7e6b82c900de01b7e7fa16a3
PJSIP_TARBALL=pjproject-$PJSIP_VER.tar.gz
PJSIP_SRC=https://github.com/pjsip/pjproject/archive/$PJSIP_VER.tar.gz

SLACKREQ='gtk2 openssl libopencore-amr alsa-lib' # 
SLACKDESC="psip: psip $PKGVER (Puppy VOIP Phone)
psip: 
psip: PSIP is a simple VOIP phone based on pjsip/pjproject.
psip: https://chiselapp.com/user/jamesbond/repository/psip/index
psip:
psip: This version is build with older version of pjproject and does
psip: not support TLS / SSL encryption.
psip: 
psip: Built with pjsip/pjproject $PJSIP_VER
psip: 
psip: 
"


### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	TARBALL=$OSXCART_TARBALL MD5SUM=$OSXCART_MD5SUM SRC_URL=$OSXCART_SRC &&
	pkg_prepare_default &&
	TARBALL=$PJSIP_TARBALL MD5SUM=$PJSIP_MD5SUM SRC_URL=$PJSIP_SRC &&
	pkg_prepare_default &&

	# patch psip
	cd tmp/psip* &&
	# all patches have been upstreamed
	true
}

### pkg_package
pkg_package() {
	rm -rf ./usr/local # don't want the libs
}

### build
pkg_build() {	
	cd /tmp/pjproject* &&
	CFLAGS="$CFLAGS -std=c++14" && gcc 12
	./configure --disable-video --disable-v4l2 --disable-sdl --disable-ffmpeg --with-external-pa &&
#   use alsa instead of portaudio
#	<< EOF cat > pjlib/include/pj/config_site.h &&
#   define PJMEDIA_AUDIO_DEV_HAS_ALSA       1
#   define PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO  0
#EOF
	make dep && make $MAKEFLAGS && make install &&

	cd ../osxcart* &&
	./configure --disable-shared &&
	make $MAKEFLAGS && make install &&	
	
	cd ../psip* &&
	sed -i -e '/^CFLAGS/ s/-Werror//' Makefile && # build without this, or it will choke on -std=c++14
	# insert built info
	sed -i -e "s|PJSIP</property>|PJSIP\n\
\n\
(Built with pjsip $PJSIP_VER and osxcart $OSXCART_VER)</property>|" psip.glade &&
	PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig \
	CFLAGS="$CFLAGS -DFATDOG_COMPILE" make release &&
	install -m755 psip /usr/bin &&
	
	# docs and files
	install -d -m755 /usr/share/sounds /usr/share/doc /usr/share/pixmaps /usr/share/applications &&
	install -m755 bell.wav /usr/share/sounds &&
	install -m755 psip-doc.html /usr/share/doc &&
	install -m755 psip48.png /usr/share/pixmaps &&
	
	# make desktop file
	install -m644 /tmp/pkg/psip.desktop /usr/share/applications &&
	ln -sfv program-spot /usr/bin/psip-spot &&

	pkg_build_slackdesc
}
