add new IP_BIND_ADDRESS_NO_PORT and IPPROTO_MPLS to netinet/in.h
[musl.git] / Makefile
blob3a60cfc030ab189b154a4a9f59531d8078b2a895
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 srcdir = .
12 exec_prefix = /usr/local
13 bindir = $(exec_prefix)/bin
15 prefix = /usr/local/musl
16 includedir = $(prefix)/include
17 libdir = $(prefix)/lib
18 syslibdir = /lib
20 BASE_SRCS = $(sort $(wildcard $(srcdir)/src/*/*.c))
21 BASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS)))
22 ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.[csS])
23 ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS)))
24 REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS)))
25 OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS))))
26 LOBJS = $(OBJS:.o=.lo)
27 GENH = obj/include/bits/alltypes.h
28 GENH_INT = obj/src/internal/version.h
29 IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h)
31 LDFLAGS =
32 LDFLAGS_AUTO =
33 LIBCC = -lgcc
34 CPPFLAGS =
35 CFLAGS =
36 CFLAGS_AUTO = -Os -pipe
37 CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
39 CFLAGS_ALL = $(CFLAGS_C99FSE)
40 CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -Iobj/src/internal -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
41 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
43 LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
45 AR = $(CROSS_COMPILE)ar
46 RANLIB = $(CROSS_COMPILE)ranlib
47 INSTALL = $(srcdir)/tools/install.sh
49 ARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h)
50 INCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h)
51 ALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH:obj/%=%) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%))
53 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
54 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
55 CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/rcrt1.o lib/crti.o lib/crtn.o
56 STATIC_LIBS = lib/libc.a
57 SHARED_LIBS = lib/libc.so
58 TOOL_LIBS = lib/musl-gcc.specs
59 ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
60 ALL_TOOLS = obj/musl-gcc
62 WRAPCC_GCC = gcc
63 WRAPCC_CLANG = clang
65 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
67 -include config.mak
69 ifeq ($(ARCH),)
70 $(error Please set ARCH in config.mak before running make.)
71 endif
73 all: $(ALL_LIBS) $(ALL_TOOLS)
75 OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
77 $(ALL_LIBS) $(ALL_TOOLS) $(CRT_LIBS:lib/%=obj/crt/%) $(OBJS) $(LOBJS) $(GENH) $(GENH_INT): | $(OBJ_DIRS)
79 $(OBJ_DIRS):
80 mkdir -p $@
82 install: install-libs install-headers install-tools
84 clean:
85 rm -rf obj lib
87 distclean: clean
88 rm -f config.mak
90 obj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed
91 sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@
93 obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git)
94 printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
96 obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h
98 obj/crt/rcrt1.o obj/src/ldso/dlstart.lo obj/src/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
100 obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/src/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
102 obj/crt/rcrt1.o: $(srcdir)/src/ldso/dlstart.c
104 obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC
106 obj/crt/$(ARCH)/crti.o: $(srcdir)/crt/$(ARCH)/crti.s
108 obj/crt/$(ARCH)/crtn.o: $(srcdir)/crt/$(ARCH)/crtn.s
110 OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%))
111 $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3
113 MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c
114 $(MEMOPS_SRCS:%.c=obj/%.o) $(MEMOPS_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS)
116 NOSSP_SRCS = $(wildcard crt/*.c) \
117 src/env/__libc_start_main.c src/env/__init_tls.c \
118 src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
119 src/string/memset.c src/string/memcpy.c \
120 src/ldso/dlstart.c src/ldso/dynlink.c
121 $(NOSSP_SRCS:%.c=obj/%.o) $(NOSSP_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
123 $(CRT_LIBS:lib/%=obj/crt/%): CFLAGS_ALL += -DCRT
125 $(LOBJS): CFLAGS_ALL += -fPIC -DSHARED
127 CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
129 # Choose invocation of assembler to be used
130 ifeq ($(ADD_CFI),yes)
131 AS_CMD = LC_ALL=C awk -f $(srcdir)/tools/add-cfi.common.awk -f $(srcdir)/tools/add-cfi.$(ARCH).awk $< | $(CC) $(CFLAGS_ALL) -x assembler -c -o $@ -
132 else
133 AS_CMD = $(CC_CMD)
134 endif
136 obj/%.o: $(srcdir)/%.s
137 $(AS_CMD)
139 obj/%.o: $(srcdir)/%.S
140 $(CC_CMD)
142 obj/%.o: $(srcdir)/%.c $(GENH) $(IMPH)
143 $(CC_CMD)
145 obj/%.lo: $(srcdir)/%.s
146 $(AS_CMD)
148 obj/%.lo: $(srcdir)/%.S
149 $(CC_CMD)
151 obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
152 $(CC_CMD)
154 lib/libc.so: $(LOBJS)
155 $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
156 -Wl,-e,_dlstart -Wl,-Bsymbolic-functions \
157 -o $@ $(LOBJS) $(LIBCC)
159 lib/libc.a: $(OBJS)
160 rm -f $@
161 $(AR) rc $@ $(OBJS)
162 $(RANLIB) $@
164 $(EMPTY_LIBS):
165 rm -f $@
166 $(AR) rc $@
168 lib/%.o: obj/crt/%.o
169 cp $< $@
171 lib/crti.o: obj/crt/$(ARCH)/crti.o
172 cp $< $@
174 lib/crtn.o: obj/crt/$(ARCH)/crtn.o
175 cp $< $@
177 lib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak
178 sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
180 obj/musl-gcc: config.mak
181 printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
182 chmod +x $@
184 obj/%-clang: $(srcdir)/tools/%-clang.in config.mak
185 sed -e 's!@CC@!$(WRAPCC_CLANG)!g' -e 's!@PREFIX@!$(prefix)!g' -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@
186 chmod +x $@
188 $(DESTDIR)$(bindir)/%: obj/%
189 $(INSTALL) -D $< $@
191 $(DESTDIR)$(libdir)/%.so: lib/%.so
192 $(INSTALL) -D -m 755 $< $@
194 $(DESTDIR)$(libdir)/%: lib/%
195 $(INSTALL) -D -m 644 $< $@
197 $(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/%
198 $(INSTALL) -D -m 644 $< $@
200 $(DESTDIR)$(includedir)/bits/%: obj/include/bits/%
201 $(INSTALL) -D -m 644 $< $@
203 $(DESTDIR)$(includedir)/%: $(srcdir)/include/%
204 $(INSTALL) -D -m 644 $< $@
206 $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
207 $(INSTALL) -D -l $(libdir)/libc.so $@ || true
209 install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
211 install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
213 install-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%)
215 musl-git-%.tar.gz: .git
216 git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@)
218 musl-%.tar.gz: .git
219 git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@)
221 .PHONY: all clean install install-libs install-headers install-tools