compat: Fixed pcie_get_minimum_link declaration
[~tnikolova/compat/.git] / bin / ckmake
index 2d9a5eb..b6780e5 100755 (executable)
@@ -25,26 +25,22 @@ UNDERLINE="\033[02m"
 KERNEL_DIR="/lib/modules"
 KLIBS=""
 LOG="ckmake.log"
+LOG_TMP="ckmake-tmp.log"
+REPORT="ckmake-report.log"
+TIME="0"
+QUIET=""
+ARGS=""
 
-LSB_RED_ID=$(/usr/bin/lsb_release -i -s)
-case $LSB_RED_ID in
-"Ubuntu")
-       for i in $(find /lib/modules/ -type d -name \*generic\* | sort -n -r); do
-               KLIBS="$KLIBS $i"
-       done
-       ;;
-*)
-       echo -e "Unsupported distribution"
-       exit
-       ;;
-esac
+RET=""
 
-nice make clean 2>&1 > $LOG
+for i in $(find /lib/modules/ -type d -name \*generic\* | sort -n -r | grep -v -E '\-[[:alnum:]]{1,2}\-'); do
+       KLIBS="$KLIBS $i"
+done
 
 function tee_color_split()
 {
        while read; do
-               echo -e $REPLY | ./scripts/skip-colors >> $LOG
+               echo -e $REPLY | ./scripts/skip-colors >> $1
                echo -e $REPLY
        done
 }
@@ -56,27 +52,100 @@ function log_try_kernel()
        echo -en "${NORMAL}"
 }
 
-for i in $KLIBS; do
-       KERNEL=$(basename $i)
-       DIR=${i}/build/
-       echo -e "--------------------------------------------" >> $LOG
-
-       if [[ ! -d $DIR ]]; then
-               continue
-       fi
-
-       # We cannot use tee_color_split() as bash read only spits
-       # out output when a newline comes in. We can modif IFS but
-       # I am still not sure how to do this properly.
-       log_try_kernel $KERNEL | ./scripts/skip-colors >> $LOG
-       log_try_kernel $KERNEL
-
-       ionice -c 3 nice -n 20 make KLIB=$DIR KLIB_BUILD=$DIR -j6 -Wunused-but-set-variable &>> $LOG
-       if [[ $? -eq 0 ]]; then
-               echo -e "${GREEN}[OK]${NORMAL}" | tee_color_split
-       else
-               echo -e "${RED}[FAILED]${NORMAL}" | tee_color_split
-       fi
-
-       nice make clean KLIB=$DIR KLIB_BUILD=$DIR 2>&1 >> $LOG
+function usage()
+{
+       echo -e "Usage: $0 [-t] <optional-target>"
+       echo -e "-t   will run: 'time ckmake; time ckmake' account for"
+       echo -e "     benchmark how long it takes to compile without ccache"
+       echo -e "     and a run after cache kicks in"
+       echo -e "-q   will ask ckmake to run make with -s to only output errors"
+       echo
+       echo -e "<optional-target>  is the arguments you want to pass to the"
+       echo -e "child make call that ckmake will use. For example if you have"
+       echo -e "a target 'linux' on your Makefile you can run 'cmake linux'"
+}
+
+for i in $@ ; do
+       case $1 in
+               "-h")
+                       usage
+                       exit 1
+                       ;;
+               "--help")
+                       usage
+                       exit 1
+                       ;;
+               "-t")
+                       TIME="1"
+                       shift
+                       ;;
+               "-s")
+                       QUIET="-s"
+                       shift
+                       ;;
+               *)
+                       ARGS="${ARGS} $1"
+                       shift
+       esac
 done
+
+function run_ckmake()
+{
+       for i in $KLIBS; do
+               KERNEL=$(basename $i)
+               DIR=${i}/build/
+               echo -e "--------------------------------------------" >> $LOG
+
+               if [[ ! -d $DIR ]]; then
+                       continue
+               fi
+
+               # We cannot use tee_color_split() as bash read only spits
+               # out output when a newline comes in. We can modif IFS but
+               # I am still not sure how to do this properly.
+               log_try_kernel $KERNEL | ./scripts/skip-colors >> $LOG
+               log_try_kernel $KERNEL
+
+               ionice -c 3 nice -n 20 make $QUIET KLIB=$DIR KLIB_BUILD=$DIR -j6 -Wunused-but-set-variable $ARGS &>> $LOG
+               CUR_RET=$?
+
+               if [[ $RET = "" ]]; then
+                       RET=$CUR_RET
+               fi
+
+               if [[ $CUR_RET -eq 0 ]]; then
+                       echo -e "${GREEN}[OK]${NORMAL}" | tee_color_split $LOG
+               else
+                       echo -e "${RED}[FAILED]${NORMAL}" | tee_color_split $LOG
+                       RET=$CUR_RET
+               fi
+
+               nice make clean KLIB=$DIR KLIB_BUILD=$DIR 2>&1 >> $LOG
+       done
+}
+
+for i in $LOG $LOG_TMP $REPORT; do
+       echo > $i
+done
+
+nice make clean 2>&1 > $LOG
+
+if [[ $TIME != "1" ]]; then
+       run_ckmake | tee_color_split $REPORT
+
+       cat $LOG $REPORT > $LOG_TMP
+       mv $LOG_TMP $LOG
+       rm -f $LOG_TMP
+
+       exit $RET
+fi
+
+time $0 $QUIET $ARGS | tee_color_split $REPORT
+time $0 $QUIET $ARGS | egrep "real|user|sys" | tee_color_split $REPORT
+
+cat $LOG $REPORT > $LOG_TMP
+mv $LOG_TMP $LOG
+
+rm -f $LOG_TMP
+
+exit $RET