chiark / gitweb /
[PATCH] klibc: update to version 0.196
[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           asprintf.o vasprintf.o \
14           vsscanf.o sscanf.o ctypes.o \
15           strntoumax.o strntoimax.o \
16           atoi.o atol.o atoll.o \
17           strtol.o strtoll.o strtoul.o strtoull.o \
18           strtoimax.o strtoumax.o \
19           globals.o exitc.o atexit.o onexit.o \
20           execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
21           fork.o wait.o wait3.o waitpid.o system.o setpgrp.o getpgrp.o \
22           daemon.o \
23           printf.o vprintf.o fprintf.o vfprintf.o perror.o \
24           statfs.o fstatfs.o umount.o \
25           open.o fopen.o fread.o fread2.o fgetc.o fgets.o \
26           fwrite.o fwrite2.o fputc.o fputs.o puts.o putchar.o \
27           sleep.o usleep.o strtotimespec.o strtotimeval.o \
28           raise.o abort.o assert.o alarm.o pause.o \
29           __signal.o sysv_signal.o bsd_signal.o siglist.o siglongjmp.o \
30           sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
31           brk.o sbrk.o malloc.o realloc.o calloc.o mmap.o \
32           memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
33           memmove.o memchr.o memrchr.o \
34           strcasecmp.o strncasecmp.o strndup.o strerror.o \
35           strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
36           strncat.o strlcpy.o strlcat.o \
37           strstr.o strncmp.o strncpy.o strrchr.o \
38           strxspn.o strspn.o strcspn.o strpbrk.o strsep.o strtok.o \
39           gethostname.o getdomainname.o getcwd.o \
40           seteuid.o setegid.o \
41           getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
42           getopt.o readdir.o \
43           syslog.o closelog.o pty.o getpt.o isatty.o reboot.o \
44           time.o utime.o llseek.o nice.o getpriority.o \
45           qsort.o \
46           lrand48.o jrand48.o mrand48.o nrand48.o srand48.o seed48.o \
47           inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
48           inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
49           send.o recv.o
50 ifeq ($(ERRLIST),1)
51 LIBOBJS += errlist.o
52 endif
53
54 SOLIB   = libc.so
55 SOHASH  = klibc.so
56
57 CRT0    = crt0.o
58 LIB     = libc.a
59
60 INTERP_O = interp.o
61
62 all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
63
64 # Add any architecture-specific rules
65 include arch/$(ARCH)/Makefile.inc
66 EMAIN ?= -e main
67
68 tests: $(TESTS)
69
70 tests/%.o : tests/%.c
71         $(CC) $(CFLAGS) -c -o $@ $<
72
73 # This particular file uses a bunch of formats gcc don't know of, in order
74 # to test the full range of our vsnprintf() function.  This outputs a bunch
75 # of useless warnings unless we tell it not to.
76 tests/testvsnp.o : tests/testvsnp.c
77         $(CC) $(CFLAGS) -Wno-format -c -o $@ $<
78
79 tests/% : tests/%.o $(LIB) $(CRT0)
80         $(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
81         cp $@ $@.stripped
82         $(STRIP) $@.stripped
83
84 tests/%.shared : tests/%.o interp.o $(SOLIB)
85         $(LD) $(LDFLAGS) -o $@ $(EMAIN) interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
86         cp $@ $@.stripped
87         $(STRIP) $@.stripped
88
89 $(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
90         rm -f $(LIB)
91         $(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) \
92                 $(wildcard syscalls/*.o) $(wildcard socketcalls/*.o)
93         $(RANLIB) $(LIB)
94
95 $(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
96         $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
97                 $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
98                 $(wildcard syscalls/*.o) $(wildcard socketcalls/*.o) \
99                 $(LIBGCC)
100
101 sha1hash: sha1hash.c
102         $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<
103
104 $(SOLIB).hash: $(SOLIB) sha1hash
105         $(NM) $(SOLIB) | \
106                 egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@
107
108 $(SOHASH): $(SOLIB) $(SOLIB).hash
109         cp -f $(SOLIB) $@
110         $(STRIP) $@
111         rm -f klibc-??????????????????????.so
112         ln -f $@ klibc-`cat $(SOLIB).hash`.so
113
114 $(INTERP_O): interp.S $(SOLIB).hash
115         $(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
116                 -DSOHASH=\"`cat $(SOLIB).hash`\" \
117                 -c -o $@ $<
118
119 crt0.o: arch/$(ARCH)/crt0.o
120         cp arch/$(ARCH)/crt0.o .
121
122 errlist.c:
123         $(PERL) makeerrlist.pl -q $(INCLUDE) -errlist > $@ || rm -f $@
124
125 # We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
126 SYSCALLS.i: SYSCALLS.def
127         $(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
128
129 syscalls.nrs: ../include/sys/syscall.h
130         $(CC) $(CFLAGS) -Wp,-dM -x c -E -o $@ $<
131
132 syscalls.dir: SYSCALLS.i syscalls.pl arch/$(ARCH)/sysstub.ph syscommon.h syscalls.nrs
133         rm -rf syscalls
134         mkdir syscalls
135         $(PERL) syscalls.pl SYSCALLS.i $(ARCH) $(BITSIZE) syscalls.nrs ../include/klibc/havesyscall.h
136         touch $@
137
138 ../include/klibc/havesyscall.h: syscalls.dir
139         : Generated by side effect
140
141 socketcalls.dir: SOCKETCALLS.def socketcalls.pl socketcommon.h
142         rm -rf socketcalls
143         mkdir socketcalls
144         $(PERL) socketcalls.pl SOCKETCALLS.def $(ARCH)
145         touch $@
146
147 %/static.obj: %.dir
148         $(MAKE) objects-$(basename $(notdir $@)) DIR=$*/
149
150 STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)*.[cS])))
151
152 objects-static: $(STATIC)
153         touch $(DIR)static.obj
154
155 clean: archclean
156         find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
157         rm -f *.a *.so *.hash *.syms *.stripped
158         rm -f $(TESTS) tests/*.stripped
159         rm -rf syscalls syscalls.dir
160         rm -rf socketcalls socketcalls.dir
161         rm -f sha1hash errlist.c
162
163 spotless: clean
164         rm -f ../include/klibc/havesyscall.h syscalls.nrs
165         find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
166                 xargs -0rt rm -f
167
168 bitsize:
169         @echo $(BITSIZE)
170
171 ifneq ($(wildcard $(DIR).*.d),)
172 include $(wildcard $(DIR).*.d)
173 endif