-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
289 lines (254 loc) · 8.16 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
#***************************************************************************#
# ArtraCFD Makefile #
# <By Huangrui Mo> #
# Copyright (C) Huangrui Mo <[email protected]> #
# This file is part of ArtraCFD. #
# ArtraCFD is free software: you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
#***************************************************************************#
#***************************************************************************#
# Options:
# 'make' or 'make all' build executable file
# 'make install' build executable file and install
# 'make uninstall' uninstall
# 'make clean' remove objects, dependency and executable files
#
# Use 'cat -e -t -v Makefile' to show the presence of tabs with ^I and
# line endings with $, which are vital to ensure that dependencies end
# properly and tabs mark the action for the rules.
#
#***************************************************************************#
#***************************************************************************#
#
# System Configuration
#
#***************************************************************************#
#
# Shell
#
SHELL := /bin/bash
#
# Installer
#
INSTALL := install
INSTALLDATA := $(INSTALL) -m 644
#
# Prefix for each installed program
#
# e.g., prefix = /usr/local
#
prefix = ~
#
# The directory to install binary executable program
#
bindir = $(prefix)/Bin
#
# The directory to install the info files in.
#
infodir = $(bindir)/info
#
# Define the executable program name
#
BINNAME := artracfd
#
# Path to the source directory, relative to the makefile
#
srcdir = .
#***************************************************************************#
#
# Compiler Configuration
#
#***************************************************************************#
#
# Define the compiler
#
# gcc GNU C compiler
# icc Intel C compiler
# mpicc MPI compiler
#
CC := gcc
#
# Define compiler flags
# This flag affects all C compilations uniformly, include implicit rules.
#
# Shared compiler flags
# -Wall Turn on all warnings
# -Wextra More restricted warnings
# -std=c99 -pedantic Use ANSI C standard
# -g Enable debugging
# -O0 No optimization; generates unoptimized code for debugging purposes.
# -O2 Recommended optimization; generates well optimized code.
# -O3 Aggressive optimization; should be validated and compared with -O2.
# GCC compiler flags
# -fstrict-aliasing Assume the strictest aliasing rules for type optimizations.
# -Og Enables optimizations that do not interfere with debugging.
# -fopenmp Enable openmp
# ICC compiler flags
# -ansi-alias Assume the strictest aliasing rules for type optimizations.
# -no-prec-div Enable optimizations for division.
# -ipo Enable cross-file optimization such as cross-file inlining.
# -fast Enable processor specific optimization and will fail for inconsistency.
# -qopenmp Enable openmp
# Use Valgrind for memory access check (http://valgrind.org/)
# -g -O0 Use this flag to compile the program, then run command line
# valgrind --leak-check=full --track-origins=yes ./artracfd -m arg
# Use Valgrind for cache missing check (http://valgrind.org/)
# -g -O2 Use this flag to compile the program, then run command line
# valgrind --tool=cachegrind ./artracfd -m arg
# Use google-perftools for performance check (https://github.com/gperftools/gperftools)
# sudo apt-get install google-perftools libgoogle-perftools-dev
# -g Enable debugging to compile the program, then run command line
# LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=./cpuprof ./artracfd -m arg
# google-pprof ./artracfd ./cpuprof (call-graph terminal)
# Enable floating-point exception handling to debug algorithm
# trapfpe.c Add into source code
# -g -O0 Use this flag to compile the program
# gdb ./artracfd
# (gdb) run -m serial
# where Show trace information
#
ifeq ($(CC),icc)
CFLAGS += -Wall -Wextra -O2 -ansi-alias -std=c99 -pedantic
else
CFLAGS += -Wall -Wextra -O2 -fstrict-aliasing -std=c99 -pedantic
endif
#
# Preprocessor options
#
CPPFLAGS +=
#
# Switch intelcc and gnu module
#
# When using gcc to compile, it is common to see an error related to
# <math.h>. This error occurs because the intelcc module is loaded
# and is pointing to the intel version of math.h. The Intel version
# of math.h does not work with the gcc compiler. There are two simple
# workarounds to fix this problem:
# Exclusively use icc to compile your jobs.
# Unload intelcc and load gcc module
# module unload intelcc
# module load gcc
#
#
# Define any directories containing header files other than /usr/include
#
# e.g., INCLUDES = -I/home/auxiliary/include -I./include
#
INCLUDES :=
#
# Define library paths in addition to /usr/lib
# If wanted libraries not in /usr/lib, specify their path using -Lpath
#
# e.g., LFLAGS = -L/home/auxiliary/lib -L./lib
#
LFLAGS :=
#
# Define any libraries to link into executable, use the -llibname option
#
LIBS := -lm
#***************************************************************************#
#
# Make Configuration
#
#***************************************************************************#
#
# Define the C source files
#
SRCS := $(wildcard *.c)
#
# Define the C object files
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .c of all words in the macro SRCS
# with the .o suffix
#
OBJS := $(SRCS:.c=.o)
#
# Search path for make program
# make uses VPATH as a search list for both
# prerequisites and targets of rules.
#
VPATH :=
#
# Clean list
#
CLEANLIST += $(OBJS) $(BINNAME)
#***************************************************************************#
#
# Build
#
#***************************************************************************#
#
# all
#
.PHONY: all
all: $(BINNAME)
@echo $(BINNAME) has been compiled
#
# install
#
.PHONY: install
install:
@echo "Creating directories"
@mkdir -p $(bindir)
@mkdir -p $(infodir)
@echo "Installing to $(bindir)/$(BINNAME)"
@$(INSTALL) $(BINNAME) $(bindir)/$(BINNAME)
@$(INSTALLDATA) $(srcdir)/Makefile $(infodir)
#
# uninstall
#
.PHONY: uninstall
uninstall:
@echo "Removing $(bindir)/$(BINNAME)"
@$(RM) $(bindir)/$(BINNAME)
#
# Invoke object files
#
$(BINNAME): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) $(CPPFLAGS) -o $@ $(OBJS) $(LFLAGS) $(LIBS)
#
# Static pattern rule for automatic prerequisite generation
#
DPND := $(SRCS:.c=.d)
# Automatic prerequisites flag: -M for any compiler, -MM for GNU to
# omit system headers. But -MM usually work with ICC without problem.
ifeq ($(CC),icc)
AUTOPRE := -MM
else
AUTOPRE := -MM
endif
$(DPND): %.d: %.c
@set -e; rm -f $@; \
$(CC) $(AUTOPRE) $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# Include generated dependencies. Extra spaces are allowed and ignored
# at the beginning of the include line, but the first character must
# NOT be a tab
ifneq ($(MAKECMDGOALS),clean)
-include ${DPND}
endif
# add dependency files to clean list
CLEANLIST += $(DPND)
#
# Build object files
# object files can be built by the automatically generated
# prerequisites through implicit rules. Generally,
# to specify additional prerequisites, such as header files,
# implicit rules are more desirable.
#
#
# clean
# When a line starts with ‘@’, the echoing of that line
# itself is suppressed.
# a '-' flag makes errors to be ignored
#
.PHONY: clean
clean:
@echo cleaning...
@- $(RM) $(CLEANLIST)
#***************************************************************************#