blob: 2fb1c998018d1da3d9eee3ee88addecca3467cf2 [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
rofl0r158f7212013-02-06 02:11:49 +010019SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
Rich Felker0b44a032011-02-12 00:22:29 -050020OBJS = $(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)
Rich Felker9f745742012-09-14 23:38:10 -040035CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
Rich Felkerd76eafc2012-05-01 19:30:03 -040036
Rich Felker0b44a032011-02-12 00:22:29 -050037AR = $(CROSS_COMPILE)ar
38RANLIB = $(CROSS_COMPILE)ranlib
Rich Felker0b44a032011-02-12 00:22:29 -050039
Rich Felkerd66ab4f2013-07-01 13:43:43 -040040ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
41ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
Rich Felker0b44a032011-02-12 00:22:29 -050042
Rich Felker41d51832011-02-24 16:37:21 -050043EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
Rich Felker0b44a032011-02-12 00:22:29 -050044EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
Rich Felker83023d12012-05-02 21:01:55 -040045CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
Rich Felkerd76eafc2012-05-01 19:30:03 -040046STATIC_LIBS = lib/libc.a
Rich Felker207c45d2011-06-27 21:38:11 -040047SHARED_LIBS = lib/libc.so
Rich Felker58f430c2012-04-22 14:32:49 -040048TOOL_LIBS = lib/musl-gcc.specs
Rich Felkerd76eafc2012-05-01 19:30:03 -040049ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
Rich Felker0b44a032011-02-12 00:22:29 -050050ALL_TOOLS = tools/musl-gcc
51
Rich Felker3e7f1862013-07-18 20:30:58 -040052LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
Rich Felker207c45d2011-06-27 21:38:11 -040053
Rich Felker0b44a032011-02-12 00:22:29 -050054-include config.mak
55
Rich Felker8d546812011-06-28 08:27:38 -040056all: $(ALL_LIBS) $(ALL_TOOLS)
Rich Felker0b44a032011-02-12 00:22:29 -050057
Rich Felker07809362012-08-17 19:32:24 -040058install: install-libs install-headers install-tools
Rich Felker0b44a032011-02-12 00:22:29 -050059
60clean:
61 rm -f crt/*.o
62 rm -f $(OBJS)
63 rm -f $(LOBJS)
Rich Felker127ab572011-02-17 17:57:26 -050064 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
Rich Felker0b44a032011-02-12 00:22:29 -050065 rm -f $(ALL_TOOLS)
66 rm -f $(GENH)
Rich Felker1355fdc2011-02-15 00:33:23 -050067 rm -f include/bits
68
Rich Felkerd76eafc2012-05-01 19:30:03 -040069distclean: clean
70 rm -f config.mak
71
Rich Felker1355fdc2011-02-15 00:33:23 -050072include/bits:
Rich Felkera36164c2011-02-17 15:15:03 -050073 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
Rich Felker1355fdc2011-02-15 00:33:23 -050074 ln -sf ../arch/$(ARCH)/bits $@
75
76include/bits/alltypes.h.sh: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050077
78include/bits/alltypes.h: include/bits/alltypes.h.sh
79 sh $< > $@
80
Rich Felkerd0437802012-08-05 12:32:20 -040081src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
82
Rich Felker0b44a032011-02-12 00:22:29 -050083%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040084 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050085
Rich Felkere7652392012-05-03 20:35:11 -040086%.o: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040087 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050088
89%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040090 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050091
Rich Felkere7652392012-05-03 20:35:11 -040092%.lo: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040093 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050094
Rich Felker207c45d2011-06-27 21:38:11 -040095lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -040096 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
97 -Wl,-e,_start -Wl,-Bsymbolic-functions \
Rich Felkerdfdc3372013-03-09 22:34:11 -050098 -o $@ $(LOBJS) $(LIBCC)
Rich Felker0b44a032011-02-12 00:22:29 -050099
Rich Felker4fd15952011-02-17 17:12:52 -0500100lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -0500101 rm -f $@
102 $(AR) rc $@ $(OBJS)
103 $(RANLIB) $@
104
Rich Felker4fd15952011-02-17 17:12:52 -0500105$(EMPTY_LIBS):
106 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500107 $(AR) rc $@
108
Rich Felker4fd15952011-02-17 17:12:52 -0500109lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500110 cp $< $@
111
Rich Felker58f430c2012-04-22 14:32:49 -0400112lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
113 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
114
115tools/musl-gcc: config.mak
Rich Felker0b3e2252012-09-21 13:47:26 -0400116 printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500117 chmod +x $@
118
119$(DESTDIR)$(bindir)/%: tools/%
120 install -D $< $@
121
Rich Felker207c45d2011-06-27 21:38:11 -0400122$(DESTDIR)$(libdir)/%.so: lib/%.so
123 install -D -m 755 $< $@
124
Rich Felkerec05a0b2011-06-23 22:13:47 -0400125$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500126 install -D -m 644 $< $@
127
Rich Felkerd66ab4f2013-07-01 13:43:43 -0400128$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
129 install -D -m 644 $< $@
130
Rich Felkerec05a0b2011-06-23 22:13:47 -0400131$(DESTDIR)$(includedir)/%: include/%
132 install -D -m 644 $< $@
133
Rich Felkerf8e054f2012-05-04 21:54:57 -0400134$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
Rich Felker207c45d2011-06-27 21:38:11 -0400135 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400136
Rich Felkerf8e054f2012-05-04 21:54:57 -0400137$(DESTDIR)$(syslibdir):
138 install -d -m 755 $(DESTDIR)$(syslibdir)
139
Rich Felker07809362012-08-17 19:32:24 -0400140install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
141
142install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
143
144install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
145
146
147
Rich Felker0b44a032011-02-12 00:22:29 -0500148.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
149
Rich Felker07809362012-08-17 19:32:24 -0400150.PHONY: all clean install install-libs install-headers install-tools