-
Notifications
You must be signed in to change notification settings - Fork 343
/
NanoLogMakeFrag
85 lines (71 loc) · 3.78 KB
/
NanoLogMakeFrag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
########
## 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