add fallocate (nonstandardized) function
[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))
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 -O3
36
37 AR      = $(CROSS_COMPILE)ar
38 RANLIB  = $(CROSS_COMPILE)ranlib
39
40 ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
41
42 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
43 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
44 CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
45 STATIC_LIBS = lib/libc.a
46 SHARED_LIBS = lib/libc.so
47 TOOL_LIBS = lib/musl-gcc.specs
48 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
49 ALL_TOOLS = tools/musl-gcc
50
51 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
52
53 -include config.mak
54
55 all: $(ALL_LIBS) $(ALL_TOOLS)
56
57 install: install-libs install-headers install-tools
58
59 clean:
60         rm -f crt/*.o
61         rm -f $(OBJS)
62         rm -f $(LOBJS)
63         rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
64         rm -f $(ALL_TOOLS)
65         rm -f $(GENH) 
66         rm -f include/bits
67
68 distclean: clean
69         rm -f config.mak
70
71 include/bits:
72         @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
73         ln -sf ../arch/$(ARCH)/bits $@
74
75 include/bits/alltypes.h.sh: include/bits
76
77 include/bits/alltypes.h: include/bits/alltypes.h.sh
78         sh $< > $@
79
80 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
81
82 %.o: $(ARCH)/%.s
83         $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
84
85 %.o: %.c $(GENH) $(IMPH)
86         $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
87
88 %.lo: $(ARCH)/%.s
89         $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
90
91 %.lo: %.c $(GENH) $(IMPH)
92         $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
93
94 lib/libc.so: $(LOBJS)
95         $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
96         -Wl,-e,_start -Wl,-Bsymbolic-functions \
97         -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC)
98
99 lib/libc.a: $(OBJS)
100         rm -f $@
101         $(AR) rc $@ $(OBJS)
102         $(RANLIB) $@
103
104 $(EMPTY_LIBS):
105         rm -f $@
106         $(AR) rc $@
107
108 lib/%.o: crt/%.o
109         cp $< $@
110
111 lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
112         sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
113
114 tools/musl-gcc: config.mak
115         printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
116         chmod +x $@
117
118 $(DESTDIR)$(bindir)/%: tools/%
119         install -D $< $@
120
121 $(DESTDIR)$(libdir)/%.so: lib/%.so
122         install -D -m 755 $< $@
123
124 $(DESTDIR)$(libdir)/%: lib/%
125         install -D -m 644 $< $@
126
127 $(DESTDIR)$(includedir)/%: include/%
128         install -D -m 644 $< $@
129
130 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
131         ln -sf $(libdir)/libc.so $@ || true
132
133 $(DESTDIR)$(syslibdir):
134         install -d -m 755 $(DESTDIR)$(syslibdir)
135
136 install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
137
138 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
139
140 install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
141
142
143
144 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
145
146 .PHONY: all clean install install-libs install-headers install-tools