+.INTERMEDIATE: vot2016.zip
+.SECONDARY: vot2016.zip
+vot2016.zip:
+ wget --progress=dot:giga -O $@ http://data.votchallenge.net/vot2016/vot2016.zip
+
+###################
+# Ninja generator #
+###################
+
+# Building all $(BUILDS) with make is slow, even when run with in
+# parallel (make -j). The target below generates build.ninja file that
+# compiles all variants in the same ways as this makefile, but faster.
+# The down side is that the build needs about 10 GB of memory.
+
+
+# Define echo depending on whether make supports the $(file) function.
+$(file >.test.file)
+ifneq ($(wildcard .test.file),)
+ echo = $(file $(1),$(2))
+else
+ define nl
+
+
+ endef
+ echo = echo $(1) '$(subst $(nl),\n,$(subst \,\\,$(2)))';
+endif
+
+# Ninja generator - to have faster parallel builds and tests
+.PHONY: build.ninja
+
+build.ninja:: $(MAKEFILE_LIST)
+ @echo "Generating $@"
+ @$(call echo,>$@,$(ninja-rule))
+ @$(foreach build,$(BUILDS),\
+ $(call echo,>>$@,$(call ninja-build,$(build),$(CMAKE_OTPS_$(build)))))
+ @$(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),\
+ $(call echo,>>$@,$(call ninja-testcase,$(build),$(seq),$(f)))$(nl))))
+ @$(call echo,>>$@,build test: PRINT_RESULTS $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))) | print-test-results)
+ @$(foreach build,$(BUILDS),$(call echo,>>$@,build test-$(build): PRINT_RESULTS $(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f)))) | print-test-results))
+ @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build test-$(seq): PRINT_RESULTS $(foreach build,$(BUILDS),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f)))) | print-test-results))
+ @$(call echo,>>$@,build plot: PLOT_RESULTS $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))) | graphGen.sh)
+ @$(foreach build,$(BUILDS),$(call echo,>>$@,build plot-$(build): PLOT_RESULTS $(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f)))) | graphGen.sh))
+ @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build plot-$(seq): PLOT_RESULTS $(foreach build,$(BUILDS),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f)))) | graphGen.sh))
+ @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build vot2016/$(seq): MAKE))
+
+ninja-test = build-$(1)/kcf_vot-$(2)-$(3).log
+
+define ninja-rule
+rule REGENERATE
+ command = MAKEFLAGS='$(MAKEFLAGS)' $(MAKE) $$out
+ description = Regenerating $$out
+ generator = 1
+rule CMAKE
+ command = cd $$subdir && cmake -G Ninja $(CMAKE_OPTS) $$opts ..
+rule NINJA
+ # Absolute path in -C allows Emacs to properly jump to error message locations
+ command = ninja -C $(CURDIR)/$$subdir
+ restat = 1
+rule TEST_SEQ
+ # Errors are ignored - they will be reported by PRINT_RESULTS
+ command = build-$$build/kcf_vot $$flags $$seq $(if $(TRAVIS),2>&1) >$$out $(if $(TRAVIS),| grep -v libdc1394); true
+rule PRINT_RESULTS
+ description = Print results
+ command = ./wvtool -w120 -v run ./print-test-results $$in
+rule PLOT_RESULTS
+ description = Plot results
+ command = ./graphGen.sh -f -s $$in
+rule MAKE
+ command = make $$out
+ pool = make
+pool make
+ depth = 1
+rule CLEAN
+# command = /usr/bin/ninja -t clean -r NINJA
+ description = Cleaning all built files...
+ command = rm -rf $(BUILDS:%=build-%)
+build clean: CLEAN
+build build.ninja: REGENERATE $(MAKEFILE_LIST)