Makefile 3.2 KB
Newer Older
R
Rich Felker 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#
# Makefile for musl (requires GNU make)
#
# This is how simple every makefile should be...
# No, I take that back - actually most should be less than half this size.
#
# Use config.mak to override any of the following variables.
# Do not make changes here.
#

exec_prefix = /usr/local
bindir = $(exec_prefix)/bin

prefix = /usr/local/musl
includedir = $(prefix)/include
libdir = $(prefix)/lib
17
syslibdir = /lib
R
Rich Felker 已提交
18 19 20 21 22 23

SRCS = $(sort $(wildcard src/*/*.c))
OBJS = $(SRCS:.c=.o)
LOBJS = $(OBJS:.o=.lo)
GENH = include/bits/alltypes.h

24 25 26 27 28 29 30 31 32 33 34
LDFLAGS = 
CPPFLAGS =
CFLAGS = -Os -pipe
CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc 

CFLAGS_ALL = $(CFLAGS_C99FSE)
CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./src/internal -I./include -I./arch/$(ARCH)
CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3

R
Rich Felker 已提交
35 36 37 38 39
AR      = $(CROSS_COMPILE)ar
RANLIB  = $(CROSS_COMPILE)ranlib

ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))

40
EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
R
Rich Felker 已提交
41 42
EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
43
STATIC_LIBS = lib/libc.a
44
SHARED_LIBS = lib/libc.so
45
TOOL_LIBS = lib/musl-gcc.specs
46
ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
R
Rich Felker 已提交
47 48
ALL_TOOLS = tools/musl-gcc

49 50
LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1

R
Rich Felker 已提交
51 52
-include config.mak

53
all: $(ALL_LIBS) $(ALL_TOOLS)
R
Rich Felker 已提交
54

55
install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
R
Rich Felker 已提交
56 57 58 59 60

clean:
	rm -f crt/*.o
	rm -f $(OBJS)
	rm -f $(LOBJS)
R
Rich Felker 已提交
61
	rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
R
Rich Felker 已提交
62 63
	rm -f $(ALL_TOOLS)
	rm -f $(GENH) 
64 65
	rm -f include/bits

66 67 68
distclean: clean
	rm -f config.mak

69
include/bits:
70
	@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
71 72 73
	ln -sf ../arch/$(ARCH)/bits $@

include/bits/alltypes.h.sh: include/bits
R
Rich Felker 已提交
74 75 76 77 78

include/bits/alltypes.h: include/bits/alltypes.h.sh
	sh $< > $@

%.o: $(ARCH)/%.s
79
	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
R
Rich Felker 已提交
80 81

%.o: %.c $(GENH)
82
	$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
R
Rich Felker 已提交
83 84

%.lo: $(ARCH)/%.s
85
	$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
R
Rich Felker 已提交
86 87

%.lo: %.c $(GENH)
88
	$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
R
Rich Felker 已提交
89

90
lib/libc.so: $(LOBJS)
91 92 93
	$(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
	-Wl,-e,_start -Wl,-Bsymbolic-functions \
	-Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
R
Rich Felker 已提交
94

95
lib/libc.a: $(OBJS)
R
Rich Felker 已提交
96 97 98 99
	rm -f $@
	$(AR) rc $@ $(OBJS)
	$(RANLIB) $@

100 101
$(EMPTY_LIBS):
	rm -f $@
R
Rich Felker 已提交
102 103
	$(AR) rc $@

104
lib/%.o: crt/%.o
R
Rich Felker 已提交
105 106
	cp $< $@

107 108 109 110 111
lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
	sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@

tools/musl-gcc: config.mak
	printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
R
Rich Felker 已提交
112 113 114 115 116
	chmod +x $@

$(DESTDIR)$(bindir)/%: tools/%
	install -D $< $@

117 118 119
$(DESTDIR)$(libdir)/%.so: lib/%.so
	install -D -m 755 $< $@

120
$(DESTDIR)$(libdir)/%: lib/%
R
Rich Felker 已提交
121 122
	install -D -m 644 $< $@

123 124 125
$(DESTDIR)$(includedir)/%: include/%
	install -D -m 644 $< $@

126
$(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
127
	install -d -m 755 $(DESTDIR)$(syslibdir) || true
128
	ln -sf $(libdir)/libc.so $@ || true
129

R
Rich Felker 已提交
130 131 132
.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)

.PHONY: all clean install