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