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 SRC_DIRS
= $(addprefix $(srcdir)/,src
/* crt ldso
)
21 BASE_GLOBS
= $(addsuffix /*.c
,$(SRC_DIRS
))
22 ARCH_GLOBS
= $(addsuffix /$(ARCH
)/*.
[csS
],$(SRC_DIRS
))
23 BASE_SRCS
= $(sort $(wildcard $(BASE_GLOBS
)))
24 ARCH_SRCS
= $(sort $(wildcard $(ARCH_GLOBS
)))
25 BASE_OBJS
= $(patsubst $(srcdir)/%,%.o
,$(basename $(BASE_SRCS
)))
26 ARCH_OBJS
= $(patsubst $(srcdir)/%,%.o
,$(basename $(ARCH_SRCS
)))
27 REPLACED_OBJS
= $(sort $(subst /$(ARCH
)/,/,$(ARCH_OBJS
)))
28 ALL_OBJS
= $(addprefix obj
/, $(filter-out $(REPLACED_OBJS
), $(sort $(BASE_OBJS
) $(ARCH_OBJS
))))
30 LIBC_OBJS
= $(filter obj
/src
/%,$(ALL_OBJS
))
31 LDSO_OBJS
= $(filter obj
/ldso
/%,$(ALL_OBJS
:%.o
=%.lo
))
32 CRT_OBJS
= $(filter obj
/crt
/%,$(ALL_OBJS
))
35 LOBJS
= $(LIBC_OBJS
:.o
=.lo
)
36 GENH
= obj
/include/bits
/alltypes.h obj
/include/bits
/syscall.h
37 GENH_INT
= obj
/src
/internal
/version.h
38 IMPH
= $(addprefix $(srcdir)/, src
/internal
/stdio_impl.h src
/internal
/pthread_impl.h src
/internal
/libc.h
)
45 CFLAGS_AUTO
= -Os
-pipe
46 CFLAGS_C99FSE
= -std
=c99
-ffreestanding
-nostdinc
48 CFLAGS_ALL
= $(CFLAGS_C99FSE
)
49 CFLAGS_ALL
+= -D_XOPEN_SOURCE
=700 -I
$(srcdir)/arch
/$(ARCH
) -I
$(srcdir)/arch
/generic
-Iobj
/src
/internal
-I
$(srcdir)/src
/internal
-Iobj
/include -I
$(srcdir)/include
50 CFLAGS_ALL
+= $(CPPFLAGS
) $(CFLAGS_AUTO
) $(CFLAGS
)
52 LDFLAGS_ALL
= $(LDFLAGS_AUTO
) $(LDFLAGS
)
54 AR
= $(CROSS_COMPILE
)ar
55 RANLIB
= $(CROSS_COMPILE
)ranlib
56 INSTALL
= $(srcdir)/tools
/install.sh
58 ARCH_INCLUDES
= $(wildcard $(srcdir)/arch
/$(ARCH
)/bits
/*.h
)
59 GENERIC_INCLUDES
= $(wildcard $(srcdir)/arch
/generic
/bits
/*.h
)
60 INCLUDES
= $(wildcard $(srcdir)/include/*.h
$(srcdir)/include/*/*.h
)
61 ALL_INCLUDES
= $(sort $(INCLUDES
:$(srcdir)/%=%) $(GENH
:obj
/%=%) $(ARCH_INCLUDES
:$(srcdir)/arch
/$(ARCH
)/%=include/%) $(GENERIC_INCLUDES
:$(srcdir)/arch
/generic
/%=include/%))
63 EMPTY_LIB_NAMES
= m rt pthread crypt util xnet resolv dl
64 EMPTY_LIBS
= $(EMPTY_LIB_NAMES
:%=lib
/lib
%.a
)
65 CRT_LIBS
= $(addprefix lib
/,$(notdir $(CRT_OBJS
)))
66 STATIC_LIBS
= lib
/libc.a
67 SHARED_LIBS
= lib
/libc.so
68 TOOL_LIBS
= lib
/musl-gcc.specs
69 ALL_LIBS
= $(CRT_LIBS
) $(STATIC_LIBS
) $(SHARED_LIBS
) $(EMPTY_LIBS
) $(TOOL_LIBS
)
70 ALL_TOOLS
= obj
/musl-gcc
75 LDSO_PATHNAME
= $(syslibdir
)/ld-musl-
$(ARCH
)$(SUBARCH
).so
.1
82 @echo
"Please set ARCH in config.mak before running make."
87 all: $(ALL_LIBS
) $(ALL_TOOLS
)
89 OBJ_DIRS
= $(sort $(patsubst %/,%,$(dir $(ALL_LIBS
) $(ALL_TOOLS
) $(ALL_OBJS
) $(GENH
) $(GENH_INT
))) obj
/include)
91 $(ALL_LIBS
) $(ALL_TOOLS
) $(ALL_OBJS
) $(ALL_OBJS
:%.o
=%.lo
) $(GENH
) $(GENH_INT
): |
$(OBJ_DIRS
)
96 obj
/include/bits
/alltypes.h
: $(srcdir)/arch
/$(ARCH
)/bits
/alltypes.h.in
$(srcdir)/include/alltypes.h.in
$(srcdir)/tools
/mkalltypes.sed
97 sed
-f
$(srcdir)/tools
/mkalltypes.sed
$(srcdir)/arch
/$(ARCH
)/bits
/alltypes.h.in
$(srcdir)/include/alltypes.h.in
> $@
99 obj
/include/bits
/syscall.h
: $(srcdir)/arch
/$(ARCH
)/bits
/syscall.h.in
101 sed
-n
-e s
/__NR_
/SYS_
/p
< $< >> $@
103 obj
/src
/internal
/version.h
: $(wildcard $(srcdir)/VERSION
$(srcdir)/.git
)
104 printf
'#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
106 obj
/src
/internal
/version.o obj
/src
/internal
/version.lo
: obj
/src
/internal
/version.h
108 obj
/crt
/rcrt1.o obj
/ldso
/dlstart.lo obj
/ldso
/dynlink.lo
: $(srcdir)/src
/internal
/dynlink.h
$(srcdir)/arch
/$(ARCH
)/reloc.h
110 obj
/crt
/crt1.o obj
/crt
/scrt1.o obj
/crt
/rcrt1.o obj
/ldso
/dlstart.lo
: $(srcdir)/arch
/$(ARCH
)/crt_arch.h
112 obj
/crt
/rcrt1.o
: $(srcdir)/ldso
/dlstart.c
114 obj
/crt
/Scrt1.o obj
/crt
/rcrt1.o
: CFLAGS_ALL
+= -fPIC
116 obj
/crt
/$(ARCH
)/crti.o
: $(srcdir)/crt
/$(ARCH
)/crti.s
118 obj
/crt
/$(ARCH
)/crtn.o
: $(srcdir)/crt
/$(ARCH
)/crtn.s
120 OPTIMIZE_SRCS
= $(wildcard $(OPTIMIZE_GLOBS
:%=$(srcdir)/src
/%))
121 $(OPTIMIZE_SRCS
:$(srcdir)/%.c
=obj
/%.o
) $(OPTIMIZE_SRCS
:$(srcdir)/%.c
=obj
/%.lo
): CFLAGS
+= -O3
123 MEMOPS_SRCS
= src
/string
/memcpy.c src
/string
/memmove.c src
/string
/memcmp.c src
/string
/memset.c
124 $(MEMOPS_SRCS
:%.c
=obj
/%.o
) $(MEMOPS_SRCS
:%.c
=obj
/%.lo
): CFLAGS_ALL
+= $(CFLAGS_MEMOPS
)
126 NOSSP_SRCS
= $(wildcard crt
/*.c
) \
127 src
/env
/__libc_start_main.c src
/env
/__init_tls.c \
128 src
/env
/__stack_chk_fail.c \
129 src
/thread
/__set_thread_area.c src
/thread
/$(ARCH
)/__set_thread_area.c \
130 src
/string
/memset.c src
/string
/$(ARCH
)/memset.c \
131 src
/string
/memcpy.c src
/string
/$(ARCH
)/memcpy.c \
132 ldso
/dlstart.c ldso
/dynlink.c
133 $(NOSSP_SRCS
:%.c
=obj
/%.o
) $(NOSSP_SRCS
:%.c
=obj
/%.lo
): CFLAGS_ALL
+= $(CFLAGS_NOSSP
)
135 $(CRT_OBJS
): CFLAGS_ALL
+= -DCRT
137 $(LOBJS
) $(LDSO_OBJS
): CFLAGS_ALL
+= -fPIC
139 CC_CMD
= $(CC
) $(CFLAGS_ALL
) -c
-o
$@
$<
141 # Choose invocation of assembler to be used
142 ifeq ($(ADD_CFI
),yes
)
143 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
$@
-
148 obj
/%.o
: $(srcdir)/%.s
151 obj
/%.o
: $(srcdir)/%.S
154 obj
/%.o
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
157 obj
/%.lo
: $(srcdir)/%.s
160 obj
/%.lo
: $(srcdir)/%.S
163 obj
/%.lo
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
166 lib
/libc.so
: $(LOBJS
) $(LDSO_OBJS
)
167 $(CC
) $(CFLAGS_ALL
) $(LDFLAGS_ALL
) -nostdlib
-shared \
168 -Wl
,-e
,_dlstart
-o
$@
$(LOBJS
) $(LDSO_OBJS
) $(LIBCC
)
179 lib
/%.o
: obj
/crt
/$(ARCH
)/%.o
185 lib
/musl-gcc.specs
: $(srcdir)/tools
/musl-gcc.specs.sh config.mak
186 sh
$< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
188 obj
/musl-gcc
: config.mak
189 printf
'#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
192 obj
/%-clang
: $(srcdir)/tools
/%-clang.in config.mak
193 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' $< > $@
196 $(DESTDIR
)$(bindir)/%: obj
/%
199 $(DESTDIR
)$(libdir)/%.so
: lib
/%.so
200 $(INSTALL
) -D
-m
755 $< $@
202 $(DESTDIR
)$(libdir)/%: lib
/%
203 $(INSTALL
) -D
-m
644 $< $@
205 $(DESTDIR
)$(includedir)/bits
/%: $(srcdir)/arch
/$(ARCH
)/bits
/%
206 $(INSTALL
) -D
-m
644 $< $@
208 $(DESTDIR
)$(includedir)/bits
/%: $(srcdir)/arch
/generic
/bits
/%
209 $(INSTALL
) -D
-m
644 $< $@
211 $(DESTDIR
)$(includedir)/bits
/%: obj
/include/bits
/%
212 $(INSTALL
) -D
-m
644 $< $@
214 $(DESTDIR
)$(includedir)/%: $(srcdir)/include/%
215 $(INSTALL
) -D
-m
644 $< $@
217 $(DESTDIR
)$(LDSO_PATHNAME
): $(DESTDIR
)$(libdir)/libc.so
218 $(INSTALL
) -D
-l
$(libdir)/libc.so
$@ || true
220 install-libs
: $(ALL_LIBS
:lib
/%=$(DESTDIR
)$(libdir)/%) $(if
$(SHARED_LIBS
),$(DESTDIR
)$(LDSO_PATHNAME
),)
222 install-headers
: $(ALL_INCLUDES
:include/%=$(DESTDIR
)$(includedir)/%)
224 install-tools
: $(ALL_TOOLS
:obj
/%=$(DESTDIR
)$(bindir)/%)
226 install: install-libs install-headers install-tools
228 musl-git-
%.
tar.gz
: .git
229 git
--git-dir
=$(srcdir)/.git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@
$(patsubst musl-git-
%.
tar.gz
,%,$@
)
232 git
--git-dir
=$(srcdir)/.git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@ v
$(patsubst musl-
%.
tar.gz
,%,$@
)
242 .PHONY
: all clean install install-libs install-headers install-tools