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#
16if [ -z "$REAL_CROSS_COMPILE" ]; then
17    echo "ERROR: The REAL_CROSS_COMPILE environment variable should be defined!"
18    exit 1
19fi
20
21# ARCH must also be defined before calling this script, e.g. 'arm' or 'x86'
22#
23if [ -z "$ARCH" ]; then
24    echo "ERROR: ARCH must be defined!"
25    exit 1
26fi
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#
35PROGPREFIX=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#
41PROGNAME=$(basename "$0")
42PROGSUFFIX=${PROGNAME##$PROGPREFIX}
43
44EXTRA_FLAGS=
45
46if [ "$PROGSUFFIX" = gcc ]; then
47    # Special case #1: For all, disable PIC code
48    EXTRA_FLAGS=$EXTRA_FLAGS" -fno-pic"
49    if [ "$ARCH" = "x86" ]; then
50        # Special case #2: For x86, disable SSE FPU arithmetic too
51        EXTRA_FLAGS=$EXTRA_FLAGS" -mfpmath=387"
52    fi
53fi
54
55# Invoke real cross-compiler toolchain program now
56${REAL_CROSS_COMPILE}$PROGSUFFIX $EXTRA_FLAGS "$@"
57