shithub: scc

Download patch

ref: 76ca88468843aaf2a21a15f240d0dc37d5ae8eb6
parent: 989c106cae3b5870d966b2cc6a83dcad73254ede
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Aug 23 11:08:56 EDT 2017

Add SCCPREFIX instead of SCCEXECPATH

SCCEXECPATH wasn't working properly because in order to use a different
location of scc we also need the location of the crt.o file. For this
reason is better to have SCCPREFIX which moves the full scc tree to
a different location.

diff: cannot open a/bin//null: file does not exist: 'a/bin//null'
--- a/Makefile
+++ b/Makefile
@@ -6,14 +6,7 @@
 
 DIRS  = inc cc1 cc2 driver lib
 
-all:
-	@set -e ;\
-	trap 'rm -f bin/cc1-* bin/cc2-* bin/scc' 0 2 3; \
-	if ! test -f bin/dep ;\
-	then \
-		echo Run make dep first >&2 ;\
-		exit 1 ;\
-	fi ;\
+FORALL = @set -e ;\
 	pwd=$$PWD; \
 	for i in $(DIRS); \
 	do \
@@ -21,62 +14,28 @@
 		$(MAKE) $@; \
 		cd $$pwd; \
 	done
-	cp cc1/cc1-* bin/
-	cp cc2/cc2-* bin/
-	cp driver/$(DRIVER)/scc bin/
 
+all: dep
+	$(FORALL)
 
 clean:
-	@set -e ;\
-	pwd=$$PWD; \
-	for i in $(DIRS); \
-	do \
-		cd $$i; \
-		$(MAKE) $@; \
-		cd $$pwd; \
-	done
-	rm -f bin/cc1-*
-	rm -f bin/cc2-*
-	rm -f bin/scc
+	$(FORALL)
+	rm -rf rootdir
 
 distclean:
-	@set -e ;\
-	pwd=$$PWD; \
-	for i in $(DIRS); \
-	do \
-		cd $$i; \
-		$(MAKE) $@; \
-		cd $$pwd; \
-	done
-	rm -f bin/cc1-*
-	rm -f bin/cc2-*
-	rm -f bin/scc
-	rm -f bin/dep
+	$(FORALL)
+	rm -f dep
+	rm -rf rootdir
 
-dep:
-	@set -e;\
-	pwd=$$PWD; \
-	for i in $(DIRS); \
-	do \
-		cd $$i; \
-		$(MAKE) $@; \
-		cd $$pwd; \
-	done
-	touch bin/dep
+dep: config.mk
+	$(FORALL)
+	touch dep
 
 tests: all
 	cd tests && $(MAKE) -e all
 
 install: all
-	mkdir -p $(DESTDIR)/$(PREFIX)/libexec/scc/
-	mkdir -p $(DESTDIR)/$(PREFIX)/bin/
-	mkdir -p $(DESTDIR)/$(PREFIX)/include/scc/
-	mkdir -p $(DESTDIR)/$(PREFIX)/lib/scc/
-	cp -f bin/cc?-* $(DESTDIR)/$(PREFIX)/libexec/scc/
-	cp -f bin/cpp.sh $(DESTDIR)/$(PREFIX)/bin/scpp
-	cp -f bin/scc $(DESTDIR)/$(PREFIX)/bin/
-	cp -f crt/crt-*.o $(DESTDIR)/$(PREFIX)/lib/scc/
-	cp -fr libc/include/* $(DESTDIR)/$(PREFIX)/include/scc/
+	cp -r rootdir/* $(DESTDIR)/$(PREFIX)/
 	find $(DESTDIR)/$(PREFIX)/include/scc/ -type f | xargs chmod 644
 	cd $(DESTDIR)/$(PREFIX)/libexec/scc/ && chmod 755 cc* && strip cc*
 	cd $(DESTDIR)/$(PREFIX)/bin && chmod 755 scpp scc && strip scc
--- a/bin/cpp.sh
+++ /dev/null
@@ -1,2 +1,0 @@
-#!/bin/sh
-scc -E $@
--- a/cc1/Makefile
+++ b/cc1/Makefile
@@ -15,6 +15,8 @@
 HDR = cc1.h ../inc/cc.h ../inc/$(STD)/cstd.h ../inc/sysincludes.h
 
 all:
+	mkdir -p ../rootdir/libexec/scc/
+	cp cc1-* ../rootdir/libexec/scc/
 
 cpp.o: stallman.msg
 
--- a/cc2/Makefile
+++ b/cc2/Makefile
@@ -13,6 +13,8 @@
 HDR = cc2.h ../inc/$(STD)/cstd.h ../inc/cc.h
 
 all:
+	mkdir -p ../rootdir/libexec/scc/
+	cp cc2-* ../rootdir/libexec/scc/
 
 dep:
 	MKQBE=${MKQBE} ./gendep.sh $(TARGETS)
--- a/driver/posix/Makefile
+++ b/driver/posix/Makefile
@@ -12,7 +12,9 @@
       ../../inc/syslibs.h \
       ../../inc/ldflags.h
 
-all: scc
+all: scc scpp
+	mkdir -p ../../rootdir/bin
+	cp scc scpp ../../rootdir/bin/
 
 dep:
 	PREFIX=$(PREFIX) USEQBE=$(USEQBE) ./gendep.sh $(TARGET)
@@ -22,6 +24,14 @@
 scc: $(OBJ) $(LIBDIR)/libcc.a
 	$(CC) $(SCC_LDFLAGS) $(OBJ) -lcc -o $@
 
+scpp: cpp.sh config.h
+	set -x ;\
+	trap "rm -f $$$$.sh" 0 2 3;\
+	rm -f $@ ;\
+	sed "s%@PREFIX@%$(PREFIX)%" < cpp.sh > $$$$.sh && \
+	chmod +x $$$$.sh && \
+	mv $$$$.sh scpp
+
 $(LIBDIR)/libcc.a:
 	cd $(LIBDIR) && $(MAKE)
 
@@ -28,6 +38,7 @@
 clean:
 	rm -f $(OBJ)
 	rm -f scc
+	rm -f scpp
 
 distclean: clean
 	rm -f config.h
--- /dev/null
+++ b/driver/posix/cpp.sh
@@ -1,0 +1,4 @@
+#!/bin/sh
+
+SCCPREFIX=$(SCCPREFIX:-@PREFIX@)
+$(SCCPREFIX)/bin/scc -E $@
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -55,7 +55,7 @@
 
 char *argv0;
 static char *arch, *sys, *abi, *format;
-static char *execpath, *objfile, *outfile;
+static char *prefix, *objfile, *outfile;
 static char *tmpdir;
 static size_t tmpdirln;
 static struct items objtmp, objout;
@@ -115,7 +115,8 @@
 		if (n < 0 || n >= sizeof(t->bin))
 			die("scc: target tool name too long");
 
-		n = snprintf(t->cmd, sizeof(t->cmd), "%s/%s", execpath, t->bin);
+		n = snprintf(t->cmd, sizeof(t->cmd),
+		             "%s/libexec/scc/%s", prefix, t->bin);
 		if (n < 0 || n >= sizeof(t->cmd))
 			die("scc: target tool path too long");
 		break;
@@ -129,13 +130,13 @@
 			addarg(tool, "-L");
 			addarg(tool, syslibs[n]);
 		}
-		n = snprintf(NULL, 0, "%s-%s-%s.o",
-		             PREFIX "/lib/scc/crt", arch, sys);
+		n = snprintf(NULL, 0, "%s/%s-%s-%s.o",
+		             prefix, "lib/scc/crt", arch, sys);
 		if (n < 0)
 			die("scc: wrong crt file name");
 		crt = xmalloc(++n);
-		n = snprintf(crt, n, "%s-%s-%s.o",
-		             PREFIX "/lib/scc/crt", arch, sys);
+		n = snprintf(crt, n, "%s/%s-%s-%s.o",
+		             prefix, "lib/scc/crt", arch, sys);
 		addarg(tool, crt);
 		break;
 	case AS:
@@ -452,8 +453,8 @@
 		abi = ABI;
 	if (!(format = getenv("FORMAT")))
 		format = FORMAT;
-	if (!(execpath = getenv("SCCEXECPATH")))
-		execpath = PREFIX "/libexec/scc";
+	if (!(prefix = getenv("SCCPREFIX")))
+		prefix = PREFIX;
 
 	ARGBEGIN {
 	case 'D':