]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/Makefile
a few updates
[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 PROTO_SRCS := $(wildcard caffe/proto/*.proto)
16 PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
17 PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
18 PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py}
19 CXX_OBJS := ${CXX_SRCS:.cpp=.o}
20 CU_OBJS := ${CU_SRCS:.cu=.cuo}
21 PROTO_OBJS := ${PROTO_SRCS:.proto=.pb.o}
22 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
23 TEST_OBJS := ${TEST_SRCS:.cpp=.o}
24 GTEST_OBJ := ${GTEST_SRC:.cpp=.o}
25 TEST_BINS := ${TEST_OBJS:.o=.testbin}
27 CUDA_DIR := /usr/local/cuda
28 CUDA_ARCH := -arch=sm_20
29 MKL_DIR := /opt/intel/mkl
31 CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
32 CUDA_LIB_DIR := $(CUDA_DIR)/lib64
33 MKL_INCLUDE_DIR := $(MKL_DIR)/include
34 MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
36 INCLUDE_DIRS := . /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
37 LIBRARY_DIRS := . /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
38 LIBRARIES := cuda cudart cublas protobuf glog mkl_rt mkl_intel_thread curand leveldb snappy
39 WARNINGS := -Wall
41 CXXFLAGS += -fPIC $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
42 LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir))
43 LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library))
45 LINK = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(WARNINGS)
46 NVCC = nvcc ${CXXFLAGS:-fPIC=-Xcompiler -fPIC} $(CPPFLAGS) $(CUDA_ARCH)
48 .PHONY: all test clean distclean linecount
50 all: $(NAME)
52 linecount: clean
53         cloc --read-lang-def=caffe.cloc caffe/
55 test: $(OBJS) $(GTEST_OBJ) $(TEST_BINS)
57 runtest: test
58         for testbin in $(TEST_BINS); do $$testbin; done
60 $(TEST_BINS): %.testbin : %.o
61         $(CXX) $< $(OBJS) $(GTEST_OBJ) -o $@ $(LDFLAGS) $(WARNINGS)
63 $(NAME): $(PROTO_GEN_CC) $(OBJS)
64         $(LINK) -shared $(OBJS) -o $(NAME)
66 $(CU_OBJS): %.cuo: %.cu
67         $(NVCC) -c $< -o $@
69 $(PROTO_GEN_CC): $(PROTO_SRCS)
70         protoc $(PROTO_SRCS) --cpp_out=. --python_out=.
72 clean:
73         @- $(RM) $(NAME) $(TEST_BINS)
74         @- $(RM) $(OBJS) $(TEST_OBJS) 
75         @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
77 distclean: clean