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