2025-01-02 11:16:39 +00:00
|
|
|
#!/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)"
|
2025-01-12 19:06:40 +00:00
|
|
|
I="$(dirname $0)/../../include"
|
2025-01-02 11:16:39 +00:00
|
|
|
[ ! -d "${I}" ] && echo "$prog: Could not determine include path" 1>&2 && exit 1
|
2025-01-12 19:06:40 +00:00
|
|
|
L="$(dirname $0)/../../lib/@@CONFIG_TARGET_TRIPLE@@"
|
2025-01-02 11:16:39 +00:00
|
|
|
[ ! -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
|
2025-01-12 19:06:40 +00:00
|
|
|
B=rpi5
|
2025-01-02 11:16:39 +00:00
|
|
|
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
|
2025-01-12 19:06:40 +00:00
|
|
|
|
2025-01-02 11:16:39 +00:00
|
|
|
case ${M} in
|
|
|
|
compile)
|
|
|
|
[ -n "${__V}" ] && set -x
|
|
|
|
exec @@CONFIG_TARGET_CC@@ \
|
|
|
|
@@CONFIG_TARGET_CC_CFLAGS@@ \
|
|
|
|
-isystem ${I}/@@CONFIG_TARGET_TRIPLE@@ \
|
|
|
|
-I ${I} \
|
2025-01-12 19:06:40 +00:00
|
|
|
-D__BSD_VISIBLE=0 \
|
|
|
|
-D__XSI_VISIBLE=0 \
|
|
|
|
-Wall \
|
|
|
|
-DAARCH=64 \
|
|
|
|
-mcpu=cortex-a76 \
|
2025-01-02 11:16:39 +00:00
|
|
|
"$@"
|
2025-01-12 19:06:40 +00:00
|
|
|
;;
|
2025-01-02 11:16:39 +00:00
|
|
|
link)
|
2025-01-12 19:06:40 +00:00
|
|
|
[ -n "${B}" ] && B="-Wl,-T,gilbraltar.ld"
|
|
|
|
[ -n "${LDFLAGS}" ] && LDFLAGS=$(echo "-Wl @@CONFIG_TARGET_LD_LDFLAGS@@" | tr ' ' ',')
|
2025-01-02 11:16:39 +00:00
|
|
|
[ -n "${__V}" ] && set -x
|
|
|
|
exec @@CONFIG_TARGET_CC@@ \
|
2025-01-12 19:06:40 +00:00
|
|
|
-L ${L} \
|
2025-01-02 11:16:39 +00:00
|
|
|
@@CONFIG_TARGET_CC_CFLAGS@@ \
|
|
|
|
-isystem ${I}/@@CONFIG_TARGET_TRIPLE@@ \
|
|
|
|
-I ${I} \
|
|
|
|
-ffreestanding \
|
|
|
|
-fstack-protector-strong \
|
2025-01-12 19:06:40 +00:00
|
|
|
"$@" \
|
|
|
|
@@CONFIG_TARGET_CC_LDFLAGS@@
|
|
|
|
-Wl,${LDFLAGS} \
|
2025-01-02 11:16:39 +00:00
|
|
|
${B} \
|
|
|
|
-static \
|
|
|
|
;;
|
|
|
|
esac
|