-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
245 lines (176 loc) · 5.6 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
241
242
243
244
# This makefile includes one optional argument variable: MODE, defining the compilation model
# By default, MODE = standard, but two other modes can be specified while calling make: "debug" and "optim"
# make MODE=standard (standard options)
# make MODE=optim (for fast use. DEFAULT MODE)
# make MODE=debug (extra debugging options)
#################################################
# Main customization variables (default values) #
#################################################
# Fortran compiler
FC ?= gfortran
# Compilation mode (default):
MODE = optim
# Path of netCDF library (must contains subrepertories lib/ and include/)
NCPATH ?= /usr
#############################
# Compiler-dependent flags: #
#############################
ifeq ($(findstring pgfortran, $(FC)), pgfortran)
#=========================#
# PGI compiler: pgfortran #
#=========================#
# Fortran language option
lang_flags = -Mfreeform
# Error and warning options:
ifeq ($(MODE), optim)
warn_flags = -Minform=severe
else ifeq ($(MODE), debug)
warn_flags = -Minform=inform
else # assume standard mode
warn_flags = -Minform=warn
endif
# Debugging options:
ifeq ($(MODE), debug)
debug_flags = -g
endif
# Code generation options:
ifneq ($(MODE), optim)
code_flags = -Mbounds
endif
ifeq ($(MODE), debug)
code_flags += -traceback
endif
# Optimization options:
ifeq ($(MODE), debug)
optim_flags = -O0
else ifeq ($(MODE), optim)
optim_flags = -O4 -fast
else
# if none of previous: assume standard mode:
optim_flags = -O2
endif
else ifeq ($(findstring gfortran, $(FC)), gfortran)
#========================#
# GNU compiler: gfortran #
#========================#
# Fortran language options:
lang_flags = -ffree-form -std=gnu
# Error and warning options:
ifeq ($(MODE), debug)
warn_flags = -Wall -Wconversion-extra -Wimplicit-interface -Wunderflow -Wextra -Wunreachable-code
else
warn_flags = -Waliasing -Wampersand -Wline-truncation -Wcharacter-truncation -Wconversion -Wunderflow -Wunreachable-code
ifeq ($(MODE), standard)
warn_flags += -Wpedantic -Wunused-dummy-argument
endif
endif
# Debugging options:
ifneq ($(MODE), optim)
debug_flags = -ffpe-trap=invalid,zero,overflow
endif
# Code generation options:
ifneq ($(MODE), optim)
code_flags = -fbounds-check
endif
ifeq ($(MODE), debug)
code_flags += -fbacktrace -g3
endif
# Optimization options:
ifeq ($(MODE), debug)
optim_flags = -O0 -fstack-protector-all
else ifeq ($(MODE), optim)
optim_flags = -O3
else
# if none of previous: assume standard mode:
optim_flags = -O1
endif
else ifeq ($(findstring ifort, $(FC)), ifort)
#========================
# Intel compiler: ifort #
#========================
# Fortran langauge options:
lang_flags = -free -132
# Error and warning options:
ifeq ($(MODE), debug)
warn_flags = -warn all
else
warn_flags = -warn general,usage,declaration,truncated_source,ignore_loc
endif
# Debugging options:
ifeq ($(MODE), debug)
debug_flags = -debug full
endif
# Options at run time
ifeq ($(MODE), debug)
code_flags = -check all -fp-stack-check -traceback
else ifeq ($(MODE), standard)
code_flags = -check bounds
endif
# Optimization options:
ifeq ($(MODE), debug)
optim_flags = -O0 -fstack-protector-all -fstack-security-check
else ifeq ($(MODE), optim)
optim_flags = -Ofast
else
# if none of previous: assume standard mode:
optim_flags = -O1
endif
endif
########################
# LIBRARY and INCLUDE: #
########################
# NetCDF library:
inc_flags += -I$(NCPATH)/include
lib_flags += -L$(NCPATH)/lib
NETCDF_FLAGS ?= -lnetcdf -lnetcdff
##############################################
# Complete list of fortran compilation flags #
##############################################
main_flags = $(lang_flags) $(warn_flags) $(debug_flags) $(code_flags) $(optim_flags)
FFLAGS = $(main_flags) $(inc_flags) $(lib_flags) $(NETCDF_FLAGS)
#############
# Root path #
#############
# Check if path assignment uses correct path
# If not, add 'updatepath' to the executable dependencies
# get root path (remove 'source' from current directory path)
pathcommand = character(len=*), parameter:: root_path = "$(CURDIR:source=)"
# get path assignment command (last line of 'path.inc' file)
currpathcommand = $(shell tail -1 path.inc)
ifneq ($(pathcommand), $(currpathcommand))
pathsource = updatepath path.inc
else
pathsource = path.inc
endif
#############################################################################
# Specific executable making rule:
shp2grid: shp2grid.o shp2grid_functions.o shapefile_io_module.o netcdf_output.o geography.o miscellaneous_functions.o scan_arguments.o
$(FC) $^ -o $@ $(FFLAGS)
test_read_shapefile: test_read_shapefile.o shapefile_io_module.o miscellaneous_functions.o
$(FC) $^ -o $@ $(FFLAGS)
# Redefine implicit rule to for making objects:
%.o: %.f90
$(FC) $< -o $@ -c $(FFLAGS)
# Additional dependencies
test_read_shapefile.o: shapefile_io_module.o miscellaneous_functions.o
netcdf_output.o: geography.o miscellaneous_functions.o
shp2grid_functions.o: netcdf_output.o geography.o
shp2grid.o: shp2grid_functions.o shapefile_io_module.o netcdf_output.o geography.o miscellaneous_functions.o scan_arguments.o $(pathsource)
############################
# Update root path command #
############################
# create path.inc file if it doesn't exist
path.inc:
touch $@
.PHONY: updatepath # make sure to always execute that command when called
updatepath:
echo '! File automatically generated by `make`' > path.inc
echo '$(pathcommand)' >> path.inc
#############################################################################
check:
@echo "$(FC) $(FFLAGS)"
.PHONY: clean clc
clean:
rm -f *.o *.mod
clc:
rm -f *.o *.mod shp2grid test_read_shapefile