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_CXX ... 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_CXX with our own cxx-syntax, 12 # which in turn setup the following env. vars expected by tools/scan-build/c++-analyzer 13 # 14 # CCC_CXX: The origianl LOCAL_CXX which does the real compilation and code-gen 15 # CLANG_CXX: The clang++ compiler which run code analyses 16 # 17 # Our own cxx-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_CXX="$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 # Ignore C standard like -std=gnu99 in LOCAL_CFLAGS but get 38 # passed for C++ compilation by build system 39 CLANG_FLAGS="$CLANG_FLAGS -Qignore-c-std-not-allowed-with-cplusplus" 40 41 # Turn off warnings which aren't useful in this context 42 CLANG_FLAGS="$CLANG_FLAGS -Wno-ignored-attributes -Wno-pedantic -Wno-builtin-requires-header -Wno-gnu -Wno-gnu-designator -Wno-knr-promoted-parameter" 43 44 if [ "$ARCH" != "host" ]; then 45 # Add target to get proper pre-defined preprocessor symbols/macros. 46 case $ARCH in 47 arm) CLANG_FLAGS="$CLANG_FLAGS -target armv5te-none-linux-androideabi" 48 ;; 49 mips) CLANG_FLAGS="$CLANG_FLAGS -target mipsel-none-linux-android" 50 ;; 51 x86) CLANG_FLAGS="$CLANG_FLAGS -target i686-none-linux-android" 52 ;; 53 esac 54 if [ "$LOCAL_CXX" != "${LOCAL_CXX%clang++*}" ]; then 55 # Don't look for its own lib/clang/x.y/include when LOCAL_CXX is clang 56 # which is rebuilt from source w/o installing its include as well 57 CLANG_FLAGS="$CLANG_FLAGS -nostdinc" 58 fi 59 else 60 # Note that unlike target flags where Android build system explicitly specify 61 # everything in command line, host tools have their own sysroot and --sysroot 62 # isn't explicitly added in the commmand line. Likelywise for other gcc implicit 63 # search directories. 64 # 65 # We can query search paths by doing "g++ -v" and parsing the output with 66 # sed -n '1,/BEGIN/!{ /END/,/BEING/!p; }' (*1), but forking gcc here adds overhead. 67 # Because host tool refresh only once 1-2 year, here we hard-code the path obtained by (*2). 68 # ToDo: The build system can do it once for each module, although it still needs to 69 # prepare both -m32 and -m64 versions, anding 2 more args in additional to $ARCH 70 # and $LOCAL_CXX 71 # 72 # (*1) as described in http://sed.sourceforge.net/sedfaq4.html#s4.24 73 # (*2) prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/bin/i686-apple-darwin10-g++ -m64 -v -E - < /dev/null 2>&1 | \ 74 # sed -n '1,/> search starts here/!{ /End of search list/,/> search starts here/!p; }' |\ 75 # sed -e 's/^/-I/' 76 # Likewise for -m32 77 # 78 CLANG_FLAGS_END="\ 79 -I prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/lib/gcc/i686-apple-darwin10/4.2.1/include" 80 fi 81 82 # Turn off warnings (at the end) on features we exploit 83 CLANG_FLAGS_END="$CLANG_FLAGS_END -Wno-return-type-c-linkage" 84 85 # Call the real c++-analyzer. Note that tools/scan-build/c++-analyzer "exec" $CCC_CXX, 86 # which is LOCAL_CXX w/o optional ccache (in "ccache g++" format) 87 export CCC_CXX="${LOCAL_CXX##* }" 88 export CLANG_CXX="`dirname $0`/analyzer++" 89 export CLANG_FLAGS 90 export CLANG_FLAGS_END 91 `dirname $0`/../tools/scan-build/c++-analyzer "$@" 92