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