From 1a741c1c0168e8b2383a62100709c625a5a8961f Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 18 Jul 2021 19:16:08 +0200 Subject: another test with c4 and a minic compiler --- miniany/build.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 miniany/build.sh (limited to 'miniany/build.sh') diff --git a/miniany/build.sh b/miniany/build.sh new file mode 100755 index 0000000..0db0d13 --- /dev/null +++ b/miniany/build.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +BINARY=${1:-cc} +COMPILER=${2:-gcc} +MODE=${3:-freestanding} +LEVEL=${4:-d} + +DEBUG=0 + +declare -a MODULES +MODULES+=("libc-${MODE}.c") +MODULES+=("$BINARY.c") + +case "${COMPILER}" in + gcc) + CFLAGS="-m32 -march=i386 -Wall -pedantic -Werror -std=c89 -x c" + ;; + clang) + CFLAGS="-m32 -march=i386 -Werror -Wall -pedantic -std=c89 -x c" + ;; + pcc) + CFLAGS="-march=i386 -Werror -Wall -std=c89 -x c" + ;; + tcc) + CFLAGS="-m32 -march=i386 -Werror -Wall -std=c89" + ;; + *) + echo "ERROR: Unknown compiler '${COMPILER}' (use gcc, clang, pcc or tcc)" 1>&2 + exit 1 + ;; +esac + +case "${LEVEL}" in + 0|1|2|3) + CFLAGS+=" -O${LEVEL}" + ;; + d) + CFLAGS+=" -g -O0" + DEBUG=1 + ;; + *) + echo "ERROR: Unknown compilation level '${LEVEL}' (use one of 0123 for -O, or d for -O0 and debugging)" 1>&2 + exit 1 + ;; +esac + +case "${MODE}" in + freestanding|hosted) + ;; + *) + echo "ERROR: Unknown environment '${MODE}' (use 'freestanding' or 'hosted')" 1>&2 + exit 1 + ;; +esac + +case "${COMPILER}:${MODE}" in + gcc:freestanding) + CFLAGS+=" -ffreestanding -fno-stack-protector -nostdlib -emain -fno-omit-frame-pointer" + ;; + clang:freestanding) + CFLAGS+=" -ffreestanding -fno-stack-protector -nostdlib -Wl,-emain -fno-omit-frame-pointer" + ;; + pcc:freestanding) + CFLAGS+=" -ffreestanding -nostdlib -Wl,-emain" + ;; + tcc:freestanding) + CFLAGS+=" -fno-bultin -nostdlib" + MODULES+=("_start-stub.c") + ;; + *:hosted) + #~ CFLAGS+=" -lbsd" + ;; +esac + +echo "${COMPILER} ${CFLAGS} -o ${BINARY} ${MODULES[@]}" +if [ "${DEBUG}" = 1 ]; then + cat ${MODULES[@]} > "${BINARY}_tmp.c" + ${COMPILER} ${CFLAGS} -o ${BINARY} "${BINARY}_tmp.c" +else + cat ${MODULES[@]} | ${COMPILER} ${CFLAGS} -o ${BINARY} - +fi + -- cgit v1.2.3-54-g00ecf