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