shithub: scc

Download patch

ref: 4f9f652f766f4ba4854889a45f1940737f3856c7
parent: 7f794f6356aa288402b0b1b60a47741d987a7e07
author: Quentin Rameau <quinq@fifth.space>
date: Thu Mar 9 07:33:55 EST 2017

[libc] Improve Makefile system using dynamic list

diff: cannot open a/libc/src/sys/amd64-linux//null: file does not exist: 'a/libc/src/sys/amd64-linux//null' diff: cannot open b/libc/src/sys/z80-linux//null: file does not exist: 'b/libc/src/sys/z80-linux//null'
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -2,8 +2,12 @@
 .POSIX:
 
 include ../../config.mk
-include sys/$(ARCH)-$(SYS)/system.mk
 
+SYSDIR = sys/$(ARCH)-$(SYS)
+SYSINC = $(SYSDIR)/system.mk
+
+-include $(SYSINC)
+
 LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
           strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
           strxfrm.o strstr.o strspn.o strcspn.o strpbrk.o strtok.o \
@@ -14,18 +18,26 @@
           localeconv.o atoi.o atexit.o exit.o \
           printf.o fprintf.o vfprintf.o \
           realloc.o calloc.o malloc.o
+LIBCSYSOBJ = $(SYSOBJ:%=$(SYSDIR)/%)
+OBJ = $(LIBCOBJ) $(LIBCSYSOBJ)
 
-OBJ = $(LIBCOBJ) $(SYSOBJ)
+all: all.bootstrap
+all.start: libc.a
 
-all: libc.a
+clean: clean.bootstrap
+clean.start:
+	rm -f *.o libc.a
+	cd $(SYSDIR) && $(MAKE) -e clean
 
-$(SYSOBJ):
-	cd sys/$(ARCH)-$(SYS) && make all
+all.bootstrap clean.bootstrap: $(SYSINC)
+	$(MAKE) -e $(@:%.bootstrap=%.start)
 
-libc.a: $(OBJ)
-	$(AR) $(ARFLAGS) $@ $?
+$(SYSINC): $(SYSDIR)/Makefile $(SYSDIR)/syscall.lst
+	cd $(SYSDIR) && $(MAKE) -e system.mk
+
+libc.a: $(SYSINC) $(OBJ)
+	$(AR) $(ARFLAGS) $@ $(OBJ)
 	ranlib $@
 
-clean:
-	rm -f *.o libc.a
-	cd sys/$(ARCH)-$(SYS) && make clean
+$(LIBCSYSOBJ):
+	cd $(SYSDIR) && $(MAKE) -e
--- a/libc/src/sys/amd64-linux/system.mk
+++ /dev/null
@@ -1,1 +1,0 @@
-$(SYSOBJ) = _read.o _write.o _open.o _close.o _lseek.o _brk.o _rt_sigaction.o _getpid.o _Exit.o _kill.o _sbrk.o
--- a/libc/src/sys/amd64-sysv-linux/Makefile
+++ b/libc/src/sys/amd64-sysv-linux/Makefile
@@ -2,21 +2,32 @@
 .POSIX:
 
 include ../../../../config.mk
+-include system.mk
+-include sysgen.mk
 
-OBJ_GEN = _read.o _write.o _open.o _close.o _lseek.o _brk.o\
-          _rt_sigaction.o _getpid.o _Exit.o _kill.o
+GENASM = $(GENOBJ:.o=.s)
+OBJ =
 
-ASM_GEN = $(OBJ_GEN:.o=.s)
-OBJ = $(OBJ_GEN)
+all: all.bootstrap
+all.start: $(SYSOBJ)
 
-all: $(OBJ) system.mk
+clean: clean.bootstrap
+clean.start:
+	rm -f *.o $(GENASM) system.mk sysgen.mk
 
-system.mk: Makefile
-	echo SYSOBJ = $(OBJ) > system.mk
+all.bootstrap clean.bootstrap: system.mk sysgen.mk
+	$(MAKE) -e $(@:%.bootstrap=%.start)
 
-$(ASM_GEN): syscall.lst
-	awk -f syscall.awk < syscall.lst
+system.mk: Makefile syscall.lst
+	printf '%s ' 'SYSOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	       $(OBJ) \
+	> $@
 
-clean:
-	rm -f *.o
-	rm -f $(ASM_GEN)
+sysgen.mk: syscall.lst
+	printf '%s ' 'GENOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	> $@
+
+$(GENASM): syscall.lst
+	awk -f syscall.awk < syscall.lst
--- a/libc/src/sys/qbe-linux/Makefile
+++ b/libc/src/sys/qbe-linux/Makefile
@@ -2,21 +2,32 @@
 .POSIX:
 
 include ../../../../config.mk
+-include system.mk
+-include sysgen.mk
 
-OBJ_GEN = _read.o _write.o _open.o _close.o _lseek.o _brk.o\
-          _rt_sigaction.o _getpid.o _Exit.o _kill.o
+GENASM = $(GENOBJ:.o=.s)
+OBJ =
 
-ASM_GEN = $(OBJ_GEN:.o=.s)
-OBJ = $(OBJ_GEN)
+all: all.bootstrap
+all.start: $(SYSOBJ)
 
-all: $(OBJ) system.mk
+clean: clean.bootstrap
+clean.start:
+	rm -f *.o $(GENASM) system.mk sysgen.mk
 
-system.mk: Makefile
-	echo SYSOBJ = $(OBJ) > system.mk
+all.bootstrap clean.bootstrap: system.mk sysgen.mk
+	$(MAKE) -e $(@:%.bootstrap=%.start)
 
-$(ASM_GEN): syscall.lst
-	awk -f syscall.awk < syscall.lst
+system.mk: Makefile syscall.lst
+	printf '%s ' 'SYSOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	       $(OBJ) \
+	> $@
 
-clean:
-	rm -f *.o
-	rm -f $(ASM_GEN)
+sysgen.mk: syscall.lst
+	printf '%s ' 'GENOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	> $@
+
+$(GENASM): syscall.lst
+	awk -f syscall.awk < syscall.lst
--- a/libc/src/sys/qbe-linux/system.mk
+++ /dev/null
@@ -1,1 +1,0 @@
-$(SYSOBJ) = _read.o _write.o _open.o _close.o _lseek.o _brk.o _rt_sigaction.o _getpid.o _Exit.o _kill.o _sbrk.o
--- /dev/null
+++ b/libc/src/sys/z80-linux/Makefile
@@ -1,0 +1,33 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
+
+include ../../../../config.mk
+-include system.mk
+-include sysgen.mk
+
+GENASM = $(GENOBJ:.o=.s)
+OBJ =
+
+all: all.bootstrap
+all.start: $(SYSOBJ)
+
+clean: clean.bootstrap
+clean.start:
+	rm -f *.o $(GENASM) system.mk sysgen.mk
+
+all.bootstrap clean.bootstrap: system.mk sysgen.mk
+	$(MAKE) -e $(@:%.bootstrap=%.start)
+
+system.mk: Makefile syscall.lst
+	printf '%s ' 'SYSOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	       $(OBJ) \
+	> $@
+
+sysgen.mk: syscall.lst
+	printf '%s ' 'GENOBJ =' \
+	       "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+	> $@
+
+$(GENASM): syscall.lst
+	awk -f syscall.awk < syscall.lst