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