-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakefile
158 lines (126 loc) · 4.25 KB
/
makefile
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# makefile for generic c++ project
# generated with `makeproject` on Tue Aug 15 16:58:29 CEST 2017
# Author: Dan Guest <[email protected]>
# _______________________________________________________________
# Basic Setup
# --- set dirs
BUILD := build
SRC := src
INC := include
DICT := dict
OUTPUT := bin
LIB := lib
# set search path
vpath %.cxx $(SRC)
vpath %.hh $(INC) $(SRC)
vpath %.h $(INC) $(SRC)
vpath %Dict.h $(DICT)
vpath %Dict.cxx $(DICT)
# --- set compiler and flags (roll c options and include paths together)
CXX ?= g++
CXXFLAGS := -O2 -Wall -fPIC -I$(INC) -g -std=c++14
LIBS := # blank, more will be added below
LDFLAGS := # blank, more will be added below
# ---- define objects from files in the SRC directory
GEN_OBJ_SRC := $(wildcard $(SRC)/*.cxx)
GEN_OBJ := $(notdir $(GEN_OBJ_SRC:%.cxx=%.o))
# this list may be manipulated in other segments further down
GEN_OBJ_PATHS := $(GEN_OBJ:%=$(BUILD)/%)
# --- all top level (added further down)
ALL_TOP_LEVEL := # blank, more will be added below
# _______________________________________________________________
# Add Top Level Objects
# --- stuff used for the c++ executable
# everything with this prefix will be built as an executable
EXE_PREFIX := ttree2hdf
ALL_EXE_SRC := $(wildcard $(SRC)/$(EXE_PREFIX)*.cxx)
ALL_EXE := $(notdir $(ALL_EXE_SRC:%.cxx=%))
ALL_EXE_PATHS := $(ALL_EXE:%=$(OUTPUT)/%)
# filter out the general objects
GEN_OBJ_PATHS := $(filter-out $(BUILD)/$(EXE_PREFIX)%.o,$(GEN_OBJ_PATHS))
# add to all top level
ALL_TOP_LEVEL += $(ALL_EXE_PATHS)
# _______________________________________________________________
# Add ROOT dicts
# Edit `DICT_FILES` if you want to add more dictionaries
DICT_FILES := $(INC)/Stl.h
TDICTS := $(notdir $(DICT_FILES:.h=Dict.o))
TDICT_PATHS := $(TDICTS:%=$(BUILD)/%)
GEN_OBJ_PATHS += $(TDICT_PATHS)
# prevent auto-deletion of dictionary objects
.SECONDARY: $(TDICT_PATHS)
# _______________________________________________________________
# Add Libraries
# --- load in root config
ROOTCFLAGS := $(shell root-config --cflags)
ROOTLIBS := $(shell root-config --libs)
# ROOTLIBS += -lCore -lTree -lRIO
ROOTLDFLAGS := $(shell root-config --ldflags)
CXXFLAGS += $(ROOTCFLAGS)
LDFLAGS += $(ROOTLDFLAGS)
LIBS += $(ROOTLIBS)
# --- add HDF5
ifndef HDF_PATH
HDF_INFO := $(shell h5c++ -showconfig | grep 'Installation point:')
HDF_PATH := $(strip $(shell echo $(HDF_INFO) | cut -d ':' -f 2 ))
ifndef HDF_PATH
$(error "couldn't find HDF, quitting")
endif
endif
# --- add boost
ifdef BOOST_PATH
CXXFLAGS += -I$(BOOST_PATH)/include
LIBS += -L$(BOOST_PATH)/lib -Wl,-rpath,$(BOOST_PATH)/lib
endif
LIBS += -lboost_program_options
CXXFLAGS += -I$(HDF_PATH)/include
LIBS += -L$(HDF_PATH)/lib -Wl,-rpath,$(HDF_PATH)/lib
LIBS += -lhdf5_cpp -lhdf5
# --- first call here
all: $(ALL_TOP_LEVEL)
# _______________________________________________________________
# Add Build Rules
# build exe
$(OUTPUT)/$(EXE_PREFIX)%: $(GEN_OBJ_PATHS) $(BUILD)/$(EXE_PREFIX)%.o
@mkdir -p $(OUTPUT)
@echo "linking $^ --> $@"
@$(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
# compile rule
$(BUILD)/%.o: %.cxx
@echo compiling $<
@mkdir -p $(BUILD)
@$(CXX) -c $(CXXFLAGS) $< -o $@
# --- ROOT dictionary generation
LINKDEF := $(SRC)/LinkDef.h
$(DICT)/%Dict.cxx: %.h $(LINKDEF)
@echo making dict $@
@mkdir -p $(DICT)
@rm -f $(DICT)/$*Dict.h $(DICT)/$*Dict.cxx
@rootcint -f $@ -c -I$(SRC) $(SRC)/$*.h $(LINKDEF)
@mkdir -p $(OUTPUT)
@mv -f $(DICT)/*.pcm $(OUTPUT)
$(BUILD)/%Dict.o: $(DICT)/%Dict.cxx
@mkdir -p $(BUILD)
@echo compiling dict $@
@$(CXX) -I. $(CXXFLAGS) $(ROOTCFLAGS) -c $< -o $@ 2> /dev/null
# use auto dependency generation
ALLOBJ := $(GEN_OBJ)
DEP := $(BUILD)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),rmdep)
include $(ALLOBJ:%.o=$(DEP)/%.d)
endif
endif
DEPTARGSTR = -MT $(BUILD)/$*.o -MT $(DEP)/$*.d
$(DEP)/%.d: %.cxx
@echo making dependencies for $<
@mkdir -p $(DEP)
@$(CXX) -MM -MP $(DEPTARGSTR) $(CXXFLAGS) $(PY_FLAGS) $< -o $@
# clean
.PHONY : clean rmdep all
CLEANLIST = *~ *.o *.o~ *.d core
clean:
rm -fr $(CLEANLIST) $(CLEANLIST:%=$(BUILD)/%) $(CLEANLIST:%=$(DEP)/%)
rm -fr $(BUILD) $(DICT) $(OUTPUT)
rmdep:
rm -f $(DEP)/*.d