-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
275 lines (272 loc) · 7.27 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
THISDIR=$(shell \pwd | sed 's%^.*/%%')
# fortran compiler
FC = gfortran
#
# general flags
compile = -c $<
output = -o $@
#
# options
options = -fimplicit-none
warnings = -W -Wall -Warray-temporaries -Wcharacter-truncation -Wfatal-errors \
-Wimplicit-interface -Wintrinsics-std -Wsurprising -Wuninitialized -pedantic
debug = -g -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow,denormal
#
# additional options for gfortran v4.5 and later
options_new = -std=f2018
warnings_new = -Wconversion-extra -Wimplicit-procedure -Winteger-division -Wreal-q-constant \
-Wrealloc-lhs-all -Wuse-without-only
debug_new = -fcheck=all
#
# concatenate options
options := $(options) $(options_new)
warnings := $(warnings) $(warnings_new)
debug := $(debug) $(debug_new)
#
# fortran compiler flags
FCFLAGS = $(includes) $(options) $(warnings) $(debug)
F77.FLAGS = -fd-lines-as-comments -std=legacy
F90.FLAGS =
FC.COMPILE = $(FC) $(compile) $(FCFLAGS)
FC.COMPILE.o = $(FC.COMPILE) $(output) $(F77.FLAGS)
FC.COMPILE.o.f90 = $(FC.COMPILE) $(output) $(F90.FLAGS)
#
# fortran linker flags
FLFLAGS = $(output) $^
FC.LINK = $(FC) $(FLFLAGS)
#
# define build directories
BINDIR := bin
OBJDIR := obj
#
# build source file lists
#
# program files (executable)
SRC.F77 = $(wildcard *.f)
SRC.F90 = $(wildcard *.f90)
# add SRCDIR if present
SRCDIR := src
ifneq ("$(strip $(wildcard $(SRCDIR)))","")
VPATH += $(subst $(subst ,, ),:,$(strip $(SRCDIR)))
SRC.F77 += $(wildcard $(SRCDIR)/*.f)
SRC.F90 += $(wildcard $(SRCDIR)/*.f90)
endif
SRC = $(SRC.F77) $(SRC.F90)
#
# "include" files (not executable, not compilable)
INCDIR := includes
# add INCDIR if present
ifneq ("$(strip $(wildcard $(INCDIR)))","")
VPATH += $(subst $(subst ,, ),:,$(strip $(INCDIR)))
includes = $(patsubst %,-I %,$(INCDIR))
INCS.F77 = $(wildcard $(INCDIR)/*.f)
INCS.F90 = $(wildcard $(INCDIR)/*.f90)
INCS. += $(patsubst $(INCDIR)/%.f, %, $(INCS.F77)) \
$(patsubst $(INCDIR)/%.f90, %, $(INCS.F90))
endif
#
# module files
# fortran module complier flags
FC.COMPILE.mod = $(FC.COMPILE) -o $(OBJDIR)/$*.o $(F90.FLAGS)
# build directory for compiled modules
MODDIR := mod
# source directory
MODDIR.in := modules
# add MODDIR.in if present
ifneq ("$(strip $(wildcard $(MODDIR.in)))","")
VPATH += $(subst $(subst ,, ),:,$(strip $(MODDIR.in)))
MODS.F77 = $(wildcard $(MODDIR.in)/*.f)
MODS.F90 = $(wildcard $(MODDIR.in)/*.f90)
MODS. += $(patsubst $(MODDIR.in)/%.f, %, $(MODS.F77)) \
$(patsubst $(MODDIR.in)/%.f90, %, $(MODS.F90))
endif
# add additional modules
MODS. +=
# add MODDIR to includes if MODS. not empty
ifneq ("$(MODS.)","")
includes:=$(includes) -J $(MODDIR)
endif
# build list of modules
MODS.mod = $(addsuffix .mod,$(MODS.))
MODS := $(addprefix $(MODDIR)/,$(MODS.mod))
#
# Add any external procudures below. Note: shared procedures should be included in a module
# unless written in a different language.
#
# function files
FUNDIR := functions
# add FUNDIR if present
ifneq ("$(strip $(wildcard $(FUNDIR)))","")
VPATH += $(subst $(subst ,, ),:,$(strip $(FUNDIR)))
FUNS.F77 = $(wildcard $(FUNDIR)/*.f)
FUNS.F90 = $(wildcard $(FUNDIR)/*.f90)
FUNS. += $(patsubst $(FUNDIR)/%.f, %, $(FUNS.F77)) \
$(patsubst $(FUNDIR)/%.f90, %, $(FUNS.F90))
endif
# add additional fucntions
FUNS. +=
#
# subroutine files
SUBDIR := subroutines
# add SUBDIR if present
ifneq ("$(strip $(wildcard $(SUBDIR)))","")
VPATH += $(subst $(subst ,, ),:,$(strip $(SUBDIR)))
SUBS.F77 = $(wildcard $(SUBDIR)/*.f)
SUBS.F90 = $(wildcard $(SUBDIR)/*.f90)
SUBS. += $(patsubst $(SUBDIR)/%.f, %, $(SUBS.F77)) \
$(patsubst $(SUBDIR)/%.f90, %, $(SUBS.F90))
endif
# add additional subroutines
SUBS. +=
#
# concatonate procedure lists (non-executables)
DEPS. = $(MODS.) $(SUBS.) $(FUNS.)
#
# build object lists
OBJS.F77 = $(SRC.F77:.f=.o)
OBJS.F90 = $(SRC.F90:.f90=.o)
OBJS.all = $(OBJS.F77) $(OBJS.F90)
OBJS.all := $(OBJS.all:$(SRCDIR)/%=%)
#
# dependencies (non-executables)
MODS. += piksrt_dim moon_calc dates
SUBS. += flmoon caldat
FUNS. += julday
DEPS. = $(MODS.) $(SUBS.) $(FUNS.)
DEPS.o = $(addsuffix .o,$(DEPS.))
OBJS.o = $(filter-out $(DEPS.o),$(OBJS.all))
DEPS := $(addprefix $(OBJDIR)/,$(DEPS.o))
OBJS := $(addprefix $(OBJDIR)/,$(OBJS.o))
#
# demo drivers
DEMOS=$(wildcard *.dem.f)
#
# executables
TARGET = badluk
DRIVERS = $(DEMOS:.dem.f=)
EXES = $(addprefix $(BINDIR)/,$(TARGET) $(DRIVERS))
#
# sub-programs
SUBDIRS :=
#
# recipes
all: $(EXES) $(SUBDIRS)
@/bin/echo -e "$(THISDIR) $@ done"
$(SUBDIRS):
@$(MAKE) --no-print-directory -C $@
#
# specific recipes
sort=piksr
$(BINDIR)/$(sort)%: $(addprefix $(OBJDIR)/, $(sort)%.dem.o $(sort)%.o $(sort)t_dim.o) | $(BINDIR)
@echo "compiling pick sort executable $@..."
$(FC.LINK)
$(BINDIR)/$(TARGET): $(addprefix $(OBJDIR)/, $(TARGET).o $(sort)4_1222.o) $(DEPS) | $(BINDIR)
@echo "compiling target executable $@..."
$(FC.LINK)
#
# generic recipes
$(BINDIR)/%: $(OBJDIR)/%.dem.o $(DEPS) | $(BINDIR)
@/bin/echo -e "\nlinking driver executable $@..."
$(FC.LINK)
$(OBJDIR)/%.dem.o: %.dem.f %.f $(MODS) | $(OBJDIR)
@/bin/echo -e "\ncompiling driver object $@..."
$(FC.COMPILE.o)
$(OBJDIR)/%.o: %.f $(MODS) | $(OBJDIR)
@/bin/echo -e "\ncompiling generic object $@..."
$(FC.COMPILE.o)
$(OBJDIR)/%.o: %.f90 $(MODS) | $(OBJDIR)
@/bin/echo -e "\ncompiling generic f90 object $@..."
$(FC.COMPILE.o.f90)
$(MODDIR)/%.mod: %.f | $(MODDIR)
@/bin/echo -e "\ncompiling generic module $@..."
$(FC.COMPILE.mod)
$(MODDIR)/%.mod: %.f90 | $(MODDIR)
@/bin/echo -e "\ncompiling generic f90 module $@..."
$(FC.COMPILE.mod)
#
# define directory creation
$(BINDIR):
@mkdir -v $(BINDIR)
$(OBJDIR):
@mkdir -v $(OBJDIR)
$(MODDIR):
ifeq ("$(wildcard $(MODS))",)
@echo "no modules specified"
else
@echo "creating $(MODDIR)..."
@mkdir -v $(MODDIR)
endif
# keep intermediate object files
.SECONDARY: $(DEPS) $(OBJS) $(MODS)
#
# recipes without outputs
.PHONY: all $(SUBDIRS) mostlyclean clean force out realclean distclean reset
#
# clean up
optSUBDIRS = $(addprefix $(MAKE) $@ --no-print-directory -C ,$(addsuffix ;,$(SUBDIRS)))
RM = @rm -vfrd
mostlyclean:
# remove compiled binaries
@echo "removing compiled binary files..."
$(RM) $(OBJDIR)/*.o
$(RM) $(OBJDIR)
$(RM) *.o *.obj
$(RM) $(MODDIR)/*.mod
$(RM) $(MODDIR)
$(RM) *.mod
$(RM) fort.*
@$(optSUBDIRS)
@echo "$(THISDIR) $@ done"
clean: mostlyclean
# remove binaries and executables
@/bin/echo -e "\nremoving compiled executable files..."
$(RM) $(BINDIR)/*
$(RM) $(BINDIR)
$(RM) *.exe
$(RM) *.out
@$(optSUBDIRS)
@echo "$(THISDIR) $@ done"
force: clean
# force re-make
@$(MAKE) --no-print-directory
out:
# remove outputs produced by executables
@/bin/echo -e "\nremoving output files..."
@$(optSUBDIRS)
@echo "$(THISDIR) $@ done"
realclean: clean out
# remove binaries and outputs
@$(optSUBDIRS)
distclean: realclean
# remove binaries, outputs, and backups
@/bin/echo -e "\nremoving backup files..."
# remove Git versions
$(RM) *.~*~
# remove Emacs backup files
$(RM) *~ \#*\#
# clean sub-programs
@$(optSUBDIRS)
@echo "$(THISDIR) $@ done"
reset: distclean
# remove untracked files
@/bin/echo -e "\nresetting repository..."
git reset HEAD
git stash
git clean -f
@$(optSUBDIRS)
@echo "$(THISDIR) $@ done"
#
# test the makefile
test: distclean all
@echo "$(THISDIR) $@ done"
#
# run executables
run: all
# run executables which do no require user input
@echo "running executables..."
$(addsuffix ;, \
$(addprefix ./$(BINDIR)/, \
$(TARGET) \
caldat \
piksrt ))
@$(optSUBDIRS)