shithub: scc

Download patch

ref: 9c0b13d8c0966d5e1eaaf878c40334f88fba7225
parent: e410bad0b6e2d7f231b821aced3eae16888aca38
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 5 09:23:33 EST 2022

scc: Use CONF as default configuration

The driver was using the first element of SYSLST as default configuration
which is not very intuitive if you want to use scc as a system compiler.
This change makes CONF the default configuration and it adds auto detection
in the all target. In case of needing a different default it can be obtained
compiling scc with:

	make CONF=xxxxx toolchain

--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
 NODEP = 1
 
 all:
-	+@PREFIX=$(PREFIX) $(MAKE) `$(SCRIPTDIR)/config` toolchain
+	+@PREFIX=$(PREFIX) $(MAKE) `$(SCRIPTDIR)/config -c` toolchain
 	+@$(MAKE) `$(SCRIPTDIR)/config` `uname -m`
 
 install:
@@ -90,11 +90,16 @@
 uninstall-arm64:
 	$(SCRIPTDIR)/uninstall -p $(SCRIPTDIR)/proto.arm64 $(ROOT)
 
-toolchain: dirs src
-libc: dirs src/libc
-libcrt: dirs src/libcrt
-src: include/scc/scc
+toolchain: src
+libc: src/libc
+libcrt: src/libcrt
+
 tests: all
+src: include/scc/scc
+
+src: dirs
+src/libc: dirs
+src/libcrt: dirs
 
 dirs: $(SCRIPTDIR)/libc-dirs
 	xargs mkdir -p < $(SCRIPTDIR)/libc-dirs
--- a/scripts/build/conf/amd64-darwin.mk
+++ b/scripts/build/conf/amd64-darwin.mk
@@ -1,4 +1,5 @@
 ARCH = amd64
 SYS = darwin
 ABI = amd64-darwin
+FORMAT = elf
 O = 6d
--- a/scripts/build/conf/amd64-dragonfly.mk
+++ b/scripts/build/conf/amd64-dragonfly.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/amd64-posix.mk
 
 SYS = dragonfly
+FORMAT = elf
--- a/scripts/build/conf/amd64-linux.mk
+++ b/scripts/build/conf/amd64-linux.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/amd64-posix.mk
 
 SYS  = linux
+FORMAT = elf
--- a/scripts/build/conf/amd64-netbsd.mk
+++ b/scripts/build/conf/amd64-netbsd.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/amd64-posix.mk
 
 SYS = netbsd
+FORMAT = elf
--- a/scripts/build/conf/amd64-openbsd.mk
+++ b/scripts/build/conf/amd64-openbsd.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/amd64-posix.mk
 
 SYS = openbsd
+FORMAT = elf
--- a/scripts/build/conf/arm32-linux.mk
+++ b/scripts/build/conf/arm32-linux.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/arm32-posix.mk
 
 SYS = linux
+FORMAT = elf
--- a/scripts/build/conf/arm64-linux.mk
+++ b/scripts/build/conf/arm64-linux.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/arm64-posix.mk
 
 SYS = linux
+FORMAT = elf
--- a/scripts/build/conf/ppc32-linux.mk
+++ b/scripts/build/conf/ppc32-linux.mk
@@ -1,3 +1,4 @@
 include $(BUILDDIR)/conf/ppc32-posix.mk
 
 SYS = linux
+FORMAT = elf
--- a/scripts/config
+++ b/scripts/config
@@ -18,3 +18,27 @@
 	echo HOST=plan9
 	;;
 esac
+
+
+for i
+do
+	case $1 in
+	-c)
+
+		mach=`uname -m`
+
+		case $mach in
+		amd64|x86_64)
+			mach=amd64
+			;;
+		esac
+
+		sys=`uname -s | tr 'A-Z' 'a-z'`
+		echo CONF=$mach-$sys
+		;;
+	*)
+		echo usage: config [-c] >&2
+		exit 1
+		;;
+	esac
+done
--- a/src/cmd/cc/posix/Makefile
+++ b/src/cmd/cc/posix/Makefile
@@ -3,8 +3,10 @@
 PROJECTDIR = ../../../..
 include $(PROJECTDIR)/scripts/rules.mk
 
-# SYSLST is a list of backend-arch-abi-sys. First
-# element of the list becomes the default target
+# SYSLST is a list of arch-abi-sys-format.
+# By default the driver uses the configuration
+# inhered from the environment, that in a normal
+# build is derived from the host configuration.
 
 SYSLST  =\
 	amd64-sysv-linux-elf\
@@ -31,7 +33,14 @@
 	chmod +x $@
 
 config.h:
-	PREFIX=$(PREFIX) ./mkconf $(SYSLST)
+	set -e;\
+	rm -f $@;\
+	trap "rm -f $$$$.h" EXIT QUIT HUP TERM;\
+	(echo '#define PREFIX "$(PREFIX)"';\
+	 echo '#define ARCH "$(ARCH)"';\
+	 echo '#define SYS  "$(SYS)"';\
+	 echo '#define ABI  "$(ABI)"';\
+	 echo '#define FORMAT "$(FORMAT)"') > $$$$.h && mv $$$$.h $@
 
 clean:
 	rm -f scc scpp *.o
--- a/src/cmd/cc/posix/mkconf
+++ /dev/null
@@ -1,14 +1,0 @@
-#!/bin/sh
-
-set -e
-
-rm -f config.h
-trap "rm -f $$.h" 0 2 3
-
-echo $@ |
-(IFS='- 	' read arch abi sys format r
-echo \#define PREFIX \"${PREFIX-$HOME}\"
-echo \#define ARCH \"$arch\"
-echo \#define SYS  \"$sys\"
-echo \#define ABI  \"$abi\"
-echo \#define FORMAT \"$format\") > $$.h && mv $$.h config.h