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
19 SRCS
= $(sort $(wildcard src
/*/*.c arch
/$(ARCH
)/src
/*.c
))
21 LOBJS
= $(OBJS
:.o
=.lo
)
22 GENH
= include/bits
/alltypes.h
23 GENH_INT
= src
/internal
/version.h
24 IMPH
= src
/internal
/stdio_impl.h src
/internal
/pthread_impl.h src
/internal
/libc.h
30 CFLAGS_C99FSE
= -std
=c99
-ffreestanding
-nostdinc
32 CFLAGS_ALL
= $(CFLAGS_C99FSE
)
33 CFLAGS_ALL
+= -D_XOPEN_SOURCE
=700 -I.
/arch
/$(ARCH
) -I.
/src
/internal
-I.
/include
34 CFLAGS_ALL
+= $(CPPFLAGS
) $(CFLAGS
)
35 CFLAGS_ALL_STATIC
= $(CFLAGS_ALL
)
36 CFLAGS_ALL_SHARED
= $(CFLAGS_ALL
) -fPIC
-DSHARED
38 AR
= $(CROSS_COMPILE
)ar
39 RANLIB
= $(CROSS_COMPILE
)ranlib
40 INSTALL
= .
/tools
/install.sh
42 ARCH_INCLUDES
= $(wildcard arch
/$(ARCH
)/bits
/*.h
)
43 ALL_INCLUDES
= $(sort $(wildcard include/*.h
include/*/*.h
) $(GENH
) $(ARCH_INCLUDES
:arch
/$(ARCH
)/%=include/%))
45 EMPTY_LIB_NAMES
= m rt pthread crypt util xnet resolv dl
46 EMPTY_LIBS
= $(EMPTY_LIB_NAMES
:%=lib
/lib
%.a
)
47 CRT_LIBS
= lib
/crt1.o lib
/Scrt1.o lib
/rcrt1.o lib
/crti.o lib
/crtn.o
48 STATIC_LIBS
= lib
/libc.a
49 SHARED_LIBS
= lib
/libc.so
50 TOOL_LIBS
= lib
/musl-gcc.specs
51 ALL_LIBS
= $(CRT_LIBS
) $(STATIC_LIBS
) $(SHARED_LIBS
) $(EMPTY_LIBS
) $(TOOL_LIBS
)
52 ALL_TOOLS
= tools
/musl-gcc
57 LDSO_PATHNAME
= $(syslibdir
)/ld-musl-
$(ARCH
)$(SUBARCH
).so
.1
61 all: $(ALL_LIBS
) $(ALL_TOOLS
)
63 install: install-libs install-headers install-tools
69 rm -f
$(ALL_LIBS
) lib
/*.
[ao
] lib
/*.so
71 rm -f
$(GENH
) $(GENH_INT
)
78 @
test "$(ARCH)" ||
{ echo
"Please set ARCH in config.mak before running make." ; exit
1 ; }
79 ln
-sf ..
/arch
/$(ARCH
)/bits
$@
81 include/bits
/alltypes.h.in
: include/bits
83 include/bits
/alltypes.h
: include/bits
/alltypes.h.in
include/alltypes.h.in tools
/mkalltypes.sed
84 sed
-f tools
/mkalltypes.sed
include/bits
/alltypes.h.in
include/alltypes.h.in
> $@
86 src
/internal
/version.h
: $(wildcard VERSION .git
)
87 printf
'#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
89 src
/internal
/version.lo
: src
/internal
/version.h
91 crt
/rcrt1.o src
/ldso
/dlstart.lo src
/ldso
/dynlink.lo
: src
/internal
/dynlink.h arch
/$(ARCH
)/reloc.h
93 crt
/crt1.o crt
/Scrt1.o crt
/rcrt1.o src
/ldso
/dlstart.lo
: $(wildcard arch
/$(ARCH
)/crt_arch.h
)
95 crt
/rcrt1.o
: src
/ldso
/dlstart.c
97 crt
/Scrt1.o crt
/rcrt1.o
: CFLAGS
+= -fPIC
99 OPTIMIZE_SRCS
= $(wildcard $(OPTIMIZE_GLOBS
:%=src
/%))
100 $(OPTIMIZE_SRCS
:%.c
=%.o
) $(OPTIMIZE_SRCS
:%.c
=%.lo
): CFLAGS
+= -O3
102 MEMOPS_SRCS
= src
/string
/memcpy.c src
/string
/memmove.c src
/string
/memcmp.c src
/string
/memset.c
103 $(MEMOPS_SRCS
:%.c
=%.o
) $(MEMOPS_SRCS
:%.c
=%.lo
): CFLAGS
+= $(CFLAGS_MEMOPS
)
105 NOSSP_SRCS
= $(wildcard crt
/*.c
) \
106 src
/env
/__libc_start_main.c src
/env
/__init_tls.c \
107 src
/thread
/__set_thread_area.c src
/env
/__stack_chk_fail.c \
108 src
/string
/memset.c src
/string
/memcpy.c \
109 src
/ldso
/dlstart.c src
/ldso
/dynlink.c
110 $(NOSSP_SRCS
:%.c
=%.o
) $(NOSSP_SRCS
:%.c
=%.lo
): CFLAGS
+= $(CFLAGS_NOSSP
)
112 $(CRT_LIBS
:lib
/%=crt
/%): CFLAGS
+= -DCRT
114 # This incantation ensures that changes to any subarch asm files will
115 # force the corresponding object file to be rebuilt, even if the implicit
116 # rule below goes indirectly through a .sub file.
118 $(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s
=.o
)): $(1)
120 $(foreach s
,$(wildcard src
/*/$(ARCH
)*/*.s
),$(eval
$(call mkasmdep
,$(s
))))
122 # Choose invocation of assembler to be used
123 # $(1) is input file, $(2) is output file, $(3) is assembler flags
124 ifeq ($(ADD_CFI
),yes
)
125 AS_CMD
= LC_ALL
=C awk
-f tools
/add-cfi.common.awk
-f tools
/add-cfi.
$(ARCH
).awk
$< |
$(CC
) -x assembler
-c
-o
$@
-
127 AS_CMD
= $(CC
) -c
-o
$@
$<
130 %.o
: $(ARCH
)$(ASMSUBARCH
)/%.sub
131 $(CC
) $(CFLAGS_ALL_STATIC
) -c
-o
$@
$(dir $<)$(shell cat
$<)
134 $(AS_CMD
) $(CFLAGS_ALL_STATIC
)
136 %.o
: %.c
$(GENH
) $(IMPH
)
137 $(CC
) $(CFLAGS_ALL_STATIC
) -c
-o
$@
$<
139 %.lo
: $(ARCH
)$(ASMSUBARCH
)/%.sub
140 $(CC
) $(CFLAGS_ALL_SHARED
) -c
-o
$@
$(dir $<)$(shell cat
$<)
143 $(AS_CMD
) $(CFLAGS_ALL_SHARED
)
145 %.lo
: %.c
$(GENH
) $(IMPH
)
146 $(CC
) $(CFLAGS_ALL_SHARED
) -c
-o
$@
$<
148 lib
/libc.so
: $(LOBJS
)
149 $(CC
) $(CFLAGS_ALL_SHARED
) $(LDFLAGS
) -nostdlib
-shared \
150 -Wl
,-e
,_dlstart
-Wl
,-Bsymbolic-functions \
151 -o
$@
$(LOBJS
) $(LIBCC
)
165 lib
/musl-gcc.specs
: tools
/musl-gcc.specs.sh config.mak
166 sh
$< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
168 tools
/musl-gcc
: config.mak
169 printf
'#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
172 tools
/%-clang
: tools
/%-clang.in config.mak
173 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' $< > $@
176 $(DESTDIR
)$(bindir)/%: tools
/%
179 $(DESTDIR
)$(libdir)/%.so
: lib
/%.so
180 $(INSTALL
) -D
-m
755 $< $@
182 $(DESTDIR
)$(libdir)/%: lib
/%
183 $(INSTALL
) -D
-m
644 $< $@
185 $(DESTDIR
)$(includedir)/bits
/%: arch
/$(ARCH
)/bits
/%
186 $(INSTALL
) -D
-m
644 $< $@
188 $(DESTDIR
)$(includedir)/%: include/%
189 $(INSTALL
) -D
-m
644 $< $@
191 $(DESTDIR
)$(LDSO_PATHNAME
): $(DESTDIR
)$(libdir)/libc.so
192 $(INSTALL
) -D
-l
$(libdir)/libc.so
$@ || true
194 install-libs
: $(ALL_LIBS
:lib
/%=$(DESTDIR
)$(libdir)/%) $(if
$(SHARED_LIBS
),$(DESTDIR
)$(LDSO_PATHNAME
),)
196 install-headers
: $(ALL_INCLUDES
:include/%=$(DESTDIR
)$(includedir)/%)
198 install-tools
: $(ALL_TOOLS
:tools
/%=$(DESTDIR
)$(bindir)/%)
200 musl-git-
%.
tar.gz
: .git
201 git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@
$(patsubst musl-git-
%.
tar.gz
,%,$@
)
204 git archive
--format
=tar.gz
--prefix=$(patsubst %.
tar.gz
,%,$@
)/ -o
$@ v
$(patsubst musl-
%.
tar.gz
,%,$@
)
206 .PHONY
: all clean install install-libs install-headers install-tools