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