Home | History | Annotate | Download | only in kernel-toolchain
      1 #!/bin/sh
      2 #
      3 # This is a wrapper around our toolchain that allows us to add a few
      4 # compiler flags.
      5 # The issue is that our toolchain are NDK-compatible, and hence enforces
      6 # -fpic (and also -mfpmath=sse for x86) by default.  When building the
      7 # kernel, we need to disable this.
      8 #
      9 # Also support ccache compilation if USE_CCACHE is defined as "1"
     10 #
     11 
     12 # REAL_CROSS_COMPILE must be defined, and its value must be one of the
     13 # CROSS_COMPILE values that are supported by the Kernel build system
     14 # (e.g. "i686-linux-android-")
     15 #
     16 if [ -z "$REAL_CROSS_COMPILE" ]; then
     17     echo "ERROR: The REAL_CROSS_COMPILE environment variable should be defined!"
     18     exit 1
     19 fi
     20 
     21 # ARCH must also be defined before calling this script, e.g. 'arm' or 'x86'
     22 #
     23 if [ -z "$ARCH" ]; then
     24     echo "ERROR: ARCH must be defined!"
     25     exit 1
     26 fi
     27 
     28 # Common prefix for all fake toolchain programs, which are all really
     29 # symlinks to this script, i.e.
     30 #
     31 # $PROGPREFIX-gcc  --> $0
     32 # $PROGPREFIX-ld   --> $0
     33 # etc...
     34 #
     35 PROGPREFIX=android-kernel-toolchain-
     36 
     37 # Get program name, must be of the form $PROGPREFIX-<suffix>, where
     38 # <suffix> can be 'gcc', 'ld', etc... We expect that the fake toolchain
     39 # files are all symlinks to this script.
     40 #
     41 PROGNAME=$(basename "$0")
     42 PROGSUFFIX=${PROGNAME##$PROGPREFIX}
     43 
     44 EXTRA_FLAGS=
     45 
     46 if [ "$PROGSUFFIX" = gcc ]; then
     47     # Special case #1: For all, disable PIC code
     48     EXTRA_FLAGS=$EXTRA_FLAGS" -fno-pic"
     49     case $ARCH in
     50         x86)
     51             # Special case #2: For x86, disable SSE FPU arithmetic too
     52             EXTRA_FLAGS=$EXTRA_FLAGS" -m32 -mfpmath=387"
     53             ;;
     54     esac
     55 fi
     56 
     57 # Invoke real cross-compiler toolchain program now
     58 ${REAL_CROSS_COMPILE}$PROGSUFFIX $EXTRA_FLAGS "$@"
     59