forked from mnycz/Summer2022_solid_proton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
240 lines (212 loc) · 7.05 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# This Makefile shows how to compile all C++, C and Fortran
# files found in $(SRCDIR) directory.
# Linking is done with g++. Need to have $CERN_ROOT and $ROOTSYS defined
###################################################################
MYOS := $(shell uname)
ARCH := $(shell arch)
USER := $(shell whoami)
MYHOST := $(shell hostname -s)
##################################################################
VERSION = 1.0
TARGET = EAll
EXECFILE = eAll.$(MYOS).$(ARCH).exe
SRCDIR := src
INCDIR := include
MainFile := SoLID_d_u_analysis.cpp
#LHAPDF=/work/eic3/users/xiaochao/lhapdf630
LHAPDF=/work/eic3/users/xiaochao/lhapdf640/
OTHERINC := -I${LHAPDF}/include
OTHERLIBS := -L${LHAPDF}/lib -lLHAPDF
###################################################################
TARGETLIB = $(TARGET)_v$(VERSION)
OBJDIR := obj.${MYOS}.$(ARCH)
###################################################################
#in the darwin machines, ar cmd has something wrong!!!
#I switch to libtool
#USAGE: libtool -static -o out.lib ObjList.o
AR := ar r
ifeq ($(MYOS),Darwin)
AR := libtool -static -o
endif
###################################################################
ifeq ($(ARCH),i686)
####
MODE := -m32
GPPFLAGS := -M
CXX := g++
FF := g77
CXXFLAGS := -Wall -O3 -g -Wno-deprecated $(MODE) -I$(INCDIR) $(OTHERINC)
CFLAGS := -Wall -O3 -g $(MODE) -I$(INCDIR) $(OTHERINC)
FFLAGS := -Wall -O3 -g $(MODE) -I$(INCDIR) $(OTHERINC)
LD := g++
LDFLAGS := -O3 -g $(MODE)
SYSLIBS := -lstdc++
else
###################################################################
###take care of 64 bit compiler stuff, for -m64 use gfortran while g77 for -m32
###########ifeq ($(ARCH),x86_64)############
ifeq ($(COMPILER_BIT),32)
MODE := -m32
FF := g77
else
MODE := -m64 -std=c++11
FF := gfortran
endif
GPPFLAGS := -M
CXX := g++
CXXFLAGS := -Wall -O3 -g -Wno-deprecated $(MODE) -I$(INCDIR) $(OTHERINC)
CFLAGS := -Wall -O3 -g $(MODE) -I$(INCDIR) $(OTHERINC)
FFLAGS := -Wall -O3 -g $(MODE) -I$(INCDIR) $(OTHERINC)
LD := g++
LDFLAGS := -O3 -g $(MODE)
SYSLIBS := -lstdc++
endif
###################################################################
#you can specify the .SUFFIXES
.SUFFIXES: .C .c .CC .cc .CPP .cpp .CXX .cxx .F .f
.PHONY: all clean test
VPATH := $(SRCDIR):$(INCDIR):$(OTHERINC)
###################################################################
#generate obj file list
FSOURCES := $(wildcard $(SRCDIR)/*.[Ff])
CSOURCES := $(wildcard $(SRCDIR)/*.[Cc])
CSOURCES += $(wildcard $(SRCDIR)/*.[Cc][Cc])
CSOURCES += $(wildcard $(SRCDIR)/*.[Cc][XxPp][XxPp])
SOURCES := $(FSOURCES) $(CSOURCES)
#add .o to all the source files
#an example of replace/patrern replace statement
#######OBJS = $(OBJS:.f=.o)#######
OBJS := $(addsuffix .o, $(basename $(SOURCES)))
OBJS := $(patsubst $(SRCDIR)/%.o,$(OBJDIR)/%.o,$(OBJS))
#do not make dependence for fortran code
COBJS := $(addsuffix .o, $(basename $(CSOURCES)))
COBJS := $(patsubst $(SRCDIR)/%.o,$(OBJDIR)/%.o,$(COBJS))
DEPS := $(subst .o,.d,$(COBJS))
MainObj := $(OBJDIR)/$(addsuffix .o, $(basename $(MainFile)))
###################################################################
ifneq ($(FSOURCES),)
ifeq ($(FF),gfortran)
SYSLIBS += -lgfortran
else
SYSLIBS += -lg2c
endif
endif
###################################################################
ROOTCFLAGS := $(shell root-config --cflags)
ROOTLIBS := $(shell root-config --libs)
ROOTGLIBS := $(shell root-config --glibs)
LIBS = $(ROOTLIBS) $(SYSLIBS)
GLIBS = $(ROOTGLIBS) -lMinuit $(SYSLIBS)
ifneq ($(FSOURCES),)
ifdef CERN_ROOT
FFLAGS += -I$(CERN_ROOT)/include
GLIBS += -L$(CERN_ROOT)/lib -lpdflib804 -lmathlib -lphtools \
-lgeant321 -lpawlib -lgraflib -lgrafX11 -lpacklib -lkernlib
endif
endif
CXXFLAGS += $(ROOTCFLAGS)
LDFLAGS += $(GLIBS) $(OTHERLIBS)
###################################################################
all: exe
# Make the $(TARGET).d file and include it.
$(OBJDIR)/%.d: %.c
@echo Making dependency for file $< ......
@set -e;\
$(CXX) $(GPPFLAGS) $(CXXFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
$(OBJDIR)/%.d: %.C
@echo Making dependency for file $< ......
@set -e;\
$(CXX) $(GPPFLAGS) $(CXXFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
$(OBJDIR)/%.d: %.cc
@echo Making dependency for file $< ......
@set -e;\
$(CXX) $(GPPFLAGS) $(CXXFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
$(OBJDIR)/%.d: %.cpp
@echo Making dependency for file $< ......
@set -e;\
$(CXX) $(GPPFLAGS) $(CXXFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
$(OBJDIR)/%.d: %.cxx
@echo Making dependency for file $< ......
@set -e;\
$(CXX) $(GPPFLAGS) $(CXXFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
#there is a problem to build dependency for fortran code...
$(OBJDIR)/%.d: %.f
@echo Making dependency for file $< ......
@set -e;\
$(FF) $(GPPFLAGS) -cpp $(FFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
@-rm -f $*.o
$(OBJDIR)/%.d: %.F
@echo Making dependency for file $< ......
@set -e;\
$(FF) $(GPPFLAGS) -cpp $(FFLAGS) -w $< |\
sed 's!$*\.o!$(OBJDIR)/& $@!' >$@;\
[ -s $@ ] || rm -f $@
@-rm -f $*.o
ifneq ($(DEPS),)
-include $(DEPS)
endif
##########################################################
lib: $(OBJDIR) $(OBJS)
@rm -f $(OBJDIR)/lib$(TARGETLIB).a
@$(AR) $(OBJDIR)/lib$(TARGETLIB).a $(OBJS)
@if [ -e $(OBJDIR)/lib$(TARGETLIB).a ] ; then echo "Finish creating target lib" $(OBJDIR)/lib$(TARGETLIB).a ;fi
# @libtool -static -o $(OBJDIR)/lib$(TARGETLIB).a $(OBJS)
# @ar r $(OBJDIR)/lib$(TARGETLIB).a $(OBJS)
exe: lib $(MainObj)
# @if [ ! -d Graph ]; then mkdir -p Graph; fi
$(LD) -o $(EXECFILE) $(MainObj) -L$(OBJDIR) -l$(TARGETLIB) $(LDFLAGS)
@echo "Linking $(EXECFILE) ...done!"
##########################################################
$(OBJDIR)/%.o: %.F
@echo Compiling $< ......
@$(FF) -c $< -o $@ $(FFLAGS)
$(OBJDIR)/%.o: %.f
@echo Compiling $< ......
@$(FF) -c $< -o $@ $(FFLAGS)
$(OBJDIR)/%.o: %.c
@echo Compiling $< ......
@$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJDIR)/%.o: %.C
@echo Compiling $< ......
@$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJDIR)/%.o: %.cxx
@echo Compiling $< ......
@$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJDIR)/%.o: %.cc
@echo Compiling $< ......
@$(CXX) -c $< -o $@ $(CXXFLAGS)
$(OBJDIR)/%.o: %.cpp
@echo Compiling $< ......
@$(CXX) -c $< -o $@ $(CXXFLAGS)
##########################################################
$(OBJDIR):
@if [ ! -d $(OBJDIR) ] ; then mkdir -p $(OBJDIR) ;fi
clean:
@rm -f $(OBJS) $(DEPS) $(OBJDIR)/lib$(TARGETLIB).a
@rm -f *~ *# $(EXECFILE) */*~ */*#
test:
@echo \\MYOS\:$(MYOS) \\ARCH\:$(ARCH)
@echo \\CFLAGS\:$(CFLAGS)
@echo \\CXXFLAGS\:$(CXXFLAGS)
@echo \\FFLAGS\:$(FFLAGS)
@echo \\LDFLAGS\:$(LDFLAGS)
@echo \\sources\: $(SOURCES)
@echo \\objs\: $(OBJS)
@echo \\dependencies: \$(DEPS)
help: test
env: test
#@echo \\sources1\: $(SOURCES1)
#@echo \\obj1\: $(OBJS1)
##########################################################