chiark / gitweb /
[PATCH] Update to version 117 of klibc (from version 108)
[elogind.git] / klibc / klibc / Makefile
1 #
2 # Makefile
3 #
4 # Main makefile
5 #
6
7 # Include configuration rules
8 include MCONFIG
9
10 TESTS   = $(patsubst %.c,%,$(wildcard tests/*.c)) \
11           $(patsubst %.c,%.shared,$(wildcard tests/*.c))
12 LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
13           vsscanf.o sscanf.o ctypes.o \
14           strntoumax.o strntoimax.o \
15           atoi.o atol.o atoll.o \
16           strtol.o strtoll.o strtoul.o strtoull.o \
17           strtoimax.o strtoumax.o \
18           globals.o exitc.o atexit.o onexit.o \
19           execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
20           fork.o wait.o wait3.o waitpid.o system.o setpgrp.o getpgrp.o \
21           open.o \
22           printf.o vprintf.o fprintf.o vfprintf.o perror.o \
23           fopen.o fread.o fread2.o fgetc.o fgets.o \
24           fwrite.o fwrite2.o fputc.o fputs.o puts.o \
25           sleep.o usleep.o raise.o abort.o assert.o alarm.o pause.o \
26           __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
27           sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
28           brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o getpagesize.o \
29           memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
30           memmove.o \
31           strcasecmp.o strncasecmp.o strndup.o strerror.o \
32           strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o \
33           strncat.o strstr.o strncmp.o strncpy.o strrchr.o strspn.o \
34           strsep.o strtok.o \
35           gethostname.o getdomainname.o getcwd.o \
36           seteuid.o setegid.o setresuid.o setresgid.o \
37           getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
38           getopt.o readdir.o \
39           syslog.o closelog.o pty.o getpt.o isatty.o reboot.o \
40           time.o utime.o fdatasync.o llseek.o select.o nice.o getpriority.o \
41           qsort.o lrand48.o srand48.o seed48.o \
42           inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
43           inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
44           send.o recv.o
45 SOLIB   = libc.so
46 SOHASH  = klibc.so
47
48 CRT0    = crt0.o
49 LIB     = libc.a
50
51 #all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
52 all:  $(CRT0) $(LIB) $(SOLIB) klibc.so
53
54 # Add any architecture-specific rules
55 include arch/$(ARCH)/Makefile.inc
56
57 tests: $(TESTS)
58
59 tests/%.o : tests/%.c
60         $(CC) $(CFLAGS) -c -o $@ $<
61
62 # This particular file uses a bunch of formats gcc don't know of, in order
63 # to test the full range of our vsnprintf() function.  This outputs a bunch
64 # of useless warnings unless we tell it not to.
65 tests/testvsnp.o : tests/testvsnp.c
66         $(CC) $(CFLAGS) -Wno-format -c -o $@ $<
67
68 tests/% : tests/%.o $(LIB) $(CRT0)
69         $(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
70         cp $@ $@.stripped
71         $(STRIP) $@.stripped
72
73 tests/%.shared : tests/%.o interp.o $(SOLIB)
74         $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
75         cp $@ $@.stripped
76         $(STRIP) $@.stripped
77
78 $(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
79         rm -f $(LIB)
80         $(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/*.o socketcalls/*.o
81         $(RANLIB) $(LIB)
82
83 $(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
84         $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
85                 $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
86                 syscalls/*.o socketcalls/*.o \
87                 $(LIBGCC)
88
89 sha1hash: sha1hash.c
90         $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<
91
92 $(SOLIB).hash: $(SOLIB) sha1hash
93         $(NM) $(SOLIB) | \
94                 egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@
95
96 $(SOHASH): $(SOLIB) $(SOLIB).hash
97         cp -f $(SOLIB) $@
98         $(STRIP) $@
99         rm -f klibc-??????????????????????.so
100         ln -f $@ klibc-`cat $(SOLIB).hash`.so
101
102 interp.o: interp.S $(SOLIB).hash
103         $(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
104                 -DSOHASH=\"`cat $(SOLIB).hash`\" \
105                 -c -o $@ $<
106
107 crt0.o: arch/$(ARCH)/crt0.o
108         cp arch/$(ARCH)/crt0.o .
109
110 syscalls.dir: SYSCALLS syscalls.pl syscommon.h
111         rm -rf syscalls
112         mkdir syscalls
113         $(PERL) syscalls.pl $(ARCH) SYSCALLS
114         touch $@
115
116 socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h
117         rm -rf socketcalls
118         mkdir socketcalls
119         $(PERL) socketcalls.pl $(ARCH) SOCKETCALLS
120         touch $@
121
122 %/static.obj: %.dir
123         $(MAKE) objects-$(basename $(notdir $@)) DIR=$*/
124
125 STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)*.[cS])))
126
127 objects-static: $(STATIC)
128         touch $(DIR)static.obj
129
130 clean: archclean
131         find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
132         rm -f *.a *.so *.hash *.syms *.stripped
133         rm -f $(TESTS) tests/*.stripped
134         rm -rf syscalls syscalls.dir
135         rm -rf socketcalls socketcalls.dir
136         rm -f sha1hash
137
138 spotless: clean
139         find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
140                 xargs -0rt rm -f
141
142 bitsize:
143         @echo $(BITSIZE)
144
145 ifneq ($(wildcard $(DIR).*.d),)
146 include $(wildcard $(DIR).*.d)
147 endif