#!/bin/sh
#
# Copyright 2005-2009 Paul Blazejowski <paulb@blazebox.homeip.net>
# Available under the terms of the GNU GPL.
#

NAME="mozilla-firefox"
VERSION="3.5.7"
REVISION="1"

PKG_SOURCEURL='http://releases.mozilla.org/pub/mozilla.org/firefox/releases/$VERSION/source/firefox-$VERSION.source.tar.bz2'
PKG_SOURCEMD5=''

PKG_TARBALL=firefox-$VERSION-source

PKG_PATCH[0]="firefox-unversiondir.patch"
PKG_PATCH[1]="all-dropline.js"
PKG_PATCH[2]="bookmarks.html"
PKG_PATCH[3]="doinst.sh"
PKG_PATCH[4]="mozconfig-fx"
PKG_PATCH[5]="mozilla-firefox.desktop"
PKG_PATCH[6]="mozconfig64-fx"
PKG_PATCH[7]="firefox-prefs.patch"

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

# This build script uses it's own CFLAGS;CXXFLAGS
#cflags ""
#cxxflags ""
prepare
applypatch 0 1
applypatch 7 1
analyzesource

# We use mozconfig, no need to pass
# any arguments to configure :-)
if [ "$DLG_ARCH" == "x86-64" ]; then
	findpatch filename mozconfig64-fx
else
	findpatch filename mozconfig-fx
fi

spewdo "cp $filename $PKG_SRCROOT/.mozconfig"
export BUILD_OFFICIAL=1 MOZILLA_OFFICIAL=1
#export LDFLAGS="-Os -march=$PKG_ARCH -fstack-protector-all -fPIC -pipe -Wl,--as-needed"
export LDFLAGS="-Os -march=$PKG_ARCH -fstack-protector-all -fPIC -pipe"

configure
make
makeinstall
# makecheck function no worky here :-(
#makecheck
tidydocumentation
analyzebinaries

# We don't need CVS repo entries in the docs :D
removedir $PKG_STAGEROOT$PKG_PREFIX/doc/$NAME-$VERSION/README

# Before copying desktop files we create the dirs
createdir $PKG_STAGEROOT$PKG_PREFIX/share/applications
createdir $PKG_STAGEROOT$PKG_PREFIX/share/pixmaps

findpatch filename all-dropline.js
spewdo "cp $filename $PKG_STAGEROOT$PKG_LIBDIR/firefox/defaults/preferences/all-dropline.js"

cat > $PKG_STAGEROOT$PKG_LIBDIR/firefox/browserconfig.properties << EOF
browser.startup.homepage=file:///usr/share/dropline/home/index.html
EOF

findpatch filename mozilla-firefox.desktop
spewdo "cp $filename $PKG_STAGEROOT$PKG_PREFIX/share/applications"

findpatch filename bookmarks.html
spewdo "cp $filename $PKG_STAGEROOT$PKG_LIBDIR/firefox/defaults/profile/bookmarks.html"

# Copy default icons for the browser :-)
createdir $PKG_STAGEROOT$PKG_LIBDIR/firefox/chrome/icons
createdir $PKG_STAGEROOT$PKG_LIBDIR/firefox/chrome/icons/default
spewdo "cp $PKG_STAGEROOT$PKG_LIBDIR/firefox/icons/mozicon128.png $PKG_STAGEROOT$PKG_PREFIX/share/pixmaps/mozilla-firefox.png"

finalizepackage
packagize
cleanup
