Home | History | Annotate | Download | only in bin
      1 #!/bin/sh
      2 
      3 # This script is invoked by Android build system "WITH_SYNTAX_CHECK=1 m/mm/mmm ..." and
      4 # accepts command line in the following format:
      5 #
      6 #    ccc-analyzer ARCH LOCAL_CC ...
      7 #
      8 # Under WITH_SYNTAX_CHECK=1, m/mm/mmm/mma/mmma wrap "make" with "tools/scan-build/scan-build"
      9 # which utillizes "clang --analyze" for static code analyses.  Script scan-build interposes
     10 # on compiler with CC/CXX ignored by the Android build system unfortunately.  Instead,
     11 # Android build system recognizes WITH_SYNTAX_CHECK and replace LOCAL_CC with our own ccc-syntax,
     12 # which in turn setup the following env. vars expected by tools/scan-build/ccc-analyzer
     13 #
     14 #   CCC_CC: The origianl LOCAL_CC which does the real compilation and code-gen
     15 #   CLANG: The clang compiler which run code analyses
     16 #
     17 # Our own ccc-syntax also export the following, and tools/scan-build/ccc-analyzer is slightly
     18 # modified to prefix/append them in options passed to clang for successful compilation
     19 #
     20 #   CLANG_FLAGS: Flags to set correct target, be compatible with gcc, etc
     21 #   CLANG_FLAGS_END:  Flags to override "$@"
     22 #
     23 
     24 ARCH="$1"
     25 LOCAL_CC="$2"
     26 shift ; shift
     27 
     28 # Turn off warning about unused options
     29 CLANG_FLAGS="-Qunused-arguments"
     30 
     31 # Turn off unknown warning options
     32 CLANG_FLAGS="$CLANG_FLAGS -Wno-unknown-warning-option"
     33 
     34 # Define WITH_SYNTAX_CHECK for code wish to behave differently when check
     35 CLANG_FLAGS="$CLANG_FLAGS -DWITH_SYNTAX_CHECK"
     36 
     37 # If LOCAL_CC is not clang and not compiling in c++ mode, turn on -std=gnu89 by default
     38 # and let "$@" later override it, if any
     39 test "$LOCAL_CC" != "${LOCAL_CC%-x c++}" -o "$LOCAL_CC" = "${LOCAL_CC%-xc++}" && cxx_mode=true
     40 if [ "$LOCAL_CC" = "${LOCAL_CC%clang}" -a "$cxx_mode" != "true" ] ; then
     41     CLANG_FLAGS="$CLANG_FLAGS -std=gnu89"
     42 fi
     43 
     44 # Turn off warnings which aren't useful in this context
     45 CLANG_FLAGS="$CLANG_FLAGS -Wno-ignored-attributes -Wno-pedantic -Wno-builtin-requires-header -Wno-gnu -Wno-gnu-designator -Wno-knr-promoted-parameter"
     46 
     47 if [ "$ARCH" != "host" ]; then
     48     # Add target to get proper pre-defined preprocessor symbols/macros.
     49     case $ARCH in
     50         arm) CLANG_FLAGS="$CLANG_FLAGS -target armv5te-none-linux-androideabi"
     51             ;;
     52         mips) CLANG_FLAGS="$CLANG_FLAGS -target mipsel-none-linux-android"
     53             ;;
     54         x86) CLANG_FLAGS="$CLANG_FLAGS -target i686-none-linux-android"
     55             ;;
     56     esac
     57     if [ "$LOCAL_CC" != "${LOCAL_CC%clang*}" ]; then
     58         # Don't look for its own lib/clang/x.y/include when LOCAL_CC is clang
     59         # which is rebuilt from source w/o installing its include as well
     60         CLANG_FLAGS="$CLANG_FLAGS -nostdinc"
     61     fi
     62 else
     63     # Note that unlike target flags where Android build system explicitly specify
     64     # everything in command line, host tools have their own sysroot and --sysroot
     65     # isn't explicitly added in the commmand line.  Likelywise for other gcc implicit
     66     # search directories.
     67     #
     68     # We can query search paths by doing "gcc -v" and parsing the output with
     69     # sed -n '1,/BEGIN/!{ /END/,/BEING/!p; }' (*1), but forking gcc here adds overhead.
     70     # Because host tool refresh only once 1-2 year, here we hard-code the path obtained by (*2).
     71     # ToDo: The build system can do it once for each module, although it still needs to
     72     # prepare both -m32 and -m64 versions, anding 2 more args in additional to $ARCH
     73     # and $LOCAL_CC
     74     #
     75     # (*1) as described in http://sed.sourceforge.net/sedfaq4.html#s4.24
     76     # (*2) prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/bin/i686-apple-darwin10-gcc -m64 -v -E - < /dev/null 2>&1 | \
     77     #         sed -n '1,/> search starts here/!{ /End of search list/,/> search starts here/!p; }' |\
     78     #         sed -e 's/^/-I/'
     79     #      Likewise for -m32
     80     #
     81     CLANG_FLAGS_END="\
     82 -I prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/lib/gcc/i686-apple-darwin10/4.2.1/include"
     83 fi
     84 
     85 # Turn off warnings (at the end) on features we exploit
     86 CLANG_FLAGS_END="$CLANG_FLAGS_END -Wno-return-type-c-linkage"
     87 
     88 # Call the real ccc-analyzer.  Note that tools/scan-build/ccc-analyzer "exec" $CCC_CC,
     89 # which is LOCAL_CC w/o optional ccache (in "ccache gcc" format)
     90 export CCC_CC="${LOCAL_CC##* }"
     91 export CLANG="`dirname $0`/analyzer"
     92 export CLANG_FLAGS
     93 export CLANG_FLAGS_END
     94 `dirname $0`/../tools/scan-build/ccc-analyzer "$@"
     95