forked from libocca/occa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
222 lines (178 loc) · 7.98 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
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 .mm .o .so .dylib
# Cancel some implicit rules
%: %.o
%.o: %.cpp
%: %.cpp
%: %.mm
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))
ifeq (${PREFIX},)
OCCA_BUILD_DIR := $(OCCA_DIR)
else
OCCA_BUILD_DIR := ${PREFIX}
endif
#=================================================
#---[ Flags ]-------------------------------------
# Expand and overwrite flag variables to avoid
# multiple expansions which are slow.
compilerFlags := $(compilerFlags)
flags := $(flags)
sharedFlag := $(sharedFlag)
pthreadFlag := $(pthreadFlag)
#=================================================
#---[ Compilation Variables ]---------------------
srcToObject = $(subst $(PROJ_DIR)/src,$(PROJ_DIR)/obj,$(1:.cpp=.o))
dontCompile = $(OCCA_DIR)/src/core/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' -o -name "*.h"))
testSources = $(realpath $(shell find $(PROJ_DIR)/tests/src -type f -name '*.cpp'))
tests = $(subst $(testPath)/src,$(testPath)/bin,$(testSources:.cpp=))
objects = $(call srcToObject,$(sources))
# Only compile Objective-C++ if Metal is enabled
ifeq ($(metalEnabled),1)
objcSrcToObject = $(subst $(PROJ_DIR)/src,$(PROJ_DIR)/obj,$(1:.mm=.o))
objcSources = $(realpath $(shell find $(PROJ_DIR)/src -type f -name '*.mm'))
objects += $(call objcSrcToObject,$(objcSources))
endif
outputs = $(libPath)/libocca.$(soExt) $(binPath)/occa
ifdef SANITIZER_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_CUDA_ENABLED@@,$(OCCA_CUDA_ENABLED),g;\
s,@@OCCA_HIP_ENABLED@@,$(OCCA_HIP_ENABLED),g;\
s,@@OCCA_OPENCL_ENABLED@@,$(OCCA_OPENCL_ENABLED),g;\
s,@@OCCA_METAL_ENABLED@@,$(OCCA_METAL_ENABLED),g;\
s,@@OCCA_BUILD_DIR@@,$(OCCA_BUILD_DIR),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)/include/occa/scripts/shellTools.sh && installOcca)
@echo "> occa info"
@$(OCCA_DIR)/bin/occa info
$(COMPILED_DEFINES_CHANGED):
#=================================================
#---[ Builds ]------------------------------------
# ---[ libocca ]-------------
$(libPath)/libocca.$(soExt):$(objects) $(headers) $(COMPILED_DEFINES)
mkdir -p $(libPath)
$(compiler) $(compilerFlags) $(sharedFlag) $(pthreadFlag) $(soNameFlag) -o $(libPath)/libocca.$(soExt) $(flags) $(objects) $(paths) $(filter-out -locca, $(linkerFlags))
$(binPath)/occa:$(OCCA_DIR)/bin/occa.cpp $(libPath)/libocca.$(soExt) $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(binPath)
$(compiler) $(compilerFlags) -o $(binPath)/occa -Wl,-rpath,$(libPath) $(flags) $(OCCA_DIR)/bin/occa.cpp $(paths) $(linkerFlags) -L$(OCCA_DIR)/lib -locca
# ===========================
# Sources with C++ headers and template headers
$(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) $<
# Sources with C++ headers
$(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) $<
# Sources with C headers
$(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) $<
# Objective-C++ sources
$(OCCA_DIR)/obj/%.o:$(OCCA_DIR)/src/%.mm $(OCCA_DIR)/include/occa/%.hpp $(COMPILED_DEFINES_CHANGED)
@mkdir -p $(abspath $(dir $@))
clang++ -x objective-c++ -o $@ $(flags) -c $(paths) $<
# Header-less sources
$(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 bin-tests
unit-tests: $(tests)
@$(testPath)/run_tests
e2e-tests: unit-tests
@$(testPath)/run_examples
bin-tests: unit-tests
@$(testPath)/run_bin_tests
$(testPath)/bin/%:$(testPath)/src/%.cpp $(outputs)
@mkdir -p $(abspath $(dir $@))
$(compiler) $(testFlags) $(pthreadFlag) -o $@ -Wl,-rpath,$(libPath) $(flags) $< $(paths) $(linkerFlags) -L$(OCCA_DIR)/lib -locca
#=================================================
#---[ Clean ]-------------------------------------
clean:
rm -rf $(objPath)/*
rm -rf $(binPath)/occa
rm -rf $(testPath)/bin
rm -rf $(testPath)/src/io/locks
rm -f $(libPath)/libocca.$(soExt)
#=================================================
#---[ 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 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 metalEnabled = $(metalEnabled))
$(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
#=================================================