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