blob: 72b640a4020c12f2992625242f339e89629b6834 [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 Felker15d143b2012-03-01 00:21:20 -050026INC = -I./src/internal -I./include -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
Rich Felker58f430c2012-04-22 14:32:49 -040039TOOL_LIBS = lib/musl-gcc.specs
40ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(TOOL_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050041ALL_TOOLS = tools/musl-gcc
42
Rich Felker207c45d2011-06-27 21:38:11 -040043LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
44
Rich Felker0b44a032011-02-12 00:22:29 -050045-include config.mak
46
Rich Felker8d546812011-06-28 08:27:38 -040047all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050048
Rich Felker3c870262012-02-17 23:17:48 -050049install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
Rich Felker0b44a032011-02-12 00:22:29 -050050
51clean:
52 rm -f crt/*.o
53 rm -f $(OBJS)
54 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050055 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050056 rm -f $(ALL_TOOLS)
57 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050058 rm -f include/bits
59
60include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050061 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050062 ln -sf ../arch/$(ARCH)/bits $@
63
64include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050065
66include/bits/alltypes.h: include/bits/alltypes.h.sh
67 sh $< > $@
68
69%.o: $(ARCH)/%.s
70 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
71
72%.o: %.c $(GENH)
73 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
74
75%.lo: $(ARCH)/%.s
76 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
77
78%.lo: %.c $(GENH)
79 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
80
Rich Felker207c45d2011-06-27 21:38:11 -040081lib/libc.so: $(LOBJS)
82 $(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
Rich Felker0b44a032011-02-12 00:22:29 -050083 $(OBJCOPY) --weaken $@
84
Rich Felker4fd15952011-02-17 17:12:52 -050085lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050086 rm -f $@
87 $(AR) rc $@ $(OBJS)
88 $(RANLIB) $@
89
Rich Felker4fd15952011-02-17 17:12:52 -050090$(EMPTY_LIBS):
91 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -050092 $(AR) rc $@
93
Rich Felker4fd15952011-02-17 17:12:52 -050094lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -050095 cp $< $@
96
Rich Felker58f430c2012-04-22 14:32:49 -040097lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
98 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
99
100tools/musl-gcc: config.mak
101 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500102 chmod +x $@
103
104$(DESTDIR)$(bindir)/%: tools/%
105 install -D $< $@
106
Rich Felker207c45d2011-06-27 21:38:11 -0400107$(DESTDIR)$(libdir)/%.so: lib/%.so
108 install -D -m 755 $< $@
109
Rich Felkerec05a0b2011-06-23 22:13:47 -0400110$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500111 install -D -m 644 $< $@
112
Rich Felkerec05a0b2011-06-23 22:13:47 -0400113$(DESTDIR)$(includedir)/%: include/%
114 install -D -m 644 $< $@
115
Rich Felker207c45d2011-06-27 21:38:11 -0400116$(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
Rich Felker523a3ab2012-03-17 00:48:55 -0400117 install -d -m 755 $(DESTDIR)$(syslibdir) || true
Rich Felker207c45d2011-06-27 21:38:11 -0400118 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400119
Rich Felker0b44a032011-02-12 00:22:29 -0500120.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
121
122.PHONY: all clean install