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 | |
rofl0r | 158f721 | 2013-02-06 02:11:49 +0100 | [diff] [blame] | 19 | SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c)) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 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) |
Rich Felker | 9f74574 | 2012-09-14 23:38:10 -0400 | [diff] [blame] | 35 | CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 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 | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 39 | INSTALL = ./tools/install.sh |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 40 | |
Rich Felker | d66ab4f | 2013-07-01 13:43:43 -0400 | [diff] [blame] | 41 | ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h) |
| 42 | ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%)) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 43 | |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 44 | EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 45 | EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) |
Rich Felker | 83023d1 | 2012-05-02 21:01:55 -0400 | [diff] [blame] | 46 | 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] | 47 | STATIC_LIBS = lib/libc.a |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 48 | SHARED_LIBS = lib/libc.so |
Rich Felker | 58f430c | 2012-04-22 14:32:49 -0400 | [diff] [blame] | 49 | TOOL_LIBS = lib/musl-gcc.specs |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 50 | ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 51 | ALL_TOOLS = tools/musl-gcc |
| 52 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 53 | LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 54 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 55 | -include config.mak |
| 56 | |
Rich Felker | 8d54681 | 2011-06-28 08:27:38 -0400 | [diff] [blame] | 57 | all: $(ALL_LIBS) $(ALL_TOOLS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 58 | |
Rich Felker | 0780936 | 2012-08-17 19:32:24 -0400 | [diff] [blame] | 59 | install: install-libs install-headers install-tools |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 60 | |
| 61 | clean: |
| 62 | rm -f crt/*.o |
| 63 | rm -f $(OBJS) |
| 64 | rm -f $(LOBJS) |
Rich Felker | 127ab57 | 2011-02-17 17:57:26 -0500 | [diff] [blame] | 65 | rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 66 | rm -f $(ALL_TOOLS) |
| 67 | rm -f $(GENH) |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 68 | rm -f include/bits |
| 69 | |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 70 | distclean: clean |
| 71 | rm -f config.mak |
| 72 | |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 73 | include/bits: |
Rich Felker | a36164c | 2011-02-17 15:15:03 -0500 | [diff] [blame] | 74 | @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] | 75 | ln -sf ../arch/$(ARCH)/bits $@ |
| 76 | |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 77 | include/bits/alltypes.h.in: include/bits |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 78 | |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 79 | include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed |
| 80 | sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 81 | |
Rich Felker | d043780 | 2012-08-05 12:32:20 -0400 | [diff] [blame] | 82 | src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h |
| 83 | |
Rich Felker | c5e34da | 2013-07-26 01:49:14 -0400 | [diff] [blame] | 84 | crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h) |
| 85 | |
| 86 | crt/Scrt1.o: CFLAGS += -fPIC |
| 87 | |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 88 | OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%)) |
| 89 | $(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3 |
| 90 | |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 91 | MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c |
| 92 | $(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS) |
| 93 | |
Rich Felker | fb72a97 | 2013-08-14 02:50:25 -0400 | [diff] [blame] | 94 | # This incantation ensures that changes to any subarch asm files will |
| 95 | # force the corresponding object file to be rebuilt, even if the implicit |
| 96 | # rule below goes indirectly through a .sub file. |
| 97 | define mkasmdep |
| 98 | $(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1) |
| 99 | endef |
| 100 | $(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s)))) |
| 101 | |
| 102 | %.o: $(ARCH)$(ASMSUBARCH)/%.sub |
| 103 | $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<) |
Rich Felker | 90d7772 | 2013-08-11 03:27:35 -0400 | [diff] [blame] | 104 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 105 | %.o: $(ARCH)/%.s |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 106 | $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 107 | |
Rich Felker | e765239 | 2012-05-03 20:35:11 -0400 | [diff] [blame] | 108 | %.o: %.c $(GENH) $(IMPH) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 109 | $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 110 | |
Rich Felker | fb72a97 | 2013-08-14 02:50:25 -0400 | [diff] [blame] | 111 | %.lo: $(ARCH)$(ASMSUBARCH)/%.sub |
| 112 | $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<) |
Rich Felker | 804e994 | 2013-08-11 03:49:16 -0400 | [diff] [blame] | 113 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 114 | %.lo: $(ARCH)/%.s |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 115 | $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 116 | |
Rich Felker | e765239 | 2012-05-03 20:35:11 -0400 | [diff] [blame] | 117 | %.lo: %.c $(GENH) $(IMPH) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 118 | $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $< |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 119 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 120 | lib/libc.so: $(LOBJS) |
Rich Felker | d76eafc | 2012-05-01 19:30:03 -0400 | [diff] [blame] | 121 | $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \ |
| 122 | -Wl,-e,_start -Wl,-Bsymbolic-functions \ |
Rich Felker | dfdc337 | 2013-03-09 22:34:11 -0500 | [diff] [blame] | 123 | -o $@ $(LOBJS) $(LIBCC) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 124 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 125 | lib/libc.a: $(OBJS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 126 | rm -f $@ |
| 127 | $(AR) rc $@ $(OBJS) |
| 128 | $(RANLIB) $@ |
| 129 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 130 | $(EMPTY_LIBS): |
| 131 | rm -f $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 132 | $(AR) rc $@ |
| 133 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 134 | lib/%.o: crt/%.o |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 135 | cp $< $@ |
| 136 | |
Rich Felker | 58f430c | 2012-04-22 14:32:49 -0400 | [diff] [blame] | 137 | lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak |
| 138 | sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ |
| 139 | |
| 140 | tools/musl-gcc: config.mak |
Rich Felker | 0b3e225 | 2012-09-21 13:47:26 -0400 | [diff] [blame] | 141 | printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 142 | chmod +x $@ |
| 143 | |
| 144 | $(DESTDIR)$(bindir)/%: tools/% |
Rich Felker | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 145 | $(INSTALL) -D $< $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 146 | |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 147 | $(DESTDIR)$(libdir)/%.so: lib/%.so |
Rich Felker | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 148 | $(INSTALL) -D -m 755 $< $@ |
Rich Felker | 207c45d | 2011-06-27 21:38:11 -0400 | [diff] [blame] | 149 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 150 | $(DESTDIR)$(libdir)/%: lib/% |
Rich Felker | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 151 | $(INSTALL) -D -m 644 $< $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 152 | |
Rich Felker | d66ab4f | 2013-07-01 13:43:43 -0400 | [diff] [blame] | 153 | $(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/% |
Rich Felker | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 154 | $(INSTALL) -D -m 644 $< $@ |
Rich Felker | d66ab4f | 2013-07-01 13:43:43 -0400 | [diff] [blame] | 155 | |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 156 | $(DESTDIR)$(includedir)/%: include/% |
Rich Felker | e678fc6 | 2013-08-17 22:21:11 -0400 | [diff] [blame] | 157 | $(INSTALL) -D -m 644 $< $@ |
Rich Felker | ec05a0b | 2011-06-23 22:13:47 -0400 | [diff] [blame] | 158 | |
Rich Felker | 82fa6b4 | 2013-08-16 17:51:38 -0400 | [diff] [blame] | 159 | $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so |
Rich Felker | 9ff8ed4 | 2013-08-31 11:36:56 -0400 | [diff] [blame^] | 160 | $(INSTALL) -D -l $(libdir)/libc.so $@ || true |
Rich Felker | f8e054f | 2012-05-04 21:54:57 -0400 | [diff] [blame] | 161 | |
Rich Felker | 0780936 | 2012-08-17 19:32:24 -0400 | [diff] [blame] | 162 | install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),) |
| 163 | |
| 164 | install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) |
| 165 | |
| 166 | install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) |
| 167 | |
| 168 | |
| 169 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 170 | .PRECIOUS: $(CRT_LIBS:lib/%=crt/%) |
| 171 | |
Rich Felker | 0780936 | 2012-08-17 19:32:24 -0400 | [diff] [blame] | 172 | .PHONY: all clean install install-libs install-headers install-tools |