blob: ad701c9011b2dfadceb5b64900b6cc1775d05dca [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
80%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040081 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050082
Rich Felkere7652392012-05-03 20:35:11 -040083%.o: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040084 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050085
86%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040087 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050088
Rich Felkere7652392012-05-03 20:35:11 -040089%.lo: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040090 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050091
Rich Felker207c45d2011-06-27 21:38:11 -040092lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -040093 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
94 -Wl,-e,_start -Wl,-Bsymbolic-functions \
Rich Felker1b231452012-08-02 21:05:43 -040095 -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC)
Rich Felker0b44a032011-02-12 00:22:29 -050096
Rich Felker4fd15952011-02-17 17:12:52 -050097lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050098 rm -f $@
99 $(AR) rc $@ $(OBJS)
100 $(RANLIB) $@
101
Rich Felker4fd15952011-02-17 17:12:52 -0500102$(EMPTY_LIBS):
103 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500104 $(AR) rc $@
105
Rich Felker4fd15952011-02-17 17:12:52 -0500106lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500107 cp $< $@
108
Rich Felker58f430c2012-04-22 14:32:49 -0400109lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
110 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
111
112tools/musl-gcc: config.mak
113 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500114 chmod +x $@
115
116$(DESTDIR)$(bindir)/%: tools/%
117 install -D $< $@
118
Rich Felker207c45d2011-06-27 21:38:11 -0400119$(DESTDIR)$(libdir)/%.so: lib/%.so
120 install -D -m 755 $< $@
121
Rich Felkerec05a0b2011-06-23 22:13:47 -0400122$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500123 install -D -m 644 $< $@
124
Rich Felkerec05a0b2011-06-23 22:13:47 -0400125$(DESTDIR)$(includedir)/%: include/%
126 install -D -m 644 $< $@
127
Rich Felkerf8e054f2012-05-04 21:54:57 -0400128$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
Rich Felker207c45d2011-06-27 21:38:11 -0400129 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400130
Rich Felkerf8e054f2012-05-04 21:54:57 -0400131$(DESTDIR)$(syslibdir):
132 install -d -m 755 $(DESTDIR)$(syslibdir)
133
Rich Felker0b44a032011-02-12 00:22:29 -0500134.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
135
136.PHONY: all clean install