libs.mk 20.4 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
##
2
## Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
##
4 5 6 7 8 9
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar's avatar
John Koleszar committed
10 11 12
##


13

Johann's avatar
Johann committed
14 15 16
# ARM assembly files are written in RVCT-style. We use some make magic to
# filter those files to allow GCC compilation
ifeq ($(ARCH_ARM),yes)
17
  ASM:=$(if $(filter yes,$(CONFIG_GCC)$(CONFIG_MSVS)),.asm.s,.asm)
Johann's avatar
Johann committed
18 19 20
else
  ASM:=.asm
endif
John Koleszar's avatar
John Koleszar committed
21

22 23 24 25 26 27
#
# Rule to generate runtime cpu detection files
#
define rtcd_h_template
$$(BUILD_PFX)$(1).h: $$(SRC_PATH_BARE)/$(2)
	@echo "    [CREATE] $$@"
James Zern's avatar
James Zern committed
28
	$$(qexec)$$(SRC_PATH_BARE)/build/make/rtcd.pl --arch=$$(TGT_ISA) \
29
          --sym=$(1) \
30
          --config=$$(CONFIG_DIR)$$(target)-$$(TOOLCHAIN).mk \
31 32 33 34
          $$(RTCD_OPTIONS) $$^ > $$@
CLEAN-OBJS += $$(BUILD_PFX)$(1).h
RTCD += $$(BUILD_PFX)$(1).h
endef
35

Johann's avatar
Johann committed
36
CODEC_SRCS-yes += CHANGELOG
37 38
CODEC_SRCS-yes += libs.mk

Adrian Grange's avatar
Adrian Grange committed
39
include $(SRC_PATH_BARE)/aom/aom_codec.mk
Yaowu Xu's avatar
Yaowu Xu committed
40 41
CODEC_SRCS-yes += $(addprefix aom/,$(call enabled,API_SRCS))
CODEC_DOC_SRCS += $(addprefix aom/,$(call enabled,API_DOC_SRCS))
John Koleszar's avatar
John Koleszar committed
42

Adrian Grange's avatar
Adrian Grange committed
43
include $(SRC_PATH_BARE)/aom_mem/aom_mem.mk
Yaowu Xu's avatar
Yaowu Xu committed
44
CODEC_SRCS-yes += $(addprefix aom_mem/,$(call enabled,MEM_SRCS))
John Koleszar's avatar
John Koleszar committed
45

Adrian Grange's avatar
Adrian Grange committed
46
include $(SRC_PATH_BARE)/aom_scale/aom_scale.mk
Yaowu Xu's avatar
Yaowu Xu committed
47
CODEC_SRCS-yes += $(addprefix aom_scale/,$(call enabled,SCALE_SRCS))
John Koleszar's avatar
John Koleszar committed
48

Adrian Grange's avatar
Adrian Grange committed
49
include $(SRC_PATH_BARE)/aom_ports/aom_ports.mk
Yaowu Xu's avatar
Yaowu Xu committed
50
CODEC_SRCS-yes += $(addprefix aom_ports/,$(call enabled,PORTS_SRCS))
Johann's avatar
Johann committed
51

Adrian Grange's avatar
Adrian Grange committed
52
include $(SRC_PATH_BARE)/aom_dsp/aom_dsp.mk
Yaowu Xu's avatar
Yaowu Xu committed
53
CODEC_SRCS-yes += $(addprefix aom_dsp/,$(call enabled,DSP_SRCS))
Johann's avatar
Johann committed
54

Adrian Grange's avatar
Adrian Grange committed
55
include $(SRC_PATH_BARE)/aom_util/aom_util.mk
Yaowu Xu's avatar
Yaowu Xu committed
56
CODEC_SRCS-yes += $(addprefix aom_util/,$(call enabled,UTIL_SRCS))
57

58 59 60 61
#  AV1 make file
ifeq ($(CONFIG_AV1),yes)
  AV1_PREFIX=av1/
  include $(SRC_PATH_BARE)/$(AV1_PREFIX)av1_common.mk
Jingning Han's avatar
Jingning Han committed
62 63
endif

64 65 66 67 68
ifeq ($(CONFIG_AV1_ENCODER),yes)
  AV1_PREFIX=av1/
  include $(SRC_PATH_BARE)/$(AV1_PREFIX)av1_cx.mk
  CODEC_SRCS-yes += $(addprefix $(AV1_PREFIX),$(call enabled,AV1_CX_SRCS))
  CODEC_EXPORTS-yes += $(addprefix $(AV1_PREFIX),$(AV1_CX_EXPORTS))
Adrian Grange's avatar
Adrian Grange committed
69 70
  CODEC_SRCS-yes += $(AV1_PREFIX)av1_cx.mk aom/aom.h aom/aomcx.h
  INSTALL-LIBS-yes += include/aom/aom.h include/aom/aomcx.h
Yaowu Xu's avatar
Yaowu Xu committed
71
  INSTALL-LIBS-$(CONFIG_SPATIAL_SVC) += include/aom/svc_context.h
72
  INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/$(AV1_PREFIX)/%
Adrian Grange's avatar
Adrian Grange committed
73
  CODEC_DOC_SRCS += aom/aom.h aom/aomcx.h
74
  CODEC_DOC_SECTIONS += av1 av1_encoder
Jingning Han's avatar
Jingning Han committed
75 76
endif

77 78 79 80 81
ifeq ($(CONFIG_AV1_DECODER),yes)
  AV1_PREFIX=av1/
  include $(SRC_PATH_BARE)/$(AV1_PREFIX)av1_dx.mk
  CODEC_SRCS-yes += $(addprefix $(AV1_PREFIX),$(call enabled,AV1_DX_SRCS))
  CODEC_EXPORTS-yes += $(addprefix $(AV1_PREFIX),$(AV1_DX_EXPORTS))
Adrian Grange's avatar
Adrian Grange committed
82 83
  CODEC_SRCS-yes += $(AV1_PREFIX)av1_dx.mk aom/aom.h aom/aomdx.h
  INSTALL-LIBS-yes += include/aom/aom.h include/aom/aomdx.h
84
  INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/$(AV1_PREFIX)/%
Adrian Grange's avatar
Adrian Grange committed
85
  CODEC_DOC_SRCS += aom/aom.h aom/aomdx.h
86
  CODEC_DOC_SECTIONS += av1 av1_decoder
Jingning Han's avatar
Jingning Han committed
87 88
endif

89 90
AV1_PREFIX=av1/
$(BUILD_PFX)$(AV1_PREFIX)%.c.o: CFLAGS += -Wextra
Jingning Han's avatar
Jingning Han committed
91

John Koleszar's avatar
John Koleszar committed
92 93 94 95 96 97 98 99 100
ifeq ($(CONFIG_ENCODERS),yes)
  CODEC_DOC_SECTIONS += encoder
endif
ifeq ($(CONFIG_DECODERS),yes)
  CODEC_DOC_SECTIONS += decoder
endif


ifeq ($(CONFIG_MSVS),yes)
Adrian Grange's avatar
Adrian Grange committed
101
CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),aommt,aommd)
102
GTEST_LIB=$(if $(CONFIG_STATIC_MSVCRT),gtestmt,gtestmd)
John Koleszar's avatar
John Koleszar committed
103 104 105 106 107 108 109
# This variable uses deferred expansion intentionally, since the results of
# $(wildcard) may change during the course of the Make.
VS_PLATFORMS = $(foreach d,$(wildcard */Release/$(CODEC_LIB).lib),$(word 1,$(subst /, ,$(d))))
endif

# The following pairs define a mapping of locations in the distribution
# tree to locations in the source/build trees.
Yaowu Xu's avatar
Yaowu Xu committed
110 111
INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/aom/%
INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/aom_ports/%
112
INSTALL_MAPS += $(LIBSUBDIR)/%     %
John Koleszar's avatar
John Koleszar committed
113 114
INSTALL_MAPS += src/%     $(SRC_PATH_BARE)/%
ifeq ($(CONFIG_MSVS),yes)
115 116
INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/%  $(p)/Release/%)
INSTALL_MAPS += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/%  $(p)/Debug/%)
John Koleszar's avatar
John Koleszar committed
117 118
endif

119 120
CODEC_SRCS-yes += build/make/version.sh
CODEC_SRCS-yes += build/make/rtcd.pl
Yaowu Xu's avatar
Yaowu Xu committed
121 122 123
CODEC_SRCS-yes += aom_ports/emmintrin_compat.h
CODEC_SRCS-yes += aom_ports/mem_ops.h
CODEC_SRCS-yes += aom_ports/mem_ops_aligned.h
Adrian Grange's avatar
Adrian Grange committed
124 125 126
CODEC_SRCS-yes += aom_ports/aom_once.h
CODEC_SRCS-yes += $(BUILD_PFX)aom_config.c
INSTALL-SRCS-no += $(BUILD_PFX)aom_config.c
127
ifeq ($(ARCH_X86)$(ARCH_X86_64),yes)
128
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += third_party/x86inc/x86inc.asm
129
endif
Yaowu Xu's avatar
Yaowu Xu committed
130 131 132 133
CODEC_EXPORTS-yes += aom/exports_com
CODEC_EXPORTS-$(CONFIG_ENCODERS) += aom/exports_enc
CODEC_EXPORTS-$(CONFIG_DECODERS) += aom/exports_dec

Adrian Grange's avatar
Adrian Grange committed
134 135 136 137 138 139
INSTALL-LIBS-yes += include/aom/aom_codec.h
INSTALL-LIBS-yes += include/aom/aom_frame_buffer.h
INSTALL-LIBS-yes += include/aom/aom_image.h
INSTALL-LIBS-yes += include/aom/aom_integer.h
INSTALL-LIBS-$(CONFIG_DECODERS) += include/aom/aom_decoder.h
INSTALL-LIBS-$(CONFIG_ENCODERS) += include/aom/aom_encoder.h
John Koleszar's avatar
John Koleszar committed
140 141
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)
142 143
INSTALL-LIBS-yes                  += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB).lib)
INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/$(CODEC_LIB)d.lib)
Adrian Grange's avatar
Adrian Grange committed
144 145
INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/aom.dll)
INSTALL-LIBS-$(CONFIG_SHARED) += $(foreach p,$(VS_PLATFORMS),$(LIBSUBDIR)/$(p)/aom.exp)
John Koleszar's avatar
John Koleszar committed
146 147
endif
else
Yaowu Xu's avatar
Yaowu Xu committed
148 149
INSTALL-LIBS-$(CONFIG_STATIC) += $(LIBSUBDIR)/libaom.a
INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(LIBSUBDIR)/libaom_g.a
John Koleszar's avatar
John Koleszar committed
150 151
endif

152
CODEC_SRCS=$(call enabled,CODEC_SRCS)
John Koleszar's avatar
John Koleszar committed
153 154 155
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(CODEC_SRCS)
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(call enabled,CODEC_EXPORTS)

156 157 158

# Generate a list of all enabled sources, in particular for exporting to gyp
# based build systems.
Yaowu Xu's avatar
Yaowu Xu committed
159
libaom_srcs.txt:
160
	@echo "    [CREATE] $@"
161
	@echo $(CODEC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
Yaowu Xu's avatar
Yaowu Xu committed
162
CLEAN-OBJS += libaom_srcs.txt
163 164


John Koleszar's avatar
John Koleszar committed
165 166 167
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)

Adrian Grange's avatar
Adrian Grange committed
168
aom.def: $(call enabled,CODEC_EXPORTS)
John Koleszar's avatar
John Koleszar committed
169
	@echo "    [CREATE] $@"
170
	$(qexec)$(SRC_PATH_BARE)/build/make/gen_msvs_def.sh\
Adrian Grange's avatar
Adrian Grange committed
171
            --name=aom\
John Koleszar's avatar
John Koleszar committed
172
            --out=$@ $^
Adrian Grange's avatar
Adrian Grange committed
173
CLEAN-OBJS += aom.def
John Koleszar's avatar
John Koleszar committed
174

175 176 177 178
# Assembly files that are included, but don't define symbols themselves.
# Filtered out to avoid Visual Studio build warnings.
ASM_INCLUDES := \
    third_party/x86inc/x86inc.asm \
Adrian Grange's avatar
Adrian Grange committed
179 180
    aom_config.asm \
    aom_ports/x86_abi_support.asm \
181

Adrian Grange's avatar
Adrian Grange committed
182
aom.$(VCPROJ_SFX): $(CODEC_SRCS) aom.def
John Koleszar's avatar
John Koleszar committed
183
	@echo "    [CREATE] $@"
184
	$(qexec)$(GEN_VCPROJ) \
Jim Bankoski's avatar
Jim Bankoski committed
185 186
            $(if $(CONFIG_SHARED),--dll,--lib) \
            --target=$(TOOLCHAIN) \
John Koleszar's avatar
John Koleszar committed
187
            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
Adrian Grange's avatar
Adrian Grange committed
188
            --name=aom \
Johann's avatar
Johann committed
189
            --proj-guid=DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74 \
Adrian Grange's avatar
Adrian Grange committed
190
            --module-def=aom.def \
Johann's avatar
Johann committed
191
            --ver=$(CONFIG_VS_VERSION) \
192
            --src-path-bare="$(SRC_PATH_BARE)" \
193 194
            --out=$@ $(CFLAGS) \
            $(filter-out $(addprefix %, $(ASM_INCLUDES)), $^) \
Johann's avatar
Johann committed
195
            --src-path-bare="$(SRC_PATH_BARE)" \
John Koleszar's avatar
John Koleszar committed
196

Adrian Grange's avatar
Adrian Grange committed
197
PROJECTS-yes += aom.$(VCPROJ_SFX)
John Koleszar's avatar
John Koleszar committed
198

Adrian Grange's avatar
Adrian Grange committed
199 200
aom.$(VCPROJ_SFX): aom_config.asm
aom.$(VCPROJ_SFX): $(RTCD)
John Koleszar's avatar
John Koleszar committed
201 202 203

endif
else
Yaowu Xu's avatar
Yaowu Xu committed
204 205 206 207
LIBAOM_OBJS=$(call objs,$(CODEC_SRCS))
OBJS-yes += $(LIBAOM_OBJS)
LIBS-$(if yes,$(CONFIG_STATIC)) += $(BUILD_PFX)libaom.a $(BUILD_PFX)libaom_g.a
$(BUILD_PFX)libaom_g.a: $(LIBAOM_OBJS)
John Koleszar's avatar
John Koleszar committed
208

Johann's avatar
Johann committed
209
SO_VERSION_MAJOR := 3
210 211
SO_VERSION_MINOR := 0
SO_VERSION_PATCH := 0
jimbankoski's avatar
jimbankoski committed
212
ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS))
Yaowu Xu's avatar
Yaowu Xu committed
213
LIBAOM_SO               := libaom.$(SO_VERSION_MAJOR).dylib
214
SHARED_LIB_SUF          := .dylib
Yaowu Xu's avatar
Yaowu Xu committed
215 216 217
EXPORT_FILE             := libaom.syms
LIBAOM_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
                             libaom.dylib  )
jimbankoski's avatar
jimbankoski committed
218
else
219
ifeq ($(filter os2%,$(TGT_OS)),$(TGT_OS))
Yaowu Xu's avatar
Yaowu Xu committed
220
LIBAOM_SO               := libaom$(SO_VERSION_MAJOR).dll
221
SHARED_LIB_SUF          := _dll.a
Yaowu Xu's avatar
Yaowu Xu committed
222 223 224
EXPORT_FILE             := libaom.def
LIBAOM_SO_SYMLINKS      :=
LIBAOM_SO_IMPLIB        := libaom_dll.a
225
else
Yaowu Xu's avatar
Yaowu Xu committed
226
LIBAOM_SO               := libaom.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH)
227
SHARED_LIB_SUF          := .so
Yaowu Xu's avatar
Yaowu Xu committed
228 229 230 231
EXPORT_FILE             := libaom.ver
LIBAOM_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
                             libaom.so libaom.so.$(SO_VERSION_MAJOR) \
                             libaom.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR))
jimbankoski's avatar
jimbankoski committed
232
endif
233
endif
jimbankoski's avatar
jimbankoski committed
234

Yaowu Xu's avatar
Yaowu Xu committed
235 236 237 238 239 240 241
LIBS-$(CONFIG_SHARED) += $(BUILD_PFX)$(LIBAOM_SO)\
                           $(notdir $(LIBAOM_SO_SYMLINKS)) \
                           $(if $(LIBAOM_SO_IMPLIB), $(BUILD_PFX)$(LIBAOM_SO_IMPLIB))
$(BUILD_PFX)$(LIBAOM_SO): $(LIBAOM_OBJS) $(EXPORT_FILE)
$(BUILD_PFX)$(LIBAOM_SO): extralibs += -lm
$(BUILD_PFX)$(LIBAOM_SO): SONAME = libaom.so.$(SO_VERSION_MAJOR)
$(BUILD_PFX)$(LIBAOM_SO): EXPORTS_FILE = $(EXPORT_FILE)
John Koleszar's avatar
John Koleszar committed
242

Yaowu Xu's avatar
Yaowu Xu committed
243
libaom.ver: $(call enabled,CODEC_EXPORTS)
John Koleszar's avatar
John Koleszar committed
244 245 246 247
	@echo "    [CREATE] $@"
	$(qexec)echo "{ global:" > $@
	$(qexec)for f in $?; do awk '{print $$2";"}' < $$f >>$@; done
	$(qexec)echo "local: *; };" >> $@
Yaowu Xu's avatar
Yaowu Xu committed
248
CLEAN-OBJS += libaom.ver
John Koleszar's avatar
John Koleszar committed
249

Yaowu Xu's avatar
Yaowu Xu committed
250
libaom.syms: $(call enabled,CODEC_EXPORTS)
jimbankoski's avatar
jimbankoski committed
251 252
	@echo "    [CREATE] $@"
	$(qexec)awk '{print "_"$$2}' $^ >$@
Yaowu Xu's avatar
Yaowu Xu committed
253
CLEAN-OBJS += libaom.syms
jimbankoski's avatar
jimbankoski committed
254

Yaowu Xu's avatar
Yaowu Xu committed
255
libaom.def: $(call enabled,CODEC_EXPORTS)
256
	@echo "    [CREATE] $@"
Yaowu Xu's avatar
Yaowu Xu committed
257
	$(qexec)echo LIBRARY $(LIBAOM_SO:.dll=) INITINSTANCE TERMINSTANCE > $@
258 259
	$(qexec)echo "DATA MULTIPLE NONSHARED" >> $@
	$(qexec)echo "EXPORTS" >> $@
Adrian Grange's avatar
Adrian Grange committed
260
	$(qexec)awk '!/aom_svc_*/ {print "_"$$2}' $^ >>$@
Yaowu Xu's avatar
Yaowu Xu committed
261
CLEAN-OBJS += libaom.def
262

Yaowu Xu's avatar
Yaowu Xu committed
263
libaom_dll.a: $(LIBAOM_SO)
264 265
	@echo "    [IMPLIB] $@"
	$(qexec)emximp -o $@ $<
Yaowu Xu's avatar
Yaowu Xu committed
266
CLEAN-OBJS += libaom_dll.a
267

Yaowu Xu's avatar
Yaowu Xu committed
268
define libaom_symlink_template
269
$(1): $(2)
jimbankoski's avatar
jimbankoski committed
270
	@echo "    [LN]     $(2) $$@"
271
	$(qexec)mkdir -p $$(dir $$@)
jimbankoski's avatar
jimbankoski committed
272
	$(qexec)ln -sf $(2) $$@
273 274
endef

Yaowu Xu's avatar
Yaowu Xu committed
275 276 277 278 279 280
$(eval $(call libaom_symlink_template,\
    $(addprefix $(BUILD_PFX),$(notdir $(LIBAOM_SO_SYMLINKS))),\
    $(BUILD_PFX)$(LIBAOM_SO)))
$(eval $(call libaom_symlink_template,\
    $(addprefix $(DIST_DIR)/,$(LIBAOM_SO_SYMLINKS)),\
    $(LIBAOM_SO)))
John Koleszar's avatar
John Koleszar committed
281

jimbankoski's avatar
jimbankoski committed
282

Yaowu Xu's avatar
Yaowu Xu committed
283 284 285
INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBAOM_SO_SYMLINKS)
INSTALL-LIBS-$(CONFIG_SHARED) += $(LIBSUBDIR)/$(LIBAOM_SO)
INSTALL-LIBS-$(CONFIG_SHARED) += $(if $(LIBAOM_SO_IMPLIB),$(LIBSUBDIR)/$(LIBAOM_SO_IMPLIB))
John Koleszar's avatar
John Koleszar committed
286

287

Adrian Grange's avatar
Adrian Grange committed
288 289
LIBS-yes += aom.pc
aom.pc: config.mk libs.mk
290
	@echo "    [CREATE] $@"
Yaowu Xu's avatar
Yaowu Xu committed
291
	$(qexec)echo '# pkg-config file from libaom $(VERSION_STRING)' > $@
292 293
	$(qexec)echo 'prefix=$(PREFIX)' >> $@
	$(qexec)echo 'exec_prefix=$${prefix}' >> $@
Takanori MATSUURA's avatar
Takanori MATSUURA committed
294
	$(qexec)echo 'libdir=$${prefix}/$(LIBSUBDIR)' >> $@
295 296
	$(qexec)echo 'includedir=$${prefix}/include' >> $@
	$(qexec)echo '' >> $@
Adrian Grange's avatar
Adrian Grange committed
297
	$(qexec)echo 'Name: aom' >> $@
298
	$(qexec)echo 'Description: AOMedia Project AVx codec implementation' >> $@
299 300 301
	$(qexec)echo 'Version: $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)' >> $@
	$(qexec)echo 'Requires:' >> $@
	$(qexec)echo 'Conflicts:' >> $@
Yaowu Xu's avatar
Yaowu Xu committed
302
	$(qexec)echo 'Libs: -L$${libdir} -laom -lm' >> $@
Johann's avatar
Johann committed
303
ifeq ($(HAVE_PTHREAD_H),yes)
304
	$(qexec)echo 'Libs.private: -lm -lpthread' >> $@
Johann's avatar
Johann committed
305 306 307
else
	$(qexec)echo 'Libs.private: -lm' >> $@
endif
308
	$(qexec)echo 'Cflags: -I$${includedir}' >> $@
Adrian Grange's avatar
Adrian Grange committed
309
INSTALL-LIBS-yes += $(LIBSUBDIR)/pkgconfig/aom.pc
310
INSTALL_MAPS += $(LIBSUBDIR)/pkgconfig/%.pc %.pc
Adrian Grange's avatar
Adrian Grange committed
311
CLEAN-OBJS += aom.pc
John Koleszar's avatar
John Koleszar committed
312 313 314 315 316 317 318
endif

#
# Rule to make assembler configuration file from C configuration file
#
ifeq ($(ARCH_X86)$(ARCH_X86_64),yes)
# YASM
Adrian Grange's avatar
Adrian Grange committed
319
$(BUILD_PFX)aom_config.asm: $(BUILD_PFX)aom_config.h
John Koleszar's avatar
John Koleszar committed
320 321 322 323 324
	@echo "    [CREATE] $@"
	@egrep "#define [A-Z0-9_]+ [01]" $< \
	    | awk '{print $$2 " equ " $$3}' > $@
else
ADS2GAS=$(if $(filter yes,$(CONFIG_GCC)),| $(ASM_CONVERSION))
Adrian Grange's avatar
Adrian Grange committed
325
$(BUILD_PFX)aom_config.asm: $(BUILD_PFX)aom_config.h
John Koleszar's avatar
John Koleszar committed
326 327 328 329
	@echo "    [CREATE] $@"
	@egrep "#define [A-Z0-9_]+ [01]" $< \
	    | awk '{print $$2 " EQU " $$3}' $(ADS2GAS) > $@
	@echo "        END" $(ADS2GAS) >> $@
Adrian Grange's avatar
Adrian Grange committed
330
CLEAN-OBJS += $(BUILD_PFX)aom_config.asm
John Koleszar's avatar
John Koleszar committed
331 332 333
endif

#
Johann's avatar
Johann committed
334
# Add assembler dependencies for configuration.
John Koleszar's avatar
John Koleszar committed
335
#
Adrian Grange's avatar
Adrian Grange committed
336 337
$(filter %.s.o,$(OBJS-yes)):     $(BUILD_PFX)aom_config.asm
$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)aom_config.asm
John Koleszar's avatar
John Koleszar committed
338

Johann's avatar
Johann committed
339

Adrian Grange's avatar
Adrian Grange committed
340 341
$(shell $(SRC_PATH_BARE)/build/make/version.sh "$(SRC_PATH_BARE)" $(BUILD_PFX)aom_version.h)
CLEAN-OBJS += $(BUILD_PFX)aom_version.h
John Koleszar's avatar
John Koleszar committed
342

John Koleszar's avatar
John Koleszar committed
343

344
##
Yaowu Xu's avatar
Yaowu Xu committed
345
## libaom test directives
346 347
##
ifeq ($(CONFIG_UNIT_TESTS),yes)
Adrian Grange's avatar
Adrian Grange committed
348
LIBAOM_TEST_DATA_PATH ?= .
349 350

include $(SRC_PATH_BARE)/test/test.mk
Yaowu Xu's avatar
Yaowu Xu committed
351 352 353 354
LIBAOM_TEST_SRCS=$(addprefix test/,$(call enabled,LIBAOM_TEST_SRCS))
LIBAOM_TEST_BIN=./test_libaom$(EXE_SFX)
LIBAOM_TEST_DATA=$(addprefix $(LIBAOM_TEST_DATA_PATH)/,\
                     $(call enabled,LIBAOM_TEST_DATA))
Adrian Grange's avatar
Adrian Grange committed
355
libaom_test_data_url=http://downloads.webmproject.org/test_data/libvpx/$(1)
356

James Zern's avatar
James Zern committed
357 358
TEST_INTRA_PRED_SPEED_BIN=./test_intra_pred_speed$(EXE_SFX)
TEST_INTRA_PRED_SPEED_SRCS=$(addprefix test/,$(call enabled,TEST_INTRA_PRED_SPEED_SRCS))
359
TEST_INTRA_PRED_SPEED_OBJS := $(sort $(call objs,$(TEST_INTRA_PRED_SPEED_SRCS)))
James Zern's avatar
James Zern committed
360

Yaowu Xu's avatar
Yaowu Xu committed
361
libaom_test_srcs.txt:
362
	@echo "    [CREATE] $@"
Yaowu Xu's avatar
Yaowu Xu committed
363 364
	@echo $(LIBAOM_TEST_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
CLEAN-OBJS += libaom_test_srcs.txt
365

Yaowu Xu's avatar
Yaowu Xu committed
366
$(LIBAOM_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1
367 368
	@echo "    [DOWNLOAD] $@"
	$(qexec)trap 'rm -f $@' INT TERM &&\
Yaowu Xu's avatar
Yaowu Xu committed
369
            curl -L -o $@ $(call libaom_test_data_url,$(@F))
370

Yaowu Xu's avatar
Yaowu Xu committed
371
testdata:: $(LIBAOM_TEST_DATA)
372 373 374 375
	$(qexec)[ -x "$$(which sha1sum)" ] && sha1sum=sha1sum;\
          [ -x "$$(which shasum)" ] && sha1sum=shasum;\
          [ -x "$$(which sha1)" ] && sha1sum=sha1;\
          if [ -n "$${sha1sum}" ]; then\
376
            set -e;\
377
            echo "Checking test data:";\
Yaowu Xu's avatar
Yaowu Xu committed
378
            for f in $(call enabled,LIBAOM_TEST_DATA); do\
379
                grep $$f $(SRC_PATH_BARE)/test/test-data.sha1 |\
Adrian Grange's avatar
Adrian Grange committed
380
                    (cd $(LIBAOM_TEST_DATA_PATH); $${sha1sum} -c);\
381
            done; \
382 383 384
        else\
            echo "Skipping test data integrity check, sha1sum not found.";\
        fi
385

386 387 388
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)

389
gtest.$(VCPROJ_SFX): $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc
390
	@echo "    [CREATE] $@"
391
	$(qexec)$(GEN_VCPROJ) \
392 393 394 395 396 397 398
            --lib \
            --target=$(TOOLCHAIN) \
            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
            --name=gtest \
            --proj-guid=EC00E1EC-AF68-4D92-A255-181690D1C9B1 \
            --ver=$(CONFIG_VS_VERSION) \
            --src-path-bare="$(SRC_PATH_BARE)" \
399
            -D_VARIADIC_MAX=10 \
400
            --out=gtest.$(VCPROJ_SFX) $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc \
401 402
            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" -I"$(SRC_PATH_BARE)/third_party/googletest/src"

403
PROJECTS-$(CONFIG_MSVS) += gtest.$(VCPROJ_SFX)
404

Adrian Grange's avatar
Adrian Grange committed
405
test_libaom.$(VCPROJ_SFX): $(LIBAOM_TEST_SRCS) aom.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
406
	@echo "    [CREATE] $@"
407
	$(qexec)$(GEN_VCPROJ) \
408 409
            --exe \
            --target=$(TOOLCHAIN) \
Yaowu Xu's avatar
Yaowu Xu committed
410
            --name=test_libaom \
411
            -D_VARIADIC_MAX=10 \
412 413
            --proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
            --ver=$(CONFIG_VS_VERSION) \
414
            --src-path-bare="$(SRC_PATH_BARE)" \
415 416
            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
            --out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
417
            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
Martin Storsjo's avatar
Martin Storsjo committed
418
            -L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
419

Yaowu Xu's avatar
Yaowu Xu committed
420
PROJECTS-$(CONFIG_MSVS) += test_libaom.$(VCPROJ_SFX)
421

Yaowu Xu's avatar
Yaowu Xu committed
422
LIBAOM_TEST_BIN := $(addprefix $(TGT_OS:win64=x64)/Release/,$(notdir $(LIBAOM_TEST_BIN)))
James Zern's avatar
James Zern committed
423 424 425

ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
PROJECTS-$(CONFIG_MSVS) += test_intra_pred_speed.$(VCPROJ_SFX)
Adrian Grange's avatar
Adrian Grange committed
426
test_intra_pred_speed.$(VCPROJ_SFX): $(TEST_INTRA_PRED_SPEED_SRCS) aom.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
James Zern's avatar
James Zern committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440
	@echo "    [CREATE] $@"
	$(qexec)$(GEN_VCPROJ) \
            --exe \
            --target=$(TOOLCHAIN) \
            --name=test_intra_pred_speed \
            -D_VARIADIC_MAX=10 \
            --proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
            --ver=$(CONFIG_VS_VERSION) \
            --src-path-bare="$(SRC_PATH_BARE)" \
            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
            --out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
            -L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
endif  # TEST_INTRA_PRED_SPEED
441 442 443 444 445 446
endif
else

include $(SRC_PATH_BARE)/third_party/googletest/gtest.mk
GTEST_SRCS := $(addprefix third_party/googletest/src/,$(call enabled,GTEST_SRCS))
GTEST_OBJS=$(call objs,$(GTEST_SRCS))
447 448 449 450
ifeq ($(filter win%,$(TGT_OS)),$(TGT_OS))
# Disabling pthreads globally will cause issues on darwin and possibly elsewhere
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += -DGTEST_HAS_PTHREAD=0
endif
James Zern's avatar
James Zern committed
451 452 453
GTEST_INCLUDES := -I$(SRC_PATH_BARE)/third_party/googletest/src
GTEST_INCLUDES += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
454 455
OBJS-yes += $(GTEST_OBJS)
LIBS-yes += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
456 457
$(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS)

Yaowu Xu's avatar
Yaowu Xu committed
458 459 460 461
LIBAOM_TEST_OBJS=$(sort $(call objs,$(LIBAOM_TEST_SRCS)))
$(LIBAOM_TEST_OBJS) $(LIBAOM_TEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
OBJS-yes += $(LIBAOM_TEST_OBJS)
BINS-yes += $(LIBAOM_TEST_BIN)
462

Yaowu Xu's avatar
Yaowu Xu committed
463
CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),aom_g,aom)
464
CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a)
James Zern's avatar
James Zern committed
465
TEST_LIBS := lib$(CODEC_LIB)$(CODEC_LIB_SUF) libgtest.a
Yaowu Xu's avatar
Yaowu Xu committed
466 467 468
$(LIBAOM_TEST_BIN): $(TEST_LIBS)
$(eval $(call linkerxx_template,$(LIBAOM_TEST_BIN), \
              $(LIBAOM_TEST_OBJS) \
Yaowu Xu's avatar
Yaowu Xu committed
469
              -L. -laom -lgtest $(extralibs) -lm))
470

James Zern's avatar
James Zern committed
471 472 473 474 475 476 477 478
ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
$(TEST_INTRA_PRED_SPEED_OBJS) $(TEST_INTRA_PRED_SPEED_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
OBJS-yes += $(TEST_INTRA_PRED_SPEED_OBJS)
BINS-yes += $(TEST_INTRA_PRED_SPEED_BIN)

$(TEST_INTRA_PRED_SPEED_BIN): $(TEST_LIBS)
$(eval $(call linkerxx_template,$(TEST_INTRA_PRED_SPEED_BIN), \
              $(TEST_INTRA_PRED_SPEED_OBJS) \
Yaowu Xu's avatar
Yaowu Xu committed
479
              -L. -laom -lgtest $(extralibs) -lm))
James Zern's avatar
James Zern committed
480 481
endif  # TEST_INTRA_PRED_SPEED

482
endif  # CONFIG_UNIT_TESTS
483

Johann's avatar
Johann committed
484 485 486
# Install test sources only if codec source is included
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\
    $(shell find $(SRC_PATH_BARE)/third_party/googletest -type f))
Yaowu Xu's avatar
Yaowu Xu committed
487
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBAOM_TEST_SRCS)
James Zern's avatar
James Zern committed
488
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(TEST_INTRA_PRED_SPEED_SRCS)
Johann's avatar
Johann committed
489

490 491
define test_shard_template
test:: test_shard.$(1)
492
test-no-data-check:: test_shard_ndc.$(1)
Yaowu Xu's avatar
Yaowu Xu committed
493
test_shard.$(1) test_shard_ndc.$(1): $(LIBAOM_TEST_BIN)
494
	@set -e; \
495 496
	 export GTEST_SHARD_INDEX=$(1); \
	 export GTEST_TOTAL_SHARDS=$(2); \
Yaowu Xu's avatar
Yaowu Xu committed
497
	 $(LIBAOM_TEST_BIN)
498
test_shard.$(1): testdata
499 500 501 502 503 504 505
.PHONY: test_shard.$(1)
endef

NUM_SHARDS := 10
SHARDS := 0 1 2 3 4 5 6 7 8 9
$(foreach s,$(SHARDS),$(eval $(call test_shard_template,$(s),$(NUM_SHARDS))))

506 507 508 509 510
endif

##
## documentation directives
##
John Koleszar's avatar
John Koleszar committed
511 512 513 514 515 516 517 518
CLEAN-OBJS += libs.doxy
DOCS-yes += libs.doxy
libs.doxy: $(CODEC_DOC_SRCS)
	@echo "    [CREATE] $@"
	@rm -f $@
	@echo "INPUT += $^" >> $@
	@echo "INCLUDE_PATH += ." >> $@;
	@echo "ENABLED_SECTIONS += $(sort $(CODEC_DOC_SECTIONS))" >> $@
519

520
## Generate rtcd.h for all objects
521
ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
522
$(OBJS-yes:.o=.d): $(RTCD)
523 524 525
else
$(OBJS-yes): $(RTCD)
endif
526 527

## Update the global src list
Yaowu Xu's avatar
Yaowu Xu committed
528
SRCS += $(CODEC_SRCS) $(LIBAOM_TEST_SRCS) $(GTEST_SRCS)
Tom Finegan's avatar
Tom Finegan committed
529 530

##
Adrian Grange's avatar
Adrian Grange committed
531
## aomdec/aomenc tests.
Tom Finegan's avatar
Tom Finegan committed
532 533 534 535 536 537 538 539 540 541 542
##
ifeq ($(CONFIG_UNIT_TESTS),yes)
TEST_BIN_PATH = .
ifeq ($(CONFIG_MSVS),yes)
# MSVC will build both Debug and Release configurations of tools in a
# sub directory named for the current target. Assume the user wants to
# run the Release tools, and assign TEST_BIN_PATH accordingly.
# TODO(tomfinegan): Is this adequate for ARM?
# TODO(tomfinegan): Support running the debug versions of tools?
TEST_BIN_PATH := $(addsuffix /$(TGT_OS:win64=x64)/Release, $(TEST_BIN_PATH))
endif
543
utiltest utiltest-no-data-check:
Adrian Grange's avatar
Adrian Grange committed
544
	$(qexec)$(SRC_PATH_BARE)/test/aomdec.sh \
Adrian Grange's avatar
Adrian Grange committed
545
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
Tom Finegan's avatar
Tom Finegan committed
546
		--bin-path $(TEST_BIN_PATH)
Adrian Grange's avatar
Adrian Grange committed
547
	$(qexec)$(SRC_PATH_BARE)/test/aomenc.sh \
Adrian Grange's avatar
Adrian Grange committed
548
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
Tom Finegan's avatar
Tom Finegan committed
549
		--bin-path $(TEST_BIN_PATH)
550
utiltest: testdata
Tom Finegan's avatar
Tom Finegan committed
551
else
552
utiltest utiltest-no-data-check:
Tom Finegan's avatar
Tom Finegan committed
553 554
	@echo Unit tests must be enabled to make the utiltest target.
endif
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569

##
## Example tests.
##
ifeq ($(CONFIG_UNIT_TESTS),yes)
# All non-MSVC targets output example targets in a sub dir named examples.
EXAMPLES_BIN_PATH = examples
ifeq ($(CONFIG_MSVS),yes)
# MSVC will build both Debug and Release configurations of the examples in a
# sub directory named for the current target. Assume the user wants to
# run the Release tools, and assign EXAMPLES_BIN_PATH accordingly.
# TODO(tomfinegan): Is this adequate for ARM?
# TODO(tomfinegan): Support running the debug versions of tools?
EXAMPLES_BIN_PATH := $(TGT_OS:win64=x64)/Release
endif
570
exampletest exampletest-no-data-check: examples
571
	$(qexec)$(SRC_PATH_BARE)/test/examples.sh \
Adrian Grange's avatar
Adrian Grange committed
572
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
573
		--bin-path $(EXAMPLES_BIN_PATH)
574
exampletest: testdata
575
else
576
exampletest exampletest-no-data-check:
577 578
	@echo Unit tests must be enabled to make the exampletest target.
endif