Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Makefile for musl (requires GNU make) |
| 3 | # |
| 4 | # This is how simple every makefile should be... |
| 5 | # No, I take that back - actually most should be less than half this size. |
| 6 | # |
| 7 | # Use config.mak to override any of the following variables. |
| 8 | # Do not make changes here. |
| 9 | # |
| 10 | |
| 11 | exec_prefix = /usr/local |
| 12 | bindir = $(exec_prefix)/bin |
| 13 | |
| 14 | prefix = /usr/local/musl |
| 15 | includedir = $(prefix)/include |
| 16 | libdir = $(prefix)/lib |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 17 | syslibdir = /lib |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 18 | |
| 19 | SRCS = $(sort $(wildcard src/*/*.c)) |
| 20 | OBJS = $(SRCS:.c=.o) |
| 21 | LOBJS = $(OBJS:.o=.lo) |
| 22 | GENH = include/bits/alltypes.h |
| 23 | |
Rich Felker | 6027201 | 2011-02-13 16:48:39 -0500 | [diff] [blame] | 24 | CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 25 | LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 26 | INC = -I./include -I./src/internal -I./arch/$(ARCH) |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 27 | PIC = -fPIC -O3 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 28 | AR = $(CROSS_COMPILE)ar |
| 29 | RANLIB = $(CROSS_COMPILE)ranlib |
| 30 | OBJCOPY = $(CROSS_COMPILE)objcopy |
| 31 | |
| 32 | ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH)) |
| 33 | |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 34 | EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 35 | EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) |
| 36 | CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 37 | STATIC_LIBS = lib/libc.a $(EMPTY_LIBS) |
| 38 | SHARED_LIBS = lib/libc.so |
| 39 | ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 40 | ALL_TOOLS = tools/musl-gcc |
| 41 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 42 | LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1 |
| 43 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 44 | -include config.mak |
| 45 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 46 | all: $(ALL_LIBS) $(ALL_TOOLS) $(ALL_LDSO) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 47 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 48 | install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(ALL_LDSO:%=$(DESTDIR)/%) $(LDSO_PATHNAME) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 49 | |
| 50 | clean: |
| 51 | rm -f crt/*.o |
| 52 | rm -f $(OBJS) |
| 53 | rm -f $(LOBJS) |
Rich Felker | 127ab57 | 2011-02-17 17:57:26 -0500 | [diff] [blame] | 54 | rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 55 | rm -f $(ALL_TOOLS) |
| 56 | rm -f $(GENH) |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 57 | rm -f include/bits |
| 58 | |
| 59 | include/bits: |
Rich Felker | a36164c | 2011-02-17 15:15:03 -0500 | [diff] [blame] | 60 | @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; } |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 61 | ln -sf ../arch/$(ARCH)/bits $@ |
| 62 | |
| 63 | include/bits/alltypes.h.sh: include/bits |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 64 | |
| 65 | include/bits/alltypes.h: include/bits/alltypes.h.sh |
| 66 | sh $< > $@ |
| 67 | |
| 68 | %.o: $(ARCH)/%.s |
| 69 | $(CC) $(CFLAGS) $(INC) -c -o $@ $< |
| 70 | |
| 71 | %.o: %.c $(GENH) |
| 72 | $(CC) $(CFLAGS) $(INC) -c -o $@ $< |
| 73 | |
| 74 | %.lo: $(ARCH)/%.s |
| 75 | $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< |
| 76 | |
| 77 | %.lo: %.c $(GENH) |
| 78 | $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< |
| 79 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 80 | lib/libc.so: $(LOBJS) |
| 81 | $(CC) $(LDFLAGS) -Wl,-soname=libc.so -o $@ $(LOBJS) -lgcc |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 82 | $(OBJCOPY) --weaken $@ |
| 83 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 84 | lib/libc.a: $(OBJS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 85 | rm -f $@ |
| 86 | $(AR) rc $@ $(OBJS) |
| 87 | $(RANLIB) $@ |
| 88 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 89 | $(EMPTY_LIBS): |
| 90 | rm -f $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 91 | $(AR) rc $@ |
| 92 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 93 | lib/%.o: crt/%.o |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 94 | cp $< $@ |
| 95 | |
| 96 | tools/musl-gcc: tools/gen-musl-gcc.sh config.mak |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 97 | sh $< "$(prefix)" "$(LDSO_PATHNAME)" > $@ || { rm -f $@ ; exit 1 ; } |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 98 | chmod +x $@ |
| 99 | |
| 100 | $(DESTDIR)$(bindir)/%: tools/% |
| 101 | install -D $< $@ |
| 102 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 103 | $(DESTDIR)$(libdir)/%.so: lib/%.so |
| 104 | install -D -m 755 $< $@ |
| 105 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 106 | $(DESTDIR)$(libdir)/%: lib/% |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 107 | install -D -m 644 $< $@ |
| 108 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 109 | $(DESTDIR)$(includedir)/%: include/% |
| 110 | install -D -m 644 $< $@ |
| 111 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame^] | 112 | $(DESTDIR)$(LDSO_PATHNAME): lib/libc.so |
| 113 | ln -sf $(libdir)/libc.so $@ || true |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 114 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 115 | .PRECIOUS: $(CRT_LIBS:lib/%=crt/%) |
| 116 | |
| 117 | .PHONY: all clean install |