-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gaodunqiao
committed
Jul 14, 2017
1 parent
ec25e64
commit 02bb7ab
Showing
14 changed files
with
520 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ notifications: | |
|
||
script: | ||
- make -C slash | ||
- make -C slash example | ||
- make -C slash check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,261 @@ | ||
CXX = g++ | ||
ifeq ($(__PERF), 1) | ||
CXXFLAGS = -O0 -g -pg -pipe -fPIC -D__XDEBUG__ -W -Wwrite-strings -Wpointer-arith -Wreorder -Wswitch -Wsign-promo -Wredundant-decls -Wformat -Wall -D_GNU_SOURCE -std=c++11 -D__STDC_FORMAT_MACROS -std=c++11 -gdwarf-2 -Wno-redundant-decls | ||
CLEAN_FILES = # deliberately empty, so we can append below. | ||
CFLAGS += ${EXTRA_CFLAGS} | ||
CXXFLAGS += ${EXTRA_CXXFLAGS} | ||
LDFLAGS += $(EXTRA_LDFLAGS) | ||
ARFLAGS = rs | ||
OPT= | ||
|
||
# Set the default DEBUG_LEVEL to 1 | ||
DEBUG_LEVEL?=0 | ||
|
||
ifeq ($(MAKECMDGOALS),dbg) | ||
DEBUG_LEVEL=2 | ||
endif | ||
|
||
ifeq ($(MAKECMDGOALS),all) | ||
DEBUG_LEVEL=0 | ||
endif | ||
|
||
ifeq ($(MAKECMDGOALS),clean) | ||
DEBUG_LEVEL=0 | ||
endif | ||
|
||
ifeq ($(MAKECMDGOALS),shared_lib) | ||
DEBUG_LEVEL=0 | ||
endif | ||
|
||
ifeq ($(MAKECMDGOALS),static_lib) | ||
DEBUG_LEVEL=0 | ||
endif | ||
|
||
# compile with -O2 if debug level is not 2 | ||
ifneq ($(DEBUG_LEVEL), 2) | ||
OPT += -O2 -fno-omit-frame-pointer | ||
# Skip for archs that don't support -momit-leaf-frame-pointer | ||
ifeq (,$(shell $(CXX) -fsyntax-only -momit-leaf-frame-pointer -xc /dev/null 2>&1)) | ||
OPT += -momit-leaf-frame-pointer | ||
endif | ||
endif | ||
|
||
# if we're compiling for release, compile without debug code (-DNDEBUG) and | ||
# don't treat warnings as errors | ||
ifeq ($(DEBUG_LEVEL),0) | ||
OPT += -DNDEBUG | ||
DISABLE_WARNING_AS_ERROR=1 | ||
else | ||
CXXFLAGS = -O2 -g -pipe -fPIC -W -Wwrite-strings -Wpointer-arith -Wreorder -Wswitch -Wsign-promo -Wredundant-decls -Wformat -Wall -D_GNU_SOURCE -D__STDC_FORMAT_MACROS -std=c++11 -gdwarf-2 -Wno-redundant-decls -Wno-sign-compare | ||
# CXXFLAGS = -Wall -W -DDEBUG -g -O0 -D__XDEBUG__ -D__STDC_FORMAT_MACROS -fPIC -std=c++11 -gdwarf-2 | ||
$(warning Warning: Compiling in debug mode. Don't use the resulting binary in production) | ||
endif | ||
|
||
SRC_DIR = ./src | ||
LIB_DIR = ./lib | ||
TESTS_DIR = ./tests | ||
#----------------------------------------------- | ||
|
||
INCLUDE_PATH = -I.. | ||
LIB_PATH = -L. \ | ||
include ./src.mk | ||
|
||
AM_DEFAULT_VERBOSITY = 0 | ||
|
||
LIBS = -lpthread | ||
AM_V_GEN = $(am__v_GEN_$(V)) | ||
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) | ||
am__v_GEN_0 = @echo " GEN " $@; | ||
am__v_GEN_1 = | ||
AM_V_at = $(am__v_at_$(V)) | ||
am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) | ||
am__v_at_0 = @ | ||
am__v_at_1 = | ||
|
||
LIBRARY = $(LIB_DIR)/libslash.a | ||
AM_V_CC = $(am__v_CC_$(V)) | ||
am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) | ||
am__v_CC_0 = @echo " CC " $@; | ||
am__v_CC_1 = | ||
CCLD = $(CC) | ||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ | ||
AM_V_CCLD = $(am__v_CCLD_$(V)) | ||
am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) | ||
am__v_CCLD_0 = @echo " CCLD " $@; | ||
am__v_CCLD_1 = | ||
AM_V_AR = $(am__v_AR_$(V)) | ||
am__v_AR_ = $(am__v_AR_$(AM_DEFAULT_VERBOSITY)) | ||
am__v_AR_0 = @echo " AR " $@; | ||
am__v_AR_1 = | ||
|
||
TESTS = \ | ||
$(TESTS_DIR)/slash_string.test \ | ||
$(TESTS_DIR)/slash_binlog.test \ | ||
$(TESTS_DIR)/slash_coding.test \ | ||
$(TESTS_DIR)/base_conf.test \ | ||
$(TESTS_DIR)/slash_env.test \ | ||
AM_LINK = $(AM_V_CCLD)$(CXX) $^ $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS) | ||
# detect what platform we're building on | ||
dummy := $(shell (export SLASH_ROOT="$(CURDIR)"; "$(CURDIR)/build_detect_platform" "$(CURDIR)/make_config.mk")) | ||
# this file is generated by the previous line to set build flags and sources | ||
include make_config.mk | ||
CLEAN_FILES += make_config.mk | ||
|
||
.PHONY: all clean check | ||
missing_make_config_paths := $(shell \ | ||
grep "\/\S*" -o $(CURDIR)/make_config.mk | \ | ||
while read path; \ | ||
do [ -e $$path ] || echo $$path; \ | ||
done | sort | uniq) | ||
|
||
$(foreach path, $(missing_make_config_paths), \ | ||
$(warning Warning: $(path) dont exist)) | ||
|
||
BASE_OBJS := $(wildcard $(SRC_DIR)/*.cc) | ||
BASE_OBJS += $(wildcard $(SRC_DIR)/*.c) | ||
BASE_OBJS += $(wildcard $(SRC_DIR)/*.cpp) | ||
OBJS = $(patsubst %.cc,%.o,$(BASE_OBJS)) | ||
CFLAGS += -g | ||
CXXFLAGS += -g | ||
|
||
# This (the first rule) must depend on "all". | ||
default: all | ||
|
||
all: $(LIBRARY) | ||
make -C example | ||
@echo "Success, go, go, go..." | ||
WARNING_FLAGS = -W -Wextra -Wall -Wsign-compare \ | ||
-Wno-unused-parameter -Wno-redundant-decls -Wwrite-strings \ | ||
-Wpointer-arith -Wreorder -Wswitch -Wsign-promo | ||
|
||
$(LIBRARY): $(OBJS) | ||
rm -rf $@ | ||
mkdir -p $(LIB_DIR) | ||
ar -rcs $@ $(OBJS) | ||
ifndef DISABLE_WARNING_AS_ERROR | ||
WARNING_FLAGS += -Werror | ||
endif | ||
|
||
$(OBJECT): $(OBJS) | ||
$(CXX) $(CXXFLAGS) -o $@ $^ $(INCLUDE_PATH) $(LIB_PATH) -Wl,-Bdynamic $(LIBS) | ||
CFLAGS += $(WARNING_FLAGS) -I.. $(PLATFORM_CCFLAGS) $(OPT) | ||
CXXFLAGS += $(WARNING_FLAGS) -I.. $(PLATFORM_CXXFLAGS) $(OPT) -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers | ||
|
||
$(OBJS): %.o : %.cc | ||
$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDE_PATH) | ||
LDFLAGS += $(PLATFORM_LDFLAGS) | ||
|
||
clean: | ||
make -C example clean | ||
rm -rf $(SRC_DIR)/*.o | ||
rm -rf $(LIB_DIR) | ||
rm -rf $(TESTS) | ||
date := $(shell date +%F) | ||
git_sha := $(shell git rev-parse HEAD 2>/dev/null) | ||
gen_build_version = sed -e s/@@GIT_SHA@@/$(git_sha)/ -e s/@@GIT_DATE_TIME@@/$(date)/ src/build_version.cc.in | ||
# Record the version of the source that we are compiling. | ||
# We keep a record of the git revision in this file. It is then built | ||
# as a regular source file as part of the compilation process. | ||
# One can run "strings executable_filename | grep _build_" to find | ||
# the version of the source that we used to build the executable file. | ||
CLEAN_FILES += src/build_version.cc | ||
|
||
src/build_version.cc: FORCE | ||
$(AM_V_GEN)rm -f $@-t | ||
$(AM_V_at)$(gen_build_version) > $@-t | ||
$(AM_V_at)if test -f $@; then \ | ||
cmp -s $@-t $@ && rm -f $@-t || mv -f $@-t $@; \ | ||
else mv -f $@-t $@; fi | ||
FORCE: | ||
|
||
LIBOBJECTS = $(LIB_SOURCES:.cc=.o) | ||
|
||
# if user didn't config LIBNAME, set the default | ||
ifeq ($(LIBNAME),) | ||
# we should only run slash in production with DEBUG_LEVEL 0 | ||
ifeq ($(DEBUG_LEVEL),0) | ||
LIBNAME=libslash | ||
else | ||
LIBNAME=libslash_debug | ||
endif | ||
endif | ||
LIBOUTPUT = ./lib | ||
dummy := $(shell mkdir -p $(LIBOUTPUT)) | ||
LIBRARY = $(LIBOUTPUT)/${LIBNAME}.a | ||
|
||
SLASH_MAJOR = $(shell egrep "SLASH_MAJOR.[0-9]" include/version.h | cut -d ' ' -f 3) | ||
SLASH_MINOR = $(shell egrep "SLASH_MINOR.[0-9]" include/version.h | cut -d ' ' -f 3) | ||
SLASH_PATCH = $(shell egrep "SLASH_PATCH.[0-9]" include/version.h | cut -d ' ' -f 3) | ||
|
||
#----------------------------------------------- | ||
# Create platform independent shared libraries. | ||
#----------------------------------------------- | ||
ifneq ($(PLATFORM_SHARED_EXT),) | ||
|
||
ifneq ($(PLATFORM_SHARED_VERSIONED),true) | ||
SHARED1 = ${LIBNAME}.$(PLATFORM_SHARED_EXT) | ||
SHARED2 = $(SHARED1) | ||
SHARED3 = $(SHARED1) | ||
SHARED4 = $(SHARED1) | ||
SHARED = $(SHARED1) | ||
else | ||
SHARED_MAJOR = $(SLASH_MAJOR) | ||
SHARED_MINOR = $(SLASH_MINOR) | ||
SHARED_PATCH = $(SLASH_PATCH) | ||
SHARED1 = ${LIBNAME}.$(PLATFORM_SHARED_EXT) | ||
ifeq ($(PLATFORM), OS_MACOSX) | ||
SHARED_OSX = $(LIBNAME).$(SHARED_MAJOR) | ||
SHARED2 = $(SHARED_OSX).$(PLATFORM_SHARED_EXT) | ||
SHARED3 = $(SHARED_OSX).$(SHARED_MINOR).$(PLATFORM_SHARED_EXT) | ||
SHARED4 = $(SHARED_OSX).$(SHARED_MINOR).$(SHARED_PATCH).$(PLATFORM_SHARED_EXT) | ||
else | ||
SHARED2 = $(SHARED1).$(SHARED_MAJOR) | ||
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR) | ||
SHARED4 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR).$(SHARED_PATCH) | ||
endif | ||
SHARED = $(SHARED1) $(SHARED2) $(SHARED3) $(SHARED4) | ||
$(SHARED1): $(SHARED4) | ||
ln -fs $(SHARED4) $(SHARED1) | ||
$(SHARED2): $(SHARED4) | ||
ln -fs $(SHARED4) $(SHARED2) | ||
$(SHARED3): $(SHARED4) | ||
ln -fs $(SHARED4) $(SHARED3) | ||
endif | ||
|
||
$(SHARED4): $(LIBOBJECTS) | ||
$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(LIB_SOURCES) \ | ||
$(LDFLAGS) -o $@ | ||
|
||
endif # PLATFORM_SHARED_EXT | ||
|
||
TESTS = slash_string_test slash_binlog_test slash_coding_test base_conf_test \ | ||
slash_env_test | ||
|
||
EXAMPLES = conf_example cond_lock_example binlog_example mutex_example hash_example | ||
|
||
.PHONY: clean tags dbg static_lib shared_lib all check example | ||
|
||
all: $(LIBRARY) | ||
|
||
static_lib: $(LIBRARY) | ||
|
||
shared_lib: $(SHARED) | ||
for f in $(notdir $(SHARED)); do mv "$$f" $(LIBOUTPUT); done | ||
|
||
example: $(EXAMPLES) | ||
|
||
check: $(LIBRARY) $(TESTS) | ||
for t in $(notdir $(TESTS)); do echo "***** Running $$t"; $(TESTS_DIR)/$$t || exit 1; done | ||
for t in $(notdir $(TESTS)); do echo "***** Running $$t"; ./$$t || exit 1; done | ||
|
||
dbg: $(LIBRARY) $(EXAMPLES) | ||
|
||
$(LIBRARY): $(LIBOBJECTS) | ||
$(AM_V_AR)rm -f $@ | ||
$(AM_V_at)$(AR) $(ARFLAGS) $@ $(LIBOBJECTS) | ||
|
||
clean: | ||
make -C ./examples clean | ||
rm -f $(TESTS) $(EXAMPLES) | ||
rm -f $(LIBRARY) $(SHARED) | ||
rm -rf $(CLEAN_FILES) | ||
rm -rf $(LIBOUTPUT) | ||
find . -name "*.[oda]" -exec rm -f {} \; | ||
find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \; | ||
|
||
# tests | ||
|
||
TEST_MAIN = tests/test_main.o | ||
|
||
slash_string_test: ./tests/slash_string_test.o $(TEST_MAIN) $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
slash_binlog_test: ./tests/slash_binlog_test.o $(TEST_MAIN) $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
base_conf_test: ./tests/base_conf_test.o $(TEST_MAIN) $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
slash_coding_test: ./tests/slash_coding_test.o $(TEST_MAIN) $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
slash_env_test: ./tests/slash_env_test.o $(TEST_MAIN) $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
# examples | ||
|
||
$(TESTS_DIR)/slash_string.test: $(TESTS_DIR)/slash_string_test.cc $(TESTS_DIR)/test_main.cc | ||
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIBRARY) $(LIBS) | ||
conf_example: examples/conf_example.o $(LIBOBJECTS) | ||
$(warning $(AM_LINK)) | ||
$(AM_LINK) | ||
|
||
$(TESTS_DIR)/slash_binlog.test: $(TESTS_DIR)/slash_binlog_test.cc $(TESTS_DIR)/test_main.cc | ||
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIBRARY) $(LIBS) | ||
cond_lock_example: examples/cond_lock_example.o $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
$(TESTS_DIR)/base_conf.test: $(TESTS_DIR)/base_conf_test.cc $(TESTS_DIR)/test_main.cc | ||
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIBRARY) $(LIBS) | ||
binlog_example: examples/binlog_example.o $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
$(TESTS_DIR)/slash_coding.test: $(TESTS_DIR)/slash_coding_test.cc $(TESTS_DIR)/test_main.cc | ||
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIBRARY) $(LIBS) | ||
mutex_example: examples/mutex_example.o $(LIBOBJECTS) | ||
$(AM_LINK) | ||
|
||
$(TESTS_DIR)/slash_env.test: $(TESTS_DIR)/slash_env_test.cc $(TESTS_DIR)/test_main.cc | ||
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIBRARY) $(LIBS) | ||
hash_example: examples/hash_example.o $(LIBOBJECTS) | ||
$(AM_LINK) |
Oops, something went wrong.