make only needs to read Makefile.incs once, thanks to the
[coreboot.git] / util / abuild / abuild
index 3325fed6e32cd6f06ac583e9414b47a73ddaa3c8..fbb801ec8288309271d8aac9d26f2d3527baa9da 100755 (executable)
@@ -18,7 +18,7 @@ ABUILD_DATE="January 29th, 2010"
 ABUILD_VERSION="0.9"
 
 # Where shall we place all the build trees?
-TARGET=$( pwd )/coreboot-builds
+TARGET=coreboot-builds
 XMLFILE=$( pwd )/abuild.xml
 
 # path to payload. Should be more generic
@@ -55,6 +55,9 @@ silent=
 # clang mode enabled by -sb option.
 scanbuild=false
 
+# use ccache
+ccache=false
+
 # stackprotect mode enabled by -ns option.
 stackprotect=false
 
@@ -143,7 +146,7 @@ function create_config
                printf "Using payload $PAYLOAD\n"
        fi
 
-       $MAKE distclean O=${build_dir}
+       $MAKE distclean obj=${build_dir}
        mkdir -p ${build_dir}
 
        if [ "$CONFIG" != "" ]; then
@@ -174,6 +177,11 @@ function create_config
                        echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> .config
                fi
 
+               if [ "$ccache" = "true" ]; then
+                       printf "(ccache enabled) "
+                       echo "CONFIG_CCACHE=y" >> .config
+               fi
+
                if [ "$scanbuild" = "true" ]; then
                        printf "(scan-build enabled) "
                        echo "CONFIG_SCANBUILD_ENABLE=y" >> .config
@@ -181,7 +189,7 @@ function create_config
                fi
        fi
 
-       yes "" | $MAKE oldconfig O=${build_dir} > ${build_dir}/config.log
+       yes "" | $MAKE oldconfig obj=${build_dir} > ${build_dir}/config.log
        ret=$?
        mv .config.old $TARGET/${VENDOR}_${MAINBOARD}/config.in
        if [ $ret -eq 0 ]; then
@@ -210,6 +218,16 @@ function create_buildenv
        MAINBOARD=$2
        CONFIG=$3
        create_config $VENDOR $MAINBOARD $CONFIG
+
+       # Allow simple "make" in the target directory
+       MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
+       echo "# autogenerated makefile" > $MAKEFILE
+       echo "TOP=$ROOT" >> $MAKEFILE
+       echo "OUT=$TARGET/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
+       echo "coreboot.rom:" >> $MAKEFILE
+       echo "  cp config.build \$(TOP)/.config" >> $MAKEFILE
+       echo "  cd \$(TOP); \$(MAKE) oldconfig obj=\$(OUT)" >> $MAKEFILE
+       echo "  cd \$(TOP); \$(MAKE) obj=\$(OUT)" >> $MAKEFILE
 }
 
 function compile_target
@@ -225,7 +243,7 @@ function compile_target
        CURR=$( pwd )
        stime=`perl -e 'print time();' 2>/dev/null || date +%s`
        build_dir=$TARGET/${VENDOR}_${MAINBOARD}
-       eval $MAKE $silent -j $cpus O=${build_dir} \
+       eval $MAKE $silent -j $cpus obj=${build_dir} \
                &> ${build_dir}/make.log
        ret=$?
        mv .config ${build_dir}/config.build
@@ -485,6 +503,7 @@ function myhelp
        printf "    [-s|--silent]                 omit compiler calls in logs\n"
        printf "    [-ns|--nostackprotect]        use gcc -fno-stack-protector option\n"
        printf "    [-sb|--scan-build]            use clang's static analyzer\n"
+       printf "    [-y|--ccache]                 use ccache\n"
        printf "    [-C|--config]                 configure-only mode\n"
        printf "    [-l|--loglevel <num>]         set loglevel\n"
        printf "    [lbroot]                      absolute path to coreboot sources\n"
@@ -520,11 +539,11 @@ test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
 getoptbrand="`getopt -V`"
 if [ "${getoptbrand:0:6}" == "getopt" ]; then
        # Detected GNU getopt that supports long options.
-       args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel: Vvhat:bp:Tc:sxCl: -- "$@"`
+       args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel:,ccache Vvhat:bp:Tc:sxCl:y -- "$@"`
        eval set "$args"
 else
        # Detected non-GNU getopt
-       args=`getopt Vvhat:bp:Tc:sxCl:o $*`
+       args=`getopt Vvhat:bp:Tc:sxCl:y $*`
        set -- $args
 fi
 
@@ -540,7 +559,7 @@ while true ; do
                -a|--all)       shift; buildall=true;;
                -b|--broken)    shift; buildbroken=true;;
                -r|--remove)    shift; remove=true; shift;;
-               -v|--verbose)   shift; verbose=true;;
+               -v|--verbose)   shift; verbose=true; silent='V=1';;
                -V|--version)   shift; myversion; exit 0;;
                -h|--help)      shift; myversion; myhelp; exit 0;;
                -p|--payloads)  shift; payloads="$1"; shift;;
@@ -549,6 +568,7 @@ while true ; do
                -s|--silent)    shift; silent="-s";;
                -ns|--nostackprotect) shift; stackprotect=true;;
                -sb|--scan-build) shift; scanbuild=true;;
+               -y|--ccache)    shift; ccache=true;;
                -C|--config)    shift; configureonly=1;;
                -l|--loglevel)  shift; loglevel="$1"; shift;;
                --)             shift; break;;