-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (96 loc) · 3.87 KB
/
Makefile
File metadata and controls
123 lines (96 loc) · 3.87 KB
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
#
# Makefile
#
# wlcsim
#
# Author: Bruno Beltran <brunobeltran0@gmail.com>
#
# # replaced rm **.o with more portable find commands
# # and regex search =~ in distclean with manual check for Y/y
SHELL:=/bin/bash
# .SHELLFLAGS="-O extglob -c"
# script to automatically generate dependencies
MAKEDEPEND=./fort_depend.py
# $(DEP_FILE) is a .dep file generated by fort_depend.py
DEP_FILE = wlcsim.dep
# compiler
FC = mpifort
# FC = $(shell if [[ type mpifort >/dev/null 2>&1 & ]]; then echo "mpifort"; else; echo "gfortran"; fi)
#TODO: fallback to gfortran gracefully, maybe with a dummy mpi.mod file?
ifeq ($(FC), mpifort)
MPI_FLAGS = -DMPI_VERSION
else
MPI_FLAGS =
endif
# compile flags
INCLUDE_DIRS = -Isrc -Isrc/third_party/FLAP/exe/mod -Isrc/third_party
DEBUGFLAGS = -ggdb -Jsrc ${INCLUDE_DIRS} -cpp
FASTFLAGS = -O3 -Jsrc ${INCLUDE_DIRS} -cpp
PEDANTICFLAGS = -ggdb -Jsrc ${INCLUDE_DIRS} -cpp -fcheck=all -Wall -pedantic -fall-intrinsics -Wno-surprising -Waliasing -Wconversion-extra -Wcompare-reals -Warray-temporaries -Warray-bounds -Wattributes -Wextra # need instrincis because need sizeof (if you don't have sizeof, just comment out read/writeBinary in params.f03), Wno-surprising to enforce Werror even though gfortran has a bug https://gcc.gnu.org/ml/fortran/2013-08/msg00050.html
FCFLAGS = ${PEDANTICFLAGS}
# link flags
# FLFLAGS = -L/usr/lib/lapack -llapack
FLFLAGS = -L/usr/local/lib/lapack -llapack
# all non-legacy and non-test files should be compiled into wlcsim
SRC := $(shell find "src" -type f -name '*.f*' \
-not -path "src/legacy/*" \
-not -path "src/tests/*" \
-not -path "src/third_party/FLAP/*" \
-not -path "src/third_party/mersenne_twister.f90" \
-not -path '*/\.*' )
# takes each *.f* -> *.o
OBJ := $(addsuffix .o,$(basename $(SRC))) src/third_party/mersenne_twister.o
TEST := $(shell find "src/tests" -type f -name '*.f*')
# program name
PROGRAM = wlcsim.exe
# by default, compile only
all: $(PROGRAM) flap depend
# a target to just run the main program
run: $(PROGRAM) dataclean
./$(PROGRAM)
# target to build main program, depends on all object files, and on the
# constructed makefile output
$(PROGRAM): flap depend dummy_prog
# ugly line, needs to ask for FLAP objects at runtime, there's probably a better
# way to do this
dummy_prog: $(OBJ)
$(FC) $(FCFLAGS) -o $(PROGRAM) $^ $(INCLUDE_DIRS) $(shell find "src/third_party/FLAP/exe/obj" -type f -not -path "src/third_party/FLAP/exe/obj/test_minimal.o") $(FLFLAGS)
src/third_party/mersenne_twister.o: src/third_party/mersenne_twister.f90
$(FC) -c -fdefault-real-8 $(FCFLAGS) src/third_party/mersenne_twister.f90 -o src/third_party/mersenne_twister.o
doc:
make -C doc html
# build third party dependencies that require "make" by hand
FLAP_DIR = src/third_party/FLAP
flap: flap_exists $(shell find ${FLAP_DIR} -type f -name '*.f*')
make -C ${FLAP_DIR}
flap_exists: ${FLAP_DIR}
git submodule update --init --recursive
# Make dependencies, easier to type
depend: $(DEP_FILE)
# this forces the "included" part of makefile itself to be rebuilt whenever the
# corresponding src files change, or when the Makefile itself changes
# While this is useful, it will force the dependency checker to run even if we
# only want to do e.g. make clean.
$(DEP_FILE): $(SRC) Makefile
@echo "Making dependencies!"
$(MAKEDEPEND) -w -o $(DEP_FILE) -f $(SRC) -c "$(FC) -c $(FCFLAGS) $(MPI_FLAGS)"
include $(DEP_FILE)
.PHONY: depend clean destroy dataclean
clean: dataclean
find src \( -iname '*.o' -or -iname '*.mod' \) -delete
rm -f ${PROGRAM} wlcsim.dep
dataclean:
mkdir -p data trash
mv data "trash/`date`"
mkdir -p data
DEATH=rm -rf trash data savedata par-run-dir.*
distclean: clean
@echo "About to destroy all simulation data, are you sure? ";
read REPLY; \
echo ""; \
if [[ "$${REPLY:0:1}" == "Y" || "$${REPLY:0:1}" == "y" ]]; then \
echo 'Running `${DEATH}`'; \
${DEATH}; \
else \
echo 'Canceling data deletion!'; \
fi