shithub: scc

Download patch

ref: de4795d333b7ac4c514288683e30afb1199f0dd7
parent: aeb36d2e67af0edb760d3c851b136ad811f4cf9c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Nov 21 03:27:08 EST 2021

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.

--- a/src/libc/Makefile
+++ b/src/libc/Makefile
@@ -16,11 +16,14 @@
 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 $@
--- /dev/null
+++ b/src/libc/gcc-scc.sh
@@ -1,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
--- 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 $@ $<
--- a/tests/libc/execute/cc.sh
+++ /dev/null
@@ -1,55 +1,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