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