scc

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

commit 9dc1194d1b8ec62ecde814fe61aa7c53e07ec091
parent 539711e6996064f0c0f82f9d0d059bb3ef3fba26
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Jan 2019 19:05:12 +0000

Separate target and toolchain configuration

Diffstat:
MMakefile | 21+++++++++++----------
Aconfig/amd64-darwin.mk | 4++++
Aconfig/amd64-dragonfly.mk | 4++++
Mconfig/amd64-linux.mk | 6------
Aconfig/amd64-netbsd.mk | 4++++
Aconfig/amd64-openbsd.mk | 4++++
Aconfig/arm32-linux.mk | 4++++
Aconfig/arm64-linux.mk | 4++++
Mconfig/i386-linux.mk | 9+++------
Aconfig/toolchain/clang.mk | 7+++++++
Aconfig/toolchain/gnu-darwin.mk | 3+++
Aconfig/toolchain/gnu.mk | 11+++++++++++
Aconfig/toolchain/pcc.mk | 3+++
Aconfig/toolchain/unix.mk | 5+++++
Mscripts/rules.mk | 19+++++++++++++++++--
Msrc/libc/Makefile.libc | 2+-
Msrc/libc/rules.mk | 1-
17 files changed, 85 insertions(+), 26 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,8 +3,10 @@ PROJECTDIR = . include $(PROJECTDIR)/scripts/rules.mk +STD = c99 +PREFIX = $(PWD)/$(PROJECTDIR)/root +MANPREFIX = $(PREFIX)/share/man DIRS = src include/scc/scc tests -ENV = $(SCRIPTDIR)/env.sh all: src @@ -14,28 +16,27 @@ dirs: $(SCRIPTDIR)/libc-proto xargs mkdir -p < $(SCRIPTDIR)/libc-proto touch dirs -$(DIRS): $(ENV) FORCE - +@. $(ENV) && cd $@ && $(MAKE) +$(DIRS): $(ENVIRON) FORCE + +@. $(ENVIRON) && cd $@ && $(MAKE) -$(ENV): +$(ENVIRON): @rm -f $@; \ trap 'r=$?;rm -f $$$$.tmp;exit $r' EXIT HUP INT QUIT TERM; \ echo PATH=$$PATH:$$PWD/$(SCRIPTDIR):. > $$$$.tmp && \ echo NM=\"$(NM)\" >> $$$$.tmp && \ echo AR=\"$(AR)\" >> $$$$.tmp && \ echo RL=\"$(RL)\" >> $$$$.tmp && \ + echo STD=\"$(STD)\" >> $$$$.tmp && \ + echo ARFLAGS=\"$(ARFLAGS)\" >> $$$$.tmp && \ echo RLFLAGS=\"$(RLFLAGS)\" >> $$$$.tmp && \ - echo export PATH RLFLAGS NM AR RL >> $$$$.tmp && \ + echo export PATH STD ARFLAGS RLFLAGS NM AR RL >> $$$$.tmp && \ mv $$$$.tmp $@ dep: $(FORALL) -clean: +clean: $(ENVIRON) $(FORALL) - rm -rf lib bin libexec dirs $(ENV) - -distclean: clean - +@cd include/scc/scc && $(MAKE) distclean + rm -rf lib bin libexec dirs $(ENVIRON) tests: all diff --git a/config/amd64-darwin.mk b/config/amd64-darwin.mk @@ -0,0 +1,4 @@ +ARCH = amd64 +SYS = darwin +ABI = amd64-darwin +DRIVER = posix diff --git a/config/amd64-dragonfly.mk b/config/amd64-dragonfly.mk @@ -0,0 +1,4 @@ +ARCH = amd64 +SYS = dragonfly +ABI = amd64-posix +DRIVER = posix diff --git a/config/amd64-linux.mk b/config/amd64-linux.mk @@ -2,9 +2,3 @@ ARCH = amd64 SYS = linux ABI = amd64-posix DRIVER = posix -STD = c99 -PREFIX = $(PWD)/$(PROJECTDIR)/root -MANPREFIX = $(PREFIX)/share/man -AS = as -RANLIB = ranlib -NM = nm diff --git a/config/amd64-netbsd.mk b/config/amd64-netbsd.mk @@ -0,0 +1,4 @@ +ARCH = amd64 +SYS = netbsd +ABI = amd64-posix +DRIVER = posix diff --git a/config/amd64-openbsd.mk b/config/amd64-openbsd.mk @@ -0,0 +1,4 @@ +ARCH = amd64 +SYS = openbsd +ABI = amd64-posix +DRIVER = posix diff --git a/config/arm32-linux.mk b/config/arm32-linux.mk @@ -0,0 +1,4 @@ +ARCH = arm32 +SYS = linux +ABI = arm32-posix +DRIVER = posix diff --git a/config/arm64-linux.mk b/config/arm64-linux.mk @@ -0,0 +1,4 @@ +ARCH = arm64 +SYS = linux +ABI = arm64-posix +DRIVER = posix diff --git a/config/i386-linux.mk b/config/i386-linux.mk @@ -1,7 +1,4 @@ +ARCH = i386 +SYS = linux +ABI = amd64-posix DRIVER = posix -STD = c99 -PREFIX = $(PWD)/$(PROJECTDIR)/root -MANPREFIX = $(PREFIX)/share/man -AS = as -RANLIB = ranlib -NM = nm diff --git a/config/toolchain/clang.mk b/config/toolchain/clang.mk @@ -0,0 +1,7 @@ +include $(PROJECTDIR)/config/toolchain/gnu.mk + +COMP = clang +ASM = clang +LINKER = ld.lld +OBJCOPY = llvm-objcopy +OBJDUMP = llvm-objdump diff --git a/config/toolchain/gnu-darwin.mk b/config/toolchain/gnu-darwin.mk @@ -0,0 +1,3 @@ +include $(PROJECTDIR)/config/toolchain/gnu.mk + +RANLIBFLAGS = -c diff --git a/config/toolchain/gnu.mk b/config/toolchain/gnu.mk @@ -0,0 +1,11 @@ +TOOLCFLAGS = -std=c99 + +COMP = gcc +ASM = as +LINKER = ld +RANLIB = ranlib +ARCHIVE = ar + +ARFLAGS = -U +NOPIE_CFLAGS = -nopie +NOPIE_LDFLAGS = -nopie diff --git a/config/toolchain/pcc.mk b/config/toolchain/pcc.mk @@ -0,0 +1,3 @@ +include $(PROJECTDIR)/config/toolchain/gnu.mk + +COMP = pcc diff --git a/config/toolchain/unix.mk b/config/toolchain/unix.mk @@ -0,0 +1,5 @@ +COMP = c99 +ASM = as +LINKER = ld +RANLIB = ranlib +ARCHIVE = ar diff --git a/scripts/rules.mk b/scripts/rules.mk @@ -1,5 +1,7 @@ CONF=amd64-linux +TOOL=unix include $(PROJECTDIR)/config/$(CONF).mk +include $(PROJECTDIR)/config/toolchain/$(TOOL).mk LIBDIR = $(PROJECTDIR)/lib/scc SCRIPTDIR = $(PROJECTDIR)/scripts @@ -9,26 +11,39 @@ BINDIR = $(PROJECTDIR)/bin LIBEXEC = $(PROJECTDIR)/libexec/scc CRTDIR = $(PROJECTDIR)/lib/scc LIBCDIR = $(CRTDIR)/$(ARCH)-$(SYS)/ +ENVIRON = $(SCRIPTDIR)/env.sh INCLUDE = -I$(INCDIR)/scc \ -RL = $(RANLIB) +CC = $(CROSS_COMPILE)$(COMP) +AS = $(CROSS_COMPILE)$(ASM) +LD = $(CROSS_COMPILE)$(LINKER) +RL = $(CROSS_COMPILE)$(RANLIB) +AR = $(CROSS_COMPILE)$(ARCHIVE) SCC_CFLAGS = $(MORECFLAGS) \ + $(TOOLCFLAGS) \ $(SYSCFLAGS) \ $(INCLUDE) \ -g \ $(CFLAGS) SCC_LDFLAGS = $(MORELFLAGS) \ + $(TOOLLDFLAGS) \ $(SYSLDFLAGS) \ -L$(LIBDIR) \ -g \ $(LDFLAGS) +SCC_ASFLAGS = $(MOREASFLAGS) \ + $(TOOLASFLAGS) \ + $(SYSASFLAGS) \ + $(ASFLAGS) + # helper macro to run over all the directories FORALL = +@set -e ;\ pwd=$$PWD; \ + . $(ENVIRON); \ for i in $(DIRS); \ do \ cd $$i; \ @@ -40,7 +55,7 @@ FORALL = +@set -e ;\ $(CC) $(SCC_LDFLAGS) -o $@ $< $(LIBS) .s.o: - $(AS) $< -o $@ + $(AS) $(SCC_ASFLAGS) $< -o $@ .c.o: $(CC) $(SCC_CFLAGS) -o $@ -c $< diff --git a/src/libc/Makefile.libc b/src/libc/Makefile.libc @@ -4,7 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk include rules.mk include objlst.mk -TARGET = $(LIBDIR)/libc.a +TARGET = $(LIBCDIR)/libc.a all: $(TARGET) diff --git a/src/libc/rules.mk b/src/libc/rules.mk @@ -1,5 +1,4 @@ INCLUDE = -I$(INCDIR) -I$(INCDIR)/bits/$(SYS) -I$(INCDIR)/bits/$(ARCH) -MORECFLAGS = -w SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h