]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - Makefile
Allow compiling all variants with ninja
[hercules2020/kcf.git] / Makefile
1 # Makefile to build all the available variants
2
3 BUILDS = opencvfft-st opencvfft-async opencvfft-openmp fftw fftw-async fftw-openmp fftw-big fftw-big-openmp cufftw cufftw-big cufftw-big-openmp cufft cufft-openmp cufft-big cufft-big-openmp
4 TESTSEQ = bag ball1 car1
5 TESTFLAGS = default fit128
6
7 all: $(foreach build,$(BUILDS),build-$(build)/kcf_vot)
8
9 CMAKE_OPTS += -G Ninja
10 #CMAKE_OPTS += -DOpenCV_DIR=~/opt/opencv-2.4/share/OpenCV
11
12 CMAKE_OTPS_opencvfft-st      = -DFFT=OpenCV
13 CMAKE_OTPS_opencvfft-async   = -DFFT=OpenCV -DASYNC=ON
14 CMAKE_OTPS_opencvfft-openmp  = -DFFT=OpenCV -DOPENMP=ON
15 CMAKE_OTPS_fftw              = -DFFT=fftw
16 CMAKE_OTPS_fftw-openmp       = -DFFT=fftw -DOPENMP=ON
17 CMAKE_OTPS_fftw-async        = -DFFT=fftw -DASYNC=ON
18 CMAKE_OTPS_fftw-big          = -DFFT=fftw -DBIG_BATCH=ON
19 CMAKE_OTPS_fftw-big-openmp   = -DFFT=fftw -DBIG_BATCH=ON -DOPENMP=ON
20 CMAKE_OTPS_cufftw            = -DFFT=cuFFTW
21 CMAKE_OTPS_cufftw-big        = -DFFT=cuFFTW -DBIG_BATCH=ON
22 CMAKE_OTPS_cufftw-big-openmp = -DFFT=cuFFTW -DBIG_BATCH=ON -DOPENMP=ON
23 CMAKE_OTPS_cufft             = -DFFT=cuFFT
24 CMAKE_OTPS_cufft-openmp      = -DFFT=cuFFT -DOPENMP=ON
25 CMAKE_OTPS_cufft-big         = -DFFT=cuFFT -DBIG_BATCH=ON
26 CMAKE_OTPS_cufft-big-openmp  = -DFFT=cuFFT -DBIG_BATCH=ON -DOPENMP=ON
27
28 .SECONDARY: $(BUILDS:%=build-%/build.ninja)
29
30 build-%/build.ninja:
31         @echo '############################################################'
32         mkdir -p $(@D)
33         cd $(@D) && cmake $(CMAKE_OPTS) $(CMAKE_OTPS_$*) ..
34
35 .PHONY: FORCE
36 build-%/kcf_vot: build-%/build.ninja $(shell git ls-files)
37         @echo '############################################################'
38         cmake --build $(@D)
39
40 $(BUILDS): %: build-%/kcf_vot
41
42 clean:
43         rm -rf $(BUILDS:%=build-%)
44
45 ##########################
46 ### Tests
47 ##########################
48
49 print-test-results = grep ^Average $(1)|sed -E -e 's|build-(.*)/kcf_vot-(.*).log:|\2;\1;|'|sort|column -t -s';'
50
51 test: $(BUILDS:%=test-%)
52         @echo; echo "Summary test results:"
53         @$(call print-test-results,$(foreach build,$(BUILDS),\
54                                    $(foreach seq,$(TESTSEQ),\
55                                    $(foreach f,$(TESTFLAGS),build-$(build)/kcf_vot-$(seq)-$(f).log))))
56
57 $(BUILDS:%=test-%): test-%:
58         @$(call print-test-results,$(foreach seq,$(TESTSEQ),\
59                                    $(foreach f,$(TESTFLAGS),build-$*/kcf_vot-$(seq)-$(f).log)))
60
61 # Usage: testcase <build> <seq>
62 define testcase
63 test-$(1): test-$(1)-$(2)
64 test-$(1)-$(2): $(foreach f,$(TESTFLAGS),build-$(1)/kcf_vot-$(2)-$(f).log)
65 $(foreach f,$(TESTFLAGS),build-$(1)/kcf_vot-$(2)-$(f).log): build-$(1)/kcf_vot $$(filter-out %/output.txt,$$(wildcard vot2016/$(2)/*)) | vot2016/$(2)
66         $$< $$(if $$(@:%fit128.log=),,--fit=128) vot2016/$(2) > $$@
67 #       cat $$@
68 endef
69
70 $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(eval $(call testcase,$(build),$(seq)))))
71
72 vot2016 $(TESTSEQ:%=vot2016/%): vot2016.zip
73         unzip -d vot2016 -q $^
74         for i in $$(ls -d vot2016/*/); do ( echo Creating $${i}images.txt; cd $$i; ls *.jpg > images.txt ); done
75
76 .INTERMEDIATE: vot2016.zip
77 .SECONDARY:    vot2016.zip
78 vot2016.zip:
79         wget http://data.votchallenge.net/vot2016/vot2016.zip
80
81 ###################
82 # Ninja generator #
83 ###################
84
85 # Building all $(BUILDS) with make is slow, even when run with in
86 # parallel (make -j). The target below generates build.ninja file that
87 # compiles all variants in the same ways as this makefile, but faster.
88 # The down side is that the build needs about 10 GB of memory.
89
90 ninja: build.ninja
91         ninja
92
93 # Ninja generator - to have faster parallel builds
94 .PHONY: build.ninja
95 build.ninja:
96         $(file >$@,$(ninja-rule))
97         $(foreach build,$(BUILDS),$(file >>$@,$(call ninja-build,$(build),$(CMAKE_OTPS_$(build)))))
98
99 define ninja-rule
100 rule cmake
101   command = cd $$$$(dirname $$out) && cmake $(CMAKE_OPTS) $$opts ..
102   description = CMake $$out
103 rule ninja
104   # Absolute path in -C allows Emacs to properly jump to error message locations
105   command = ninja -C `realpath $$$$(dirname $$out)`
106   description = Ninja $$out
107 endef
108
109 define ninja-build
110 build build-$(1)/build.ninja: cmake
111   opts = $(2)
112 build build-$(1)/kcf_vot: ninja build-$(1)/build.ninja build.ninja
113 endef