1##
2##  Copyright (c) 2016 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# List of tools to build.
12TOOLS-yes            += tiny_ssim.c
13tiny_ssim.SRCS       += vpx/vpx_integer.h y4minput.c y4minput.h \
14                        vpx/vpx_codec.h vpx/src/vpx_image.c
15tiny_ssim.SRCS       += vpx_mem/vpx_mem.c vpx_mem/vpx_mem.h
16tiny_ssim.SRCS       += vpx_dsp/ssim.h vpx_scale/yv12config.h
17tiny_ssim.SRCS       += vpx_ports/mem.h vpx_ports/mem.h
18tiny_ssim.SRCS       += vpx_mem/include/vpx_mem_intrnl.h
19tiny_ssim.GUID        = 3afa9b05-940b-4d68-b5aa-55157d8ed7b4
20tiny_ssim.DESCRIPTION = Generate SSIM/PSNR from raw .yuv files
21
22#
23# End of specified files. The rest of the build rules should happen
24# automagically from here.
25#
26
27
28# Expand list of selected tools to build (as specified above)
29TOOLS           = $(addprefix tools/,$(call enabled,TOOLS))
30ALL_SRCS        = $(foreach ex,$(TOOLS),$($(notdir $(ex:.c=)).SRCS))
31CFLAGS += -I../include
32
33ifneq ($(CONFIG_CODEC_SRCS), yes)
34  CFLAGS += -I../include/vpx
35endif
36
37# Expand all tools sources into a variable containing all sources
38# for that tools (not just them main one specified in TOOLS)
39# and add this file to the list (for MSVS workspace generation)
40$(foreach ex,$(TOOLS),$(eval $(notdir $(ex:.c=)).SRCS += $(ex) tools.mk))
41
42
43# Create build/install dependencies for all tools. The common case
44# is handled here. The MSVS case is handled below.
45NOT_MSVS = $(if $(CONFIG_MSVS),,yes)
46DIST-BINS-$(NOT_MSVS)      += $(addprefix bin/,$(TOOLS:.c=$(EXE_SFX)))
47DIST-SRCS-yes              += $(ALL_SRCS)
48OBJS-$(NOT_MSVS)           += $(call objs,$(ALL_SRCS))
49BINS-$(NOT_MSVS)           += $(addprefix $(BUILD_PFX),$(TOOLS:.c=$(EXE_SFX)))
50
51# Instantiate linker template for all tools.
52$(foreach bin,$(BINS-yes),\
53    $(eval $(bin):)\
54    $(eval $(call linker_template,$(bin),\
55        $(call objs,$($(notdir $(bin:$(EXE_SFX)=)).SRCS)) -lm)))
56
57# The following pairs define a mapping of locations in the distribution
58# tree to locations in the source/build trees.
59INSTALL_MAPS += src/%.c   %.c
60INSTALL_MAPS += src/%     $(SRC_PATH_BARE)/%
61INSTALL_MAPS += bin/%     %
62INSTALL_MAPS += %         %
63
64
65# Build Visual Studio Projects. We use a template here to instantiate
66# explicit rules rather than using an implicit rule because we want to
67# leverage make's VPATH searching rather than specifying the paths on
68# each file in TOOLS. This has the unfortunate side effect that
69# touching the source files trigger a rebuild of the project files
70# even though there is no real dependency there (the dependency is on
71# the makefiles). We may want to revisit this.
72define vcproj_template
73$(1): $($(1:.$(VCPROJ_SFX)=).SRCS) vpx.$(VCPROJ_SFX)
74	$(if $(quiet),@echo "    [vcproj] $$@")
75	$(qexec)$$(GEN_VCPROJ)\
76            --exe\
77            --target=$$(TOOLCHAIN)\
78            --name=$$(@:.$(VCPROJ_SFX)=)\
79            --ver=$$(CONFIG_VS_VERSION)\
80            --proj-guid=$$($$(@:.$(VCPROJ_SFX)=).GUID)\
81            --src-path-bare="$(SRC_PATH_BARE)" \
82            --as=$$(AS) \
83            $$(if $$(CONFIG_STATIC_MSVCRT),--static-crt) \
84            --out=$$@ $$(INTERNAL_CFLAGS) $$(CFLAGS) \
85            $$(INTERNAL_LDFLAGS) $$(LDFLAGS) $$^
86endef
87TOOLS_BASENAME := $(notdir $(TOOLS))
88PROJECTS-$(CONFIG_MSVS) += $(TOOLS_BASENAME:.c=.$(VCPROJ_SFX))
89INSTALL-BINS-$(CONFIG_MSVS) += $(foreach p,$(VS_PLATFORMS),\
90                               $(addprefix bin/$(p)/,$(TOOLS_BASENAME:.c=.exe)))
91$(foreach proj,$(call enabled,PROJECTS),\
92    $(eval $(call vcproj_template,$(proj))))
93
94#
95# Documentation Rules
96#
97%.dox: %.c
98	@echo "    [DOXY] $@"
99	@mkdir -p $(dir $@)
100	@echo "/*!\page tools_$(@F:.dox=) $(@F:.dox=)" > $@
101	@echo "   \includelineno $(<F)" >> $@
102	@echo "*/" >> $@
103
104tools.dox: tools.mk
105	@echo "    [DOXY] $@"
106	@echo "/*!\page tools Tools" > $@
107	@echo "    This SDK includes a number of tools/utilities."\
108	      "The following tools are included: ">>$@
109	@$(foreach ex,$(sort $(notdir $(TOOLS:.c=))),\
110	   echo "     - \subpage tools_$(ex) $($(ex).DESCRIPTION)" >> $@;)
111	@echo "*/" >> $@
112
113CLEAN-OBJS += tools.doxy tools.dox $(TOOLS:.c=.dox)
114DOCS-yes += tools.doxy tools.dox
115tools.doxy: tools.dox $(TOOLS:.c=.dox)
116	@echo "INPUT += $^" > $@
117