blob: 683850d30078075a71741a3895ed8df7705acbb4 [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
Rich Felkere7652392012-05-03 20:35:11 -040023IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
Rich Felker0b44a032011-02-12 00:22:29 -050024
Rich Felkerd76eafc2012-05-01 19:30:03 -040025LDFLAGS =
Rich Felker1b231452012-08-02 21:05:43 -040026LIBCC = -lgcc
Rich Felkerd76eafc2012-05-01 19:30:03 -040027CPPFLAGS =
28CFLAGS = -Os -pipe
29CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
30
31CFLAGS_ALL = $(CFLAGS_C99FSE)
Rich Felkerfcaec912012-07-11 02:44:14 -040032CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
Rich Felkerd76eafc2012-05-01 19:30:03 -040033CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
34CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
35CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
36
Rich Felker0b44a032011-02-12 00:22:29 -050037AR = $(CROSS_COMPILE)ar
38RANLIB = $(CROSS_COMPILE)ranlib
Rich Felker0b44a032011-02-12 00:22:29 -050039
40ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
41
Rich Felker41d51832011-02-24 16:37:21 -050042EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050043EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
Rich Felker83023d12012-05-02 21:01:55 -040044CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
Rich Felkerd76eafc2012-05-01 19:30:03 -040045STATIC_LIBS = lib/libc.a
Rich Felker207c45d2011-06-27 21:38:11 -040046SHARED_LIBS = lib/libc.so
Rich Felker58f430c2012-04-22 14:32:49 -040047TOOL_LIBS = lib/musl-gcc.specs
Rich Felkerd76eafc2012-05-01 19:30:03 -040048ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050049ALL_TOOLS = tools/musl-gcc
50
Rich Felker207c45d2011-06-27 21:38:11 -040051LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
52
Rich Felker0b44a032011-02-12 00:22:29 -050053-include config.mak
54
Rich Felker8d546812011-06-28 08:27:38 -040055all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050056
Rich Felker3c870262012-02-17 23:17:48 -050057install: $(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 -050058
59clean:
60 rm -f crt/*.o
61 rm -f $(OBJS)
62 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050063 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050064 rm -f $(ALL_TOOLS)
65 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050066 rm -f include/bits
67
Rich Felkerd76eafc2012-05-01 19:30:03 -040068distclean: clean
69 rm -f config.mak
70
Rich Felker1355fdc2011-02-15 00:33:23 -050071include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050072 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050073 ln -sf ../arch/$(ARCH)/bits $@
74
75include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050076
77include/bits/alltypes.h: include/bits/alltypes.h.sh
78 sh $< > $@
79
Rich Felkerd0437802012-08-05 12:32:20 -040080src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
81
Rich Felker0b44a032011-02-12 00:22:29 -050082%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040083 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050084
Rich Felkere7652392012-05-03 20:35:11 -040085%.o: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040086 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050087
88%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040089 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050090
Rich Felkere7652392012-05-03 20:35:11 -040091%.lo: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040092 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050093
Rich Felker207c45d2011-06-27 21:38:11 -040094lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -040095 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
96 -Wl,-e,_start -Wl,-Bsymbolic-functions \
Rich Felker1b231452012-08-02 21:05:43 -040097 -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC)
Rich Felker0b44a032011-02-12 00:22:29 -050098
Rich Felker4fd15952011-02-17 17:12:52 -050099lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -0500100 rm -f $@
101 $(AR) rc $@ $(OBJS)
102 $(RANLIB) $@
103
Rich Felker4fd15952011-02-17 17:12:52 -0500104$(EMPTY_LIBS):
105 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500106 $(AR) rc $@
107
Rich Felker4fd15952011-02-17 17:12:52 -0500108lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500109 cp $< $@
110
Rich Felker58f430c2012-04-22 14:32:49 -0400111lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
112 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
113
114tools/musl-gcc: config.mak
115 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500116 chmod +x $@
117
118$(DESTDIR)$(bindir)/%: tools/%
119 install -D $< $@
120
Rich Felker207c45d2011-06-27 21:38:11 -0400121$(DESTDIR)$(libdir)/%.so: lib/%.so
122 install -D -m 755 $< $@
123
Rich Felkerec05a0b2011-06-23 22:13:47 -0400124$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500125 install -D -m 644 $< $@
126
Rich Felkerec05a0b2011-06-23 22:13:47 -0400127$(DESTDIR)$(includedir)/%: include/%
128 install -D -m 644 $< $@
129
Rich Felkerf8e054f2012-05-04 21:54:57 -0400130$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
Rich Felker207c45d2011-06-27 21:38:11 -0400131 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400132
Rich Felkerf8e054f2012-05-04 21:54:57 -0400133$(DESTDIR)$(syslibdir):
134 install -d -m 755 $(DESTDIR)$(syslibdir)
135
Rich Felker0b44a032011-02-12 00:22:29 -0500136.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
137
138.PHONY: all clean install