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/tools/gcc-sdk/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 # Please refer to prebuilts/tools/gcc-sdk/gcc for similar trick to determine 82 # bitness 83 options=" ${@} " # sentinel prefix/suffix space to simplify pattern match below 84 suffix_m32=${options##* -m32 } # suffix after the last -m32 85 suffix_m64=${options##* -m64 } # suffix after the last -m64 86 len_m32=${#suffix_m32} # length of suffix after the last -m32 87 len_m64=${#suffix_m64} # length of suffix after the last -m64 88 if [ $len_m32 -ge $len_m64 ] ; then 89 CLANG_FLAGS_END="\ 90 -I prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/lib/gcc/x86_64-linux/4.6.x-google/include \ 91 -I prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/lib/gcc/x86_64-linux/4.6.x-google/include-fixed \ 92 -I prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/x86_64-linux/include \ 93 -I prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/sysroot/usr/include" 94 else 95 CLANG_FLAGS_END="\ 96 -I prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/lib/gcc/i686-linux/4.6.x-google/include \ 97 -I prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/lib/gcc/i686-linux/4.6.x-google/include-fixed \ 98 -I prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/i686-linux/include \ 99 -I prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/sysroot/usr/include" 100 fi 101 fi 102 103 # Turn off warnings (at the end) on features we exploit 104 CLANG_FLAGS_END="$CLANG_FLAGS_END -Wno-return-type-c-linkage" 105 106 # Call the real ccc-analyzer. Note that tools/scan-build/ccc-analyzer "exec" $CCC_CC, 107 # which is LOCAL_CC w/o optional ccache (in "ccache gcc" format) 108 export CCC_CC="${LOCAL_CC##* }" 109 export CLANG="`dirname $0`/analyzer" 110 export CLANG_FLAGS 111 export CLANG_FLAGS_END 112 `dirname $0`/../tools/scan-build/ccc-analyzer "$@" 113