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 MALLOC_DIR
= oldmalloc
21 SRC_DIRS
= $(addprefix $(srcdir)/,src
/* src
/malloc
/$(MALLOC_DIR
) crt ldso
$(COMPAT_SRC_DIRS
))
22 BASE_GLOBS
= $(addsuffix /*.c
,$(SRC_DIRS
))
23 ARCH_GLOBS
= $(addsuffix /$(ARCH
)/*.
[csS
],$(SRC_DIRS
))
24 BASE_SRCS
= $(sort $(wildcard $(BASE_GLOBS
)))
25 ARCH_SRCS
= $(sort $(wildcard $(ARCH_GLOBS
)))
26 BASE_OBJS
= $(patsubst $(srcdir)/%,%.o
,$(basename $(BASE_SRCS
)))
27 ARCH_OBJS
= $(patsubst $(srcdir)/%,%.o
,$(basename $(ARCH_SRCS
)))
28 REPLACED_OBJS
= $(sort $(subst /$(ARCH
)/,/,$(ARCH_OBJS
)))
29 ALL_OBJS
= $(addprefix obj
/, $(filter-out $(REPLACED_OBJS
), $(sort $(BASE_OBJS
) $(ARCH_OBJS
))))
31 LIBC_OBJS
= $(filter obj
/src
/%,$(ALL_OBJS
)) $(filter obj
/compat
/%,$(ALL_OBJS
))
32 LDSO_OBJS
= $(filter obj
/ldso
/%,$(ALL_OBJS
:%.o
=%.lo
))
33 CRT_OBJS
= $(filter obj
/crt
/%,$(ALL_OBJS
))
36 LOBJS
= $(LIBC_OBJS
:.o
=.lo
)
37 GENH
= obj
/include/bits
/alltypes.h obj
/include/bits
/syscall.h
38 GENH_INT
= obj
/src
/internal
/version.h
39 IMPH
= $(addprefix $(srcdir)/, src
/internal
/stdio_impl.h src
/internal
/pthread_impl.h src
/internal
/locale_impl.h src
/internal
/libc.h
)
46 CFLAGS_AUTO
= -Os
-pipe
47 CFLAGS_C99FSE
= -std
=c99
-ffreestanding
-nostdinc
49 CFLAGS_ALL
= $(CFLAGS_C99FSE
)
50 CFLAGS_ALL
+= -D_XOPEN_SOURCE
=700 -I
$(srcdir)/arch
/$(ARCH
) -I
$(srcdir)/arch
/generic
-Iobj
/src
/internal
-I
$(srcdir)/src
/include -I
$(srcdir)/src
/internal
-Iobj
/include -I
$(srcdir)/include
51 CFLAGS_ALL
+= $(CPPFLAGS
) $(CFLAGS_AUTO
) $(CFLAGS
)
53 LDFLAGS_ALL
= $(LDFLAGS_AUTO
) $(LDFLAGS
)
55 AR
= $(CROSS_COMPILE
)ar
56 RANLIB
= $(CROSS_COMPILE
)ranlib
57 INSTALL
= $(srcdir)/tools
/install.sh
59 ARCH_INCLUDES
= $(wildcard $(srcdir)/arch
/$(ARCH
)/bits
/*.h
)
60 GENERIC_INCLUDES
= $(wildcard $(srcdir)/arch
/generic
/bits
/*.h
)
61 INCLUDES
= $(wildcard $(srcdir)/include/*.h
$(srcdir)/include/*/*.h
)
62 ALL_INCLUDES
= $(sort $(INCLUDES
:$(srcdir)/%=%) $(GENH
:obj
/%=%) $(ARCH_INCLUDES
:$(srcdir)/arch
/$(ARCH
)/%=include/%) $(GENERIC_INCLUDES
:$(srcdir)/arch
/generic
/%=include/%))
64 EMPTY_LIB_NAMES
= m rt pthread crypt util xnet resolv dl
65 EMPTY_LIBS
= $(EMPTY_LIB_NAMES
:%=lib
/lib
%.a
)
66 CRT_LIBS
= $(addprefix lib
/,$(notdir $(CRT_OBJS
)))
67 STATIC_LIBS
= lib
/libc.a
68 SHARED_LIBS
= lib
/libc.so
69 TOOL_LIBS
= lib
/musl-gcc.specs
70 ALL_LIBS
= $(CRT_LIBS
) $(STATIC_LIBS
) $(SHARED_LIBS
) $(EMPTY_LIBS
) $(TOOL_LIBS
)
71 ALL_TOOLS
= obj
/musl-gcc
76 LDSO_PATHNAME
= $(syslibdir
)/ld-musl-
$(ARCH
)$(SUBARCH
).so
.1
79 -include $(srcdir)/arch
/$(ARCH
)/arch.mak
84 @echo
"Please set ARCH in config.mak before running make."
89 all: $(ALL_LIBS
) $(ALL_TOOLS
)
91 OBJ_DIRS
= $(sort $(patsubst %/,%,$(dir $(ALL_LIBS
) $(ALL_TOOLS
) $(ALL_OBJS
) $(GENH
) $(GENH_INT
))) obj
/include)
93 $(ALL_LIBS
) $(ALL_TOOLS
) $(ALL_OBJS
) $(ALL_OBJS
:%.o
=%.lo
) $(GENH
) $(GENH_INT
): |
$(OBJ_DIRS
)
98 obj
/include/bits
/alltypes.h
: $(srcdir)/arch
/$(ARCH
)/bits
/alltypes.h.in
$(srcdir)/include/alltypes.h.in
$(srcdir)/tools
/mkalltypes.sed
99 sed
-f
$(srcdir)/tools
/mkalltypes.sed
$(srcdir)/arch
/$(ARCH
)/bits
/alltypes.h.in
$(srcdir)/include/alltypes.h.in
> $@
101 obj
/include/bits
/syscall.h
: $(srcdir)/arch
/$(ARCH
)/bits
/syscall.h.in
103 sed
-n
-e s
/__NR_
/SYS_
/p
< $< >> $@
105 obj
/src
/internal
/version.h
: $(wildcard $(srcdir)/VERSION
$(srcdir)/.git
)
106 printf
'#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@
108 obj
/src
/internal
/version.o obj
/src
/internal
/version.lo
: obj
/src
/internal
/version.h
110 obj
/crt
/rcrt1.o obj
/ldso
/dlstart.lo obj
/ldso
/dynlink.lo
: $(srcdir)/src
/internal
/dynlink.h
$(srcdir)/arch
/$(ARCH
)/reloc.h
112 obj
/crt
/crt1.o obj
/crt
/scrt1.o obj
/crt
/rcrt1.o obj
/ldso
/dlstart.lo
: $(srcdir)/arch
/$(ARCH
)/crt_arch.h
114 obj
/crt
/rcrt1.o
: $(srcdir)/ldso
/dlstart.c
116 obj
/crt
/Scrt1.o obj
/crt
/rcrt1.o
: CFLAGS_ALL
+= -fPIC
118 OPTIMIZE_SRCS
= $(wildcard $(OPTIMIZE_GLOBS
:%=$(srcdir)/src
/%))
119 $(OPTIMIZE_SRCS
:$(srcdir)/%.c
=obj
/%.o
) $(OPTIMIZE_SRCS
:$(srcdir)/%.c
=obj
/%.lo
): CFLAGS
+= -O3
121 MEMOPS_OBJS
= $(filter %/memcpy.o
%/memmove.o
%/memcmp.o
%/memset.o
, $(LIBC_OBJS
))
122 $(MEMOPS_OBJS
) $(MEMOPS_OBJS
:%.o
=%.lo
): CFLAGS_ALL
+= $(CFLAGS_MEMOPS
)
124 NOSSP_OBJS
= $(CRT_OBJS
) $(LDSO_OBJS
) $(filter \
125 %/__libc_start_main.o
%/__init_tls.o
%/__stack_chk_fail.o \
126 %/__set_thread_area.o
%/memset.o
%/memcpy.o \
128 $(NOSSP_OBJS
) $(NOSSP_OBJS
:%.o
=%.lo
): CFLAGS_ALL
+= $(CFLAGS_NOSSP
)
130 $(CRT_OBJS
): CFLAGS_ALL
+= -DCRT
132 $(LOBJS
) $(LDSO_OBJS
): CFLAGS_ALL
+= -fPIC
134 CC_CMD
= $(CC
) $(CFLAGS_ALL
) -c
-o
$@
$<
136 # Choose invocation of assembler to be used
137 ifeq ($(ADD_CFI
),yes
)
138 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
$@
-
143 obj
/%.o
: $(srcdir)/%.s
146 obj
/%.o
: $(srcdir)/%.S
149 obj
/%.o
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
152 obj
/%.lo
: $(srcdir)/%.s
155 obj
/%.lo
: $(srcdir)/%.S
158 obj
/%.lo
: $(srcdir)/%.c
$(GENH
) $(IMPH
)
161 lib
/libc.so
: $(LOBJS
) $(LDSO_OBJS
)
162 $(CC
) $(CFLAGS_ALL
) $(LDFLAGS_ALL
) -nostdlib
-shared \
163 -Wl
,-e
,_dlstart
-o
$@
$(LOBJS
) $(LDSO_OBJS
) $(LIBCC
)
174 lib
/%.o
: obj
/crt
/$(ARCH
)/%.o
180 lib
/musl-gcc.specs
: $(srcdir)/tools
/musl-gcc.specs.sh config.mak
181 sh
$< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
183 obj
/musl-gcc
: config.mak
184 printf
'#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
187 obj
/%-clang
: $(srcdir)/tools
/%-clang.in config.mak
188 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' $< > $@
191 $(DESTDIR
)$(bindir)/%: obj
/%
194 $(DESTDIR
)$(libdir)/%.so
: lib
/%.so
195 $(INSTALL
) -D
-m
755 $< $@
197 $(DESTDIR
)$(libdir)/%: lib
/%
198 $(INSTALL
) -D
-m
644 $< $@
200 $(DESTDIR
)$(includedir)/bits
/%: $(srcdir)/arch
/$(ARCH
)/bits
/%
201 $(INSTALL
) -D
-m
644 $< $@
203 $(DESTDIR
)$(includedir)/bits
/%: $(srcdir)/arch
/generic
/bits
/%
204 $(INSTALL
) -D
-m
644 $< $@
206 $(DESTDIR
)$(includedir)/bits
/%: obj
/include/bits
/%
207 $(INSTALL
) -D
-m
644 $< $@
209 $(DESTDIR
)$(includedir)/%: $(srcdir)/include/%
210 $(INSTALL
) -D
-m
644 $< $@
212 $(DESTDIR
)$(LDSO_PATHNAME
): $(DESTDIR
)$(libdir)/libc.so
213 $(INSTALL
) -D
-l
$(libdir)/libc.so
$@ || true
215 install-libs
: $(ALL_LIBS
:lib
/%=$(DESTDIR
)$(libdir)/%) $(if
$(SHARED_LIBS
),$(DESTDIR
)$(LDSO_PATHNAME
),)
217 install-headers
: $(ALL_INCLUDES
:include/%=$(DESTDIR
)$(includedir)/%)
219 install-tools
: $(ALL_TOOLS
:obj
/%=$(DESTDIR
)$(bindir)/%)
221 install: install-libs install-headers install-tools
223 musl-git-
%.
tar.gz
: .git
224 git
--git-dir
=$(srcdir)/.git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@
$(patsubst musl-git-
%.
tar.gz
,%,$@
)
227 git
--git-dir
=$(srcdir)/.git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@ v
$(patsubst musl-
%.
tar.gz
,%,$@
)
237 .PHONY
: all clean install install-libs install-headers install-tools