shithub: scc

Download patch

ref: dc9b022343d45753671f0382c9699aea2584875c
parent: a4b082e87a11db4311b8b84224abfdb9dbad297a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Sep 16 21:03:24 EDT 2017

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.

--- 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 @@
 	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
 
-dep: 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
 	$(FORALL)
 	touch dep
 
--- a/as/Makefile
+++ b/as/Makefile
@@ -6,6 +6,7 @@
 
 OBJ = main.o emit.o ins.o parser.o
 HDR = ../inc/scc.h as.h
+MOREFLAGS = $(AS_CFLAGS)
 
 all:
 
@@ -17,8 +18,9 @@
 $(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 @@
 	rm -f as-*
 
 distclean: clean
-	rm -f makefile
+	rm -f makefile dep
 
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -7,7 +7,7 @@
 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 @@
 $(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 @@
 
 distclean: clean
 	rm -f makefile
-
+	rm -f dep
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -7,7 +7,7 @@
 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 @@
 	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 @@
 
 distclean: clean
 	rm -f makefile
+	rm -f dep
 
--- a/config.mk
+++ /dev/null
@@ -1,49 +1,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 $@ $<
-
--- /dev/null
+++ b/config.mk.def
@@ -1,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
--- 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:
--- /dev/null
+++ b/system.mk
@@ -1,0 +1,5 @@
+# Plan9
+SYSCFLAGS = -D_SUSV2_SOURCE
+
+# NetBSD
+AS_CFLAGS = -D_ANSI_SOURCE