### this file is sourced not run
PKGVER=31.2.0.1
PKGBUILD=1
PKGARCH=x86_64

# source: BLFS Firefox 2014-06-06 modified for PaleMoon
TARBALL=palemoon-$PKGVER-source.tar.xz
MD5SUM=924422cea73074243a95e9f9caf6997b
#SRC_URL=https://github.com/MoonchildProductions/UXP/archive/PM${PKGVER}_Release.tar.gz
#SRC_URL=https://github.com/MoonchildProductions/Pale-Moon/archive/${PKGVER}_Release.tar.gz
#SRC_URL=http://archive.palemoon.org/source/palemoon-${PKGVER}-source.tar.xz
SRC_URL=http://archive.palemoon.org/source/palemoon-${PKGVER}.source.tar.xz
#SRC_URL=http://distro.ibiblio.org/fatdog/source/800/$TARBALL
BUNDLE=

SLACKREQ='alsa-lib gtk2 ffmpeg' # autoconf213 build-time dependency
SLACKDESC="palemoon: palemoon $PKGVER (Web browser)  
palemoon:  
palemoon: Palemoon is a derivative of Firefox browser, but built with
palemoon: specially selected features to make it slim and fast.
palemoon: 
palemoon: http://www.palemoon.org/
palemoon: 
palemoon: 
palemoon: 
palemoon: 
palemoon: 
"

### default pkg_download
### default pkg_prepare
pkg_prepare() {
#	mkdir tmp/palemoon-source
#	cp -a /mnt/sda5/play/palemoon-build-dir tmp/palemoon-source # USE-PREBUILT
	pkg_prepare_default &&
	cd tmp/palemoon-source* &&
	#sed -i 's#xlocale#locale#' platform/intl/icu/source/i18n/digitlst.cpp &&
	true
}

### package
pkg_package() {
	# cp -a tmp/*/palemoon-build-dir /mnt/sda5/play # backup the build output
	mkdir -p usr/$LIBDIR/palemoon-$PKGVER/browser/defaults &&
	cp -a tmp/pkg/profile usr/$LIBDIR/palemoon-$PKGVER/browser/defaults
}
### build
pkg_build() {
	! [ -e /usr/bin/env ] && ln -s /tools/bin/env /usr/bin
	cd /tmp/palemoon-source* &&
############## MOZ-BUILD START #############
#<< "USE-PREBUILT"	
	chmod -R 0777 * # need this for palemoon, source is Windows-based
	
	export SHELL=/bin/sh PYTHON=python2.7-$USE_ARCH
	#export PATH=/usr/lib/distcc:$PATH DISTCC_HOSTS='192.168.6.1/10,lzo localhost' MAKEFLAGS=-j12
	#export PATH=/usr/lib/distcc:$PATH DISTCC_HOSTS='192.168.0.3/4,lzo 192.168.0.5/4,lzo localhost' MAKEFLAGS=-j12
	cat > mozconfig << EOF
#######	# official settings from http://developer.palemoon.org/build/linux/ ########

# Please see https://www.palemoon.org/redist.shtml for restrictions when using the official branding.
#ac_add_options --enable-official-branding  # Fatdog - we don't use official branding
#export MOZILLA_OFFICIAL=1

ac_add_options --enable-application=palemoon
ac_add_options --enable-optimize="-O2 -w"
# Fatdog: we previous disabled jemalloc, as Firefox says there was no need for kernel 3+ glib 2.36+
# But since 29.1.0 we re-enable it as it seems to offer better performance.
ac_add_options --enable-jemalloc 
ac_add_options --enable-strip
ac_add_options --enable-devtools
ac_add_options --enable-av1
ac_add_options --enable-phoenix-extensions
ac_add_options --disable-eme
ac_add_options --disable-webrtc
ac_add_options --disable-gamepad
ac_add_options --disable-tests
ac_add_options --disable-debug
ac_add_options --disable-necko-wifi
ac_add_options --disable-updater
ac_add_options --with-pthreads

ac_add_options --x-libraries=/usr/$LIBDIR
ac_add_options --enable-default-toolkit=cairo-gtk2
export MOZ_PKG_SPECIAL=gtk2

######## end of official settings ########

######## settings originally from pm4linux ########

mk_add_options AUTOCLOBBER=1
ac_add_options --disable-crashreporter
ac_add_options --disable-accessibility
ac_add_options --disable-parental-controls

ac_add_options --disable-debug-symbols
ac_add_options --enable-chrome-format=omni

######## end of settings originally from pm4linux ########

# additional settings for Fatdog, based on LFS
# If you have a multicore machine you can speed up the build by running
# several jobs at once, but if you have a single core, delete this line:
mk_add_options MOZ_MAKE_FLAGS="$MAKEFLAGS" #-j6 or whatever

mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/palemoon-build-dir

ac_add_options --disable-dbus
ac_add_options --disable-pulseaudio
ac_add_options --enable-alsa

# disable sync services: https://github.com/MoonchildProductions/UXP/commit/e5e21699ca95369651670a302fde26dc6c19b4bd
ac_add_options --disable-sync

# Uncomment these if you have installed them:
ac_add_options --enable-startup-notification
ac_add_options --enable-system-hunspell
# ac_add_options --enable-system-sqlite # changes often - use internal instead
# ac_add_options --with-system-libevent
# ac_add_options --with-system-libvpx # no longer applicable for 28.9.3 onwards
# ac_add_options --with-system-nspr   # changes often - use internal instead
# ac_add_options --with-system-nss    # changes often - use internal instead

ac_add_options --enable-system-ffi
ac_add_options --with-system-jpeg
# ac_add_options --with-system-png    # no longer applicable for 28.9.3 onwards
ac_add_options --with-system-zlib
ac_add_options --with-system-bz2
# ac_add_options --with-system-icu    # no longer applicable for 28.9.3 onwards

#ac_add_options --disable-elf-hack
#ac_add_options --with-arm-kuser
#export LDFLAGS="-Wl,--no-keep-memory -Wl,--reduce-memory-overheads" # failed on ld.gold
export LDFLAGS="-Wl,--no-keep-memory"
EOF
	#export ICU_DATA=/usr/share/icu/current/ && # so ICU knows where its data is
	make -f client.mk && 
	( cd palemoon-build-dir; make package; ) &&
	#make -C palemoon-build-dir/browser/installer &&
#USE-PREBUILT
############## MOZ-BUILD END #############
	
	# install
	rm -rf /usr/$LIBDIR/palemoon /usr/$LIBDIR/palemoon-$PKGVER &&
	cp -a palemoon-build-dir/dist/palemoon /usr/$LIBDIR/palemoon-$PKGVER &&
	ln -sf palemoon-$PKGVER /usr/$LIBDIR/palemoon &&
	ln -sf /usr/$LIBDIR/palemoon/palemoon /usr/bin/palemoon &&
	ln -sfv /usr/$LIBDIR/palemoon-$PKGVER/browser/icons/mozicon128.png \
        /usr/share/pixmaps/palemoon.png &&
	
	# plugins dir
	mkdir -pv /usr/$LIBDIR/mozilla/plugins                   &&
	ln -sfv ../mozilla/plugins /usr/$LIBDIR/palemoon-$PKGVER &&

	# "fast firefox by uncompressing omni.ja - thanks to BarryK
	#echo "unpacking omni.ja" &&
	#cd /usr/$LIBDIR/palemoon &&
	#mkdir xxx && cd xxx && 
	#{ unzip ../omni.ja; rm ../omni.ja; zip -r0 ../omni.ja *; } > /dev/null &&
	#cd .. && rm -rf xxx &&
	
	pkg_build_slackdesc && 	
	rm -f /usr/bin/env &&

	# run palemoon as spot
	#install -m755 /tmp/pkg/palemoon-spot /usr/bin &&
	ln -s program-spot /usr/bin/palemoon-spot &&
	
	# desktop file
	install -m644 /tmp/pkg/palemoon.desktop /usr/share/applications
}


