2 ## Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
15 # If a target wasn't specified, invoke for all enabled targets.
17 @for t in $(ALL_TARGETS); do \
18 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
25 test-no-data-check:: .DEFAULT
28 exampletest-no-data-check utiltest-no-data-check: .DEFAULT
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.
33 md5sum := $(firstword $(wildcard \
34 $(foreach e,md5sum openssl,\
35 $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\
37 md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum))
39 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
41 @for t in $(ALL_TARGETS); do \
42 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
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;) \
52 @if [ -d "$(DIST_DIR)" ]; then \
53 echo " [MD5SUM] $(DIST_DIR)"; \
55 $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \
56 | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2 \1/' \
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.
64 include $(target)-$(TOOLCHAIN).mk
67 VPATH=$(SRC_PATH_BARE)
68 CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
69 CXXFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
70 ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/
73 TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
74 TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN)))
75 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
76 quiet:=$(if $(or $(verbose), $(V)),, yes)
77 qexec=$(if $(quiet),@)
79 # Cancel built-in implicit rules
93 rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.S.o=.asm.S)
98 if [ -z "$(target)" ]; then \
100 rm -f config.log config.mk; \
101 rm -f vpx_config.[hc] vpx_config.asm; \
104 rm -f $(target)-$(TOOLCHAIN).mk; \
119 .PHONY: test-no-data-check exampletest-no-data-check utiltest-no-data-check
121 exampletest-no-data-check utiltest-no-data-check:
123 # Force to realign stack always on OS/2
124 ifeq ($(TOOLCHAIN), x86-os2-gcc)
125 CFLAGS += -mstackrealign
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
147 $(BUILD_PFX)%_vsx.c.d: CFLAGS += -maltivec -mvsx
148 $(BUILD_PFX)%_vsx.c.o: CFLAGS += -maltivec -mvsx
150 $(BUILD_PFX)%.c.d: %.c
151 $(if $(quiet),@echo " [DEP] $@")
152 $(qexec)mkdir -p $(dir $@)
153 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
155 $(BUILD_PFX)%.c.o: %.c
156 $(if $(quiet),@echo " [CC] $@")
157 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
158 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
160 $(BUILD_PFX)%.cc.d: %.cc
161 $(if $(quiet),@echo " [DEP] $@")
162 $(qexec)mkdir -p $(dir $@)
163 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
165 $(BUILD_PFX)%.cc.o: %.cc
166 $(if $(quiet),@echo " [CXX] $@")
167 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
168 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
170 $(BUILD_PFX)%.cpp.d: %.cpp
171 $(if $(quiet),@echo " [DEP] $@")
172 $(qexec)mkdir -p $(dir $@)
173 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
175 $(BUILD_PFX)%.cpp.o: %.cpp
176 $(if $(quiet),@echo " [CXX] $@")
177 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
178 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
180 $(BUILD_PFX)%.asm.d: %.asm
181 $(if $(quiet),@echo " [DEP] $@")
182 $(qexec)mkdir -p $(dir $@)
183 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
184 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
186 $(BUILD_PFX)%.asm.o: %.asm
187 $(if $(quiet),@echo " [AS] $@")
188 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
189 $(qexec)$(AS) $(ASFLAGS) -o $@ $<
191 $(BUILD_PFX)%.S.d: %.S
192 $(if $(quiet),@echo " [DEP] $@")
193 $(qexec)mkdir -p $(dir $@)
194 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
195 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
197 $(BUILD_PFX)%.S.o: %.S
198 $(if $(quiet),@echo " [AS] $@")
199 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
200 $(qexec)$(AS) $(ASFLAGS) -o $@ $<
203 %.c.S: CFLAGS += -DINLINE_ASM
204 $(BUILD_PFX)%.c.S: %.c
205 $(if $(quiet),@echo " [GEN] $@")
206 $(qexec)$(if $(CONFIG_DEPENDENCY_TRACKING),,mkdir -p $(dir $@))
207 $(qexec)$(CC) -S $(CFLAGS) -o $@ $<
210 $(BUILD_PFX)%.asm.S: %.asm
211 $(if $(quiet),@echo " [ASM CONVERSION] $@")
212 $(qexec)mkdir -p $(dir $@)
213 $(qexec)$(ASM_CONVERSION) <$< >$@
215 # If we're in debug mode, pretend we don't have GNU strip, to fall back to
216 # the copy implementation
217 HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
218 ifeq ($(HAVE_GNU_STRIP),yes)
219 # Older binutils strip global symbols not needed for relocation processing
220 # when given --strip-unneeded. Using nm and awk to identify globals and
221 # keep them caused command line length issues under mingw and segfaults in
222 # test_libvpx were observed under OS/2: simply use --strip-debug.
224 $(if $(quiet),@echo " [STRIP] $@ < $<")
225 $(qexec)$(STRIP) --strip-debug \
229 $(if $(quiet),@echo " [CP] $@ < $<")
236 pairmap=$(if $(strip $(2)),\
237 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
238 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
241 enabled=$(filter-out $($(1)-no),$($(1)-yes))
242 cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
244 find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
245 find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
246 obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o
247 objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
249 install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
251 not=$(subst yes,no,$(1))
253 ifeq ($(CONFIG_MSVS),yes)
254 lib_file_name=$(1).lib
256 lib_file_name=lib$(1).a
261 define linker_template
262 $(1): $(filter-out -%,$(2))
264 $(if $(quiet),@echo " [LD] $$@")
265 $(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
267 define linkerxx_template
268 $(1): $(filter-out -%,$(2))
270 $(if $(quiet),@echo " [LD] $$@")
271 $(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
273 # make-3.80 has a bug with expanding large input strings to the eval function,
274 # which was triggered in some cases by the following component of
276 # $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
277 # $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
278 # This may be useful to revisit in the future (it tries to locate libraries
279 # in a search path and add them as prerequisites
281 define install_map_template
282 $(DIST_DIR)/$(1): $(2)
283 $(if $(quiet),@echo " [INSTALL] $$@")
284 $(qexec)mkdir -p $$(dir $$@)
285 $(qexec)cp -p $$< $$@
288 define archive_template
289 # Not using a pattern rule here because we don't want to generate empty
290 # archives when they are listed as a dependency in files not responsible
293 $(if $(quiet),@echo " [AR] $$@")
294 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$^
298 # Not using a pattern rule here because we don't want to generate empty
299 # archives when they are listed as a dependency in files not responsible
302 # This needs further abstraction for dealing with non-GNU linkers.
304 $(if $(quiet),@echo " [LD] $$@")
305 $(qexec)$$(LD) -shared $$(LDFLAGS) \
306 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
307 -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \
308 $$(filter %.o,$$^) $$(extralibs)
312 # Not using a pattern rule here because we don't want to generate empty
313 # archives when they are listed as a dependency in files not responsible
316 $(if $(quiet),@echo " [LD] $$@")
317 $(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \
318 -exported_symbols_list $$(EXPORTS_FILE) \
319 -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \
321 $$(filter %.o,$$^) $$(extralibs)
325 # Not using a pattern rule here because we don't want to generate empty
326 # archives when they are listed as a dependency in files not responsible
329 $(if $(quiet),@echo " [LD] $$@")
330 $(qexec)$$(LD) -Zdll $$(LDFLAGS) \
332 $$(filter %.o,$$^) $$(extralibs) $$(EXPORTS_FILE)
337 # Get current configuration
340 include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
343 skip_deps := $(filter %clean,$(MAKECMDGOALS))
344 skip_deps += $(findstring testdata,$(MAKECMDGOALS))
345 ifeq ($(strip $(skip_deps)),)
346 ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
347 # Older versions of make don't like -include directives with no arguments
348 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
349 -include $(filter %.d,$(OBJS-yes:.o=.d))
355 # Configuration dependent rules
357 $(call pairmap,install_map_templates,$(INSTALL_MAPS))
359 DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
363 INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
364 ifeq ($(MAKECMDGOALS),dist)
365 INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
367 .install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
371 rm -f .docs .install-docs $(DOCS)
373 BINS=$(call enabled,BINS)
377 INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
378 ifeq ($(MAKECMDGOALS),dist)
379 INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
381 .install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
385 rm -f .bins .install-bins $(BINS)
387 LIBS=$(call enabled,LIBS)
390 $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
391 $(foreach lib,$(filter %so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
392 $(foreach lib,$(filter %$(SO_VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib))))
393 $(foreach lib,$(filter %$(SO_VERSION_MAJOR).dll,$(LIBS)),$(eval $(call dll_template,$(lib))))
395 INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
396 ifeq ($(MAKECMDGOALS),dist)
397 INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
399 .install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
403 rm -f .libs .install-libs $(LIBS)
405 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
406 PROJECTS=$(call enabled,PROJECTS)
407 .projects: $(PROJECTS)
410 INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
411 ifeq ($(MAKECMDGOALS),dist)
412 INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
414 .install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
418 rm -f .projects .install-projects $(PROJECTS)
421 # If there are any source files to be distributed, then include the build
423 ifneq ($(call enabled,DIST-SRCS),)
424 DIST-SRCS-yes += configure
425 DIST-SRCS-yes += build/make/configure.sh
426 DIST-SRCS-yes += build/make/gen_asm_deps.sh
427 DIST-SRCS-yes += build/make/Makefile
428 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh
429 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh
430 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh
431 DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh
432 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
433 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas.pl
434 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2gas_apple.pl
435 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/ads2armasm_ms.pl
436 DIST-SRCS-$(VPX_ARCH_ARM) += build/make/thumb.pm
437 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk
439 INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
440 ifeq ($(MAKECMDGOALS),dist)
441 INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
443 .install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
449 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
450 BUILD_TARGETS += .projects
451 INSTALL_TARGETS += .install-projects
453 BUILD_TARGETS += .docs .libs .bins
454 INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
455 all: $(BUILD_TARGETS)
456 install:: $(INSTALL_TARGETS)
457 dist: $(INSTALL_TARGETS)
460 .SUFFIXES: # Delete default suffix rules