]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - Makefile
Allow generating build.ninja also with GNU make 3.81
[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 book
5 TESTFLAGS = default fit128
6
7 all: $(foreach build,$(BUILDS),build-$(build)/kcf_vot)
8
9 CMAKE_OPTS += -G Ninja
10
11 ## Useful setting - uncomment and modify as needed
12 # CMAKE_OPTS += -DOpenCV_DIR=~/opt/opencv-2.4/share/OpenCV
13 # CMAKE_OPTS += -DCUDA_VERBOSE_BUILD=ON -DCUDA_NVCC_FLAGS="--verbose;--save-temps"
14 # export CC=gcc-5
15 # export CXX=g++-5
16 # export CUDA_BIN_PATH=/usr/local/cuda-9.0
17
18 CMAKE_OTPS_opencvfft-st      = -DFFT=OpenCV
19 CMAKE_OTPS_opencvfft-async   = -DFFT=OpenCV -DASYNC=ON
20 CMAKE_OTPS_opencvfft-openmp  = -DFFT=OpenCV -DOPENMP=ON
21 CMAKE_OTPS_fftw              = -DFFT=fftw
22 CMAKE_OTPS_fftw-openmp       = -DFFT=fftw -DOPENMP=ON
23 CMAKE_OTPS_fftw-async        = -DFFT=fftw -DASYNC=ON
24 CMAKE_OTPS_fftw-big          = -DFFT=fftw -DBIG_BATCH=ON
25 CMAKE_OTPS_fftw-big-openmp   = -DFFT=fftw -DBIG_BATCH=ON -DOPENMP=ON
26 CMAKE_OTPS_cufftw            = -DFFT=cuFFTW
27 CMAKE_OTPS_cufftw-big        = -DFFT=cuFFTW -DBIG_BATCH=ON
28 CMAKE_OTPS_cufftw-big-openmp = -DFFT=cuFFTW -DBIG_BATCH=ON -DOPENMP=ON
29 CMAKE_OTPS_cufft             = -DFFT=cuFFT
30 CMAKE_OTPS_cufft-openmp      = -DFFT=cuFFT -DOPENMP=ON
31 CMAKE_OTPS_cufft-big         = -DFFT=cuFFT -DBIG_BATCH=ON
32 CMAKE_OTPS_cufft-big-openmp  = -DFFT=cuFFT -DBIG_BATCH=ON -DOPENMP=ON
33
34 .SECONDARY: $(BUILDS:%=build-%/build.ninja)
35
36 build-%/build.ninja:
37         @echo '############################################################'
38         mkdir -p $(@D)
39         cd $(@D) && cmake $(CMAKE_OPTS) $(CMAKE_OTPS_$*) ..
40
41 .PHONY: FORCE
42 build-%/kcf_vot: build-%/build.ninja $(shell git ls-files)
43         @echo '############################################################'
44         cmake --build $(@D)
45
46 $(BUILDS): %: build-%/kcf_vot
47
48 clean:
49         rm -rf $(BUILDS:%=build-%)
50
51 ##########################
52 ### Tests
53 ##########################
54
55 print-test-results = grep ^Average $(1)|sed -E -e "s|build-(.*)/kcf_vot-(.*).log:|\2;\1;|"|sort|column -t -s";"
56
57 test: $(BUILDS:%=test-%)
58         @echo; echo "Summary test results:"
59         @$(call print-test-results,$(foreach build,$(BUILDS),\
60                                    $(foreach seq,$(TESTSEQ),\
61                                    $(foreach f,$(TESTFLAGS),build-$(build)/kcf_vot-$(seq)-$(f).log))))
62
63 $(BUILDS:%=test-%): test-%:
64         @$(call print-test-results,$(foreach seq,$(TESTSEQ),\
65                                    $(foreach f,$(TESTFLAGS),build-$*/kcf_vot-$(seq)-$(f).log)))
66
67 # Usage: testcase <build> <seq>
68 define testcase
69 test-$(1): test-$(1)-$(2)
70 test-$(1)-$(2): $(foreach f,$(TESTFLAGS),build-$(1)/kcf_vot-$(2)-$(f).log)
71 $(foreach f,$(TESTFLAGS),build-$(1)/kcf_vot-$(2)-$(f).log): build-$(1)/kcf_vot $$(filter-out %/output.txt,$$(wildcard vot2016/$(2)/*)) | vot2016/$(2)
72         $$< $$(if $$(@:%fit128.log=),,--fit=128) vot2016/$(2) > $$@
73         $(if $(TRAVIS),,cat $$@)
74 endef
75
76 $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(eval $(call testcase,$(build),$(seq)))))
77
78 vot2016 $(TESTSEQ:%=vot2016/%): vot2016.zip
79         unzip -d vot2016 -q $^
80         for i in $$(ls -d vot2016/*/); do ( echo Creating $${i}images.txt; cd $$i; ls *.jpg > images.txt ); done
81
82 .INTERMEDIATE: vot2016.zip
83 .SECONDARY:    vot2016.zip
84 vot2016.zip:
85         wget http://data.votchallenge.net/vot2016/vot2016.zip
86
87 ###################
88 # Ninja generator #
89 ###################
90
91 # Building all $(BUILDS) with make is slow, even when run with in
92 # parallel (make -j). The target below generates build.ninja file that
93 # compiles all variants in the same ways as this makefile, but faster.
94 # The down side is that the build needs about 10 GB of memory.
95
96 ninja: build.ninja
97         ninja
98
99 define nl
100
101
102 endef
103
104 define echo
105 echo $(1) '$(subst $(nl),\n,$(subst \,\\,$(2)))';
106 endef
107
108 # Ninja generator - to have faster parallel builds and tests
109 .PHONY: build.ninja
110 build.ninja:
111         @$(call echo,>$@,$(ninja-rule))
112         @$(foreach build,$(BUILDS),\
113                 $(call echo,>>$@,$(call ninja-build,$(build),$(CMAKE_OTPS_$(build)))))
114         @$(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),\
115                 $(call echo,>>$@,$(call ninja-testcase,$(build),$(seq),$(f)))$(nl))))
116         @$(call echo,>>$@,build test: print_results $(foreach build,$(BUILDS),$(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
117         @$(foreach build,$(BUILDS),$(call echo,>>$@,build test-$(build): print_results $(foreach seq,$(TESTSEQ),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
118         @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build test-$(seq): print_results $(foreach build,$(BUILDS),$(foreach f,$(TESTFLAGS),$(call ninja-test,$(build),$(seq),$(f))))))
119         @$(foreach seq,$(TESTSEQ),$(call echo,>>$@,build vot2016/$(seq): make))
120
121
122 define ninja-rule
123 rule cmake
124   command = cd $$$$(dirname $$out) && cmake $(CMAKE_OPTS) $$opts ..
125   description = CMake $$out
126 rule ninja
127   # Absolute path in -C allows Emacs to properly jump to error message locations
128   command = ninja -C `realpath $$$$(dirname $$out)`
129   description = Ninja $$out
130 rule test_seq
131   command = build-$$build/kcf_vot $$flags $$seq > $$out
132 rule print_results
133   description = Print results
134   command = $(call print-test-results,$$in)
135 rule make
136   command = make $$out
137 endef
138
139 define ninja-build
140 build build-$(1)/build.ninja: cmake
141   opts = $(2)
142 build build-$(1)/kcf_vot: ninja build-$(1)/build.ninja build.ninja
143 default build-$(1)/kcf_vot
144 endef
145
146 ninja-test = build-$(1)/kcf_vot-$(2)-$(3).log
147
148 # Usage: ninja-testcase <build> <seq> <flags>
149 define ninja-testcase
150 build build-$(1)/kcf_vot-$(2)-$(3).log: test_seq build-$(1)/kcf_vot $(filter-out %/output.txt,$(wildcard vot2016/$(2)/*)) || vot2016/$(2)
151   build = $(1)
152   seq = vot2016/$(2)
153   flags = $(if $(3:fit128=),,--fit=128)
154 endef