-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (109 loc) · 5.89 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
# ******************************************************************************
# * VARIABLES *
# ******************************************************************************
DEBUG ?= false
FTNLIB ?= $(abspath ../fortranlib)
DEBG_OPTS := -g -fcheck=all
LANG_OPTS := -fopenmp -ffree-form -ffree-line-length-none -frecursive -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -fPIC
WARN_OPTS := -Wall -Wextra -Waliasing -Wcharacter-truncation -Wconversion-extra -Wimplicit-interface -Wimplicit-procedure -Wunderflow -Wtabs
OPTM_OPTS := -O2
MACH_OPTS := -march=native -m64
# ******************************************************************************
# * BINARIES *
# ******************************************************************************
CUT := $(shell which cut 2> /dev/null || echo "ERROR")
FC := $(shell which gfortran-mp-14 2> /dev/null || echo "ERROR")
GREP := $(shell which grep 2> /dev/null || echo "ERROR")
PYTHON3 := $(shell which python3.12 2> /dev/null || echo "ERROR")
RM := $(shell which rm 2> /dev/null || echo "ERROR")
# ******************************************************************************
# * DYNAMIC VARIABLES *
# ******************************************************************************
ifeq ($(DEBUG), true)
LANG_OPTS += $(DEBG_OPTS)
endif
# ******************************************************************************
# * CHECK BINARIES *
# ******************************************************************************
ifeq ($(CUT),ERROR)
$(error The binary "cut" is not installed)
endif
ifeq ($(FC),ERROR)
$(error The binary "fc" is not installed)
endif
ifeq ($(GREP),ERROR)
$(error The binary "grep" is not installed)
endif
ifeq ($(PYTHON3),ERROR)
$(error The binary "python3" is not installed)
endif
ifeq ($(RM),ERROR)
$(error The binary "rm" is not installed)
endif
# ******************************************************************************
# * CHECK PYTHON MODULES *
# ******************************************************************************
# ifneq ($(shell $(PYTHON3) -c "import numpy; print(0)" 2> /dev/null),0)
# $(error The Python module "numpy" is not installed)
# endif
# ******************************************************************************
# * DERIVED VARIABLES *
# ******************************************************************************
# SUFFIX ?= $(shell $(PYTHON3) -c "import sysconfig; print(sysconfig.get_config_var(\"EXT_SUFFIX\"))")
# ******************************************************************************
# * USER-SPECIFIED TARGETS *
# ******************************************************************************
# "gmake -r [all]" = "gmake -r compile" (default)
all: compile
# "gmake -r clean" = removes the compiled code
clean:
$(RM) -f convertBINtoPPM createFlood downscale *.mod *.o
$(MAKE) -r -C $(FTNLIB) FC=$(FC) PYTHON3=$(PYTHON3) clean
# "gmake -r compile" = compiles the code
compile: convertBINtoPPM \
createFlood \
downscale
# "gmake -r help" = print this help
help:
echo "These are the available options:"
$(GREP) -E "^# \"gmake -r " Makefile | $(CUT) -c 2-
# ******************************************************************************
# * ENVIRONMENT SETTINGS *
# ******************************************************************************
.SILENT: help
# ******************************************************************************
# * INTERNALLY-SPECIFIED TARGETS *
# ******************************************************************************
# NOTE: There was a bug in NumPy (using "meson" to build) where "f2py" would
# copy the file to a build folder and, therefore, the relative paths to
# external libraries would break. To work around this I prepend the
# current directory to the library path to make it an absolute path. See:
# * https://github.com/numpy/numpy/issues/25344
# NOTE: See https://numpy.org/doc/stable/f2py/buildtools/distutils-to-meson.html
$(FTNLIB)/%.mod \
$(FTNLIB)/%.o &: $(FTNLIB)/%.F90
$(MAKE) -r -C $(FTNLIB) DEBUG=$(DEBUG) FC=$(FC) PYTHON3=$(PYTHON3) $*.o
mod_funcs.mod \
mod_funcs.o &: $(FTNLIB)/mod_safe.mod \
mod_funcs.F90
$(FC) -c $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) -I$(FTNLIB) mod_funcs.F90
convertBINtoPPM.o: $(FTNLIB)/mod_safe.mod \
convertBINtoPPM.F90
$(FC) -c $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) -I$(FTNLIB) convertBINtoPPM.F90 -o $@
createFlood.o: $(FTNLIB)/mod_safe.mod \
mod_funcs.mod \
createFlood.F90
$(FC) -c $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) -I$(FTNLIB) createFlood.F90 -o $@
downscale.o: $(FTNLIB)/mod_safe.mod \
downscale.F90
$(FC) -c $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) -I$(FTNLIB) downscale.F90 -o $@
convertBINtoPPM: $(FTNLIB)/mod_safe.o \
convertBINtoPPM.o
$(FC) $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) convertBINtoPPM.o $(FTNLIB)/mod_safe.o -o $@
createFlood: $(FTNLIB)/mod_safe.o \
mod_funcs.o \
createFlood.o
$(FC) $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) createFlood.o $(FTNLIB)/mod_safe.o mod_funcs.o -o $@
downscale: $(FTNLIB)/mod_safe.o \
downscale.o
$(FC) $(LANG_OPTS) $(WARN_OPTS) $(OPTM_OPTS) $(MACH_OPTS) downscale.o $(FTNLIB)/mod_safe.o -o $@