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