blob: f02780758258cdd0443c0b2fa6416a9baee5b089 [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
Rich Felker207c45d2011-06-27 21:38:11 -040017syslibdir = /lib
Rich Felker0b44a032011-02-12 00:22:29 -050018
19SRCS = $(sort $(wildcard src/*/*.c))
20OBJS = $(SRCS:.c=.o)
21LOBJS = $(OBJS:.o=.lo)
22GENH = include/bits/alltypes.h
23
Rich Felker60272012011-02-13 16:48:39 -050024CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
Rich Felker41d51832011-02-24 16:37:21 -050025LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions
Rich Felker7b2dd222011-02-15 03:56:52 -050026INC = -I./include -I./src/internal -I./arch/$(ARCH)
Rich Felker41d51832011-02-24 16:37:21 -050027PIC = -fPIC -O3
Rich Felker0b44a032011-02-12 00:22:29 -050028AR = $(CROSS_COMPILE)ar
29RANLIB = $(CROSS_COMPILE)ranlib
30OBJCOPY = $(CROSS_COMPILE)objcopy
31
32ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
33
Rich Felker41d51832011-02-24 16:37:21 -050034EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050035EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
36CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
Rich Felker207c45d2011-06-27 21:38:11 -040037STATIC_LIBS = lib/libc.a $(EMPTY_LIBS)
38SHARED_LIBS = lib/libc.so
39ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050040ALL_TOOLS = tools/musl-gcc
41
Rich Felker207c45d2011-06-27 21:38:11 -040042LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
43
Rich Felker0b44a032011-02-12 00:22:29 -050044-include config.mak
45
Rich Felker8d546812011-06-28 08:27:38 -040046all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050047
Rich Felker8d546812011-06-28 08:27:38 -040048install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(DESTDIR)$(LDSO_PATHNAME)
Rich Felker0b44a032011-02-12 00:22:29 -050049
50clean:
51 rm -f crt/*.o
52 rm -f $(OBJS)
53 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050054 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050055 rm -f $(ALL_TOOLS)
56 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050057 rm -f include/bits
58
59include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050060 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050061 ln -sf ../arch/$(ARCH)/bits $@
62
63include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050064
65include/bits/alltypes.h: include/bits/alltypes.h.sh
66 sh $< > $@
67
68%.o: $(ARCH)/%.s
69 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
70
71%.o: %.c $(GENH)
72 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
73
74%.lo: $(ARCH)/%.s
75 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
76
77%.lo: %.c $(GENH)
78 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
79
Rich Felker207c45d2011-06-27 21:38:11 -040080lib/libc.so: $(LOBJS)
81 $(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
Rich Felker0b44a032011-02-12 00:22:29 -050082 $(OBJCOPY) --weaken $@
83
Rich Felker4fd15952011-02-17 17:12:52 -050084lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050085 rm -f $@
86 $(AR) rc $@ $(OBJS)
87 $(RANLIB) $@
88
Rich Felker4fd15952011-02-17 17:12:52 -050089$(EMPTY_LIBS):
90 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -050091 $(AR) rc $@
92
Rich Felker4fd15952011-02-17 17:12:52 -050093lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -050094 cp $< $@
95
96tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
Rich Felker207c45d2011-06-27 21:38:11 -040097 sh $< "$(prefix)" "$(LDSO_PATHNAME)" > $@ || { rm -f $@ ; exit 1 ; }
Rich Felker0b44a032011-02-12 00:22:29 -050098 chmod +x $@
99
100$(DESTDIR)$(bindir)/%: tools/%
101 install -D $< $@
102
Rich Felker207c45d2011-06-27 21:38:11 -0400103$(DESTDIR)$(libdir)/%.so: lib/%.so
104 install -D -m 755 $< $@
105
Rich Felkerec05a0b2011-06-23 22:13:47 -0400106$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500107 install -D -m 644 $< $@
108
Rich Felkerec05a0b2011-06-23 22:13:47 -0400109$(DESTDIR)$(includedir)/%: include/%
110 install -D -m 644 $< $@
111
Rich Felker207c45d2011-06-27 21:38:11 -0400112$(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
113 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400114
Rich Felker0b44a032011-02-12 00:22:29 -0500115.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
116
117.PHONY: all clean install