fix inet_pton
[musl.git] / Makefile
blob7ac58d486c3ca803f07223c50c68dd0a218d17ba
2 # Makefile for musl (requires GNU make)
4 # This is how simple every makefile should be...
5 # No, I take that back - actually most should be less than half this size.
7 # Use config.mak to override any of the following variables.
8 # Do not make changes here.
11 exec_prefix = /usr/local
12 bindir = $(exec_prefix)/bin
14 prefix = /usr/local/musl
15 includedir = $(prefix)/include
16 libdir = $(prefix)/lib
17 syslibdir = /lib
19 SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
20 OBJS = $(SRCS:.c=.o)
21 LOBJS = $(OBJS:.o=.lo)
22 GENH = include/bits/alltypes.h
23 IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
25 LDFLAGS =
26 LIBCC = -lgcc
27 CPPFLAGS =
28 CFLAGS = -Os -pipe
29 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
31 CFLAGS_ALL = $(CFLAGS_C99FSE)
32 CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
33 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
34 CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
35 CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
37 AR = $(CROSS_COMPILE)ar
38 RANLIB = $(CROSS_COMPILE)ranlib
39 INSTALL = ./tools/install.sh
41 ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
42 ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
44 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
45 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
46 CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
47 STATIC_LIBS = lib/libc.a
48 SHARED_LIBS = lib/libc.so
49 TOOL_LIBS = lib/musl-gcc.specs
50 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
51 ALL_TOOLS = tools/musl-gcc
53 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
55 -include config.mak
57 all: $(ALL_LIBS) $(ALL_TOOLS)
59 install: install-libs install-headers install-tools
61 clean:
62 rm -f crt/*.o
63 rm -f $(OBJS)
64 rm -f $(LOBJS)
65 rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
66 rm -f $(ALL_TOOLS)
67 rm -f $(GENH)
68 rm -f include/bits
70 distclean: clean
71 rm -f config.mak
73 include/bits:
74 @test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
75 ln -sf ../arch/$(ARCH)/bits $@
77 include/bits/alltypes.h.in: include/bits
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 > $@
82 src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
84 crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
86 crt/Scrt1.o: CFLAGS += -fPIC
88 OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
89 $(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
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)
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))))
102 %.o: $(ARCH)$(ASMSUBARCH)/%.sub
103 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
105 %.o: $(ARCH)/%.s
106 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
108 %.o: %.c $(GENH) $(IMPH)
109 $(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
111 %.lo: $(ARCH)$(ASMSUBARCH)/%.sub
112 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
114 %.lo: $(ARCH)/%.s
115 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
117 %.lo: %.c $(GENH) $(IMPH)
118 $(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
120 lib/libc.so: $(LOBJS)
121 $(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
122 -Wl,-e,_start -Wl,-Bsymbolic-functions \
123 -o $@ $(LOBJS) $(LIBCC)
125 lib/libc.a: $(OBJS)
126 rm -f $@
127 $(AR) rc $@ $(OBJS)
128 $(RANLIB) $@
130 $(EMPTY_LIBS):
131 rm -f $@
132 $(AR) rc $@
134 lib/%.o: crt/%.o
135 cp $< $@
137 lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
138 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
140 tools/musl-gcc: config.mak
141 printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
142 chmod +x $@
144 $(DESTDIR)$(bindir)/%: tools/%
145 $(INSTALL) -D $< $@
147 $(DESTDIR)$(libdir)/%.so: lib/%.so
148 $(INSTALL) -D -m 755 $< $@
150 $(DESTDIR)$(libdir)/%: lib/%
151 $(INSTALL) -D -m 644 $< $@
153 $(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
154 $(INSTALL) -D -m 644 $< $@
156 $(DESTDIR)$(includedir)/%: include/%
157 $(INSTALL) -D -m 644 $< $@
159 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
160 $(INSTALL) -D -l $(libdir)/libc.so $@ || true
162 install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
164 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
166 install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
170 .PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
172 .PHONY: all clean install install-libs install-headers install-tools