-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
147 lines (106 loc) · 3.61 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
#------------------------------------------------------------------------------
# Description: Makefile to build analyzers
# Created: Wed Jul 15 17:37:36 2015 by mkanalyzer.py
# Author: Daniele Marconi
#------------------------------------------------------------------------------
ifndef ROOTSYS
$(error *** Please set up Root)
endif
name := analyzer
# Sub-directories
srcdir := src
tmpdir := tmp
libdir := lib
incdir := include
$(shell mkdir -p tmp)
$(shell mkdir -p lib)
# Set this equal to the @ symbol to suppress display of instructions
# while make executes
ifdef verbose
AT :=
else
AT := @
endif
# Get list of sources to be compiled into applications
appsrcs := $(wildcard *.cc)
# Construct list of applications
applications := $(appsrcs:.cc=)
# Construct names of object models from list of sources
appobjs := $(addprefix $(tmpdir)/,$(appsrcs:.cc=.o))
# Get list of sources to be made into shared libraries
cppsrcs := $(wildcard $(srcdir)/*.cpp)
cppobjs := $(subst $(srcdir)/,$(tmpdir)/,$(cppsrcs:.cpp=.o))
ccsrcs := $(wildcard $(srcdir)/*.cc)
ccobjs := $(subst $(srcdir)/,$(tmpdir)/,$(ccsrcs:.cc=.o))
objects := $(cppobjs) $(ccobjs)
sharedlib := $(libdir)/lib$(name).so
# Display list of applications to be built
#say := $(shell echo -e "Apps: $(applications)" >& 2)
#say := $(shell echo -e "AppObjs: $(appobjs)" >& 2)
#say := $(shell echo -e "Objects: $(objects)" >& 2)
#$(error bye!)
#-----------------------------------------------------------------------
# Define which compilers and linkers to use
# C++ Compiler
CXX := g++
# Define paths to be searched for C++ header files (#include ....)
CPPFLAGS:= -I. -I$(incdir) -I$(srcdir) $(shell root-config --cflags)
# Define compiler flags to be used
# -c perform compilation step only
# -g include debug information in the executable file
# -O2 optimize
# -ansi require strict adherance to C++ standard
# -Wall warn if source uses any non-standard C++
# -pipe communicate via different stages of compilation
# using pipes rather than temporary files
CXXFLAGS:= -c -g -O2 -ansi -Wall -pipe -fPIC
# C++ Linker
# set default path to shared library
LD := g++ -Wl,-rpath,$(PWD)/$(libdir)
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
LDSHARED := $(LD) -dynamiclib
else
LDSHARED := $(LD) -shared
endif
# Linker flags
LDFLAGS := -g
# Libraries
LIBS := $(shell root-config --libs) -L$(libdir) -lMinuit -lMathMore -lMathCore
# Rules
# The structure of a rule is
# target : source
# command
# The command makes a target from the source.
# $@ refers to the target
# $< refers to the source
all: $(sharedlib) $(applications)
bin: $(applications)
lib: $(sharedlib)
# Syntax:
# list of targets : target pattern : source pattern
# Make applications depend on shared libraries to force the latter
# to be built first
$(applications) : % : $(tmpdir)/%.o $(sharedlib)
@echo "---> Linking $@"
$(AT)$(LD) $(LDFLAGS) $< $(LIBS) -lanalyzer -o $@
$(sharedlib) : $(objects)
@echo "---> Linking `basename $@`"
$(AT)$(LDSHARED) $(LDFLAGS) -fPIC $(objects) $(LIBS) -o $@
$(cppobjs) : $(tmpdir)/%.o : $(srcdir)/%.cpp
@echo "---> Compiling `basename $<`"
$(AT)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ >& $*.FAILED
$(AT)rm -rf $*.FAILED
$(ccobjs) : $(tmpdir)/%.o : $(srcdir)/%.cc
@echo "---> Compiling `basename $<`"
$(AT)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ >& $*.FAILED
$(AT)rm -rf $*.FAILED
$(appobjs) : $(tmpdir)/%.o : %.cc
@echo "---> Compiling `basename $<`"
$(AT)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $< -o $@ >& $*.FAILED
$(AT)rm -rf $*.FAILED
# Define clean up rules
clean :
rm -rf $(tmpdir)/*.o
veryclean :
rm -rf $(tmpdir)/*.o $(applications) $(libdir)/*.so