libs.mk 20.8 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
##
Yaowu Xu's avatar
Yaowu Xu committed
2
## Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
##
Yaowu Xu's avatar
Yaowu Xu committed
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
##


Johann's avatar
Johann committed
13 14 15
# 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)
16
  ASM:=$(if $(filter yes,$(CONFIG_GCC)$(CONFIG_MSVS)),.asm.s,.asm)
Johann's avatar
Johann committed
17 18 19
else
  ASM:=.asm
endif
John Koleszar's avatar
John Koleszar committed
20

21 22 23 24 25 26
#
# 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
27
	$$(qexec)$$(SRC_PATH_BARE)/build/make/rtcd.pl --arch=$$(TGT_ISA) \
28
          --sym=$(1) \
29
          --config=$$(CONFIG_DIR)$$(target)-$$(TOOLCHAIN).mk \
30 31 32 33
          $$(RTCD_OPTIONS) $$^ > $$@
CLEAN-OBJS += $$(BUILD_PFX)$(1).h
RTCD += $$(BUILD_PFX)$(1).h
endef
34

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

Yaowu Xu's avatar
Yaowu Xu committed
38
include $(SRC_PATH_BARE)/aom/aom_codec.mk
39 40
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
41

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

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

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

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

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

Yaowu Xu's avatar
Yaowu Xu committed
57 58 59 60
#  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
61 62
endif

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

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

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

John Koleszar's avatar
John Koleszar committed
90
ifeq ($(CONFIG_MSVS),yes)
Yaowu Xu's avatar
Yaowu Xu committed
91
CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),aommt,aommd)
92
GTEST_LIB=$(if $(CONFIG_STATIC_MSVCRT),gtestmt,gtestmd)
John Koleszar's avatar
John Koleszar committed
93 94 95 96 97 98 99
# 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.
100 101
INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/aom/%
INSTALL_MAPS += include/aom/% $(SRC_PATH_BARE)/aom_ports/%
102
INSTALL_MAPS += $(LIBSUBDIR)/%     %
John Koleszar's avatar
John Koleszar committed
103 104
INSTALL_MAPS += src/%     $(SRC_PATH_BARE)/%
ifeq ($(CONFIG_MSVS),yes)
105 106
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
107 108
endif

109 110
CODEC_SRCS-yes += build/make/version.sh
CODEC_SRCS-yes += build/make/rtcd.pl
111 112 113
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
Yaowu Xu's avatar
Yaowu Xu committed
114 115 116
CODEC_SRCS-yes += aom_ports/aom_once.h
CODEC_SRCS-yes += $(BUILD_PFX)aom_config.c
INSTALL-SRCS-no += $(BUILD_PFX)aom_config.c
117
ifeq ($(ARCH_X86)$(ARCH_X86_64),yes)
118
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += third_party/x86inc/x86inc.asm
119
endif
120
CODEC_EXPORTS-yes += aom/exports_com
121 122
CODEC_EXPORTS-$(CONFIG_AV1_ENCODER) += aom/exports_enc
CODEC_EXPORTS-$(CONFIG_AV1_DECODER) += aom/exports_dec
123

Yaowu Xu's avatar
Yaowu Xu committed
124 125 126 127
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
128 129
INSTALL-LIBS-$(CONFIG_AV1_DECODER) += include/aom/aom_decoder.h
INSTALL-LIBS-$(CONFIG_AV1_ENCODER) += include/aom/aom_encoder.h
John Koleszar's avatar
John Koleszar committed
130 131
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)
132 133
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)
Yaowu Xu's avatar
Yaowu Xu committed
134 135
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
136 137
endif
else
138 139
INSTALL-LIBS-$(CONFIG_STATIC) += $(LIBSUBDIR)/libaom.a
INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(LIBSUBDIR)/libaom_g.a
John Koleszar's avatar
John Koleszar committed
140 141
endif

142
CODEC_SRCS=$(call enabled,CODEC_SRCS)
John Koleszar's avatar
John Koleszar committed
143 144 145
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(CODEC_SRCS)
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(call enabled,CODEC_EXPORTS)

146 147 148

# Generate a list of all enabled sources, in particular for exporting to gyp
# based build systems.
149
libaom_srcs.txt:
150
	@echo "    [CREATE] $@"
151
	@echo $(CODEC_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
152
CLEAN-OBJS += libaom_srcs.txt
153 154


John Koleszar's avatar
John Koleszar committed
155 156 157
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)

Yaowu Xu's avatar
Yaowu Xu committed
158
aom.def: $(call enabled,CODEC_EXPORTS)
John Koleszar's avatar
John Koleszar committed
159
	@echo "    [CREATE] $@"
160
	$(qexec)$(SRC_PATH_BARE)/build/make/gen_msvs_def.sh\
Yaowu Xu's avatar
Yaowu Xu committed
161
            --name=aom\
John Koleszar's avatar
John Koleszar committed
162
            --out=$@ $^
Yaowu Xu's avatar
Yaowu Xu committed
163
CLEAN-OBJS += aom.def
John Koleszar's avatar
John Koleszar committed
164

165 166 167 168
# 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 \
Yaowu Xu's avatar
Yaowu Xu committed
169
    aom_config.asm \
170
    aom_ports/x86_abi_support.asm \
171

Yaowu Xu's avatar
Yaowu Xu committed
172
aom.$(VCPROJ_SFX): $(CODEC_SRCS) aom.def
John Koleszar's avatar
John Koleszar committed
173
	@echo "    [CREATE] $@"
174
	$(qexec)$(GEN_VCPROJ) \
Jim Bankoski's avatar
Jim Bankoski committed
175 176
            $(if $(CONFIG_SHARED),--dll,--lib) \
            --target=$(TOOLCHAIN) \
John Koleszar's avatar
John Koleszar committed
177
            $(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
Yaowu Xu's avatar
Yaowu Xu committed
178
            --name=aom \
Johann's avatar
Johann committed
179
            --proj-guid=DCE19DAF-69AC-46DB-B14A-39F0FAA5DB74 \
Yaowu Xu's avatar
Yaowu Xu committed
180
            --module-def=aom.def \
Johann's avatar
Johann committed
181
            --ver=$(CONFIG_VS_VERSION) \
182
            --src-path-bare="$(SRC_PATH_BARE)" \
183 184
            --out=$@ $(CFLAGS) \
            $(filter-out $(addprefix %, $(ASM_INCLUDES)), $^) \
Johann's avatar
Johann committed
185
            --src-path-bare="$(SRC_PATH_BARE)" \
John Koleszar's avatar
John Koleszar committed
186

Yaowu Xu's avatar
Yaowu Xu committed
187
PROJECTS-yes += aom.$(VCPROJ_SFX)
John Koleszar's avatar
John Koleszar committed
188

Yaowu Xu's avatar
Yaowu Xu committed
189 190
aom.$(VCPROJ_SFX): aom_config.asm
aom.$(VCPROJ_SFX): $(RTCD)
John Koleszar's avatar
John Koleszar committed
191 192 193

endif
else
194 195 196 197
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
198

199
SO_VERSION_MAJOR := 0
200 201
SO_VERSION_MINOR := 0
SO_VERSION_PATCH := 0
jimbankoski's avatar
jimbankoski committed
202
ifeq ($(filter darwin%,$(TGT_OS)),$(TGT_OS))
203
LIBAOM_SO               := libaom.$(SO_VERSION_MAJOR).dylib
204
SHARED_LIB_SUF          := .dylib
205 206 207
EXPORT_FILE             := libaom.syms
LIBAOM_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, \
                             libaom.dylib  )
jimbankoski's avatar
jimbankoski committed
208
else
209
ifeq ($(filter iphonesimulator%,$(TGT_OS)),$(TGT_OS))
210
LIBAOM_SO               := libaom.$(SO_VERSION_MAJOR).dylib
211
SHARED_LIB_SUF          := .dylib
212 213
EXPORT_FILE             := libaom.syms
LIBAOM_SO_SYMLINKS      := $(addprefix $(LIBSUBDIR)/, libaom.dylib)
214
else
215
ifeq ($(filter os2%,$(TGT_OS)),$(TGT_OS))
216
LIBAOM_SO               := libaom$(SO_VERSION_MAJOR).dll
217
SHARED_LIB_SUF          := _dll.a
218 219 220
EXPORT_FILE             := libaom.def
LIBAOM_SO_SYMLINKS      :=
LIBAOM_SO_IMPLIB        := libaom_dll.a
221
else
222
LIBAOM_SO               := libaom.so.$(SO_VERSION_MAJOR).$(SO_VERSION_MINOR).$(SO_VERSION_PATCH)
223
SHARED_LIB_SUF          := .so
224 225 226 227
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
228
endif
229
endif
230
endif
jimbankoski's avatar
jimbankoski committed
231

232 233 234 235 236 237 238
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
239

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

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

252
libaom.def: $(call enabled,CODEC_EXPORTS)
253
	@echo "    [CREATE] $@"
254
	$(qexec)echo LIBRARY $(LIBAOM_SO:.dll=) INITINSTANCE TERMINSTANCE > $@
255 256
	$(qexec)echo "DATA MULTIPLE NONSHARED" >> $@
	$(qexec)echo "EXPORTS" >> $@
James Zern's avatar
James Zern committed
257
	$(qexec)awk '{print "_"$$2}' $^ >>$@
258
CLEAN-OBJS += libaom.def
259

260
libaom_dll.a: $(LIBAOM_SO)
261 262
	@echo "    [IMPLIB] $@"
	$(qexec)emximp -o $@ $<
263
CLEAN-OBJS += libaom_dll.a
264

265
define libaom_symlink_template
266
$(1): $(2)
jimbankoski's avatar
jimbankoski committed
267
	@echo "    [LN]     $(2) $$@"
268
	$(qexec)mkdir -p $$(dir $$@)
jimbankoski's avatar
jimbankoski committed
269
	$(qexec)ln -sf $(2) $$@
270 271
endef

272 273 274 275 276 277
$(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
278

jimbankoski's avatar
jimbankoski committed
279

280 281 282
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
283

284

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

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

#
Johann's avatar
Johann committed
331
# Add assembler dependencies for configuration.
John Koleszar's avatar
John Koleszar committed
332
#
Yaowu Xu's avatar
Yaowu Xu committed
333 334
$(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
335

Johann's avatar
Johann committed
336

Yaowu Xu's avatar
Yaowu Xu committed
337 338
$(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
339

340 341 342 343 344 345
#
# Add include path for libwebm sources.
#
ifeq ($(CONFIG_WEBM_IO),yes)
  CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/libwebm
endif
John Koleszar's avatar
John Koleszar committed
346

347
##
348
## libaom test directives
349 350
##
ifeq ($(CONFIG_UNIT_TESTS),yes)
351
LIBAOM_TEST_DATA_PATH ?= .
352 353

include $(SRC_PATH_BARE)/test/test.mk
354
LIBAOM_TEST_SRCS=$(addprefix test/,$(call enabled,LIBAOM_TEST_SRCS))
Yaowu Xu's avatar
Yaowu Xu committed
355
LIBAOM_TEST_BIN=./test_libaom$(EXE_SFX)
356
LIBAOM_TEST_DATA=$(addprefix $(LIBAOM_TEST_DATA_PATH)/,\
357
                     $(call enabled,LIBAOM_TEST_DATA))
358
libaom_test_data_url=https://storage.googleapis.com/downloads.webmproject.org/test_data/libvpx/$(1)
359

James Zern's avatar
James Zern committed
360 361
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))
362
TEST_INTRA_PRED_SPEED_OBJS := $(sort $(call objs,$(TEST_INTRA_PRED_SPEED_SRCS)))
James Zern's avatar
James Zern committed
363

364
libaom_test_srcs.txt:
365
	@echo "    [CREATE] $@"
366 367
	@echo $(LIBAOM_TEST_SRCS) | xargs -n1 echo | LC_ALL=C sort -u > $@
CLEAN-OBJS += libaom_test_srcs.txt
368

369
$(LIBAOM_TEST_DATA): $(SRC_PATH_BARE)/test/test-data.sha1
370 371
	@echo "    [DOWNLOAD] $@"
	$(qexec)trap 'rm -f $@' INT TERM &&\
372
            curl -L -o $@ $(call libaom_test_data_url,$(@F))
373

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

389 390
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)
391
gtest.$(VCPROJ_SFX): $(SRC_PATH_BARE)/third_party/googletest/src/googletest/src/gtest-all.cc
392
	@echo "    [CREATE] $@"
393
	$(qexec)$(GEN_VCPROJ) \
394 395 396 397 398 399 400
            --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)" \
401
            -D_VARIADIC_MAX=10 \
402 403 404 405
            --out=gtest.$(VCPROJ_SFX) \
	    $(SRC_PATH_BARE)/third_party/googletest/src/googletest/src/gtest-all.cc \
            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/googletest/include" \
	    -I"$(SRC_PATH_BARE)/third_party/googletest/src/googletest"
406

407
PROJECTS-$(CONFIG_MSVS) += gtest.$(VCPROJ_SFX)
408

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

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

427
LIBAOM_TEST_BIN := $(addprefix $(TGT_OS:win64=x64)/Release/,$(notdir $(LIBAOM_TEST_BIN)))
James Zern's avatar
James Zern committed
428 429 430

ifneq ($(strip $(TEST_INTRA_PRED_SPEED_OBJS)),)
PROJECTS-$(CONFIG_MSVS) += test_intra_pred_speed.$(VCPROJ_SFX)
Yaowu Xu's avatar
Yaowu Xu committed
431
test_intra_pred_speed.$(VCPROJ_SFX): $(TEST_INTRA_PRED_SPEED_SRCS) aom.$(VCPROJ_SFX) gtest.$(VCPROJ_SFX)
James Zern's avatar
James Zern committed
432 433 434 435 436 437 438 439 440 441 442
	@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) \
443
            -I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/googletest/include" \
James Zern's avatar
James Zern committed
444 445
            -L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
endif  # TEST_INTRA_PRED_SPEED
446 447 448 449
endif
else

include $(SRC_PATH_BARE)/third_party/googletest/gtest.mk
450
GTEST_SRCS := $(addprefix third_party/,$(call enabled,GTEST_SRCS))
451
GTEST_OBJS=$(call objs,$(GTEST_SRCS))
452 453 454 455
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
456 457
GTEST_INCLUDES := -I$(SRC_PATH_BARE)/third_party/googletest/src/googletest
GTEST_INCLUDES += -I$(SRC_PATH_BARE)/third_party/googletest/src/googletest/include
James Zern's avatar
James Zern committed
458
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CXXFLAGS += $(GTEST_INCLUDES)
459 460
OBJS-yes += $(GTEST_OBJS)
LIBS-yes += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
461 462
$(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS)

463 464 465 466
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)
467

468
CODEC_LIB=$(if $(CONFIG_DEBUG_LIBS),aom_g,aom)
469
CODEC_LIB_SUF=$(if $(CONFIG_SHARED),$(SHARED_LIB_SUF),.a)
James Zern's avatar
James Zern committed
470
TEST_LIBS := lib$(CODEC_LIB)$(CODEC_LIB_SUF) libgtest.a
471 472 473 474
$(LIBAOM_TEST_BIN): $(TEST_LIBS)
$(eval $(call linkerxx_template,$(LIBAOM_TEST_BIN), \
              $(LIBAOM_TEST_OBJS) \
              -L. -laom -lgtest $(extralibs) -lm))
475

James Zern's avatar
James Zern committed
476 477 478 479 480 481 482 483
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) \
484
              -L. -laom -lgtest $(extralibs) -lm))
James Zern's avatar
James Zern committed
485 486
endif  # TEST_INTRA_PRED_SPEED

487
endif  # CONFIG_UNIT_TESTS
488

Johann's avatar
Johann committed
489 490 491
# 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))
492
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBAOM_TEST_SRCS)
James Zern's avatar
James Zern committed
493
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(TEST_INTRA_PRED_SPEED_SRCS)
Johann's avatar
Johann committed
494

495 496
define test_shard_template
test:: test_shard.$(1)
497
test-no-data-check:: test_shard_ndc.$(1)
498
test_shard.$(1) test_shard_ndc.$(1): $(LIBAOM_TEST_BIN)
499
	@set -e; \
500 501
	 export GTEST_SHARD_INDEX=$(1); \
	 export GTEST_TOTAL_SHARDS=$(2); \
502
	 $(LIBAOM_TEST_BIN)
503
test_shard.$(1): testdata
504 505 506 507 508 509 510
.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))))

511 512 513 514 515
endif

##
## documentation directives
##
John Koleszar's avatar
John Koleszar committed
516 517 518 519 520 521 522 523
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))" >> $@
524

525
## Generate rtcd.h for all objects
526
ifeq ($(CONFIG_DEPENDENCY_TRACKING),yes)
527
$(OBJS-yes:.o=.d): $(RTCD)
528 529 530
else
$(OBJS-yes): $(RTCD)
endif
531 532

## Update the global src list
533
SRCS += $(CODEC_SRCS) $(LIBAOM_TEST_SRCS) $(GTEST_SRCS)
Tom Finegan's avatar
Tom Finegan committed
534 535

##
Yaowu Xu's avatar
Yaowu Xu committed
536
## aomdec/aomenc tests.
Tom Finegan's avatar
Tom Finegan committed
537 538 539 540 541 542 543 544 545 546 547
##
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
548
utiltest utiltest-no-data-check:
Yaowu Xu's avatar
Yaowu Xu committed
549
	$(qexec)$(SRC_PATH_BARE)/test/aomdec.sh \
550
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
Tom Finegan's avatar
Tom Finegan committed
551
		--bin-path $(TEST_BIN_PATH)
Yaowu Xu's avatar
Yaowu Xu committed
552
	$(qexec)$(SRC_PATH_BARE)/test/aomenc.sh \
553
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
Tom Finegan's avatar
Tom Finegan committed
554
		--bin-path $(TEST_BIN_PATH)
555
utiltest: testdata
Tom Finegan's avatar
Tom Finegan committed
556
else
557
utiltest utiltest-no-data-check:
Tom Finegan's avatar
Tom Finegan committed
558 559
	@echo Unit tests must be enabled to make the utiltest target.
endif
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574

##
## 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
575
exampletest exampletest-no-data-check: examples
576
	$(qexec)$(SRC_PATH_BARE)/test/examples.sh \
577
		--test-data-path $(LIBAOM_TEST_DATA_PATH) \
578
		--bin-path $(EXAMPLES_BIN_PATH)
579
exampletest: testdata
580
else
581
exampletest exampletest-no-data-check:
582 583
	@echo Unit tests must be enabled to make the exampletest target.
endif