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 |
Rich Felker | e765239 | 2012-05-03 20:35:11 -0400 | [diff] [blame] | 23 | IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 24 | |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 25 | LDFLAGS = |
Rich Felker | 1b23145 | 2012-08-02 21:05:43 -0400 | [diff] [blame] | 26 | LIBCC = -lgcc |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 27 | CPPFLAGS = |
| 28 | CFLAGS = -Os -pipe |
| 29 | CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc |
| 30 | |
| 31 | CFLAGS_ALL = $(CFLAGS_C99FSE) |
Rich Felker | fcaec91 | 2012-07-11 02:44:14 -0400 | [diff] [blame] | 32 | CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 33 | CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS) |
| 34 | CFLAGS_ALL_STATIC = $(CFLAGS_ALL) |
| 35 | CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED -O3 |
| 36 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 37 | AR = $(CROSS_COMPILE)ar |
| 38 | RANLIB = $(CROSS_COMPILE)ranlib |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 39 | |
| 40 | ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH)) |
| 41 | |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 42 | EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 43 | EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) |
Rich Felker | 83023d1 | 2012-05-02 21:01:55 -0400 | [diff] [blame] | 44 | CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 45 | STATIC_LIBS = lib/libc.a |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 46 | SHARED_LIBS = lib/libc.so |
Rich Felker | 58f430c | 2012-04-22 14:32:49 -0400 | [diff] [blame] | 47 | TOOL_LIBS = lib/musl-gcc.specs |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 48 | ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 49 | ALL_TOOLS = tools/musl-gcc |
| 50 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 51 | LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1 |
| 52 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 53 | -include config.mak |
| 54 | |
Rich Felker | 8d54681 | 2011-06-28 08:27:38 -0400 | [diff] [blame] | 55 | all: $(ALL_LIBS) $(ALL_TOOLS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 56 | |
Rich Felker | 3c87026 | 2012-02-17 23:17:48 -0500 | [diff] [blame] | 57 | install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 58 | |
| 59 | clean: |
| 60 | rm -f crt/*.o |
| 61 | rm -f $(OBJS) |
| 62 | rm -f $(LOBJS) |
Rich Felker | 127ab57 | 2011-02-17 17:57:26 -0500 | [diff] [blame] | 63 | rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 64 | rm -f $(ALL_TOOLS) |
| 65 | rm -f $(GENH) |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 66 | rm -f include/bits |
| 67 | |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 68 | distclean: clean |
| 69 | rm -f config.mak |
| 70 | |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 71 | include/bits: |
Rich Felker | a36164c | 2011-02-17 15:15:03 -0500 | [diff] [blame] | 72 | @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] | 73 | ln -sf ../arch/$(ARCH)/bits $@ |
| 74 | |
| 75 | include/bits/alltypes.h.sh: include/bits |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 76 | |
| 77 | include/bits/alltypes.h: include/bits/alltypes.h.sh |
| 78 | sh $< > $@ |
| 79 | |
Rich Felker | d043780 | 2012-08-05 12:32:20 -0400 | [diff] [blame] | 80 | src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h |
| 81 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 82 | %.o: $(ARCH)/%.s |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 83 | $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 84 | |
Rich Felker | e765239 | 2012-05-03 20:35:11 -0400 | [diff] [blame] | 85 | %.o: %.c $(GENH) $(IMPH) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 86 | $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 87 | |
| 88 | %.lo: $(ARCH)/%.s |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 89 | $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 90 | |
Rich Felker | e765239 | 2012-05-03 20:35:11 -0400 | [diff] [blame] | 91 | %.lo: %.c $(GENH) $(IMPH) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 92 | $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 93 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 94 | lib/libc.so: $(LOBJS) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 95 | $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \ |
| 96 | -Wl,-e,_start -Wl,-Bsymbolic-functions \ |
Rich Felker | 1b23145 | 2012-08-02 21:05:43 -0400 | [diff] [blame] | 97 | -Wl,-soname=libc.so -o $@ $(LOBJS) $(LIBCC) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 98 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 99 | lib/libc.a: $(OBJS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 100 | rm -f $@ |
| 101 | $(AR) rc $@ $(OBJS) |
| 102 | $(RANLIB) $@ |
| 103 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 104 | $(EMPTY_LIBS): |
| 105 | rm -f $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 106 | $(AR) rc $@ |
| 107 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 108 | lib/%.o: crt/%.o |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 109 | cp $< $@ |
| 110 | |
Rich Felker | 58f430c | 2012-04-22 14:32:49 -0400 | [diff] [blame] | 111 | lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak |
| 112 | sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ |
| 113 | |
| 114 | tools/musl-gcc: config.mak |
| 115 | printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 116 | chmod +x $@ |
| 117 | |
| 118 | $(DESTDIR)$(bindir)/%: tools/% |
| 119 | install -D $< $@ |
| 120 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 121 | $(DESTDIR)$(libdir)/%.so: lib/%.so |
| 122 | install -D -m 755 $< $@ |
| 123 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 124 | $(DESTDIR)$(libdir)/%: lib/% |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 125 | install -D -m 644 $< $@ |
| 126 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 127 | $(DESTDIR)$(includedir)/%: include/% |
| 128 | install -D -m 644 $< $@ |
| 129 | |
Rich Felker | f8e054f | 2012-05-04 21:54:57 -0400 | [diff] [blame] | 130 | $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(syslibdir) |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 131 | ln -sf $(libdir)/libc.so $@ || true |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 132 | |
Rich Felker | f8e054f | 2012-05-04 21:54:57 -0400 | [diff] [blame] | 133 | $(DESTDIR)$(syslibdir): |
| 134 | install -d -m 755 $(DESTDIR)$(syslibdir) |
| 135 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 136 | .PRECIOUS: $(CRT_LIBS:lib/%=crt/%) |
| 137 | |
| 138 | .PHONY: all clean install |