1570af302Sopenharmony_ci# 2570af302Sopenharmony_ci# Makefile for musl (requires GNU make) 3570af302Sopenharmony_ci# 4570af302Sopenharmony_ci# This is how simple every makefile should be... 5570af302Sopenharmony_ci# No, I take that back - actually most should be less than half this size. 6570af302Sopenharmony_ci# 7570af302Sopenharmony_ci# Use config.mak to override any of the following variables. 8570af302Sopenharmony_ci# Do not make changes here. 9570af302Sopenharmony_ci# 10570af302Sopenharmony_ci 11570af302Sopenharmony_cisrcdir = . 12570af302Sopenharmony_ciexec_prefix = /usr/local 13570af302Sopenharmony_cibindir = $(exec_prefix)/bin 14570af302Sopenharmony_ci 15570af302Sopenharmony_ciprefix = /usr/local/musl 16570af302Sopenharmony_ciincludedir = $(prefix)/include 17570af302Sopenharmony_cilibdir = $(prefix)/lib 18570af302Sopenharmony_cisyslibdir = /lib 19570af302Sopenharmony_ci 20570af302Sopenharmony_ciMALLOC_DIR = mallocng 21570af302Sopenharmony_ciSRC_DIRS = $(addprefix $(srcdir)/,src/* src/malloc/$(MALLOC_DIR) crt ldso $(COMPAT_SRC_DIRS)) 22570af302Sopenharmony_ciBASE_GLOBS = $(addsuffix /*.c,$(SRC_DIRS)) 23570af302Sopenharmony_ciARCH_GLOBS = $(addsuffix /$(ARCH)/*.[csS],$(SRC_DIRS)) 24570af302Sopenharmony_ciBASE_SRCS = $(sort $(wildcard $(BASE_GLOBS))) 25570af302Sopenharmony_ciARCH_SRCS = $(sort $(wildcard $(ARCH_GLOBS))) 26570af302Sopenharmony_ciBASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS))) 27570af302Sopenharmony_ciARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS))) 28570af302Sopenharmony_ciREPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS))) 29570af302Sopenharmony_ciALL_OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS)))) 30570af302Sopenharmony_ci 31570af302Sopenharmony_ciLIBC_OBJS = $(filter obj/src/%,$(ALL_OBJS)) $(filter obj/compat/%,$(ALL_OBJS)) 32570af302Sopenharmony_ciLDSO_OBJS = $(filter obj/ldso/%,$(ALL_OBJS:%.o=%.lo)) 33570af302Sopenharmony_ciCRT_OBJS = $(filter obj/crt/%,$(ALL_OBJS)) 34570af302Sopenharmony_ci 35570af302Sopenharmony_ciAOBJS = $(LIBC_OBJS) 36570af302Sopenharmony_ciLOBJS = $(LIBC_OBJS:.o=.lo) 37570af302Sopenharmony_ciGENH = obj/include/bits/alltypes.h obj/include/bits/syscall.h 38570af302Sopenharmony_ciGENH_INT = obj/src/internal/version.h 39570af302Sopenharmony_ciIMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/locale_impl.h src/internal/libc.h) 40570af302Sopenharmony_ci 41570af302Sopenharmony_ciLDFLAGS = 42570af302Sopenharmony_ciLDFLAGS_AUTO = 43570af302Sopenharmony_ciLIBCC = -lgcc 44570af302Sopenharmony_ciCPPFLAGS = 45570af302Sopenharmony_ciCFLAGS = 46570af302Sopenharmony_ciCFLAGS_AUTO = -Os -pipe 47570af302Sopenharmony_ciCFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc 48570af302Sopenharmony_ci 49570af302Sopenharmony_ciCFLAGS_ALL = $(CFLAGS_C99FSE) 50570af302Sopenharmony_ciCFLAGS_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 51570af302Sopenharmony_ciCFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS) 52570af302Sopenharmony_ci 53570af302Sopenharmony_ciLDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS) 54570af302Sopenharmony_ci 55570af302Sopenharmony_ciAR = $(CROSS_COMPILE)ar 56570af302Sopenharmony_ciRANLIB = $(CROSS_COMPILE)ranlib 57570af302Sopenharmony_ciINSTALL = $(srcdir)/tools/install.sh 58570af302Sopenharmony_ci 59570af302Sopenharmony_ciARCH_INCLUDES = $(wildcard $(srcdir)/arch/$(ARCH)/bits/*.h) 60570af302Sopenharmony_ciGENERIC_INCLUDES = $(wildcard $(srcdir)/arch/generic/bits/*.h) 61570af302Sopenharmony_ciINCLUDES = $(wildcard $(srcdir)/include/*.h $(srcdir)/include/*/*.h) 62570af302Sopenharmony_ciALL_INCLUDES = $(sort $(INCLUDES:$(srcdir)/%=%) $(GENH:obj/%=%) $(ARCH_INCLUDES:$(srcdir)/arch/$(ARCH)/%=include/%) $(GENERIC_INCLUDES:$(srcdir)/arch/generic/%=include/%)) 63570af302Sopenharmony_ci 64570af302Sopenharmony_ciEMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl 65570af302Sopenharmony_ciEMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) 66570af302Sopenharmony_ciCRT_LIBS = $(addprefix lib/,$(notdir $(CRT_OBJS))) 67570af302Sopenharmony_ciSTATIC_LIBS = lib/libc.a 68570af302Sopenharmony_ciSHARED_LIBS = lib/libc.so 69570af302Sopenharmony_ciTOOL_LIBS = lib/musl-gcc.specs 70570af302Sopenharmony_ciALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) 71570af302Sopenharmony_ciALL_TOOLS = obj/musl-gcc 72570af302Sopenharmony_ci 73570af302Sopenharmony_ciWRAPCC_GCC = gcc 74570af302Sopenharmony_ciWRAPCC_CLANG = clang 75570af302Sopenharmony_ci 76570af302Sopenharmony_ciLDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 77570af302Sopenharmony_ci 78570af302Sopenharmony_ci-include config.mak 79570af302Sopenharmony_ci-include $(srcdir)/arch/$(ARCH)/arch.mak 80570af302Sopenharmony_ci 81570af302Sopenharmony_ciifeq ($(ARCH),) 82570af302Sopenharmony_ci 83570af302Sopenharmony_ciall: 84570af302Sopenharmony_ci @echo "Please set ARCH in config.mak before running make." 85570af302Sopenharmony_ci @exit 1 86570af302Sopenharmony_ci 87570af302Sopenharmony_cielse 88570af302Sopenharmony_ci 89570af302Sopenharmony_ciall: $(ALL_LIBS) $(ALL_TOOLS) 90570af302Sopenharmony_ci 91570af302Sopenharmony_ciOBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(GENH) $(GENH_INT))) obj/include) 92570af302Sopenharmony_ci 93570af302Sopenharmony_ci$(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.lo) $(GENH) $(GENH_INT): | $(OBJ_DIRS) 94570af302Sopenharmony_ci 95570af302Sopenharmony_ci$(OBJ_DIRS): 96570af302Sopenharmony_ci mkdir -p $@ 97570af302Sopenharmony_ci 98570af302Sopenharmony_ciobj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed 99570af302Sopenharmony_ci sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@ 100570af302Sopenharmony_ci 101570af302Sopenharmony_ciobj/include/bits/syscall.h: $(srcdir)/arch/$(ARCH)/bits/syscall.h.in 102570af302Sopenharmony_ci cp $< $@ 103570af302Sopenharmony_ci sed -n -e s/__NR_/SYS_/p < $< >> $@ 104570af302Sopenharmony_ci 105570af302Sopenharmony_ciobj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git) 106570af302Sopenharmony_ci printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@ 107570af302Sopenharmony_ci 108570af302Sopenharmony_ciobj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h 109570af302Sopenharmony_ci 110570af302Sopenharmony_ciobj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h 111570af302Sopenharmony_ci 112570af302Sopenharmony_ciobj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h 113570af302Sopenharmony_ci 114570af302Sopenharmony_ciobj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c 115570af302Sopenharmony_ci 116570af302Sopenharmony_ciobj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC 117570af302Sopenharmony_ci 118570af302Sopenharmony_ciOPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) 119570af302Sopenharmony_ci$(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3 120570af302Sopenharmony_ci 121570af302Sopenharmony_ciMEMOPS_OBJS = $(filter %/memcpy.o %/memmove.o %/memcmp.o %/memset.o, $(LIBC_OBJS)) 122570af302Sopenharmony_ci$(MEMOPS_OBJS) $(MEMOPS_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) 123570af302Sopenharmony_ci 124570af302Sopenharmony_ciNOSSP_OBJS = $(CRT_OBJS) $(LDSO_OBJS) $(filter \ 125570af302Sopenharmony_ci %/__libc_start_main.o %/__init_tls.o %/__stack_chk_fail.o \ 126570af302Sopenharmony_ci %/__set_thread_area.o %/memset.o %/memcpy.o \ 127570af302Sopenharmony_ci , $(LIBC_OBJS)) 128570af302Sopenharmony_ci$(NOSSP_OBJS) $(NOSSP_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP) 129570af302Sopenharmony_ci 130570af302Sopenharmony_ci$(CRT_OBJS): CFLAGS_ALL += -DCRT 131570af302Sopenharmony_ci 132570af302Sopenharmony_ci$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC 133570af302Sopenharmony_ci 134570af302Sopenharmony_ciCC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $< 135570af302Sopenharmony_ci 136570af302Sopenharmony_ci# Choose invocation of assembler to be used 137570af302Sopenharmony_ciifeq ($(ADD_CFI),yes) 138570af302Sopenharmony_ci 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 $@ - 139570af302Sopenharmony_cielse 140570af302Sopenharmony_ci AS_CMD = $(CC_CMD) 141570af302Sopenharmony_ciendif 142570af302Sopenharmony_ci 143570af302Sopenharmony_ciobj/%.o: $(srcdir)/%.s 144570af302Sopenharmony_ci $(AS_CMD) 145570af302Sopenharmony_ci 146570af302Sopenharmony_ciobj/%.o: $(srcdir)/%.S 147570af302Sopenharmony_ci $(CC_CMD) 148570af302Sopenharmony_ci 149570af302Sopenharmony_ciobj/%.o: $(srcdir)/%.c $(GENH) $(IMPH) 150570af302Sopenharmony_ci $(CC_CMD) 151570af302Sopenharmony_ci 152570af302Sopenharmony_ciobj/%.lo: $(srcdir)/%.s 153570af302Sopenharmony_ci $(AS_CMD) 154570af302Sopenharmony_ci 155570af302Sopenharmony_ciobj/%.lo: $(srcdir)/%.S 156570af302Sopenharmony_ci $(CC_CMD) 157570af302Sopenharmony_ci 158570af302Sopenharmony_ciobj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH) 159570af302Sopenharmony_ci $(CC_CMD) 160570af302Sopenharmony_ci 161570af302Sopenharmony_cilib/libc.so: $(LOBJS) $(LDSO_OBJS) 162570af302Sopenharmony_ci $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \ 163570af302Sopenharmony_ci -Wl,-e,_dlstart -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC) 164570af302Sopenharmony_ci 165570af302Sopenharmony_cilib/libc.a: $(AOBJS) 166570af302Sopenharmony_ci rm -f $@ 167570af302Sopenharmony_ci $(AR) rc $@ $(AOBJS) 168570af302Sopenharmony_ci $(RANLIB) $@ 169570af302Sopenharmony_ci 170570af302Sopenharmony_ci$(EMPTY_LIBS): 171570af302Sopenharmony_ci rm -f $@ 172570af302Sopenharmony_ci $(AR) rc $@ 173570af302Sopenharmony_ci 174570af302Sopenharmony_cilib/%.o: obj/crt/$(ARCH)/%.o 175570af302Sopenharmony_ci cp $< $@ 176570af302Sopenharmony_ci 177570af302Sopenharmony_cilib/%.o: obj/crt/%.o 178570af302Sopenharmony_ci cp $< $@ 179570af302Sopenharmony_ci 180570af302Sopenharmony_cilib/musl-gcc.specs: $(srcdir)/tools/musl-gcc.specs.sh config.mak 181570af302Sopenharmony_ci sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ 182570af302Sopenharmony_ci 183570af302Sopenharmony_ciobj/musl-gcc: config.mak 184570af302Sopenharmony_ci printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ 185570af302Sopenharmony_ci chmod +x $@ 186570af302Sopenharmony_ci 187570af302Sopenharmony_ciobj/%-clang: $(srcdir)/tools/%-clang.in config.mak 188570af302Sopenharmony_ci 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' $< > $@ 189570af302Sopenharmony_ci chmod +x $@ 190570af302Sopenharmony_ci 191570af302Sopenharmony_ci$(DESTDIR)$(bindir)/%: obj/% 192570af302Sopenharmony_ci $(INSTALL) -D $< $@ 193570af302Sopenharmony_ci 194570af302Sopenharmony_ci$(DESTDIR)$(libdir)/%.so: lib/%.so 195570af302Sopenharmony_ci $(INSTALL) -D -m 755 $< $@ 196570af302Sopenharmony_ci 197570af302Sopenharmony_ci$(DESTDIR)$(libdir)/%: lib/% 198570af302Sopenharmony_ci $(INSTALL) -D -m 644 $< $@ 199570af302Sopenharmony_ci 200570af302Sopenharmony_ci$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/$(ARCH)/bits/% 201570af302Sopenharmony_ci $(INSTALL) -D -m 644 $< $@ 202570af302Sopenharmony_ci 203570af302Sopenharmony_ci$(DESTDIR)$(includedir)/bits/%: $(srcdir)/arch/generic/bits/% 204570af302Sopenharmony_ci $(INSTALL) -D -m 644 $< $@ 205570af302Sopenharmony_ci 206570af302Sopenharmony_ci$(DESTDIR)$(includedir)/bits/%: obj/include/bits/% 207570af302Sopenharmony_ci $(INSTALL) -D -m 644 $< $@ 208570af302Sopenharmony_ci 209570af302Sopenharmony_ci$(DESTDIR)$(includedir)/%: $(srcdir)/include/% 210570af302Sopenharmony_ci $(INSTALL) -D -m 644 $< $@ 211570af302Sopenharmony_ci 212570af302Sopenharmony_ci$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so 213570af302Sopenharmony_ci $(INSTALL) -D -l $(libdir)/libc.so $@ || true 214570af302Sopenharmony_ci 215570af302Sopenharmony_ciinstall-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),) 216570af302Sopenharmony_ci 217570af302Sopenharmony_ciinstall-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%) 218570af302Sopenharmony_ci 219570af302Sopenharmony_ciinstall-tools: $(ALL_TOOLS:obj/%=$(DESTDIR)$(bindir)/%) 220570af302Sopenharmony_ci 221570af302Sopenharmony_ciinstall: install-libs install-headers install-tools 222570af302Sopenharmony_ci 223570af302Sopenharmony_cimusl-git-%.tar.gz: .git 224570af302Sopenharmony_ci git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ $(patsubst musl-git-%.tar.gz,%,$@) 225570af302Sopenharmony_ci 226570af302Sopenharmony_cimusl-%.tar.gz: .git 227570af302Sopenharmony_ci git --git-dir=$(srcdir)/.git archive --format=tar.gz --prefix=$(patsubst %.tar.gz,%,$@)/ -o $@ v$(patsubst musl-%.tar.gz,%,$@) 228570af302Sopenharmony_ci 229570af302Sopenharmony_ciendif 230570af302Sopenharmony_ci 231570af302Sopenharmony_ciclean: 232570af302Sopenharmony_ci rm -rf obj lib 233570af302Sopenharmony_ci 234570af302Sopenharmony_cidistclean: clean 235570af302Sopenharmony_ci rm -f config.mak 236570af302Sopenharmony_ci 237570af302Sopenharmony_ci.PHONY: all clean install install-libs install-headers install-tools 238