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

# source: BLFS 7.5 updated for latest
TARBALL=seamonkey-$PKGVER.source.tar.xz
MD5SUM=5accffb416ec8f593e7fd33ee73182ba
SRC_URL=http://ftp.mozilla.org/pub/seamonkey/candidates/2.46-candidates/build6/source/seamonkey-2.46.source.tar.xz
#SRC_URL=https://archive.mozilla.org/pub/mozilla.org/seamonkey/releases/$PKGVER/source/$TARBALL
BUNDLE=

SLACKREQ='alsa-lib gtk2 libvpx gstreamer2 gst2-plugins-base gst2-plugins-good gst2-libav'
SLACKDESC="seamonkey: seamonkey $PKGVER (Web browser suite)  
seamonkey:  
seamonkey: SeaMonkey is a browser suite, the Open Source sibling of Netscape. 
seamonkey: It includes the browser, composer, mail and news clients, and an 
seamonkey: IRC client. It is the follow-on to the Mozilla browser suite.  
seamonkey: 
seamonkey: 
seamonkey: 
seamonkey: 
seamonkey: 
seamonkey:
"

### default pkg_download
### default pkg_prepare
pkg_prepare() {
	###Seamonkey-2.46 bugs, may not be needed for english locals
	pkg_prepare_default &&
	cd tmp/seamonkey-*/mozilla/ &&
	patch -Np1 -i ../../pkg/bug1231349_workaround.patch &&	
	patch -RNp1 -i ../../pkg/0002-Bug-1234012-Do-not-try-to-copy-files-from-the-non-ex.patch &&  ###Reverse patch that did away with default profile copying. Bug 1234012
	patch -RNp1 -i ../../pkg/0003-Bug-1234012-Remove-the-NS_APP_PROFILE_DEFAULTS_-NLOC.patch &&
	cd ..
	patch -Np1 -i ../pkg/bug_1231349.diff
	
}

### package
pkg_package() {
	#cp -a tmp/*/moz-build-dir /mnt/sda5/play # backup the build output
	
	### add fatdog standard profile
	rm -rf usr/$LIBDIR/seamonkey-$PKGVER/defaults/profile &&
	tar -xf $CHROOT_DIR/tmp/pkg/sm-profile.tar.bz2 -C usr/$LIBDIR/seamonkey-$PKGVER/defaults &&
	
	### add 'close tab' extension
	mkdir -p usr/$LIBDIR/seamonkey-$PKGVER/extensions/"seatabx2@extensions.moz"
	tar --strip-components=1 -xf $CHROOT_DIR/tmp/pkg/seatabx2.tar.xz \
	    -C usr/$LIBDIR/seamonkey-$PKGVER/extensions/"seatabx2@extensions.moz"
	### add HTML5 full screen extension 
	tar -xf $CHROOT_DIR/tmp/pkg/trufullscreen.tar.xz \
	    -C usr/$LIBDIR/seamonkey-$PKGVER/extensions/
}

### build
pkg_build() {
	! [ -e /usr/bin/env ] && ln -s /tools/bin/env /usr/bin
	cd /tmp/seamonkey*
#################### MOZ-BUILD START ###################
#<< "USE-PREBUILT"
	mkdir moz-build-dir
	ln -s ../moz-build-dir ./mozilla/
	export SHELL=/bin/sh PYTHON=python2.7-$USE_ARCH
	cat > mozconfig << EOF
# 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

# If you have installed DBus-Glib delete this option:
ac_add_options --disable-dbus

# If you have installed wireless-tools delete this option:
ac_add_options --disable-necko-wifi

# If you have installed libnotify delete this option:
#ac_add_options --disable-libnotify

# 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
# ac_add_options --with-system-libevent
ac_add_options --with-system-libvpx
# ac_add_options --with-system-nspr
# ac_add_options --with-system-nss

mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/moz-build-dir
ac_add_options --disable-crashreporter
ac_add_options --disable-tests
ac_add_options --disable-updater
ac_add_options --enable-application=suite
ac_add_options --prefix=/usr
ac_add_options --libdir=/usr/$LIBDIR
ac_add_options --with-pthreads
ac_add_options --with-system-jpeg
ac_add_options --with-system-zlib
ac_add_options --with-system-bz2
ac_add_options --enable-calendar
ac_add_options --enable-optimize=-Os
ac_add_options --enable-system-ffi
ac_add_options --enable-system-pixman
ac_add_options --with-pthreads
ac_add_options --with-system-bz2
ac_add_options --with-system-jpeg
ac_add_options --with-system-zlib
ac_add_options --disable-pulseaudio
ac_add_options --enable-default-toolkit=cairo-gtk2
export LDFLAGS="-Wl,--no-keep-memory -Wl,--reduce-memory-overheads"
EOF
	make -f client.mk && 
	make -C moz-build-dir/suite/installer &&
#USE-PREBUILT
#################### MOZ-BUILD END ###################

	# install
	rm -rf /usr/$LIBDIR/seamonkey /usr/$LIBDIR/seamonkey-$PKGVER &&
	cp -a moz-build-dir/dist/seamonkey /usr/$LIBDIR/seamonkey-$PKGVER &&
	ln -sf seamonkey-$PKGVER /usr/$LIBDIR/seamonkey &&
	ln -sf /usr/$LIBDIR/seamonkey/seamonkey /usr/bin/seamonkey &&
	
	# plugins dir
	mkdir -pv /usr/$LIBDIR/mozilla/plugins                   &&
	ln -sfv ../mozilla/plugins /usr/$LIBDIR/seamonkey-$PKGVER &&
	
	# manpage
	cp -v moz-build-dir/dist/man/man1/seamonkey.1 /usr/share/man/man1 &&

	# clear extensions/* and distribution/extensions/* (modern themes and whatnot)
	rm -r /usr/$LIBDIR/seamonkey-$PKGVER/extensions/*  &&
	rm -r /usr/$LIBDIR/seamonkey-$PKGVER/distribution/extensions/* && 
		
	# install our components - calendar, lightning, inspector, chatzilla to extensions
	echo "installing calendar" &&
	mkdir -p /usr/$LIBDIR/seamonkey/extensions/"{e2fda1a4-762b-4020-b5ad-a41df1933103}" &&
	unzip moz-build-dir/dist/xpi-stage/lightning*xpi -d  \
	/usr/$LIBDIR/seamonkey/extensions/"{e2fda1a4-762b-4020-b5ad-a41df1933103}" > /dev/null &&

	echo "installing calendar timezone" &&
	mkdir -p /usr/$LIBDIR/seamonkey/extensions/"calendar-timezones@mozilla.org" &&
	unzip moz-build-dir/dist/xpi-stage/calendar-timezones*xpi -d  \
	/usr/$LIBDIR/seamonkey/extensions/"calendar-timezones@mozilla.org" > /dev/null &&

	echo "installing gdata provider" &&
	mkdir -p /usr/$LIBDIR/seamonkey/extensions/"{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}" &&
	unzip moz-build-dir/dist/xpi-stage/gdata*xpi -d \
	/usr/$LIBDIR/seamonkey/extensions/"{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}" > /dev/null &&
	
	echo "installing DOM inspector" &&
	mkdir -p /usr/$LIBDIR/seamonkey/extensions/"inspector@mozilla.org" &&
	unzip moz-build-dir/dist/xpi-stage/inspector*xpi -d \
	/usr/$LIBDIR/seamonkey/extensions/"inspector@mozilla.org" > /dev/null &&

	echo "installing chatzilla" &&
	mkdir -p /usr/$LIBDIR/seamonkey/extensions/"{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}" &&
	unzip moz-build-dir/dist/xpi-stage/chatzilla*xpi -d \
	/usr/$LIBDIR/seamonkey/extensions/"{59c81df5-4b7a-477b-912d-4e0fdf64e5f2}" > /dev/null &&
	
	# "fast" seamonkey by uncompressing omni.ja - thanks to BarryK
	echo "unpacking omni.ja" &&
	cd /usr/$LIBDIR/seamonkey &&
	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 seamonkey as spot
	install -m755 /tmp/pkg/seamonkey-spot /usr/bin &&

	# desktop files
	install -m644 /tmp/pkg/seamonkey.desktop /usr/share/applications &&	
	install -m644 /tmp/pkg/seamonkey-mail.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/seamonkey-composer-html-editor.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/seamonkey-addressbook.desktop /usr/share/applications

}


