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