#! /bin/sh if false ;then OPTVAL=`getopt -o cb:l:s:k:L:v -n 'build-all' -- "$@"` else # XNU/BSD getopt is special... OPTVAL=$(getopt cb:l:s:k:L:v "$@") fi if [ $? != 0 ] then echo 'Usage: see source...' exit 2 fi eval set -- "$OPTVAL" cd $(dirname $0) #set -x b=$PWD # base directory l=$b/build.log # where to log operations s=$b/build.seq # build sequence k=$b/kext.stage # where to place kexts after build load='' # list of kexts to load clean=0 verbose=0 while true ;do case "$1" in -c) clean=1 shift 1 ;; -v) verbose=$(($verbose + 1)) shift 1 ;; -b) b=$2 shift 2 ;; -l) l=$2 shift 2 ;; -s) s=$2 shift 2 ;; -k) k=$2 shift 2 ;; -L) load=$2 shift 2 ;; --) shift break ;; *) echo "Internal error!" exit 1 ;; esac done echo > $l function message () { local msg msg="$1" echo $msg echo $msg >> $l } function abort () { local msg msg=$1 message "$1" exit 1 } function configure_xcode () { local path local pfile local module path=$PWD module=$(basename $path) pfile=$path/$module.xcode/project.pbxproj if [ -r $pfile.template ] ;then cpp \ -P \ -include $b/build-config \ $pfile.template | \ tail +2 > $pfile else abort "missing $pfile.template" fi } if [ x$clean != x0 ] ;then echo "Removing..." find $b/ -type d -name build rm -fr $(find $b/ -type d -name build) find $b/ -print0 | xargs -0 touch fi cat $s | while read ;do d=$REPLY if [ x$d = x ] ;then : # empty line. Do nothing elif [ ${d:0:1} = '#' ] ;then : # comment. Skip else cd $d || abort "Cannot cd to $d" message "________ Building in $d __________" #configure_xcode if [ $verbose -gt 0 ] ;then xcodebuild 2>&1 | tee -a $l else xcodebuild >> $l 2>&1 || abort "Build failure in $d. See $l" fi # tail -2 $l cd $b fi done # copy all built kexts into $k # sudo is used, because extensions are later chowned to root. sudo rm -f ../include/arch ln -s ../include/arch-xnu ../include/arch sudo rm -fr $k || abort "Cannot clean $k" mkdir $k || abort "Cannot create $k" cp -R $(find ../ -name \*.kext -type d) $k || abort "Cannot stage kexts" cd $k || abort "Cannot chdir to $k" sudo chown -R root:wheel * || abort "Cannot chown kexts to root:wheel" if [ x$load != x ] ;then cd $k sudo kextload -r $k $load else sudo chown -R root:wheel * fi cd $b sync;sync;sync