#!/bin/bash

# xjjk's Mozilla Projects Build Script v1.1
# See http://tamasrepus.hotnudiegirls.com/ for latest updates

# Setup:
# Change the variables below to suit where your sources are and what options
# you want with your build.

# Description of script variables:
# BUILDDIR : Where things will be built. Preferably a fast disk with ample
#  space (200+ MB)
# MOZSRCDIR : The root of checked out CVS sources, including the module name
#  (i.e. below, I checked out sources in /usr/src/mozilla, and the module
#  name is mozilla
# Hopefully the rest of the variables' function is obvious

# General use:
# 1. Update local CVS repository using "build-mozilla.sh update"
# 2. Build desired project by using "build-mozilla.sh projectname"
# 3. Go into $BUILDDIR/projectname-build, and install, or test by
#     running one of the binaries in dist/bin

# See my website for information on how to contact me with suggestions,
#  comments, and improvements.

BUILDDIR=/tmp/build
MOZSRCDIR=/usr/src/mozilla/mozilla
MAKECMD="nice -19 make -j4"

export MOZ_MAKE_FLAGS="-j4"
#export MOZ_INTERNAL_LIBART_LGPL=1
export MOZILLA_OFFICIAL=1
export BUILD_OFFICIAL=1
export CC="ccache gcc"
export CXX="ccache g++"
export CFLAGS="-O3 -march=athlon-xp -pipe -falign-functions=4 -fforce-addr -mfpmath=sse -msse -mmmx -m3dnow"
export CXXFLAGS=$CFLAGS

cd $BUILDDIR
mkdir firefox-build
mkdir thunderbird-build
mkdir mozilla-build

function base-configure-cmd() {
	echo -n \
	configure \
		--enable-reorder \
		--enable-nable-elf-dynstr-gc \
		--enable-cpp-rtti \
		--disable-debug \
		--disable-tests \
		--enable-strip \
		--enable-strip-libs \
		--enable-xterm-updates \
		--enable-nspr-autoconf \
		--enable-extensions=all \
		--with-default-mozilla-five-home \
		--enable-crypto \
		--disable-xprint \
		--disable-installer \
		--without-system-nspr \
		--enable-default-toolkit=gtk2 \
		--disable-freetype2 \
		--enable-xft \
		--enable-xinerama \
		--with-system-zlib \
		--with-system-jpeg \
		--with-system-png
}
	
case "$1" in
	update)
		cd $MOZSRCDIR
		cd ..
		export CVSROOT=:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
		export MOZ_PHOENIX=1
		export MOZ_THUNDERBIRD=1
		cvs co -f mozilla/client.mk
		make -f mozilla/client.mk checkout
		;;
	firefox)
		export MOZ_PHOENIX=1
		cd $BUILDDIR/firefox-build
		$MOZSRCDIR/`base-configure-cmd` \
			--enable-optimize="$CFLAGS" \
			--prefix=/usr/local/mozilla-cvs/firefox \
			--with-user-appdir=".mozilla-cvs-firefox" \
			--disable-ldap \
			--disable-composer \
			--disable-mailnews
		$MAKECMD
		;;
	mozilla)
		cd $BUILDDIR/mozilla-build
		$MOZSRCDIR/`base-configure-cmd` \
			--enable-optimize="$CFLAGS" \
			--prefix=/usr/local/mozilla-cvs/mozilla \
			--with-user-appdir=.mozilla-cvs-mozilla
		$MAKECMD
		;;
	thunderbird)
		export MOZ_THUNDERBIRD=1
		cd $BUILDDIR/thunderbird-build
		$MOZSRCDIR/`base-configure-cmd` \
			--enable-optimize="$CFLAGS" \
			--prefix=/usr/local/mozilla-cvs/thunderbird \
			--with-user-appdir=.mozilla-cvs-thunderbird \
			--disable-composer
		$MAKECMD
		;;
	*)
		echo "Usage: build-mozilla.sh update|firefox|mozilla|thunderbird"
		;;
esac

	
