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 |
| 17 | |
| 18 | SRCS = $(sort $(wildcard src/*/*.c)) |
| 19 | OBJS = $(SRCS:.c=.o) |
| 20 | LOBJS = $(OBJS:.o=.lo) |
| 21 | GENH = include/bits/alltypes.h |
| 22 | |
Rich Felker | 6027201 | 2011-02-13 16:48:39 -0500 | [diff] [blame] | 23 | CFLAGS = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 24 | LDFLAGS = -nostdlib -shared -fPIC -Wl,-e,_start -Wl,-Bsymbolic-functions |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 25 | INC = -I./include -I./src/internal -I./arch/$(ARCH) |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 26 | PIC = -fPIC -O3 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 27 | AR = $(CROSS_COMPILE)ar |
| 28 | RANLIB = $(CROSS_COMPILE)ranlib |
| 29 | OBJCOPY = $(CROSS_COMPILE)objcopy |
| 30 | |
| 31 | ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH)) |
| 32 | |
Rich Felker | 41d5183 | 2011-02-24 16:37:21 -0500 | [diff] [blame] | 33 | EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 34 | EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) |
| 35 | CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o |
| 36 | LIBC_LIBS = lib/libc.a |
| 37 | ALL_LIBS = $(LIBC_LIBS) $(CRT_LIBS) $(EMPTY_LIBS) |
| 38 | |
| 39 | ALL_TOOLS = tools/musl-gcc |
| 40 | |
| 41 | -include config.mak |
| 42 | |
| 43 | all: $(ALL_LIBS) $(ALL_TOOLS) |
| 44 | |
| 45 | install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%) |
| 46 | |
| 47 | clean: |
| 48 | rm -f crt/*.o |
| 49 | rm -f $(OBJS) |
| 50 | rm -f $(LOBJS) |
Rich Felker | 127ab57 | 2011-02-17 17:57:26 -0500 | [diff] [blame] | 51 | rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 52 | rm -f $(ALL_TOOLS) |
| 53 | rm -f $(GENH) |
Rich Felker | 1355fdc | 2011-02-15 00:33:23 -0500 | [diff] [blame] | 54 | rm -f include/bits |
| 55 | |
| 56 | include/bits: |
Rich Felker | a36164c | 2011-02-17 15:15:03 -0500 | [diff] [blame] | 57 | @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] | 58 | ln -sf ../arch/$(ARCH)/bits $@ |
| 59 | |
| 60 | include/bits/alltypes.h.sh: include/bits |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 61 | |
| 62 | include/bits/alltypes.h: include/bits/alltypes.h.sh |
| 63 | sh $< > $@ |
| 64 | |
| 65 | %.o: $(ARCH)/%.s |
| 66 | $(CC) $(CFLAGS) $(INC) -c -o $@ $< |
| 67 | |
| 68 | %.o: %.c $(GENH) |
| 69 | $(CC) $(CFLAGS) $(INC) -c -o $@ $< |
| 70 | |
| 71 | %.lo: $(ARCH)/%.s |
| 72 | $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< |
| 73 | |
| 74 | %.lo: %.c $(GENH) |
| 75 | $(CC) $(CFLAGS) $(INC) $(PIC) -c -o $@ $< |
| 76 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 77 | lib/libc.so: $(LOBJS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 78 | $(CC) $(LDFLAGS) -o $@ $(LOBJS) -lgcc |
| 79 | $(OBJCOPY) --weaken $@ |
| 80 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 81 | lib/libc.a: $(OBJS) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 82 | rm -f $@ |
| 83 | $(AR) rc $@ $(OBJS) |
| 84 | $(RANLIB) $@ |
| 85 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 86 | $(EMPTY_LIBS): |
| 87 | rm -f $@ |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 88 | $(AR) rc $@ |
| 89 | |
Rich Felker | 4fd1595 | 2011-02-17 17:12:52 -0500 | [diff] [blame] | 90 | lib/%.o: crt/%.o |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 91 | cp $< $@ |
| 92 | |
| 93 | tools/musl-gcc: tools/gen-musl-gcc.sh config.mak |
| 94 | sh $< "$(prefix)" > $@ || { rm -f $@ ; exit 1 ; } |
| 95 | chmod +x $@ |
| 96 | |
| 97 | $(DESTDIR)$(bindir)/%: tools/% |
| 98 | install -D $< $@ |
| 99 | |
| 100 | $(DESTDIR)$(prefix)/%: % |
| 101 | install -D -m 644 $< $@ |
| 102 | |
| 103 | .PRECIOUS: $(CRT_LIBS:lib/%=crt/%) |
| 104 | |
| 105 | .PHONY: all clean install |