blob: 2265fce43958582282ae1c4d92cde5490be9af01 [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 Felkerd76eafc2012-05-01 19:30:03 -040024LDFLAGS =
25CPPFLAGS =
26CFLAGS = -Os -pipe
27CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
28
29CFLAGS_ALL = $(CFLAGS_C99FSE)
30CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./src/internal -I./include -I./arch/$(ARCH)
31CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
32CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
33CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
34
Rich Felker0b44a032011-02-12 00:22:29 -050035AR = $(CROSS_COMPILE)ar
36RANLIB = $(CROSS_COMPILE)ranlib
Rich Felker0b44a032011-02-12 00:22:29 -050037
38ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
39
Rich Felker41d51832011-02-24 16:37:21 -050040EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050041EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
42CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
Rich Felkerd76eafc2012-05-01 19:30:03 -040043STATIC_LIBS = lib/libc.a
Rich Felker207c45d2011-06-27 21:38:11 -040044SHARED_LIBS = lib/libc.so
Rich Felker58f430c2012-04-22 14:32:49 -040045TOOL_LIBS = lib/musl-gcc.specs
Rich Felkerd76eafc2012-05-01 19:30:03 -040046ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050047ALL_TOOLS = tools/musl-gcc
48
Rich Felker207c45d2011-06-27 21:38:11 -040049LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
50
Rich Felker0b44a032011-02-12 00:22:29 -050051-include config.mak
52
Rich Felker8d546812011-06-28 08:27:38 -040053all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050054
Rich Felker3c870262012-02-17 23:17:48 -050055install: $(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 -050056
57clean:
58 rm -f crt/*.o
59 rm -f $(OBJS)
60 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050061 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050062 rm -f $(ALL_TOOLS)
63 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050064 rm -f include/bits
65
Rich Felkerd76eafc2012-05-01 19:30:03 -040066distclean: clean
67 rm -f config.mak
68
Rich Felker1355fdc2011-02-15 00:33:23 -050069include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050070 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050071 ln -sf ../arch/$(ARCH)/bits $@
72
73include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050074
75include/bits/alltypes.h: include/bits/alltypes.h.sh
76 sh $< > $@
77
78%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040079 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050080
81%.o: %.c $(GENH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040082 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050083
84%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040085 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050086
87%.lo: %.c $(GENH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040088 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050089
Rich Felker207c45d2011-06-27 21:38:11 -040090lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -040091 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
92 -Wl,-e,_start -Wl,-Bsymbolic-functions \
93 -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
Rich Felker0b44a032011-02-12 00:22:29 -050094
Rich Felker4fd15952011-02-17 17:12:52 -050095lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050096 rm -f $@
97 $(AR) rc $@ $(OBJS)
98 $(RANLIB) $@
99
Rich Felker4fd15952011-02-17 17:12:52 -0500100$(EMPTY_LIBS):
101 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500102 $(AR) rc $@
103
Rich Felker4fd15952011-02-17 17:12:52 -0500104lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500105 cp $< $@
106
Rich Felker58f430c2012-04-22 14:32:49 -0400107lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
108 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
109
110tools/musl-gcc: config.mak
111 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500112 chmod +x $@
113
114$(DESTDIR)$(bindir)/%: tools/%
115 install -D $< $@
116
Rich Felker207c45d2011-06-27 21:38:11 -0400117$(DESTDIR)$(libdir)/%.so: lib/%.so
118 install -D -m 755 $< $@
119
Rich Felkerec05a0b2011-06-23 22:13:47 -0400120$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500121 install -D -m 644 $< $@
122
Rich Felkerec05a0b2011-06-23 22:13:47 -0400123$(DESTDIR)$(includedir)/%: include/%
124 install -D -m 644 $< $@
125
Rich Felker207c45d2011-06-27 21:38:11 -0400126$(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
Rich Felker523a3ab2012-03-17 00:48:55 -0400127 install -d -m 755 $(DESTDIR)$(syslibdir) || true
Rich Felker207c45d2011-06-27 21:38:11 -0400128 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400129
Rich Felker0b44a032011-02-12 00:22:29 -0500130.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
131
132.PHONY: all clean install