scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 340c62a644c9d6a3844edd48c1681adaa4c2cad2
parent 2d3f8b02e98c3981afbd080d88a75e23bff2b2b4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 17 Sep 2017 01:03:24 +0200

Add automatic specific flags per system

At this moment we already have a dep target, so it is a very
good idea to use that target to do a bit more intelligent
configuration and populate some flags that depend of the
host system.

Diffstat:
MMakefile | 12+++++++++---
Mas/Makefile | 6++++--
Mcc1/Makefile | 7++++---
Mcc2/Makefile | 6++++--
Dconfig.mk | 49-------------------------------------------------
Aconfig.mk.def | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mdriver/Makefile | 3+++
Asystem.mk | 5+++++
8 files changed, 78 insertions(+), 59 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,8 +1,6 @@ # scc - Suckless C Compiler .POSIX: -include config.mk - DIRS = inc cc1 cc2 driver lib as FORALL = @set -e ;\ @@ -22,11 +20,19 @@ clean: rm -rf rootdir distclean: + touch config.mk # we need config.mk for makes in $DIRS $(FORALL) rm -f dep rm -rf rootdir + rm -f config.mk + +config.mk: + trap "rm -f $$.mk" 0 2 3; \ + (cat config.mk.def ;\ + sed -n '/^# '`uname`'/,/^$$/p' system.mk) > $$.mk && \ + mv $$.mk config.mk -dep: config.mk +dep: config.mk $(FORALL) touch dep diff --git a/as/Makefile b/as/Makefile @@ -6,6 +6,7 @@ include $(LIBDIR)/libdep.mk OBJ = main.o emit.o ins.o parser.o HDR = ../inc/scc.h as.h +MOREFLAGS = $(AS_CFLAGS) all: @@ -17,8 +18,9 @@ as: $(OBJ) $(LIBDIR)/libscc.a: $(LIB-OBJ) cd $(LIBDIR) && $(MAKE) -dep: +dep: ../config.mk Makefile ./gendep.sh $(TARGETS) + touch dep clean: rm -f *.o @@ -27,5 +29,5 @@ clean: rm -f as-* distclean: clean - rm -f makefile + rm -f makefile dep diff --git a/cc1/Makefile b/cc1/Makefile @@ -7,7 +7,7 @@ LIBDIR = ../lib/scc include ../config.mk include $(LIBDIR)/libdep.mk -MOREFLAGS = -I../inc/$(STD) +MOREFLAGS = -I../inc/$(STD) $(CC1_CFLAGS) OBJ = types.o decl.o lex.o error.o symbol.o main.o expr.o \ code.o stmt.o cpp.o fold.o init.o builtin.o @@ -23,8 +23,9 @@ cpp.o: stallman.msg $(LIBDIR)/libscc.a: $(LIB-OBJ) cd $(LIBDIR) && $(MAKE) -dep: +dep: ../config.mk Makefile ./gendep.sh $(TARGETS) + touch dep clean: rm -f *.o @@ -33,4 +34,4 @@ clean: distclean: clean rm -f makefile - + rm -f dep diff --git a/cc2/Makefile b/cc2/Makefile @@ -7,7 +7,7 @@ LIBDIR = ../lib/scc include ../config.mk include $(LIBDIR)/libdep.mk -MOREFLAGS = -I../inc/$(STD) +MOREFLAGS = -I../inc/$(STD) $(CC2_CFLAGS) OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/scc.h @@ -16,8 +16,9 @@ all: mkdir -p ../rootdir/libexec/scc/ cp cc2-* ../rootdir/libexec/scc/ -dep: +dep: ../config.mk Makefile MKQBE=${MKQBE} ./gendep.sh $(TARGETS) + touch dep $(LIBDIR)/libscc.a: $(LIB-OBJ) cd $(LIBDIR) && $(MAKE) @@ -35,4 +36,5 @@ clean: distclean: clean rm -f makefile + rm -f dep diff --git a/config.mk b/config.mk @@ -1,49 +0,0 @@ -# scc version -VERSION = 0.1 - -## Customize below to fit your system -# TARGETS is defined by a list of backend-arch-abi-sys. First -# element of the list becomes the default target - -TARGETS = amd64-sysv-linux-elf \ - i386-sysv-linux-elf \ - amd64-sysv-openbsd-elf - -# USEQBE selects QBE by default in the targets that support it -USEQBE = 1 - -#MKQBE enable build of qbe backends -MKQBE = 1 - -DRIVER = posix - -# Can be c89 or c99 -STD = c99 - -# paths -PREFIX = $(HOME) -MANPREFIX = $(PREFIX)/share/man - -# scc expects to be built by a C99 compiler -# if your system is not at least POSIX 2004 compatible, adjust CC -# CC = c99 -# AR = ar -AS = as - -# for Plan9 add -D_SUSV2_SOURCE -# for NetBSD add -D_ANSI_SOURCE -SCC_CFLAGS = $(MOREFLAGS) \ - -g \ - $(CFLAGS) - -SCC_LDFLAGS = -L$(LIBDIR)/ $(LDFLAGS) - -.s.o: - $(AS) $< -o $@ - -.c.o: - $(CC) $(SCC_CFLAGS) -o $@ -c $< - -.c: - $(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $< - diff --git a/config.mk.def b/config.mk.def @@ -0,0 +1,49 @@ +# scc version +VERSION = 0.1 + +## Customize below to fit your system +# TARGETS is defined by a list of backend-arch-abi-sys. First +# element of the list becomes the default target + +TARGETS = amd64-sysv-linux-elf \ + i386-sysv-linux-elf \ + amd64-sysv-openbsd-elf + +# USEQBE selects QBE by default in the targets that support it +USEQBE = 1 + +#MKQBE enable build of qbe backends +MKQBE = 1 + +DRIVER = posix + +# Can be c89 or c99 +STD = c99 + +# paths +PREFIX = $(HOME) +MANPREFIX = $(PREFIX)/share/man + +# scc expects to be built by a C99 compiler +# if your system is not at least POSIX 2004 compatible, adjust CC +# CC = c99 +# AR = ar +AS = as + +SCC_CFLAGS = $(MOREFLAGS) \ + $(SYSCFLAGS) \ + -g \ + $(CFLAGS) + +SCC_LDFLAGS = -L$(LIBDIR)/ $(LDFLAGS) + +.s.o: + $(AS) $< -o $@ + +.c.o: + $(CC) $(SCC_CFLAGS) -o $@ -c $< + +.c: + $(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $< + +# system specific flags diff --git a/driver/Makefile b/driver/Makefile @@ -1,5 +1,8 @@ .POSIX: +# fallback case if DRIVER isn't defined +DRIVER = posix + include ../config.mk all dep clean distclean: diff --git a/system.mk b/system.mk @@ -0,0 +1,5 @@ +# Plan9 +SYSCFLAGS = -D_SUSV2_SOURCE + +# NetBSD +AS_CFLAGS = -D_ANSI_SOURCE