-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
753 lines (745 loc) · 32.4 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MAKEFILE for compiling and testing the Batteries Included Fortran Library (BiF-Lib)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Developed by Scott E Boyce <[email protected]>
#
# If you use BiF-lib, this MAKEFILE, a derivative of this makefile
# please include in any publications the following citations:
#
# Boyce, S.E., 2024, Batteries Included Fortran Library (BiF-Lib), version 1.2.0: U.S. Geological Survey Software Release, https://doi.org/10.5066/P9K2IQ6Y
#
# Boyce, S.E., Hanson, R.T., Ferguson, I., Schmid, W., Henson, W., Reimann, T., Mehl, S.M., and Earll, M.M., 2020, One-Water Hydrologic Flow Model: A MODFLOW based conjunctive-use simulation software: U.S. Geological Survey Techniques and Methods 6–A60, 435 p., https://doi.org/10.3133/tm6A60
#
# Boyce, S.E., 2022, MODFLOW One-Water Hydrologic Flow Model (MF-OWHM) Conjunctive Use and Integrated Hydrologic Flow Modeling Software, version 2.2.x: U.S. Geological Survey Software Release, https://doi.org/10.5066/P9P8I8GS
#
# PROVIDED AS IS WITHOUT WARRANTY OR HELP.
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# This makefile contains the options for compiling using Intel, GFortran, and LLVM.
# It is recommended to use the current release of either the Intel Fortran or GNU Fortran compilers.
# Older versions had a set of known compiler bugs that have been summitted to Intel and GCC, and were subsequently patched with recent compiler versions.
# If you receive "internal compiler error" when running this makefile, it is because the compiler version does not work.
# Linux on windows recommends using MinGW or WSL. Cygwin is an emulator and its use is not recommended.
#
# The Intel Fortran compiler is now part of Intel oneAPI and has two different versions:
# Intel Fortran Compiler Classic (ifort) and Intel Fortran (ifx).
# ifx is not recommended and will raise lots of "internal compiler error"s
# ifort can have issues depending on the compiler version.
# oneAPI versioning is based on YYYY.m.p, where YYYY is year, m is major version, p and patch version.
# oneAPI versions may not match its subcomponents,
# for example, oneAPI version 2023.0.0, has ifx version 2023.0.0, and ifort version 2021.8.0
#
# Gfortran many versions that are identified by their major versioning. The current versions in use are 10.x.y, 11.x.y, and 12.x.y
# The gfortran version can be determined by "gfortran --version" and
# specific major versions of gfortran can be invoked as gfortran-XX where XX is the major version, such as gfortran-12
#
# The LLVM compilers, FLANG and CLANG, are still experimental and not yet fully supported.
#
# ifx WILL NOT compile this project (feature not implemented errors)
# ifort 2021.8.0 WILL NOT compile this project (oneAPI 2023.0.0)
# ifort 2021.7.0 and earlier WILL compile this project (oneAPI 2022.2.1)
# gfortran 11.3.0 and 12.1.0 WILL compile this project (others have not been tested)
#
# The initial setup has the compiler type variables set to the
# GNU Compiler Collection (gfortran and gcc)
# To compile with the Intel Fortran Compiler Classic (ifort), you will need to set:
# COMPILER := INTEL
# F90 := ifort
# CC := icc # -> only needed if compiling C code, otherwise ignored
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# To Invoke/Compile type from command prompt:
# make Compile the src files and the main.f90 that is used for testing. Binary located in bin
# make run Same as above, but runs the resulting test binary. By default compiles with main.f90, but you can change to different tests by: makefile run MAIN=DriverFile.f90
# make clean Delete all object (.o) and module (.mod) files --> Note this uses the Unix find command and not Windows
# make reset Same as clean, except deletes all binaries. --> Note this uses the Unix find command and not Windows
#
# To define a different driver main file you either edit this makefile or specify the following argument
# make MAIN=main.f90 #where main.f90 is replaced with your driver file.
#
# Specify debug or release to run without modifying the makefile:
# make CONFIG=debug or
# make CONFIG=release or
# make run CONFIG=debug or
#
# make COMPILER=gcc F90=gfortran or
# make COMPILER=gcc F90=gfortran CONFIG=debug
#
# Accepted keywords are (Note that all have defaults within this script):
# CONFIG => debug or release
# COMPILER => GCC or INTEL or LLVM --> Indicates the compiler collection used for auto setting compiler flags
# F90 => gfortran or ifort
# CC => gcc or icc
#
# bin_out => Location and Name (plus extension) of the final program. If not specified, then bin_out = $(bin_dir)/$(PROGRAM)$(ext)
# src_dir => Location of the source files -- Do not include a trailing / (that is, ./out1/out2)
# int_dir => Location of the intermediate files (.o and .mod) -- Do not include a trailing / (that is, ./out1/out2)
# test_dir => Location to run program when using "make run" -- Do not include a trailing / (that is, ./out1/out2)
#
# ARG => Arguments passed to program when using "make run"
# PROGRAM => Name file program without extension (note variable is ignored if bin_out is set).
# bin_dir => Location to place final program (note variable is ignored if bin_out is set). -- Do not include a trailing / (that is, ./out1/out2)
#
# --note all these variables should have detailed explanations where they are defined in this makefile.
# --bin_out overrides the default binary name with the user specified one, that is: $(F90) -o $(bin_out)
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# If you want to use Intel Fortran on Windows 10
# then run the makefile in the Intel Command Prompt (for example, run from the start menu: Compiler 19.1 Update 1 for Intel 64 Visual Studio 2019 environment)
# or you will get path or license errors from Intel.
# -- Linux Intel Fortran works fine with this makefile if ifort is in the PATH variable.
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# If you want to use Gfortran on Windows 10
# then you will need to:
# 1) Install MSYS: https://www.msys2.org/
# 2) Add to windows PATH variable:
# A) C:\msys64\mingw64\bin
# B) C:\msys64\usr\bin
# 3) Open a bash prompt.
# A) If in windows path just type "bash" in the cmd.exe windows
# B) Otherwise, it is located at: C:\msys64\usr\bin\bash.exe
# 4) Run the following commands in bash,
# after each command restart bash (close and reopen the window)
# A) pacman --needed -S bash pacman pacman-mirrors msys2-runtime
# B) pacman -Syu
# C) pacman -Suu
# D) pacman -S make
# E) pacman -S mingw64/mingw-w64-x86_64-gcc
# F) pacman -S mingw64/mingw-w64-x86_64-gcc-fortran
# G) pacman -S mingw64/mingw-w64-x86_64-gdb
# After that, you can now do updates to all components with the command:
# 5) pacman -Suy
#
# To search for additional packages go to:
# https://packages.msys2.org/search
# and change the search in to "Packages"
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#
#############################################################################
#############################################################################
### Set the following Variables ###
#############################################################################
#############################################################################
#
# Compilation Configuration-Optimization Scheme
# ===> Accepted Answers: RELEASE, DEBUG
CONFIG := debug
#
# Compilation Software --> Indicates the compiler collection used for setting compiler flags
# ===> Accepted Answers: INTEL, GCC, LLVM --> LLVM not fully-supported yet
COMPILER := INTEL
#
#
# Define the Fortran Compiler
# ===> For example: gfortran, gfortran-9, gfortran-10, ifort
# ****Note that the version of your Fortran compiler may not support all of the Fortran Standards (viz 2003, 2008, 2015)
F90 := ifort
#
# Define the C Compiler
# ===> Accepted Answers: gcc, icc
CC := icc
#
# Program Name - Do not include extension (eg .exe). Also _debug will automatically be added if CONFIG = debug. Use bin_out= to specify exact location and name for binary.
#
PROGRAM := bif
#
# Compile STATICALLY? That is, no library dependence and compile with STATIC options.
# ===> Accepted Answers: YES, NO
STATIC := YES
#
# Should compilation force DOUBLE PRECISION for all REAL variables? That is: REAL => DOUBLE PRECIONS.
# ===> Accepted Answers: YES, NO
#
DBLE := NO
#
# Pass Command Arguments when running executable.
# This is only used for "make run", for example "make run ARG=Name.nam"
ARG =
#
#
########################################################################
########################################################################
# DO NOT MODIFY BELOW THIS LINE
# UNLESS YOU KNOW WHAT YOUR DOING
########################################################################
########################################################################
#
########################################################################
#
#
# Program Name for echo output
ST:=
# Whitespace starts after $(ST)
#
ECHO_NAME := $(ST) Batteries Included Fortran
#
#
#Define final BIN, SOURCE, and Testing directories => Can be blank, but do not include the trailing forward slash /
#
bin_dir ?=./bin
#
src_dir ?=./src
#
# Location where test files are run
test_dir ?=./examples
#
# define the intermediate directory object and mod files are placed here
#
obj_dir :=$(strip $(shell echo $(CONFIG) | tr A-Z a-z))_$(strip $(shell echo $(F90) | tr A-Z a-z))
int_dir ?=./obj/$(obj_dir)
#int_dir:= ./obj
#
TESTDIR := ./tests/src
#
#############################################################################
#
# Construct a function for converting space delimited variables to new lines
null :=
sp := ${null} ${null}
sp2 := ${null} ${null}
sp4 := ${null} ${null}
#${sp} := ${sp} # ${sp} function returns a space
#${sp2} := ${sp2} # ${sp2} function returns 2 spaces
#funct -> @echo -e " $(subst ${sp},\n,${text})"
#
#
#############################################################################
#
# Define the Fortran source files.
#
MAIN := ./tests/src/array_data_types_test.f90 \
./tests/src/sort_test.f90 \
./tests/src/main_tests.f90 \
./tests/src/main.f90
#
main_src:= \
$(src_dir)/util_misc/constants.f90 \
$(src_dir)/datetime/calendar_functions.f90 \
$(src_dir)/datetime/sleep_interface.f90 \
$(src_dir)/datetime/timer_instruction.f90 \
$(src_dir)/dynamic_arrays/dynamic_array_int32.f90 \
$(src_dir)/math_numbers/descriptive_statistics.f90 \
$(src_dir)/math_numbers/hexadecimal_instruction.f90 \
$(src_dir)/math_numbers/isqrt_interface.f90 \
$(src_dir)/math_numbers/log2_interface.f90 \
$(src_dir)/math_numbers/number_conversion_interface.f90 \
$(src_dir)/math_numbers/power_interface.f90 \
$(src_dir)/math_numbers/prime_finder.f90 \
$(src_dir)/math_numbers/random_routines_interface.f90 \
$(src_dir)/math_numbers/relax_interface.f90 \
$(src_dir)/math_numbers/secant_interface.f90 \
$(src_dir)/spatial/xy_grid_coordinate_interface.f90 \
$(src_dir)/strings/cast_to_string_interface.f90 \
$(src_dir)/strings/num2str_interface.f90 \
$(src_dir)/strings/parse_word_interface.f90 \
$(src_dir)/system/console_commander.f90 \
$(src_dir)/system/directory_iso_c_binding.f90 \
$(src_dir)/types_and_containers/array_data_types_instruction.f90 \
$(src_dir)/types_and_containers/binary_heap_instruction.f90 \
$(src_dir)/types_and_containers/integer_array_builder.f90 \
$(src_dir)/types_and_containers/circular_queue_instruction.f90 \
$(src_dir)/types_and_containers/integer_queue_instruction.f90 \
$(src_dir)/types_and_containers/linked_list_instruction.f90 \
$(src_dir)/types_and_containers/name_id_interface.f90 \
$(src_dir)/types_and_containers/rolling_pointer_instruction.f90 \
$(src_dir)/types_and_containers/variable_pointer_list_interface.f90 \
$(src_dir)/unicode/unicode_interface.f90 \
$(src_dir)/unit_test/unit_testing_instruction.f90 \
$(src_dir)/util_misc/alloc_interface.f90 \
$(src_dir)/util_misc/is_routine_interface.f90 \
$(src_dir)/util_misc/same_memory_address_interface.f90 \
$(src_dir)/util_misc/set_array_interface.f90 \
$(src_dir)/datetime/date_operator_instruction.f90 \
$(src_dir)/dynamic_arrays/dynamic_array.f90 \
$(src_dir)/error/error_interface.f90 \
$(src_dir)/input_reader/buffered_reader_instruction.f90 \
$(src_dir)/io/post_key_sub.f90 \
$(src_dir)/sort/sort_interface_driver.f90 \
$(src_dir)/sort/sort_interface_ascii.f90 \
$(src_dir)/sort/sort_interface_int32.f90 \
$(src_dir)/sort/sort_interface_int64.f90 \
$(src_dir)/sort/sort_interface_multi.f90 \
$(src_dir)/sort/sort_interface_rel32.f90 \
$(src_dir)/sort/sort_interface_rel64.f90 \
$(src_dir)/sort/sort_interface_wild.f90 \
$(src_dir)/strings/line_writer_interface.f90 \
$(src_dir)/system/path_interface.f90 \
$(src_dir)/types_and_containers/hash_table_instruction.f90 \
$(src_dir)/util_misc/position_interface.f90 \
$(src_dir)/util_misc/util_interface.f90 \
$(src_dir)/error/warning_type_instruction.f90 \
$(src_dir)/io/generic_open_interface.fpp \
$(src_dir)/math_numbers/EquationParser.f90 \
$(src_dir)/spatial/obs_group_interpolator.f90 \
$(src_dir)/strings/is_ascii_interface.f90 \
$(src_dir)/io/file_incrementer_interface.f90 \
$(src_dir)/io/file_io_interface.f90 \
$(src_dir)/spatial/adjacency_list_instruction_and_shortest_path.f90 \
$(src_dir)/strings/string_routines.f90 \
$(src_dir)/io/cycling_text_file_interface.f90 \
$(src_dir)/io/generic_input_file_instruction.f90 \
$(src_dir)/io/generic_output_file_instruction.f90 \
$(src_dir)/io/write_array_interface.f90 \
$(src_dir)/input_reader/generic_block_reader_instruction.f90 \
$(src_dir)/datetime/time_series_file_instruction.f90 \
$(src_dir)/types_and_containers/IXJ_instruction.f90 \
$(src_dir)/types_and_containers/lookup_table_instruction.f90 \
$(src_dir)/input_reader/uload_and_sfac_interface.f90 \
$(src_dir)/input_reader/transient_file_reader_instruction.f90 \
$(src_dir)/input_reader/list_array_input_interface.f90 \
$(src_dir)/input_reader/sub_block_input_interface.f90
#
#############################################################################
#
# Listing of all source files (if multiple variables for specifying source locations)
#
all_src := $(main_src) $(MAIN)
#
#############################################################################
#
#Define the source code directory search path (really only need source directories)
# $(sort $(dir $(all_src))) gets all the directories that source files reside in
# -? "$(sort" XYZ) removes duplicates
#
VPATH := $(sort $(dir $(all_src))) $(int_dir) $(bin_dir) $(TESTDIR)
#
#############################################################################
#
# Change all source names with extension changed to ".o"
obj:=$(addsuffix .o, $(basename $(notdir $(all_src))))
# Old method, manually replace each extension by patter matching
#obj:= $(patsubst %.f90, %.o, \
# $(patsubst %.f, %.o, \
# $(patsubst %.fpp, %.o, \
# $(patsubst %.c, %.o, \
# $(patsubst %.for, %.o, \
# $(patsubst %.F, %.o, \
# $(patsubst %.F90, %.o, \
# $(patsubst %.FOR, %.o, \
# $(notdir $(all_src)) \
# ) ) ) ) ) ) ) )
#
#obj:= $(patsubst %.f90,%.o,$(patsubst %.f,%.o,$(src)))
#
########################################################################
#
# Check for if Windows or Unix
#
#
ifeq ($(OS),Windows_NT)
ext:=.exe
else
ext:=.nix
endif
#
########################################################################
#
# Note bash on windows sometimes calls C:\Windows\System32\find.exe,
# but want Bash "find" with no extension
# Check if windows, if so, then find bash find equivalent.
#
ifeq ($(OS),Windows_NT)
FIND:=$(strip $(shell \
( \
notSET="T"; \
for FP in `which --all find`; do \
if [[ $$FP == *Win* ]] || \
[[ $$FP == *WIN* ]] || \
[[ $$FP == *win* ]]; \
then continue ; \
else \
echo "$$FP"; \
notSET="F"; \
break; fi; \
done; \
if [ $$notSET = "T" ]; then echo "find"; fi; \
FP=; \
notSET=; \
) \
) )
else
FIND:=find
endif
#
########################################################################
#
# Check for if Windows and set resource file for icon -> windres ./icon/*.rc ./icon/*.res
#
# --> windres and gfortran can have issues so skipping makefile icon generation
#
###icon_rc := ./icon/XYZ.rc
###icon_res := ./icon/XYZ.res
####
###ifeq ($(OS),Windows_NT)
### res:=$(shell windres $(icon_rc) $(icon_res) || echo )
### ifeq ($(res), )
### res:=$(icon_res)
### else
### res:=
### endif
###
###else
### res:=
###endif
#
# ------------------------------------
define echo2
@echo; echo
endef
# ------------------------------------
define echo3
@echo; echo; echo
endef
# ------------------------------------
define echo4
@echo; echo; echo; echo
endef
# ------------------------------------
#
#
########################################################################
#
# Remove blanks to ensure checks match to names
#
CFG :=$(strip $(shell echo $(CONFIG) | tr [:lower:] [:upper:]))
CMPLR :=$(strip $(shell echo $(COMPILER) | tr a-z A-Z))
STATIC :=$(strip $(shell echo $(STATIC) | tr a-z A-Z))
DBLE :=$(strip $(shell echo $(DBLE) | tr a-z A-Z))
F90 :=$(strip $(F90))
CC :=$(strip $(CC))
PROGRAM :=$(strip $(PROGRAM))
#
########################################################################
#
# Set up names and optimizations depending on compiler and configuration
#
ifeq ($(CFG), DEBUG)
#
PROGRAM:=$(PROGRAM)-debug
#
F90FlagsIntel :=-O0 -g -debug -traceback -assume nocc_omp -fpe0 -fp-model source -nologo -warn nousage -check bounds,pointers,stack,format,output_conversion,uninit
F90FlagsGCC :=-O0 -g -w -fcheck=all -fbacktrace -fdefault-double-8 -ffree-line-length-2048 -fmax-errors=10 -ffpe-trap=zero,overflow,underflow -finit-real=nan #-fstack-usage #<= THIS PROVIDES LOTS OF INFO -std=f2008
F90FlagsLLVM :=
#
CFlagsIntel :=-O0 -debug -g -fbuiltin
CFlagsGCC :=-O0 -g -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast
CFlagsLLVM :=
else
# NOTE "-ip" can sometimes cause catastrophic error: **Internal compiler error:
#
F90FlagsIntel :=-O2 -assume nocc_omp -fpe0 -fp-model source -threads -warn nousage -nologo
F90FlagsGCC :=-O2 -w -fno-backtrace -fno-range-check -fdefault-double-8 -ffree-line-length-2048
F90FlagsLLVM :=
#
CFlagsIntel :=-O2 -fbuiltin
CFlagsGCC :=-O2 -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast
CFlagsLLVM :=
endif
#
########################################################################
#
# Check if DBLE == YES to add default REAL-8 options
#
ifeq ($(DBLE), YES)
#
F90FlagsIntel+= -real-size 64
F90FlagsGCC += -fdefault-real-8
F90FlagsLLVM += -fdefault-real-8
endif
#
########################################################################
#
# Establish Proper Optimization Flags and Static Flags
#
# Ensure that variables are set if STATIC not in use
ifneq ($(strip $(STATIC)), YES)
STATIC:=
STATICLNK:=
endif
#
# STATICLNK+= -static-libgfortran => This can cause problems with gcc runtime so best not to use
ifeq ($(CMPLR), GCC)
mod:=-J$(int_dir)
F90FLAGS:=$(F90FlagsGCC)
#
ifdef GDB
F90FLAGS += -ggdb3
endif
#
ifeq ($(strip $(STATIC)), YES)
STATIC :=-static -static-libgfortran -static-libgcc -static-libstdc++
STATICLNK:=-static -static-libgfortran -static-libgcc -static-libstdc++
endif
#
CFLAGS:=$(CFlagsGCC)
endif
#
ifeq ($(CMPLR), INTEL)
mod:=-module $(int_dir)
F90FLAGS:=$(F90FlagsIntel)
ifeq ($(strip $(STATIC)), YES)
STATIC :=-static -static-intel -qopenmp-link=static -static-libstdc++ -static-libgcc
STATICLNK:=-static -static-intel -qopenmp-link=static -static-libstdc++ -static-libgcc
endif
#
CFLAGS:=$(CFlagsINTEL)
endif
#
ifeq ($(CMPLR), LLVM)
mod:=-module $(int_dir)
F90FLAGS:=$(F90FlagsLLVM)
#
ifdef GDB
F90FLAGS += -ggdb3
endif
#
ifeq ($(strip $(STATIC)), YES)
STATIC :=-static-flang-libs
STATICLNK:=-static-flang-libs
endif
#
CFLAGS:=$(CFlagsLLVM)
endif
#
#
########################################################################
#
# Remove Variable Blank Space For Cleaner Output
#
F90FLAGS :=$(strip $(F90FLAGS))
CFLAGS :=$(strip $(CFLAGS))
STATIC :=$(strip $(STATIC))
STATICLNK:=$(strip $(STATICLNK))
#
########################################################################
#
#SET UP PROGRAM NAME
#
bin_out ?= $(bin_dir)/$(PROGRAM)$(ext)
#
###########################################################################
###########################################################################
# DEFINE ALL TASK FUNCTIONS ###
# THE FOLLOW TARGETS EVALUATE THE COMPILATION ###
###########################################################################
###########################################################################
#
#
all:
@$(MAKE) --no-print-directory runMake || $(MAKE) --no-print-directory errorClean
#
run:
@$(MAKE) --no-print-directory runTest || $(MAKE) --no-print-directory errorClean
#
rebuild: quietClean all
#
compile: prinLink:=NO
compile: preClean $(int_dir) $(bin_out) completed
#
runMake: prinLink:=YES
runMake: startMSG preClean CompFlags $(int_dir) $(bin_out) dashes completed
#
runTest: runMake
${echo2}
@echo "Now running program to evaluate tests."
${echo2}
cd $(test_dir) ; $(abspath $(bin_out)) $(ARG)
${echo3}
@echo " MAKEFILE TESTS COMPLETE"
${echo2}
#
startMSG:
${echo2}
@echo "################################################################################"
@echo "################################################################################"
@echo "################################################################################"
@echo "# #"
@echo "# #"
@echo "# $(CFG) COMPILATION"
@echo "# #"
@echo "# OF #"
@echo "# #"
@echo "#$(ECHO_NAME)"
@echo "# #"
@echo "# #"
@echo "################################################################################"
@echo "################################################################################"
@echo "################################################################################"
${echo2}
#
CompFlags:
@echo "--------------------------------------------------------------------------------"
@echo
@echo "Starting compilation with the following flags: "
${echo2}
@echo " $(F90):"
@printf " $(subst ${sp},\n${sp4},$(F90FLAGS) $(mod) $(STATIC))"
${echo3}
@echo " $(CC):"
@printf " $(subst ${sp},\n${sp4},$(CFLAGS) $(STATIC))"
${echo3}
@echo "Compiled object, module, and submodule files will be placed in:"
@echo; echo " $(realpath $(int_dir))"
${echo2}
@echo "================================================================================"
${echo2}
#
preClean:
@rm -rf $(bin_out)
#
$(int_dir):
@mkdir -p $@
#
$(bin_out): $(addprefix $(int_dir)/,$(obj))
@echo
@if [ "$(prinLink)" = "YES" ]; then \
echo ; \
echo "================================================================================" ; \
echo; echo ; \
echo "OBJECTS HAVE BEEN CREATED NOW LINKING FINAL BINARY:" ; \
echo ; \
echo "$(F90) $(int_dir)/*.o -o $@" ; \
echo ; \
else \
echo "NOW LINKING FINAL BINARY" ; \
echo ; \
fi
@$(F90) $(F90FLAGS) $(mod) $^ $(STATICLNK) -o $@
#
dashes:
@echo
@echo "--------------------------------------------------------------------------------"
${echo2}
completed:
@echo "#########################################"
@echo "### ###"
@echo "### MAKEFILE COMPILATION COMPLETE ###"
@echo "### ###"
@echo "#########################################"
${echo4}
#
# --> Note this uses the Unix find command and NOT Windows
# If you get an error on windows, its using the wrong one --> See MinGW or MySYS64)
clean:
@echo
$(FIND) ./obj -not -name 'obj' -name '*.o' -delete
$(FIND) ./obj -not -name 'obj' -name '*.mod' -delete
$(FIND) ./obj -not -name 'obj' -name '*.smod' -delete
${echo2}
#
cleanOBJ:
@echo
$(FIND) ./obj -not -name 'obj' -not -name '.keep' -name '*' -delete
${echo2}
#
quietClean:
@echo
$(FIND) $(int_dir) -name '*.o' -delete 2>/dev/null || true
$(FIND) $(int_dir) -name '*.mod' -delete 2>/dev/null || true
$(FIND) $(int_dir) -name '*.smod' -delete 2>/dev/null || true
${echo2}
#
errorClean:
${echo4}
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@echo "@@########################################################@@"
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@echo
@echo " MAKEFILE FAILED"
@echo
@echo " TO MAKE $(CFG) COMPILATION OF"
@echo
@echo " $(bin_out)"
${echo2}
rm -rf $(bin_out)
${echo2}
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
@echo "@@########################################################@@"
@echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
${echo4}
#
reset:
@echo
$(FIND) . -name '*.o' -delete
$(FIND) . -name '*.mod' -delete
$(FIND) . -name '*.smod' -delete
@echo
$(FIND) ./obj -not -name 'obj' -not -name '.keep' -name '*' -delete
@echo
$(FIND) $(notdir $(bin_dir)) -not -name '$(notdir $(bin_dir))' -not -name '.keep' -name '*' -delete
${echo2}
#
# The following target allows for printing a specific variable. old method: @echo $*=$($*)
# make print-CC --> will print out the value of $(CC)
#
print-%:
@echo '$*=$($*)'
@echo ' origin = $(origin $*)'
@echo ' flavor = $(flavor $*)'
@echo ' value = $(value $*)'
#
#################################################################################
### Object Code Recipes ######################################################
#################################################################################
#
$(int_dir)/%.o : %.c
@echo "$(CC) $(notdir $<)"
@echo
@$(CC) $(CFLAGS) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.f
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.F
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.f90
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.F90
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.fpp
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
$(int_dir)/%.o : %.for
@echo "$(F90) $(notdir $<)"
@echo
@$(F90) $(F90FLAGS) $(mod) $(STATIC) -c $< -o $@
#
#
###############################################################################
#
# Setup suffixes that will be processes # .h .mod
.SUFFIXES: .o .f .for .F .FOR .f90 .F90 .fpp .c
#
# #############################################################################
#
# Phony Targets
.PHONY: all run clean cleanOBJ reset runMake runTest preclean errorClean startMSG print-% completed dashes compile
#
# #############################################################################
#
# Suppress echoing of commands
.SILENT: startMSG CompFlags dashes completed print-%
#
#
# THE END #####################################################################