1 #!/bin/sh 2 3 # This script is invoked by Android build system "WITH_SYNTAX_CHECK=1 make ..." and 4 # accepts command line in the following format: 5 # 6 # cxx-syntax ARCH LOCAL_CXX ... 7 # 8 # It calls "clang++ -fsyntax-only ..." to utilize clang's better diagnostics 9 # before calling "LOCAL_CXX ..." for code generation. ARCH is translated 10 # into "-target XXX" (see below) to get proper pre-defined preprocessor 11 # symbols/macros. Some clang-specific warnings are disabled to be compatible 12 # with Android toolchain mostly gcc. 13 # 14 # The compilation time is slightly longer, and the generated object file 15 # should be the same as w/o WITH_SYNTAX_CHECK 16 # 17 # Note that although Android build system doesn't call LOCAL_CXX with any of 18 # the following flags, this script should check and skip "clang -fsyntax-only" 19 # if options contain any of the following: '-print-*', '-dump*', '@*', '-E', 20 # '-' or '-M', for use elsewhere. 21 # 22 23 ARCH="$1" 24 LOCAL_CXX="$2" 25 shift ; shift 26 27 # Turn on syntax-only 28 CLANG_FLAGS="-fsyntax-only" 29 30 # Turn off warning about unused options 31 CLANG_FLAGS="$CLANG_FLAGS -Qunused-arguments" 32 33 # Turn off unknown warning options 34 CLANG_FLAGS="$CLANG_FLAGS -Wno-unknown-warning-option" 35 36 # Define WITH_SYNTAX_CHECK for code wish to behave differently when check 37 CLANG_FLAGS="$CLANG_FLAGS -DWITH_SYNTAX_CHECK" 38 39 # Ignore C standard like -std=gnu99 in LOCAL_CFLAGS but get 40 # passed for C++ compilation by build system 41 CLANG_FLAGS="$CLANG_FLAGS -Qignore-c-std-not-allowed-with-cplusplus" 42 43 # Turn off warnings which aren't useful in this context 44 CLANG_FLAGS="$CLANG_FLAGS -Wno-ignored-attributes -Wno-pedantic -Wno-builtin-requires-header -Wno-gnu -Wno-gnu-designator -Wno-knr-promoted-parameter" 45 46 if [ "$ARCH" != "host" ]; then 47 # Add target to get proper pre-defined preprocessor symbols/macros. 48 case $ARCH in 49 arm) CLANG_FLAGS="$CLANG_FLAGS -target armv5te-none-linux-androideabi" 50 ;; 51 mips) CLANG_FLAGS="$CLANG_FLAGS -target mipsel-none-linux-android" 52 ;; 53 x86) CLANG_FLAGS="$CLANG_FLAGS -target i686-none-linux-android" 54 ;; 55 esac 56 if [ "$LOCAL_CXX" != "${LOCAL_CXX%clang++*}" ]; then 57 # Don't look for its own lib/clang/x.y/include when LOCAL_CXX is clang 58 # which is rebuilt from source w/o installing its include as well 59 CLANG_FLAGS="$CLANG_FLAGS -nostdinc" 60 fi 61 else 62 # Note that unlike target flags where Android build system explicitly specify 63 # everything in command line, host tools have their own sysroot and --sysroot 64 # isn't explicitly added in the commmand line. Likelywise for other gcc implicit 65 # search directories. 66 # 67 # We can query search paths by doing "g++ -v" and parsing the output with 68 # sed -n '1,/BEGIN/!{ /END/,/BEING/!p; }' (*1), but forking gcc here adds overhead. 69 # Because host tool refresh only once 1-2 year, here we hard-code the path obtained by (*2). 70 # ToDo: The build system can do it once for each module, although it still needs to 71 # prepare both -m32 and -m64 versions, anding 2 more args in additional to $ARCH 72 # and $LOCAL_CXX 73 # 74 # (*1) as described in http://sed.sourceforge.net/sedfaq4.html#s4.24 75 # (*2) prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/bin/i686-apple-darwin10-g++ -m64 -v -E - < /dev/null 2>&1 | \ 76 # sed -n '1,/> search starts here/!{ /End of search list/,/> search starts here/!p; }' |\ 77 # sed -e 's/^/-I/' 78 # Likewise for -m32 79 # 80 read -d '' CLANG_FLAGS_END <<"EOF" 81 -I prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1/lib/gcc/i686-apple-darwin10/4.2.1/include 82 EOF 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 it 89 `dirname $0`/analyzer++ $CLANG_FLAGS "$@" $CLANG_FLAGS_END 90 if [ "$?" != 0 ]; then 91 test $WITH_SYNTAX_CHECK -ge 2 && echo '*** ERROR ***': `dirname $0`/analyzer++ $CLANG_FLAGS "$@" $CLANG_FLAGS_END 92 exit 1 93 fi 94 $LOCAL_CXX "$@" 95