chiark / gitweb /
[PATCH] sync klibc with release 0.95
[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 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 \
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 unsetenv.o getopt.o readdir.o \
37           syslog.o closelog.o pty.o isatty.o reboot.o \
38           time.o utime.o fdatasync.o llseek.o select.o nice.o getpriority.o \
39           qsort.o lrand48.o srand48.o seed48.o \
40           inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
41           inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
42           send.o recv.o
43 SOLIB   = libc.so
44 SOHASH  = klibc.so
45
46 CRT0    = crt0.o
47 LIB     = libc.a
48
49 #all: tests $(CRT0) $(LIB) $(SOLIB) klibc.so
50 all:  $(CRT0) $(LIB) $(SOLIB) klibc.so
51
52 # Add any architecture-specific rules
53 include arch/$(ARCH)/Makefile.inc
54
55 tests: $(TESTS)
56
57 tests/%.o : tests/%.c
58         $(CC) $(CFLAGS) -c -o $@ $<
59
60 # This particular file uses a bunch of formats gcc don't know of, in order
61 # to test the full range of our vsnprintf() function.  This outputs a bunch
62 # of useless warnings unless we tell it not to.
63 tests/testvsnp.o : tests/testvsnp.c
64         $(CC) $(CFLAGS) -Wno-format -c -o $@ $<
65
66 tests/% : tests/%.o $(LIB) $(CRT0)
67         $(LD) $(LDFLAGS) -o $@ $(CRT0) $< $(LIB) $(LIBGCC)
68         cp $@ $@.stripped
69         $(STRIP) $@.stripped
70
71 tests/%.shared : tests/%.o interp.o $(SOLIB)
72         $(LD) $(LDFLAGS) -o $@ -e main interp.o tests/$*.o -R $(SOLIB) $(LIBGCC)
73         cp $@ $@.stripped
74         $(STRIP) $@.stripped
75
76 $(LIB): __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
77         rm -f $(LIB)
78         $(AR) cq $(LIB) __static_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/*.o socketcalls/*.o
79         $(RANLIB) $(LIB)
80
81 $(SOLIB): $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) syscalls/static.obj socketcalls/static.obj
82         $(LD) $(LDFLAGS) $(SHAREDFLAGS) -o $@ \
83                 $(CRT0) __shared_init.o $(LIBOBJS) $(ARCHOBJS) \
84                 syscalls/*.o socketcalls/*.o \
85                 $(LIBGCC)
86
87 sha1hash: sha1hash.c
88         $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $<
89
90 $(SOLIB).hash: $(SOLIB) sha1hash
91         $(NM) $(SOLIB) | \
92                 egrep '^[0-9a-fA-F]+ [ADRTW] ' | sort | ./sha1hash > $@
93
94 $(SOHASH): $(SOLIB) $(SOLIB).hash
95         cp -f $(SOLIB) $@
96         $(STRIP) $@
97         rm -f klibc-??????????????????????.so
98         ln -f $@ klibc-`cat $(SOLIB).hash`.so
99
100 interp.o: interp.S $(SOLIB).hash
101         $(CC) $(CFLAGS) -D__ASSEMBLY__ -DLIBDIR=\"$(SHLIBDIR)\" \
102                 -DSOHASH=\"`cat $(SOLIB).hash`\" \
103                 -c -o $@ $<
104
105 crt0.o: arch/$(ARCH)/crt0.o
106         cp arch/$(ARCH)/crt0.o .
107
108 syscalls.dir: SYSCALLS syscalls.pl syscommon.h
109         rm -rf syscalls
110         mkdir syscalls
111         $(PERL) syscalls.pl $(ARCH) SYSCALLS
112         touch $@
113
114 socketcalls.dir: SOCKETCALLS socketcalls.pl socketcommon.h
115         rm -rf socketcalls
116         mkdir socketcalls
117         $(PERL) socketcalls.pl $(ARCH) SOCKETCALLS
118         touch $@
119
120 %/static.obj: %.dir
121         $(MAKE) objects-$(basename $(notdir $@)) DIR=$*
122
123 STATIC = $(addsuffix .o,$(basename $(wildcard $(DIR)/*.[cS])))
124
125 objects-static: $(STATIC)
126         touch $(DIR)/static.obj
127
128 clean: archclean
129         find . -type f -a \( -name \*.[isoa] -o -name \*.l[iso] \) -print0 | xargs -0rt rm -f
130         rm -f *.a *.so *.hash *.syms *.stripped
131         rm -f $(TESTS) tests/*.stripped
132         rm -rf syscalls syscalls.dir
133         rm -rf socketcalls socketcalls.dir
134         rm -f sha1hash
135
136 spotless: clean
137         find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
138                 xargs -0rt rm -f
139
140 bitsize:
141         @echo $(BITSIZE)
142
143 ifneq ($(wildcard $(DIR)/.*.d),)
144 include $(wildcard $(DIR)/.*.d)
145 endif