shithub: scc

Download patch

ref: bf2b631c10be44df6ca87c9b7e7fb279a9a4d4ec
parent: d7171eb5761cad852580cf0b9d352725a9cb1015
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Jan 18 12:40:40 EST 2020

[libc] Allows multi target

After this change, several configurations can be compiled
and they will not collided since every one of them has
a different extension. This patch also removes the ugly
mklst shell script which was locating the object files
using find.

--- a/config/config/amd64-darwin.mk
+++ b/config/config/amd64-darwin.mk
@@ -1,3 +1,4 @@
 ARCH = amd64
 SYS = darwin
 ABI = amd64-darwin
+O = 6d
--- a/config/config/amd64-dragonfly.mk
+++ b/config/config/amd64-dragonfly.mk
@@ -1,3 +1,3 @@
-ARCH = amd64
+include $(PROJECTDIR)/config/config/amd64-posix.mk
+
 SYS = dragonfly
-ABI = amd64-posix
--- a/config/config/amd64-linux.mk
+++ b/config/config/amd64-linux.mk
@@ -1,3 +1,3 @@
-ARCH = amd64
+include $(PROJECTDIR)/config/config/amd64-posix.mk
+
 SYS  = linux
-ABI  = amd64-posix
--- a/config/config/amd64-netbsd.mk
+++ b/config/config/amd64-netbsd.mk
@@ -1,3 +1,3 @@
-ARCH = amd64
+include $(PROJECTDIR)/config/config/amd64-posix.mk
+
 SYS = netbsd
-ABI = amd64-posix
--- a/config/config/amd64-openbsd.mk
+++ b/config/config/amd64-openbsd.mk
@@ -1,3 +1,3 @@
-ARCH = amd64
+include $(PROJECTDIR)/config/config/amd64-posix.mk
+
 SYS = openbsd
-ABI = amd64-posix
--- /dev/null
+++ b/config/config/amd64-posix.mk
@@ -1,0 +1,3 @@
+ARCH = amd64
+ABI  = amd64-posix
+O    = 6
--- a/config/config/arm32-linux.mk
+++ b/config/config/arm32-linux.mk
@@ -1,3 +1,3 @@
-ARCH = arm32
+include $(PROJECTDIR)/config/config/arm32-posix.mk
+
 SYS = linux
-ABI = arm32-posix
--- /dev/null
+++ b/config/config/arm32-posix.mk
@@ -1,0 +1,3 @@
+ABI = arm32-posix
+ARCH = arm32
+O = 5
--- a/config/config/arm64-linux.mk
+++ b/config/config/arm64-linux.mk
@@ -1,3 +1,3 @@
-ARCH = arm64
+include $(PROJECTDIR)/config/config/arm64-linux.mk
+
 SYS = linux
-ABI = arm64-posix
--- /dev/null
+++ b/config/config/arm64-posix.mk
@@ -1,0 +1,3 @@
+ARCH = arm64
+ABI = arm64-posix
+O = 6
--- a/scripts/rules.mk
+++ b/scripts/rules.mk
@@ -12,7 +12,7 @@
 BINDIR     = $(PROJECTDIR)/bin
 LIBEXEC    = $(PROJECTDIR)/libexec/scc
 CRTDIR     = $(PROJECTDIR)/lib/scc
-LIBCDIR    = $(CRTDIR)/$(ARCH)-$(SYS)/
+LIBCDIR    = $(CRTDIR)/$(ARCH)-$(SYS)
 ENVIRON    = $(SCRIPTDIR)/env.sh
 
 INCLUDE    = -I$(INCDIR)/scc
--- a/src/libc/.gitignore
+++ b/src/libc/.gitignore
@@ -1,1 +1,5 @@
-objlst.mk
+*.6
+*.7
+*.8
+*.z
+libc.lst
--- a/src/libc/Makefile
+++ b/src/libc/Makefile
@@ -3,24 +3,28 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include rules.mk
 
-DIRS = arch\
-       assert\
-       ctype\
-       locale\
-       stdio\
-       stdlib\
-       string\
-       time\
+DIRS =\
+	arch\
+	assert\
+	ctype\
+	locale\
+	stdio\
+	stdlib\
+	string\
+	time\
 
-all: $(DIRS) objlst.mk
-	+@$(MAKE) -f Makefile.libc
+all: $(LIBC)
 
-$(DIRS): FORCE
+$(LIBC): $(LIBCLST)
+	mklib -o $@ `cat $(LIBCLST)`
+
+$(LIBCLST): $(DIRS)
+
+$(DIRS): rm-lst
 	+@cd $@ && $(MAKE)
 
-objlst.mk: $(DIRS) FORCE
-	mklst $@
+rm-lst: FORCE
+	rm -f $(LIBCLST)
 
-clean:
+clean: rm-lst
 	$(FORALL)
-	rm -f objlst.mk
--- a/src/libc/Makefile.libc
+++ /dev/null
@@ -1,17 +1,0 @@
-.POSIX:
-PROJECTDIR =../..
-include $(PROJECTDIR)/scripts/rules.mk
-include rules.mk
-include objlst.mk
-
-LIBC   = $(LIBCDIR)/libc.a
-CRT    = $(LIBCDIR)/crt.o
-TARGET = $(LIBC) $(CRT)
-
-all: $(TARGET)
-
-$(LIBC): $(OBJS)
-	mklib -o $@ $?
-
-$(CRT): arch/$(ARCH)/$(SYS)/crt.o
-	cp arch/$(ARCH)/$(SYS)/crt.o $@
--- a/src/libc/arch/amd64/Makefile
+++ b/src/libc/arch/amd64/Makefile
@@ -3,10 +3,13 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../rules.mk
 
-OBJS = longjmp.o setjmp.o
+OBJS = longjmp.$O setjmp.$O
 DIRS = netbsd openbsd dragonfly linux darwin
 
-all: $(OBJS) $(SYS)
+all: $(LIBC) $(SYS)
+
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
 $(SYS): FORCE
 	+@cd $@ && $(MAKE)
--- a/src/libc/arch/amd64/darwin/Makefile
+++ b/src/libc/arch/amd64/darwin/Makefile
@@ -3,35 +3,41 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = __Exit.o \
-        __close.o \
-        __getpid.o \
-        __kill.o \
-        __lseek.o \
-        __open.o \
-        __read.o \
-        __write.o \
-        __sigaction.o\
-        _getheap.o \
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS =\
+	__Exit.$O\
+	__close.$O\
+	__getpid.$O\
+	__kill.$O\
+	__lseek.$O\
+	__open.$O\
+	__read.$O\
+	__write.$O\
+	__sigaction.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS  =\
+	$(GENOBJS)\
+	_getheap.$O\
+	_tzone.$O\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_sys_errlist.$O\
 
-crt.o: ../crt-posix.s
+# Rules
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+all: $(LIBC) $(CRT)
 
+$(LIBCLST): $(OBJS)
+	$(MKLST)
+
+crt.$O: ../crt-posix.s
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '$$2 ~ /^__/ {print $$2".s"}' syscall.lst`
+	rm -f $(GENSRC)
 	rm -f syscall _sys_errlist.c
--- a/src/libc/arch/amd64/darwin/gensys.sh
+++ b/src/libc/arch/amd64/darwin/gensys.sh
@@ -5,7 +5,9 @@
 # until the 4th parameter, so we only have to set the syscall
 # number in rax
 
-awk 'NF == 2 {printf("0x%x\t%s\n", 33554432 + $1, $2)}' syscall.lst |
+awk 'NF == 2 && $2 == "'$1'" {
+	printf("0x%x\t%s\n", 33554432 + $1, $2)
+}' syscall.lst |
 while read num name
 do
 cat <<EOF > $name.s
--- a/src/libc/arch/amd64/dragonfly/Makefile
+++ b/src/libc/arch/amd64/dragonfly/Makefile
@@ -3,36 +3,42 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = _Exit.o \
-        _close.o \
-        _getpid.o \
-        _kill.o \
-        _lseek.o \
-        _open.o \
-        _read.o \
-        _write.o \
-        _brk.o \
-        _getheap.o \
-        _sigaction.o\
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS =\
+	_Exit.$O\
+	_close.$O\
+	_getpid.$O\
+	_kill.$O\
+	_lseek.$O\
+	_open.$O\
+	_read.$O\
+	_write.$O\
+	_brk.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS =\
+	$(GENOBJS)\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_getheap.$O\
+	_sigaction.$O\
+	_tzone.$O\
+	_sys_errlist.$O\
 
-crt.o: crt-posix.s
+# Rules
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+all: $(LIBC) $(CRT)
 
+$(LIBCLST): $(OBJS)
+	$(MKLST)
+
+crt.$O: ../crt-posix.s
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
-	rm -f syscall _sys_errlist.c
+	rm -f $(GENSRC)
+	rm -f _sys_errlist.c
--- a/src/libc/arch/amd64/dragonfly/gensys.sh
+++ b/src/libc/arch/amd64/dragonfly/gensys.sh
@@ -5,8 +5,9 @@
 # until the 4th parameter, so we only have to set the syscall
 # number in rax
 
-sed 's/[ 	]*#.*//
-     /^$/d' syscall.lst |
+sed -n "
+     s/[ 	]*#.*//
+     /$1/p" syscall.lst |
 while read num name
 do
 cat <<EOF > $name.s
--- a/src/libc/arch/amd64/linux/Makefile
+++ b/src/libc/arch/amd64/linux/Makefile
@@ -3,38 +3,43 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = _Exit.o \
-        _close.o \
-        _getpid.o \
-        _kill.o \
-        _lseek.o \
-        _open.o \
-        _sigaction.o \
-        _read.o \
-        _write.o \
-        _brk.o \
-        _getheap.o \
-        _cerrno.o \
-        _sigaction.o \
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS =\
+	_Exit.$O\
+	_close.$O\
+	_getpid.$O\
+	_kill.$O\
+	_lseek.$O\
+	_open.$O\
+	_read.$O\
+	_write.$O\
+	_brk.$O\
+	_sigaction.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS  = \
+	$(GENOBJS)\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_cerrno.$O\
+	_getheap.$O\
+	_tzone.$O\
+	_sys_errlist.$O\
 
-crt.o: ../crt-posix.s
+# Rules
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+all: $(LIBC) $(CRT)
 
+$(LIBCLST): $(OBJS)
+	$(MKLST)
+
+crt.$O: ../crt-posix.s
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
-	rm -f syscall _sys_errlist.c
+	rm -f $(GENSRC)
+	rm -f _sys_errlist.c
--- a/src/libc/arch/amd64/linux/gensys.sh
+++ b/src/libc/arch/amd64/linux/gensys.sh
@@ -5,10 +5,12 @@
 # until the 4th parameter, so we only have to set the syscall
 # number in rax
 
-sed 's/[ 	]*#.*//
-     /^$/d' syscall.lst |
+sed -n "
+     s/[ 	]*#.*//
+     /$1/p" syscall.lst |
 while read num name
 do
+
 cat <<EOF > $name.s
 	.file	"$name.s"
 
@@ -18,4 +20,5 @@
 	syscall
 	jmp	_cerrno
 EOF
+
 done
--- a/src/libc/arch/amd64/netbsd/Makefile
+++ b/src/libc/arch/amd64/netbsd/Makefile
@@ -3,39 +3,42 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = _Exit.o \
-        _close.o \
-        _getpid.o \
-        _kill.o \
-        _lseek.o \
-        _open.o \
-        _read.o \
-        _write.o \
-        _brk.o \
-        _getheap.o \
-        _setcontext.o \
-        _sigaction.o \
-        _sigaction2.o \
-        _sigaction.o\
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS  =\
+	_Exit.$O\
+	_close.$O\
+	_getpid.$O\
+	_kill.$O\
+	_lseek.$O\
+	_open.$O\
+	_read.$O\
+	_write.$O\
+	_brk.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS =\
+	$(GENOBJS)\
+	_getheap.$O\
+	_setcontext.$O\
+	_sigaction.$O\
+	_sigaction2.$O\
+	_tzone.$O\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_sys_errlist.$O\
 
-crt.o: ../crt-posix.s ../../crt-netbsd.s
+all: $(LIBC) $(CRT)
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
+crt.$O: ../crt-posix.s ../../crt-netbsd.s
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f $(GENSRC)
 	rm -f syscall _sys_errlist.c
--- a/src/libc/arch/amd64/netbsd/gensys.sh
+++ b/src/libc/arch/amd64/netbsd/gensys.sh
@@ -5,8 +5,9 @@
 # until the 4th parameter, so we only have to set the syscall
 # number in rax
 
-sed 's/[ 	]*#.*//
-     /^$/d' syscall.lst |
+sed -n "
+     s/[ 	]*#.*//
+     /$1/p" syscall.lst |
 while read num name
 do
 cat <<EOF > $name.s
--- a/src/libc/arch/amd64/openbsd/Makefile
+++ b/src/libc/arch/amd64/openbsd/Makefile
@@ -3,36 +3,40 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = _Exit.o \
-        _close.o \
-        _getpid.o \
-        _kill.o \
-        _lseek.o \
-        _open.o \
-        _read.o \
-        _write.o \
-        _brk.o \
-        _getheap.o \
-        _sigaction.o\
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS =\
+	_Exit.$O\
+	_close.$O\
+	_getpid.$O\
+	_kill.$O\
+	_lseek.$O\
+	_open.$O\
+	_read.$O\
+	_write.$O\
+	_brk.$O\
+	_sigaction.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS =\
+	$(GENOBJS)\
+	_getheap.$O\
+	_tzone.$O\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_sys_errlist.$O\
 
-crt.o: ../crt-posix.s ../../crt-openbsd.s
+all: $(LIBC) $(CRT)
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
+crt.$O: ../crt-posix.s ../../crt-openbsd.s
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f $(GENSRC)
 	rm -f syscall _sys_errlist.c
--- a/src/libc/arch/amd64/openbsd/gensys.sh
+++ b/src/libc/arch/amd64/openbsd/gensys.sh
@@ -5,8 +5,9 @@
 # until the 4th parameter, so we only have to set the syscall
 # number in rax
 
-sed 's/[ 	]*#.*//
-     /^$/d' syscall.lst |
+sed -n "
+     s/[ 	]*#.*//
+     /$1/p" syscall.lst |
 while read num name
 do
 cat <<EOF > $name.s
--- a/src/libc/arch/arm32/Makefile
+++ b/src/libc/arch/arm32/Makefile
@@ -3,10 +3,13 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../rules.mk
 
-OBJS = longjmp.o setjmp.o
+OBJS = longjmp.$O setjmp.$O
 DIRS = linux
 
-all: $(OBJS) $(SYS)
+all: $(LIBC) $(SYS)
+
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
 $(SYS): FORCE
 	+@cd $@ && $(MAKE)
--- a/src/libc/arch/arm32/linux/Makefile
+++ b/src/libc/arch/arm32/linux/Makefile
@@ -3,38 +3,42 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS  = _Exit.o \
-        _close.o \
-        _brk.o \
-        _getpid.o \
-        _kill.o \
-        _lseek.o \
-        _openat.o \
-        _read.o \
-        _write.o \
-        _getheap.o \
-        _cerrno.o \
-        _open.o \
-        _sigaction.o \
-        _tzone.o \
-        getenv.o \
-        raise.o \
-        signal.o \
-        time.o \
-        _sys_errlist.o \
-        crt.o \
+GENOBJS =\
+	_Exit.$O\
+	_close.$O\
+	_brk.$O\
+	_getpid.$O\
+	_kill.$O\
+	_lseek.$O\
+	_openat.$O\
+	_read.$O\
+	_write.$O\
+	_sigaction.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS =\
+	$(GENOBJS)\
+	_cerrno.$O\
+	_getheap.$O\
+	_open.$O\
+	_tzone.$O\
+	getenv.$O\
+	raise.$O\
+	signal.$O\
+	time.$O\
+	_sys_errlist.$O\
 
+all: $(LIBC) $(CRT)
+
+$(LIBCLST): $(OBJS)
+	$(MKLST)
+
 crt.o: ../crt-posix.s
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+$(GENSRC): syscall.lst
+	gensys.sh $*
 
 clean:
-	rm -f `awk '/[0-9]*	_/ {print $$2".s"}' syscall.lst`
+	rm -f $(GENSRC)
 	rm -f syscall _sys_errlist.c
--- a/src/libc/arch/arm32/linux/gensys.sh
+++ b/src/libc/arch/arm32/linux/gensys.sh
@@ -1,7 +1,8 @@
 #!/bin/sh
 
-sed 's/[ 	]*#.*//
-     /^$/d' syscall.lst |
+sed -n "
+     s/[ 	]*#.*//
+     /$1/p" syscall.lst |
 while read num name
 do
 cat <<EOF > $name.s
--- a/src/libc/arch/arm64/Makefile
+++ b/src/libc/arch/arm64/Makefile
@@ -3,10 +3,13 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../rules.mk
 
-OBJS = longjmp.o setjmp.o
+OBJS = longjmp.$O setjmp.$O
 DIRS = linux
 
-all: $(OBJS) $(SYS)
+all: $(LIBC) $(SYS)
+
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
 $(SYS): FORCE
 	+@cd $@ && $(MAKE)
--- a/src/libc/arch/i386/Makefile
+++ b/src/libc/arch/i386/Makefile
@@ -3,10 +3,13 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../rules.mk
 
-OBJS = longjmp.o setjmp.o
+OBJS = longjmp.$O setjmp.$O
 DIRS = linux
 
-all: $(OBJS) $(SYS)
+all: $(LIBC) $(SYS)
+
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
 $(SYS): FORCE
 	+@cd $@ && $(MAKE)
--- a/src/libc/arch/i386/linux/Makefile
+++ b/src/libc/arch/i386/linux/Makefile
@@ -3,40 +3,42 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../../../rules.mk
 
-OBJS 	=\
-	_Exit.o\
-	_close.o\
-	_open.o\
-	_read.o\
-	_write.o\
-	_lseek.o\
-	_brk.o\
-	_sigaction.o\
-	_getpid.o\
-	_Exit.o\
-	_kill.o\
-	_getheap.o\
-	crt.o\
-	signal.o\
-	raise.o\
-	_cerrno.o\
-	signal.o
+GENOBJS =\
+	_Exit.$O\
+	_close.$O\
+	_open.$O\
+	_read.$O\
+	_write.$O\
+	_lseek.$O\
+	_brk.$O\
+	_sigaction.$O\
+	_getpid.$O\
+	_kill.$O\
 
-all: syscall
-	$(MAKE) objs
+GENSRC = $(GENOBJS:.$O=.s)
 
-objs: $(OBJS)
+OBJS =\
+	$(GENOBJS)\
+	signal.$O\
+	raise.$O\
+	_getheap.$O\
+	_cerrno.$O\
+	signal.$O
 
-crt.o:	../crt-posix.s
+all: $(LIBC) $(CRT)
 
-raise.o:	../../posix/raise.c
+$(LIBCLST): $(OBJS)
+	$(MKLST)
 
-signal.o:	../../posix/signal.c
+crt.o: ../crt-posix.s
 
-syscall: syscall.lst
-	gensys.sh syscall.lst
-	touch syscall
+raise.o: ../../posix/raise.c
 
+signal.o: ../../posix/signal.c
+
+$(GENSRC): syscall.lst
+	gensys.sh $*
+
 clean:
-	rm -f `awk '/[0-9]*\t/{print $$2".s"}' syscall.lst`
+	rm -f $(GENSRC)
 	rm -f syscall _sys_errlist.c
--- a/src/libc/arch/i386/linux/gensys.sh
+++ b/src/libc/arch/i386/linux/gensys.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-awk '/^[0-9]*\t/ {
+awk '! /^#/ && $2 == "'$1'" {
 	syscall=$2
 	fname=$2".s"
 	noper=$3
@@ -14,18 +14,18 @@
 	       "\tpushl\t%%esi\n\n",
 	       "\tpushl\t%%edi\n"
 	       "\tmovl\t%%esp,%%ebp\n"
-	       syscall, syscall > fname
+	       syscall, syscall
 
 	if (noper > 0)
-		printf "\tmovl\t20(%%ebp),%%ebx\n" >> fname
+		printf "\tmovl\t20(%%ebp),%%ebx\n"
 	if (noper > 1)
-		printf "\tmovl\t24(%%ebp),%%ecx\n" >> fname
+		printf "\tmovl\t24(%%ebp),%%ecx\n"
 	if (noper > 2)
-		printf "\tmovl\t28(%%ebp),%%edx\n" >> fname
+		printf "\tmovl\t28(%%ebp),%%edx\n"
 	if (noper > 3)
-		printf "\tmovl\t28(%%ebp),%%esi\n" >> fname
+		printf "\tmovl\t28(%%ebp),%%esi\n"
 	if (noper > 4)
-		printf "\tmovl\t28(%%ebp),%%edi\n" >> fname
+		printf "\tmovl\t28(%%ebp),%%edi\n"
 
 	printf "\tmovl\t$%d,%%eax\n"
 	       "\tint\t$0x80\n"
@@ -33,6 +33,6 @@
 	       "\tpopl\t%%esi\n"
 	       "\tpopl\t%%ebx\n"
 	       "\tpopl\t%%ebp\n"
-	       "\tjmp\t_cerrno\n", $1 >> fname
+	       "\tjmp\t_cerrno\n", $1
 
-} ' syscall.lst
+} ' syscall.lst > $1.s
--- a/src/libc/assert/Makefile
+++ b/src/libc/assert/Makefile
@@ -3,7 +3,8 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = __assert.o\
-       assert.o\
+OBJS =\
+	__assert.$O\
+	assert.$O\
 
 all: $(OBJS)
--- a/src/libc/ctype/Makefile
+++ b/src/libc/ctype/Makefile
@@ -3,22 +3,26 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = ctype.o\
-       isalnum.o\
-       isalpha.o\
-       isascii.o\
-       isblank.o\
-       iscntrl.o\
-       isdigit.o\
-       isgraph.o\
-       islower.o\
-       isprint.o\
-       ispunct.o\
-       isspace.o\
-       isupper.o\
-       isxdigit.o\
-       toascii.o\
-       tolower.o\
-       toupper.o\
+OBJS =\
+	ctype.$O\
+	isalnum.$O\
+	isalpha.$O\
+	isascii.$O\
+	isblank.$O\
+	iscntrl.$O\
+	isdigit.$O\
+	isgraph.$O\
+	islower.$O\
+	isprint.$O\
+	ispunct.$O\
+	isspace.$O\
+	isupper.$O\
+	isxdigit.$O\
+	toascii.$O\
+	tolower.$O\
+	toupper.$O\
 
 all: $(OBJS)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)
--- a/src/libc/locale/Makefile
+++ b/src/libc/locale/Makefile
@@ -3,7 +3,11 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = localeconv.o\
-       setlocale.o\
+OBJS =\
+	localeconv.$O\
+	setlocale.$O\
 
 all: $(OBJS)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)
--- a/src/libc/mklst
+++ /dev/null
@@ -1,9 +1,0 @@
-#!/bin/sh
-
-set -e
-
-rm -f $1
-trap 'r=$?;rm -f $$.tmp;exit $r' HUP EXIT QUIT TERM
-
-(echo OBJS=\\
- find . -name '*.o' | sed 's/$/\\/') > $$.tmp && mv $$.tmp $1
--- a/src/libc/rules.mk
+++ b/src/libc/rules.mk
@@ -1,6 +1,68 @@
-INCLUDE    = -I$(INCDIR) -I$(INCDIR)/bits/$(SYS) -I$(INCDIR)/bits/$(ARCH)
+INCLUDE  =\
+	-I$(INCDIR)\
+	-I$(INCDIR)/bits/$(SYS)\
+	-I$(INCDIR)/bits/$(ARCH)\
 
 SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h
 
+LIBC = $(LIBCDIR)/libc.a
+CRT = $(LIBCDIR)/libcrt.o
+LIBCLST= $(PROJECTDIR)/src/libc/libc.lst
+
+MKLST = \
+	echo $?  |\
+	tr ' ' '\n' |\
+	tr -s '\n' |\
+	sed 's@^@$(PWD)/@' >> $(LIBCLST)
+
+# Rules
+
+.SUFFIXES: .6 .7 .8 .z
+
 _sys_errlist.c: $(SYSERRNO)
 	../../mkerrstr $(SYSERRNO)
+
+$(LIBC): $(LIBCLST)
+
+$(CRT): crt.$O
+	cp crt.$O $@
+
+clean: clean-libc
+
+clean-libc: FORCE
+	rm -f *.6 *.7 *.8 *.z
+
+# amd64-posix objects
+.c.6:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.s.6:
+	$(AS) $(SCC_ASFLAGS) $< -o $@
+
+# amd64-darwin objects
+.c.6d:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.s.6d:
+	$(AS) $(SCC_ASFLAGS) $< -o $@
+
+# arm64-posix objects
+.c.7:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.s.7:
+	$(AS) $(SCC_ASFLAGS) $< -o $@
+
+# 386-posix objects
+.c.8:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.s.8:
+	$(AS) $(SCC_ASFLAGS) $< -o $@
+
+# z80 objects
+.c.z:
+	$(CC) $(SCC_CFLAGS) -o $@ -c $<
+
+.s.z:
+	$(AS) $(SCC_ASFLAGS) $< -o $@
--- a/src/libc/stdio/Makefile
+++ b/src/libc/stdio/Makefile
@@ -3,44 +3,48 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = __getc.o\
-       __putc.o\
-       _flsbuf.o\
-       _fpopen.o\
-       clearerr.o\
-       fclose.o\
-       feof.o\
-       ferror.o\
-       fgetc.o\
-       fgets.o\
-       fopen.o\
-       fprintf.o\
-       fputc.o\
-       fputs.o\
-       fread.o\
-       freopen.o\
-       fseek.o\
-       ftell.o\
-       fwrite.o\
-       getc.o\
-       getchar.o\
-       gets.o\
-       perror.o\
-       printf.o\
-       putc.o\
-       putchar.o\
-       puts.o\
-       rewind.o\
-       setbuf.o\
-       setvbuf.o\
-       snprintf.o\
-       sprintf.o\
-       __iob.o\
-       tmpnam.o\
-       vfprintf.o\
-       vsnprintf.o\
-       vsprintf.o\
-       vprintf.o\
-       _allocbuf.o\
+OBJS =\
+	__getc.o\
+	__putc.$O\
+	_flsbuf.$O\
+	_fpopen.$O\
+	clearerr.$O\
+	fclose.$O\
+	feof.$O\
+	ferror.$O\
+	fgetc.$O\
+	fgets.$O\
+	fopen.$O\
+	fprintf.$O\
+	fputc.$O\
+	fputs.$O\
+	fread.$O\
+	freopen.$O\
+	fseek.$O\
+	ftell.$O\
+	fwrite.$O\
+	getc.$O\
+	getchar.$O\
+	gets.$O\
+	perror.$O\
+	printf.$O\
+	putc.$O\
+	putchar.$O\
+	puts.$O\
+	rewind.$O\
+	setbuf.$O\
+	setvbuf.$O\
+	snprintf.$O\
+	sprintf.$O\
+	__iob.$O\
+	tmpnam.$O\
+	vfprintf.$O\
+	vsnprintf.$O\
+	vsprintf.$O\
+	vprintf.$O\
+	_allocbuf.$O\
 
 all: $(OBJS)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)
--- a/src/libc/stdlib/Makefile
+++ b/src/libc/stdlib/Makefile
@@ -3,26 +3,30 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = _dtoi.o\
-       abort.o\
-       abs.o\
-       atexit.o\
-       atoi.o\
-       atol.o\
-       atoll.o\
-       bsearch.o\
-       calloc.o\
-       errno.o\
-       exit.o\
-       labs.o\
-       llabs.o\
-       malloc.o\
-       qsort.o\
-       rand.o\
-       realloc.o\
-       strtol.o\
-       strtoll.o\
-       strtoul.o\
-       strtoull.o\
+OBJS =\
+	_dtoi.$O\
+	abort.$O\
+	abs.$O\
+	atexit.$O\
+	atoi.$O\
+	atol.$O\
+	atoll.$O\
+	bsearch.$O\
+	calloc.$O\
+	errno.$O\
+	exit.$O\
+	labs.$O\
+	llabs.$O\
+	malloc.$O\
+	qsort.$O\
+	rand.$O\
+	realloc.$O\
+	strtol.$O\
+	strtoll.$O\
+	strtoul.$O\
+	strtoull.$O\
 
 all: $(OBJS)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)
--- a/src/libc/string/Makefile
+++ b/src/libc/string/Makefile
@@ -3,28 +3,32 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = memchr.o\
-       memcmp.o\
-       memcpy.o\
-       memmove.o\
-       memset.o\
-       strcat.o\
-       strchr.o\
-       strcmp.o\
-       strcoll.o\
-       strcpy.o\
-       strcspn.o\
-       strerror.o\
-       strlen.o\
-       strncat.o\
-       strncmp.o\
-       strncpy.o\
-       strnlen.o\
-       strpbrk.o\
-       strrchr.o\
-       strspn.o\
-       strstr.o\
-       strtok.o\
-       strxfrm.o\
+OBJS = \
+	memchr.$O\
+	memcmp.$O\
+	memcpy.$O\
+	memmove.$O\
+	memset.$O\
+	strcat.$O\
+	strchr.$O\
+	strcmp.$O\
+	strcoll.$O\
+	strcpy.$O\
+	strcspn.$O\
+	strerror.$O\
+	strlen.$O\
+	strncat.$O\
+	strncmp.$O\
+	strncpy.$O\
+	strnlen.$O\
+	strpbrk.$O\
+	strrchr.$O\
+	strspn.$O\
+	strstr.$O\
+	strtok.$O\
+	strxfrm.$O\
 
-all: $(OBJS)
+all: $(LIBC)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)
--- a/src/libc/time/Makefile
+++ b/src/libc/time/Makefile
@@ -3,13 +3,17 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-OBJS = _daysyear.o\
-       asctime.o\
-       ctime.o\
-       difftime.o\
-       gmtime.o\
-       localtime.o\
-       mktime.o\
-       strftime.o\
+OBJS =\
+	_daysyear.$O\
+	asctime.$O\
+	ctime.$O\
+	difftime.$O\
+	gmtime.$O\
+	localtime.$O\
+	mktime.$O\
+	strftime.$O\
 
 all: $(OBJS)
+
+$(LIBC): $(OBJS)
+	$(MKLIB)