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
12# ARM assembly files are written in RVCT-style. We use some make magic to
13# filter those files to allow GCC compilation
14ifeq ($(VPX_ARCH_ARM),yes)
15  ASM:=$(if $(filter yes,$(CONFIG_GCC)$(CONFIG_MSVS)),.asm.S,.asm)
16else
17  ASM:=.asm
18endif
19
20#
21# Rule to generate runtime cpu detection files
22#
23define rtcd_h_template
24$$(BUILD_PFX)$(1).h: $$(SRC_PATH_BARE)/$(2)
25	@echo "    [CREATE] $$@"
26	$$(qexec)$$(SRC_PATH_BARE)/build/make/rtcd.pl --arch=$$(TGT_ISA) \
27          --sym=$(1) \
28          --config=$$(CONFIG_DIR)$$(target)-$$(TOOLCHAIN).mk \
29          $$(RTCD_OPTIONS) $$^ > $$@
30CLEAN-OBJS += $$(BUILD_PFX)$(1).h
31RTCD += $$(BUILD_PFX)$(1).h
32endef
33
34CODEC_SRCS-yes += CHANGELOG
35CODEC_SRCS-yes += libs.mk
36
37include $(SRC_PATH_BARE)/vpx/vpx_codec.mk
38CODEC_SRCS-yes += $(addprefix vpx/,$(call enabled,API_SRCS))
39CODEC_DOC_SRCS += $(addprefix vpx/,$(call enabled,API_DOC_SRCS))
40
41include $(SRC_PATH_BARE)/vpx_mem/vpx_mem.mk
42CODEC_SRCS-yes += $(addprefix vpx_mem/,$(call enabled,MEM_SRCS))
43
44include $(SRC_PATH_BARE)/vpx_scale/vpx_scale.mk
45CODEC_SRCS-yes += $(addprefix vpx_scale/,$(call enabled,SCALE_SRCS))
46
47include $(SRC_PATH_BARE)/vpx_ports/vpx_ports.mk
48CODEC_SRCS-yes += $(addprefix vpx_ports/,$(call enabled,PORTS_SRCS))
49
50include $(SRC_PATH_BARE)/vpx_dsp/vpx_dsp.mk
51CODEC_SRCS-yes += $(addprefix vpx_dsp/,$(call enabled,DSP_SRCS))
52
53include $(SRC_PATH_BARE)/vpx_util/vpx_util.mk
54CODEC_SRCS-yes += $(addprefix vpx_util/,$(call enabled,UTIL_SRCS))
55
56ifeq ($(CONFIG_VP8),yes)
57  VP8_PREFIX=vp8/
58  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8_common.mk
59endif
60
61ifeq ($(CONFIG_VP8_ENCODER),yes)
62  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8cx.mk
63  CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_CX_SRCS))
64  CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_CX_EXPORTS))
65  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
66  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
67  CODEC_DOC_SECTIONS += vp8 vp8_encoder
68endif
69
70ifeq ($(CONFIG_VP8_DECODER),yes)
71  include $(SRC_PATH_BARE)/$(VP8_PREFIX)vp8dx.mk
72  CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_DX_SRCS))
73  CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_DX_EXPORTS))
74  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
75  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
76  CODEC_DOC_SECTIONS += vp8 vp8_decoder
77endif
78
79ifeq ($(CONFIG_VP9),yes)
80  VP9_PREFIX=vp9/
81  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9_common.mk
82endif
83
84ifeq ($(CONFIG_VP9_ENCODER),yes)
85  VP9_PREFIX=vp9/
86  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9cx.mk
87  CODEC_SRCS-yes += $(addprefix $(VP9_PREFIX),$(call enabled,VP9_CX_SRCS))
88  CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_CX_EXPORTS))
89  CODEC_SRCS-yes += $(VP9_PREFIX)vp9cx.mk vpx/vp8.h vpx/vp8cx.h
90  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8cx.h
91  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/%
92  CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8cx.h
93  CODEC_DOC_SECTIONS += vp9 vp9_encoder
94endif
95
96ifeq ($(CONFIG_VP9_DECODER),yes)
97  VP9_PREFIX=vp9/
98  include $(SRC_PATH_BARE)/$(VP9_PREFIX)vp9dx.mk
99  CODEC_SRCS-yes += $(addprefix $(VP9_PREFIX),$(call enabled,VP9_DX_SRCS))
100  CODEC_EXPORTS-yes += $(addprefix $(VP9_PREFIX),$(VP9_DX_EXPORTS))
101  CODEC_SRCS-yes += $(VP9_PREFIX)vp9dx.mk vpx/vp8.h vpx/vp8dx.h
102  INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
103  INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP9_PREFIX)/%
104  CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8dx.h
105  CODEC_DOC_SECTIONS += vp9 vp9_decoder
106endif
107
108ifeq ($(CONFIG_ENCODERS),yes)
109  CODEC_DOC_SECTIONS += encoder
110endif
111ifeq ($(CONFIG_DECODERS),yes)
112  CODEC_DOC_SECTIONS += decoder
113endif
114
115ifeq ($(CONFIG_MSVS),yes)
116CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),vpxmt,vpxmd)
117GTEST_LIB=$(if $(CONFIG_STATIC_MSVCRT),gtestmt,gtestmd)
118# This variable uses deferred expansion intentionally, since the results of
119# $(wildcard) may change during the course of the Make.
120VS_PLATFORMS = $(foreach d,$(wildcard */Release/$(CODEC_LIB).lib),$(word 1,$(subst /, ,$(d))))
121endif
122
123# The following pairs define a mapping of locations in the distribution
124# tree to locations in the source/build trees.
125INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/vpx/%
126INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/vpx_ports/%
127INSTALL_MAPS += $(LIBSUBDIR)/%     %
128INSTALL_MAPS += src/%     $(SRC_PATH_BARE)/%
129ifeq ($(CONFIG_MSVS),yes)
130INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/%  $(p)/Release/%)
131INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/%  $(p)/Debug/%)
132endif
133
134CODEC_SRCS-yes += build/make/version.sh
135CODEC_SRCS-yes += build/make/rtcd.pl
136CODEC_SRCS-yes += vpx_ports/emmintrin_compat.h
137CODEC_SRCS-yes += vpx_ports/mem_ops.h
138CODEC_SRCS-yes += vpx_ports/mem_ops_aligned.h
139CODEC_SRCS-yes += vpx_ports/vpx_once.h
140CODEC_SRCS-yes += $(BUILD_PFX)vpx_config.c
141INSTALL-SRCS-no += $(BUILD_PFX)vpx_config.c
142ifeq ($(VPX_ARCH_X86)$(VPX_ARCH_X86_64),yes)
143INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += third_party/x86inc/x86inc.asm
144INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += vpx_dsp/x86/bitdepth_conversion_sse2.asm
145endif
146CODEC_EXPORTS-yes += vpx/exports_com
147CODEC_EXPORTS-$(CONFIG_ENCODERS) += vpx/exports_enc
148CODEC_EXPORTS-$(CONFIG_DECODERS) += vpx/exports_dec
149
150INSTALL-LIBS-yes += include/vpx/vpx_codec.h
151INSTALL-LIBS-yes += include/vpx/vpx_frame_buffer.h
152INSTALL-LIBS-yes += include/vpx/vpx_image.h
153INSTALL-LIBS-yes += include/vpx/vpx_integer.h
154INSTALL-LIBS-$(CONFIG_DECODERS) += include/vpx/vpx_decoder.h
155INSTALL-LIBS-$(CONFIG_ENCODERS) += include/vpx/vpx_encoder.h
156ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
157ifeq ($(CONFIG_MSVS),yes)
158INSTALL-LIBS-yes                  += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB).lib)
159INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB)d.lib)
160INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/vpx.dll)
161INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/vpx.exp)
162endif
163else
164INSTALL-LIBS-$(CONFIG_STATIC) += $(LIBSUBDIR)/libvpx.a
165INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(LIBSUBDIR)/libvpx_g.a
166endif
167
168CODEC_SRCS=$(call enabled,CODEC_SRCS)
169INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(CODEC_SRCS)
170INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(call enabled,CODEC_EXPORTS)
171
172
173# Generate a list of all enabled sources, in particular for exporting to gyp
174# based build systems.
175libvpx_srcs.txt:
176	@echo "    [CREATE] $@"
177	@echo $(CODEC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
178CLEAN-OBJS += libvpx_srcs.txt
179
180# Assembly files that are included, but don't define symbols themselves.
181# Filtered out to avoid Windows build warnings.
182ASM_INCLUDES := \
183    third_party/x86inc/x86inc.asm \
184    vpx_config.asm \
185    vpx_ports/x86_abi_support.asm \
186    vpx_dsp/x86/bitdepth_conversion_sse2.asm \
187
188ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
189ifeq ($(CONFIG_MSVS),yes)
190
191vpx.def: $(call enabled,CODEC_EXPORTS)
192	@echo "    [CREATE] $@"
193	$(qexec)$(SRC_PATH_BARE)/build/make/gen_msvs_def.sh\
194            --name=vpx\
195            --out=$@ $^
196CLEAN-OBJS += vpx.def
197
198vpx.$(VCPROJ_SFX): VCPROJ_SRCS=$(filter-out $(addprefix %, $(ASM_INCLUDES)), $^)
199
200vpx.$(VCPROJ_SFX): $(CODEC_SRCS) vpx.def
201	@echo "    [CREATE] $@"
202	$(qexec)$(GEN_VCPROJ) \
203            $(if $(CONFIG_SHARED),--dll,--lib) \
204            --target=$(TOOLCHAIN) \
205            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
206            --name=vpx \
207            --proj-guid=DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74 \
208            --module-def=vpx.def \
209            --ver=$(CONFIG_VS_VERSION) \
210            --src-path-bare="$(SRC_PATH_BARE)" \
211            --out=$@ $(CFLAGS) \
212            $(filter $(SRC_PATH_BARE)/vp8/%.c, $(VCPROJ_SRCS)) \
213            $(filter $(SRC_PATH_BARE)/vp8/%.h, $(VCPROJ_SRCS)) \
214            $(filter $(SRC_PATH_BARE)/vp9/%.c, $(VCPROJ_SRCS)) \
215            $(filter $(SRC_PATH_BARE)/vp9/%.h, $(VCPROJ_SRCS)) \
216            $(filter $(SRC_PATH_BARE)/vpx/%, $(VCPROJ_SRCS)) \
217            $(filter $(SRC_PATH_BARE)/vpx_dsp/%, $(VCPROJ_SRCS)) \
218            $(filter-out $(addprefix $(SRC_PATH_BARE)/, \
219                           vp8/%.c vp8/%.h vp9/%.c vp9/%.h vpx/% vpx_dsp/%), \
220              $(VCPROJ_SRCS)) \
221            --src-path-bare="$(SRC_PATH_BARE)" \
222
223PROJECTS-yes += vpx.$(VCPROJ_SFX)
224
225vpx.$(VCPROJ_SFX): vpx_config.asm
226vpx.$(VCPROJ_SFX): $(RTCD)
227
228endif
229else
230LIBVPX_OBJS=$(call objs, $(filter-out $(ASM_INCLUDES), $(CODEC_SRCS)))
231OBJS-yes += $(LIBVPX_OBJS)
232LIBS-$(if yes,$(CONFIG_STATIC)) += $(BUILD_PFX)libvpx.a $(BUILD_PFX)libvpx_g.a
233$(BUILD_PFX)libvpx_g.a: $(LIBVPX_OBJS)
234
235SO_VERSION_MAJOR := 6
236SO_VERSION_MINOR := 2
237SO_VERSION_PATCH := 0
238ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS))
239LIBVPX_SO               := libvpx.$(SO_VERSION_MAJOR).dylib
240SHARED_LIB_SUF          := .dylib
241EXPORT_FILE             := libvpx.syms
242LIBVPX_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
243                             libvpx.dylib  )
244else
245ifeq ($(filter iphonesimulator%,$(TGT_OS)),$(TGT_OS))
246LIBVPX_SO               := libvpx.$(SO_VERSION_MAJOR).dylib
247SHARED_LIB_SUF          := .dylib
248EXPORT_FILE             := libvpx.syms
249LIBVPX_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, libvpx.dylib)
250else
251ifeq ($(filter os2%,$(TGT_OS)),$(TGT_OS))
252LIBVPX_SO               := libvpx$(SO_VERSION_MAJOR).dll
253SHARED_LIB_SUF          := _dll.a
254EXPORT_FILE             := libvpx.def
255LIBVPX_SO_SYMLINKS      :=
256LIBVPX_SO_IMPLIB        := libvpx_dll.a
257else
258LIBVPX_SO               := libvpx.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH)
259SHARED_LIB_SUF          := .so
260EXPORT_FILE             := libvpx.ver
261LIBVPX_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
262                             libvpx.so libvpx.so.$(SO_VERSION_MAJOR) \
263                             libvpx.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR))
264endif
265endif
266endif
267
268LIBS-$(CONFIG_SHARED) += $(BUILD_PFX)$(LIBVPX_SO)\
269                           $(notdir $(LIBVPX_SO_SYMLINKS)) \
270                           $(if $(LIBVPX_SO_IMPLIB), $(BUILD_PFX)$(LIBVPX_SO_IMPLIB))
271$(BUILD_PFX)$(LIBVPX_SO): $(LIBVPX_OBJS) $(EXPORT_FILE)
272$(BUILD_PFX)$(LIBVPX_SO): extralibs += -lm
273$(BUILD_PFX)$(LIBVPX_SO): SONAME = libvpx.so.$(SO_VERSION_MAJOR)
274$(BUILD_PFX)$(LIBVPX_SO): EXPORTS_FILE = $(EXPORT_FILE)
275
276libvpx.def: $(call enabled,CODEC_EXPORTS)
277	@echo "    [CREATE] $@"
278	$(qexec)echo LIBRARY $(LIBVPX_SO:.dll=) INITINSTANCE TERMINSTANCE > $@
279	$(qexec)echo "DATA MULTIPLE NONSHARED" >> $@
280	$(qexec)echo "EXPORTS" >> $@
281	$(qexec)awk '!/vpx_svc_*/ {print "_"$$2}' $^ >>$@
282CLEAN-OBJS += libvpx.def
283
284libvpx_dll.a: $(LIBVPX_SO)
285	@echo "    [IMPLIB] $@"
286	$(qexec)emximp -o $@ $<
287CLEAN-OBJS += libvpx_dll.a
288
289define libvpx_symlink_template
290$(1): $(2)
291	@echo "    [LN]     $(2) $$@"
292	$(qexec)mkdir -p $$(dir $$@)
293	$(qexec)ln -sf $(2) $$@
294endef
295
296$(eval $(call libvpx_symlink_template,\
297    $(addprefix $(BUILD_PFX),$(notdir $(LIBVPX_SO_SYMLINKS))),\
298    $(BUILD_PFX)$(LIBVPX_SO)))
299$(eval $(call libvpx_symlink_template,\
300    $(addprefix $(DIST_DIR)/,$(LIBVPX_SO_SYMLINKS)),\
301    $(LIBVPX_SO)))
302
303
304INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBVPX_SO_SYMLINKS)
305INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBSUBDIR)/$(LIBVPX_SO)
306INSTALL-LIBS-$(CONFIG_SHARED) += $(if $(LIBVPX_SO_IMPLIB),$(LIBSUBDIR)/$(LIBVPX_SO_IMPLIB))
307
308
309LIBS-yes += vpx.pc
310vpx.pc: config.mk libs.mk
311	@echo "    [CREATE] $@"
312	$(qexec)echo '# pkg-config file from libvpx $(VERSION_STRING)' > $@
313	$(qexec)echo 'prefix=$(PREFIX)' >> $@
314	$(qexec)echo 'exec_prefix=$${prefix}' >> $@
315	$(qexec)echo 'libdir=$${prefix}/$(LIBSUBDIR)' >> $@
316	$(qexec)echo 'includedir=$${prefix}/include' >> $@
317	$(qexec)echo '' >> $@
318	$(qexec)echo 'Name: vpx' >> $@
319	$(qexec)echo 'Description: WebM Project VPx codec implementation' >> $@
320	$(qexec)echo 'Version: $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)' >> $@
321	$(qexec)echo 'Requires:' >> $@
322	$(qexec)echo 'Conflicts:' >> $@
323	$(qexec)echo 'Libs: -L$${libdir} -lvpx -lm' >> $@
324ifeq ($(HAVE_PTHREAD_H),yes)
325	$(qexec)echo 'Libs.private: -lm -lpthread' >> $@
326else
327	$(qexec)echo 'Libs.private: -lm' >> $@
328endif
329	$(qexec)echo 'Cflags: -I$${includedir}' >> $@
330INSTALL-LIBS-yes += $(LIBSUBDIR)/pkgconfig/vpx.pc
331INSTALL_MAPS += $(LIBSUBDIR)/pkgconfig/%.pc %.pc
332CLEAN-OBJS += vpx.pc
333endif
334
335libvpx.ver: $(call enabled,CODEC_EXPORTS)
336	@echo "    [CREATE] $@"
337	$(qexec)echo "{ global:" > $@
338	$(qexec)for f in $?; do awk '{print $$2";"}' < $$f >>$@; done
339	$(qexec)echo "local: *; };" >> $@
340CLEAN-OBJS += libvpx.ver
341
342libvpx.syms: $(call enabled,CODEC_EXPORTS)
343	@echo "    [CREATE] $@"
344	$(qexec)awk '{print "_"$$2}' $^ >$@
345CLEAN-OBJS += libvpx.syms
346
347#
348# Rule to make assembler configuration file from C configuration file
349#
350ifeq ($(VPX_ARCH_X86)$(VPX_ARCH_X86_64),yes)
351# YASM
352$(BUILD_PFX)vpx_config.asm: $(BUILD_PFX)vpx_config.h
353	@echo "    [CREATE] $@"
354	@egrep "#define [A-Z0-9_]+ [01]" $< \
355	    | awk '{print $$2 " equ " $$3}' > $@
356else
357ADS2GAS=$(if $(filter yes,$(CONFIG_GCC)),| $(ASM_CONVERSION))
358$(BUILD_PFX)vpx_config.asm: $(BUILD_PFX)vpx_config.h
359	@echo "    [CREATE] $@"
360	@egrep "#define [A-Z0-9_]+ [01]" $< \
361	    | awk '{print $$2 " EQU " $$3}' $(ADS2GAS) > $@
362	@echo "        END" $(ADS2GAS) >> $@
363CLEAN-OBJS += $(BUILD_PFX)vpx_config.asm
364endif
365
366#
367# Add assembler dependencies for configuration.
368#
369$(filter %.S.o,$(OBJS-yes)):     $(BUILD_PFX)vpx_config.asm
370$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm
371
372
373$(shell $(SRC_PATH_BARE)/build/make/version.sh "$(SRC_PATH_BARE)" $(BUILD_PFX)vpx_version.h)
374CLEAN-OBJS += $(BUILD_PFX)vpx_version.h
375
376#
377# Add include path for libwebm sources.
378#
379ifeq ($(CONFIG_WEBM_IO),yes)
380  CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/libwebm
381endif
382
383##
384## libvpx test directives
385##
386ifeq ($(CONFIG_UNIT_TESTS),yes)
387LIBVPX_TEST_DATA_PATH ?= .
388
389include $(SRC_PATH_BARE)/test/test.mk
390LIBVPX_TEST_SRCS=$(addprefix test/,$(call enabled,LIBVPX_TEST_SRCS))
391LIBVPX_TEST_BIN=./test_libvpx$(EXE_SFX)
392LIBVPX_TEST_DATA=$(addprefix $(LIBVPX_TEST_DATA_PATH)/,\
393                     $(call enabled,LIBVPX_TEST_DATA))
394libvpx_test_data_url=https://storage.googleapis.com/downloads.webmproject.org/test_data/libvpx/$(1)
395
396TEST_INTRA_PRED_SPEED_BIN=./test_intra_pred_speed$(EXE_SFX)
397TEST_INTRA_PRED_SPEED_SRCS=$(addprefix test/,$(call enabled,TEST_INTRA_PRED_SPEED_SRCS))
398TEST_INTRA_PRED_SPEED_OBJS := $(sort $(call objs,$(TEST_INTRA_PRED_SPEED_SRCS)))
399
400libvpx_test_srcs.txt:
401	@echo "    [CREATE] $@"
402	@echo $(LIBVPX_TEST_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
403CLEAN-OBJS += libvpx_test_srcs.txt
404
405$(LIBVPX_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1
406	@echo "    [DOWNLOAD] $@"
407	# Attempt to download the file using curl, retrying once if it fails for a
408	# partial file (18).
409	$(qexec)( \
410	  trap 'rm -f $@' INT TERM; \
411	  curl="curl --retry 1 -L -o $@ $(call libvpx_test_data_url,$(@F))"; \
412	  $$curl; \
413	  case "$$?" in \
414	    18) $$curl -C -;; \
415	  esac \
416	)
417
418testdata:: $(LIBVPX_TEST_DATA)
419	$(qexec)[ -x "$$(which sha1sum)" ] && sha1sum=sha1sum;\
420          [ -x "$$(which shasum)" ] && sha1sum=shasum;\
421          [ -x "$$(which sha1)" ] && sha1sum=sha1;\
422          if [ -n "$${sha1sum}" ]; then\
423            set -e;\
424            echo "Checking test data:";\
425            for f in $(call enabled,LIBVPX_TEST_DATA); do\
426                grep $$f $(SRC_PATH_BARE)/test/test-data.sha1 |\
427                    (cd $(LIBVPX_TEST_DATA_PATH); $${sha1sum} -c);\
428            done; \
429        else\
430            echo "Skipping test data integrity check, sha1sum not found.";\
431        fi
432
433ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
434ifeq ($(CONFIG_MSVS),yes)
435
436gtest.$(VCPROJ_SFX): $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc
437	@echo "    [CREATE] $@"
438	$(qexec)$(GEN_VCPROJ) \
439            --lib \
440            --target=$(TOOLCHAIN) \
441            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
442            --name=gtest \
443            --proj-guid=EC00E1EC-AF68-4D92-A255-181690D1C9B1 \
444            --ver=$(CONFIG_VS_VERSION) \
445            --src-path-bare="$(SRC_PATH_BARE)" \
446            -D_VARIADIC_MAX=10 \
447            --out=gtest.$(VCPROJ_SFX) $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc \
448            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" -I"$(SRC_PATH_BARE)/third_party/googletest/src"
449
450PROJECTS-$(CONFIG_MSVS) += gtest.$(VCPROJ_SFX)
451
452test_libvpx.$(VCPROJ_SFX): $(LIBVPX_TEST_SRCS) vpx.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
453	@echo "    [CREATE] $@"
454	$(qexec)$(GEN_VCPROJ) \
455            --exe \
456            --target=$(TOOLCHAIN) \
457            --name=test_libvpx \
458            -D_VARIADIC_MAX=10 \
459            --proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
460            --ver=$(CONFIG_VS_VERSION) \
461            --src-path-bare="$(SRC_PATH_BARE)" \
462            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
463            --out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
464            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
465            $(if $(CONFIG_WEBM_IO),-I"$(SRC_PATH_BARE)/third_party/libwebm") \
466            -L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
467
468PROJECTS-$(CONFIG_MSVS) += test_libvpx.$(VCPROJ_SFX)
469
470LIBVPX_TEST_BIN := $(addprefix $(TGT_OS:win64=x64)/Release/,$(notdir $(LIBVPX_TEST_BIN)))
471
472ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
473PROJECTS-$(CONFIG_MSVS) += test_intra_pred_speed.$(VCPROJ_SFX)
474test_intra_pred_speed.$(VCPROJ_SFX): $(TEST_INTRA_PRED_SPEED_SRCS) vpx.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
475	@echo "    [CREATE] $@"
476	$(qexec)$(GEN_VCPROJ) \
477            --exe \
478            --target=$(TOOLCHAIN) \
479            --name=test_intra_pred_speed \
480            -D_VARIADIC_MAX=10 \
481            --proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
482            --ver=$(CONFIG_VS_VERSION) \
483            --src-path-bare="$(SRC_PATH_BARE)" \
484            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
485            --out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
486            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
487            -L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
488endif  # TEST_INTRA_PRED_SPEED
489endif
490else
491
492include $(SRC_PATH_BARE)/third_party/googletest/gtest.mk
493GTEST_SRCS := $(addprefix third_party/googletest/src/,$(call enabled,GTEST_SRCS))
494GTEST_OBJS=$(call objs,$(GTEST_SRCS))
495ifeq ($(filter win%,$(TGT_OS)),$(TGT_OS))
496# Disabling pthreads globally will cause issues on darwin and possibly elsewhere
497$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -DGTEST_HAS_PTHREAD=0
498endif
499GTEST_INCLUDES := -I$(SRC_PATH_BARE)/third_party/googletest/src
500GTEST_INCLUDES += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
501$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
502OBJS-yes += $(GTEST_OBJS)
503LIBS-yes += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
504$(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS)
505
506LIBVPX_TEST_OBJS=$(sort $(call objs,$(LIBVPX_TEST_SRCS)))
507$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
508OBJS-yes += $(LIBVPX_TEST_OBJS)
509BINS-yes += $(LIBVPX_TEST_BIN)
510
511CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),vpx_g,vpx)
512CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a)
513TEST_LIBS := lib$(CODEC_LIB)$(CODEC_LIB_SUF) libgtest.a
514$(LIBVPX_TEST_BIN): $(TEST_LIBS)
515$(eval $(call linkerxx_template,$(LIBVPX_TEST_BIN), \
516              $(LIBVPX_TEST_OBJS) \
517              -L. -lvpx -lgtest $(extralibs) -lm))
518
519ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
520$(TEST_INTRA_PRED_SPEED_OBJS) $(TEST_INTRA_PRED_SPEED_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
521OBJS-yes += $(TEST_INTRA_PRED_SPEED_OBJS)
522BINS-yes += $(TEST_INTRA_PRED_SPEED_BIN)
523
524$(TEST_INTRA_PRED_SPEED_BIN): $(TEST_LIBS)
525$(eval $(call linkerxx_template,$(TEST_INTRA_PRED_SPEED_BIN), \
526              $(TEST_INTRA_PRED_SPEED_OBJS) \
527              -L. -lvpx -lgtest $(extralibs) -lm))
528endif  # TEST_INTRA_PRED_SPEED
529
530endif  # CONFIG_UNIT_TESTS
531
532# Install test sources only if codec source is included
533INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\
534    $(shell find $(SRC_PATH_BARE)/third_party/googletest -type f))
535INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBVPX_TEST_SRCS)
536INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(TEST_INTRA_PRED_SPEED_SRCS)
537
538define test_shard_template
539test:: test_shard.$(1)
540test-no-data-check:: test_shard_ndc.$(1)
541test_shard.$(1) test_shard_ndc.$(1): $(LIBVPX_TEST_BIN)
542	@set -e; \
543	 export GTEST_SHARD_INDEX=$(1); \
544	 export GTEST_TOTAL_SHARDS=$(2); \
545	 $(LIBVPX_TEST_BIN)
546test_shard.$(1): testdata
547.PHONY: test_shard.$(1)
548endef
549
550NUM_SHARDS := 10
551SHARDS := 0 1 2 3 4 5 6 7 8 9
552$(foreach s,$(SHARDS),$(eval $(call test_shard_template,$(s),$(NUM_SHARDS))))
553
554endif
555
556##
557## documentation directives
558##
559CLEAN-OBJS += libs.doxy
560DOCS-yes += libs.doxy
561libs.doxy: $(CODEC_DOC_SRCS)
562	@echo "    [CREATE] $@"
563	@rm -f $@
564	@echo "INPUT += $^" >> $@
565	@echo "INCLUDE_PATH += ." >> $@;
566	@echo "ENABLED_SECTIONS += $(sort $(CODEC_DOC_SECTIONS))" >> $@
567
568## Generate rtcd.h for all objects
569ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
570$(OBJS-yes:.o=.d): $(RTCD)
571else
572$(OBJS-yes): $(RTCD)
573endif
574
575## Update the global src list
576SRCS += $(CODEC_SRCS) $(LIBVPX_TEST_SRCS) $(GTEST_SRCS)
577
578##
579## vpxdec/vpxenc tests.
580##
581ifeq ($(CONFIG_UNIT_TESTS),yes)
582TEST_BIN_PATH = .
583ifeq ($(CONFIG_MSVS),yes)
584# MSVC will build both Debug and Release configurations of tools in a
585# sub directory named for the current target. Assume the user wants to
586# run the Release tools, and assign TEST_BIN_PATH accordingly.
587# TODO(tomfinegan): Is this adequate for ARM?
588# TODO(tomfinegan): Support running the debug versions of tools?
589TEST_BIN_PATH := $(addsuffix /$(TGT_OS:win64=x64)/Release, $(TEST_BIN_PATH))
590endif
591utiltest utiltest-no-data-check:
592	$(qexec)$(SRC_PATH_BARE)/test/vpxdec.sh \
593		--test-data-path $(LIBVPX_TEST_DATA_PATH) \
594		--bin-path $(TEST_BIN_PATH)
595	$(qexec)$(SRC_PATH_BARE)/test/vpxenc.sh \
596		--test-data-path $(LIBVPX_TEST_DATA_PATH) \
597		--bin-path $(TEST_BIN_PATH)
598utiltest: testdata
599else
600utiltest utiltest-no-data-check:
601	@echo Unit tests must be enabled to make the utiltest target.
602endif
603
604##
605## Example tests.
606##
607ifeq ($(CONFIG_UNIT_TESTS),yes)
608# All non-MSVC targets output example targets in a sub dir named examples.
609EXAMPLES_BIN_PATH = examples
610ifeq ($(CONFIG_MSVS),yes)
611# MSVC will build both Debug and Release configurations of the examples in a
612# sub directory named for the current target. Assume the user wants to
613# run the Release tools, and assign EXAMPLES_BIN_PATH accordingly.
614# TODO(tomfinegan): Is this adequate for ARM?
615# TODO(tomfinegan): Support running the debug versions of tools?
616EXAMPLES_BIN_PATH := $(TGT_OS:win64=x64)/Release
617endif
618exampletest exampletest-no-data-check: examples
619	$(qexec)$(SRC_PATH_BARE)/test/examples.sh \
620		--test-data-path $(LIBVPX_TEST_DATA_PATH) \
621		--bin-path $(EXAMPLES_BIN_PATH)
622exampletest: testdata
623else
624exampletest exampletest-no-data-check:
625	@echo Unit tests must be enabled to make the exampletest target.
626endif
627