1 2# Find where we're running from, so we can store generated files here. 3ifeq ($(origin MAKEFILE_DIR), undefined) 4 MAKEFILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 5endif 6 7# Try to figure out the host system 8HOST_OS := 9ifeq ($(OS),Windows_NT) 10 HOST_OS = WINDOWS 11else 12 UNAME_S := $(shell uname -s) 13 ifeq ($(UNAME_S),Linux) 14 HOST_OS := LINUX 15 endif 16 ifeq ($(UNAME_S),Darwin) 17 HOST_OS := OSX 18 endif 19endif 20 21ARCH := $(shell if [[ $(shell uname -m) =~ i[345678]86 ]]; then echo x86_32; else echo $(shell uname -m); fi) 22 23# Where compiled objects are stored. 24OBJDIR := $(MAKEFILE_DIR)/gen/obj/ 25BINDIR := $(MAKEFILE_DIR)/gen/bin/ 26LIBDIR := $(MAKEFILE_DIR)/gen/lib/ 27GENDIR := $(MAKEFILE_DIR)/gen/obj/ 28 29# Settings for the host compiler. 30CXX := $(CC_PREFIX) gcc 31CXXFLAGS := --std=c++11 -O3 -DNDEBUG 32CC := $(CC_PREFIX) gcc 33CFLAGS := 34LDOPTS := 35LDOPTS += -L/usr/local/lib 36ARFLAGS := -r 37 38INCLUDES := \ 39-I. \ 40-I$(MAKEFILE_DIR)/../../../ \ 41-I$(MAKEFILE_DIR)/downloads/ \ 42-I$(MAKEFILE_DIR)/downloads/eigen \ 43-I$(MAKEFILE_DIR)/downloads/gemmlowp \ 44-I$(MAKEFILE_DIR)/downloads/neon_2_sse \ 45-I$(MAKEFILE_DIR)/downloads/farmhash/src \ 46-I$(MAKEFILE_DIR)/downloads/flatbuffers/include \ 47-I$(GENDIR) 48# This is at the end so any globally-installed frameworks like protobuf don't 49# override local versions in the source tree. 50INCLUDES += -I/usr/local/include 51 52LIBS := \ 53-lstdc++ \ 54-lpthread \ 55-lm \ 56-lz 57 58# If we're on Linux, also link in the dl library. 59ifeq ($(HOST_OS),LINUX) 60 LIBS += -ldl -lpthread 61endif 62 63include $(MAKEFILE_DIR)/ios_makefile.inc 64 65# This library is the main target for this makefile. It will contain a minimal 66# runtime that can be linked in to other programs. 67LIB_NAME := libtensorflow-lite.a 68LIB_PATH := $(LIBDIR)$(LIB_NAME) 69 70# A small example program that shows how to link against the library. 71BENCHMARK_PATH := $(BINDIR)benchmark_model 72 73BENCHMARK_SRCS := \ 74tensorflow/contrib/lite/tools/benchmark_model.cc 75BENCHMARK_OBJS := $(addprefix $(OBJDIR), \ 76$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(BENCHMARK_SRCS)))) 77 78# What sources we want to compile, must be kept in sync with the main Bazel 79# build files. 80 81CORE_CC_ALL_SRCS := \ 82$(wildcard tensorflow/contrib/lite/*.cc) \ 83$(wildcard tensorflow/contrib/lite/kernels/*.cc) \ 84$(wildcard tensorflow/contrib/lite/kernels/internal/*.cc) \ 85$(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.cc) \ 86$(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.cc) \ 87$(wildcard tensorflow/contrib/lite/*.c) \ 88$(wildcard tensorflow/contrib/lite/kernels/*.c) \ 89$(wildcard tensorflow/contrib/lite/kernels/internal/*.c) \ 90$(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.c) \ 91$(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.c) \ 92$(wildcard tensorflow/contrib/lite/downloads/farmhash/src/farmhash.cc) 93# Remove any duplicates. 94CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS)) 95CORE_CC_EXCLUDE_SRCS := \ 96$(wildcard tensorflow/contrib/lite/*test.cc) \ 97$(wildcard tensorflow/contrib/lite/*/*test.cc) \ 98$(wildcard tensorflow/contrib/lite/*/*/*test.cc) \ 99$(wildcard tensorflow/contrib/lite/*/*/*/*test.cc) \ 100$(wildcard tensorflow/contrib/lite/kernels/test_util.cc) \ 101$(BENCHMARK_SRCS) 102# Filter out all the excluded files. 103TF_LITE_CC_SRCS := $(filter-out $(CORE_CC_EXCLUDE_SRCS), $(CORE_CC_ALL_SRCS)) 104# File names of the intermediate files target compilation generates. 105TF_LITE_CC_OBJS := $(addprefix $(OBJDIR), \ 106$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(TF_LITE_CC_SRCS)))) 107LIB_OBJS := $(TF_LITE_CC_OBJS) 108 109# For normal manually-created TensorFlow C++ source files. 110$(OBJDIR)%.o: %.cc 111 @mkdir -p $(dir $@) 112 $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ 113 114# For normal manually-created TensorFlow C++ source files. 115$(OBJDIR)%.o: %.c 116 @mkdir -p $(dir $@) 117 $(CC) $(CCFLAGS) $(INCLUDES) -c $< -o $@ 118 119# The target that's compiled if there's no command-line arguments. 120all: $(LIB_PATH) $(BENCHMARK_PATH) 121 122# Gathers together all the objects we've compiled into a single '.a' archive. 123$(LIB_PATH): $(LIB_OBJS) 124 @mkdir -p $(dir $@) 125 $(AR) $(ARFLAGS) $(LIB_PATH) $(LIB_OBJS) 126 127$(BENCHMARK_PATH): $(BENCHMARK_OBJS) $(LIB_PATH) 128 @mkdir -p $(dir $@) 129 $(CXX) $(CXXFLAGS) $(INCLUDES) \ 130 -o $(BENCHMARK_PATH) $(BENCHMARK_OBJS) \ 131 $(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS) 132 133# Gets rid of all generated files. 134clean: 135 rm -rf $(MAKEFILE_DIR)/gen 136 137# Gets rid of target files only, leaving the host alone. Also leaves the lib 138# directory untouched deliberately, so we can persist multiple architectures 139# across builds for iOS and Android. 140cleantarget: 141 rm -rf $(OBJDIR) 142 rm -rf $(BINDIR) 143 144$(DEPDIR)/%.d: ; 145.PRECIOUS: $(DEPDIR)/%.d 146 147-include $(patsubst %,$(DEPDIR)/%.d,$(basename $(TF_CC_SRCS))) 148