scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 2c899ad6dae851ee1c0212f74293cfbd18977be6
parent 3d0c95a32783e7bd937b0f81ada5a46ff7e5fcd8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 18 Jan 2020 17:40:40 +0100

[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.

Diffstat:
Mconfig/config/amd64-darwin.mk | 1+
Mconfig/config/amd64-dragonfly.mk | 4++--
Mconfig/config/amd64-linux.mk | 4++--
Mconfig/config/amd64-netbsd.mk | 4++--
Mconfig/config/amd64-openbsd.mk | 4++--
Aconfig/config/amd64-posix.mk | 3+++
Mconfig/config/arm32-linux.mk | 4++--
Aconfig/config/arm32-posix.mk | 3+++
Mconfig/config/arm64-linux.mk | 4++--
Aconfig/config/arm64-posix.mk | 3+++
Mscripts/rules.mk | 2+-
Msrc/libc/.gitignore | 6+++++-
Msrc/libc/Makefile | 34+++++++++++++++++++---------------
Dsrc/libc/Makefile.libc | 17-----------------
Msrc/libc/arch/amd64/Makefile | 7+++++--
Msrc/libc/arch/amd64/darwin/Makefile | 64+++++++++++++++++++++++++++++++++++-----------------------------
Msrc/libc/arch/amd64/darwin/gensys.sh | 4+++-
Msrc/libc/arch/amd64/dragonfly/Makefile | 68+++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/libc/arch/amd64/dragonfly/gensys.sh | 5+++--
Msrc/libc/arch/amd64/linux/Makefile | 71++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/libc/arch/amd64/linux/gensys.sh | 7+++++--
Msrc/libc/arch/amd64/netbsd/Makefile | 69++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/libc/arch/amd64/netbsd/gensys.sh | 5+++--
Msrc/libc/arch/amd64/openbsd/Makefile | 64++++++++++++++++++++++++++++++++++------------------------------
Msrc/libc/arch/amd64/openbsd/gensys.sh | 5+++--
Msrc/libc/arch/arm32/Makefile | 7+++++--
Msrc/libc/arch/arm32/linux/Makefile | 62+++++++++++++++++++++++++++++++++-----------------------------
Msrc/libc/arch/arm32/linux/gensys.sh | 5+++--
Msrc/libc/arch/arm64/Makefile | 7+++++--
Msrc/libc/arch/i386/Makefile | 7+++++--
Msrc/libc/arch/i386/linux/Makefile | 70++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/libc/arch/i386/linux/gensys.sh | 18+++++++++---------
Msrc/libc/assert/Makefile | 5+++--
Msrc/libc/ctype/Makefile | 38+++++++++++++++++++++-----------------
Msrc/libc/locale/Makefile | 8++++++--
Dsrc/libc/mklst | 9---------
Msrc/libc/rules.mk | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/libc/stdio/Makefile | 82+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/libc/stdlib/Makefile | 46+++++++++++++++++++++++++---------------------
Msrc/libc/string/Makefile | 52++++++++++++++++++++++++++++------------------------
Msrc/libc/time/Makefile | 20++++++++++++--------
41 files changed, 546 insertions(+), 416 deletions(-)

diff --git 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 diff --git 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 diff --git 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 diff --git 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 diff --git 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 diff --git a/config/config/amd64-posix.mk b/config/config/amd64-posix.mk @@ -0,0 +1,3 @@ +ARCH = amd64 +ABI = amd64-posix +O = 6 diff --git 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 diff --git a/config/config/arm32-posix.mk b/config/config/arm32-posix.mk @@ -0,0 +1,3 @@ +ABI = arm32-posix +ARCH = arm32 +O = 5 diff --git 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 diff --git a/config/config/arm64-posix.mk b/config/config/arm64-posix.mk @@ -0,0 +1,3 @@ +ARCH = arm64 +ABI = arm64-posix +O = 6 diff --git a/scripts/rules.mk b/scripts/rules.mk @@ -12,7 +12,7 @@ INCDIR = $(PROJECTDIR)/include 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 diff --git a/src/libc/.gitignore b/src/libc/.gitignore @@ -1 +1,5 @@ -objlst.mk +*.6 +*.7 +*.8 +*.z +libc.lst diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -3,24 +3,28 @@ PROJECTDIR =../.. 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 diff --git a/src/libc/Makefile.libc b/src/libc/Makefile.libc @@ -1,17 +0,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 $@ diff --git a/src/libc/arch/amd64/Makefile b/src/libc/arch/amd64/Makefile @@ -3,10 +3,13 @@ PROJECTDIR =../../../.. 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) diff --git a/src/libc/arch/amd64/darwin/Makefile b/src/libc/arch/amd64/darwin/Makefile @@ -3,35 +3,41 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: ../crt-posix.s - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + __Exit.$O\ + __close.$O\ + __getpid.$O\ + __kill.$O\ + __lseek.$O\ + __open.$O\ + __read.$O\ + __write.$O\ + __sigaction.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +OBJS =\ + $(GENOBJS)\ + _getheap.$O\ + _tzone.$O\ + getenv.$O\ + raise.$O\ + signal.$O\ + time.$O\ + _sys_errlist.$O\ + +# Rules + +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 diff --git 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 diff --git a/src/libc/arch/amd64/dragonfly/Makefile b/src/libc/arch/amd64/dragonfly/Makefile @@ -3,36 +3,42 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: crt-posix.s - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _getpid.$O\ + _kill.$O\ + _lseek.$O\ + _open.$O\ + _read.$O\ + _write.$O\ + _brk.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +OBJS =\ + $(GENOBJS)\ + getenv.$O\ + raise.$O\ + signal.$O\ + time.$O\ + _getheap.$O\ + _sigaction.$O\ + _tzone.$O\ + _sys_errlist.$O\ + +# Rules + +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 diff --git 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 diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile @@ -3,38 +3,43 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: ../crt-posix.s - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _getpid.$O\ + _kill.$O\ + _lseek.$O\ + _open.$O\ + _read.$O\ + _write.$O\ + _brk.$O\ + _sigaction.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +OBJS = \ + $(GENOBJS)\ + getenv.$O\ + raise.$O\ + signal.$O\ + time.$O\ + _cerrno.$O\ + _getheap.$O\ + _tzone.$O\ + _sys_errlist.$O\ + +# Rules + +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 diff --git 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 @@ $name: syscall jmp _cerrno EOF + done diff --git a/src/libc/arch/amd64/netbsd/Makefile b/src/libc/arch/amd64/netbsd/Makefile @@ -3,39 +3,42 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: ../crt-posix.s ../../crt-netbsd.s - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _getpid.$O\ + _kill.$O\ + _lseek.$O\ + _open.$O\ + _read.$O\ + _write.$O\ + _brk.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +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) + +$(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 diff --git 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 diff --git a/src/libc/arch/amd64/openbsd/Makefile b/src/libc/arch/amd64/openbsd/Makefile @@ -3,36 +3,40 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: ../crt-posix.s ../../crt-openbsd.s - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _getpid.$O\ + _kill.$O\ + _lseek.$O\ + _open.$O\ + _read.$O\ + _write.$O\ + _brk.$O\ + _sigaction.$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) + +$(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 diff --git 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 diff --git a/src/libc/arch/arm32/Makefile b/src/libc/arch/arm32/Makefile @@ -3,10 +3,13 @@ PROJECTDIR =../../../.. 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) diff --git a/src/libc/arch/arm32/linux/Makefile b/src/libc/arch/arm32/linux/Makefile @@ -3,38 +3,42 @@ PROJECTDIR =../../../../.. 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 \ - -all: syscall - $(MAKE) objs - -objs: $(OBJS) +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _brk.$O\ + _getpid.$O\ + _kill.$O\ + _lseek.$O\ + _openat.$O\ + _read.$O\ + _write.$O\ + _sigaction.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +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 diff --git 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 diff --git a/src/libc/arch/arm64/Makefile b/src/libc/arch/arm64/Makefile @@ -3,10 +3,13 @@ PROJECTDIR =../../../.. 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) diff --git a/src/libc/arch/i386/Makefile b/src/libc/arch/i386/Makefile @@ -3,10 +3,13 @@ PROJECTDIR =../../../.. 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) diff --git a/src/libc/arch/i386/linux/Makefile b/src/libc/arch/i386/linux/Makefile @@ -3,40 +3,42 @@ PROJECTDIR =../../../../.. 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 - -all: syscall - $(MAKE) objs - -objs: $(OBJS) - -crt.o: ../crt-posix.s - -raise.o: ../../posix/raise.c - -signal.o: ../../posix/signal.c - -syscall: syscall.lst - gensys.sh syscall.lst - touch syscall +GENOBJS =\ + _Exit.$O\ + _close.$O\ + _open.$O\ + _read.$O\ + _write.$O\ + _lseek.$O\ + _brk.$O\ + _sigaction.$O\ + _getpid.$O\ + _kill.$O\ + +GENSRC = $(GENOBJS:.$O=.s) + +OBJS =\ + $(GENOBJS)\ + signal.$O\ + raise.$O\ + _getheap.$O\ + _cerrno.$O\ + signal.$O + +all: $(LIBC) $(CRT) + +$(LIBCLST): $(OBJS) + $(MKLST) + +crt.o: ../crt-posix.s + +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 diff --git 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 @@ awk '/^[0-9]*\t/ { "\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 @@ awk '/^[0-9]*\t/ { "\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 diff --git a/src/libc/assert/Makefile b/src/libc/assert/Makefile @@ -3,7 +3,8 @@ PROJECTDIR =../../.. include $(PROJECTDIR)/scripts/rules.mk include ../rules.mk -OBJS = __assert.o\ - assert.o\ +OBJS =\ + __assert.$O\ + assert.$O\ all: $(OBJS) diff --git a/src/libc/ctype/Makefile b/src/libc/ctype/Makefile @@ -3,22 +3,26 @@ PROJECTDIR =../../.. 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) diff --git a/src/libc/locale/Makefile b/src/libc/locale/Makefile @@ -3,7 +3,11 @@ PROJECTDIR =../../.. include $(PROJECTDIR)/scripts/rules.mk include ../rules.mk -OBJS = localeconv.o\ - setlocale.o\ +OBJS =\ + localeconv.$O\ + setlocale.$O\ all: $(OBJS) + +$(LIBC): $(OBJS) + $(MKLIB) diff --git a/src/libc/mklst b/src/libc/mklst @@ -1,9 +0,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 diff --git 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 $@ diff --git a/src/libc/stdio/Makefile b/src/libc/stdio/Makefile @@ -3,44 +3,48 @@ PROJECTDIR =../../.. 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) diff --git a/src/libc/stdlib/Makefile b/src/libc/stdlib/Makefile @@ -3,26 +3,30 @@ PROJECTDIR =../../.. 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) diff --git a/src/libc/string/Makefile b/src/libc/string/Makefile @@ -3,28 +3,32 @@ PROJECTDIR =../../.. 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) diff --git a/src/libc/time/Makefile b/src/libc/time/Makefile @@ -3,13 +3,17 @@ PROJECTDIR =../../.. 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)