1## 2## Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3## 4## Use of this source code is governed by a BSD-style license 5## that can be found in the LICENSE file in the root of the source 6## tree. An additional intellectual property rights grant can be found 7## in the file PATENTS. All contributing project authors may 8## be found in the AUTHORS file in the root of the source tree. 9## 10 11 12include config.mk 13quiet?=true 14ifeq ($(target),) 15# If a target wasn't specified, invoke for all enabled targets. 16.DEFAULT: 17 @for t in $(ALL_TARGETS); do \ 18 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ 19 done 20all: .DEFAULT 21clean:: .DEFAULT 22exampletest: .DEFAULT 23install:: .DEFAULT 24test: .DEFAULT 25test-no-data-check: .DEFAULT 26testdata: .DEFAULT 27utiltest: .DEFAULT 28exampletest-no-data-check utiltest-no-data-check: .DEFAULT 29test_%: .DEFAULT ; 30 31# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be 32# installed on cygwin, so we need to autodetect here. 33md5sum := $(firstword $(wildcard \ 34 $(foreach e,md5sum openssl,\ 35 $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\ 36 )) 37md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum)) 38 39TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) 40dist: 41 @for t in $(ALL_TARGETS); do \ 42 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\ 43 done 44 # Run configure for the user with the current toolchain. 45 @if [ -d "$(DIST_DIR)/src" ]; then \ 46 mkdir -p "$(DIST_DIR)/build"; \ 47 cd "$(DIST_DIR)/build"; \ 48 echo "Rerunning configure $(CONFIGURE_ARGS)"; \ 49 ../src/configure $(CONFIGURE_ARGS); \ 50 $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \ 51 fi 52 @if [ -d "$(DIST_DIR)" ]; then \ 53 echo " [MD5SUM] $(DIST_DIR)"; \ 54 cd $(DIST_DIR) && \ 55 $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \ 56 | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2 \1/' \ 57 > md5sums.txt;\ 58 fi 59endif 60 61# Since we invoke make recursively for multiple targets we need to include the 62# .mk file for the correct target, but only when $(target) is non-empty. 63ifneq ($(target),) 64include $(target)-$(TOOLCHAIN).mk 65endif 66BUILD_ROOT?=. 67VPATH=$(SRC_PATH_BARE) 68CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH) 69CXXFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH) 70ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/ 71DIST_DIR?=dist 72HOSTCC?=gcc 73TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN))) 74TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN))) 75TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN))) 76quiet:=$(if $(or $(verbose), $(V)),, yes) 77qexec=$(if $(quiet),@) 78 79# Cancel built-in implicit rules 80%: %.o 81%.asm: 82%.a: 83%: %.cc 84 85# 86# Common rules" 87# 88.PHONY: all 89all: 90 91.PHONY: clean 92clean:: 93 rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.S.o=.asm.S) 94 rm -f $(CLEAN-OBJS) 95 96.PHONY: clean 97distclean: clean 98 if [ -z "$(target)" ]; then \ 99 rm -f Makefile; \ 100 rm -f config.log config.mk; \ 101 rm -f vpx_config.[hc] vpx_config.asm; \ 102 rm -f arm_neon.h; \ 103 else \ 104 rm -f $(target)-$(TOOLCHAIN).mk; \ 105 fi 106 107.PHONY: dist 108dist: 109.PHONY: exampletest 110exampletest: 111.PHONY: install 112install:: 113.PHONY: test 114test: 115.PHONY: testdata 116testdata: 117.PHONY: utiltest 118utiltest: 119.PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check 120test-no-data-check: 121exampletest-no-data-check utiltest-no-data-check: 122 123# Force to realign stack always on OS/2 124ifeq ($(TOOLCHAIN), x86-os2-gcc) 125CFLAGS += -mstackrealign 126endif 127 128# x86[_64] 129$(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx 130$(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx 131$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 132$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2 133$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3 134$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3 135$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3 136$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3 137$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1 138$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1 139$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx 140$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx 141$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2 142$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 143$(BUILD_PFX)%_avx512.c.d: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl 144$(BUILD_PFX)%_avx512.c.o: CFLAGS += -mavx512f -mavx512cd -mavx512bw -mavx512dq -mavx512vl 145 146# POWER 147$(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx 148$(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx 149 150# MIPS 151$(BUILD_PFX)%_msa.c.d: CFLAGS += -mmsa 152$(BUILD_PFX)%_msa.c.o: CFLAGS += -mmsa 153 154# LOONGARCH 155$(BUILD_PFX)%_lsx.c.d: CFLAGS += -mlsx 156$(BUILD_PFX)%_lsx.c.o: CFLAGS += -mlsx 157$(BUILD_PFX)%_lasx.c.d: CFLAGS += -mlasx 158$(BUILD_PFX)%_lasx.c.o: CFLAGS += -mlasx 159 160$(BUILD_PFX)%.c.d: %.c 161 $(if $(quiet),@echo " [DEP] $@") 162 $(qexec)mkdir -p $(dir $@) 163 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@ 164 165$(BUILD_PFX)%.c.o: %.c 166 $(if $(quiet),@echo " [CC] $@") 167 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 168 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $< 169 170$(BUILD_PFX)%.cc.d: %.cc 171 $(if $(quiet),@echo " [DEP] $@") 172 $(qexec)mkdir -p $(dir $@) 173 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@ 174 175$(BUILD_PFX)%.cc.o: %.cc 176 $(if $(quiet),@echo " [CXX] $@") 177 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 178 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< 179 180$(BUILD_PFX)%.cpp.d: %.cpp 181 $(if $(quiet),@echo " [DEP] $@") 182 $(qexec)mkdir -p $(dir $@) 183 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@ 184 185$(BUILD_PFX)%.cpp.o: %.cpp 186 $(if $(quiet),@echo " [CXX] $@") 187 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 188 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< 189 190$(BUILD_PFX)%.asm.d: %.asm 191 $(if $(quiet),@echo " [DEP] $@") 192 $(qexec)mkdir -p $(dir $@) 193 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 194 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 195 196$(BUILD_PFX)%.asm.o: %.asm 197 $(if $(quiet),@echo " [AS] $@") 198 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 199 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 200 201$(BUILD_PFX)%.S.d: %.S 202 $(if $(quiet),@echo " [DEP] $@") 203 $(qexec)mkdir -p $(dir $@) 204 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 205 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 206 207$(BUILD_PFX)%.S.o: %.S 208 $(if $(quiet),@echo " [AS] $@") 209 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 210 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 211 212.PRECIOUS: %.c.S 213%.c.S: CFLAGS += -DINLINE_ASM 214$(BUILD_PFX)%.c.S: %.c 215 $(if $(quiet),@echo " [GEN] $@") 216 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 217 $(qexec)$(CC) -S $(CFLAGS) -o $@ $< 218 219.PRECIOUS: %.asm.S 220$(BUILD_PFX)%.asm.S: %.asm 221 $(if $(quiet),@echo " [ASM CONVERSION] $@") 222 $(qexec)mkdir -p $(dir $@) 223 $(qexec)$(ASM_CONVERSION) <$< >$@ 224 225# If we're in debug mode, pretend we don't have GNU strip, to fall back to 226# the copy implementation 227HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP)) 228ifeq ($(HAVE_GNU_STRIP),yes) 229# Older binutils strip global symbols not needed for relocation processing 230# when given --strip-unneeded. Using nm and awk to identify globals and 231# keep them caused command line length issues under mingw and segfaults in 232# test_libvpx were observed under OS/2: simply use --strip-debug. 233%.a: %_g.a 234 $(if $(quiet),@echo " [STRIP] $@ < $<") 235 $(qexec)$(STRIP) --strip-debug \ 236 -o $@ $< 237else 238%.a: %_g.a 239 $(if $(quiet),@echo " [CP] $@ < $<") 240 $(qexec)cp $< $@ 241endif 242 243# 244# Utility functions 245# 246pairmap=$(if $(strip $(2)),\ 247 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\ 248 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\ 249) 250 251enabled=$(filter-out $($(1)-no),$($(1)-yes)) 252cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2))) 253 254find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2))))) 255find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) ) 256obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o 257objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) )) 258 259install_map_templates=$(eval $(call install_map_template,$(1),$(2))) 260 261not=$(subst yes,no,$(1)) 262 263ifeq ($(CONFIG_MSVS),yes) 264lib_file_name=$(1).lib 265else 266lib_file_name=lib$(1).a 267endif 268# 269# Rule Templates 270# 271define linker_template 272$(1): $(filter-out -%,$(2)) 273$(1): 274 $(if $(quiet),@echo " [LD] $$@") 275 $(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) 276endef 277define linkerxx_template 278$(1): $(filter-out -%,$(2)) 279$(1): 280 $(if $(quiet),@echo " [LD] $$@") 281 $(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) 282endef 283# make-3.80 has a bug with expanding large input strings to the eval function, 284# which was triggered in some cases by the following component of 285# linker_template: 286# $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\ 287# $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2)))) 288# This may be useful to revisit in the future (it tries to locate libraries 289# in a search path and add them as prerequisites 290 291define install_map_template 292$(DIST_DIR)/$(1): $(2) 293 $(if $(quiet),@echo " [INSTALL] $$@") 294 $(qexec)mkdir -p $$(dir $$@) 295 $(qexec)cp -p $$< $$@ 296endef 297 298define archive_template 299# Not using a pattern rule here because we don't want to generate empty 300# archives when they are listed as a dependency in files not responsible 301# for creating them. 302$(1): 303 $(if $(quiet),@echo " [AR] $$@") 304 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$^ 305endef 306 307define so_template 308# Not using a pattern rule here because we don't want to generate empty 309# archives when they are listed as a dependency in files not responsible 310# for creating them. 311# 312# This needs further abstraction for dealing with non-GNU linkers. 313$(1): 314 $(if $(quiet),@echo " [LD] $$@") 315 $(qexec)$$(LD) -shared $$(LDFLAGS) \ 316 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \ 317 -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \ 318 $$(filter %.o,$$^) $$(extralibs) 319endef 320 321define dl_template 322# Not using a pattern rule here because we don't want to generate empty 323# archives when they are listed as a dependency in files not responsible 324# for creating them. 325$(1): 326 $(if $(quiet),@echo " [LD] $$@") 327 $(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \ 328 -exported_symbols_list $$(EXPORTS_FILE) \ 329 -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \ 330 -o $$@ \ 331 $$(filter %.o,$$^) $$(extralibs) 332endef 333 334define dll_template 335# Not using a pattern rule here because we don't want to generate empty 336# archives when they are listed as a dependency in files not responsible 337# for creating them. 338$(1): 339 $(if $(quiet),@echo " [LD] $$@") 340 $(qexec)$$(LD) -Zdll $$(LDFLAGS) \ 341 -o $$@ \ 342 $$(filter %.o,$$^) $$(extralibs) $$(EXPORTS_FILE) 343endef 344 345 346# 347# Get current configuration 348# 349ifneq ($(target),) 350include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk 351endif 352 353skip_deps := $(filter %clean,$(MAKECMDGOALS)) 354skip_deps += $(findstring testdata,$(MAKECMDGOALS)) 355ifeq ($(strip $(skip_deps)),) 356 ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes) 357 # Older versions of make don't like -include directives with no arguments 358 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),) 359 -include $(filter %.d,$(OBJS-yes:.o=.d)) 360 endif 361 endif 362endif 363 364# 365# Configuration dependent rules 366# 367$(call pairmap,install_map_templates,$(INSTALL_MAPS)) 368 369DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS) 370.docs: $(DOCS) 371 @touch $@ 372 373INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS) 374ifeq ($(MAKECMDGOALS),dist) 375INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS) 376endif 377.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS)) 378 @touch $@ 379 380clean:: 381 rm -f .docs .install-docs $(DOCS) 382 383BINS=$(call enabled,BINS) 384.bins: $(BINS) 385 @touch $@ 386 387INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS) 388ifeq ($(MAKECMDGOALS),dist) 389INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS) 390endif 391.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS)) 392 @touch $@ 393 394clean:: 395 rm -f .bins .install-bins $(BINS) 396 397LIBS=$(call enabled,LIBS) 398.libs: $(LIBS) 399 @touch $@ 400$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib)))) 401$(foreach lib,$(filter %so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib)))) 402$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib)))) 403$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dll,$(LIBS)),$(eval $(call dll_template,$(lib)))) 404 405INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS) 406ifeq ($(MAKECMDGOALS),dist) 407INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS) 408endif 409.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS)) 410 @touch $@ 411 412clean:: 413 rm -f .libs .install-libs $(LIBS) 414 415ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 416PROJECTS=$(call enabled,PROJECTS) 417.projects: $(PROJECTS) 418 @touch $@ 419 420INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS) 421ifeq ($(MAKECMDGOALS),dist) 422INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS) 423endif 424.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS)) 425 @touch $@ 426 427clean:: 428 rm -f .projects .install-projects $(PROJECTS) 429endif 430 431# If there are any source files to be distributed, then include the build 432# system too. 433ifneq ($(call enabled,DIST-SRCS),) 434 DIST-SRCS-yes += configure 435 DIST-SRCS-yes += build/make/configure.sh 436 DIST-SRCS-yes += build/make/gen_asm_deps.sh 437 DIST-SRCS-yes += build/make/Makefile 438 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh 439 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh 440 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh 441 DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh 442 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh 443 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas.pl 444 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas_apple.pl 445 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2armasm_ms.pl 446 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/thumb.pm 447 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk 448endif 449INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS) 450ifeq ($(MAKECMDGOALS),dist) 451INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS) 452endif 453.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS)) 454 @touch $@ 455 456clean:: 457 rm -f .install-srcs 458 459ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 460 BUILD_TARGETS += .projects 461 INSTALL_TARGETS += .install-projects 462endif 463BUILD_TARGETS += .docs .libs .bins 464INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins 465all: $(BUILD_TARGETS) 466install:: $(INSTALL_TARGETS) 467dist: $(INSTALL_TARGETS) 468test: 469 470.SUFFIXES: # Delete default suffix rules 471