加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
NanoLogMakeFrag 3.78 KB
一键复制 编辑 原始数据 按行查看 历史
########
## This file expresses the rules required to compile with Preprocessor NanoLog.
## It defines a macro (run-cxx) to preprocess and compile user source files,
## and the rules required to build the NanoLog library.
##
## Users are expected to:
## 1) Define the macro NANOLOG_DIR to point to the NanoLog directory
## and the macro USER_OBJS to list all *.o to be produced by the
## user executing run-cxx on their source files.
## 2) Use run-cxx to compile their sources (see documentation below)
## 3) Add the following variable definition in their sources
## EXTRA_NANOLOG_FLAGS=-DPREPROCESSOR_NANOLOG
## 4) Include this MakeFrag in their main GNUmakefile
##
## The sample_preprocessor/GNUmakefile shows an example of the integration.
#######
RUNTIME_DIR=$(NANOLOG_DIR)/runtime
PREPROC_DIR=$(NANOLOG_DIR)/preprocessor
# run-cxx:
# Compile a user C++ source file to an object file using the NanoLog system.
# The first parameter $(1) should be the output filename (*.o)
# The second parameter $(2) should be the input filename (*.cc)
# The optional third parameter $(3) should be additional options compiler options.
# The optional fourth parameter ($4) should be gnu preprocessor options.
define run-cxx
$(CXX) -E -I $(RUNTIME_DIR) $(2) -o $(2).i -std=c++11 $(4)
@mkdir -p generated
python $(PREPROC_DIR)/parser.py --mapOutput="generated/$(2).map" $(2).i
$(CXX) -I $(RUNTIME_DIR) -c -o $(1) $(2).ii $(3)
@rm -f $(2).i $(2).ii generated/GeneratedCode.cc
endef
RUNTIME_CXX_FLAGS= -std=c++11 -O3 -DNDEBUG -g
NANO_LOG_LIBRARY_LIBS=-lrt -pthread
COMWARNS := -Wall -Wformat=2 -Wextra \
-Wwrite-strings -Wno-unused-parameter -Wmissing-format-attribute
CWARNS := $(COMWARNS) -Wmissing-prototypes -Wmissing-declarations -Wshadow \
-Wbad-function-cast
CXXWARNS := $(COMWARNS) -Wno-non-template-friend -Woverloaded-virtual \
-Wcast-qual -Wcast-align -Wno-address-of-packed-member -Wconversion -Weffc++
LIB_SRCFILES=Cycles.cc NanoLog.cc Util.cc Log.cc RuntimeLogger.cc TimeTrace.cc
RUNTIME_CC=$(addprefix $(RUNTIME_DIR)/,$(LIB_SRCFILES))
RUNTIME_OBJS=$(addprefix generated/library/, $(LIB_SRCFILES:.cc=.o))
.PHONY: all
all:
# Collates the metadata generated by run-cxx and constructs a generated source
# file and its object file
generated/GeneratedCode.o: $(USER_OBJS)
@mkdir -p generated
python $(PREPROC_DIR)/parser.py --combinedOutput="generated/GeneratedCode.cc" $(shell find generated -type f -name "*.map" -printf ' "%h/%f" ')
$(CXX) $(RUNTIME_CXX_FLAGS) $(CXXWARNS) -c -o $@ generated/GeneratedCode.cc -I $(RUNTIME_DIR) -Igenerated
# Builds the static parts of the NanoLog library that don't change
generated/library/%.o: $(RUNTIME_DIR)/%.cc
@mkdir -p generated/library
$(CXX) $(RUNTIME_CXX_FLAGS) $(CXXWARNS) -c -I $(RUNTIME_DIR) -Igenerated $(EXTRA_NANOLOG_FLAGS) -o $@ $<
# Constructs the customized NanoLog library and decompressor for this compilation.
# It is unique per user source compilation via the dependency on GeneratedCode.o -> $(USER_OBJS)
libNanoLog.a: $(RUNTIME_OBJS) generated/GeneratedCode.o decompressor
ar -cr libNanoLog.a $(RUNTIME_OBJS) generated/GeneratedCode.o
decompressor: $(RUNTIME_OBJS) generated/GeneratedCode.o $(RUNTIME_DIR)/LogDecompressor.cc
$(CXX) $(RUNTIME_CXX_FLAGS) $(CXXWARNS) $^ -I$(RUNTIME_DIR) -Igenerated $(NANO_LOG_LIBRARY_LIBS) $(EXTRA_NANOLOG_FLAGS) -o decompressor
clean-all: clean
@rm -f libNanoLog.a $(RUNTIME_OBJS) decompressor
@rm -rf generated $(RUNTIME_DIR)/.depend
# Automatic rules to build *.h dependencies for NanoLog. Taken from
# https://stackoverflow.com/questions/2394609/makefile-header-dependencies
depend: .depend_nanolog
.depend_nanolog: $(RUNTIME_CC)
@rm -f $(RUNTIME_DIR)/.depend
$(CXX) $(RUNTIME_CXX_FLAGS) -I $(RUNTIME_DIR) -MM $^ > .depend_nanolog;
@sed -i -E "s#(^[^ ])#$(RUNTIME_DIR)/\1#" .depend_nanolog
include .depend_nanolog
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化