[hackers] [scc] [libc] Improve Makefile system using dynamic list || Quentin Rameau

From: <git_AT_suckless.org>
Date: Tue, 21 Mar 2017 12:08:57 +0100 (CET)

commit f9f434747f348c70f60f06fddab5de2e02616a8c
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Mar 9 12:33:55 2017 +0100
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Tue Mar 21 12:07:54 2017 +0100

    [libc] Improve Makefile system using dynamic list

diff --git a/libc/src/Makefile b/libc/src/Makefile
index 33cfe95..f84edee 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -2,7 +2,11 @@
 .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 \
_AT_@ -14,18 +18,26 @@ LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
           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 $(_AT_:%.bootstrap=%.start)
 
-libc.a: $(OBJ)
- $(AR) $(ARFLAGS) $_AT_ $?
+$(SYSINC): $(SYSDIR)/Makefile $(SYSDIR)/syscall.lst
+ cd $(SYSDIR) && $(MAKE) -e system.mk
+
+libc.a: $(SYSINC) $(OBJ)
+ $(AR) $(ARFLAGS) $_AT_ $(OBJ)
         ranlib $_AT_
 
-clean:
- rm -f *.o libc.a
- cd sys/$(ARCH)-$(SYS) && make clean
+$(LIBCSYSOBJ):
+ cd $(SYSDIR) && $(MAKE) -e
diff --git a/libc/src/sys/amd64-linux/system.mk b/libc/src/sys/amd64-linux/system.mk
deleted file mode 100644
index 7835082..0000000
--- a/libc/src/sys/amd64-linux/system.mk
+++ /dev/null
_AT_@ -1 +0,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
diff --git a/libc/src/sys/amd64-sysv-linux/Makefile b/libc/src/sys/amd64-sysv-linux/Makefile
index 21ab643..555b8a9 100644
--- a/libc/src/sys/amd64-sysv-linux/Makefile
+++ b/libc/src/sys/amd64-sysv-linux/Makefile
_AT_@ -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 $(_AT_:%.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) \
+ > $_AT_
+
+sysgen.mk: syscall.lst
+ printf '%s ' 'GENOBJ =' \
+ "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+ > $_AT_
 
-clean:
- rm -f *.o
- rm -f $(ASM_GEN)
+$(GENASM): syscall.lst
+ awk -f syscall.awk < syscall.lst
diff --git a/libc/src/sys/qbe-linux/Makefile b/libc/src/sys/qbe-linux/Makefile
index 21ab643..555b8a9 100644
--- a/libc/src/sys/qbe-linux/Makefile
+++ b/libc/src/sys/qbe-linux/Makefile
_AT_@ -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 $(_AT_:%.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) \
+ > $_AT_
+
+sysgen.mk: syscall.lst
+ printf '%s ' 'GENOBJ =' \
+ "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+ > $_AT_
 
-clean:
- rm -f *.o
- rm -f $(ASM_GEN)
+$(GENASM): syscall.lst
+ awk -f syscall.awk < syscall.lst
diff --git a/libc/src/sys/qbe-linux/system.mk b/libc/src/sys/qbe-linux/system.mk
deleted file mode 100644
index 7835082..0000000
--- a/libc/src/sys/qbe-linux/system.mk
+++ /dev/null
_AT_@ -1 +0,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
diff --git a/libc/src/sys/z80-linux/Makefile b/libc/src/sys/z80-linux/Makefile
new file mode 100644
index 0000000..555b8a9
--- /dev/null
+++ b/libc/src/sys/z80-linux/Makefile
_AT_@ -0,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 $(_AT_:%.bootstrap=%.start)
+
+system.mk: Makefile syscall.lst
+ printf '%s ' 'SYSOBJ =' \
+ "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+ $(OBJ) \
+ > $_AT_
+
+sysgen.mk: syscall.lst
+ printf '%s ' 'GENOBJ =' \
+ "$$(awk '/^#/{next}{printf "%s.o ", $$2}' syscall.lst)" \
+ > $_AT_
+
+$(GENASM): syscall.lst
+ awk -f syscall.awk < syscall.lst
diff --git a/libc/src/sys/z80-linux/syscall.lst b/libc/src/sys/z80-linux/syscall.lst
new file mode 100644
index 0000000..e69de29
Received on Tue Mar 21 2017 - 12:08:57 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 21 2017 - 12:12:19 CET