summaryrefslogtreecommitdiff
path: root/klibc/klibc/Makefile
blob: 0d5b197f0d8684b6cbe0f0faab0c2017f97ac0a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
# Makefile
#
# Main makefile
#

# Include configuration rules
include MCONFIG

TESTS   = $(patsubst %.c,%,$(wildcard tests/*.c)) \
	  $(patsubst %.c,%.shared,$(wildcard tests/*.c))
LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
	  vsscanf.o sscanf.o ctypes.o \
	  strntoumax.o strntoimax.o \
	  atoi.o atol.o atoll.o \
	  strtol.o strtoll.o strtoul.o strtoull.o \
	  strtoimax.o strtoumax.o \
	  globals.o exitc.o atexit.o onexit.o \
	  execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
	  fork.o wait.o wait3.o waitpid.o system.o setpgrp.o \
	  printf.o vprintf.o fprintf.o vfprintf.o perror.o \
	  fopen.o fread.o fread2.o fgetc.o fgets.o \
	  fwrite.o fwrite2.o fputc.o fputs.o puts.o \
	  sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
	  __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
	  sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
	  brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o getpagesize.o \
	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
	  memmove.o \
	  strcasecmp.o strncasecmp.o strndup.o strerror.o \
	  strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o \
	  strncat.o strstr.o strncmp.o strncpy.o strrchr.o strspn.o \
	  strsep.o strtok.o \
	  gethostname.o getdomainname.o getcwd.o \
	  seteuid.o setegid.o setresuid.o setresgid.o \
	  getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
	  getopt.o readdir.o \
	  syslog.o closelog.o pty.o isatty.o reboot.o \
	  time.o utime.o fdatasync.o llseek.o select.o nice.o getpriority.o \
	  qsort.o lrand48.o srand48.o seed48.o \
	  inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
	  inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
	  send.o recv.o
SOLIB   = libc.so
SOHASH  = klibc.so

CRT0    = crt0.o
LIB     = libc.a

#all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
all:  $(CRT0) $(LIB) $(SOLIB) klibc.so

# Add any architecture-specific rules
include arch/$(ARCH)/Makefile.inc

tests: $(TESTS)

tests/%.o : tests/%.c
	$(CC) $(CFLAGS) -c -o $@ $<

# This particular file uses a bunch of formats gcc don't know of, in order
# to test the full range of our vsnprintf() function.  This outputs a bunch
# of useless warnings unless we tell it not to.
tests/testvsnp.o : tests/testvsnp.c
	$(CC) $(CFLAGS) -Wno-format -c -o $@ $<

tests/% : tests/%.o $(LIB) $(CRT0)
	$(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
	cp $@ $@.stripped
	$(STRIP) $@.stripped

tests/%.shared : tests/%.o interp.o $(SOLIB)
	$(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
	cp $@ $@.stripped
	$(STRIP) $@.stripped

$(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
	rm -f $(LIB)
	$(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/*.o socketcalls/*.o
	$(RANLIB) $(LIB)

$(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
	$(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
		$(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
	        syscalls/*.o socketcalls/*.o \
		$(LIBGCC)

sha1hash: sha1hash.c
	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<

$(SOLIB).hash: $(SOLIB) sha1hash
	$(NM) $(SOLIB) | \
		egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@

$(SOHASH): $(SOLIB) $(SOLIB).hash
	cp -f $(SOLIB) $@
	$(STRIP) $@
	rm -f klibc-??????????????????????.so
	ln -f $@ klibc-`cat $(SOLIB).hash`.so

interp.o: interp.S $(SOLIB).hash
	$(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
		-DSOHASH=\"`cat $(SOLIB).hash`\" \
		-c -o $@ $<

crt0.o: arch/$(ARCH)/crt0.o
	cp arch/$(ARCH)/crt0.o .

syscalls.dir: SYSCALLS syscalls.pl syscommon.h
	rm -rf syscalls
	mkdir syscalls
	$(PERL) syscalls.pl $(ARCH) SYSCALLS
	touch $@

socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h
	rm -rf socketcalls
	mkdir socketcalls
	$(PERL) socketcalls.pl $(ARCH) SOCKETCALLS
	touch $@

%/static.obj: %.dir
	$(MAKE) objects-$(basename $(notdir $@)) DIR=$*/

STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)*.[cS])))

objects-static: $(STATIC)
	touch $(DIR)static.obj

clean: archclean
	find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
	rm -f *.a *.so *.hash *.syms *.stripped
	rm -f $(TESTS) tests/*.stripped
	rm -rf syscalls syscalls.dir
	rm -rf socketcalls socketcalls.dir
	rm -f sha1hash

spotless: clean
	find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
		xargs -0rt rm -f

bitsize:
	@echo $(BITSIZE)

ifneq ($(wildcard $(DIR).*.d),)
include $(wildcard $(DIR).*.d)
endif