shithub: scc

Download patch

ref: 9649f784e703493c96c77c0aef192554d77ff48b
parent: f9ca0be9d9c62fdb419256b4c7c56e04c3ad52da
parent: 95651e8ba1805242ac3cbbccce37b3cdabe16891
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Feb 17 04:05:27 EST 2018

Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc

--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,9 @@
 # scc - Suckless C Compiler
+.POSIX:
 
-include config.mk.def
+PROJECTDIR = .
 
-.POSIX:
+include rules.mk
 
 DIRS  = inc cc1 cc2 driver lib as ar nm objdump
 
@@ -19,12 +20,6 @@
 	$(FORALL)
 	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
 	$(FORALL)
--- a/ar/Makefile
+++ b/ar/Makefile
@@ -1,7 +1,8 @@
 .POSIX:
 
-LIBDIR    = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
 OBJ       = main.o $(DRIVER)/stat.c
@@ -8,13 +9,13 @@
 MOREFLAGS = -I$(DRIVER)
 
 all: ar-$(DRIVER)
-	mkdir -p ../../rootdir/bin
-	cp ar-$(DRIVER) ../rootdir/bin/ar
+	mkdir -p $(PROJECTDIR)/rootdir/bin
+	cp ar-$(DRIVER) $(PROJECTDIR)/rootdir/bin/ar
 
 ar-$(DRIVER): $(OBJ) $(LIBDIR)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
-main.o: ../inc/scc.h ../inc/ar.h
+main.o: $(PROJECTDIR)/inc/scc.h $(PROJECTDIR)/inc/ar.h
 
 $(DRIVER)/stat.o: $(DRIVER)/stat.h
 
--- a/as/Makefile
+++ b/as/Makefile
@@ -1,12 +1,13 @@
 .POSIX:
 
-LIBDIR  = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
 OBJ = main.o symbol.o ins.o parser.o expr.o myro.o
-HDR = ../inc/scc.h as.h
-MOREFLAGS = -I../inc/$(STD) $(AS_CFLAGS)
+HDR = $(PROJECTDIR)/inc/scc.h as.h
+MOREFLAGS = -I$(PROJECTDIR)/inc/$(STD) $(AS_CFLAGS)
 
 all:
 
@@ -15,7 +16,7 @@
 as: $(OBJ)
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
-myro.o: ../inc/myro.h
+myro.o: $(PROJECTDIR)/inc/myro.h
 
 $(LIBDIR)/libscc.a: $(LIB-OBJ)
 	+cd $(LIBDIR) && $(MAKE)
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -3,20 +3,22 @@
 # Makefile is only used as a template for makefile.
 # If you modify Makefile remember to run make dep
 
-LIBDIR    = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
-MOREFLAGS = -I../inc/$(STD) $(CC1_CFLAGS)
+MOREFLAGS = -I$(PROJECTDIR)/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
 
-HDR = cc1.h ../inc/scc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h
+HDR = cc1.h $(PROJECTDIR)/inc/scc.h $(PROJECTDIR)/inc/$(STD)/cstd.h $(PROJECTDIR)/inc/sysincludes.h
 
 all:
-	mkdir -p ../rootdir/libexec/scc/
-	cp cc1-* ../rootdir/libexec/scc/
+	mkdir -p $(PROJECTDIR)/rootdir/libexec/scc/
+	cp cc1-* $(PROJECTDIR)/rootdir/libexec/scc/
 
 $(LIBDIR)/libscc.a: $(LIB-OBJ)
 	+cd $(LIBDIR) && $(MAKE)
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -3,18 +3,19 @@
 # Makefile is only used as a template for makefile.
 # If you modify Makefile remember to run make dep
 
-LIBDIR    = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
-MOREFLAGS = -I../inc/$(STD) $(CC2_CFLAGS)
+MOREFLAGS = -I$(PROJECTDIR)/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
+HDR = cc2.h $(PROJECTDIR)/inc/$(STD)/cstd.h $(PROJECTDIR)/inc/scc.h
 
 all:
-	mkdir -p ../rootdir/libexec/scc/
-	cp cc2-* ../rootdir/libexec/scc/
+	mkdir -p $(PROJECTDIR)/rootdir/libexec/scc/
+	cp cc2-* $(PROJECTDIR)/rootdir/libexec/scc/
 
 dep:
 	MKQBE=${MKQBE} ./gendep.sh $(TARGETS)
--- a/config.mk.def
+++ b/config.mk.def
@@ -30,31 +30,3 @@
 # CC = c99
 # AR = ar
 AS = as
-
-SCC_CFLAGS = $(MOREFLAGS) \
-             $(SYSCFLAGS) \
-             -g \
-             $(CFLAGS)
-
-SCC_LDFLAGS = -L$(LIBDIR)/ -g $(LDFLAGS)
-
-.s.o:
-	$(AS) $< -o $@
-
-.c.o:
-	$(CC) $(SCC_CFLAGS) -o $@ -c $<
-
-.c:
-	$(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $<
-
-# helper macro to run over all the directories
-FORALL = +@set -e ;\
-	pwd=$$PWD; \
-	for i in $(DIRS); \
-	do \
-		cd $$i; \
-		$(MAKE) $@; \
-		cd $$pwd; \
-	done
-
-# system specific flags
--- /dev/null
+++ b/configure
@@ -1,0 +1,15 @@
+#!/bin/sh
+
+if [ ! -e config.mk ]
+then
+	printf '%s\n' 'Generating config.mk from defaults...' \
+	              '(edit it for customization and then re-run this script)'
+	trap "rm -f $$.mk" 0 2 3; \
+	(cat config.mk.def ;\
+	sed -n '/^# '`uname`'/,/^$$/p' system.mk) > $$.mk && \
+	mv $$.mk config.mk
+fi
+
+printf 'Generating arch-dependant build files...\n'
+make dep > /dev/null && \
+printf 'You can now install scc with “make install”\n'
--- a/driver/Makefile
+++ b/driver/Makefile
@@ -1,9 +1,10 @@
 .POSIX:
 
+PROJECTDIR = ..
 # fallback case if DRIVER isn't defined
 DRIVER = posix
 
-include ../config.mk
+include $(PROJECTDIR)/rules.mk
 
 all dep clean distclean:
 	+cd $(DRIVER) && $(MAKE) $@
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -1,19 +1,20 @@
 .POSIX:
 
-LIBDIR    = ../../lib/scc
-include ../../config.mk
+PROJECTDIR = ../..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
 OBJ = scc.o
 HDR = config.h \
-      ../../inc/scc.h \
-      ../../inc/arg.h \
-      ../../inc/syslibs.h \
-      ../../inc/ldflags.h
+      $(PROJECTDIR)/inc/scc.h \
+      $(PROJECTDIR)/inc/arg.h \
+      $(PROJECTDIR)/inc/syslibs.h \
+      $(PROJECTDIR)/inc/ldflags.h
 
 all: scc cpp
-	mkdir -p ../../rootdir/bin
-	cp scc cpp ../../rootdir/bin/
+	mkdir -p $(PROJECTDIR)/rootdir/bin
+	cp scc cpp $(PROJECTDIR)/rootdir/bin/
 
 dep:
 	PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./gendep.sh $(TARGETS)
--- a/inc/Makefile
+++ b/inc/Makefile
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../config.mk
+PROJECTDIR = ..
+
+include $(PROJECTDIR)/rules.mk
 
 HDR = ldflags.h sysincludes.h syslibs.h
 
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../config.mk
+PROJECTDIR = ..
+
+include $(PROJECTDIR)/rules.mk
 
 DIRS = scc
 
--- a/lib/c/target/Makefile
+++ b/lib/c/target/Makefile
@@ -1,5 +1,7 @@
 
-include ../../../config.mk
+PROJECTDIR = ../../..
+
+include $(PROJECTDIR)/rules.mk
 
 DIRS = $(TARGETS)
 
--- a/lib/c/target/amd64-sysv-linux-elf/Makefile
+++ b/lib/c/target/amd64-sysv-linux-elf/Makefile
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../../../../config.mk
+PROJECTDIR = ../../../..
+
+include $(PROJECTDIR)/rules.mk
 include ../objlst.mk
 include ../common.mk
 
--- a/lib/c/target/amd64-sysv-openbsd-elf/Makefile
+++ b/lib/c/target/amd64-sysv-openbsd-elf/Makefile
@@ -1,5 +1,7 @@
 .POSIX:
 
-include ../../../../config.mk
+PROJECTDIR = ../../../..
+
+include $(PROJECTDIR)/rules.mk
 include ../objlst.mk
 include ../common.mk
--- a/lib/c/target/i386-sysv-linux-elf/Makefile
+++ b/lib/c/target/i386-sysv-linux-elf/Makefile
@@ -1,5 +1,7 @@
 .POSIX:
 
-include ../../../../config.mk
+PROJECTDIR = ../../../..
+
+include $(PROJECTDIR)/rules.mk
 include ../objlst.mk
 include ../common.mk
--- a/lib/c/target/z80-scc-none-none/Makefile
+++ b/lib/c/target/z80-scc-none-none/Makefile
@@ -1,5 +1,7 @@
 .POSIX:
 
-include ../../../../config.mk
+PROJECTDIR = ../../../..
+
+include $(PROJECTDIR)/rules.mk
 include ../objlst.mk
 include ../common.mk
--- a/lib/crt/Makefile
+++ b/lib/crt/Makefile
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../../config.mk
+PROJECTDIR = ../..
+
+include $(PROJECTDIR)/rules.mk
 
 all:
 
--- a/lib/scc/Makefile
+++ b/lib/scc/Makefile
@@ -1,14 +1,15 @@
 .POSIX:
 
-LIBDIR = ./
-include ../../config.mk
+PROJECTDIR = ../..
+LIBDIR = .
+include $(PROJECTDIR)/rules.mk
 include libdep.mk
 
 all: libscc.a
 
-$(LIB-OBJ): ../../inc/scc.h
-$(LIBDIR)/wmyro.o: ../../inc/myro.h
-$(LIBDIR)/rmyro.o: ../../inc/myro.h
+$(LIB-OBJ): $(PROJECTDIR)/inc/scc.h
+$(LIBDIR)/wmyro.o: $(PROJECTDIR)/inc/myro.h
+$(LIBDIR)/rmyro.o: $(PROJECTDIR)/inc/myro.h
 
 libscc.a: $(LIB-OBJ)
 	ar $(ARFLAGS) $@ $?
--- a/lib/sys/Makefile
+++ b/lib/sys/Makefile
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../../config.mk
+PROJECTDIR = ../..
+
+include $(PROJECTDIR)/rules.mk
 
 all clean distclean:
 	+@pwd=$$PWD ;\
--- a/lib/sys/common.mk
+++ b/lib/sys/common.mk
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../../../config.mk
+PROJECTDIR = ../../..
+
+include $(PROJECTDIR)/rules.mk
 
 all clean distclean: system.mk
 	+$(MAKE) ABI=$(ABI) -f ../libsys.mk $@
--- a/lib/sys/libsys.mk
+++ b/lib/sys/libsys.mk
@@ -1,6 +1,8 @@
 .POSIX:
 
-include ../../../config.mk
+PROJECTDIR = ../../..
+
+include $(PROJECTDIR)/rules.mk
 include system.mk
 
 ASM = $(OBJ:.o=.s)
--- a/nm/Makefile
+++ b/nm/Makefile
@@ -1,7 +1,8 @@
 .POSIX:
 
-LIBDIR    = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
 OBJ       = main.o
@@ -11,7 +12,7 @@
 nm: $(OBJ) $(LIBDIR)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
-main.o: ../inc/scc.h ../inc/ar.h ../inc/myro.h
+main.o: $(PROJECTDIR)/inc/scc.h $(PROJECTDIR)/inc/ar.h $(PROJECTDIR)/inc/myro.h
 
 $(LIBDIR)/libscc.a: $(LIB-OBJ)
 	+cd $(LIBDIR) && $(MAKE)
--- a/objdump/Makefile
+++ b/objdump/Makefile
@@ -1,7 +1,8 @@
 .POSIX:
 
-LIBDIR    = ../lib/scc
-include ../config.mk
+PROJECTDIR = ..
+LIBDIR = $(PROJECTDIR)/lib/scc
+include $(PROJECTDIR)/rules.mk
 include $(LIBDIR)/libdep.mk
 
 OBJ       = main.o 
@@ -11,7 +12,7 @@
 objdump: $(OBJ) $(LIBDIR)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
-main.o: ../inc/scc.h ../inc/myro.h ../inc/arg.h
+main.o: $(PROJECTDIR)/inc/scc.h $(PROJECTDIR)/inc/myro.h $(PROJECTDIR)/inc/arg.h
 
 $(LIBDIR)/libscc.a: $(LIB-OBJ)
 	+cd $(LIBDIR) && $(MAKE)
--- /dev/null
+++ b/rules.mk
@@ -1,0 +1,27 @@
+include $(PROJECTDIR)/config.mk
+
+SCC_CFLAGS = $(MOREFLAGS) \
+             $(SYSCFLAGS) \
+             -g \
+             $(CFLAGS)
+
+SCC_LDFLAGS = -L$(LIBDIR) -g $(LDFLAGS)
+
+# helper macro to run over all the directories
+FORALL = +@set -e ;\
+	pwd=$$PWD; \
+	for i in $(DIRS); \
+	do \
+		cd $$i; \
+		$(MAKE) $@; \
+		cd $$pwd; \
+	done
+
+.s.o:
+	$(AS) $< -o $@
+
+.c.o:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.c:
+	$(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $<