fix uninitialized/stale use of alloc (%m modifier) flag in scanf
[musl] / Makefile
1 #
2 # Makefile for musl (requires GNU make)
3 #
4 # This is how simple every makefile should be...
5 # No, I take that back - actually most should be less than half this size.
6 #
7 # Use config.mak to override any of the following variables.
8 # Do not make changes here.
9 #
10
11 exec_prefix = /usr/local
12 bindir = $(exec_prefix)/bin
13
14 prefix = /usr/local/musl
15 includedir = $(prefix)/include
16 libdir = $(prefix)/lib
17 syslibdir = /lib
18
19 SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
20 OBJS = $(SRCS:.c=.o)
21 LOBJS = $(OBJS:.o=.lo)
22 GENH = include/bits/alltypes.h
23 IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
24
25 LDFLAGS = 
26 LIBCC = -lgcc
27 CPPFLAGS =
28 CFLAGS = -Os -pipe
29 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc 
30
31 CFLAGS_ALL = $(CFLAGS_C99FSE)
32 CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
33 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
34 CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
35 CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
36
37 AR      = $(CROSS_COMPILE)ar
38 RANLIB  = $(CROSS_COMPILE)ranlib
39
40 ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
41 ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
42
43 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
44 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
45 CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
46 STATIC_LIBS = lib/libc.a
47 SHARED_LIBS = lib/libc.so
48 TOOL_LIBS = lib/musl-gcc.specs
49 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
50 ALL_TOOLS = tools/musl-gcc
51
52 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
53
54 -include config.mak
55
56 all: $(ALL_LIBS) $(ALL_TOOLS)
57
58 install: install-libs install-headers install-tools
59
60 clean:
61         rm -f crt/*.o
62         rm -f $(OBJS)
63         rm -f $(LOBJS)
64         rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
65         rm -f $(ALL_TOOLS)
66         rm -f $(GENH) 
67         rm -f include/bits
68
69 distclean: clean
70         rm -f config.mak
71
72 include/bits:
73         @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
74         ln -sf ../arch/$(ARCH)/bits $@
75
76 include/bits/alltypes.h.sh: include/bits
77
78 include/bits/alltypes.h: include/bits/alltypes.h.sh
79         sh $< > $@
80
81 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
82
83 %.o: $(ARCH)/%.s
84         $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
85
86 %.o: %.c $(GENH) $(IMPH)
87         $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
88
89 %.lo: $(ARCH)/%.s
90         $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
91
92 %.lo: %.c $(GENH) $(IMPH)
93         $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
94
95 lib/libc.so: $(LOBJS)
96         $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
97         -Wl,-e,_start -Wl,-Bsymbolic-functions \
98         -o $@ $(LOBJS) $(LIBCC)
99
100 lib/libc.a: $(OBJS)
101         rm -f $@
102         $(AR) rc $@ $(OBJS)
103         $(RANLIB) $@
104
105 $(EMPTY_LIBS):
106         rm -f $@
107         $(AR) rc $@
108
109 lib/%.o: crt/%.o
110         cp $< $@
111
112 lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
113         sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
114
115 tools/musl-gcc: config.mak
116         printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
117         chmod +x $@
118
119 $(DESTDIR)$(bindir)/%: tools/%
120         install -D $< $@
121
122 $(DESTDIR)$(libdir)/%.so: lib/%.so
123         install -D -m 755 $< $@
124
125 $(DESTDIR)$(libdir)/%: lib/%
126         install -D -m 644 $< $@
127
128 $(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
129         install -D -m 644 $< $@
130
131 $(DESTDIR)$(includedir)/%: include/%
132         install -D -m 644 $< $@
133
134 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
135         ln -sf $(libdir)/libc.so $@ || true
136
137 $(DESTDIR)$(syslibdir):
138         install -d -m 755 $(DESTDIR)$(syslibdir)
139
140 install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
141
142 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
143
144 install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
145
146
147
148 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
149
150 .PHONY: all clean install install-libs install-headers install-tools