smol-gilbraltar/toolchain/cc.in

109 lines
3.5 KiB
Bash

#!/bin/sh
# Copyright (c) 2015-2021 Solo5 Contributors
# Copyright (c) 2024 Romain Calascibetta
#
# This file is part of Gilbraltar, a bare-metal OS for RaspBerry Pi 5.
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice appear
# in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# @@CONFIG_TARGET_TRIPLE@@-cc: Gilbraltar wrapper for 'cc'.
# Generated by configure.sh at build time.
#
# Passes through to @@CONFIG_TARGET_CC@ for actual work. Defines all flags
# required for correct operation when building C code intended for inclusion in
# a Gilbraltar operating system.
#
# Provides a '-z gilbraltar-abi=ABI' option to select the Gilbraltar bindings to
# use if linking. ABI defaults to 'stub' to accomodate non-Gilbraltar-aware
# build systems, such as GNU autoconf, which use 'cc'-as-linker to test for the
# presence of symbols.
prog="$(basename $0)"
I="$(dirname $0)/../../include"
[ ! -d "${I}" ] && echo "$prog: Could not determine include path" 1>&2 && exit 1
L="$(dirname $0)/../../lib/@@CONFIG_TARGET_TRIPLE@@"
[ ! -d "${L}" ] && echo "$prog: Could not determine library path" 1>&2 && exit 1
# we can't really tell if 'cc' is called with no input, but work around the
# most obvious cases and stop them from "succeeding" and producing an "a.out"
[ "$#" -lt 1 ] && \
echo "$prog: No input files. Compilation terminated." 1>&1 && exit 1
[ "$#" -eq 1 -a "$1" = "-v" ] && exec @@CONFIG_TARGET_CC@@ "$@"
# default to cc as linker, unless we see args to the contrary
M=link
B=rpi5
Z=
for arg do
shift
if [ -n "${Z}" ]; then
# handle -z linker-arg
Z=
case "$arg" in
gilbraltar-abi=*)
B="${arg##*=}"
continue
;;
*)
set -- "$@" "-z" "$arg"
continue
;;
esac
fi
case "$arg" in
-c|-S|-E)
M=compile
;;
-z)
if [ -z "${Z}" ]; then
Z=1
continue
fi
;;
esac
set -- "$@" "$arg"
done
case ${M} in
compile)
[ -n "${__V}" ] && set -x
exec @@CONFIG_TARGET_CC@@ \
@@CONFIG_TARGET_CC_CFLAGS@@ \
-isystem ${I}/@@CONFIG_TARGET_TRIPLE@@ \
-I ${I} \
-D__BSD_VISIBLE=0 \
-D__XSI_VISIBLE=0 \
-Wall \
-DAARCH=64 \
-mcpu=cortex-a76 \
"$@"
;;
link)
[ -n "${B}" ] && B="-Wl,-T,gilbraltar.ld"
[ -n "${LDFLAGS}" ] && LDFLAGS=$(echo "-Wl @@CONFIG_TARGET_LD_LDFLAGS@@" | tr ' ' ',')
[ -n "${__V}" ] && set -x
exec @@CONFIG_TARGET_CC@@ \
-L ${L} \
@@CONFIG_TARGET_CC_CFLAGS@@ \
-isystem ${I}/@@CONFIG_TARGET_TRIPLE@@ \
-I ${I} \
-ffreestanding \
-fstack-protector-strong \
"$@" \
@@CONFIG_TARGET_CC_LDFLAGS@@
-Wl,${LDFLAGS} \
${B} \
-static \
;;
esac