blob: 1bdea61eed0932952491eb8903bb763db52260e8 [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 =
26CPPFLAGS =
27CFLAGS = -Os -pipe
28CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
29
30CFLAGS_ALL = $(CFLAGS_C99FSE)
31CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./src/internal -I./include -I./arch/$(ARCH)
32CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
33CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
34CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3
35
Rich Felker0b44a032011-02-12 00:22:29 -050036AR = $(CROSS_COMPILE)ar
37RANLIB = $(CROSS_COMPILE)ranlib
Rich Felker0b44a032011-02-12 00:22:29 -050038
39ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
40
Rich Felker41d51832011-02-24 16:37:21 -050041EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050042EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
Rich Felker83023d12012-05-02 21:01:55 -040043CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
Rich Felkerd76eafc2012-05-01 19:30:03 -040044STATIC_LIBS = lib/libc.a
Rich Felker207c45d2011-06-27 21:38:11 -040045SHARED_LIBS = lib/libc.so
Rich Felker58f430c2012-04-22 14:32:49 -040046TOOL_LIBS = lib/musl-gcc.specs
Rich Felkerd76eafc2012-05-01 19:30:03 -040047ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050048ALL_TOOLS = tools/musl-gcc
49
Rich Felker207c45d2011-06-27 21:38:11 -040050LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
51
Rich Felker0b44a032011-02-12 00:22:29 -050052-include config.mak
53
Rich Felker8d546812011-06-28 08:27:38 -040054all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050055
Rich Felker3c870262012-02-17 23:17:48 -050056install: $(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 -050057
58clean:
59 rm -f crt/*.o
60 rm -f $(OBJS)
61 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050062 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050063 rm -f $(ALL_TOOLS)
64 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050065 rm -f include/bits
66
Rich Felkerd76eafc2012-05-01 19:30:03 -040067distclean: clean
68 rm -f config.mak
69
Rich Felker1355fdc2011-02-15 00:33:23 -050070include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050071 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050072 ln -sf ../arch/$(ARCH)/bits $@
73
74include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050075
76include/bits/alltypes.h: include/bits/alltypes.h.sh
77 sh $< > $@
78
79%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040080 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050081
Rich Felkere7652392012-05-03 20:35:11 -040082%.o: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040083 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050084
85%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040086 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050087
Rich Felkere7652392012-05-03 20:35:11 -040088%.lo: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040089 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050090
Rich Felker207c45d2011-06-27 21:38:11 -040091lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -040092 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
93 -Wl,-e,_start -Wl,-Bsymbolic-functions \
94 -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
Rich Felker0b44a032011-02-12 00:22:29 -050095
Rich Felker4fd15952011-02-17 17:12:52 -050096lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -050097 rm -f $@
98 $(AR) rc $@ $(OBJS)
99 $(RANLIB) $@
100
Rich Felker4fd15952011-02-17 17:12:52 -0500101$(EMPTY_LIBS):
102 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500103 $(AR) rc $@
104
Rich Felker4fd15952011-02-17 17:12:52 -0500105lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500106 cp $< $@
107
Rich Felker58f430c2012-04-22 14:32:49 -0400108lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
109 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
110
111tools/musl-gcc: config.mak
112 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500113 chmod +x $@
114
115$(DESTDIR)$(bindir)/%: tools/%
116 install -D $< $@
117
Rich Felker207c45d2011-06-27 21:38:11 -0400118$(DESTDIR)$(libdir)/%.so: lib/%.so
119 install -D -m 755 $< $@
120
Rich Felkerec05a0b2011-06-23 22:13:47 -0400121$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500122 install -D -m 644 $< $@
123
Rich Felkerec05a0b2011-06-23 22:13:47 -0400124$(DESTDIR)$(includedir)/%: include/%
125 install -D -m 644 $< $@
126
Rich Felkerf8e054f2012-05-04 21:54:57 -0400127$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
Rich Felker207c45d2011-06-27 21:38:11 -0400128 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400129
Rich Felkerf8e054f2012-05-04 21:54:57 -0400130$(DESTDIR)$(syslibdir):
131 install -d -m 755 $(DESTDIR)$(syslibdir)
132
Rich Felker0b44a032011-02-12 00:22:29 -0500133.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
134
135.PHONY: all clean install