1 # This Makefile compiles the label_image example for the Raspberry Pi. 2 # See tensorflow/contrib/pi_examples/README.md for full build instructions. 3 4 # Find where we're running from, so we can store generated files here. 5 SCRIPT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 6 7 # The location of the tensorflow/contrib/makefile directory. 8 TFMAKEFILE_DIR := $(SCRIPT_DIR)/../../makefile 9 10 # Where compiled objects are stored. 11 GENDIR := $(SCRIPT_DIR)/gen/ 12 OBJDIR := $(GENDIR)obj/ 13 LIBDIR := $(GENDIR)lib/ 14 BINDIR := $(GENDIR)bin/ 15 16 # The expected locations of the TensorFlow library. 17 TFLIBDIR := $(TFMAKEFILE_DIR)/gen/lib 18 TFLIBS := $(TFLIBDIR)/libtensorflow-core.a 19 20 # Where the downloads have been stored. 21 DOWNLOADSDIR := $(TFMAKEFILE_DIR)/downloads 22 23 # The location of the compiled protobuf headers generated by TensorFlow. 24 PBTGENDIR := $(TFMAKEFILE_DIR)/gen/proto_text/ 25 PROTOGENDIR := $(TFMAKEFILE_DIR)/gen/proto/ 26 27 # The name of the output program we're compiling. 28 EXECUTABLE_NAME := $(BINDIR)/camera 29 30 # Settings for the target compiler. 31 CXX := gcc 32 OPTFLAGS := -O0 33 CXXFLAGS := --std=c++11 $(OPTFLAGS) 34 LDFLAGS := \ 35 -L/usr/local/lib \ 36 -L$(TFLIBDIR) \ 37 -Wl,--no-whole-archive 38 INCLUDES := \ 39 -I/usr/local/include \ 40 -I. \ 41 -I$(DOWNLOADSDIR) \ 42 -I$(DOWNLOADSDIR)/eigen/ \ 43 -I$(PROTOGENDIR) \ 44 -I$(PBTGENDIR) 45 LIBS := \ 46 -Wl,--allow-multiple-definition \ 47 -Wl,--whole-archive \ 48 -ltensorflow-core \ 49 -Wl,--no-whole-archive \ 50 -lstdc++ \ 51 -lprotobuf \ 52 -lv4l2 \ 53 -ldl \ 54 -lpthread \ 55 -lm \ 56 -ljpeg \ 57 -lz 58 LIBFLAGS := 59 60 EXECUTABLE_SRCS := tensorflow/contrib/pi_examples/camera/camera.cc 61 62 # File names of the intermediate files target compilation generates. 63 EXECUTABLE_OBJS := $(addprefix $(OBJDIR), $(EXECUTABLE_SRCS:.cc=.o)) 64 65 .PHONY: clean 66 67 # The target that's compiled if there's no command-line arguments. 68 all: $(EXECUTABLE_NAME) 69 70 # Rules for target compilation. 71 72 $(EXECUTABLE_NAME): $(EXECUTABLE_OBJS) $(TFLIBS) 73 @mkdir -p $(dir $@) 74 $(CXX) $(CXXFLAGS) $(INCLUDES) \ 75 -o $(EXECUTABLE_NAME) $(EXECUTABLE_OBJS) \ 76 $(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS) 77 78 # Matches on C++ source files. 79 $(OBJDIR)%.o: %.cc 80 @mkdir -p $(dir $@) 81 $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ 82 83 # Gets rid of all generated files. 84 clean: 85 rm -rf $(GENDIR) 86