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.
12 exec_prefix = /usr
/local
13 bindir = $(exec_prefix)/bin
15 prefix = /usr
/local
/musl
16 includedir = $(prefix)/include
17 libdir = $(prefix)/lib
20 BASE_SRCS
= $(sort $(wildcard $(srcdir)/src
/*/*.c
$(srcdir)/arch
/$(ARCH
)/src
/*.
[csS
]))
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
)
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
65 LDSO_PATHNAME
= $(syslibdir
)/ld-musl-
$(ARCH
)$(SUBARCH
).so
.1
70 $(error Please set ARCH in config.mak before running make.
)
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
)
82 install: install-libs install-headers install-tools
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
$@
-
136 obj
/%.o
: $(srcdir)/%.s
139 obj
/%.o
: $(srcdir)/%.S
142 obj
/%.o
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
145 obj
/%.lo
: $(srcdir)/%.s
148 obj
/%.lo
: $(srcdir)/%.S
151 obj
/%.lo
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
154 lib
/libc.so
: $(LOBJS
)
155 $(CC
) $(CFLAGS_ALL
) $(LDFLAGS_ALL
) -nostdlib
-shared \
156 -Wl
,-e
,_dlstart
-Wl
,-Bsymbolic-functions \
157 -o
$@
$(LOBJS
) $(LIBCC
)
171 lib
/crti.o
: obj
/crt
/$(ARCH
)/crti.o
174 lib
/crtn.o
: obj
/crt
/$(ARCH
)/crtn.o
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)" > $@
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' $< > $@
188 $(DESTDIR
)$(bindir)/%: obj
/%
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
,%,$@
)
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