-
Notifications
You must be signed in to change notification settings - Fork 49
/
Makefile
executable file
·241 lines (204 loc) · 6.93 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
#================================================================#
# LaGriT Makefile
# -------------------------------------------------------------- #
#
# Targets:
# - release : build a LaGriT binary with shared libs
# - static : build a LaGriT binary with static libs
# - exodus : build the Exodus library
# - test : run the LaGriT test suite
# - help : show a help screen
# - header : build src/lagrit.h header file
# - clean : remove all object and mod files
# - clobber : remove all object and mod files *and* library
#
# Variables:
# CC (default: gcc) : C source compiler
# FC (default: gfortran) : Fortran source compiler
# FC90 (default: gfortran) : Fortran90 source compiler
# WITH_EXODUS (default: 1) : Build with or without Exodus
# DEBUG (default: 0) : Built in debug (1) or optimized (0) mode
# EXO_LIB_DIR (default: LAGRIT_ROOT_DIR/seacas/lib) : ExodusII library location
# EXE_NAME (default: src/lagrit) : binary filename for LaGriT
# EXO_CMAKE_FLAGS (default: none) : Add custom CMake flags to pass to cmake-exodus
#================================================================#
# TODO:
# - Add support for 32 bit machines
CC := gcc
CXX := g++
FC := gfortran
FC90 := $(FC)
OBJDIR := objects/
WITH_EXODUS := 1
# Detect 64 or 32 bit arch; detect OS name
BIT_SIZE := $(shell getconf LONG_BIT)
OPSYS := $(shell uname -s)
MAJOR_VERSION := 3
MINOR_VERSION := 320
BUILD_DATE := $(shell date +%Y/%m/%d)
BUILD_TYPE := Release
EXE_NAME := src/lagrit
EXO_BUILD_DIR := $(shell pwd)
EXO_LIB_DIR := $(shell pwd)/seacas/lib
EXO_CMAKE_FLAGS :=
LG_UTIL_LIB := lg_util_lib.a
SRC_LIB := lagrit_lib.a
define LAGRIT_H_TEXT
c
c----------------------------------------------------------------
c Auto-generated LaGriT program banner
c
c Substitute the TAG strings with Date and Linux, Darwin, WIN, etc.
c Compile library with updated lagrit.h used in writinit()
c This template is preserved in lagrit.template.h
c----------------------------------------------------------------
c
integer v_major, v_minor
parameter (v_major=$(MAJOR_VERSION))
parameter (v_minor=$(MINOR_VERSION))
c
character*22 date_compile
character*8 os_name
character*16 my_name
c
data my_name /'lagrit'/
c os_name is used to find and write OS related files
c make sure it is a version recognized in Makefile
c and writinit.f for forming header info
data os_name /'$(OPSYS)'/
c
data date_compile /'$(BUILD_DATE) $(BUILD_TYPE) '/
c
integer NCall
save NCall
character*8 Version
save Version
c
c----------------------------------------------------------------
c
endef
export LAGRIT_H_TEXT
define LAGRIT_HELP
----------------------- LAGRIT MAKEFILE -----------------------
This is an automatic build tool for the Los Alamos Grid Toolbox.
USAGE:
make [options] [target]
TARGETS:
- make release
Optimized build (with shared libraries)
- make static
Optimized build (with static libraries)
- make DEBUG=1 release
Debug build (with shared libraries)
- make DEBUG=1 static
Debug build (with static libraries)
- make exodus
Download and build the SANDIA ExodusII Fortran library.
By default, it will download to the current working directory.
This can be changed by running
make EXO_BUILD_DIR=/exodus/path/out/ exodus
- make test
Run the LaGriT test suite on the created binary.
If you have changed or moved LaGriT from src/lagrit, use
the option EXE_NAME=/path/to/lagrit
OPTIONS:
CC (default: gcc) : C source compiler
FC (default: gfortran) : Fortran source compiler
FC90 (default: gfortran) : Fortran90 source compiler
WITH_EXODUS (default: 1) : Build with or without Exodus
DEBUG (default: 0) : Built in debug (1) or optimized (0) mode
EXO_LIB_DIR (default: LAGRIT_ROOT_DIR/seacas/lib) : ExodusII library location
EXE_NAME (default: src/lagrit) : binary filename for LaGriT
EXO_CMAKE_FLAGS (default: none) : Add custom CMake flags to pass to cmake-exodus
endef
export LAGRIT_HELP
# release, no exo, shared
BUILDLIBS := src/lagrit_main.o src/lagrit_fdate.o src/$(SRC_LIB) lg_util/src/$(LG_UTIL_LIB)
LINKERFLAGS := -fcray-pointer -fdefault-integer-8 -m64
BUILDFLAGS := -fcray-pointer -fdefault-integer-8 -m64 -fno-sign-zero -lm -lstdc++
OSX_STATIC_LIBS :=
SYS_LNK_FLAGS :=
ifeq ($(OPSYS),Darwin)
LINKERFLAGS += -Dmacx64
BUILDFLAGS += -Dmacx64
OSX_STATIC_LIBS :=
else ifeq ($(OPSYS),Linux)
LINKERFLAGS += -Dlinx64
BUILDFLAGS += -Dlinx64
SYS_LNK_FLAGS += -no-pie
else ifeq ($(findstring CYGWIN_NT,$(OPSYS)),CYGWIN_NT)
LINKERFLAGS += -Dwin64
BUILDFLAGS += -Dwin64
endif
ifeq ($(DEBUG),1)
LINKERFLAGS += -g -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow,denormal
BUILDFLAGS += -g -fbacktrace -ffpe-trap=invalid,zero,overflow,underflow,denormal
else
LINKERFLAGS += -O
BUILDFLAGS += -O
endif
ifeq ($(wildcard $(EXO_LIB_DIR)),)
EXO_LIB_DIR := /usr/lib
endif
ifeq ($(WITH_EXODUS),1)
BUILDFLAGS += -L$(EXO_LIB_DIR) -lexodus_for -lexodus -lnetcdf -lhdf5_hl -lhdf5 -lz -ldl
FAIL_THRESH := 2
else
FAIL_THRESH := 3
endif
.PHONY: release static header before clean clobber test exodus
release: BUILD_TYPE = Release
release: build
build : header before
$(FC) -o $(EXE_NAME) $(SYS_LNK_FLAGS) $(BUILDLIBS) $(BUILDFLAGS)
header :
@echo "$$LAGRIT_H_TEXT" > src/lagrit.h
before : src/lagrit_main.o src/lagrit_fdate.o
make -C lg_util/src/ LIB=$(LG_UTIL_LIB) CC=$(CC) FC=$(FC) DEBUG=$(DEBUG)
make -C src/ LIB=$(SRC_LIB) WITHEXODUS=$(WITH_EXODUS) CC=$(CC) FC=$(FC) EXO_INCLUDE_DIR=$(EXO_LIB_DIR)/../include DEBUG=$(DEBUG)
clean :
make -C lg_util/src/ clean
make -C src/ clean
clobber :
make -C lg_util/src/ clobber
make -C src/ clobber
rm src/*.o ; rm $(EXE_NAME)
test :
@export LG_CWD=$(shell pwd); \
cd test/; \
python3 suite.py -f -l 1 -exe=$$LG_CWD/$(EXE_NAME) -hf=$(FAIL_THRESH);
help :
@echo "$$LAGRIT_HELP"
exodus :
set -e; \
export CGNS=OFF; \
export MATIO=OFF; \
export SHARED=NO; \
export LG_DIR=`pwd`; \
export NEEDS_ZLIB=YES; \
export GNU_PARALLEL=OFF; \
export BUILD=YES; \
export CC=$(CC); export CXX=$(CXX); export FC=$(FC); export FC90=$(FC90); \
git clone https://github.com/gsjaardema/seacas.git $(EXO_BUILD_DIR)/seacas || true; \
cd $(EXO_BUILD_DIR)/seacas; \
git checkout ba60a4d19516c433967581fbb8525c56f03b7c3e; \
export ACCESS=`pwd`; \
if [[ `uname -s` == *"CYGWIN"* ]]; then \
BUILD=NO ./install-tpl.sh; \
sed -i 's/defined(_WIN32) || defined(__CYGWIN__)/defined(_WIN32)/g' `ls -t -d TPL/zlib-* | head -1`/gzguts.h; \
export DOWNLOAD=NO; \
fi; \
./install-tpl.sh; \
cd TPL; \
../cmake-exodus $(EXO_CMAKE_FLAGS) -DFORTRAN=YES; \
make && make install; \
cd $(LG_DIR); \
echo "Build directory:"; \
echo " $(EXO_BUILD_DIR)/seacas/lib"; \
echo ""
static: BUILD_TYPE = Static
static: LINKERFLAGS += -static
static: BUILDFLAGS += -static-libgfortran -static-libgcc
static: build
%.o : %.f
$(FC) $(LINKERFLAGS) -c -o $@ $<