forked from libocca/occa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
214 lines (174 loc) · 8.06 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
# The MIT License (MIT)
#
# Copyright (c) 2014-2018 David Medina and Tim Warburton
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
rmSlash = $(patsubst %/,%,$1)
OCCA_DIR := $(call rmSlash,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
PROJ_DIR := $(OCCA_DIR)
# Clear the list of suffixes
.SUFFIXES:
.SUFFIXES: .hpp .h .tpp .cpp .o .so
# Cancel some implicit rules
%: %.o
%.o: %.cpp
%: %.cpp
include $(OCCA_DIR)/scripts/Makefile
#---[ Working Paths ]-----------------------------
ifeq ($(usingWinux),0)
compilerFlags += $(picFlag)
fCompilerFlags += $(picFlag)
else
sharedFlag += $(picFlag)
endif
# [-L$OCCA_DIR/lib -locca] are kept for applications
# using $OCCA_DIR/scripts/Makefile
paths += -I$(srcPath)
paths := $(filter-out -L$(OCCA_DIR)/lib,$(paths))
linkerFlags := $(filter-out -locca,$(linkerFlags))
#=================================================
#---[ Flags ]-------------------------------------
# Expand and overwrite flag variables to avoid
# multiple expansions which are slow.
compilerFlags := $(compilerFlags)
flags := $(flags)
sharedFlag := $(sharedFlag)
pthreadFlag := $(pthreadFlag)
#=================================================
#---[ variables ]---------------------------------
srcToObject = $(subst $(PROJ_DIR)/src,$(PROJ_DIR)/obj,$(1:.cpp=.o))
dontCompile = $(OCCA_DIR)/src/kernelOperators.cpp $(OCCA_DIR)/src/tools/runFunction.cpp
sources = $(realpath $(shell find $(PROJ_DIR)/src -type f -name '*.cpp'))
sources := $(filter-out $(dontCompile),$(sources))
headers = $(realpath $(shell find $(PROJ_DIR)/include -type f -name '*.hpp'))
testSources = $(realpath $(shell find $(PROJ_DIR)/tests/src -type f -name '*.cpp'))
tests = $(subst $(testPath)/src,$(testPath)/bin,$(testSources:.cpp=))
objects = $(call srcToObject,$(sources))
outputs = $(libPath)/libocca.so $(binPath)/occa
ifndef VALGRIND_ENABLED
testFlags = $(compilerFlags) -fsanitize=address -fno-omit-frame-pointer
else
testFlags = $(compilerFlags)
endif
#=================================================
#---[ Compile Library ]---------------------------
# Setup compiled defines and force rebuild if defines changed
COMPILED_DEFINES := $(OCCA_DIR)/include/occa/defines/compiledDefines.hpp
NEW_COMPILED_DEFINES := $(OCCA_DIR)/.compiledDefines
MAKE_COMPILED_DEFINES := $(shell cat "$(OCCA_DIR)/scripts/compiledDefinesTemplate.hpp" | \
sed "s,@@OCCA_OS@@,$(OCCA_OS),g;\
s,@@OCCA_USING_VS@@,$(OCCA_USING_VS),g;\
s,@@OCCA_UNSAFE@@,$(OCCA_UNSAFE),g;\
s,@@OCCA_MPI_ENABLED@@,$(OCCA_MPI_ENABLED),g; \
s,@@OCCA_OPENMP_ENABLED@@,$(OCCA_OPENMP_ENABLED),g;\
s,@@OCCA_OPENCL_ENABLED@@,$(OCCA_OPENCL_ENABLED),g;\
s,@@OCCA_CUDA_ENABLED@@,$(OCCA_CUDA_ENABLED),g;\
s,@@OCCA_HIP_ENABLED@@,$(OCCA_HIP_ENABLED),g;" > "$(NEW_COMPILED_DEFINES)")
MAKE_COMPILED_DEFINES := $(shell \
[ ! -f "$(COMPILED_DEFINES)" -o -n "$(shell diff -q $(COMPILED_DEFINES) $(NEW_COMPILED_DEFINES))" ] \
&& cp "$(NEW_COMPILED_DEFINES)" "$(COMPILED_DEFINES)" \
)
MAKE_COMPILED_DEFINES := $(shell rm $(NEW_COMPILED_DEFINES))
all: $(objects) $(outputs)
@(. $(OCCA_DIR)/scripts/shellTools.sh && installOcca)
@echo "> occa info"
@$(OCCA_DIR)/bin/occa info
$(COMPILED_DEFINES_CHANGED):
#=================================================
#---[ Builds ]------------------------------------
# ---[ libocca ]-------------
$(libPath)/libocca.so:$(objects) $(headers) $(COMPILED_DEFINES)
mkdir -p $(libPath)
$(compiler) $(compilerFlags) $(sharedFlag) $(pthreadFlag) -o $(libPath)/libocca.so $(flags) $(objects) $(paths) $(filter-out -locca, $(linkerFlags))
$(binPath)/occa:$(OCCA_DIR)/scripts/occa.cpp $(libPath)/libocca.so $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(binPath)
$(compiler) $(compilerFlags) -o $(binPath)/occa -Wl,-rpath,$(libPath) $(flags) $(OCCA_DIR)/scripts/occa.cpp $(paths) $(linkerFlags) -L$(OCCA_DIR)/lib -locca
# ===========================
$(OCCA_DIR)/obj/%.o:$(OCCA_DIR)/src/%.cpp $(OCCA_DIR)/include/occa/%.hpp $(OCCA_DIR)/include/occa/%.tpp $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(compilerFlags) -o $@ $(flags) -c $(paths) $<
$(OCCA_DIR)/obj/%.o:$(OCCA_DIR)/src/%.cpp $(OCCA_DIR)/include/occa/%.hpp $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(compilerFlags) -o $@ $(flags) -c $(paths) $<
$(OCCA_DIR)/obj/%.o:$(OCCA_DIR)/src/%.cpp $(OCCA_DIR)/include/occa/%.h $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(compilerFlags) -o $@ $(flags) -c $(paths) $<
$(OCCA_DIR)/obj/%.o:$(OCCA_DIR)/src/%.cpp $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(compilerFlags) -o $@ $(flags) -c $(paths) $<
#=================================================
#---[ Test ]--------------------------------------
tests: $(tests)
test: unit-tests e2e-tests
unit-tests: $(tests)
@$(testPath)/run_tests
e2e-tests: unit-tests
@$(testPath)/run_examples
$(testPath)/bin/%:$(testPath)/src/%.cpp $(libPath)/libocca.so
@mkdir -p $(abspath $(dir $@))
$(compiler) $(testFlags) $(pthreadFlag) -o $@ $(flags) $< $(paths) $(linkerFlags) -L$(OCCA_DIR)/lib -locca
#=================================================
#---[ Clean ]-------------------------------------
clean:
rm -rf $(objPath)/*
rm -rf $(binPath)/*
rm -rf $(testPath)/bin/*;
rm -f $(libPath)/libocca.so
rm -f $(OCCA_DIR)/scripts/main
#=================================================
#---[ Info ]--------------------------------------
info:
$(info --------------------------------)
$(info CXX = $(or $(CXX),(empty)))
$(info CXXFLAGS = $(or $(CXXFLAGS),(empty)))
$(info LDFLAGS = $(or $(LDFLAGS),(empty)))
$(info --------------------------------)
$(info compiler = $(value compiler))
$(info compilerFlags = $(compilerFlags))
$(info flags = $(flags))
$(info paths = $(paths))
$(info sharedFlag = $(sharedFlag))
$(info pthreadFlag = $(pthreadFlag))
$(info linkerFlags = $(linkerFlags))
$(info --------------------------------)
# $(info OCCA_DEVELOPER = $(OCCA_DEVELOPER))
$(info debugEnabled = $(debugEnabled))
$(info checkEnabled = $(checkEnabled))
$(info debugFlags = $(debugFlags))
$(info releaseFlags = $(releaseFlags))
$(info picFlag = $(picFlag))
$(info --------------------------------)
$(info mpiEnabled = $(mpiEnabled))
$(info openmpEnabled = $(openmpEnabled))
$(info openclEnabled = $(openclEnabled))
$(info cudaEnabled = $(cudaEnabled))
$(info hipEnabled = $(hipEnabled))
$(info --------------------------------)
@true
#=================================================
#---[ Print ]-------------------------------------
# Print the contents of a makefile variable, e.g.: 'make print-compiler'.
print-%:
$(info [ variable name]: $*)
$(info [ origin]: $(origin $*))
$(info [ value]: $(value $*))
$(info [expanded value]: $($*))
$(info )
@true
#=================================================