-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakerules
192 lines (161 loc) · 5.86 KB
/
Makerules
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
#!/bin/env make
#
# created by Sebastian Ehlert in March 2018 (v 2.2)
# 2.0: recreated from scratch
# 2.1: refined the generation of dependencies, since it crashed if not
# done in the main directory
# 2.2: modified the clean command, to be less severe
#
###------------------------------------------------------------------------###
# a nice trick to print all 'important' targets this Makefile can produce
.PHONY: help
# would be made by default if there is no .DEFAULT_GOAL set
help:
@echo "This Makefile kindly provides to you:" && \
$(MAKE) --print-data-base --question | \
awk '/^[^.%][-A-Za-z0-9]*:/ {print substr($$1, 1, length($$1)-1)}' | \
sort | pr --omit-pagination --width=80 --columns=4
##############################################################################
## only edit this file if you know what you are doing ##
##############################################################################
###------------------------------------------------------------------------###
# set the path for make to search in:
vpath % $(SRCDIR):$(XTBDIR)
###------------------------------------------------------------------------###
# to use the Intel-Compiler please set MKLROOT somewhere
ifeq ($(OSTYPE),LINUXI)
FC := ifort
CC := icc
# compile flags
FCFLAGS := -O -axAVX -qopenmp -fpp -r8
FCFLAGS += -module $(MODDIR)
FCFLAGS += -I$(INCDIR) \
-I$(MKLROOT)/include/intel64/lp64 \
-I$(MKLROOT)/include
CCFLAGS := -O -DLINUX
CCFLAGS += -D_Float128=__float128
# check for debug build
ifeq ($(DEBUG_BUILD),yes)
FCFLAGS += -g -traceback -check all -debug all
CCFLAGS += -g -DEBUG
endif # DEBUG
# linker
FL := ifort
# general flags for linking, this is build incremental to get an overview
FLFLAGS := -static -fopenmp
# add path to libraries
FLFLAGS += -L$(MKLROOT)/lib/intel64 \
-L$(LIBDIR)
# add path to modules
FLFLAGS += -module $(MODDIR)
# add path to include files
FLFLAGS += -I$(MKLROOT)/include/intel64/lp64 \
-I$(MKLROOT)/include
# add special linker options for the MKL library
FLFLAGS += -Wl,--start-group \
-lmkl_intel_lp64 \
-lmkl_core \
-lmkl_intel_thread \
-Wl,--end-group
endif # LINUXI
###------------------------------------------------------------------------###
# set the targets
.PHONY: all library program depend
# this is the first, so it will be made by default
all: library
all: program
# we can also enforce it by
.DEFAULT_GOAL=all
###------------------------------------------------------------------------###
# generate the name of the program and the library
LIBNAME := $(LIBDIR)/lib$(NAME).a
PROGNAME := $(EXEDIR)/$(NAME)
ifeq ($(BUILD_IN_BIN),yes)
PROGNAME += $(HOME)/bin/$(NAME)
endif # BIN
# set up the dependencies
ifeq ($(USE_DEPENDENCIES),yes)
DEPS := $(patsubst %.o,$(DEPDIR)/%.d,\
$(OBJSP) $(OBJS3) $(OBJS2) $(OBJS1) $(OBJS0))
endif # DEP
# put all objects in the build directory
OBJS3 := $(addprefix $(OUTDIR)/,$(OBJS3))
OBJS2 := $(addprefix $(OUTDIR)/,$(OBJS2))
OBJS1 := $(addprefix $(OUTDIR)/,$(OBJS1))
OBJS0 := $(addprefix $(OUTDIR)/,$(OBJS0))
OBJSP := $(addprefix $(OUTDIR)/,$(OBJSP))
# libraries
LIBS := $(addprefix -l,$(NAME) $(LIBS))
# we merge all files for convinience
OBJS:= $(OBJSP) $(OBJS3) $(OBJS2) $(OBJS1) $(OBJS0)
# everything should also dependent on the local Makefile
ifeq ($(MAKEFILE_DEP),yes)
MAKEDEP := Makefile
endif # DEP
ifeq ($(DEP_MAKEFILE_DEP),yes)
DEPMAKEDEP := Makefile
endif # DEP
###------------------------------------------------------------------------###
# set up the targets for all
library: $(LIBNAME)
program: $(PROGNAME)
ifeq ($(USE_DEPENDENCIES),yes)
depend: $(DEPS)
endif # DEP
###------------------------------------------------------------------------###
# define how to actually generate the library and the program
$(LIBNAME): $(OBJS3) $(OBJS2) $(OBJS1) $(OBJS0)
@echo "creating $@" && \
$(AR) rv $@ $? && \
echo "finished building $@ successfully"
# build everything together
$(PROGNAME): $(LIBNAME) $(OBJSP)
@echo "linking $@" && \
$(FL) $(OBJSP) $(LIBS) $(FLFLAGS) -o $@ && \
echo "finished linking $@ successfully"
###------------------------------------------------------------------------###
# first deactivate some implicit rules
%.o : %.mod
%.f : %.F
# now the rules to actually build the object files
$(OUTDIR)/%.o: %.f $(MAKEDEP)
@echo "making $@ from $<" && \
$(FC) $(FCFLAGS) -c $< -o $@
$(OUTDIR)/%.o: %.f90 $(MAKEDEP)
@echo "making $@ from $<" && \
$(FC) $(FCFLAGS) -c $< -o $@
$(OUTDIR)/%.o: %.c $(MAKEDEP)
@echo "making $@ from $<" && \
$(CC) $(CCFLAGS) -c $< -o $@
ifeq ($(USE_DEPENDENCIES),yes)
# this is a crutial part of this Makefile!
-include $(DEPS)
$(OUTDIR)/%.o: $(DEPDIR)/%.d
# now for the dependencies,
# we use a script hacked together in ruby (v 2.5.0) for this job
$(DEPDIR)/%.d: %.f90 $(DEPMAKEDEP)
@echo "generating dependencies for $<" && \
deps=`ruby $(MAKEDIR)/depend.rb $<` && \
echo "\$$(OUTDIR)/$*.o:$$deps" > $@
$(DEPDIR)/%.d: %.f $(DEPMAKEDEP)
@echo "generating dependencies for $<" && \
deps=`ruby $(MAKEDIR)/depend.rb $<` && \
echo "\$$(OUTDIR)/$*.o:$$deps" > $@
# no hacks needed for C/C++ dependencies
$(DEPDIR)/%.d: %.c $(DEPMAKEDEP)
@echo "generating dependencies for $<" && \
$(CC) $(CPPFLAGS) -MM $< > $@
$(DEPDIR)/%.d: %.cc $(DEPMAKEDEP)
@echo "generating dependencies for $<" && \
$(CXX) $(CPPFLAGS) -MM $< > $@
endif # DEP
###------------------------------------------------------------------------###
# clean up, at the right places
.PHONY: clean distclean veryclean
clean:
$(RM) $(filter %.o,$(OBJS))
distclean:
$(RM) $(OUTDIR)/*.o $(MODDIR)/*.mod $(PROGNAME) $(LIBNAME)
# in case you use the dependency build you can get rid of those files to
veryclean: distclean
$(RM) $(DEPDIR)/*.d