-
Notifications
You must be signed in to change notification settings - Fork 2
/
GMake.common
113 lines (79 loc) · 2.68 KB
/
GMake.common
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
# basic rules for building the source. Problems are built in
# sub-directories.
# vpath is the list of directories to search for source files.
vpath %.f90 $(SRC_DIRS)
vpath %.f $(SRC_DIRS)
# odir is the directory where we put the .o and .mod files as we build
odir := _build.$(suf)
# source files
F90SOURCES := $(foreach dir, $(SRC_DIRS), $(notdir $(wildcard $(dir)/*.f90)))
FSOURCES := $(foreach dir, $(SRC_DIRS), $(notdir $(wildcard $(dir)/*.f)))
F90SOURCES_DIR := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.f90))
# dependencies
$(odir)/deps: $(F90SOURCES_DIR)
@if [ ! -d $(odir) ]; then mkdir -p $(odir); fi
../util/dep.py --prefix $(odir)/ $(F90SOURCES_DIR) > $(odir)/deps
include $(odir)/deps
# set the compiler flags for those compilers we know about
ifeq ($(FC),gfortran)
#FFLAGS := -c -O2 -g -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid -finit-real=nan
FFLAGS := -c -O2 -g -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero,overflow,underflow -finit-real=snan
ifdef ACC
FFLAGS += -fopenacc
endif
ifdef OMP
FFLAGS += -fopenmp
endif
FFLAGS += -J $(odir) -I $(odir)
wrapper := $(FC)
link := $(wrapper)
else ifeq ($(FC),pgf95)
wrapper := ftn
link := $(wrapper)
ifdef ACC
FFLAGS := -c -fast -acc -ta=nvidia -lcudart -mcmodel=medium -Minfo
link += -acc -ta=nvidia
else
FFLAGS := -c -fast -mcmodel=medium -Minfo
endif
FFLAGS += -module $(odir) -I$(odir)
ifdef OMP
FFLAGS += -mp=nonuma -Minfo=mp
endif
else ifeq ($(FC),pgf95_local)
ifdef ACC
FFLAGS := -c -fast -acc -ta=nvidia -lcudart -mcmodel=medium -Minfo
#FFLAGS := -c -g -acc -ta=nvidia -lcudart -Minfo
else
FFLAGS := -c -fast -mp -lpthread -Mvect=levels:4 -Minfo
#FFLAGS := -c -fast -Minfo
endif
FFLAGS += -module $(odir) -I$(odir)
wrapper := pgf95
link := $(wrapper) -acc -ta=nvidia
else ifeq ($(FC),Cray)
FFLAGS := -c -h acc,msgs -lcudart -em -J $(odir) -I $(odir)
wrapper := ftn
link := $(wrapper) -h acc,msgs -lcudart
else
$(error ERROR: compiler $(FC) invalid)
endif
# default rule for building the object files
$(odir)/%.o: %.f90
@if [ ! -d $(odir) ]; then mkdir -p $(odir); fi
$(wrapper) $(FFLAGS) -o $@ $<
$(odir)/%.o: %.f
@if [ ! -d $(odir) ]; then mkdir -p $(odir); fi
$(wrapper) $(FFLAGS) -o $@ $<
# create the list of dependencies for the final build (all the .o files)
OBJECTS := $(addprefix $(odir)/, $(F90SOURCES:.f90=.o))
OBJECTS += $(addprefix $(odir)/, $(FSOURCES:.f=.o))
.PHONY: clean
.SECONDARY: $(OBJECTS)
# targets for cleaning up
clean:
rm -f $(odir)/*.o $(odir)/*.mod *.cub *.ptx
realclean: clean
rm -rf _build* *.cub *.ptx
rm -f *.exe
print-%: ; @echo $* is $($*)