]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/Makefile
05b7bc042780bdf9177a97a0b67f8c084b79c613
[jacinto-ai/caffe-jacinto.git] / src / Makefile
1 #
2 # The following defines a variable named "NAME" with a value of "myprogram". By convention,
3 # a lowercase prefix (in this case "program") and an uppercased suffix (in this case "NAME"), separated
4 # by an underscore is used to name attributes for a common element. Think of this like
5 # using program.NAME, program.C_SRCS, etc. There are no structs in Make, so we use this convention
6 # to keep track of attributes that all belong to the same target or program.  
7 #
8 PROJECT := caffe
9 NAME := lib$(PROJECT).so
10 TEST_NAME := test_$(PROJECT)
11 CXX_SRCS := $(shell find caffe ! -name "test_*.cpp" -name "*.cpp")
12 CU_SRCS := $(shell find caffe -name "*.cu")
13 TEST_SRCS := $(shell find caffe -name "test_*.cpp")
14 GTEST_SRC := gtest/gtest-all.cpp
15 PROGRAM_SRCS := $(shell find programs -name "*.cpp")
16 PROTO_SRCS := $(wildcard caffe/proto/*.proto)
17 PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
18 PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
19 PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py}
20 CXX_OBJS := ${CXX_SRCS:.cpp=.o}
21 CU_OBJS := ${CU_SRCS:.cu=.cuo}
22 PROGRAM_OBJS := ${PROGRAM_SRCS:.cpp=.o}
23 PROTO_OBJS := ${PROTO_SRCS:.proto=.pb.o}
24 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
25 TEST_OBJS := ${TEST_SRCS:.cpp=.o}
26 GTEST_OBJ := ${GTEST_SRC:.cpp=.o}
27 TEST_BINS := ${TEST_OBJS:.o=.testbin}
28 PROGRAM_BINS :=${PROGRAM_OBJS:.o=.bin}
30 CUDA_DIR := /usr/local/cuda
31 CUDA_ARCH := -arch=sm_20
32 MKL_DIR := /opt/intel/mkl
34 CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
35 CUDA_LIB_DIR := $(CUDA_DIR)/lib64
36 MKL_INCLUDE_DIR := $(MKL_DIR)/include
37 MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
39 INCLUDE_DIRS := . /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
40 LIBRARY_DIRS := . /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
41 LIBRARIES := cuda cudart cublas protobuf glog mkl_rt mkl_intel_thread curand \
42                 leveldb snappy opencv_core opencv_highgui
43 WARNINGS := -Wall
45 CXXFLAGS += -fPIC $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
46 LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir))
47 LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library))
49 LINK = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(WARNINGS)
50 NVCC = nvcc ${CXXFLAGS:-fPIC=-Xcompiler -fPIC} $(CPPFLAGS) $(CUDA_ARCH)
52 .PHONY: all test clean distclean linecount program
54 all: $(NAME)
56 linecount: clean
57         cloc --read-lang-def=caffe.cloc caffe/
59 test: $(OBJS) $(GTEST_OBJ) $(TEST_BINS)
61 program: $(OBJS) $(PROGRAM_BINS)
63 runtest: test
64         for testbin in $(TEST_BINS); do $$testbin; done
66 $(TEST_BINS): %.testbin : %.o
67         $(CXX) $< $(OBJS) $(GTEST_OBJ) -o $@ $(LDFLAGS) $(WARNINGS)
69 $(PROGRAM_BINS): %.bin : %.o
70         $(CXX) $< $(OBJS) -o $@ $(LDFLAGS) $(WARNINGS)
72 $(NAME): $(PROTO_GEN_CC) $(OBJS)
73         $(LINK) -shared $(OBJS) -o $(NAME)
75 $(CU_OBJS): %.cuo: %.cu
76         $(NVCC) -c $< -o $@
78 $(PROTO_GEN_CC): $(PROTO_SRCS)
79         protoc $(PROTO_SRCS) --cpp_out=. --python_out=.
81 clean:
82         @- $(RM) $(NAME) $(TEST_BINS)
83         @- $(RM) $(OBJS) $(TEST_OBJS) 
84         @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
86 distclean: clean