Advertisement
Guest User

build_all.sh

a guest
Jul 7th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.21 KB | None | 0 0
  1. #!/bin/sh
  2. TMPDIR="./tmp-build-all"
  3. BUILD_DIR="./builds"
  4. CONFIG="../../tools/configure"
  5. MAKE_FILE="Makefile"
  6. NOW=$(date +"%m-%d-%Y_%r")
  7. THREADS=" -j2"
  8. if [ "$2" = "RUNNING" ];
  9. then
  10.     echo "Running"
  11.  
  12. else
  13.     echo "First Run"
  14.     echo "#invocation $0 $*"
  15.     echo "Logging to $(readlink -f $1.log)"
  16.     echo "Builds stored in $(readlink -f $BUILD_DIR)"
  17.     if [ "$2" = "clean" ];
  18.     then
  19.         echo "clean build, removing build root directory"
  20.         if [ -d "$BUILD_DIR" ]; then
  21.             rm -rf "$BUILD_DIR"
  22.         fi
  23.     fi
  24.  
  25.     echo "------------------------------------------"
  26.     echo "Started $(date +"%m-%d-%Y_%r")" >$1.log
  27.     #Push to new shell instance so we can log StdOut and StdErr
  28.     #Only pipe StdErr to the current shell
  29.     echo `$0 $1 RUNNING 2>&1 >>$1.log | tee --append $1.log >&2`
  30.     exit 0
  31. fi
  32.  
  33. usage ()
  34. {
  35.     echo "Usage: $0 <build file>"
  36.     echo "Example:"
  37.     echo "$0 ../www/buildserver/builds"
  38.     exit 1
  39. }
  40.  
  41. # check number of arguments
  42. if [ $# -le 0 ]; then
  43.     usage
  44. fi
  45.  
  46. # print invocation, for reference
  47. echo "#invocation $0 $*"
  48. echo "\n\n"
  49. # build file
  50. BUILD_FILE="$1"
  51.  
  52. # check build file
  53. #if [ ! -d "builds" ];
  54. if [ ! -e "$BUILD_FILE" ]; then
  55.     echo "ERROR: build file doesn't exist $BUILD_FILE" 1>&2
  56.     exit 2
  57. fi
  58. # remove build directory
  59. #rm -rf "$BUILD_DIR"
  60. if [ ! -d "$BUILD_DIR" ]; then
  61.     echo "Build root directory doesn't exist, creating: $BUILD_DIR" 1>&2
  62.     #create build directory
  63.     mkdir "$BUILD_DIR"
  64. fi
  65. # cd into it
  66. cd "$BUILD_DIR"
  67. # process lines in the build
  68.  
  69. while read line
  70. do
  71.  
  72.     #replace tools path with our own
  73.      line=`echo $line | sed -e "s#../tools/configure#$CONFIG#"`
  74.     # ignore wps and manual lines
  75.      if `echo "$line" | grep -E "(wps)|(manual)|(sim)" > /dev/null 2>&1`; then
  76.      1>&2 echo "Ignored"
  77.      1>&2 echo "$line"| awk 'BEGIN { FS=":" } { print $3 }'
  78.      continue
  79.    fi
  80.     # format of each line: compiler:x:name:title:file:hint:command
  81.     NAME=`echo "$line" | awk 'BEGIN { FS=":" } { print $3 }'`
  82.     LN=$(wc -l < "../$1.log")
  83.     1>&2 echo "Line: $(($LN+1)), $BUILD_DIR/build_$NAME"
  84.     CMD=`echo "$line$THREADS" | awk 'BEGIN { FS=":" } { print $7 }'`
  85.     echo "$CMD"
  86.     # remove temporary directory
  87.     #rm -rf "$TMPDIR"
  88.     # create name directory and cd into it
  89. if [ ! -d "build_$NAME" ]; then
  90.     #create build directory
  91.     mkdir "build_$NAME"
  92. else
  93.     if [ -e "build_$NAME/$MAKE_FILE" ]; then
  94.         echo "Make file already exists build_$NAME/$MAKE_FILE" 1>&2
  95.         CMD=`echo "$line" | awk 'BEGIN { FS="&&" } { print $2 }'`
  96.         CMD="make$THREADS && $CMD"
  97.         echo "$CMD"
  98.     fi
  99.  
  100.  
  101. fi
  102.  
  103.     cd "build_$NAME"
  104.     # the command extract is of the form
  105.     # ../tools/configure <options> && make <blabla>
  106.     # try to run configure
  107.     # it might error if the target compiler is not installed for example
  108.  
  109.     if eval $CMD >/dev/null; then # &>/dev/null #
  110.  
  111.         echo "$NAME: ok"
  112.         echo "\n\n"
  113.     else
  114.         #print config error
  115.  
  116.         >&2 echo "$NAME: <config/build error>" 2>&1
  117.         echo "\n\n"
  118.  
  119.     fi
  120.     # cd back to build directory
  121.     cd ..
  122.  
  123. done < "../$BUILD_FILE"
  124. echo "Ended $(date +"%m-%d-%Y_%r")"
  125. # remove temp directory
  126. rm -rf "$TMPDIR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement