#!/bin/sh # Copyright (C) 2004 Nokia # Author: veli.mankinen@movial.fi # Licenced under GPL, see COPYING for details # qmode : 1 = yes/no # 2 = string question() { local q=$1 local qmode=$2 local def=$3 if [ "$qmode" = "1" ] ; then while [ 1 = 1 ] ; do echo -n "$q [yes/no] ($def): " >&2 read answer if [ "x$answer" = "x" ] ; then echo "$def" return fi if [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; then echo "Answer 'yes' or 'no' !!" >&2 else echo "$answer" return fi done elif [ "$qmode" = "2" ] ; then echo -n "$q ($def): " >&2 read answer if [ "x$answer" = "x" ] ; then answer="$def" fi echo "$answer" return fi echo "ERROR: With question mode (script internal error) !?!!" >&2 } set -e if [ "x$1" = "x" ] ; then MISSING=0 CHECK_DEPS=`question "Check if you have all the needed debian packages installed?" 1 yes` if [ "$CHECK_DEPS" = "yes" ] ; then IFS=$'\n' for i in `cat doc/debian-packages.txt | grep -ve "^#" -ve "^$"` ; do if ! dpkg-query -l ''$i'' 2>/dev/null | grep "^[hi]i " >/dev/null ; then echo " - Package '$i' is missing!" MISSING=1 fi done unset IFS fi if [ "$MISSING" = 1 ] ; then CONTINUE=`question "Some packages are missing. Do you want to continue building?" 1 no` if [ "$CONTINUE" = "no" ] ; then exit 1 fi fi echo "---" SB_BUILD_OPT_CLEAN_SOURCE=`question "Clean everything in source tree before build?" 1 no` SB_BUILD_OPT_CLEAN_TARGET=`question "Clean target ($SB_BUILD_OPT_ROOT/scratchbox/*) before build?" 1 no` echo "---" SB_BUILD_OPT_BUILD_HOST_COMP=`question "Would you like to build the 'host compiler'?" 1 yes` if [ "$SB_BUILD_OPT_BUILD_HOST_COMP" = "yes" ] ; then SB_BUILD_OPT_CLEAN_COMPILERS=`question " Clean installation directory before build?" 1 no` fi echo "---" SB_BUILD_OPT_BUILD_TOOLS=`question "Would you like to build 'tools'?" 1 yes` SB_BUILD_OPT_BUILD_POST_INSTALL=`question "Would you like to run 'post-install'?" 1 yes` echo "---" SB_BUILD_OPT_GENERATE_DOCS=`question "Would you like to generate the HTML documentation?" 1 yes` echo "---" SB_BUILD_OPT_MAKEOPTS=`question "Give make options (-j4 etc.)" 2 "-j1"` SB_BUILD_OPT_USE_CCACHE=`question "Use ccache during compile" 1 yes` # SB_BUILD_OPT_USE_CACHECC1=`question "Use cachecc1 during compile (Dont't use both (ccache and this))" 1 no` SB_BUILD_OPT_SBOX_VERSION=`question "Give scratchbox version" 2 "CVS-$(date +%Y%m%d)"` echo "---" SB_BUILD_OPT_DARCS_USE=`question "Use snapshots of darcs repositories {disable for releases}" 1 yes` if [ "$SB_BUILD_OPT_DARCS_USE" = "yes" ] ; then SB_BUILD_OPT_DARCS_REPOS=`question " Repository location?" 2 "$(dirname $(pwd))"` fi echo "---" SB_BUILD_OPT_OUT_FILE=`question "Save output to file named {"-" means none}" 2 "build.out"` echo "---" SAVE_FILE=`question "Save these options to file named" 2 "build.config"` rm -rf $SAVE_FILE for i in `set | grep "SB_BUILD_OPT_" | tr " " "£"`; do I=`echo $i | tr "£" " "`; echo "$I" >>$SAVE_FILE; done else source $1 fi LOGFILE=$PWD/build.log TIME="/usr/bin/time -vao $LOGFILE" log() { echo >>$LOGFILE -e '\n'`date +"%Y-%m-%d %H:%M:%S"` $@ } do_build() { export SBOX_VERSION=$SB_BUILD_OPT_SBOX_VERSION if [ "$SB_BUILD_OPT_DARCS_USE" = "yes" ] ; then export DARCS_SNAPSHOTS="$SB_BUILD_OPT_DARCS_REPOS" fi for i in `seq 70`; do echo >>$LOGFILE -n "=" done echo >>$LOGFILE log "Begin" if [ "$SB_BUILD_OPT_CLEAN_SOURCE" = "yes" ] ; then log "Cleaning source tree" $TIME make clean fi if [ "$SB_BUILD_OPT_CLEAN_TARGET" = "yes" ] ; then log "Cleaning installation" $TIME rm -rf $SB_BUILD_OPT_ROOT/scratchbox/* \ $SB_BUILD_OPT_ROOT/scratchbox/.run_me_first_done \ $SB_BUILD_OPT_ROOT/scratchbox/.sudo_mode fi if [ -d _darcs ] || [ ! -e doc/ChangeLog ]; then log "Updating ChangeLog" $TIME make doc/ChangeLog fi log "Building base" $TIME make base $SB_BUILD_OPT_MAKEOPTS BUILD_CACHE=$SB_BUILD_OPT_ROOT/scratchbox/build_cache if [ "$SB_BUILD_OPT_USE_CCACHE" = "yes" ] ; then if [ ! -x $BUILD_CACHE/ccache ] ; then log "Building temporary ccache" $TIME make -C tools/ccache $SB_BUILD_OPT_MAKEOPTS clean build \ SBOX_SPECS=/dev/null CATEGORY_GCCDIR=/usr CATEGORY_LDFLAGS= mkdir -p $BUILD_CACHE cp `find tools/ccache/work/ -name ccache -perm +111` $BUILD_CACHE/ make -C tools/ccache clean fi ln -sf ccache $BUILD_CACHE/gcc ln -sf ccache $BUILD_CACHE/cc ln -sf ccache $BUILD_CACHE/g++ ln -sf ccache $BUILD_CACHE/arm-linux-gcc ln -sf ccache $BUILD_CACHE/i386-linux-gcc ln -sf ccache $BUILD_CACHE/sbox-kgcc-arm-linux-gcc export CCACHE_UMASK=002 export PATH=$BUILD_CACHE:$PATH fi # if [ "$SB_BUILD_OPT_USE_CACHECC1" = "yes" ] ; then # if [ ! -x $BUILD_CACHE/cachecc1 ] ; then # log "Building temporary cachecc1" # $TIME make -C tools/cachecc1 $SB_BUILD_OPT_MAKEOPTS clean build \ # SBOX_SPECS=/dev/null CATEGORY_GCCDIR=/usr CATEGORY_LDFLAGS= # # mkdir -p $BUILD_CACHE # cp `find tools/cachecc1/work/ -name cachecc1 -perm +111` $BUILD_CACHE/ # cp `find tools/cachecc1/work/ -name followcc1.so` $BUILD_CACHE/ # # make -C tools/cachecc1 clean # fi # # if [ "x$CACHECC1DIR" = "x" ] ; then # export CACHECC1DIR=$HOME/.cachecc1 # fi # mkdir -p $CACHECC1DIR # # export CACHECC1=$BUILD_CACHE/cachecc1 # export LD_PRELOAD=$BUILD_CACHE/followcc1.so # fi if [ "$SB_BUILD_OPT_BUILD_HOST_COMP" = "yes" ] ; then if [ "$SB_BUILD_OPT_CLEAN_COMPILERS" = "yes" ] ; then log "Cleaning host-gcc source tree and installation" make -C compilers/host_gcc $SB_BUILD_OPT_MAKEOPTS clean-installation fi log "Building host-gcc" $TIME make $SB_BUILD_OPT_MAKEOPTS host-gcc fi log "Building utils" $TIME make utils $SB_BUILD_OPT_MAKEOPTS if [ "$SB_BUILD_OPT_BUILD_TOOLS" = "yes" ] ; then log "Building tools" $TIME make $SB_BUILD_OPT_MAKEOPTS tools fi if [ "$SB_BUILD_OPT_BUILD_POST_INSTALL" = "yes" ] ; then log "Running post-install" $TIME make $SB_BUILD_OPT_MAKEOPTS post-install fi if [ "$SB_BUILD_OPT_GENERATE_DOCS" = "yes" ] ; then log "Building documentation" $TIME make $SB_BUILD_OPT_MAKEOPTS docs fi log "End" echo >>$LOGFILE } if [ x"$SB_BUILD_OPT_OUT_FILE" = x- ] ; then do_build else do_build 2>&1 | tee "$SB_BUILD_OPT_OUT_FILE" fi