shithub: scc

Download patch

ref: c4e18492e995b3eeefe33495b7e7822a700c18d8
parent: 6fe4bfa800433e39ea7f70645103e5dccdd9411d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 17 03:01:24 EDT 2018

Add rules related to rootdir

The Makefiles were copying blindly to rootdir, and with this
version all the Makefiles have the correct dependencies and
the copies are done only when it is actually needed.

--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,6 @@
 
 clean:
 	$(FORALL)
-	rm -rf rootdir
 
 distclean:
 	touch config.mk    # we need config.mk for makes in $DIRS
--- a/ar/Makefile
+++ b/ar/Makefile
@@ -7,15 +7,18 @@
 OBJ       = main.o $(DRIVER)/driver.o
 MOREFLAGS = -I$(DRIVER)
 
-all: ar-$(DRIVER)
-	cp ar-$(DRIVER) $(PROJECTDIR)/rootdir/bin/ar
+all: $(BINDIR)/ar
 
+$(BINDIR)/ar: ar-$(DRIVER)
+	cp ar-$(DRIVER) $@
+
 ar-$(DRIVER): $(OBJ) $(LIBSCC)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
 dep:
 	$(PROJECTDIR)/mkdep.sh
+
 clean:
-	rm -f ar-* *.o $(DRIVER)/*.o
+	rm -f ar-* *.o $(DRIVER)/*.o $(BINDIR)/ar
 
 include deps.mk
--- a/as/Makefile
+++ b/as/Makefile
@@ -6,9 +6,10 @@
 
 OBJ = main.o symbol.o ins.o parser.o expr.o myro.o
 MOREFLAGS = -I$(INCDIR)/$(STD) $(AS_CFLAGS)
+TARGETS = $(LIBEXEC)/as-amd64 $(LIBEXEC)/as-i386 \
+          $(LIBEXEC)/as-i286 $(LIBEXEC)/as-z80
 
-all: as-amd64 as-i386 as-i286 as-z80
-	cp as-* $(PROJECTDIR)/rootdir/bin
+all: $(TARGETS)
 
 dep:
 	$(PROJECTDIR)/mkdep.sh
@@ -17,6 +18,7 @@
 	rm -f *.o target/*/*.o
 	rm -f target/*/*tbl.c
 	rm -f as-*
+	rm -f $(TARGETS)
 
 include target/amd64.mk
 include target/i386.mk
--- a/as/target/amd64.mk
+++ b/as/target/amd64.mk
@@ -1,3 +1,7 @@
+
+$(LIBEXEC)/as-amd64: as-amd64
+	cp as-amd64 $@
+
 AMD64_OBJ = $(OBJ) target/x86/amd64tbl.o target/x86/amd64.o target/x86/ins.o
 
 target/x86/amd64tbl.c: gentbl.awk target/x86/x86.dat target/x86/rules.dat
--- a/as/target/i286.mk
+++ b/as/target/i286.mk
@@ -1,4 +1,7 @@
 
+$(LIBEXEC)/as-i286: as-i286
+	cp as-i286 $@
+
 I286_OBJ = $(OBJ) target/x86/i286tbl.o target/x86/i286.o target/x86/ins.o
 
 target/x86/i286tbl.c: gentbl.awk target/x86/x86.dat target/x86/rules.dat
--- a/as/target/i386.mk
+++ b/as/target/i386.mk
@@ -1,3 +1,7 @@
+
+$(LIBEXEC)/as-i386: as-i386
+	cp as-i386 $@
+
 I386_OBJ = $(OBJ) target/x86/i386tbl.o target/x86/i386.o target/x86/ins.o
 
 target/x86/i386tbl.c: gentbl.awk target/x86/x86.dat target/x86/rules.dat
--- a/as/target/z80.mk
+++ b/as/target/z80.mk
@@ -1,3 +1,7 @@
+
+$(LIBEXEC)/as-z80: as-z80
+	cp as-z80 $@
+
 Z80_OBJ = $(OBJ) target/x80/z80tbl.o target/x80/z80.o target/x80/ins.o
 
 target/x80/z80tbl.c: gentbl.awk target/x80/x80.dat target/x80/rules.dat
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -10,9 +10,11 @@
 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
 
-all:
-	cp cc1-* $(PROJECTDIR)/rootdir/libexec/scc/
+TARGETS   = $(LIBEXEC)/cc1-amd64-sysv $(LIBEXEC)/cc1-arm64-sysv \
+            $(LIBEXEC)/cc1-i386-sysv  $(LIBEXEC)/cc1-z80-scc
 
+all: $(TARGETS)
+
 dep:
 	$(PROJECTDIR)/mkdep.sh
 
@@ -20,6 +22,7 @@
 	rm -f *.o
 	rm -f target/*/*.o
 	rm -f cc1-*
+	rm -f $(TARGETS)
 
 include target/amd64-sysv/arch.mk
 include target/arm64-sysv/arch.mk
--- a/cc1/target/amd64-sysv/arch.mk
+++ b/cc1/target/amd64-sysv/arch.mk
@@ -1,4 +1,6 @@
-all: cc1-amd64-sysv
+
+$(LIBEXEC)/cc1-amd64-sysv: cc1-amd64-sysv
+	cp cc1-amd64-sysv $@
 
 OBJ-amd64-sysv= $(OBJ)  target/amd64-sysv/arch.o
 
--- a/cc1/target/arm64-sysv/arch.mk
+++ b/cc1/target/arm64-sysv/arch.mk
@@ -1,4 +1,6 @@
-all: cc1-arm64-sysv
+
+$(LIBEXEC)/cc1-arm64-sysv: cc1-arm64-sysv
+	cp cc1-arm64-sysv $@
 
 OBJ-arm64-sysv= $(OBJ)  target/arm64-sysv/arch.o
 
--- a/cc1/target/i386-sysv/arch.mk
+++ b/cc1/target/i386-sysv/arch.mk
@@ -1,5 +1,6 @@
 
-all: cc1-i386-sysv
+$(LIBEXEC)/cc1-i386-sysv: cc1-i386-sysv
+	cp cc1-i386-sysv $@
 
 OBJ-i386-sysv= $(OBJ)  target/i386-sysv/arch.o
 
--- a/cc1/target/z80-scc/arch.mk
+++ b/cc1/target/z80-scc/arch.mk
@@ -1,7 +1,8 @@
 
-all: cc1-z80-scc
+$(LIBEXEC)/cc1-z80-scc: cc1-z80-scc
+	cp cc1-z80-scc $@
 
-OBJ-z80-scc= $(OBJ)  target/z80-scc/arch.o
+OBJ-z80-scc= $(OBJ) target/z80-scc/arch.o
 
 cc1-z80-scc: $(OBJ-z80-scc) $(LIBSCC)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ-z80-scc) -lscc -o $@
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -8,14 +8,14 @@
 
 OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o
 
-all:
-	cp cc2-* $(PROJECTDIR)/rootdir/libexec/scc/
+TARGETS  = $(LIBEXEC)/cc2-amd64-sysv  $(LIBEXEC)/cc2-i386-sysv \
+           $(LIBEXEC)/cc2-qbe_amd64-sysv $(LIBEXEC)/cc2-z80-scc
 
+all: $(TARGETS)
+
 dep:
 	$(PROJECTDIR)/mkdep.sh
 
-main.o: error.h
-
 error.h: cc2.h
 	rm -f $@; trap 'rm -f $$$$.h' EXIT INT QUIT ;\
 	awk -f generror.awk cc2.h > $$$$.h && mv $$$$.h $@
@@ -24,6 +24,7 @@
 	rm -f *.o
 	rm -f target/*/*.o
 	rm -f cc2-* error.h
+	rm -f $(TARGETS)
 
 include target/amd64-sysv/target.mk
 include target/i386-sysv/target.mk
--- a/cc2/target/amd64-sysv/target.mk
+++ b/cc2/target/amd64-sysv/target.mk
@@ -1,4 +1,6 @@
-all: cc2-amd64-sysv
+
+$(LIBEXEC)/cc2-amd64-sysv: cc2-amd64-sysv
+	cp cc2-amd64-sysv $@
 
 target/amd64-sysv/code.o: $(INCDIR)/$(STD)/cstd.h
 
--- a/cc2/target/i386-sysv/target.mk
+++ b/cc2/target/i386-sysv/target.mk
@@ -1,4 +1,6 @@
-all: cc2-i386-sysv
+
+$(LIBEXEC)/cc2-i386-sysv: cc2-i386-sysv
+	cp cc2-i386-sysv $@
 
 target/i386-sysv/code.o: $(INCDIR)/$(STD)/cstd.h
 
--- a/cc2/target/qbe_amd64-sysv/target.mk
+++ b/cc2/target/qbe_amd64-sysv/target.mk
@@ -1,4 +1,6 @@
-all: cc2-qbe_amd64-sysv
+
+$(LIBEXEC)/cc2-qbe_amd64-sysv: cc2-qbe_amd64-sysv
+	cp cc2-qbe_amd64-sysv $@
 
 target/qbe/cgen.o: $(INCDIR)/$(STD)/cstd.h
 
--- a/cc2/target/z80-scc/target.mk
+++ b/cc2/target/z80-scc/target.mk
@@ -1,4 +1,6 @@
-all: cc2-z80-scc
+
+$(LIBEXEC)/cc2-z80-scc: cc2-z80-scc
+	cp cc2-z80-scc $@
 
 target/z80-scc/code.o: $(INCDIR)/$(STD)/cstd.h
 
--- a/config.mk.def
+++ b/config.mk.def
@@ -2,14 +2,6 @@
 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 \
-          z80-scc-none-none \
-          i386-sysv-linux-elf \
-          amd64-sysv-openbsd-elf
-
 # USEQBE selects QBE by default in the targets that support it
 USEQBE = 1
 
--- a/configure
+++ b/configure
@@ -1,5 +1,11 @@
 #!/bin/sh
 
+set -e
+
+echo Generating file tree...
+mkdir -p rootdir/libexec/scc
+mkdir -p rootdir/bin
+
 if test ! -e config.mk
 then
 	printf '%s\n' 'Generating config.mk from defaults...' \
@@ -10,6 +16,7 @@
 	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'
+echo Generating arch-dependant build files...
+make dep > /dev/null
+
+echo You can now install scc with \"make install\"
--- a/driver/Makefile
+++ b/driver/Makefile
@@ -7,4 +7,4 @@
 include $(PROJECTDIR)/rules.mk
 
 all dep clean distclean:
-	+cd $(DRIVER) && $(MAKE) $@
+	+@cd $(DRIVER) && $(MAKE) $@
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -4,9 +4,22 @@
 include $(PROJECTDIR)/rules.mk
 include $(LIBSCC)/libdep.mk
 
-all: scc cpp
-	cp scc cpp $(PROJECTDIR)/rootdir/bin/
+# SYSLST is a list of backend-arch-abi-sys. First
+# element of the list becomes the default target
 
+SYSLST  = amd64-sysv-linux-elf z80-scc-none-none \
+          i386-sysv-linux-elf amd64-sysv-openbsd-elf
+
+TARGETS = $(BINDIR)/scc $(BINDIR)/scpp
+
+all: $(TARGETS)
+
+$(BINDIR)/scc: scc
+	cp scc $@
+
+$(BINDIR)/scpp: cpp
+	cp cpp $@
+
 scc: scc.o $(LIBSCC)/libscc.a
 	$(CC) $(SCC_LDFLAGS) scc.o -lscc -o $@
 
@@ -19,11 +32,12 @@
 	mv $$$$.sh $@
 
 dep:
-	PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./config.sh $(TARGETS)
+	PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./config.sh $(SYSLST)
 	$(PROJECTDIR)/mkdep.sh
 
 clean:
 	rm -f scc scpp *.o
+	rm -f $(TARGETS)
 
 distclean:
 	rm -f config.h
--- a/ld/Makefile
+++ b/ld/Makefile
@@ -6,9 +6,11 @@
 
 OBJ = main.o coff32.o obj.o
 
-all: ld
-	cp ld $(PROJECTDIR)/rootdir/bin
+all: $(BINDIR)/ld
 
+$(BINDIR)/ld: ld
+	cp ld $@
+
 ld: $(OBJ) $(LIBSCC)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
@@ -16,6 +18,6 @@
 	$(PROJECTDIR)/mkdep.sh
 
 clean:
-	rm -f ld *.o
+	rm -f $(BINDIR)/ld ld *.o
 
 include deps.mk
--- a/mkdep.sh
+++ b/mkdep.sh
@@ -6,8 +6,11 @@
 (sed '/^#deps/q' deps.mk
 for i in `find . -name '*.c'`
 do
-	file=`echo $i | sed -e 's,^./,,' -e 's/\.c$/.o/'`
-	dir=`dirname $i | sed 's,/*$,,'`
-	sed -n '/#include "/ s,#include "\(.*\)",'"$file: $dir"'/\1,p' $i
+	file=`basename $i | sed 's/\.c$/.o/'`
+
+	dir=`dirname $i |
+	     sed -e 's,^\./,,' -e 's,^\.$,,' -e 's,...*[^/],&/,'`
+
+	sed -n "/#include \"/ s,#include \"\(.*\)\",$dir$file: $dir\1,p" $i
 done |
 LC_ALL=C sort -s) > $$.tmp && mv $$.tmp deps.mk
--- a/nm/Makefile
+++ b/nm/Makefile
@@ -6,7 +6,9 @@
 
 OBJ       = main.o coff32.o formats.o
 
-all: nm
+all: $(BINDIR)/nm
+
+$(BINDIR)/nm: nm
 	cp nm $(PROJECTDIR)/rootdir/bin/nm
 
 nm: $(OBJ) $(LIBSCC)/libscc.a
@@ -16,7 +18,7 @@
 	$(PROJECTDIR)/mkdep.sh
 
 clean:
-	rm -f nm *.o
+	rm -f $(BINDIR)/nm nm *.o
 
 distclean: clean
 
--- a/objdump/Makefile
+++ b/objdump/Makefile
@@ -6,9 +6,11 @@
 
 OBJ       = main.o 
 
-all: objdump
-	cp objdump $(PROJECTDIR)/rootdir/bin
+all: $(BINDIR)/objdump
 
+$(BINDIR)/objdump: objdump
+	cp objdump $@
+
 objdump: $(OBJ) $(LIBSCC)/libscc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lscc -o $@
 
@@ -16,6 +18,6 @@
 	$(PROJECTDIR)/mkdep.sh
 
 clean:
-	rm -f objdump *.o
+	rm -f $(BINDIR)/objdump objdump *.o
 
 include deps.mk
--- a/rules.mk
+++ b/rules.mk
@@ -1,7 +1,9 @@
 include $(PROJECTDIR)/config.mk
 
+BINDIR  = $(PROJECTDIR)/rootdir/bin
 INCDIR  = $(PROJECTDIR)/inc/
-LIBSCC = $(PROJECTDIR)/lib/scc
+LIBEXEC = $(PROJECTDIR)/rootdir/libexec/scc/
+LIBSCC  = $(PROJECTDIR)/lib/scc
 
 SCC_CFLAGS = $(MOREFLAGS) \
              $(SYSCFLAGS) \
@@ -29,15 +31,6 @@
 .c:
 	$(CC) $(SCC_CFLAGS) $(SCC_LDFLAGS) -o $@ $<
 
-
-all: $(PROJECTDIR)/rootdir/bin $(PROJECTDIR)/rootdir/libexec/scc
-
-$(PROJECTDIR)/rootdir/bin:
-	mkdir -p $(PROJECTDIR)/rootdir/bin
-
-$(PROJECTDIR)/rootdir/libexec/scc:
-	mkdir -p $(PROJECTDIR)/rootdir/libexec/scc
-
-distclean: clean
-
+all:
 dep:
+distclean: clean