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
18 SRCS = $(sort $(wildcard src/*/*.c))
20 LOBJS = $(OBJS:.o=.lo)
21 GENH = include/bits/alltypes.h
23 CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
24 LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions
25 INC = -I./include -I./src/internal -I./arch/$(ARCH)
27 AR = $(CROSS_COMPILE)ar
28 RANLIB = $(CROSS_COMPILE)ranlib
29 OBJCOPY = $(CROSS_COMPILE)objcopy
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 LIBC_LIBS = lib/libc.a
37 ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS)
38 ALL_LDSO = lib/ld-musl-$(ARCH).so.1
40 ALL_TOOLS = tools/musl-gcc
44 all: $(ALL_LIBS) $(ALL_TOOLS) $(ALL_LDSO)
46 install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(ALL_LDSO:%=$(DESTDIR)/%) $(ALL_LDSO:%/ld-musl-$(ARCH).so.1=$(DESTDIR)$(libdir)/libc.so)
52 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
58 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
59 ln -sf ../arch/$(ARCH)/bits $@
61 include/bits/alltypes.h.sh: include/bits
63 include/bits/alltypes.h: include/bits/alltypes.h.sh
67 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
70 $(CC) $(CFLAGS) $(INC) -c -o $@ $<
73 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
76 $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<
78 lib/ld-musl-$(ARCH).so.1: $(LOBJS)
79 $(CC) $(LDFLAGS) -Wl,-soname=libc.so.1 -o $@ $(LOBJS) -lgcc
80 $(OBJCOPY) --weaken $@
94 tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
95 sh $< "$(prefix)" "$(ARCH)" > $@ || { rm -f $@ ; exit 1 ; }
98 $(DESTDIR)$(bindir)/%: tools/%
101 $(DESTDIR)$(libdir)/%: lib/%
102 install -D -m 644 $< $@
104 $(DESTDIR)$(includedir)/%: include/%
105 install -D -m 644 $< $@
107 $(DESTDIR)/lib/ld-musl-$(ARCH).so.1: lib/ld-musl-$(ARCH).so.1
108 install -D -m 755 $< $@
110 $(DESTDIR)$(libdir)/libc.so: lib/ld-musl-$(ARCH).so.1
111 ln -sf /lib/ld-musl-$(ARCH).so.1 $@
113 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
115 .PHONY: all clean install