Makefile 2.8 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
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./include -I./src/internal -I./arch/$(ARCH)
27
PIC     = -fPIC -O3
R
Rich Felker 已提交
28 29 30 31 32 33
AR      = $(CROSS_COMPILE)ar
RANLIB  = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy

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

34
EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
R
Rich Felker 已提交
35 36
EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
37 38 39
STATIC_LIBS = lib/libc.a $(EMPTY_LIBS)
SHARED_LIBS = lib/libc.so
ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS)
R
Rich Felker 已提交
40 41
ALL_TOOLS = tools/musl-gcc

42 43
LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1

R
Rich Felker 已提交
44 45
-include config.mak

46
all: $(ALL_LIBS) $(ALL_TOOLS)
R
Rich Felker 已提交
47

48
install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(DESTDIR)$(LDSO_PATHNAME)
R
Rich Felker 已提交
49 50 51 52 53

clean:
	rm -f crt/*.o
	rm -f $(OBJS)
	rm -f $(LOBJS)
R
Rich Felker 已提交
54
	rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
R
Rich Felker 已提交
55 56
	rm -f $(ALL_TOOLS)
	rm -f $(GENH) 
57 58 59
	rm -f include/bits

include/bits:
60
	@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
61 62 63
	ln -sf ../arch/$(ARCH)/bits $@

include/bits/alltypes.h.sh: include/bits
R
Rich Felker 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

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

%.o: $(ARCH)/%.s
	$(CC) $(CFLAGS) $(INC) -c -o $@ $<

%.o: %.c $(GENH)
	$(CC) $(CFLAGS) $(INC) -c -o $@ $<

%.lo: $(ARCH)/%.s
	$(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<

%.lo: %.c $(GENH)
	$(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $<

80 81
lib/libc.so: $(LOBJS)
	$(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc
R
Rich Felker 已提交
82 83
	$(OBJCOPY) --weaken $@

84
lib/libc.a: $(OBJS)
R
Rich Felker 已提交
85 86 87 88
	rm -f $@
	$(AR) rc $@ $(OBJS)
	$(RANLIB) $@

89 90
$(EMPTY_LIBS):
	rm -f $@
R
Rich Felker 已提交
91 92
	$(AR) rc $@

93
lib/%.o: crt/%.o
R
Rich Felker 已提交
94 95 96
	cp $< $@

tools/musl-gcc: tools/gen-musl-gcc.sh config.mak
97
	sh $< "$(prefix)" "$(LDSO_PATHNAME)" > $@ || { rm -f $@ ; exit 1 ; }
R
Rich Felker 已提交
98 99 100 101 102
	chmod +x $@

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

103 104 105
$(DESTDIR)$(libdir)/%.so: lib/%.so
	install -D -m 755 $< $@

106
$(DESTDIR)$(libdir)/%: lib/%
R
Rich Felker 已提交
107 108
	install -D -m 644 $< $@

109 110 111
$(DESTDIR)$(includedir)/%: include/%
	install -D -m 644 $< $@

112 113
$(DESTDIR)$(LDSO_PATHNAME): lib/libc.so
	ln -sf $(libdir)/libc.so $@ || true
114

R
Rich Felker 已提交
115 116 117
.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)

.PHONY: all clean install