ref: 505471768e8e83bfe42d1884dcd7ab038f06a6cc
parent: 03c0fe7804daa71325f6827b7953579c74548881
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 24 03:01:39 EDT 2018
[lib/c] Add support for target dependencies Target only could define dependencies using syscall.lst, which generates all the object files needed for syscalls, but it was impossible to add other types.
--- a/lib/c/syscall.h
+++ b/lib/c/syscall.h
@@ -7,12 +7,6 @@
extern void _Exit(int status);
extern int _access(char *path, int mode);
-extern int raise(int sig);
-extern void (*signal(int sig, void (*func)(int)))(int);
-extern char *getenv(const char *var);
-extern int rename(const char *from, const char *to);
-extern int remove(const char *path);
-
/* auxiliar functions */
#ifdef stdin
--- a/lib/c/target/amd64-sysv-linux/Makefile
+++ b/lib/c/target/amd64-sysv-linux/Makefile
@@ -1,14 +1,15 @@
.POSIX:
PROJECTDIR = ../../../..
+include $(PROJECTDIR)/rules.mk
+
SYSNAME = amd64-sysv-linux
+SCC_CFLAGS = -nostdinc -I$(INCDIR) -I$(INCDIR)/bits/amd64-sysv/
+SYSOBJ = raise.o signal.o
-include $(PROJECTDIR)/rules.mk
-include ../script/objlst.mk
include syscall.mk
+include ../script/objlst.mk
include ../script/common.mk
-SCC_CFLAGS = -nostdinc -I$(INCDIR) -I$(INCDIR)/bits/amd64-sysv/
-
-dep:
- ../script/syscall.sh
+raise.o: ../posix/raise.c ../../syscall.h
+signal.o: ../posix/signal.c ../../syscall.h
--- a/lib/c/target/amd64-sysv-linux/syscall.lst
+++ b/lib/c/target/amd64-sysv-linux/syscall.lst
@@ -9,3 +9,5 @@
38 _getpid
60 _Exit
32 _kill
+39 _getpid
+62 _kill
--- a/lib/c/target/amd64-sysv-linux/syscall.mk
+++ b/lib/c/target/amd64-sysv-linux/syscall.mk
@@ -1,1 +1,1 @@
-SYS = _read.o _write.o _open.o _close.o _lseek.o _brk.o _rt_sigaction.o _getpid.o _Exit.o _kill.o
+SYSCALL = _read.o _write.o _open.o _close.o _lseek.o _brk.o _rt_sigaction.o _getpid.o _Exit.o _kill.o _getpid.o _kill.o
--- /dev/null
+++ b/lib/c/target/posix/raise.c
@@ -1,0 +1,17 @@
+
+#include <stddef.h>
+#include <signal.h>
+#include "../../syscall.h"
+
+#undef raise
+
+/* TODO: Add sys.h and store these definitions there */
+
+extern int _getpid(void);
+extern int _kill(int pid, int signum);
+
+int
+raise(int signum)
+{
+ return _kill(_getpid(), signum);
+}
--- /dev/null
+++ b/lib/c/target/posix/signal.c
@@ -1,0 +1,9 @@
+
+#include <signal.h>
+
+#undef signal
+
+void
+(*signal(int signum, void (*func)(int)))(int)
+{
+}
--- a/lib/c/target/script/common.mk
+++ b/lib/c/target/script/common.mk
@@ -1,9 +1,9 @@
-SYSASM = $(SYS:.o=.s)
+SYSASM = $(SYSCALL:.o=.s)
TARGET = $(LIBDIR)/$(SYSNAME)/libc.a
all: $(TARGET)
-$(TARGET): $(OBJ) $(SYS)
+$(TARGET): $(LIBOBJ) $(SYSOBJ) $(SYSCALL)
$(AR) $(ARFLAGS) $@ $?
ranlib $@
@@ -10,6 +10,7 @@
clean:
rm -f *.o *.a
rm -f $(SYSASM)
+ rm -f $(TARGET)
$(SYSASM): syscall.lst
../script/amd64-sysv.sh
--- a/lib/c/target/script/objlst.mk
+++ b/lib/c/target/script/objlst.mk
@@ -1,25 +1,25 @@
-OBJ = bsearch.o qsort.o \
- abs.o __abs.o labs.o __labs.o llabs.o __llabs.o \
- perror.o strerror.o \
- tmpnam.o \
- sprintf.o snprintf.o vsprintf.o vsnprintf.o \
- printf.o fprintf.o vfprintf.o \
- fgets.o gets.o fgetc.o fputc.o getchar.o putchar.o \
- fputs.o puts.o fread.o fwrite.o \
- getc.o putc.o __putc.o __getc.o \
- rewind.o fseek.o ferror.o feof.o clearerr.o \
- setbuf.o setvbuf.o \
- fclose.o fopen.o freopen.o _fpopen.o _flsbuf.o stdio.o \
- realloc.o calloc.o malloc.o \
- __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 \
- memset.o memcpy.o memmove.o memcmp.o memchr.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 toupper.o tolower.o ctype.o setlocale.o \
- localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o
+LIBOBJ = bsearch.o qsort.o \
+ abs.o __abs.o labs.o __labs.o llabs.o __llabs.o \
+ perror.o strerror.o \
+ tmpnam.o \
+ sprintf.o snprintf.o vsprintf.o vsnprintf.o \
+ printf.o fprintf.o vfprintf.o \
+ fgets.o gets.o fgetc.o fputc.o getchar.o putchar.o \
+ fputs.o puts.o fread.o fwrite.o \
+ getc.o putc.o __putc.o __getc.o \
+ rewind.o fseek.o ferror.o feof.o clearerr.o \
+ setbuf.o setvbuf.o \
+ fclose.o fopen.o freopen.o _fpopen.o _flsbuf.o stdio.o \
+ realloc.o calloc.o malloc.o \
+ __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 \
+ memset.o memcpy.o memmove.o memcmp.o memchr.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 toupper.o tolower.o ctype.o setlocale.o \
+ localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o
#rules
__abs.o: ../../__abs.c
--- a/lib/c/target/script/objlst.sh
+++ b/lib/c/target/script/objlst.sh
@@ -17,4 +17,4 @@
done
echo .
-echo w) | ed -s objlst.mk
+echo w) | ed -s script/objlst.mk
--- a/lib/c/target/script/syscall.sh
+++ b/lib/c/target/script/syscall.sh
@@ -1,7 +1,7 @@
#!/bin/sh
(echo '/SYS/c'
- awk 'BEGIN {printf "SYS = "}
+ awk 'BEGIN {printf "SYSCALL = "}
! /^#/ {printf "%s.o ", $2}
END {print ""}' syscall.lst
echo .