blob: 277aa00a420fa645f782bd9fa81245583cc30a66 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#
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
11exec_prefix = /usr/local
12bindir = $(exec_prefix)/bin
13
14prefix = /usr/local/musl
15includedir = $(prefix)/include
16libdir = $(prefix)/lib
17
18SRCS = $(sort $(wildcard src/*/*.c))
19OBJS = $(SRCS:.c=.o)
20LOBJS = $(OBJS:.o=.lo)
21GENH = include/bits/alltypes.h
22
Rich Felker60272012011-02-13 16:48:39 -050023CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
Rich Felker41d51832011-02-24 16:37:21 -050024LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions
Rich Felker7b2dd222011-02-15 03:56:52 -050025INC = -I./include -I./src/internal -I./arch/$(ARCH)
Rich Felker41d51832011-02-24 16:37:21 -050026PIC = -fPIC -O3
Rich Felker0b44a032011-02-12 00:22:29 -050027AR = $(CROSS_COMPILE)ar
28RANLIB = $(CROSS_COMPILE)ranlib
29OBJCOPY = $(CROSS_COMPILE)objcopy
30
31ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
32
Rich Felker41d51832011-02-24 16:37:21 -050033EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050034EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
35CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
36LIBC_LIBS = lib/libc.a
37ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS)
Rich Felkerec05a0b2011-06-23 22:13:47 -040038ALL_LDSO = lib/ld-musl-$(ARCH).so.1
Rich Felker0b44a032011-02-12 00:22:29 -050039
40ALL_TOOLS = tools/musl-gcc
41
42-include config.mak
43
Rich Felkerec05a0b2011-06-23 22:13:47 -040044all: $(ALL_LIBS) $(ALL_TOOLS) $(ALL_LDSO)
Rich Felker0b44a032011-02-12 00:22:29 -050045
Rich Felkerec05a0b2011-06-23 22:13:47 -040046install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(ALL_LDSO:%=$(DESTDIR)/%) $(ALL_LDSO:%/ld-musl-$(ARCH).so.1=$(DESTDIR)$(libdir)/libc.so)
Rich Felker0b44a032011-02-12 00:22:29 -050047
48clean:
49 rm -f crt/*.o
50 rm -f $(OBJS)
51 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050052 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050053 rm -f $(ALL_TOOLS)
54 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050055 rm -f include/bits
56
57include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050058 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050059 ln -sf ../arch/$(ARCH)/bits $@
60
61include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050062
63include/bits/alltypes.h: include/bits/alltypes.h.sh
64 sh $< > $@
65
66%.o: $(ARCH)/%.s
67 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
68
69%.o: %.c $(GENH)
70 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
71
72%.lo: $(ARCH)/%.s
73 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
74
75%.lo: %.c $(GENH)
76 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
77
Rich Felkerec05a0b2011-06-23 22:13:47 -040078lib/ld-musl-$(ARCH).so.1: $(LOBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050079 $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc
80 $(OBJCOPY) --weaken $@
81
Rich Felker4fd15952011-02-17 17:12:52 -050082lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050083 rm -f $@
84 $(AR) rc $@ $(OBJS)
85 $(RANLIB) $@
86
Rich Felker4fd15952011-02-17 17:12:52 -050087$(EMPTY_LIBS):
88 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -050089 $(AR) rc $@
90
Rich Felker4fd15952011-02-17 17:12:52 -050091lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -050092 cp $< $@
93
94tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
Rich Felkerec05a0b2011-06-23 22:13:47 -040095 sh $< "$(prefix)" "$(ARCH)" > $@ || { rm -f $@ ; exit 1 ; }
Rich Felker0b44a032011-02-12 00:22:29 -050096 chmod +x $@
97
98$(DESTDIR)$(bindir)/%: tools/%
99 install -D $< $@
100
Rich Felkerec05a0b2011-06-23 22:13:47 -0400101$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500102 install -D -m 644 $< $@
103
Rich Felkerec05a0b2011-06-23 22:13:47 -0400104$(DESTDIR)$(includedir)/%: include/%
105 install -D -m 644 $< $@
106
107$(DESTDIR)/lib/ld-musl-$(ARCH).so.1: lib/ld-musl-$(ARCH).so.1
108 install -D -m 755 $< $@
109
110$(DESTDIR)$(libdir)/libc.so: $(DESTDIR)/lib/ld-musl-$(ARCH).so.1
111 echo 'GROUP ( /lib/ld-musl-$(ARCH).so.1 )' > $@
112
Rich Felker0b44a032011-02-12 00:22:29 -0500113.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
114
115.PHONY: all clean install