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