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 else \ 103 rm -f $(target)-$(TOOLCHAIN).mk; \ 104 fi 105 106.PHONY: dist 107dist: 108.PHONY: exampletest 109exampletest: 110.PHONY: install 111install:: 112.PHONY: test 113test:: 114.PHONY: testdata 115testdata:: 116.PHONY: utiltest 117utiltest: 118.PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check 119test-no-data-check:: 120exampletest-no-data-check utiltest-no-data-check: 121 122# Force to realign stack always on OS/2 123ifeq ($(TOOLCHAIN), x86-os2-gcc) 124CFLAGS += -mstackrealign 125endif 126 127# x86[_64] 128$(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx 129$(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx 130$(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 131$(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2 132$(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3 133$(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3 134$(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3 135$(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3 136$(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1 137$(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1 138$(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx 139$(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx 140$(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2 141$(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2 142 143# POWER 144$(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx 145$(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx 146 147$(BUILD_PFX)%.c.d: %.c 148 $(if $(quiet),@echo " [DEP] $@") 149 $(qexec)mkdir -p $(dir $@) 150 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@ 151 152$(BUILD_PFX)%.c.o: %.c 153 $(if $(quiet),@echo " [CC] $@") 154 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 155 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $< 156 157$(BUILD_PFX)%.cc.d: %.cc 158 $(if $(quiet),@echo " [DEP] $@") 159 $(qexec)mkdir -p $(dir $@) 160 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@ 161 162$(BUILD_PFX)%.cc.o: %.cc 163 $(if $(quiet),@echo " [CXX] $@") 164 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 165 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< 166 167$(BUILD_PFX)%.cpp.d: %.cpp 168 $(if $(quiet),@echo " [DEP] $@") 169 $(qexec)mkdir -p $(dir $@) 170 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@ 171 172$(BUILD_PFX)%.cpp.o: %.cpp 173 $(if $(quiet),@echo " [CXX] $@") 174 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 175 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $< 176 177$(BUILD_PFX)%.asm.d: %.asm 178 $(if $(quiet),@echo " [DEP] $@") 179 $(qexec)mkdir -p $(dir $@) 180 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 181 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 182 183$(BUILD_PFX)%.asm.o: %.asm 184 $(if $(quiet),@echo " [AS] $@") 185 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 186 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 187 188$(BUILD_PFX)%.S.d: %.S 189 $(if $(quiet),@echo " [DEP] $@") 190 $(qexec)mkdir -p $(dir $@) 191 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \ 192 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@ 193 194$(BUILD_PFX)%.S.o: %.S 195 $(if $(quiet),@echo " [AS] $@") 196 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 197 $(qexec)$(AS) $(ASFLAGS) -o $@ $< 198 199.PRECIOUS: %.c.S 200%.c.S: CFLAGS += -DINLINE_ASM 201$(BUILD_PFX)%.c.S: %.c 202 $(if $(quiet),@echo " [GEN] $@") 203 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@)) 204 $(qexec)$(CC) -S $(CFLAGS) -o $@ $< 205 206.PRECIOUS: %.asm.S 207$(BUILD_PFX)%.asm.S: %.asm 208 $(if $(quiet),@echo " [ASM CONVERSION] $@") 209 $(qexec)mkdir -p $(dir $@) 210 $(qexec)$(ASM_CONVERSION) <$< >$@ 211 212# If we're in debug mode, pretend we don't have GNU strip, to fall back to 213# the copy implementation 214HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP)) 215ifeq ($(HAVE_GNU_STRIP),yes) 216# Older binutils strip global symbols not needed for relocation processing 217# when given --strip-unneeded. Using nm and awk to identify globals and 218# keep them caused command line length issues under mingw and segfaults in 219# test_libvpx were observed under OS/2: simply use --strip-debug. 220%.a: %_g.a 221 $(if $(quiet),@echo " [STRIP] $@ < $<") 222 $(qexec)$(STRIP) --strip-debug \ 223 -o $@ $< 224else 225%.a: %_g.a 226 $(if $(quiet),@echo " [CP] $@ < $<") 227 $(qexec)cp $< $@ 228endif 229 230# 231# Utility functions 232# 233pairmap=$(if $(strip $(2)),\ 234 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\ 235 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\ 236) 237 238enabled=$(filter-out $($(1)-no),$($(1)-yes)) 239cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2))) 240 241find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2))))) 242find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) ) 243obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o 244objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) )) 245 246install_map_templates=$(eval $(call install_map_template,$(1),$(2))) 247 248not=$(subst yes,no,$(1)) 249 250ifeq ($(CONFIG_MSVS),yes) 251lib_file_name=$(1).lib 252else 253lib_file_name=lib$(1).a 254endif 255# 256# Rule Templates 257# 258define linker_template 259$(1): $(filter-out -%,$(2)) 260$(1): 261 $(if $(quiet),@echo " [LD] $$@") 262 $(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) 263endef 264define linkerxx_template 265$(1): $(filter-out -%,$(2)) 266$(1): 267 $(if $(quiet),@echo " [LD] $$@") 268 $(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs)) 269endef 270# make-3.80 has a bug with expanding large input strings to the eval function, 271# which was triggered in some cases by the following component of 272# linker_template: 273# $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\ 274# $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2)))) 275# This may be useful to revisit in the future (it tries to locate libraries 276# in a search path and add them as prerequisites 277 278define install_map_template 279$(DIST_DIR)/$(1): $(2) 280 $(if $(quiet),@echo " [INSTALL] $$@") 281 $(qexec)mkdir -p $$(dir $$@) 282 $(qexec)cp -p $$< $$@ 283endef 284 285define archive_template 286# Not using a pattern rule here because we don't want to generate empty 287# archives when they are listed as a dependency in files not responsible 288# for creating them. 289$(1): 290 $(if $(quiet),@echo " [AR] $$@") 291 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$^ 292endef 293 294define so_template 295# Not using a pattern rule here because we don't want to generate empty 296# archives when they are listed as a dependency in files not responsible 297# for creating them. 298# 299# This needs further abstraction for dealing with non-GNU linkers. 300$(1): 301 $(if $(quiet),@echo " [LD] $$@") 302 $(qexec)$$(LD) -shared $$(LDFLAGS) \ 303 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \ 304 -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \ 305 $$(filter %.o,$$^) $$(extralibs) 306endef 307 308define dl_template 309# Not using a pattern rule here because we don't want to generate empty 310# archives when they are listed as a dependency in files not responsible 311# for creating them. 312$(1): 313 $(if $(quiet),@echo " [LD] $$@") 314 $(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \ 315 -exported_symbols_list $$(EXPORTS_FILE) \ 316 -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \ 317 -o $$@ \ 318 $$(filter %.o,$$^) $$(extralibs) 319endef 320 321define dll_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) -Zdll $$(LDFLAGS) \ 328 -o $$@ \ 329 $$(filter %.o,$$^) $$(extralibs) $$(EXPORTS_FILE) 330endef 331 332 333# 334# Get current configuration 335# 336ifneq ($(target),) 337include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk 338endif 339 340skip_deps := $(filter %clean,$(MAKECMDGOALS)) 341skip_deps += $(findstring testdata,$(MAKECMDGOALS)) 342ifeq ($(strip $(skip_deps)),) 343 ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes) 344 # Older versions of make don't like -include directives with no arguments 345 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),) 346 -include $(filter %.d,$(OBJS-yes:.o=.d)) 347 endif 348 endif 349endif 350 351# 352# Configuration dependent rules 353# 354$(call pairmap,install_map_templates,$(INSTALL_MAPS)) 355 356DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS) 357.docs: $(DOCS) 358 @touch $@ 359 360INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS) 361ifeq ($(MAKECMDGOALS),dist) 362INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS) 363endif 364.install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS)) 365 @touch $@ 366 367clean:: 368 rm -f .docs .install-docs $(DOCS) 369 370BINS=$(call enabled,BINS) 371.bins: $(BINS) 372 @touch $@ 373 374INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS) 375ifeq ($(MAKECMDGOALS),dist) 376INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS) 377endif 378.install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS)) 379 @touch $@ 380 381clean:: 382 rm -f .bins .install-bins $(BINS) 383 384LIBS=$(call enabled,LIBS) 385.libs: $(LIBS) 386 @touch $@ 387$(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib)))) 388$(foreach lib,$(filter %so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib)))) 389$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib)))) 390$(foreach lib,$(filter %$(SO_VERSION_MAJOR).dll,$(LIBS)),$(eval $(call dll_template,$(lib)))) 391 392INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS) 393ifeq ($(MAKECMDGOALS),dist) 394INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS) 395endif 396.install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS)) 397 @touch $@ 398 399clean:: 400 rm -f .libs .install-libs $(LIBS) 401 402ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 403PROJECTS=$(call enabled,PROJECTS) 404.projects: $(PROJECTS) 405 @touch $@ 406 407INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS) 408ifeq ($(MAKECMDGOALS),dist) 409INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS) 410endif 411.install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS)) 412 @touch $@ 413 414clean:: 415 rm -f .projects .install-projects $(PROJECTS) 416endif 417 418# If there are any source files to be distributed, then include the build 419# system too. 420ifneq ($(call enabled,DIST-SRCS),) 421 DIST-SRCS-yes += configure 422 DIST-SRCS-yes += build/make/configure.sh 423 DIST-SRCS-yes += build/make/gen_asm_deps.sh 424 DIST-SRCS-yes += build/make/Makefile 425 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh 426 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh 427 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh 428 DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh 429 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh 430 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl 431 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas_apple.pl 432 DIST-SRCS-$(ARCH_ARM) += build/make/ads2armasm_ms.pl 433 DIST-SRCS-$(ARCH_ARM) += build/make/thumb.pm 434 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk 435endif 436INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS) 437ifeq ($(MAKECMDGOALS),dist) 438INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS) 439endif 440.install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS)) 441 @touch $@ 442 443clean:: 444 rm -f .install-srcs 445 446ifeq ($(CONFIG_EXTERNAL_BUILD),yes) 447 BUILD_TARGETS += .projects 448 INSTALL_TARGETS += .install-projects 449endif 450BUILD_TARGETS += .docs .libs .bins 451INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins 452all: $(BUILD_TARGETS) 453install:: $(INSTALL_TARGETS) 454dist: $(INSTALL_TARGETS) 455test:: 456 457.SUFFIXES: # Delete default suffix rules 458