]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - Makefile
WIP-tests
[jacinto-ai/caffe-jacinto.git] / Makefile
1 PROJECT := caffe
3 CONFIG_FILE := Makefile.config
4 # Explicitly check for the config file, otherwise make -k will proceed anyway.
5 ifeq ($(wildcard $(CONFIG_FILE)),)
6 $(error $(CONFIG_FILE) not found. See $(CONFIG_FILE).example.)
7 endif
8 include $(CONFIG_FILE)
10 BUILD_DIR_LINK := $(BUILD_DIR)
11 ifeq ($(RELEASE_BUILD_DIR),)
12         RELEASE_BUILD_DIR := .$(BUILD_DIR)_release
13 endif
14 ifeq ($(DEBUG_BUILD_DIR),)
15         DEBUG_BUILD_DIR := .$(BUILD_DIR)_debug
16 endif
18 DEBUG ?= 0
19 ifeq ($(DEBUG), 1)
20         BUILD_DIR := $(DEBUG_BUILD_DIR)
21         OTHER_BUILD_DIR := $(RELEASE_BUILD_DIR)
22 else
23         BUILD_DIR := $(RELEASE_BUILD_DIR)
24         OTHER_BUILD_DIR := $(DEBUG_BUILD_DIR)
25 endif
27 THIRDPARTY_DIR := ./3rdparty
29 # All of the directories containing code.
30 SRC_DIRS := $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \
31         \( -name '*.cpp' -o -name '*.proto' \) | grep -q ." \; -print)
33 # The target shared library name
34 LIBRARY_NAME := $(PROJECT)$(LIBRARY_NAME_SUFFIX)
35 LIB_BUILD_DIR := $(BUILD_DIR)/lib
36 STATIC_NAME := $(LIB_BUILD_DIR)/lib$(LIBRARY_NAME).a
37 DYNAMIC_VERSION_MAJOR           := 0
38 DYNAMIC_VERSION_MINOR           := 16
39 DYNAMIC_VERSION_REVISION        := 3
40 DYNAMIC_NAME_SHORT := lib$(LIBRARY_NAME).so
41 DYNAMIC_SONAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR)
42 DYNAMIC_VERSIONED_NAME_SHORT := $(DYNAMIC_SONAME_SHORT).$(DYNAMIC_VERSION_REVISION)
43 DYNAMIC_NAME := $(LIB_BUILD_DIR)/$(DYNAMIC_VERSIONED_NAME_SHORT)
44 COMMON_FLAGS += -DCAFFE_VERSION=$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)
45 # NVCaffe requires C++ 11
46 COMMON_FLAGS += -std=c++11
47 COMMON_FLAGS += -DCUDA_NO_HALF
49 ##############################
50 # Get all source files
51 ##############################
52 # CXX_SRCS are the source files excluding the test ones.
53 CXX_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cpp" -name "*.cpp")
54 # CU_SRCS are the cuda source files
55 CU_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cu" -name "*.cu")
56 # TEST_SRCS are the test source files
57 TEST_MAIN_SRC := src/$(PROJECT)/test/test_caffe_main.cpp
58 TEST_SRCS := $(shell find src/$(PROJECT) -name "test_*.cpp")
59 TEST_SRCS := $(filter-out $(TEST_MAIN_SRC), $(TEST_SRCS))
60 TEST_CU_SRCS := $(shell find src/$(PROJECT) -name "test_*.cu")
61 GTEST_SRC := src/gtest/gtest-all.cpp
62 # TOOL_SRCS are the source files for the tool binaries
63 TOOL_SRCS := $(shell find tools -name "*.cpp")
64 # EXAMPLE_SRCS are the source files for the example binaries
65 EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
66 # BUILD_INCLUDE_DIR contains any generated header files we want to include.
67 BUILD_INCLUDE_DIR := $(BUILD_DIR)/src
68 # PROTO_SRCS are the protocol buffer definitions
69 PROTO_SRC_DIR := src/$(PROJECT)/proto
70 PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto)
71 # PROTO_BUILD_DIR will contain the .cc and obj files generated from
72 # PROTO_SRCS; PROTO_BUILD_INCLUDE_DIR will contain the .h header files
73 PROTO_BUILD_DIR := $(BUILD_DIR)/$(PROTO_SRC_DIR)
74 PROTO_BUILD_INCLUDE_DIR := $(BUILD_INCLUDE_DIR)/$(PROJECT)/proto
75 # NONGEN_CXX_SRCS includes all source/header files except those generated
76 # automatically (e.g., by proto).
77 NONGEN_CXX_SRCS := $(shell find \
78         src/$(PROJECT) \
79         include/$(PROJECT) \
80         python/$(PROJECT) \
81         matlab/+$(PROJECT)/private \
82         examples \
83         tools \
84         -name "*.cpp" -or -name "*.hpp" -or -name "*.cu" -or -name "*.cuh")
85 LINT_SCRIPT := scripts/cpp_lint.py
86 LINT_OUTPUT_DIR := $(BUILD_DIR)/.lint
87 LINT_EXT := lint.txt
88 LINT_OUTPUTS := $(addsuffix .$(LINT_EXT), $(addprefix $(LINT_OUTPUT_DIR)/, $(NONGEN_CXX_SRCS)))
89 EMPTY_LINT_REPORT := $(BUILD_DIR)/.$(LINT_EXT)
90 NONEMPTY_LINT_REPORT := $(BUILD_DIR)/$(LINT_EXT)
91 # PY$(PROJECT)_SRC is the python wrapper for $(PROJECT)
92 PY$(PROJECT)_SRC := python/$(PROJECT)/_$(PROJECT).cpp
93 PY$(PROJECT)_SO := python/$(PROJECT)/_$(PROJECT).so
94 PY$(PROJECT)_HXX := include/$(PROJECT)/layers/python_layer.hpp
95 # MAT$(PROJECT)_SRC is the mex entrance point of matlab package for $(PROJECT)
96 MAT$(PROJECT)_SRC := matlab/+$(PROJECT)/private/$(PROJECT)_.cpp
97 ifneq ($(MATLAB_DIR),)
98         MAT_SO_EXT := $(shell $(MATLAB_DIR)/bin/mexext)
99 endif
100 MAT$(PROJECT)_SO := matlab/+$(PROJECT)/private/$(PROJECT)_.$(MAT_SO_EXT)
102 ##############################
103 # Derive generated files
104 ##############################
105 # The generated files for protocol buffers
106 PROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \
107                 $(notdir ${PROTO_SRCS:.proto=.pb.h}))
108 PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \
109                 $(notdir ${PROTO_SRCS:.proto=.pb.h}))
110 PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc})
111 PY_PROTO_BUILD_DIR := python/$(PROJECT)/proto
112 PY_PROTO_INIT := python/$(PROJECT)/proto/__init__.py
113 PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py}, \
114                 $(PY_PROTO_BUILD_DIR)/$(notdir $(file)))
115 # The objects corresponding to the source files
116 # These objects will be linked into the final shared library, so we
117 # exclude the tool, example, and test objects.
118 CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o})
119 CU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o})
120 PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
121 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
122 # tool, example, and test objects
123 TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o})
124 TOOL_BUILD_DIR := $(BUILD_DIR)/tools
125 TEST_CXX_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT)/test
126 TEST_CU_BUILD_DIR := $(BUILD_DIR)/cuda/src/$(PROJECT)/test
127 TEST_CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o})
128 TEST_CU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o})
129 TEST_OBJS := $(TEST_CXX_OBJS) $(TEST_CU_OBJS)
130 GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o})
131 EXAMPLE_OBJS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o})
132 # Output files for automatic dependency generation
133 DEPS := ${CXX_OBJS:.o=.d} ${CU_OBJS:.o=.d} ${TEST_CXX_OBJS:.o=.d} \
134         ${TEST_CU_OBJS:.o=.d} $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}
135 # tool, example, and test bins
136 TOOL_BINS := ${TOOL_OBJS:.o=.bin}
137 EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin}
138 # symlinks to tool bins without the ".bin" extension
139 TOOL_BIN_LINKS := ${TOOL_BINS:.bin=}
140 # Put the test binaries in build/test for convenience.
141 TEST_BIN_DIR := $(BUILD_DIR)/test
142 TEST_CU_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \
143                 $(foreach obj,$(TEST_CU_OBJS),$(basename $(notdir $(obj))))))
144 TEST_CXX_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \
145                 $(foreach obj,$(TEST_CXX_OBJS),$(basename $(notdir $(obj))))))
146 TEST_BINS := $(TEST_CXX_BINS) $(TEST_CU_BINS)
147 # TEST_ALL_BIN is the test binary that links caffe dynamically.
148 TEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin
150 ##############################
151 # Derive compiler warning dump locations
152 ##############################
153 WARNS_EXT := warnings.txt
154 CXX_WARNS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o.$(WARNS_EXT)})
155 CU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o.$(WARNS_EXT)})
156 TOOL_WARNS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o.$(WARNS_EXT)})
157 EXAMPLE_WARNS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o.$(WARNS_EXT)})
158 TEST_WARNS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o.$(WARNS_EXT)})
159 TEST_CU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o.$(WARNS_EXT)})
160 ALL_CXX_WARNS := $(CXX_WARNS) $(TOOL_WARNS) $(EXAMPLE_WARNS) $(TEST_WARNS)
161 ALL_CU_WARNS := $(CU_WARNS) $(TEST_CU_WARNS)
162 ALL_WARNS := $(ALL_CXX_WARNS) $(ALL_CU_WARNS)
164 EMPTY_WARN_REPORT := $(BUILD_DIR)/.$(WARNS_EXT)
165 NONEMPTY_WARN_REPORT := $(BUILD_DIR)/$(WARNS_EXT)
167 ##############################
168 # Derive include and lib directories
169 ##############################
170 ifeq ($(shell uname -m),aarch64)
171     TEGRA=1
172     NO_NVML=1
173 endif
175 CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
177 CUDA_LIB_DIR :=
178 # add <cuda>/lib64 only if it exists
179 ifneq ("$(wildcard $(CUDA_DIR)/lib64)","")
180         CUDA_LIB_DIR += $(CUDA_DIR)/lib64
181         CUDA_LIB_DIR += /usr/lib/nvidia-384 /usr/lib/nvidia-381 /usr/lib/nvidia-375 /usr/lib/nvidia-367 /usr/lib/nvidia-361 /usr/lib/nvidia-352
182 endif
183 CUDA_LIB_DIR += $(CUDA_DIR)/lib
185 INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include $(THIRDPARTY_DIR)
186 ifneq ($(CPU_ONLY), 1)
187         INCLUDE_DIRS += $(CUDA_INCLUDE_DIR)
188         LIBRARY_DIRS += $(CUDA_LIB_DIR)
189         LIBRARIES := cudart cublas curand
190 ifneq ($(NO_NVML), 1)
191         LIBRARIES += nvidia-ml
192 endif
193 endif
195 LIBRARIES += boost_system glog gflags protobuf boost_filesystem m turbojpeg
196 ifeq ($(TEGRA), 1)
197     LIBRARIES += hdf5_serial_hl hdf5_serial
198 else
199     LIBRARIES += hdf5_hl hdf5
200 endif
202 # handle IO dependencies
203 USE_LEVELDB ?= 1
204 USE_LMDB ?= 1
205 USE_OPENCV ?= 1
207 ifeq ($(USE_LEVELDB), 1)
208         LIBRARIES += leveldb snappy
209 endif
210 ifeq ($(USE_LMDB), 1)
211         LIBRARIES += lmdb
212 endif
213 ifeq ($(USE_OPENCV), 1)
214         LIBRARIES += opencv_core opencv_highgui opencv_imgproc
216         ifeq ($(OPENCV_VERSION), 3)
217                 LIBRARIES += opencv_imgcodecs
218         endif
219                 
220 endif
221 PYTHON_LIBRARIES ?= boost_python python2.7
222 WARNINGS := -Wall -Wno-sign-compare
224 ##############################
225 # Set build directories
226 ##############################
228 DISTRIBUTE_DIR ?= distribute
229 DISTRIBUTE_SUBDIRS := $(DISTRIBUTE_DIR)/bin $(DISTRIBUTE_DIR)/lib
230 DIST_ALIASES := dist
231 ifneq ($(strip $(DISTRIBUTE_DIR)),distribute)
232                 DIST_ALIASES += distribute
233 endif
235 ALL_BUILD_DIRS := $(sort $(BUILD_DIR) $(addprefix $(BUILD_DIR)/, $(SRC_DIRS)) \
236         $(addprefix $(BUILD_DIR)/cuda/, $(SRC_DIRS)) \
237         $(LIB_BUILD_DIR) $(TEST_BIN_DIR) $(PY_PROTO_BUILD_DIR) $(LINT_OUTPUT_DIR) \
238         $(DISTRIBUTE_SUBDIRS) $(PROTO_BUILD_INCLUDE_DIR))
240 ##############################
241 # Set directory for Doxygen-generated documentation
242 ##############################
243 DOXYGEN_CONFIG_FILE ?= ./.Doxyfile
244 # should be the same as OUTPUT_DIRECTORY in the .Doxyfile
245 DOXYGEN_OUTPUT_DIR ?= ./doxygen
246 DOXYGEN_COMMAND ?= doxygen
247 # All the files that might have Doxygen documentation.
248 DOXYGEN_SOURCES := $(shell find \
249         src/$(PROJECT) \
250         include/$(PROJECT) \
251         python/ \
252         matlab/ \
253         examples \
254         tools \
255         -name "*.cpp" -or -name "*.hpp" -or -name "*.cu" -or -name "*.cuh" -or \
256         -name "*.py" -or -name "*.m")
257 DOXYGEN_SOURCES += $(DOXYGEN_CONFIG_FILE)
260 ##############################
261 # Configure build
262 ##############################
264 # Determine platform
265 UNAME := $(shell uname -s)
266 ifeq ($(UNAME), Linux)
267         LINUX := 1
268 else ifeq ($(UNAME), Darwin)
269         OSX := 1
270         OSX_MAJOR_VERSION := $(shell sw_vers -productVersion | cut -f 1 -d .)
271         OSX_MINOR_VERSION := $(shell sw_vers -productVersion | cut -f 2 -d .)
272 endif
274 # Linux
275 ifeq ($(LINUX), 1)
276         CXX ?= /usr/bin/g++
277         GCCVERSION := $(shell $(CXX) -dumpversion | cut -f1,2 -d.)
278         # older versions of gcc are too dumb to build boost with -Wuninitalized
279         ifeq ($(shell echo | awk '{exit $(GCCVERSION) < 4.6;}'), 1)
280                 WARNINGS += -Wno-uninitialized
281         endif
282         # boost::thread is reasonably called boost_thread (compare OS X)
283         # We will also explicitly add stdc++ to the link target.
284         LIBRARIES += boost_thread stdc++
285         VERSIONFLAGS += -Wl,-soname,$(DYNAMIC_SONAME_SHORT) -Wl,-rpath,$(ORIGIN)/../lib
286 endif
288 # OS X:
289 # clang++ instead of g++
290 # libstdc++ for NVCC compatibility on OS X >= 10.9 with CUDA < 7.0
291 ifeq ($(OSX), 1)
292         CXX := /usr/bin/clang++
293         ifneq ($(CPU_ONLY), 1)
294                 CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release [0-9.]*' | grep -o '[0-9.]*')
295                 ifeq ($(shell echo | awk '{exit $(CUDA_VERSION) < 7.0;}'), 1)
296                         CXXFLAGS += -stdlib=libstdc++
297                         LINKFLAGS += -stdlib=libstdc++
298                 endif
299                 # clang throws this warning for cuda headers
300                 WARNINGS += -Wno-unneeded-internal-declaration
301                 # 10.11 strips DYLD_* env vars so link CUDA (rpath is available on 10.5+)
302                 OSX_10_OR_LATER   := $(shell [ $(OSX_MAJOR_VERSION) -ge 10 ] && echo true)
303                 OSX_10_5_OR_LATER := $(shell [ $(OSX_MINOR_VERSION) -ge 5 ] && echo true)
304                 ifeq ($(OSX_10_OR_LATER),true)
305                         ifeq ($(OSX_10_5_OR_LATER),true)
306                                 LDFLAGS += -Wl,-rpath,$(CUDA_LIB_DIR)
307                         endif
308                 endif
309         endif
310         # gtest needs to use its own tuple to not conflict with clang
311         COMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
312         # boost::thread is called boost_thread-mt to mark multithreading on OS X
313         LIBRARIES += boost_thread-mt
314         # we need to explicitly ask for the rpath to be obeyed
315         ORIGIN := @loader_path
316         VERSIONFLAGS += -Wl,-install_name,$(DYNAMIC_SONAME_SHORT) -Wl,-rpath,$(ORIGIN)/../../build/lib
317 else
318         ORIGIN := \$$ORIGIN
319 endif
321 # Custom compiler
322 ifdef CUSTOM_CXX
323         CXX := $(CUSTOM_CXX)
324 endif
326 # Static linking
327 ifneq (,$(findstring clang++,$(CXX)))
328         STATIC_LINK_COMMAND := -Wl,-force_load $(STATIC_NAME)
329 else ifneq (,$(findstring g++,$(CXX)))
330         STATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive
331 else
332   # The following line must not be indented with a tab, since we are not inside a target
333   $(error Cannot static link with the $(CXX) compiler)
334 endif
336 # Debugging
337 ifeq ($(DEBUG), 1)
338         COMMON_FLAGS += -DDEBUG -g -O0
339         NVCCFLAGS += -G
340 else
341         COMMON_FLAGS += -DNDEBUG -O2
342 endif
344 # cuDNN acceleration configuration.
345 ifeq ($(USE_CUDNN), 1)
346         ifdef CUDNN_ROOT
347                 CUDNN_DIR := $(CUDNN_ROOT)
348         endif
349         LIBRARIES += cudnn
350         INCLUDE_DIRS += $(CUDNN_DIR)/cuda/include $(CUDNN_DIR)/include $(CUDNN_DIR)
351         LIBRARY_DIRS += $(CUDNN_DIR)/cuda/lib64 $(CUDNN_DIR)/lib64 $(CUDNN_DIR)
352         COMMON_FLAGS += -DUSE_CUDNN
353 endif
355 # NCCL acceleration configuration
356 ifeq ($(USE_NCCL), 1)
357         LIBRARIES += nccl
358         COMMON_FLAGS += -DUSE_NCCL
359 endif
361 # configure IO libraries
362 ifeq ($(USE_OPENCV), 1)
363         COMMON_FLAGS += -DUSE_OPENCV
364 endif
365 ifeq ($(USE_LEVELDB), 1)
366         COMMON_FLAGS += -DUSE_LEVELDB
367 endif
368 ifeq ($(USE_LMDB), 1)
369         COMMON_FLAGS += -DUSE_LMDB
370 ifeq ($(ALLOW_LMDB_NOLOCK), 1)
371         COMMON_FLAGS += -DALLOW_LMDB_NOLOCK
372 endif
373 endif
375 # CPU-only configuration
376 ifeq ($(CPU_ONLY), 1)
377         OBJS := $(PROTO_OBJS) $(CXX_OBJS)
378         TEST_OBJS := $(TEST_CXX_OBJS)
379         TEST_BINS := $(TEST_CXX_BINS)
380         ALL_WARNS := $(ALL_CXX_WARNS)
381         TEST_FILTER := --gtest_filter="-*GPU*"
382         COMMON_FLAGS += -DCPU_ONLY
383 endif
385 ifeq ($(NO_NVML), 1)
386         COMMON_FLAGS += -DNO_NVML=1
387 endif
389 ifeq ($(TEST_FP16), 1)
390         COMMON_FLAGS += -DTEST_FP16=1
391 endif
393 # Python layer support
394 ifeq ($(WITH_PYTHON_LAYER), 1)
395         COMMON_FLAGS += -DWITH_PYTHON_LAYER
396         LIBRARIES += $(PYTHON_LIBRARIES)
397 endif
399 # BLAS configuration (default = ATLAS)
400 BLAS ?= atlas
401 ifeq ($(BLAS), mkl)
402         # MKL
403         LIBRARIES += mkl_rt
404         COMMON_FLAGS += -DUSE_MKL
405         MKLROOT ?= /opt/intel/mkl
406         BLAS_INCLUDE ?= $(MKLROOT)/include
407         BLAS_LIB ?= $(MKLROOT)/lib $(MKLROOT)/lib/intel64
408 else ifeq ($(BLAS), open)
409         # OpenBLAS
410         LIBRARIES += openblas
411 else
412         # ATLAS
413         ifeq ($(LINUX), 1)
414                 ifeq ($(BLAS), atlas)
415                         # Linux simply has cblas and atlas
416                         LIBRARIES += cblas atlas
417                 endif
418         else ifeq ($(OSX), 1)
419                 # OS X packages atlas as the vecLib framework
420                 LIBRARIES += cblas
421                 # 10.10 has accelerate while 10.9 has veclib
422                 XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep 'version' | sed 's/[^0-9]*\([0-9]\).*/\1/')
423                 XCODE_CLT_GEQ_6 := $(shell [ $(XCODE_CLT_VER) -gt 5 ] && echo 1)
424                 ifeq ($(XCODE_CLT_GEQ_6), 1)
425                         BLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/
426                         LDFLAGS += -framework Accelerate
427                 else
428                         BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
429                         LDFLAGS += -framework vecLib
430                 endif
431         endif
432 endif
433 INCLUDE_DIRS += $(BLAS_INCLUDE)
434 LIBRARY_DIRS += $(BLAS_LIB)
436 LIBRARY_DIRS += $(LIB_BUILD_DIR)
438 # Automatic dependency generation (nvcc is handled separately)
439 CXXFLAGS += -MMD -MP
441 # Complete build flags.
442 COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
443 CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
444 NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
445 # mex may invoke an older gcc that is too liberal with -Wuninitalized
446 MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized -std=c++11
447 LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
449 USE_PKG_CONFIG ?= 0
450 ifeq ($(USE_PKG_CONFIG), 1)
451         PKG_CONFIG := $(shell pkg-config opencv --libs)
452 else
453         PKG_CONFIG :=
454 endif
455 LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \
456                 $(foreach library,$(LIBRARIES),-l$(library))
457 PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))
459 # 'superclean' target recursively* deletes all files ending with an extension
460 # in $(SUPERCLEAN_EXTS) below.  This may be useful if you've built older
461 # versions of Caffe that do not place all generated files in a location known
462 # to the 'clean' target.
464 # 'supercleanlist' will list the files to be deleted by make superclean.
466 # * Recursive with the exception that symbolic links are never followed, per the
467 # default behavior of 'find'.
468 SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo
470 # Set the sub-targets of the 'everything' target.
471 EVERYTHING_TARGETS := all py$(PROJECT) test warn lint
472 # Only build matcaffe as part of "everything" if MATLAB_DIR is specified.
473 ifneq ($(MATLAB_DIR),)
474         EVERYTHING_TARGETS += mat$(PROJECT)
475 endif
477 ##############################
478 # Define build targets
479 ##############################
480 .PHONY: all lib test clean docs linecount lint lintclean tools examples $(DIST_ALIASES) \
481         py mat py$(PROJECT) mat$(PROJECT) proto runtest \
482         superclean supercleanlist supercleanfiles warn everything
484 all: lib tools examples
486 lib: $(STATIC_NAME) $(DYNAMIC_NAME)
488 everything: $(EVERYTHING_TARGETS)
490 linecount:
491         cloc --read-lang-def=$(PROJECT).cloc \
492                 src/$(PROJECT) include/$(PROJECT) tools examples \
493                 python matlab
495 lint: $(EMPTY_LINT_REPORT)
497 lintclean:
498         @ $(RM) -r $(LINT_OUTPUT_DIR) $(EMPTY_LINT_REPORT) $(NONEMPTY_LINT_REPORT)
500 docs: $(DOXYGEN_OUTPUT_DIR)
501         @ cd ./docs ; ln -sfn ../$(DOXYGEN_OUTPUT_DIR)/html doxygen
503 $(DOXYGEN_OUTPUT_DIR): $(DOXYGEN_CONFIG_FILE) $(DOXYGEN_SOURCES)
504         $(DOXYGEN_COMMAND) $(DOXYGEN_CONFIG_FILE)
506 $(EMPTY_LINT_REPORT): $(LINT_OUTPUTS) | $(BUILD_DIR)
507         @ cat $(LINT_OUTPUTS) > $@
508         @ if [ -s "$@" ]; then \
509                 cat $@; \
510                 mv $@ $(NONEMPTY_LINT_REPORT); \
511                 echo "Found one or more lint errors."; \
512                 exit 1; \
513           fi; \
514           $(RM) $(NONEMPTY_LINT_REPORT); \
515           echo "No lint errors!";
517 $(LINT_OUTPUTS): $(LINT_OUTPUT_DIR)/%.lint.txt : % $(LINT_SCRIPT) | $(LINT_OUTPUT_DIR)
518         @ mkdir -p $(dir $@)
519         @ python $(LINT_SCRIPT) --filter=-legal,-build/include,-runtime/references,-readability,-whitespace/comments $< 2>&1 \
520                 | grep -v "^Done processing " \
521                 | grep -v "^Total errors found: 0" \
522                 > $@ \
523                 || true
525 test: $(TEST_ALL_BIN) $(TEST_ALL_DYNLINK_BIN) $(TEST_BINS)
527 tools: $(TOOL_BINS) $(TOOL_BIN_LINKS)
529 examples: $(EXAMPLE_BINS)
531 py$(PROJECT): py
533 py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY)
535 $(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)
536         @ echo CXX/LD -o $@ $<
537         $(Q)$(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \
538                 -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(PYTHON_LDFLAGS) \
539                 -Wl,-rpath,$(ORIGIN)/../../build/lib
541 mat$(PROJECT): mat
543 mat: $(MAT$(PROJECT)_SO)
545 $(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME)
546         @ if [ -z "$(MATLAB_DIR)" ]; then \
547                 echo "MATLAB_DIR must be specified in $(CONFIG_FILE)" \
548                         "to build mat$(PROJECT)."; \
549                 exit 1; \
550         fi
551         @ echo MEX $<
552         $(Q)$(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) \
553                         CXX="$(CXX)" \
554                         CXXFLAGS="\$$CXXFLAGS $(MATLAB_CXXFLAGS)" \
555                         CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output $@
556         @ if [ -f "$(PROJECT)_.d" ]; then \
557                 mv -f $(PROJECT)_.d $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}; \
558         fi
560 runtest: $(TEST_ALL_BIN)
561         $(TOOL_BUILD_DIR)/caffe
562         $(TEST_ALL_BIN) $(TEST_GPUID) --gtest_shuffle $(TEST_FILTER)
564 pytest: py
565         cd python; python -m unittest discover -s caffe/test
567 mattest: mat
568         cd matlab; $(MATLAB_DIR)/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'
570 warn: $(EMPTY_WARN_REPORT)
572 $(EMPTY_WARN_REPORT): $(ALL_WARNS) | $(BUILD_DIR)
573         @ cat $(ALL_WARNS) > $@
574         @ if [ -s "$@" ]; then \
575                 cat $@; \
576                 mv $@ $(NONEMPTY_WARN_REPORT); \
577                 echo "Compiler produced one or more warnings."; \
578                 exit 1; \
579           fi; \
580           $(RM) $(NONEMPTY_WARN_REPORT); \
581           echo "No compiler warnings!";
583 $(ALL_WARNS): %.o.$(WARNS_EXT) : %.o
585 $(BUILD_DIR_LINK): $(BUILD_DIR)/.linked
587 # Create a target ".linked" in this BUILD_DIR to tell Make that the "build" link
588 # is currently correct, then delete the one in the OTHER_BUILD_DIR in case it
589 # exists and $(DEBUG) is toggled later.
590 $(BUILD_DIR)/.linked:
591         @ mkdir -p $(BUILD_DIR)
592         @ $(RM) $(OTHER_BUILD_DIR)/.linked
593         @ $(RM) -r $(BUILD_DIR_LINK)
594         @ ln -s $(BUILD_DIR) $(BUILD_DIR_LINK)
595         @ touch $@
597 $(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)
598         @ mkdir -p $@
600 $(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
601         @ echo LD -o $@
602         $(Q)$(CXX) -shared -o $@ $(OBJS) $(VERSIONFLAGS) $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_FLAGS)
603         @ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_SONAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_SONAME_SHORT)
604         @ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT);   ln -s $(DYNAMIC_SONAME_SHORT) $(DYNAMIC_NAME_SHORT)
606 $(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
607         @ echo AR -o $@
608         $(Q)ar rcs $@ $(OBJS)
610 $(BUILD_DIR)/%.o: %.cpp | $(ALL_BUILD_DIRS)
611         @ echo CXX $<
612         $(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
613                 || (cat $@.$(WARNS_EXT); exit 1)
614         @ cat $@.$(WARNS_EXT)
616 $(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \
617                 | $(PROTO_BUILD_DIR)
618         @ echo CXX $<
619         $(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
620                 || (cat $@.$(WARNS_EXT); exit 1)
621         @ cat $@.$(WARNS_EXT)
623 $(BUILD_DIR)/cuda/%.o: %.cu | $(ALL_BUILD_DIRS)
624         @ echo NVCC $<
625         $(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -M $< -o ${@:.o=.d} \
626                 -odir $(@D)
627         $(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ 2> $@.$(WARNS_EXT) \
628                 || (cat $@.$(WARNS_EXT); exit 1)
629         @ cat $@.$(WARNS_EXT)
631 $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
632                 | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
633         @ echo CXX/LD -o $@ $<
634         $(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
635                 -o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
637 $(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
638         $(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
639         @ echo LD $<
640         $(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
641                 -o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
643 $(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \
644         $(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
645         @ echo LD $<
646         $(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
647                 -o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
649 # Target for extension-less symlinks to tool binaries with extension '*.bin'.
650 $(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
651         @ $(RM) $@
652         @ ln -s $(notdir $<) $@
654 $(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)
655         @ echo CXX/LD -o $@
656         $(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
657                 -Wl,-rpath,$(ORIGIN)/../lib
659 $(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)
660         @ echo CXX/LD -o $@
661         $(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
662                 -Wl,-rpath,$(ORIGIN)/../../lib
664 proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)
666 $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \
667                 $(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR)
668         @ echo PROTOC $<
669         $(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<
671 $(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \
672                 $(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR)
673         @ echo PROTOC \(python\) $<
674         $(Q)protoc --proto_path=$(PROTO_SRC_DIR) --python_out=$(PY_PROTO_BUILD_DIR) $<
676 $(PY_PROTO_INIT): | $(PY_PROTO_BUILD_DIR)
677         touch $(PY_PROTO_INIT)
679 clean:
680         @- $(RM) -rf $(ALL_BUILD_DIRS)
681         @- $(RM) -rf $(OTHER_BUILD_DIR)
682         @- $(RM) -rf $(BUILD_DIR_LINK)
683         @- $(RM) -rf $(DISTRIBUTE_DIR)
684         @- $(RM) $(PY$(PROJECT)_SO)
685         @- $(RM) $(MAT$(PROJECT)_SO)
687 supercleanfiles:
688         $(eval SUPERCLEAN_FILES := $(strip \
689                         $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)' \
690                         -not -path './data/*'))))
692 supercleanlist: supercleanfiles
693         @ \
694         if [ -z "$(SUPERCLEAN_FILES)" ]; then \
695                 echo "No generated files found."; \
696         else \
697                 echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \
698         fi
700 superclean: clean supercleanfiles
701         @ \
702         if [ -z "$(SUPERCLEAN_FILES)" ]; then \
703                 echo "No generated files found."; \
704         else \
705                 echo "Deleting the following generated files:"; \
706                 echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \
707                 $(RM) $(SUPERCLEAN_FILES); \
708         fi
710 $(DIST_ALIASES): $(DISTRIBUTE_DIR)
712 $(DISTRIBUTE_DIR): all py | $(DISTRIBUTE_SUBDIRS)
713         # add proto
714         cp -r src/caffe/proto $(DISTRIBUTE_DIR)/
715         # add include
716         cp -r include $(DISTRIBUTE_DIR)/
717         cp -r 3rdparty/half_float $(DISTRIBUTE_DIR)/include
718         mkdir -p $(DISTRIBUTE_DIR)/include/caffe/proto
719         cp $(PROTO_GEN_HEADER_SRCS) $(DISTRIBUTE_DIR)/include/caffe/proto
720         # add tool and example binaries
721         cp $(TOOL_BINS) $(DISTRIBUTE_DIR)/bin
722         cp $(EXAMPLE_BINS) $(DISTRIBUTE_DIR)/bin
723         # add libraries
724         cp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib
725         install -m 644 $(DYNAMIC_NAME) $(DISTRIBUTE_DIR)/lib
726         cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_SONAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_SONAME_SHORT)
727         cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT);   ln -s $(DYNAMIC_SONAME_SHORT) $(DYNAMIC_NAME_SHORT)
728         # add python - it's not the standard way, indeed...
729         cp -r python $(DISTRIBUTE_DIR)/python
731 -include $(DEPS)