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 $$?;\
29 # Note: md5sum is not installed on OS X, but openssl is. Openssl may not be
30 # installed on cygwin, so we need to autodetect here.
31 md5sum := $(firstword $(wildcard \
32 $(foreach e,md5sum openssl,\
33 $(foreach p,$(subst :, ,$(PATH)),$(p)/$(e)*))\
35 md5sum := $(if $(filter %openssl,$(md5sum)),$(md5sum) dgst -md5,$(md5sum))
37 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
39 @for t in $(ALL_TARGETS); do \
40 $(MAKE) --no-print-directory target=$$t $(MAKECMDGOALS) || exit $$?;\
42 # Run configure for the user with the current toolchain.
43 @if [ -d "$(DIST_DIR)/src" ]; then \
44 mkdir -p "$(DIST_DIR)/build"; \
45 cd "$(DIST_DIR)/build"; \
46 echo "Rerunning configure $(CONFIGURE_ARGS)"; \
47 ../src/configure $(CONFIGURE_ARGS); \
48 $(if $(filter vs%,$(TGT_CC)),make NO_LAUNCH_DEVENV=1;) \
50 @if [ -d "$(DIST_DIR)" ]; then \
51 echo " [MD5SUM] $(DIST_DIR)"; \
53 $(md5sum) `find . -name md5sums.txt -prune -o -type f -print` \
54 | sed -e 's/MD5(\(.*\))= \([0-9a-f]\{32\}\)/\2 \1/' \
60 # Normally, we want to build the filename from the target and the toolchain.
61 # This disambiguates from the $(target).mk file that exists in the source tree.
62 # However, the toolchain is part of the target in universal builds, so we
63 # don't want to include TOOLCHAIN in that case. FAT_ARCHS is used to test
64 # if we're in the universal case.
65 include $(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk
68 VPATH=$(SRC_PATH_BARE)
69 CFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
70 CXXFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT) -I$(SRC_PATH)
71 ASFLAGS+=-I$(BUILD_PFX)$(BUILD_ROOT)/ -I$(SRC_PATH)/
74 TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
75 TGT_OS:=$(word 2, $(subst -, ,$(TOOLCHAIN)))
76 TGT_CC:=$(word 3, $(subst -, ,$(TOOLCHAIN)))
77 quiet:=$(if $(or $(verbose), $(V)),, yes)
78 qexec=$(if $(quiet),@)
80 # Cancel built-in implicit rules
94 rm -f $(OBJS-yes) $(OBJS-yes:.o=.d) $(OBJS-yes:.asm.s.o=.asm.s)
99 if [ -z "$(target)" ]; then \
101 rm -f config.log config.mk; \
102 rm -f vpx_config.[hc] vpx_config.asm; \
104 rm -f $(target)-$(TOOLCHAIN).mk; \
120 # Add compiler flags for intrinsic files
121 $(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx
122 $(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx
123 $(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2
124 $(BUILD_PFX)%_sse2.c.o: CFLAGS += -msse2
125 $(BUILD_PFX)%_sse3.c.d: CFLAGS += -msse3
126 $(BUILD_PFX)%_sse3.c.o: CFLAGS += -msse3
127 $(BUILD_PFX)%_ssse3.c.d: CFLAGS += -mssse3
128 $(BUILD_PFX)%_ssse3.c.o: CFLAGS += -mssse3
129 $(BUILD_PFX)%_sse4.c.d: CFLAGS += -msse4.1
130 $(BUILD_PFX)%_sse4.c.o: CFLAGS += -msse4.1
131 $(BUILD_PFX)%_avx.c.d: CFLAGS += -mavx
132 $(BUILD_PFX)%_avx.c.o: CFLAGS += -mavx
133 $(BUILD_PFX)%_avx2.c.d: CFLAGS += -mavx2
134 $(BUILD_PFX)%_avx2.c.o: CFLAGS += -mavx2
136 $(BUILD_PFX)%.c.d: %.c
137 $(if $(quiet),@echo " [DEP] $@")
138 $(qexec)mkdir -p $(dir $@)
139 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
141 $(BUILD_PFX)%.c.o: %.c
142 $(if $(quiet),@echo " [CC] $@")
143 $(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
145 $(BUILD_PFX)%.cc.d: %.cc
146 $(if $(quiet),@echo " [DEP] $@")
147 $(qexec)mkdir -p $(dir $@)
148 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
150 $(BUILD_PFX)%.cc.o: %.cc
151 $(if $(quiet),@echo " [CXX] $@")
152 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
154 $(BUILD_PFX)%.cpp.d: %.cpp
155 $(if $(quiet),@echo " [DEP] $@")
156 $(qexec)mkdir -p $(dir $@)
157 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
159 $(BUILD_PFX)%.cpp.o: %.cpp
160 $(if $(quiet),@echo " [CXX] $@")
161 $(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
163 $(BUILD_PFX)%.asm.d: %.asm
164 $(if $(quiet),@echo " [DEP] $@")
165 $(qexec)mkdir -p $(dir $@)
166 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
167 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
169 $(BUILD_PFX)%.asm.o: %.asm
170 $(if $(quiet),@echo " [AS] $@")
171 $(qexec)$(AS) $(ASFLAGS) -o $@ $<
173 $(BUILD_PFX)%.s.d: %.s
174 $(if $(quiet),@echo " [DEP] $@")
175 $(qexec)mkdir -p $(dir $@)
176 $(qexec)$(SRC_PATH_BARE)/build/make/gen_asm_deps.sh \
177 --build-pfx=$(BUILD_PFX) --depfile=$@ $(ASFLAGS) $< > $@
179 $(BUILD_PFX)%.s.o: %.s
180 $(if $(quiet),@echo " [AS] $@")
181 $(qexec)$(AS) $(ASFLAGS) -o $@ $<
184 %.c.S: CFLAGS += -DINLINE_ASM
185 $(BUILD_PFX)%.c.S: %.c
186 $(if $(quiet),@echo " [GEN] $@")
187 $(qexec)$(CC) -S $(CFLAGS) -o $@ $<
190 $(BUILD_PFX)%.asm.s: %.asm
191 $(if $(quiet),@echo " [ASM CONVERSION] $@")
192 $(qexec)mkdir -p $(dir $@)
193 $(qexec)$(ASM_CONVERSION) <$< >$@
195 # If we're in debug mode, pretend we don't have GNU strip, to fall back to
196 # the copy implementation
197 HAVE_GNU_STRIP := $(if $(CONFIG_DEBUG),,$(HAVE_GNU_STRIP))
198 ifeq ($(HAVE_GNU_STRIP),yes)
199 # Older binutils strip global sybols not needed for relocation processing
200 # when given --strip-unneeded. Use nm and awk to identify globals and
203 $(if $(quiet),@echo " [STRIP] $@ < $<")
204 $(qexec)$(STRIP) --strip-unneeded \
205 `$(NM) $< | grep ' [A-TV-Z] ' | awk '{print "-K"$$3'}`\
209 $(if $(quiet),@echo " [CP] $@ < $<")
214 # Rule to extract assembly constants from C sources
216 obj_int_extract: build/make/obj_int_extract.c
217 $(if $(quiet),@echo " [HOSTCC] $@")
218 $(qexec)$(HOSTCC) -I. -I$(SRC_PATH_BARE) -o $@ $<
219 CLEAN-OBJS += obj_int_extract
224 pairmap=$(if $(strip $(2)),\
225 $(call $(1),$(word 1,$(2)),$(word 2,$(2)))\
226 $(call pairmap,$(1),$(wordlist 3,$(words $(2)),$(2)))\
229 enabled=$(filter-out $($(1)-no),$($(1)-yes))
230 cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
232 find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
233 find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
234 obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o
235 objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
237 install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
239 not=$(subst yes,no,$(1))
241 ifeq ($(CONFIG_MSVS),yes)
242 lib_file_name=$(1).lib
244 lib_file_name=lib$(1).a
249 define linker_template
250 $(1): $(filter-out -%,$(2))
252 $(if $(quiet),@echo " [LD] $$@")
253 $(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
255 define linkerxx_template
256 $(1): $(filter-out -%,$(2))
258 $(if $(quiet),@echo " [LD] $$@")
259 $(qexec)$$(CXX) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
261 # make-3.80 has a bug with expanding large input strings to the eval function,
262 # which was triggered in some cases by the following component of
264 # $(1): $$(call find_file, $(patsubst -l%,lib%.a,$(filter -l%,$(2))),\
265 # $$(patsubst -L%,%,$$(filter -L%,$$(LDFLAGS) $(2))))
266 # This may be useful to revisit in the future (it tries to locate libraries
267 # in a search path and add them as prerequisites
269 define install_map_template
270 $(DIST_DIR)/$(1): $(2)
271 $(if $(quiet),@echo " [INSTALL] $$@")
272 $(qexec)mkdir -p $$(dir $$@)
273 $(qexec)cp -p $$< $$@
276 define archive_template
277 # Not using a pattern rule here because we don't want to generate empty
278 # archives when they are listed as a dependency in files not responsible
281 $(if $(quiet),@echo " [AR] $$@")
282 $(qexec)$$(AR) $$(ARFLAGS) $$@ $$?
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
290 # This needs further abstraction for dealing with non-GNU linkers.
292 $(if $(quiet),@echo " [LD] $$@")
293 $(qexec)$$(LD) -shared $$(LDFLAGS) \
294 -Wl,--no-undefined -Wl,-soname,$$(SONAME) \
295 -Wl,--version-script,$$(EXPORTS_FILE) -o $$@ \
296 $$(filter %.o,$$^) $$(extralibs)
300 # Not using a pattern rule here because we don't want to generate empty
301 # archives when they are listed as a dependency in files not responsible
304 $(if $(quiet),@echo " [LD] $$@")
305 $(qexec)$$(LD) -dynamiclib $$(LDFLAGS) \
306 -exported_symbols_list $$(EXPORTS_FILE) \
307 -Wl,-headerpad_max_install_names,-compatibility_version,1.0,-current_version,$$(VERSION_MAJOR) \
309 $$(filter %.o,$$^) $$(extralibs)
314 define lipo_lib_template
315 $(1): $(addsuffix /$(1),$(FAT_ARCHS))
316 $(if $(quiet),@echo " [LIPO] $$@")
317 $(qexec)libtool -static -o $$@ $$?
320 define lipo_bin_template
321 $(1): $(addsuffix /$(1),$(FAT_ARCHS))
322 $(if $(quiet),@echo " [LIPO] $$@")
323 $(qexec)lipo -output $$@ -create $$?
328 # Get current configuration
331 include $(SRC_PATH_BARE)/$(target:-$(TOOLCHAIN)=).mk
334 skip_deps := $(filter %clean,$(MAKECMDGOALS))
335 skip_deps += $(findstring testdata,$(MAKECMDGOALS))
336 ifeq ($(strip $(skip_deps)),)
337 # Older versions of make don't like -include directives with no arguments
338 ifneq ($(filter %.d,$(OBJS-yes:.o=.d)),)
339 -include $(filter %.d,$(OBJS-yes:.o=.d))
344 # Configuration dependent rules
346 $(call pairmap,install_map_templates,$(INSTALL_MAPS))
348 DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,DOCS)
352 INSTALL-DOCS=$(call cond_enabled,CONFIG_INSTALL_DOCS,INSTALL-DOCS)
353 ifeq ($(MAKECMDGOALS),dist)
354 INSTALL-DOCS+=$(call cond_enabled,CONFIG_INSTALL_DOCS,DIST-DOCS)
356 .install-docs: .docs $(addprefix $(DIST_DIR)/,$(INSTALL-DOCS))
360 rm -f .docs .install-docs $(DOCS)
362 BINS=$(call enabled,BINS)
366 INSTALL-BINS=$(call cond_enabled,CONFIG_INSTALL_BINS,INSTALL-BINS)
367 ifeq ($(MAKECMDGOALS),dist)
368 INSTALL-BINS+=$(call cond_enabled,CONFIG_INSTALL_BINS,DIST-BINS)
370 .install-bins: .bins $(addprefix $(DIST_DIR)/,$(INSTALL-BINS))
374 rm -f .bins .install-bins $(BINS)
376 LIBS=$(call enabled,LIBS)
379 $(foreach lib,$(filter %_g.a,$(LIBS)),$(eval $(call archive_template,$(lib))))
380 $(foreach lib,$(filter %so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH),$(LIBS)),$(eval $(call so_template,$(lib))))
381 $(foreach lib,$(filter %$(VERSION_MAJOR).dylib,$(LIBS)),$(eval $(call dl_template,$(lib))))
383 INSTALL-LIBS=$(call cond_enabled,CONFIG_INSTALL_LIBS,INSTALL-LIBS)
384 ifeq ($(MAKECMDGOALS),dist)
385 INSTALL-LIBS+=$(call cond_enabled,CONFIG_INSTALL_LIBS,DIST-LIBS)
387 .install-libs: .libs $(addprefix $(DIST_DIR)/,$(INSTALL-LIBS))
391 rm -f .libs .install-libs $(LIBS)
393 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
394 PROJECTS=$(call enabled,PROJECTS)
395 .projects: $(PROJECTS)
398 INSTALL-PROJECTS=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,INSTALL-PROJECTS)
399 ifeq ($(MAKECMDGOALS),dist)
400 INSTALL-PROJECTS+=$(call cond_enabled,CONFIG_INSTALL_PROJECTS,DIST-PROJECTS)
402 .install-projects: .projects $(addprefix $(DIST_DIR)/,$(INSTALL-PROJECTS))
406 rm -f .projects .install-projects $(PROJECTS)
409 # If there are any source files to be distributed, then include the build
411 ifneq ($(call enabled,DIST-SRCS),)
412 DIST-SRCS-yes += configure
413 DIST-SRCS-yes += build/make/configure.sh
414 DIST-SRCS-yes += build/make/gen_asm_deps.sh
415 DIST-SRCS-yes += build/make/Makefile
416 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_def.sh
417 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_proj.sh
418 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_sln.sh
419 DIST-SRCS-$(CONFIG_MSVS) += build/make/gen_msvs_vcxproj.sh
420 DIST-SRCS-$(CONFIG_MSVS) += build/make/msvs_common.sh
421 DIST-SRCS-$(CONFIG_MSVS) += build/x86-msvs/obj_int_extract.bat
422 DIST-SRCS-$(CONFIG_MSVS) += build/arm-msvs/obj_int_extract.bat
423 DIST-SRCS-$(CONFIG_RVCT) += build/make/armlink_adapter.sh
424 # Include obj_int_extract if we use offsets from *_asm_*_offsets
425 DIST-SRCS-$(ARCH_ARM)$(ARCH_X86)$(ARCH_X86_64) += build/make/obj_int_extract.c
426 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas.pl
427 DIST-SRCS-$(ARCH_ARM) += build/make/ads2gas_apple.pl
428 DIST-SRCS-$(ARCH_ARM) += build/make/ads2armasm_ms.pl
429 DIST-SRCS-$(ARCH_ARM) += build/make/thumb.pm
430 DIST-SRCS-yes += $(target:-$(TOOLCHAIN)=).mk
432 INSTALL-SRCS := $(call cond_enabled,CONFIG_INSTALL_SRCS,INSTALL-SRCS)
433 ifeq ($(MAKECMDGOALS),dist)
434 INSTALL-SRCS += $(call cond_enabled,CONFIG_INSTALL_SRCS,DIST-SRCS)
436 .install-srcs: $(addprefix $(DIST_DIR)/src/,$(INSTALL-SRCS))
442 ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
443 BUILD_TARGETS += .projects
444 INSTALL_TARGETS += .install-projects
446 BUILD_TARGETS += .docs .libs .bins
447 INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
448 all: $(BUILD_TARGETS)
449 install:: $(INSTALL_TARGETS)
450 dist: $(INSTALL_TARGETS)