blob: 00aa7069bfaf914ee9530bedc9590031891bdb96 [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
Rich Felker9448b052013-07-22 11:22:36 -040076include/bits/alltypes.h.in: include/bits
Rich Felker0b44a032011-02-12 00:22:29 -050077
Rich Felker9448b052013-07-22 11:22:36 -040078include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed
79 sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@
Rich Felker0b44a032011-02-12 00:22:29 -050080
Rich Felkerd0437802012-08-05 12:32:20 -040081src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
82
Rich Felkerc5e34da2013-07-26 01:49:14 -040083crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
84
85crt/Scrt1.o: CFLAGS += -fPIC
86
Rich Felkera80847d2013-07-22 21:22:04 -040087OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
88$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
89
Rich Felker4a1f55e2013-08-01 17:12:23 -040090MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c
91$(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
92
Rich Felker0b44a032011-02-12 00:22:29 -050093%.o: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -040094 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050095
Rich Felkere7652392012-05-03 20:35:11 -040096%.o: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -040097 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -050098
99%.lo: $(ARCH)/%.s
Rich Felkerd76eafc2012-05-01 19:30:03 -0400100 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -0500101
Rich Felkere7652392012-05-03 20:35:11 -0400102%.lo: %.c $(GENH) $(IMPH)
Rich Felkerd76eafc2012-05-01 19:30:03 -0400103 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
Rich Felker0b44a032011-02-12 00:22:29 -0500104
Rich Felker207c45d2011-06-27 21:38:11 -0400105lib/libc.so: $(LOBJS)
Rich Felkerd76eafc2012-05-01 19:30:03 -0400106 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
107 -Wl,-e,_start -Wl,-Bsymbolic-functions \
Rich Felkerdfdc3372013-03-09 22:34:11 -0500108 -o $@ $(LOBJS) $(LIBCC)
Rich Felker0b44a032011-02-12 00:22:29 -0500109
Rich Felker4fd15952011-02-17 17:12:52 -0500110lib/libc.a: $(OBJS)
Rich Felker0b44a032011-02-12 00:22:29 -0500111 rm -f $@
112 $(AR) rc $@ $(OBJS)
113 $(RANLIB) $@
114
Rich Felker4fd15952011-02-17 17:12:52 -0500115$(EMPTY_LIBS):
116 rm -f $@
Rich Felker0b44a032011-02-12 00:22:29 -0500117 $(AR) rc $@
118
Rich Felker4fd15952011-02-17 17:12:52 -0500119lib/%.o: crt/%.o
Rich Felker0b44a032011-02-12 00:22:29 -0500120 cp $< $@
121
Rich Felker58f430c2012-04-22 14:32:49 -0400122lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
123 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
124
125tools/musl-gcc: config.mak
Rich Felker0b3e2252012-09-21 13:47:26 -0400126 printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
Rich Felker0b44a032011-02-12 00:22:29 -0500127 chmod +x $@
128
129$(DESTDIR)$(bindir)/%: tools/%
130 install -D $< $@
131
Rich Felker207c45d2011-06-27 21:38:11 -0400132$(DESTDIR)$(libdir)/%.so: lib/%.so
133 install -D -m 755 $< $@
134
Rich Felkerec05a0b2011-06-23 22:13:47 -0400135$(DESTDIR)$(libdir)/%: lib/%
Rich Felker0b44a032011-02-12 00:22:29 -0500136 install -D -m 644 $< $@
137
Rich Felkerd66ab4f2013-07-01 13:43:43 -0400138$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
139 install -D -m 644 $< $@
140
Rich Felkerec05a0b2011-06-23 22:13:47 -0400141$(DESTDIR)$(includedir)/%: include/%
142 install -D -m 644 $< $@
143
Rich Felkerf8e054f2012-05-04 21:54:57 -0400144$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
Rich Felker207c45d2011-06-27 21:38:11 -0400145 ln -sf $(libdir)/libc.so $@ || true
Rich Felkerec05a0b2011-06-23 22:13:47 -0400146
Rich Felkerf8e054f2012-05-04 21:54:57 -0400147$(DESTDIR)$(syslibdir):
148 install -d -m 755 $(DESTDIR)$(syslibdir)
149
Rich Felker07809362012-08-17 19:32:24 -0400150install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
151
152install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
153
154install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
155
156
157
Rich Felker0b44a032011-02-12 00:22:29 -0500158.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
159
Rich Felker07809362012-08-17 19:32:24 -0400160.PHONY: all clean install install-libs install-headers install-tools