commit db14fc326082e6a7527d6f0ab3954fea88462b05
parent 56aaae7dc83c343b6e334d662c5b0aca9ccfe630
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 18 Jan 2025 11:56:18 +0100
build: Make libmach recursive
Libmach was the last Makefile compiling things out of the
current directory, and it was a bit ugly because it had to
define files per directory and the dependencies were harder
to generate.
As we already have a dep target that creates a new makefile
that target was reused to include the list of objects. To
be sure that dep is always called a top level deps target
was created that uses a stamp file to ensure it.
Diffstat:
8 files changed, 105 insertions(+), 73 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -6,6 +6,7 @@ libexec/
dirs
*.gcno
*.gcda
+/deps
/src/cmd/scc-addr2line
/src/cmd/scc-objcopy
/src/cmd/scc-objdump
diff --git a/Makefile b/Makefile
@@ -1,5 +1,11 @@
.POSIX:
+all: deps
+
+deps:
+ $(MAKE) dep;\
+ touch $@;\
+
all dep tests install uninstall: check_config FORCE
+@$(MAKE) -f main.mk $@
@@ -33,6 +39,6 @@ clean: FORCE
distclean: FORCE
touch config.mk
$(MAKE) -f main.mk distclean
- rm -f config.mk
+ rm -f config.mk deps
FORCE:
diff --git a/scripts/rules.mk b/scripts/rules.mk
@@ -200,20 +200,32 @@ clean-dirs:
clean-files:
rm -f *.i *.d *.o *.a *.elf $(TARGET)
-dep: inc-dep
- @set -e; \
+dep: add-makefile recursive-dep
+
+add-makefile: FORCE
+ test -n "$(NODEP)" || $(MKDEP)
+
+recursive-dep: FORCE
+ +@set -e; \
for i in $(DIRS); \
do \
test $$i = tests && continue;\
cd $$i; \
- $(MAKE) $@; \
+ $(MAKE) dep; \
cd -; \
done
-inc-dep: FORCE
- test -n "$(NODEP)" || $(MKDEP)
+distclean: clean recursive-distclean
-distclean: clean del-inc-dep
+del-makefile: FORCE
+ rm -f makefile
-del-inc-dep: FORCE
- find . -name makefile | xargs rm -f
+recursive-distclean: del-makefile FORCE
+ +@set -e;\
+ for i in $(DIRS); \
+ do\
+ test $$i = tests && continue;\
+ cd $$i;\
+ $(MAKE) distclean;\
+ cd -;\
+ done
diff --git a/src/libmach/Makefile b/src/libmach/Makefile
@@ -1,50 +1,31 @@
.POSIX:
+DIRS =\
+ elf64\
+ coff32\
+
PROJECTDIR =../..
include $(PROJECTDIR)/scripts/rules.mk
-include coff32/rules.mk
-include elf64/rules.mk
TARGET = libmach.a
all: $(TARGET)
OBJS =\
- archive.o\
- armember.o\
- delobj.o\
- findsec.o\
- getindex.o\
- getsec.o\
- getsym.o\
- loadmap.o\
- mach.o\
- newmap.o\
- newobj.o \
- newobj.o\
- objpos.o\
- objprobe.o\
- objtype.o\
- pack.o\
- pc2line.o\
- readobj.o\
- rebase.o\
- setindex.o\
- setmap.o\
- setsec.o\
- setsym.o\
- strip.o\
- unpack.o\
- writeobj.o\
- $(COFF32_OBJS)\
- $(ELF64_OBJS)\
all: $(TARGET)
+ +@$(MAKE) $(DIRS)
+ +@$(MAKE) $(TARGET)
$(TARGET): $(OBJS)
$(AR) $(PROJ_ARFLAGS) $@ $?
$(RL) $(PROJ_RLFLAGS) $@
cp $@ $(LIBDIR)/scc
-clean:
- rm -f */*.o
+dep:
+ (echo H;\
+ echo /OBJS/a;\
+ ls *.c */*.c | sed -E 's/(.*)\.c$$/ \1.o\\/';\
+ echo .; \
+ echo w) |\
+ ed -s makefile
diff --git a/src/libmach/coff32/Makefile b/src/libmach/coff32/Makefile
@@ -0,0 +1,38 @@
+.POSIX:
+
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS =\
+ coff32.o\
+ coff32archs.o\
+ coff32del.o\
+ coff32getidx.o\
+ coff32getsec.o\
+ coff32getsym.o\
+ coff32loadmap.o\
+ coff32new.o\
+ coff32pc2line.o\
+ coff32probe.o\
+ coff32read.o\
+ coff32setidx.o\
+ coff32setsec.o\
+ coff32setsym.o\
+ coff32strip.o\
+ coff32type.o\
+ coff32write.o\
+ coff32xgetidx.o\
+ coff32xsetidx.o\
+
+COFFHDRS =\
+ $(INCDIR)/bits/scc/coff32/aouthdr.h\
+ $(INCDIR)/bits/scc/coff32/filehdr.h\
+ $(INCDIR)/bits/scc/coff32/linenum.h\
+ $(INCDIR)/bits/scc/coff32/reloc.h\
+ $(INCDIR)/bits/scc/coff32/scnhdr.h\
+ $(INCDIR)/bits/scc/coff32/storclass.h\
+ $(INCDIR)/bits/scc/coff32/syms.h
+
+all: $(OBJS)
+
+$(OBJS): $(COFFHDRS)
diff --git a/src/libmach/coff32/rules.mk b/src/libmach/coff32/rules.mk
@@ -1,22 +0,0 @@
-COFF32_OBJS =\
- coff32/coff32.o \
- coff32/coff32archs.o\
- coff32/coff32del.o \
- coff32/coff32new.o \
- coff32/coff32type.o \
- coff32/coff32probe.o \
- coff32/coff32read.o \
- coff32/coff32strip.o \
- coff32/coff32write.o \
- coff32/coff32setidx.o \
- coff32/coff32xsetidx.o \
- coff32/coff32getidx.o \
- coff32/coff32xgetidx.o \
- coff32/coff32setidx.o \
- coff32/coff32getidx.o \
- coff32/coff32pc2line.o \
- coff32/coff32getsym.o \
- coff32/coff32setsym.o \
- coff32/coff32getsec.o \
- coff32/coff32setsec.o \
- coff32/coff32loadmap.o\
diff --git a/src/libmach/elf64/Makefile b/src/libmach/elf64/Makefile
@@ -0,0 +1,26 @@
+.POSIX:
+
+PROJECTDIR =../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS =\
+ elf64.o\
+ elf64archs.o\
+ elf64del.o\
+ elf64getsec.o\
+ elf64getsym.o\
+ elf64new.o\
+ elf64probe.o\
+ elf64read.o\
+ elf64type.o\
+
+ELFHDRS =\
+ $(INCDIR)/bits/scc/elf/elfent.h\
+ $(INCDIR)/bits/scc/elf/elfhdr.h\
+ $(INCDIR)/bits/scc/elf/elfphdr.h\
+ $(INCDIR)/bits/scc/elf/elfshdr.h\
+ $(INCDIR)/bits/scc/elf/elftypes.h\
+
+all: $(OBJS)
+
+$(OBJS): $(ELFHDRS)
diff --git a/src/libmach/elf64/rules.mk b/src/libmach/elf64/rules.mk
@@ -1,10 +0,0 @@
-ELF64_OBJS =\
- elf64/elf64.o \
- elf64/elf64archs.o\
- elf64/elf64new.o\
- elf64/elf64probe.o\
- elf64/elf64read.o\
- elf64/elf64type.o\
- elf64/elf64getsec.o\
- elf64/elf64del.o\
- elf64/elf64getsym.o\