Makefile 3.3 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

SRCS = $(sort $(wildcard src/*/*.c))
OBJS = $(SRCS:.c=.o)
LOBJS = $(OBJS:.o=.lo)
GENH = include/bits/alltypes.h
23
IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
R
Rich Felker 已提交
24

25 26 27 28 29 30
LDFLAGS = 
CPPFLAGS =
CFLAGS = -Os -pipe
CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc 

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

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

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

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

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

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

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

56
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 已提交
57 58 59 60 61

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

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

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

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

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

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

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

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

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

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

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

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

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

108 109 110 111 112
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 已提交
113 114 115 116 117
	chmod +x $@

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

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

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

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

127
$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir)
128
	ln -sf $(libdir)/libc.so $@ || true
129

130 131 132
$(DESTDIR)$(syslibdir):
	install -d -m 755 $(DESTDIR)$(syslibdir)

R
Rich Felker 已提交
133 134 135
.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)

.PHONY: all clean install