
# [BEGIN] of config section

rockver=1.6.1   # Release Version
develsnapshot=0 # Is this a devel-snapshot (i.e. not a release)
devlv=1         # development level (incrase to mark all pkgs as 'old')
autobackup=0    # Should we do a backup every hour

stripbins=1     # def=1, Should we strip all binaries
makerebuild=1   # def=1, Should we make a stage 5 (rebuild)
buildoptpkgs=1  # def=1, Should we build the optional pkgs
buildextpkgs=1  # def=1, Should we build the extension pkgs
abortonerror=1  # def=1, Should we abort if a package fails to build
retryfailed=1   # def=1, Should we retry building 'broken' packages
dontprintlogs=1 # def=1, Should we suppress the build logs to stdout
useflwrapper=1  # def=1, Should we use the flist wrapper library

# [END] of config section

[ $develsnapshot = 1 ] && rockver="$rockver-DEV"

export PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:\
/usr/local/bin:/usr/X11/bin:/usr/games
umask 022

if [ "`date '+%Y'`" -lt 1990 ] ; then
	echo
	echo " ! ! !  Your clock is not set. Not doing anything.  ! ! !"
	echo
	echo "Set you clock using the command:  date MMDDhhmm[[CC]YY][.ss]"
	echo
	exit 1
fi

if [ `wc -l < /proc/swaps` -le 1 ] ; then
	echo
	echo " ! ! !  It looks like you have no active swap partition.  ! ! !"
	echo
	echo "That can couse the build scripts to hang your system!. Activate"
	echo "a swap partition using the 'swapon' command and try again."
	echo
	exit 1
fi

if [ $autobackup = 1 -a -d backup/ -a -w backup/ ] ; then
	x="backup/rockbak-$rockver.`date +%Y-%m-%d-%H`.tar.bz2"
	if [ ! -f $x -a -z "$NO_AUTO_BACKUP" ] ; then
		echo "Autobackup enabled -> Creating this hours backup."
		touch $x ; ./scripts/Create-SrcTar
		cp -v rock-src-$rockver.tar.bz2 $x
	fi
fi

crossnative=native           ; stagelevel=5           ; arch=any
arch_sizeof_long_long=undef  ; arch_sizeof_int=undef  ; arch_machine=undef
arch_sizeof_char_p=undef     ; arch_sizeof_long=undef ; arch_bigendian=undef
arch_sizeof_short=undef      ; arch_target=any-unknown-linux

[ -f ./Config ] && . ./Config
[ -f ./arch-conf/$arch/archtest.out ] && . ./arch-conf/$arch/archtest.out
[ -f ./arch-conf/$arch/config ] && . ./arch-conf/$arch/config

for x in wget mmv bzip2 ; do
	y=0
	for z in `echo "$PATH" | tr : ' '`
		do [ -f $z/$x ] && y=1 ; done
	if [ $y = 0 ] ; then
		echo "!!!"
		echo "!!! The program '$x' is needed by the ROCK Linux build scripts."
		echo "!!! Please install this program. If it doesn't come with the"
		echo "!!! distribution you are using you can get it from this webpage:"
		[ $x = mmv   ] && echo "!!! ftp://ftp.unix-ag.org/pub/os/linux/i386/misc/"
		[ $x = wget  ] && echo "!!! ftp://ftp.gnu.org/pub/gnu/wget/"
		[ $x = bzip2 ] && echo "!!! ftp://sourceware.cygnus.com/pub/bzip2/"
		echo "!!!" ; exit 1
	fi
done

if [ -f /bin/pwd ] ; then base=`/bin/pwd`
elif [ -f /usr/bin/pwd ] ; then base=`/usr/bin/pwd`
else base=`pwd` ; fi

root=""

# the gcc_wrapper needs to be used so make it be first in the PATH
export PATH="$base/lib:$PATH"

export BUILD_CC="gcc" BUILD_CXX="g++" MAKE="make"
unset CPP ARFLAGS ASFLAGS CFLAGS CXXFLAGS CPPFLAGS LDFLAGS 

export CC_WRAPPER_MYPATH="$base/lib"
export CC_WRAPPER_SILENT="1"       CC_WRAPPER_OTHERS=""
export CC_WRAPPER_INSERT=""        CC_WRAPPER_REMOVE=""
export CC_WRAPPER_APPEND=""        CC_WRAPPER_FILTER=""

CC_WRAPPER_INSERT="-O2 -pipe" ; CC_WRAPPER_REMOVE="-O -O[01]"
y="arch-conf/$arch/gcc-options"
if [ -f "$y" ] ; then CC_WRAPPER_INSERT="$CC_WRAPPER_INSERT `cat $y`" ; fi

if [ "$stripbins" ] ; then
	CC_WRAPPER_INSERT="$CC_WRAPPER_INSERT -s"
	CC_WRAPPER_REMOVE="$CC_WRAPPER_REMOVE -g*"
fi

export CC_WRAPPER_INSERT CC_WRAPPER_REMOVE

if [ "$crossnative" = native ] ; then
	build="$arch_target" ; target="$arch_target"
	export CC="gcc" CXX="g++" STRIP="strip"
	export LD="ld" AR="ar" RANLIB="ranlib"
	export AS="as" GASP="gasp" NM="nm"
else
	[ "$build" ] || build="`uname -m -p | tr " " -`-linux-gnu" ; target="$arch_target"
	export CC="$target-gcc" CXX="$target-g++" STRIP="$target-strip"
	export LD="$target-ld" AR="$target-ar" RANLIB="$target-ranlib"
	export AS="$target-as" GASP="$target-gasp" NM="$target-nm"
fi
