scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 14e42234afd219c5d4fd4afd03509cf67cdc5145
parent 23495f800b903c0fe1261a385ed304994509f437
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 23 Aug 2017 15:08:56 +0100

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.

Diffstat:
MMakefile | 65++++++++++++-----------------------------------------------------
Dbin/cpp.sh | 2--
Mcc1/Makefile | 2++
Mcc2/Makefile | 2++
Mdriver/posix/Makefile | 13++++++++++++-
Adriver/posix/cpp.sh | 4++++
Mdriver/posix/scc.c | 17+++++++++--------
7 files changed, 41 insertions(+), 64 deletions(-)

diff --git a/Makefile b/Makefile @@ -6,14 +6,7 @@ include config.mk 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 @@ all: $(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 diff --git a/bin/cpp.sh b/bin/cpp.sh @@ -1,2 +0,0 @@ -#!/bin/sh -scc -E $@ diff --git a/cc1/Makefile b/cc1/Makefile @@ -15,6 +15,8 @@ OBJ = types.o decl.o lex.o error.o symbol.o main.o expr.o \ 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 diff --git a/cc2/Makefile b/cc2/Makefile @@ -13,6 +13,8 @@ OBJ = main.o parser.o peep.o symbol.o node.o code.o optm.o 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) diff --git a/driver/posix/Makefile b/driver/posix/Makefile @@ -12,7 +12,9 @@ HDR = config.h \ ../../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,12 +24,21 @@ $(OBJ): $(HDR) 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) clean: rm -f $(OBJ) rm -f scc + rm -f scpp distclean: clean rm -f config.h diff --git a/driver/posix/cpp.sh b/driver/posix/cpp.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +SCCPREFIX=$(SCCPREFIX:-@PREFIX@) +$(SCCPREFIX)/bin/scc -E $@ diff --git a/driver/posix/scc.c b/driver/posix/scc.c @@ -55,7 +55,7 @@ static struct tool { 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 @@ inittool(int tool) 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 @@ inittool(int tool) 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 @@ main(int argc, char *argv[]) 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':