2 # Makefile for musl (requires GNU make)
4 # This is how simple every makefile should be...
5 # No, I take that back - actually most should be less than half this size.
7 # Use config.mak to override any of the following variables.
8 # Do not make changes here.
11 exec_prefix = /usr/local
12 bindir = $(exec_prefix)/bin
14 prefix = /usr/local/musl
15 includedir = $(prefix)/include
16 libdir = $(prefix)/lib
19 SRCS = $(sort $(wildcard src/*/*.c))
21 LOBJS = $(OBJS:.o=.lo)
22 GENH = include/bits/alltypes.h
24 CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
25 LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions
26 INC = -I./src/internal -I./include -I./arch/$(ARCH)
28 AR = $(CROSS_COMPILE)ar
29 RANLIB = $(CROSS_COMPILE)ranlib
31 ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
33 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
34 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
35 CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
36 STATIC_LIBS = lib/libc.a $(EMPTY_LIBS)
37 SHARED_LIBS = lib/libc.so
38 TOOL_LIBS = lib/musl-gcc.specs
39 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(TOOL_LIBS)
40 ALL_TOOLS = tools/musl-gcc
42 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1
46 all: $(ALL_LIBS) $(ALL_TOOLS)
48 install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
54 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
60 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
61 ln -sf ../arch/$(ARCH)/bits $@
63 include/bits/alltypes.h.sh: include/bits
65 include/bits/alltypes.h: include/bits/alltypes.h.sh
69 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
72 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
75 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
78 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
81 $(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
95 lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
96 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
98 tools/musl-gcc: config.mak
99 printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
102 $(DESTDIR)$(bindir)/%: tools/%
105 $(DESTDIR)$(libdir)/%.so: lib/%.so
106 install -D -m 755 $< $@
108 $(DESTDIR)$(libdir)/%: lib/%
109 install -D -m 644 $< $@
111 $(DESTDIR)$(includedir)/%: include/%
112 install -D -m 644 $< $@
114 $(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
115 install -d -m 755 $(DESTDIR)$(syslibdir) || true
116 ln -sf $(libdir)/libc.so $@ || true
118 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
120 .PHONY: all clean install