forked from AFD-Illinois/iharm3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
147 lines (115 loc) · 3.77 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
# Problem to compile
PROB = torus
# Top directory of HDF5, or blank if using h5pcc
HDF5_DIR =
# Top directory of MPI, or blank if using mpicc
# Highly recommended to use mpicc!
MPI_DIR =
# Top directory of GSL, or blank if installed to system
GSL_DIR =
# System /lib equivalent (can be /usr/lib, /lib64, /usr/lib64)
# Can leave this blank if it's included automatically by GCC
SYSTEM_LIBDIR = /lib64
# Try pointing this to h5pcc on your machine, before hunting down libraries
CC=h5pcc
# Example CFLAGS for going fast with GCC
CFLAGS = -std=gnu99 -O3 -march=native -mtune=native -flto -fopenmp -funroll-loops
MATH_LIB = -lm
# ICC does not like -lm and uses different flags
#CFLAGS = -xCORE-AVX2 -Ofast -fstrict-aliasing -Wall -Werror -ipo -qopenmp
#MATH_LIB =
# Name of the executable
EXE = harm
# Override these defaults if we know the machine we're working with
# Once you know what compiles, add it as a machine def here
MAKEFILE_PATH := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
HOST := $(shell hostname)
ifneq (,$(findstring stampede2,$(HOST)))
-include $(MAKEFILE_PATH)/machines/stampede2.make
endif
ifneq (,$(findstring theta,$(HOST)))
-include $(MAKEFILE_PATH)/machines/theta.make
endif
ifneq (,$(findstring frontera,$(HOST)))
-include $(MAKEFILE_PATH)/machines/frontera.make
endif
ifneq (,$(findstring beginsbh,begins$(HOST)))
-include $(MAKEFILE_PATH)/machines/bh.make
endif
-include $(MAKEFILE_PATH)/machines/$(HOST).make
# Everything below this should be static
## VERSION PRESERVATION ##
GIT_VERSION := $(shell cd $(MAKEFILE_PATH); git describe --dirty --always --tags)
## LINKING PARAMETERS ##
LINK = $(CC)
LDFLAGS = $(CFLAGS)
HDF5_LIB = -lhdf5_hl -lhdf5
MPI_LIB = #TODO these are hard to find due to ubiquity of mpicc
GSL_LIB = -lgsl -lgslcblas
## LOGIC FOR PATHS ##
CORE_DIR := $(MAKEFILE_PATH)/core/
PROB_DIR := $(MAKEFILE_PATH)/prob/$(PROB)/
VPATH = $(CORE_DIR):$(PROB_DIR)
#ARC_DIR := $(MAKEFILE_PATH)/prob/$(PROB)/build_archive/
# TODO this is I think gmake-specific
ARC_DIR := $(CURDIR)/build_archive/
SRC := $(wildcard $(CORE_DIR)/*.c) $(wildcard $(PROB_DIR)/*.c)
HEAD := $(wildcard $(CORE_DIR)/*.h) $(wildcard $(PROB_DIR)/*.h)
HEAD_ARC := $(addprefix $(ARC_DIR)/, $(notdir $(HEAD)))
OBJ := $(addprefix $(ARC_DIR)/, $(notdir $(SRC:%.c=%.o)))
INC = -I$(ARC_DIR)
LIBDIR =
LIB = $(MATH_LIB) $(GSL_LIB)
# Add HDF and MPI directories only if compiler doesn't
ifneq ($(strip $(HDF5_DIR)),)
INC += -I$(HDF5_DIR)/include/
LIBDIR += -L$(HDF5_DIR)/lib/
LIB += $(HDF5_LIB)
endif
ifneq ($(strip $(MPI_DIR)),)
INC += -I$(MPI_DIR)/include/
LIBDIR += -L$(MPI_DIR)/lib/
LIB += $(MPI_LIB)
endif
ifneq ($(strip $(GSL_DIR)),)
INC += -I$(GSL_DIR)/include/
LIBDIR += -L$(GSL_DIR)/lib/
endif
ifneq ($(strip $(SYSTEM_LIBDIR)),)
# Prefer user libraries (above) to system
LIBDIR += -L$(SYSTEM_LIBDIR)
endif
## TARGETS ##
.PRECIOUS: $(ARC_DIR)/$(EXE) $(ARC_DIR)/%
default: build
build: $(EXE)
@echo -e "Completed build of prob: $(PROB)"
@echo -e "CFLAGS: $(CFLAGS)"
debug: CFLAGS += -g -Wall -Werror
debug: CFLAGS += -DDEBUG=1
debug: build
profile: CFLAGS += -g -pg
profile: build
vtune: CFLAGS += -g -Wall -Werror
vtune: CFLAGS += -debug inline-debug-info -shared-intel
vtune: build
clean:
@echo "Cleaning build files..."
@rm -f $(EXE) $(OBJ)
distclean: clean
@echo "Cleaning config files..."
@rm -rf build_archive
archive-invalidation: distclean
$(EXE): $(ARC_DIR)/$(EXE)
@cp $(ARC_DIR)/$(EXE) .
$(ARC_DIR)/$(EXE): $(OBJ)
@echo -e "\tLinking $(EXE)"
@$(LINK) $(LDFLAGS) $(OBJ) $(LIBDIR) $(LIB) -o $(ARC_DIR)/$(EXE)
@rm $(OBJ) # This ensures full recompile
$(ARC_DIR)/%.o: $(ARC_DIR)/%.c $(HEAD_ARC)
@echo -e "\tCompiling $(notdir $<)"
@$(CC) $(CFLAGS) $(INC) -DGIT_VERSION=$(GIT_VERSION) -c $< -o $@
$(ARC_DIR)/%: % | $(ARC_DIR)
@cp $< $(ARC_DIR)
$(ARC_DIR):
@mkdir $(ARC_DIR)