scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit daa5c9259be0c5c4179098e954763e496812edab
parent f076da480f5ade0c7630cfc2795418c7166f7137
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 21 Nov 2021 08:27:08 +0100

libc: Add a gcc driver to the libc

Having a gcc driver helps to test the libc without worrying
about the code generated by scc. It also provides debug
symbols that can be kind while debugging.

Diffstat:
Msrc/libc/Makefile | 7+++++--
Asrc/libc/gcc-scc.sh | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/libc/execute/Makefile | 2+-
Dtests/libc/execute/cc.sh | 55-------------------------------------------------------
4 files changed, 78 insertions(+), 58 deletions(-)

diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -16,11 +16,14 @@ include rules.mk include objs/$(ARCH)-$(SYS).mk NODEP = 1 -TARGET = $(LIBC) +TARGET = $(LIBC) $(BINDIR)/gcc-scc all: $(DIRS) - $(MAKE) $(LIBC) + $(MAKE) $(TARGET) $(LIBC): $(OBJS) $(AR) $(PROJ_ARFLAGS) $(LIBC) $? $(RL) $(PROJ_RLFLAGS) $(LIBC) + +$(BINDIR)/gcc-scc: gcc-scc.sh + cp gcc-scc.sh $@ diff --git a/src/libc/gcc-scc.sh b/src/libc/gcc-scc.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +set -e + +for i +do + case "$i" in + -r) + root=$2 + shift 2 + ;; + -a) + abi=$2 + shift 2 + ;; + -s) + sys=$2 + shift 2 + ;; + -o) + out=$2 + shift 2 + ;; + -c) + onlycc=1; + shift + ;; + -*) + echo usage: cc.sh [-o outfile][-c][-r root][-a abi][-s sys] file + exit 1 + ;; + esac +done + +sys=${sys:-`uname | tr 'A-Z' 'a-z'`} +abi=${abi:-amd64} +out=${out:-a.out} +root=${root:-${SCCPREFIX:-`dirname $0`/..}} +inc=$root/include +arch_inc=$inc/bits/$abi +sys_inc=$inc/bits/$sys +sys_arch_inc=$inc/bits/$sys/$abi +lib=$root/lib/scc/${abi}-${sys} +crt=$root/lib/scc/${abi}-${sys}/crt.o +obj=${1%.c}.o +cc=${CROSS_COMPILE}gcc +ld=${CROSS_COMPILE}ld + +case `uname` in +OpenBSD) + nopie=-no-pie + ;; +esac + +includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc -I$sys_arch_inc" +cflags="-std=c99 -g -w -fno-pie -fno-stack-protector -ffreestanding -static" +ldflags="-g -z nodefaultlib -static -L$lib" + +if test ${onlycc:-0} -eq 1 +then + $cc $cflags $includes -c $@ +else + for i + do + case $i in + *.c) + $cc $cflags $includes -c $i + ;; + esac + done + $ld $ldflags $nopie `echo $@ | sed 's/\.c$/.o/g'` $crt -lc -lcrt -o $out +fi diff --git a/tests/libc/execute/Makefile b/tests/libc/execute/Makefile @@ -1,6 +1,6 @@ .POSIX: -CC = ./cc.sh +CC = gcc-scc .c: $(CC) $(CFLAGS) -o $@ $< diff --git a/tests/libc/execute/cc.sh b/tests/libc/execute/cc.sh @@ -1,55 +0,0 @@ -#!/bin/sh - -set -e - -for i -do - case "$i" in - -r) - root=$2 - shift 2 - ;; - -a) - abi=$2 - shift 2 - ;; - -s) - sys=$2 - shift 2 - ;; - -o) - out=$2 - shift 2 - ;; - -*) - echo usage: cc.sh [-o outfile][-r root][-a abi][-s sys] file - exit 1 - ;; - esac -done - -sys=${sys:-`uname | tr 'A-Z' 'a-z'`} -abi=${abi:-amd64} -out=${out:-a.out} -root=${root:-${SCCPREFIX:-../../..}} -inc=$root/include -arch_inc=$inc/bits/$abi -sys_inc=$inc/bits/$sys -lib=$root/lib/scc/${abi}-${sys} -crt=$root/lib/scc/${abi}-${sys}/crt.o -obj=${1%.c}.o -cc=${CROSS_COMPILE}gcc -ld=${CROSS_COMPILE}ld - -case `uname` in -OpenBSD) - nopie=-no-pie - ;; -esac - -includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc" -cflags="-std=c99 -g -w -fno-pie -fno-stack-protector -ffreestanding -static" -ldflags="-g -z nodefaultlib -static -L$lib" - -$cc $cflags $includes -c $1 -$ld $ldflags $nopie $obj $crt -lc -lcrt -o $out