#!/bin/bash -x
#
# Build Debian-style cross compiler packages
#
# Copyright 2006-2010  Hector Oron <hector.oron@gmail.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
# Latest version of this file can be downloaded from:
#  http://www.emdebian.org/repos/current/host/trunk/buildcross/trunk/

. /etc/buildcross.conf
. /usr/lib/buildcross/functions

trap at_exit HUP INT QUIT TERM ABRT

usage(){
	echo "Usage: ${0##*/} [OPTION]"
	echo "Build Debian cross toolchain system."
	echo " "
	cat << EOF
	-h|--help	displays this help
	-V|--version	displays version number
	-i|--init	start the build
	-c|--clean	clean dirs and remove cross binary files

	Configuration file: /etc/buildcross.conf

EOF
}

case $1 in
 -h|--help)
 	usage
	exit 0
	;;
 -V|--version)
 	echo "Version: 0.0.11"
	exit 0
	;;
 -v|--verbose)
	unset VERBOSE
	export VERBOSE=yes
	;;
 -i|--init)
	myecho INFO "I: Starting build"
	if [ ! -d $LOGPATH ]; then
        	mkdir -p $LOGPATH
	fi
	if [ x"$FORCE_UPGRADE" = xyes ] && [ x${ROOTCMD} = xsudo ] ; then
		idcheck
		update-sys
	else
		myecho INFO "I: set ROOTCMD and FORCE_UPGRADE if you wish to upgrade your system"
	fi
	time em_wrap | tee $LOGPATH/build.log 
 	;;
 -c|--clean)
	echo "I: Cleaning dirs and removing cross binaries"
	em_clean
	;;
 -bds|--bootstrap-debsrc)
	echo "I: Bootstrapping a new system from Debian sources"
	. /usr/lib/buildcross/functions-rfs
	bootstrap_debsrc debian
	;;
 -bus|--bootstrap-upsrc)
	echo "I: Bootstrapping a new system from Debian sources"
	. /usr/lib/buildcross/functions-rfs
	bootstrap_upsrc upstream
	;;
 *)
	usage
	exit 0
	;;
esac

