Repository: hbase Updated Branches: refs/heads/HBASE-14850 9b43493f8 -> d2bc6b1b7
HBASE-17768 [C++] Makefile should recompile only the changed sources (Sudeep Sunthankar) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d2bc6b1b Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d2bc6b1b Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d2bc6b1b Branch: refs/heads/HBASE-14850 Commit: d2bc6b1b78efe87ff540ccfa8374ee5daec13da2 Parents: 9b43493 Author: Enis Soztutar <e...@apache.org> Authored: Tue Mar 14 14:35:22 2017 -0700 Committer: Enis Soztutar <e...@apache.org> Committed: Tue Mar 14 14:35:22 2017 -0700 ---------------------------------------------------------------------- hbase-native-client/Makefile | 132 +++++++++++++++++-------------- hbase-native-client/Makefile.protos | 68 +++++++++------- 2 files changed, 113 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/d2bc6b1b/hbase-native-client/Makefile ---------------------------------------------------------------------- diff --git a/hbase-native-client/Makefile b/hbase-native-client/Makefile index 166c6ab..143c00c 100644 --- a/hbase-native-client/Makefile +++ b/hbase-native-client/Makefile @@ -15,82 +15,94 @@ # specific language governing permissions and limitations # under the License. -#use "gcc" to compile source files -CC:=g++ -LD:=g++ - -DEBUG_PATH = build/debug -RELEASE_PATH = build/release -PROTO_SRC_DIR = build/if -MODULES = connection core serde test-util utils security exceptions -SRC_DIR = $(MODULES) -DEBUG_BUILD_DIR = $(addprefix $(DEBUG_PATH)/,$(MODULES)) -RELEASE_BUILD_DIR = $(addprefix $(RELEASE_PATH)/,$(MODULES)) -INCLUDE_DIR = . build/ $(JAVA_HOME)/include/ $(JAVA_HOME)/include/linux +#use "g++" to compile source files +CC := g++ +LD := g++ + +BUILD_PATH := build +DEBUG_PATH := $(BUILD_PATH)/debug +RELEASE_PATH := $(BUILD_PATH)/release +PROTO_SRC_DIR := if +PROTO_CXX_DIR := $(BUILD_PATH)/if +MODULES := connection core exceptions security serde test-util utils +SRC_DIR := $(MODULES) +DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/,$(MODULES)) +RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/,$(MODULES)) +INCLUDE_DIR := . $(BUILD_PATH) $(JAVA_HOME)/include/ $(JAVA_HOME)/include/linux #flags to pass to the CPP compiler & linker -CPPFLAGS_DEBUG = -D_GLIBCXX_USE_CXX11_ABI=0 -g -Wall -std=c++14 -pedantic -fPIC -CPPFLAGS_RELEASE = -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -O2 -Wall -std=c++14 -pedantic -fPIC -LDFLAGS = -lprotobuf -lzookeeper_mt -lsasl2 -lfolly -lwangle -LINKFLAG = -shared -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm +CPPFLAGS_DEBUG := -D_GLIBCXX_USE_CXX11_ABI=0 -g -Wall -std=c++14 -pedantic -fPIC -MMD -MP +CPPFLAGS_RELEASE := -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -O2 -Wall -std=c++14 -pedantic -fPIC -MMD -MP +LDFLAGS := -lprotobuf -lzookeeper_mt -lsasl2 -lfolly -lwangle -L $(JAVA_HOME)/jre/lib/amd64/server -ljvm +LINKFLAG := -shared #define list of source files and object files -ALLSRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) -EXCLUDE_SRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*-test.cc)) core/simple-client.cc -SRC = $(filter-out $(EXCLUDE_SRC), $(ALLSRC)) -PROTOSRC = $(patsubst %.proto, $(addprefix build/,%.pb.cc),$(wildcard if/*.proto)) -DEPS = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.h)) -PROTODEPS = $(patsubst %.proto, $(addprefix build/,%.pb.h),$(wildcard if/*.proto)) -DEBUG_OBJ = $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) +ALLSRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) +EXCLUDE_SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*-test.cc)) core/simple-client.cc +SRC := $(filter-out $(EXCLUDE_SRC), $(ALLSRC)) +PROTOSRC := $(patsubst %.proto, $(addprefix $(BUILD_PATH)/,%.pb.cc),$(wildcard if/*.proto)) +PROTOHDR := $(patsubst %.proto, $(addprefix $(BUILD_PATH)/,%.pb.h),$(wildcard if/*.proto)) +DEBUG_OBJ := $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) DEBUG_OBJ += $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(PROTOSRC)) -RELEASE_OBJ = $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) +RELEASE_OBJ := $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) RELEASE_OBJ += $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(PROTOSRC)) -INCLUDES = $(addprefix -I,$(INCLUDE_DIR)) - -LIB_DIR = /usr/local -LIB_LIBDIR = $(LIB_DIR)/lib -LIB_INCDIR = $(LIB_DIR)/include -LIB_RELEASE=$(RELEASE_PATH)/libHbaseClient.so -ARC_RELEASE=$(RELEASE_PATH)/libHbaseClient.a -LIB_DEBUG=$(DEBUG_PATH)/libHbaseClient_d.so -ARC_DEBUG=$(DEBUG_PATH)/libHbaseClient_d.a +INCLUDES := $(addprefix -I,$(INCLUDE_DIR)) + +LIB_DIR := /usr/local +LIB_LIBDIR := $(LIB_DIR)/lib +LIB_INCDIR := $(LIB_DIR)/include +LIB_RELEASE := $(RELEASE_PATH)/libHbaseClient.so +ARC_RELEASE := $(RELEASE_PATH)/libHbaseClient.a +LIB_DEBUG := $(DEBUG_PATH)/libHbaseClient_d.so +ARC_DEBUG := $(DEBUG_PATH)/libHbaseClient_d.a + +build: checkdirs protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) vpath %.cc $(SRC_DIR) -build: checkdirs copyfiles protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) -$(LIB_DEBUG): $(DEBUG_BUILD_DIR) +$(LIB_DEBUG): define make-goal-dbg -$1/%.o: %.cc $(DEPS) $(PROTODEPS) $(PROTOSRC) - $(CC) -c $$< -o $$@ $(CPPFLAGS_DEBUG) $(INCLUDES) +DEPS := $(DEBUG_OBJ:.o=.d) +-include $(DEPS) +$1/%.o: %.cc + $(CC) -c $$< -o $$@ -MF$$(@:%.o=%.d) -MT$$@ $(CPPFLAGS_DEBUG) $(INCLUDES) endef -$(LIB_RELEASE): $(RELEASE_BUILD_DIR) +$(LIB_RELEASE): define make-goal-rel -$1/%.o: %.cc $(DEPS) $(PROTODEPS) $(PROTOSRC) - $(CC) -c $$< -o $$@ $(CPPFLAGS_RELEASE) $(INCLUDES) +DEPS := $(RELEASE_OBJ:.o=.d) +-include $(DEPS) +$1/%.o: %.cc + $(CC) -c $$< -o $$@ -MF$$(@:%.o=%.d) -MT$$@ $(CPPFLAGS_RELEASE) $(INCLUDES) endef .PHONY: all clean install -checkdirs: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(PROTO_SRC_DIR) +checkdirs: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(PROTO_CXX_DIR) copyfiles: - bin/copy-protobuf.sh - bin/copy-version.sh + @bin/copy-protobuf.sh + @bin/copy-version.sh -protos: createprotosrc - @make all -f Makefile.protos +$(PROTO_CXX_DIR)/%.pb.cc $(PROTO_CXX_DIR)/%.pb.h: $(PROTO_SRC_DIR)/%.proto + @protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_CXX_DIR) $< -createprotosrc: $(PROTO_SRC_DIR) - @protoc --proto_path=if --cpp_out=$(PROTO_SRC_DIR) if/*.proto +#Run parallel jobs to speed up compilation +protos: $(PROTO_CXX_DIR) $(PROTOSRC) $(PROTOHDR) + @make -j8 all -f Makefile.protos install: cp $(LIB_RELEASE) $(LIB_LIBDIR)/libHbaseClient.so cp $(ARC_RELEASE) $(LIB_LIBDIR)/libHbaseClient.a cp $(LIB_DEBUG) $(LIB_LIBDIR)/libHbaseClient_d.so cp $(ARC_DEBUG) $(LIB_LIBDIR)/libHbaseClient_d.a + ldconfig -$(PROTO_SRC_DIR): +uninstall: + rm -f $(LIB_LIBDIR)/libHbaseClient.so $(LIB_LIBDIR)/libHbaseClient.a $(LIB_LIBDIR)/libHbaseClient_d.so $(ARC_DEBUG) $(LIB_LIBDIR)/libHbaseClient_d.a + ldconfig + +$(PROTO_CXX_DIR): @mkdir -p $@ $(DEBUG_BUILD_DIR): @@ -111,9 +123,8 @@ $(LIB_RELEASE): $(RELEASE_OBJ) $(LIB_DEBUG): $(DEBUG_OBJ) $(LD) $(LINKFLAG) -o $@ $(LDFLAGS) $(DEBUG_OBJ) -#to clean re-compilable files clean: - @rm -rf $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(LIB_RELEASE) $(LIB_DEBUG) $(ARC_RELEASE) $(ARC_DEBUG) docs buck-out build + @rm -rf docs buck-out $(BUILD_PATH) $(foreach bdir,$(DEBUG_BUILD_DIR), $(eval $(call make-goal-dbg,$(bdir)))) @@ -131,11 +142,16 @@ doc: help: @echo "Available targets:" @echo "" - @echo " build : will build everything." - @echo " clean : will remove the docs folder, object files and local libraries" - @echo " install : will copy the libs to $(LIB_LIBDIR). super user priviliege would be required." - @echo " check : will test everything." - @echo " protos : will build the corresponding sources for protobufs present in if/ directory." - @echo " lint : will ensure that code conforms to Google coding style." - -all: build doc check + @echo " all : builds everything, creates doc and runs tests." + @echo " build : will build/rebuild everything." + @echo " check : will test everything." + @echo " clean : removes docs folder, object files and local libraries from build/ directory." + @echo " copyfiles : copies native version.h from mvn build and proto locally to hbase-native-client." + @echo " doc : generates documentation." + @echo " install : will copy the libs to $(LIB_LIBDIR). super user priviliege would be required." + @echo " protos : will create PB CPP sec and headers from if/*.proto and build them." + @echo " uninstall : removes the libs from $(LIB_LIBDIR)." + @echo " lint : will ensure that code conforms to Google coding style." + @echo "If no target is specified 'build' will be executed" + +all: copyfiles build doc check http://git-wip-us.apache.org/repos/asf/hbase/blob/d2bc6b1b/hbase-native-client/Makefile.protos ---------------------------------------------------------------------- diff --git a/hbase-native-client/Makefile.protos b/hbase-native-client/Makefile.protos index 2c6316b..4cf8982 100644 --- a/hbase-native-client/Makefile.protos +++ b/hbase-native-client/Makefile.protos @@ -15,56 +15,66 @@ # specific language governing permissions and limitations # under the License. -#use "gcc" to compile source files -CC:=g++ -LD:=g++ +#use "g++" to compile source files +CC := g++ -DEBUG_PATH = build/debug -RELEASE_PATH = build/release -MODULES = build/if -SRC_DIR = $(MODULES) -DEBUG_BUILD_DIR = $(addprefix $(DEBUG_PATH)/,$(MODULES)) -RELEASE_BUILD_DIR = $(addprefix $(RELEASE_PATH)/,$(MODULES)) -INCLUDE_DIR = . +BUILD_PATH := build +DEBUG_PATH := $(BUILD_PATH)/debug +RELEASE_PATH := $(BUILD_PATH)/release +MODULES := $(BUILD_PATH)/if +SRC_DIR := $(MODULES) +DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/,$(MODULES)) +RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/,$(MODULES)) +INCLUDE_DIR := . $(BUILD_PATH)/if #flags to pass to the CPP compiler & linker -CPPFLAGS_DEBUG = -D_GLIBCXX_USE_CXX11_ABI=0 -g -Wall -std=c++14 -pedantic -fPIC -CPPFLAGS_RELEASE = -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -O2 -Wall -std=c++14 -pedantic -fPIC +CPPFLAGS_DEBUG := -D_GLIBCXX_USE_CXX11_ABI=0 -g -Wall -std=c++14 -pedantic -fPIC -MMD -MP +CPPFLAGS_RELEASE := -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -O2 -Wall -std=c++14 -pedantic -fPIC -MMD -MP #define list of source files and object files -SRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) -DEPS = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.h)) -DEBUG_OBJ = $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) -RELEASE_OBJ = $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) -INCLUDES = $(addprefix -I,$(INCLUDE_DIR)) +SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) +DEBUG_OBJ := $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) +RELEASE_OBJ := $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) +INCLUDES := $(addprefix -I,$(INCLUDE_DIR)) + +all: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(DEBUG_OBJ) $(RELEASE_OBJ) vpath %.cc $(SRC_DIR) -$(DEBUG_OBJ): $(DEBUG_BUILD_DIR) +$(DEBUG_OBJ): define make-goal-dbg -$1/%.o: %.cc $(DEPS) - $(CC) -c $$< -o $$@ $(CPPFLAGS_DEBUG) $(INCLUDES) +DEPS := $(DEBUG_OBJ:.o=.d) +-include $(DEPS) +$1/%.o: %.cc + $(CC) -c $$< -o $$@ -MF$$(@:%.o=%.d) -MT$$@ $(CPPFLAGS_DEBUG) $(INCLUDES) endef -$(RELEASE_OBJ): $(RELEASE_BUILD_DIR) +$(RELEASE_OBJ): define make-goal-rel -$1/%.o: %.cc $(DEPS) - $(CC) -c $$< -o $$@ $(CPPFLAGS_RELEASE) $(INCLUDES) +DEPS := $(RELEASE_OBJ:.o=.d) +-include $(DEPS) +$1/%.o: %.cc + $(CC) -c $$< -o $$@ -MF$$(@:%.o=%.d) -MT$$@ $(CPPFLAGS_RELEASE) $(INCLUDES) endef +.PHONY: all clean + $(DEBUG_BUILD_DIR): @mkdir -p $@ $(RELEASE_BUILD_DIR): @mkdir -p $@ -.PHONY: all clean - -all: $(DEBUG_OBJ) $(RELEASE_OBJ) - clean: - @rm -rf $(DEBUG_OBJ) $(RELEASE_OBJ) + @rm -rf $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) -$(foreach bdir,$(DEBUG_BUILD_DIR), $(eval $(call make-goal-dbg,$(bdir)))) +$(foreach bdir,$(DEBUG_BUILD_DIR),$(eval $(call make-goal-dbg,$(bdir)))) $(foreach bdir,$(RELEASE_BUILD_DIR),$(eval $(call make-goal-rel,$(bdir)))) + +help: + @echo "This Makefile invocation will only work when protobuf sources and headers have been generated by running 'make protos'" + @echo "Available targets:" + @echo "" + @echo " all : creates objects for the generated PB src." + @echo " clean : removes PB objects."