scc

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

commit 856d3c7dbd889b25f3e5be8559f67ab3f65a0384
parent 36b8769dd5c503c420bb9404c0f0c2d4bfd2db82
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Oct 2024 18:27:00 +0200

build: Do not target outer directories

Having rules that build things out of the current directory makes
everything more difficult, because when building in nested directories
then you have the binary in a different directory. Also, having the /
character in a target is not portable.

Diffstat:
M.gitignore | 29+++++++++++++++++++++++++++++
Msrc/cmd/Makefile | 50++++++++++++++++++++++++++++----------------------
Msrc/cmd/as/Makefile | 17++++++++---------
Msrc/cmd/as/target/powerpc/powerpc.mk | 3++-
Msrc/cmd/as/target/powerpc/powerpc64.mk | 3++-
Msrc/cmd/as/target/x80/z80.mk | 3++-
Msrc/cmd/as/target/x86/amd64.mk | 3++-
Msrc/cmd/as/target/x86/i286.mk | 3++-
Msrc/cmd/as/target/x86/i386.mk | 3++-
Msrc/cmd/cc/cc1/Makefile | 5+++--
Msrc/cmd/cc/cc2/Makefile | 10+++++-----
Msrc/cmd/cc/cc2/target/amd64-sysv/target.mk | 3++-
Msrc/cmd/cc/cc2/target/i386-sysv/target.mk | 3++-
Msrc/cmd/cc/cc2/target/qbe_amd64-sysv/target.mk | 3++-
Msrc/cmd/cc/cc2/target/qbe_arm64-sysv/target.mk | 3++-
Msrc/cmd/cc/cc2/target/z80-scc/target.mk | 3++-
Msrc/cmd/cc/posix/Makefile | 23+++++++++++------------
Msrc/cmd/ld/Makefile | 3++-
Msrc/cmd/make/Makefile | 5+++--
Msrc/libmach/Makefile | 3++-
Msrc/libscc/Makefile | 3++-
21 files changed, 115 insertions(+), 66 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -6,3 +6,32 @@ libexec/ dirs *.gcno *.gcda +/src/cmd/scc-addr2line +/src/cmd/scc-objcopy +/src/cmd/scc-objdump +/src/cmd/scc-size +/src/cmd/scc-strip +/src/cmd/scc-ar +/src/cmd/scc-nm +/src/cmd/scc-ranlib +/src/cmd/as/as-amd64 +/src/cmd/as/as-i286 +/src/cmd/as/as-i386 +/src/cmd/as/as-powerpc +/src/cmd/as/as-powerpc64 +/src/cmd/as/as-z80 +/src/cmd/cc/cc1/cc1 +/src/cmd/cc/cc1/cpp-bug.c +/src/cmd/cc/cc1/f.c +/src/cmd/cc/cc1/len-macro.c +/src/cmd/cc/cc2/cc2-amd64-sysv +/src/cmd/cc/cc2/cc2-i386-sysv +/src/cmd/cc/cc2/cc2-qbe_amd64-sysv +/src/cmd/cc/cc2/cc2-qbe_arm64-sysv +/src/cmd/cc/cc2/cc2-z80-scc +/src/cmd/cc/posix/scc +/src/cmd/cc/posix/scc-cc +/src/cmd/cc/posix/scc-cpp +/src/cmd/ld/scc-ld +/src/cmd/make/scc-make +/ diff --git a/src/cmd/Makefile b/src/cmd/Makefile @@ -10,18 +10,21 @@ PROJECTDIR = ../.. include $(PROJECTDIR)/scripts/rules.mk TARGET =\ - $(BINDIR)/scc-nm\ - $(BINDIR)/scc-ar\ - $(BINDIR)/scc-strip\ - $(BINDIR)/scc-size\ - $(BINDIR)/scc-ranlib\ - $(BINDIR)/scc-objdump\ - $(BINDIR)/scc-objcopy\ - $(BINDIR)/scc-addr2line\ - $(LIBEXEC)/scc/qbe\ + scc-nm\ + scc-ar\ + scc-strip\ + scc-size\ + scc-ranlib\ + scc-objdump\ + scc-objcopy\ + scc-addr2line\ + qbe/qbe\ all: $(TARGET) $(DIRS) +qbe/qbe: qbe + cp $@ $(LIBEXEC)/scc + qbe/.git: git submodule init qbe git submodule update qbe @@ -29,33 +32,36 @@ qbe/.git: qbe: qbe/.git FORCE +cd qbe && $(MAKE) CC=$(CC) CFLAGS='$(PROJ_CFLAGS)' -qbe/qbe: qbe - -$(LIBEXEC)/scc/qbe: qbe/qbe - cp qbe/qbe $@ - -$(BINDIR)/scc-nm: nm.o $(LIBMACH) $(LIBSCC) +scc-nm: nm.o $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) nm.o -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-strip: strip.o $(LIBMACH) $(LIBSCC) +scc-strip: strip.o $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) strip.o -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-size: size.o $(LIBMACH) $(LIBSCC) +scc-size: size.o $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) size.o -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-ranlib: ranlib.o $(LIBMACH) $(LIBSCC) +scc-ranlib: ranlib.o $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) ranlib.o -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-objdump: objdump.o $(LIBMACH) +scc-objdump: objdump.o $(LIBMACH) $(CC) $(PROJ_LDFLAGS) objdump.o -lmach $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-objcopy: objcopy.o $(LIBMACH) +scc-objcopy: objcopy.o $(LIBMACH) $(CC) $(PROJ_LDFLAGS) objcopy.o -lmach $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-addr2line: addr2line.o $(LIBMACH) $(LIBSCC) +scc-addr2line: addr2line.o $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) addr2line.o -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-ar: ar.o $(LIBSCC) +scc-ar: ar.o $(LIBSCC) $(CC) $(PROJ_LDFLAGS) ar.o $(PROJ_LDLIBS) -lscc -o $@ + cp $@ $(BINDIR) include deps.mk diff --git a/src/cmd/as/Makefile b/src/cmd/as/Makefile @@ -13,13 +13,12 @@ OBJS = \ symbol.o\ TARGET =\ - $(BINDIR)/scc-as\ - $(LIBEXEC)/scc/as-amd64\ - $(LIBEXEC)/scc/as-i286\ - $(LIBEXEC)/scc/as-i386\ - $(LIBEXEC)/scc/as-powerpc\ - $(LIBEXEC)/scc/as-powerpc64\ - $(LIBEXEC)/scc/as-z80 \ + as-amd64\ + as-i286\ + as-i386\ + as-powerpc\ + as-powerpc64\ + as-z80 \ MORE_LDLIBS = -lscc -lmach @@ -27,8 +26,8 @@ all: $(TARGET) $(TARGET): $(LIBSCC) $(LIBMACH) -$(BINDIR)/scc-as: as - cp as $@ +scc-as: as + cp as $(BINDIR) genhash.o: ../../libscc/genhash.c $(HOSTCC) -c ../../libscc/genhash.c diff --git a/src/cmd/as/target/powerpc/powerpc.mk b/src/cmd/as/target/powerpc/powerpc.mk @@ -8,5 +8,6 @@ POWERPC_OBJ =\ $(POWERPC)/powerpctbl.c: $(POWERPC)/ops.dat $(POWERPC)/opers.dat lexh ./mktbl -f powerpc -c powerpc -$(LIBEXEC)/scc/as-powerpc: $(POWERPC_OBJ) +as-powerpc: $(POWERPC_OBJ) $(CC) $(PROJ_LDFLAGS) $(POWERPC_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/as/target/powerpc/powerpc64.mk b/src/cmd/as/target/powerpc/powerpc64.mk @@ -8,5 +8,6 @@ POWERPC64_OBJ =\ $(POWERPC)/powerpc64tbl.c: $(POWERPC)/ops.dat $(POWERPC)/opers.dat lexh ./mktbl -f powerpc -c powerpc64 -$(LIBEXEC)/scc/as-powerpc64: $(POWERPC64_OBJ) +as-powerpc64: $(POWERPC64_OBJ) $(CC) $(PROJ_LDFLAGS) $(POWERPC64_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/as/target/x80/z80.mk b/src/cmd/as/target/x80/z80.mk @@ -7,5 +7,6 @@ Z80_OBJ =\ target/x80/z80tbl.c: target/x80/ops.dat target/x80/opers.dat lexh ./mktbl -f x80 -c z80 -$(LIBEXEC)/scc/as-z80: $(OBJ) $(Z80_OBJ) +as-z80: $(OBJ) $(Z80_OBJ) $(CC) $(PROJ_LDFLAGS) $(Z80_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/as/target/x86/amd64.mk b/src/cmd/as/target/x86/amd64.mk @@ -7,5 +7,6 @@ AMD64_OBJ =\ target/x86/amd64tbl.c: target/x86/ops.dat target/x86/opers.dat lexh ./mktbl -f x86 -c amd64 -$(LIBEXEC)/scc/as-amd64: $(AMD64_OBJ) +as-amd64: $(AMD64_OBJ) $(CC) $(PROJ_LDFLAGS) $(AMD64_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/as/target/x86/i286.mk b/src/cmd/as/target/x86/i286.mk @@ -7,5 +7,6 @@ I286_OBJ =\ target/x86/i286tbl.c: target/x86/ops.dat target/x86/opers.dat lexh ./mktbl -f x86 -c i286 -$(LIBEXEC)/scc/as-i286: $(I286_OBJ) +as-i286: $(I286_OBJ) $(CC) $(PROJ_LDFLAGS) $(I286_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/as/target/x86/i386.mk b/src/cmd/as/target/x86/i386.mk @@ -7,5 +7,6 @@ I386_OBJ =\ target/x86/i386tbl.c: target/x86/ops.dat target/x86/opers.dat lexh ./mktbl -f x86 -c i386 -$(LIBEXEC)/scc/as-i386: $(I386_OBJ) +as-i386: $(I386_OBJ) $(CC) $(PROJ_LDFLAGS) $(I386_OBJ) $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/cc1/Makefile b/src/cmd/cc/cc1/Makefile @@ -23,11 +23,12 @@ OBJS =\ i386-sysv.o \ z80-scc.o\ -TARGET = $(LIBEXEC)/scc/cc1 +TARGET = cc1 -all: $(TARGET) +all: cc1 $(TARGET): $(LIBSCC) $(OBJS) $(CC) $(PROJ_LDFLAGS) $(OBJS) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc/cc1 include deps.mk diff --git a/src/cmd/cc/cc2/Makefile b/src/cmd/cc/cc2/Makefile @@ -15,11 +15,11 @@ OBJS =\ optm.o\ TARGET =\ - $(LIBEXEC)/scc/cc2-amd64-sysv\ - $(LIBEXEC)/scc/cc2-i386-sysv\ - $(LIBEXEC)/scc/cc2-qbe_amd64-sysv\ - $(LIBEXEC)/scc/cc2-qbe_arm64-sysv\ - $(LIBEXEC)/scc/cc2-z80-scc\ + cc2-amd64-sysv\ + cc2-i386-sysv\ + cc2-qbe_amd64-sysv\ + cc2-qbe_arm64-sysv\ + cc2-z80-scc\ all: $(TARGET) diff --git a/src/cmd/cc/cc2/target/amd64-sysv/target.mk b/src/cmd/cc/cc2/target/amd64-sysv/target.mk @@ -4,5 +4,6 @@ OBJ-amd64-sysv = $(OBJS) \ target/amd64-sysv/code.o \ target/amd64-sysv/types.o -$(LIBEXEC)/scc/cc2-amd64-sysv: $(LIBSCC) $(OBJ-amd64-sysv) +cc2-amd64-sysv: $(LIBSCC) $(OBJ-amd64-sysv) $(CC) $(PROJ_LDFLAGS) $(OBJ-amd64-sysv) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/cc2/target/i386-sysv/target.mk b/src/cmd/cc/cc2/target/i386-sysv/target.mk @@ -4,5 +4,6 @@ OBJ-i386-sysv = $(OBJS) \ target/i386-sysv/code.o \ target/i386-sysv/types.o -$(LIBEXEC)/scc/cc2-i386-sysv: $(LIBSCC) $(OBJ-i386-sysv) +cc2-i386-sysv: $(LIBSCC) $(OBJ-i386-sysv) $(CC) $(PROJ_LDFLAGS) $(OBJ-i386-sysv) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/cc2/target/qbe_amd64-sysv/target.mk b/src/cmd/cc/cc2/target/qbe_amd64-sysv/target.mk @@ -4,5 +4,6 @@ OBJ-qbe_amd64-sysv = $(OBJS) \ target/qbe/code.o \ target/amd64-sysv/types.o -$(LIBEXEC)/scc/cc2-qbe_amd64-sysv: $(LIBSCC) $(OBJ-qbe_amd64-sysv) +cc2-qbe_amd64-sysv: $(LIBSCC) $(OBJ-qbe_amd64-sysv) $(CC) $(PROJ_LDFLAGS) $(OBJ-qbe_amd64-sysv) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/cc2/target/qbe_arm64-sysv/target.mk b/src/cmd/cc/cc2/target/qbe_arm64-sysv/target.mk @@ -4,5 +4,6 @@ OBJ-qbe_arm64-sysv = $(OBJS) \ target/qbe/code.o \ target/arm64-sysv/types.o \ -$(LIBEXEC)/scc/cc2-qbe_arm64-sysv: $(LIBSCC) $(OBJ-qbe_arm64-sysv) +cc2-qbe_arm64-sysv: $(LIBSCC) $(OBJ-qbe_arm64-sysv) $(CC) $(PROJ_LDFLAGS) $(OBJ-qbe_arm64-sysv) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/cc2/target/z80-scc/target.mk b/src/cmd/cc/cc2/target/z80-scc/target.mk @@ -4,5 +4,6 @@ OBJ-z80-scc = $(OBJS) \ target/z80-scc/code.o \ target/z80-scc/types.o \ -$(LIBEXEC)/scc/cc2-z80-scc: $(LIBSCC) $(OBJ-z80-scc) +cc2-z80-scc: $(LIBSCC) $(OBJ-z80-scc) $(CC) $(PROJ_LDFLAGS) $(OBJ-z80-scc) -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(LIBEXEC)/scc diff --git a/src/cmd/cc/posix/Makefile b/src/cmd/cc/posix/Makefile @@ -3,26 +3,25 @@ PROJECTDIR = ../../../.. include $(PROJECTDIR)/scripts/rules.mk -TARGETS =\ - $(BINDIR)/scc-cc\ - $(BINDIR)/scc-cpp\ - $(BINDIR)/scc\ +TARGET =\ + scc-cc\ + scc-cpp\ + scc\ -all: $(TARGETS) +all: $(TARGET) -$(BINDIR)/scc-cc: $(LIBSCC) cc.o +scc-cc: $(LIBSCC) cc.o $(CC) $(PROJ_LDFLAGS) cc.o -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) -$(BINDIR)/scc-cpp: scc.sh +scc-cpp: scc.sh cp scc.sh $@ chmod +x $@ + cp $@ $(BINDIR) -$(BINDIR)/scc: scc.sh +scc: scc.sh cp scc.sh $@ chmod +x $@ - -clean: - rm -f scc scpp *.o - rm -f $(TARGETS) + cp $@ $(BINDIR) include deps.mk diff --git a/src/cmd/ld/Makefile b/src/cmd/ld/Makefile @@ -2,7 +2,7 @@ PROJECTDIR = ../../.. include $(PROJECTDIR)/scripts/rules.mk -TARGET = $(BINDIR)/scc-ld +TARGET = scc-ld OBJS =\ main.o\ @@ -18,5 +18,6 @@ all: $(TARGET) $(TARGET): $(OBJS) $(LIBMACH) $(LIBSCC) $(CC) $(PROJ_LDFLAGS) $(OBJS) -lmach -lscc $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) include deps.mk diff --git a/src/cmd/make/Makefile b/src/cmd/make/Makefile @@ -10,11 +10,12 @@ OBJS =\ rules.o\ $(DRIVER).o\ -TARGET = $(BINDIR)/scc-make +TARGET = scc-make all: $(TARGET) -$(BINDIR)/scc-make: $(OBJS) +scc-make: $(OBJS) $(CC) $(PROJ_LDFLAGS) $(OBJS) $(PROJ_LDLIBS) -o $@ + cp $@ $(BINDIR) $(OBJS): make.h diff --git a/src/libmach/Makefile b/src/libmach/Makefile @@ -5,7 +5,7 @@ include $(PROJECTDIR)/scripts/rules.mk include coff32/rules.mk include elf64/rules.mk -TARGET = $(LIBDIR)/scc/libmach.a +TARGET = libmach.a all: $(TARGET) @@ -44,6 +44,7 @@ all: $(TARGET) $(TARGET): $(OBJS) $(AR) $(PROJ_ARFLAGS) $@ $? $(RL) $(PROJ_RLFLAGS) $@ + cp $@ $(LIBDIR)/scc clean: rm -f $(TBLS) objlst.mk diff --git a/src/libscc/Makefile b/src/libscc/Makefile @@ -20,12 +20,13 @@ OBJS =\ getstat-$(DRIVER).o\ setstat-$(DRIVER).o\ -TARGET = $(LIBDIR)/scc/libscc.a +TARGET = libscc.a all: $(TARGET) $(TARGET): $(OBJS) $(AR) $(PROJ_ARFLAGS) $@ $? $(RL) $(PROJ_RLFLAGS) $@ + cp $@ $(LIBDIR)/scc include deps.mk