shithub: scc

Download patch

ref: b69371a0b166e409a3571cf987f74b4a187564f0
parent: bd49f398995ad7da3198d1a3d3309591dd23c9ee
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun May 30 12:43:03 EDT 2021

build: Simplify the libc build system

The build system was too complex and needed several layers
of recursive Makefiles. This new version tries to simplify
it just using a list of objects predefined, instead of
trying to generate it dynamically.

--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@
 include $(PROJECTDIR)/scripts/rules.mk
 
 PREFIX= /usr/local
+NODEP = 1
 
 all:
 	+@$(MAKE) `$(SCRIPTDIR)/config` toolchain
@@ -28,20 +29,11 @@
 	xargs mkdir -p < $(SCRIPTDIR)/libc-proto
 	touch dirs
 
-dep:
-	$(FORALL)
-
 install: all
 	$(SCRIPTDIR)/install $(PREFIX)
 
-distclean: clean
-	$(MAKE) $(ENVIRON)
-	$(FORALL)
-	rm -f $(ENVIRON)
-
-clean: $(ENVIRON)
-	$(FORALL)
+clean:
 	xargs rm -rf < $(SCRIPTDIR)/libc-proto
-	rm -f dirs $(ENVIRON)
+	rm -f dirs
 
 tests: all
--- a/include/scc/scc/Makefile
+++ b/include/scc/scc/Makefile
@@ -10,6 +10,8 @@
 	syslibs.h\
 	cstd.h\
 
+NODEP = 1
+
 all: $(SYSHDR)
 
 cstd.h: cstd-$(STD).h
@@ -27,5 +29,5 @@
 syslibs.h:
 	cp syslibs.def.h $@
 
-distclean:
+clean:
 	rm -f $(SYSHDR)
--- a/scripts/rules.mk
+++ b/scripts/rules.mk
@@ -18,6 +18,7 @@
 BUILDDIR  = $(PROJECTDIR)/scripts/build
 CRTDIR    = $(PROJECTDIR)/lib/scc
 LIBCDIR   = $(CRTDIR)/$(ARCH)-$(SYS)
+MKDEP     = $(SCRIPTDIR)/mkdep
 
 # library dependences helpers
 LIBMACH = $(LIBDIR)/scc/libmach.a
@@ -95,13 +96,11 @@
 
 # helper macro to run over all the directories
 FORALL = +@set -e ;\
-	pwd=$$PWD; \
-	. $(ENVIRON); \
 	for i in $(DIRS); \
 	do \
 		cd $$i; \
 		$(MAKE) $@; \
-		cd $$pwd; \
+		cd -; \
 	done
 
 $(DIRS): FORCE
@@ -198,10 +197,10 @@
 	done
 
 clean-files:
-	rm -f *.i *.d *.o *.a *.ko *.elf $(TARGET)
-	rm -f *.csmes *.csexe
+	rm -f *.i *.d *.o *.a *.elf $(TARGET)
 
-dep:
+dep: inc-dep
+	$(FORALL)
 
 inc-dep: FORCE
-	mkdep
+	test -n "$(NODEP)" || $(MKDEP)
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,9 +12,8 @@
 PROJECTDIR = ..
 include $(PROJECTDIR)/scripts/rules.mk
 
+NODEP = 1
+
 all: cmd
 
 cmd: $(LIBS)
-
-dep clean:
-	$(FORALL)
--- a/src/cmd/Makefile
+++ b/src/cmd/Makefile
@@ -44,9 +44,4 @@
 $(BINDIR)/ar: ar.o $(DRIVER).o
 	$(CC) $(PROJ_LDFLAGS) ar.o $(DRIVER).o -o $@
 
-dep: inc-dep
-
-dep clean:
-	$(FORALL)
-
 include deps.mk
--- a/src/cmd/as/Makefile
+++ b/src/cmd/as/Makefile
@@ -24,8 +24,6 @@
 
 $(TARGET): $(LIBSCC)
 
-dep: inc-dep
-
 clean:
 	rm -f target/*/*.o target/*/*tbl.c
 
--- a/src/cmd/cc/Makefile
+++ b/src/cmd/cc/Makefile
@@ -8,7 +8,6 @@
 PROJECTDIR = ../../..
 include $(PROJECTDIR)/scripts/rules.mk
 
-all: $(DIRS)
+NODEP = 1
 
-dep clean:
-	$(FORALL)
+all: $(DIRS)
--- a/src/cmd/cc/cc1/Makefile
+++ b/src/cmd/cc/cc1/Makefile
@@ -30,6 +30,4 @@
 $(TARGET): $(LIBSCC) $(OBJS)
 	$(CC) $(PROJ_LDFLAGS) $(OBJS) -lscc -o $@
 
-dep: inc-dep
-
 include deps.mk
--- a/src/cmd/cc/cc2/Makefile
+++ b/src/cmd/cc/cc2/Makefile
@@ -29,8 +29,6 @@
 	trap 'r=$?;rm -f $$$$.h;exit $r' EXIT INT QUIT ;\
 	awk -f generror.awk cc2.h > $$$$.h && mv $$$$.h $@
 
-dep: inc-dep
-
 clean:
 	rm -f target/*/*.o error.h
 
--- a/src/cmd/cc/posix/Makefile
+++ b/src/cmd/cc/posix/Makefile
@@ -29,8 +29,6 @@
 config.h:
 	PREFIX=$(PREFIX) ./mkconf $(SYSLST)
 
-dep: inc-dep
-
 clean:
 	rm -f scc scpp *.o
 	rm -f $(TARGETS)
--- a/src/cmd/deps.mk
+++ b/src/cmd/deps.mk
@@ -60,6 +60,12 @@
 ./as/target/x86/ins.o: $(INCDIR)/scc/scc/scc.h
 ./as/target/x86/ins.o: ./as/target/x86/../../as.h
 ./as/target/x86/ins.o: ./as/target/x86/proc.h
+./cc/cc1/amd64-sysv.o: $(INCDIR)/scc/scc/scc.h
+./cc/cc1/amd64-sysv.o: ./cc/cc1/cc1.h
+./cc/cc1/arch.o: $(INCDIR)/scc/scc/scc.h
+./cc/cc1/arch.o: ./cc/cc1/cc1.h
+./cc/cc1/arm64-sysv.o: $(INCDIR)/scc/scc/scc.h
+./cc/cc1/arm64-sysv.o: ./cc/cc1/cc1.h
 ./cc/cc1/builtin.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc1/builtin.o: ./cc/cc1/cc1.h
 ./cc/cc1/code.o: $(INCDIR)/scc/scc/scc.h
@@ -77,6 +83,8 @@
 ./cc/cc1/expr.o: ./cc/cc1/cc1.h
 ./cc/cc1/fold.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc1/fold.o: ./cc/cc1/cc1.h
+./cc/cc1/i386-sysv.o: $(INCDIR)/scc/scc/scc.h
+./cc/cc1/i386-sysv.o: ./cc/cc1/cc1.h
 ./cc/cc1/init.o: $(INCDIR)/scc/scc/cstd.h
 ./cc/cc1/init.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc1/init.o: ./cc/cc1/cc1.h
@@ -92,17 +100,11 @@
 ./cc/cc1/symbol.o: $(INCDIR)/scc/scc/cstd.h
 ./cc/cc1/symbol.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc1/symbol.o: ./cc/cc1/cc1.h
-./cc/cc1/target/amd64-sysv/arch.o: $(INCDIR)/scc/scc/scc.h
-./cc/cc1/target/amd64-sysv/arch.o: ./cc/cc1/target/amd64-sysv/../../cc1.h
-./cc/cc1/target/arm64-sysv/arch.o: $(INCDIR)/scc/scc/scc.h
-./cc/cc1/target/arm64-sysv/arch.o: ./cc/cc1/target/arm64-sysv/../../cc1.h
-./cc/cc1/target/i386-sysv/arch.o: $(INCDIR)/scc/scc/scc.h
-./cc/cc1/target/i386-sysv/arch.o: ./cc/cc1/target/i386-sysv/../../cc1.h
-./cc/cc1/target/z80-scc/arch.o: $(INCDIR)/scc/scc/scc.h
-./cc/cc1/target/z80-scc/arch.o: ./cc/cc1/target/z80-scc/../../cc1.h
 ./cc/cc1/types.o: $(INCDIR)/scc/scc/cstd.h
 ./cc/cc1/types.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc1/types.o: ./cc/cc1/cc1.h
+./cc/cc1/z80-scc.o: $(INCDIR)/scc/scc/scc.h
+./cc/cc1/z80-scc.o: ./cc/cc1/cc1.h
 ./cc/cc2/code.o: $(INCDIR)/scc/scc/scc.h
 ./cc/cc2/code.o: ./cc/cc2/cc2.h
 ./cc/cc2/main.o: $(INCDIR)/scc/scc/arg.h
--- a/src/cmd/ld/Makefile
+++ b/src/cmd/ld/Makefile
@@ -19,9 +19,4 @@
 $(TARGET): $(OBJS) $(LIBMACH) $(LIBSCC)
 	$(CC) $(PROJ_LDFLAGS) $(OBJS) -lmach -lscc -o $@
 
-dep: inc-dep
-
-clean:
-	rm -f $(OBJS)
-
 include deps.mk
--- a/src/libc/.gitignore
+++ b/src/libc/.gitignore
@@ -3,4 +3,4 @@
 *.8
 *.z
 *.q
-libc.lst
+*.6d
--- a/src/libc/Makefile
+++ b/src/libc/Makefile
@@ -1,7 +1,7 @@
 .POSIX:
 
+PROJECTDIR = ../..
 DIRS =\
-	arch\
 	assert\
 	ctype\
 	locale\
@@ -9,23 +9,18 @@
 	stdlib\
 	string\
 	time\
+	arch\
 
-PROJECTDIR =../..
 include $(PROJECTDIR)/scripts/rules.mk
 include rules.mk
+include objs/$(ARCH)-$(SYS).mk
 
+NODEP = 1
+TARGET = $(LIBC)
 
-all: $(LIBC)
+all: $(DIRS)
+	$(MAKE) $(LIBC)
 
-$(LIBC): $(DIRS)
-	$(AR) $(PROJ_ARFLAGS) $@ `cat $(LIBCLST)`
-	$(RL) $(PROJ_RLFLAGS) $@
-
-rm-lst: FORCE
-	rm -f $(LIBCLST)
-
-dep:
-	$(FORALL)
-
-clean: rm-lst
-	$(FORALL)
+$(LIBC): $(OBJS)
+	$(AR) $(PROJ_ARFLAGS) $(LIBC) $?
+	$(RL) $(PROJ_RLFLAGS) $(LIBC)
--- a/src/libc/arch/Makefile
+++ b/src/libc/arch/Makefile
@@ -11,7 +11,6 @@
 include $(PROJECTDIR)/scripts/rules.mk
 include ../rules.mk
 
-all: $(ARCH)
+NODEP = 1
 
-dep clean:
-	$(FORALL)
+all: $(ARCH)
--- a/src/libc/arch/amd64/Makefile
+++ b/src/libc/arch/amd64/Makefile
@@ -14,22 +14,8 @@
 OBJS =\
 	longjmp.$O\
 	setjmp.$O\
-	memchr.$O\
-	memcmp.$O\
 	memcpy.$O\
-	memmove.$O\
-	memset.$O\
 
-all: $(LIBC) $(SYS)
-
-$(LIBC): $(LIBCLST)
-
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
-
-dep clean:
-	$(FORALL)
+all: $(OBJS) $(SYS)
 
 include deps.mk
--- a/src/libc/arch/amd64/darwin/Makefile
+++ b/src/libc/arch/amd64/darwin/Makefile
@@ -20,26 +20,16 @@
 OBJS  =\
 	$(GENOBJS)\
 	_getheap.$O\
-	_tzone.$O\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
 	_sys_errlist.$O\
 
 # Rules
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/amd64/darwin/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/amd64/darwin/deps.mk
+++ b/src/libc/arch/amd64/darwin/deps.mk
@@ -1,6 +1,1 @@
 #deps
-./_tzone.o: ./../../posix/_tzone.c
-./getenv.o: ./../../posix/getenv.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
-./time.o: ./../../posix/time.c
--- a/src/libc/arch/amd64/darwin/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/amd64/darwin/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/amd64/darwin/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/amd64/darwin/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/amd64/deps.mk
+++ b/src/libc/arch/amd64/deps.mk
@@ -1,34 +1,1 @@
 #deps
-./darwin/_tzone.o: ./darwin/../../posix/_tzone.c
-./darwin/getenv.o: ./darwin/../../posix/getenv.c
-./darwin/raise.o: ./darwin/../../posix/raise.c
-./darwin/signal.o: ./darwin/../../posix/signal.c
-./darwin/time.o: ./darwin/../../posix/time.c
-./dragonfly/_getheap.o: ./dragonfly/../../posix/_getheap.c
-./dragonfly/_tzone.o: ./dragonfly/../../posix/_tzone.c
-./dragonfly/getenv.o: ./dragonfly/../../posix/getenv.c
-./dragonfly/raise.o: ./dragonfly/../../posix/raise.c
-./dragonfly/signal.o: ./dragonfly/../../posix/signal.c
-./dragonfly/time.o: ./dragonfly/../../posix/time.c
-./linux/_getheap.o: ./linux/../../linux/_getheap.c
-./linux/_tzone.o: ./linux/../../posix/_tzone.c
-./linux/getenv.o: ./linux/../../posix/getenv.c
-./linux/raise.o: ./linux/../../posix/raise.c
-./linux/signal.o: ./linux/../../posix/signal.c
-./linux/time.o: ./linux/../../posix/time.c
-./memchr.o: ./../../string/memchr.c
-./memcmp.o: ./../../string/memcmp.c
-./memmove.o: ./../../string/memmove.c
-./memset.o: ./../../string/memset.c
-./netbsd/_getheap.o: ./netbsd/../../posix/_getheap.c
-./netbsd/_tzone.o: ./netbsd/../../posix/_tzone.c
-./netbsd/getenv.o: ./netbsd/../../posix/getenv.c
-./netbsd/raise.o: ./netbsd/../../posix/raise.c
-./netbsd/signal.o: ./netbsd/../../posix/signal.c
-./netbsd/time.o: ./netbsd/../../posix/time.c
-./openbsd/_getheap.o: ./openbsd/../../posix/_getheap.c
-./openbsd/_tzone.o: ./openbsd/../../posix/_tzone.c
-./openbsd/getenv.o: ./openbsd/../../posix/getenv.c
-./openbsd/raise.o: ./openbsd/../../posix/raise.c
-./openbsd/signal.o: ./openbsd/../../posix/signal.c
-./openbsd/time.o: ./openbsd/../../posix/time.c
--- a/src/libc/arch/amd64/dragonfly/Makefile
+++ b/src/libc/arch/amd64/dragonfly/Makefile
@@ -19,28 +19,16 @@
 
 OBJS =\
 	$(GENOBJS)\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
-	_getheap.$O\
-	_sigaction.$O\
-	_tzone.$O\
 	_sys_errlist.$O\
 
 # Rules
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/amd64/dragonfly/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_getheap.c"
--- a/src/libc/arch/amd64/dragonfly/_sigaction.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <stddef.h>
-#include <sys.h>
-
-extern int _sigaction2(int sig,
-                       struct sigaction *new, struct sigaction *old,
-                       int siginfo[], int num);
-
-int
-_sigaction(int sig, struct sigaction *new, struct sigaction *old)
-{
-	extern int _setcontext[];
-
-	return _sigaction2(sig, new, old, _setcontext, 2);
-}
--- a/src/libc/arch/amd64/dragonfly/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/amd64/dragonfly/deps.mk
+++ b/src/libc/arch/amd64/dragonfly/deps.mk
@@ -1,7 +1,1 @@
 #deps
-./_getheap.o: ./../../posix/_getheap.c
-./_tzone.o: ./../../posix/_tzone.c
-./getenv.o: ./../../posix/getenv.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
-./time.o: ./../../posix/time.c
--- a/src/libc/arch/amd64/dragonfly/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/amd64/dragonfly/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/amd64/dragonfly/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/amd64/dragonfly/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/amd64/linux/Makefile
+++ b/src/libc/arch/amd64/linux/Makefile
@@ -23,29 +23,17 @@
 
 OBJS  = \
 	$(GENOBJS)\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
-	clock.$O\
 	_cerrno.$O\
-	_getheap.$O\
-	_tzone.$O\
 	_sys_errlist.$O\
 
 # Rules
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/amd64/linux/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../linux/_getheap.c"
--- a/src/libc/arch/amd64/linux/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/amd64/linux/clock.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/clock.c"
--- a/src/libc/arch/amd64/linux/deps.mk
+++ b/src/libc/arch/amd64/linux/deps.mk
@@ -1,7 +1,1 @@
 #deps
-./_getheap.o: ./../../linux/_getheap.c
-./_tzone.o: ./../../posix/_tzone.c
-./getenv.o: ./../../posix/getenv.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
-./time.o: ./../../posix/time.c
--- a/src/libc/arch/amd64/linux/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/amd64/linux/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/amd64/linux/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/amd64/linux/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/amd64/memchr.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memchr.c"
--- a/src/libc/arch/amd64/memcmp.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcmp.c"
--- a/src/libc/arch/amd64/memmove.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memmove.c"
--- a/src/libc/arch/amd64/memset.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memset.c"
--- a/src/libc/arch/amd64/netbsd/Makefile
+++ b/src/libc/arch/amd64/netbsd/Makefile
@@ -19,28 +19,16 @@
 
 OBJS =\
 	$(GENOBJS)\
-	_getheap.$O\
 	_setcontext.$O\
-	_sigaction.$O\
 	_sigaction2.$O\
-	_tzone.$O\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
 	_sys_errlist.$O\
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s ../netbsd/crt.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-deps: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/amd64/netbsd/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_getheap.c"
--- a/src/libc/arch/amd64/netbsd/_sigaction.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <stddef.h>
-#include <sys.h>
-
-extern int _sigaction2(int sig,
-                       struct sigaction *new, struct sigaction *old,
-                       int siginfo[], int num);
-
-int
-_sigaction(int sig, struct sigaction *new, struct sigaction *old)
-{
-	extern int _setcontext[];
-
-	return _sigaction2(sig, new, old, _setcontext, 2);
-}
--- a/src/libc/arch/amd64/netbsd/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/amd64/netbsd/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/amd64/netbsd/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/amd64/netbsd/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/amd64/netbsd/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/amd64/openbsd/Makefile
+++ b/src/libc/arch/amd64/openbsd/Makefile
@@ -14,18 +14,12 @@
 	_read.$O\
 	_write.$O\
 	_brk.$O\
-	_sigaction.$O\
+	_sigaction2.$O\
 
 GENSRC = $(GENOBJS:.$O=.s)
 
 OBJS =\
 	$(GENOBJS)\
-	_getheap.$O\
-	_tzone.$O\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
 	_sys_errlist.$O\
 
 all: $(LIBC) $(CRT)
@@ -37,8 +31,6 @@
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/amd64/openbsd/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_getheap.c"
--- a/src/libc/arch/amd64/openbsd/_sigaction.c
+++ /dev/null
@@ -1,14 +1,0 @@
-#include <stddef.h>
-#include <sys.h>
-
-extern int _sigaction2(int sig,
-                       struct sigaction *new, struct sigaction *old,
-                       int siginfo[], int num);
-
-int
-_sigaction(int sig, struct sigaction *new, struct sigaction *old)
-{
-	extern int _setcontext[];
-
-	return _sigaction2(sig, new, old, _setcontext, 2);
-}
--- /dev/null
+++ b/src/libc/arch/amd64/openbsd/_sigaction2.s
@@ -1,0 +1,12 @@
+	.file	"_sigaction2.s"
+
+	.globl	_sigaction2
+_sigaction2:
+	movq	$46,%rax
+	syscall
+	jb	1f
+	retq
+
+1:	movq	%rax,(errno)
+	movq	$-1,%rax
+	retq
--- a/src/libc/arch/amd64/openbsd/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/amd64/openbsd/deps.mk
+++ b/src/libc/arch/amd64/openbsd/deps.mk
@@ -1,7 +1,1 @@
 #deps
-./_getheap.o: ./../../posix/_getheap.c
-./_tzone.o: ./../../posix/_tzone.c
-./getenv.o: ./../../posix/getenv.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
-./time.o: ./../../posix/time.c
--- a/src/libc/arch/amd64/openbsd/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/amd64/openbsd/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/amd64/openbsd/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/amd64/openbsd/syscall.lst
+++ b/src/libc/arch/amd64/openbsd/syscall.lst
@@ -6,6 +6,6 @@
 6	_close
 17	_brk
 20	_getpid
-46	_sigaction
+46	_sigaction2
 122	_kill
 198	_lseek
--- a/src/libc/arch/amd64/openbsd/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/arm/Makefile
+++ b/src/libc/arch/arm/Makefile
@@ -10,22 +10,7 @@
 OBJS =\
 	longjmp.$O\
 	setjmp.$O\
-	memchr.$O\
-	memcmp.$O\
-	memcpy.$O\
-	memmove.$O\
-	memset.$O\
 
-all: $(LIBC) $(SYS)
-
-$(LIBC): $(LIBCLST)
-
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
-
-dep clean:
-	$(FORALL)
+all: $(OBJS) $(SYS)
 
 include deps.mk
--- a/src/libc/arch/arm/deps.mk
+++ b/src/libc/arch/arm/deps.mk
@@ -1,13 +1,1 @@
 #deps
-./linux/_getheap.o: ./linux/../../linux/_getheap.c
-./linux/_open.o: ./linux/../../../syscall.h
-./linux/_tzone.o: ./linux/../../posix/_tzone.c
-./linux/getenv.o: ./linux/../../posix/getenv.c
-./linux/raise.o: ./linux/../../posix/raise.c
-./linux/signal.o: ./linux/../../posix/signal.c
-./linux/time.o: ./linux/../../posix/time.c
-./memchr.o: ./../../string/memchr.c
-./memcmp.o: ./../../string/memcmp.c
-./memcpy.o: ./../../string/memcpy.c
-./memmove.o: ./../../string/memmove.c
-./memset.o: ./../../string/memset.c
--- a/src/libc/arch/arm/linux/Makefile
+++ b/src/libc/arch/arm/linux/Makefile
@@ -21,26 +21,14 @@
 OBJS =\
 	$(GENOBJS)\
 	_cerrno.$O\
-	_getheap.$O\
-	_open.$O\
-	_tzone.$O\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
 	_sys_errlist.$O\
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.o: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/arm/linux/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../linux/_getheap.c"
--- a/src/libc/arch/arm/linux/_open.c
+++ /dev/null
@@ -1,13 +1,0 @@
-#include <stddef.h>
-
-#include "../../../syscall.h"
-
-#define AT_FDCWD  -100
-
-extern int _openat(int fd, const char *fname, int flags, int mode);
-
-int
-_open(const char *fname, int flags, int mode)
-{
-	return _openat(AT_FDCWD, fname, flags, mode);
-}
--- a/src/libc/arch/arm/linux/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- a/src/libc/arch/arm/linux/deps.mk
+++ b/src/libc/arch/arm/linux/deps.mk
@@ -1,8 +1,1 @@
 #deps
-./_getheap.o: ./../../linux/_getheap.c
-./_open.o: ./../../../syscall.h
-./_tzone.o: ./../../posix/_tzone.c
-./getenv.o: ./../../posix/getenv.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
-./time.o: ./../../posix/time.c
--- a/src/libc/arch/arm/linux/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/arm/linux/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/arm/linux/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/arm/linux/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/arm/memchr.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memchr.c"
--- a/src/libc/arch/arm/memcmp.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcmp.c"
--- a/src/libc/arch/arm/memcpy.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcpy.c"
--- a/src/libc/arch/arm/memmove.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memmove.c"
--- a/src/libc/arch/arm/memset.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memset.c"
--- a/src/libc/arch/arm64/Makefile
+++ b/src/libc/arch/arm64/Makefile
@@ -10,22 +10,7 @@
 OBJS =\
 	longjmp.$O\
 	setjmp.$O\
-	memchr.$O\
-	memcmp.$O\
-	memcpy.$O\
-	memmove.$O\
-	memset.$O\
 
-all: $(LIBC) $(SYS)
-
-$(LIBC): $(LIBCLST)
-
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
-
-clean:
-	$(FORALL)
+all: $(OBJS) $(SYS)
 
 include deps.mk
--- a/src/libc/arch/arm64/deps.mk
+++ b/src/libc/arch/arm64/deps.mk
@@ -1,13 +1,1 @@
 #deps
-./linux/_getheap.o: ./linux/../../linux/_getheap.c
-./linux/_open.o: ./linux/../../../syscall.h
-./linux/_tzone.o: ./linux/../../posix/_tzone.c
-./linux/getenv.o: ./linux/../../posix/getenv.c
-./linux/raise.o: ./linux/../../posix/raise.c
-./linux/signal.o: ./linux/../../posix/signal.c
-./linux/time.o: ./linux/../../posix/time.c
-./memchr.o: ./../../string/memchr.c
-./memcmp.o: ./../../string/memcmp.c
-./memcpy.o: ./../../string/memcpy.c
-./memmove.o: ./../../string/memmove.c
-./memset.o: ./../../string/memset.c
--- a/src/libc/arch/arm64/linux/Makefile
+++ b/src/libc/arch/arm64/linux/Makefile
@@ -20,20 +20,10 @@
 
 OBJS =\
 	$(GENOBJS)\
-	getenv.$O\
-	raise.$O\
-	signal.$O\
-	time.$O\
-	_tzone.$O\
-	_open.$O\
-	_getheap.$O\
 	_cerrno.$O\
 	_sys_errlist.$O\
 
-all: $(LIBC) $(CRT)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
+all: $(OBJS) $(CRT)
 
 crt.$O: ../crt-posix.s
 
--- a/src/libc/arch/arm64/linux/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../linux/_getheap.c"
--- a/src/libc/arch/arm64/linux/_open.c
+++ /dev/null
@@ -1,13 +1,0 @@
-#include <stddef.h>
-
-#include "../../../syscall.h"
-
-#define AT_FDCWD  -100
-
-extern int _openat(int fd, const char *fname, int flags, int mode);
-
-int
-_open(const char *fname, int flags, int mode)
-{
-	return _openat(AT_FDCWD, fname, flags, mode);
-}
--- a/src/libc/arch/arm64/linux/_tzone.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/_tzone.c"
--- /dev/null
+++ b/src/libc/arch/arm64/linux/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- a/src/libc/arch/arm64/linux/getenv.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/getenv.c"
--- a/src/libc/arch/arm64/linux/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/arm64/linux/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/arm64/linux/time.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/time.c"
--- a/src/libc/arch/arm64/memchr.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memchr.c"
--- a/src/libc/arch/arm64/memcmp.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcmp.c"
--- a/src/libc/arch/arm64/memcpy.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcpy.c"
--- a/src/libc/arch/arm64/memmove.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memmove.c"
--- a/src/libc/arch/arm64/memset.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memset.c"
--- /dev/null
+++ b/src/libc/arch/bsd/_sigaction.c
@@ -1,0 +1,14 @@
+#include <stddef.h>
+#include <sys.h>
+
+extern int _sigaction2(int sig,
+                       struct sigaction *new, struct sigaction *old,
+                       int siginfo[], int num);
+
+int
+_sigaction(int sig, struct sigaction *new, struct sigaction *old)
+{
+	extern int _setcontext[];
+
+	return _sigaction2(sig, new, old, _setcontext, 2);
+}
--- a/src/libc/arch/i386/Makefile
+++ b/src/libc/arch/i386/Makefile
@@ -10,22 +10,7 @@
 OBJS =\
 	longjmp.$O\
 	setjmp.$O\
-	memchr.$O\
-	memcmp.$O\
-	memcpy.$O\
-	memmove.$O\
-	memset.$O\
 
-all: $(LIBC) $(SYS)
-
-$(LIBC): $(LIBCLST)
-
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
-
-dep clean:
-	$(FORALL)
+all: $(OBJS) $(SYS)
 
 include deps.mk
--- a/src/libc/arch/i386/deps.mk
+++ b/src/libc/arch/i386/deps.mk
@@ -1,9 +1,1 @@
 #deps
-./linux/_getheap.o: ./linux/../../linux/_getheap.c
-./linux/raise.o: ./linux/../../posix/raise.c
-./linux/signal.o: ./linux/../../posix/signal.c
-./memchr.o: ./../../string/memchr.c
-./memcmp.o: ./../../string/memcmp.c
-./memcpy.o: ./../../../string/memcpy.c
-./memmove.o: ./../../string/memmove.c
-./memset.o: ./../../string/memset.c
--- a/src/libc/arch/i386/linux/Makefile
+++ b/src/libc/arch/i386/linux/Makefile
@@ -20,23 +20,15 @@
 
 OBJS =\
 	$(GENOBJS)\
-	signal.$O\
-	raise.$O\
-	_getheap.$O\
 	_cerrno.$O\
-	signal.$O
+	_sys_errlist.$O\
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/i386/linux/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../linux/_getheap.c"
--- a/src/libc/arch/i386/linux/deps.mk
+++ b/src/libc/arch/i386/linux/deps.mk
@@ -1,4 +1,1 @@
 #deps
-./_getheap.o: ./../../linux/_getheap.c
-./raise.o: ./../../posix/raise.c
-./signal.o: ./../../posix/signal.c
--- a/src/libc/arch/i386/linux/raise.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/raise.c"
--- a/src/libc/arch/i386/linux/signal.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../posix/signal.c"
--- a/src/libc/arch/i386/memchr.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memchr.c"
--- a/src/libc/arch/i386/memcmp.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcmp.c"
--- a/src/libc/arch/i386/memcpy.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../../string/memcpy.c"
--- a/src/libc/arch/i386/memmove.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memmove.c"
--- a/src/libc/arch/i386/memset.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memset.c"
--- /dev/null
+++ b/src/libc/arch/posix/_open.c
@@ -1,0 +1,13 @@
+#include <stddef.h>
+
+#include "../../../syscall.h"
+
+#define AT_FDCWD  -100
+
+extern int _openat(int fd, const char *fname, int flags, int mode);
+
+int
+_open(const char *fname, int flags, int mode)
+{
+	return _openat(AT_FDCWD, fname, flags, mode);
+}
--- a/src/libc/arch/posix/clock.c
+++ b/src/libc/arch/posix/clock.c
@@ -9,7 +9,6 @@
 	       r.ru_stime.tv_usec / (1000000 / CLOCKS_PER_SEC);
 }
 
-
 clock_t
 clock(void)
 {
--- a/src/libc/arch/posix/clock.h
+++ b/src/libc/arch/posix/clock.h
@@ -1,15 +1,6 @@
-#ifndef CLOCK_H
-#define CLOCK_H
-
-#include <time.h>
-
-#define RUSAGE_SELF	0
-
-typedef long int clock_t;
-
 struct timeval {
-	long int tv_sec;
-	long int tv_usec;
+	time_t tv_sec;
+	suseconds_t tv_usec;
 };
 
 struct rusage {
@@ -30,5 +21,3 @@
 	long int ru_nvcsw;
 	long int ru_nivcsw;
 };
-
-#endif
--- a/src/libc/arch/posix/time.c
+++ b/src/libc/arch/posix/time.c
@@ -1,12 +1,7 @@
 #include <time.h>
 
-struct timeval {
-	time_t tv_sec;
-	int tv_usec; /* TODO use a arch type */
-};
-
 int
-_gettimeofday(struct timeval * restrict tp, void * restrict tzp);
+_gettimeofday(struct timeval *restrict, void *tzp);
 
 time_t
 time(time_t *t)
--- a/src/libc/arch/ppc/Makefile
+++ b/src/libc/arch/ppc/Makefile
@@ -10,22 +10,7 @@
 OBJS =\
 	longjmp.$O\
 	setjmp.$O\
-	memchr.$O\
-	memcmp.$O\
-	memcpy.$O\
-	memmove.$O\
-	memset.$O\
 
-all: $(LIBC) $(SYS)
-
-$(LIBC): $(LIBCLST)
-
-$(LIBCLST): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
-
-dep clean:
-	$(FORALL)
+all: $(OBJS) $(SYS)
 
 include deps.mk
--- a/src/libc/arch/ppc/deps.mk
+++ b/src/libc/arch/ppc/deps.mk
@@ -1,7 +1,1 @@
 #deps
-./linux/_getheap.o: ./linux/../../linux/_getheap.c
-./memchr.o: ./../../string/memchr.c
-./memcmp.o: ./../../string/memcmp.c
-./memcpy.o: ./../../string/memcpy.c
-./memmove.o: ./../../string/memmove.c
-./memset.o: ./../../string/memset.c
--- a/src/libc/arch/ppc/linux/Makefile
+++ b/src/libc/arch/ppc/linux/Makefile
@@ -22,21 +22,15 @@
 OBJS  = \
 	$(GENOBJS)\
 	_cerrno.$O\
-	_getheap.$O\
 
 # Rules
 
-all: $(LIBC) $(CRT)
+all: $(OBJS) $(CRT)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
 crt.$O: ../crt-posix.s
 
 $(GENSRC): syscall.lst
 	./gensys.sh $(@:.s=)
-
-dep: inc-dep
 
 clean:
 	rm -f $(GENSRC)
--- a/src/libc/arch/ppc/linux/_getheap.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../linux/_getheap.c"
--- a/src/libc/arch/ppc/linux/deps.mk
+++ b/src/libc/arch/ppc/linux/deps.mk
@@ -1,2 +1,1 @@
 #deps
-./_getheap.o: ./../../linux/_getheap.c
--- a/src/libc/arch/ppc/memchr.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memchr.c"
--- a/src/libc/arch/ppc/memcmp.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcmp.c"
--- a/src/libc/arch/ppc/memcpy.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memcpy.c"
--- a/src/libc/arch/ppc/memmove.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memmove.c"
--- a/src/libc/arch/ppc/memset.c
+++ /dev/null
@@ -1,1 +1,0 @@
-#include "../../string/memset.c"
--- a/src/libc/assert/Makefile
+++ b/src/libc/assert/Makefile
@@ -7,11 +7,6 @@
 	__assert.$O\
 	assert.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- a/src/libc/ctype/Makefile
+++ b/src/libc/ctype/Makefile
@@ -22,11 +22,6 @@
 	tolower.$O\
 	toupper.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- a/src/libc/locale/Makefile
+++ b/src/libc/locale/Makefile
@@ -7,11 +7,6 @@
 	localeconv.$O\
 	setlocale.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- /dev/null
+++ b/src/libc/objs/amd64-darwin.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/amd64-dragonfly.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/amd64-linux.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/amd64-netbsd.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/amd64-openbsd.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/arm-linux.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/arm64-linux.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/common-objs.mk
@@ -1,0 +1,107 @@
+COMMON_OBJS =\
+	assert/__assert.$O\
+	assert/assert.$O\
+	ctype/ctype.$O\
+	ctype/isalnum.$O\
+	ctype/isalpha.$O\
+	ctype/isascii.$O\
+	ctype/isblank.$O\
+	ctype/iscntrl.$O\
+	ctype/isdigit.$O\
+	ctype/isgraph.$O\
+	ctype/islower.$O\
+	ctype/isprint.$O\
+	ctype/ispunct.$O\
+	ctype/isspace.$O\
+	ctype/isupper.$O\
+	ctype/isxdigit.$O\
+	ctype/toascii.$O\
+	ctype/tolower.$O\
+	ctype/toupper.$O\
+	locale/localeconv.$O\
+	locale/setlocale.$O\
+	stdio/__getc.$O\
+	stdio/__iob.$O\
+	stdio/__putc.$O\
+	stdio/_allocbuf.$O\
+	stdio/_flsbuf.$O\
+	stdio/_fpopen.$O\
+	stdio/clearerr.$O\
+	stdio/fclose.$O\
+	stdio/feof.$O\
+	stdio/ferror.$O\
+	stdio/fgetc.$O\
+	stdio/fgets.$O\
+	stdio/fopen.$O\
+	stdio/fprintf.$O\
+	stdio/fputc.$O\
+	stdio/fputs.$O\
+	stdio/fread.$O\
+	stdio/freopen.$O\
+	stdio/fseek.$O\
+	stdio/ftell.$O\
+	stdio/fwrite.$O\
+	stdio/getc.$O\
+	stdio/getchar.$O\
+	stdio/gets.$O\
+	stdio/perror.$O\
+	stdio/printf.$O\
+	stdio/putc.$O\
+	stdio/putchar.$O\
+	stdio/puts.$O\
+	stdio/remove.$O\
+	stdio/rewind.$O\
+	stdio/setbuf.$O\
+	stdio/setvbuf.$O\
+	stdio/snprintf.$O\
+	stdio/sprintf.$O\
+	stdio/tmpnam.$O\
+	stdio/vfprintf.$O\
+	stdio/vprintf.$O\
+	stdio/vsnprintf.$O\
+	stdio/vsprintf.$O\
+	stdlib/_dtoi.$O\
+	stdlib/abort.$O\
+	stdlib/abs.$O\
+	stdlib/atexit.$O\
+	stdlib/atoi.$O\
+	stdlib/atol.$O\
+	stdlib/atoll.$O\
+	stdlib/bsearch.$O\
+	stdlib/calloc.$O\
+	stdlib/errno.$O\
+	stdlib/exit.$O\
+	stdlib/labs.$O\
+	stdlib/llabs.$O\
+	stdlib/malloc.$O\
+	stdlib/qsort.$O\
+	stdlib/rand.$O\
+	stdlib/realloc.$O\
+	stdlib/strtol.$O\
+	stdlib/strtoll.$O\
+	stdlib/strtoul.$O\
+	stdlib/strtoull.$O\
+	string/strcat.$O\
+	string/strchr.$O\
+	string/strcmp.$O\
+	string/strcoll.$O\
+	string/strcpy.$O\
+	string/strcspn.$O\
+	string/strerror.$O\
+	string/strncat.$O\
+	string/strncmp.$O\
+	string/strncpy.$O\
+	string/strpbrk.$O\
+	string/strrchr.$O\
+	string/strspn.$O\
+	string/strstr.$O\
+	string/strtok.$O\
+	string/strxfrm.$O\
+	time/_daysyear.$O\
+	time/asctime.$O\
+	time/ctime.$O\
+	time/difftime.$O\
+	time/gmtime.$O\
+	time/localtime.$O\
+	time/mktime.$O\
+	time/strftime.$O\
--- /dev/null
+++ b/src/libc/objs/i386-linux.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/ppc-linux.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- /dev/null
+++ b/src/libc/objs/z80-msxdos.mk
@@ -1,0 +1,4 @@
+include objs/common-objs.mk
+
+OBJS =\
+	$(COMMON_OBJS)\
--- a/src/libc/rules.mk
+++ b/src/libc/rules.mk
@@ -1,23 +1,21 @@
+#MORE_CFLAGS = -I$(INCDIR)
+#LIBCDIR = $(PROJECTDIR)/src/libc
+
 CINCLUDES =\
 	-I$(INCDIR)\
 	-I$(INCDIR)/bits/$(SYS)\
 	-I$(INCDIR)/bits/$(ARCH)\
 
+MORE_ARFLAGS = -u
+
 SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h
 
 LIBC = $(LIBCDIR)/libc.a
 CRT = $(LIBCDIR)/crt.o
-LIBCLST= $(PROJECTDIR)/src/libc/libc.lst
 
-MKLST = \
-	echo $?  |\
-	tr ' ' '\n' |\
-	sed '/^$$/d' |\
-	sed 's@^@$(PWD)/@' >> $(LIBCLST)
-
 # Rules
 
-.SUFFIXES: .6 .7 .8 .z .q
+.SUFFIXES: .6 .7 .8 .z .q .6d
 
 _sys_errlist.c: $(SYSERRNO)
 	../../mkerrstr $(SYSERRNO)
@@ -28,7 +26,7 @@
 clean: clean-libc
 
 clean-libc: FORCE
-	rm -f *.6 *.7 *.8 *.z *.q
+	rm -f *.6d *.6 *.7 *.8 *.z *.q
 
 # amd64-posix objects
 .c.6:
--- a/src/libc/stdio/Makefile
+++ b/src/libc/stdio/Makefile
@@ -45,11 +45,6 @@
 	vprintf.$O\
 	_allocbuf.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- a/src/libc/stdio/deps.mk
+++ b/src/libc/stdio/deps.mk
@@ -16,5 +16,6 @@
 ./fseek.o: ./../libc.h
 ./fseek.o: ./../syscall.h
 ./ftell.o: ./../syscall.h
+./remove.o: ./../syscall.h
 ./setvbuf.o: ./../libc.h
 ./tmpnam.o: ./../syscall.h
--- a/src/libc/stdlib/Makefile
+++ b/src/libc/stdlib/Makefile
@@ -26,11 +26,6 @@
 	strtoul.$O\
 	strtoull.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- a/src/libc/string/Makefile
+++ b/src/libc/string/Makefile
@@ -23,11 +23,6 @@
 	strtok.$O\
 	strxfrm.$O\
 
-all: $(LIBC)
-
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-dep: inc-dep
+all: $(OBJS)
 
 include deps.mk
--- a/src/libc/syscall.h
+++ b/src/libc/syscall.h
@@ -1,9 +1,9 @@
-extern void *_brk(void *addr);
-extern int _open(const char *path, int flags, int mode);
-extern int _close(int fd);
-extern int _read(int fd, void *buf, size_t n);
-extern int _write(int fd, void *buf, size_t n);
-extern int _lseek(int fd, long off, int whence);
-extern void _Exit(int status);
-extern int _access(char *path, int mode);
-extern int _unlink(const char *path);
+extern int _brk(void *);
+extern void _exit(int);
+extern int _close(int);
+extern int _getpid(void);
+extern int _kill(int, int);
+extern int _open(const char *, int, int);
+extern int _read(int, void *, size_t);
+extern int _unlink(const char *);
+extern int _write(int, void *, size_t);
--- a/src/libc/time/Makefile
+++ b/src/libc/time/Makefile
@@ -14,18 +14,12 @@
 	strftime.$O\
 	tz.$O\
 
-all: $(LIBC)
+all: $(OBJS)
 
-$(LIBC): $(OBJS)
-	$(MKLST)
-
-$(OBJS): tz.c
-
 tz.c: timezone.lst
 	awk -f gentz.awk $? >$@
 
-dep: inc-dep
-
-distclean: tz.c
+clean:
+	rm -f tz.c
 
 include deps.mk
--- a/src/libc/time/deps.mk
+++ b/src/libc/time/deps.mk
@@ -4,3 +4,4 @@
 ./localtime.o: ./../libc.h
 ./mktime.o: ./../libc.h
 ./strftime.o: ./../libc.h
+./tz.o: ./../libc.h
--- a/src/libcrt/Makefile
+++ b/src/libcrt/Makefile
@@ -1,7 +1,15 @@
 .POSIX:
 
+DIRS =\
+	amd64\
+	arm\
+	arm64\
+	i386\
+	ppc\
+
 PROJECTDIR=../..
 include $(PROJECTDIR)/scripts/rules.mk
 
-all clean dep:
-	cd $(ARCH) && $(MAKE) $@
+NODEP = 1
+
+all: $(ARCH)
--- /dev/null
+++ b/src/libcrt/amd64/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- /dev/null
+++ b/src/libcrt/arm/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- /dev/null
+++ b/src/libcrt/arm64/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- /dev/null
+++ b/src/libcrt/i386/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- /dev/null
+++ b/src/libcrt/ppc/deps.mk
@@ -1,0 +1,1 @@
+#deps
--- a/src/libmach/Makefile
+++ b/src/libmach/Makefile
@@ -39,12 +39,7 @@
 objlst.mk: $(OBJS) $(DIRS)
 	./mklst $@
 
-dep: inc-dep
-	$(FORALL)
-
 clean:
-	$(FORALL)
 	rm -f $(TBLS) objlst.mk
-
 
 include deps.mk
--- a/src/libmach/coff32/Makefile
+++ b/src/libmach/coff32/Makefile
@@ -24,6 +24,4 @@
 
 all: $(OBJS)
 
-dep: inc-dep
-
 include deps.mk
--- a/src/libscc/Makefile
+++ b/src/libscc/Makefile
@@ -23,6 +23,4 @@
 	$(AR) $(PROJ_ARFLAGS) $@ $?
 	$(RL) $(PROJ_RLFLAGS) $@
 
-dep: inc-dep
-
 include deps.mk
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -10,8 +10,12 @@
 	libc/execute\
 	cc/execute cc/error\
 
-PROJECTDIR = ..
-include $(PROJECTDIR)/scripts/rules.mk
-
 all clean:
-	$(FORALL)
+	for i in $(DIRS);\
+	do \
+		cd $$i;\
+		$(MAKE) $@;\
+		cd -;\
+	done
+
+dep: