d0f16dfcac2096c37a366336a45779cba6ddb5ad
[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
18 SRCS = $(sort $(wildcard src/*/*.c))
19 OBJS = $(SRCS:.c=.o)
20 LOBJS = $(OBJS:.o=.lo)
21 GENH = include/bits/alltypes.h
22
23 CFLAGS  = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
24 LDFLAGS = -nostdlib -shared -Wl,-Bsymbolic
25 INC     = -I./include -I./src/internal
26 PIC     = -fPIC
27 AR      = $(CROSS_COMPILE)ar
28 RANLIB  = $(CROSS_COMPILE)ranlib
29 OBJCOPY = $(CROSS_COMPILE)objcopy
30
31 ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
32
33 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv
34 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
35 CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
36 LIBC_LIBS = lib/libc.a
37 ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS)
38
39 ALL_TOOLS = tools/musl-gcc
40
41 -include config.mak
42
43 all: $(ALL_LIBS) $(ALL_TOOLS)
44
45 install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
46
47 clean:
48         rm -f crt/*.o
49         rm -f $(OBJS)
50         rm -f $(LOBJS)
51         rm -f $(ALL_LIBS) lib/*
52         rm -f $(ALL_TOOLS)
53         rm -f $(GENH) 
54         rm -f include/bits
55
56 include/bits:
57         ln -sf ../arch/$(ARCH)/bits $@
58
59 include/bits/alltypes.h.sh: include/bits
60
61 include/bits/alltypes.h: include/bits/alltypes.h.sh
62         sh $< > $@
63
64 %.o: $(ARCH)/%.s
65         $(CC) $(CFLAGS) $(INC) -c -o $@ $<
66
67 %.o: %.c $(GENH)
68         $(CC) $(CFLAGS) $(INC) -c -o $@ $<
69
70 %.lo: $(ARCH)/%.s
71         $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
72
73 %.lo: %.c $(GENH)
74         $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
75
76 lib/libc.so: $(LOBJS)
77         $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc
78         $(OBJCOPY) --weaken $@
79
80 lib/libc.a: $(OBJS)
81         rm -f $@
82         $(AR) rc $@ $(OBJS)
83         $(RANLIB) $@
84
85 $(EMPTY_LIBS):
86         $(AR) rc $@
87
88 lib/%.o: crt/%.o
89         cp $< $@
90
91 tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
92         sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; }
93         chmod +x $@
94
95 $(DESTDIR)$(bindir)/%: tools/%
96         install -D $< $@
97
98 $(DESTDIR)$(prefix)/%: %
99         install -D -m 644 $< $@
100
101 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
102
103 .PHONY: all clean install