Debian Codegraph @

GNUmakefile

raw
1 # Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
2 # SPDX-License-Identifier: BSD-3-Clause
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
5 #
6 # See INSTALL.md for usage.
7
8 #-------------------------------------------------------------------------------
9 # Configuration
10 # Variables defined in make.inc, or use make's defaults:
11 # CXX, CXXFLAGS -- C compiler and flags
12 # LD, LDFLAGS, LIBS -- Linker, options, library paths, and libraries
13 # AR, RANLIB -- Archiver, ranlib updates library TOC
14 # prefix -- where to install BLAS++
15
16 ifeq (${MAKECMDGOALS},config)
17 # For `make config`, don't include make.inc with previous config;
18 # force re-creating make.inc.
19 .PHONY: config
20 config: make.inc
21
22 make.inc: force
23 else ifneq (clean,${findstring clean,${MAKECMDGOALS}})
24 # For `make clean` or `make distclean`, don't include make.inc,
25 # which could generate it. Otherwise, include make.inc.
26 include make.inc
27 endif
28
29 python ?= python3
30
31 force: ;
32
33 make.inc:
34 ${python} configure.py
35
36 # Defaults if not given in make.inc. GNU make doesn't have defaults for these.
37 NVCC ?= nvcc
38 HIPCC ?= hipcc
39 RANLIB ?= ranlib
40 prefix ?= /opt/slate
41
42 abs_prefix := ${abspath ${prefix}}
43
44 # Default LD=ld won't work; use CXX. Can override in make.inc or environment.
45 ifeq (${origin LD},default)
46 LD = ${CXX}
47 endif
48
49 # Use abi-compliance-checker to compare the ABI (application binary
50 # interface) of 2 releases. Changing the ABI does not necessarily change
51 # the API (application programming interface). Rearranging a struct or
52 # changing a by-value argument from int64 to int doesn't change the
53 # API--no source code changes are required, just a recompile.
54 #
55 # if structs or routines are changed or removed:
56 # bump major version and reset minor, revision = 0;
57 # else if structs or routines are added:
58 # bump minor version and reset revision = 0;
59 # else (e.g., bug fixes):
60 # bump revision
61 #
62 # soversion is major ABI version.
63 abi_version = 2.0.0
64 soversion = ${word 1, ${subst ., ,${abi_version}}}
65
66 #-------------------------------------------------------------------------------
67 ldflags_shared = -shared
68
69 # auto-detect OS
70 # $OSTYPE may not be exported from the shell, so echo it
71 ostype := ${shell echo $${OSTYPE}}
72 ifneq (,${findstring darwin, ${ostype}})
73 # MacOS is darwin
74 macos = 1
75 # MacOS needs shared library's path set, and shared library version.
76 ldflags_shared += -install_name @rpath/${notdir $@} \
77 -current_version ${abi_version} \
78 -compatibility_version ${soversion}
79 so = dylib
80 so2 = .dylib
81 # on macOS, .dylib comes after version: libfoo.4.dylib
82 else
83 # Linux needs shared library's soname.
84 ldflags_shared += -Wl,-soname,${notdir ${lib_soname}}
85 so = so
86 so1 = .so
87 # on Linux, .so comes before version: libfoo.so.4
88 endif
89
90 #-------------------------------------------------------------------------------
91 ifeq (${papi},1)
92 CXXFLAGS += -DBLAS_HAVE_PAPI -I ${PAPI_DIR}/include
93 LDFLAGS += -L ${PAPI_DIR}/lib -Wl,-rpath,${abspath ${PAPI_DIR}/lib}
94 LIBS += -lsde
95 TEST_LIBS += -lpapi
96 endif
97
98 #-------------------------------------------------------------------------------
99 # Detect CUDA or HIP from make.inc LIBS.
100 cuda = 0
101 hip = 0
102 ifneq (,${findstring cublas,${LIBS}})
103 cuda = 1
104 else ifneq (,${findstring rocblas,${LIBS}})
105 hip = 1
106 endif
107
108 #-------------------------------------------------------------------------------
109 # if shared
110 ifneq (${static},1)
111 CXXFLAGS += -fPIC
112 NVCCFLAGS += --compiler-options -fPIC
113 HIPCCFLAGS += -fPIC
114 LDFLAGS += -fPIC
115 lib_ext = ${so}
116 else
117 lib_ext = a
118 endif
119
120 #-------------------------------------------------------------------------------
121 # Files
122
123 lib_src = ${wildcard src/*.cc}
124 ifeq (${cuda},1)
125 lib_src += ${wildcard src/cuda/*.cu}
126 endif
127 ifeq (${hip},1)
128 lib_src += ${wildcard src/hip/*.hip}
129 endif
130
131 lib_obj = ${addsuffix .o, ${basename ${lib_src}}}
132 dep += ${addsuffix .d, ${basename ${lib_src}}}
133
134 tester_src = ${wildcard test/*.cc}
135 tester_obj = ${addsuffix .o, ${basename ${tester_src}}}
136 dep += ${addsuffix .d, ${basename ${tester_src}}}
137
138 tester = test/tester
139
140 pkg = lib/pkgconfig/blaspp.pc
141
142 #-------------------------------------------------------------------------------
143 # TestSweeper
144
145 testsweeper_dir = ${wildcard ../testsweeper}
146 ifeq (${testsweeper_dir},)
147 testsweeper_dir = ${wildcard ./testsweeper}
148 endif
149
150 testsweeper_src = ${wildcard ${testsweeper_dir}/testsweeper.cc ${testsweeper_dir}/testsweeper.hh}
151
152 testsweeper = ${testsweeper_dir}/libtestsweeper.${lib_ext}
153
154 testsweeper: ${testsweeper}
155
156 ifneq (${testsweeper_dir},)
157 ${testsweeper}: ${testsweeper_src}
158 cd ${testsweeper_dir} && ${MAKE} lib CXX=${CXX}
159 else
160 ${testsweeper}:
161 ${error Tester requires TestSweeper, which was not found. Run 'make config' \
162 or download manually from https://github.com/icl-utk-edu/testsweeper}
163 endif
164
165 # Compile TestSweeper before BLAS++.
166 ${lib_obj} ${tester_obj}: | ${testsweeper}
167
168 #-------------------------------------------------------------------------------
169 # Get Mercurial id, and make version.o depend on it via .id file.
170
171 ifneq (${wildcard .git},)
172 id := ${shell git rev-parse --short HEAD}
173 src/version.o: CXXFLAGS += -DBLASPP_ID='"${id}"'
174 endif
175
176 last_id := ${shell [ -e .id ] && cat .id || echo 'NA'}
177 ifneq (${id},${last_id})
178 .id: force
179 endif
180
181 .id:
182 echo ${id} > .id
183
184 src/version.o: .id
185
186 #-------------------------------------------------------------------------------
187 # BLAS++ specific flags and libraries
188 CXXFLAGS += -I./include
189 NVCCFLAGS += -I./include
190 HIPCCFLAGS += -I./include
191
192 # additional flags and libraries for testers
193 ${tester_obj}: CXXFLAGS += -I${testsweeper_dir}
194
195 TEST_LDFLAGS += -L./lib -Wl,-rpath,${abspath ./lib}
196 TEST_LDFLAGS += -L${testsweeper_dir} -Wl,-rpath,${abspath ${testsweeper_dir}}
197 TEST_LIBS += -lblaspp -ltestsweeper
198
199 #-------------------------------------------------------------------------------
200 # Rules
201 .DELETE_ON_ERROR:
202 .SUFFIXES:
203 .PHONY: all docs hooks lib src test tester headers include clean distclean
204 .DEFAULT_GOAL = all
205
206 all: lib tester hooks
207
208 install: lib ${pkg}
209 mkdir -p ${DESTDIR}${abs_prefix}/include/blas
210 mkdir -p ${DESTDIR}${abs_prefix}/lib${LIB_SUFFIX}/pkgconfig
211 cp include/*.hh ${DESTDIR}${abs_prefix}/include/
212 cp include/blas/*.h ${DESTDIR}${abs_prefix}/include/blas/
213 cp include/blas/*.hh ${DESTDIR}${abs_prefix}/include/blas/
214 cp -av ${lib_name}* ${DESTDIR}${abs_prefix}/lib${LIB_SUFFIX}/
215 cp ${pkg} ${DESTDIR}${abs_prefix}/lib${LIB_SUFFIX}/pkgconfig/
216
217 uninstall:
218 ${RM} ${DESTDIR}${abs_prefix}/include/blas.hh
219 ${RM} -r ${DESTDIR}${abs_prefix}/include/blas
220 ${RM} ${DESTDIR}${abs_prefix}/lib${LIB_SUFFIX}/${notdir ${lib_name}*}
221 ${RM} ${DESTDIR}${abs_prefix}/lib${LIB_SUFFIX}/pkgconfig/blaspp.pc
222
223 #-------------------------------------------------------------------------------
224 # if re-configured, recompile everything
225 ${lib_obj} ${tester_obj}: make.inc
226
227 #-------------------------------------------------------------------------------
228 # Generic rule for shared libraries.
229 # For libfoo.so version 4.5.6, this creates libfoo.so.4.5.6 and symlinks
230 # libfoo.so.4 -> libfoo.so.4.5.6
231 # libfoo.so -> libfoo.so.4
232 #
233 # Needs [private] variables set (shown with example values):
234 # LDFLAGS = -L/path/to/lib
235 # LIBS = -lmylib
236 # lib_obj = src/foo.o src/bar.o
237 # lib_so_abi = libfoo.so.4.5.6
238 # lib_soname = libfoo.so.4
239 # abi_version = 4.5.6
240 # soversion = 4
241 %.${lib_ext}:
242 mkdir -p lib
243 ${LD} ${LDFLAGS} ${ldflags_shared} ${LIBS} ${lib_obj} -o ${lib_so_abi}
244 ln -fs ${notdir ${lib_so_abi}} ${lib_soname}
245 ln -fs ${notdir ${lib_soname}} $@
246
247 # Generic rule for static libraries, creates libfoo.a.
248 # The library should depend only on its objects.
249 %.a:
250 mkdir -p lib
251 ${RM} $@
252 ${AR} cr $@ $^
253 ${RANLIB} $@
254
255 #-------------------------------------------------------------------------------
256 # BLAS++ library
257 # so is like libfoo.so or libfoo.dylib
258 # so_abi is like libfoo.so.4.5.6 or libfoo.4.5.6.dylib
259 # soname is like libfoo.so.4 or libfoo.4.dylib
260 lib_name = lib/libblaspp
261 lib_a = ${lib_name}.a
262 lib_so = ${lib_name}.${so}
263 lib = ${lib_name}.${lib_ext}
264 lib_so_abi = ${lib_name}${so1}.${abi_version}${so2}
265 lib_soname = ${lib_name}${so1}.${soversion}${so2}
266
267 ${lib_so}: ${lib_obj}
268
269 ${lib_a}: ${lib_obj}
270
271 # sub-directory rules
272 lib src: ${lib}
273
274 lib/clean src/clean:
275 ${RM} ${lib_a} ${lib_so} ${lib_so_abi} ${lib_soname} ${lib_obj}
276
277 #-------------------------------------------------------------------------------
278 # tester
279 ${tester}: ${tester_obj} ${lib} ${testsweeper}
280 ${LD} ${TEST_LDFLAGS} ${LDFLAGS} ${tester_obj} \
281 ${TEST_LIBS} ${LIBS} -o $@
282
283 # sub-directory rules
284 # Note 'test' is sub-directory rule; 'tester' is CMake-compatible rule.
285 test: ${tester}
286 tester: ${tester}
287
288 test/clean:
289 ${RM} ${tester} test/*.o
290
291 test/check: check
292
293 check: tester
294 cd test; ${python} run_tests.py --quick
295
296 #-------------------------------------------------------------------------------
297 # headers
298 # precompile headers to verify self-sufficiency
299 headers = ${wildcard include/blas.hh include/blas/*.h include/blas/*.hh test/*.hh}
300 headers_gch = ${addsuffix .gch, ${basename ${headers}}}
301
302 headers: ${headers_gch}
303
304 headers/clean:
305 ${RM} ${headers_gch}
306
307 # sub-directory rules
308 include: headers
309
310 include/clean: headers/clean
311
312 #-------------------------------------------------------------------------------
313 # pkgconfig
314 # Keep -std=c++11 in CXXFLAGS. Keep -fopenmp in LDFLAGS.
315 CXXFLAGS_clean = ${filter-out -O% -W% -pedantic -D% -I./include -MMD -fPIC -fopenmp, ${CXXFLAGS}}
316 CPPFLAGS_clean = ${filter-out -O% -W% -pedantic -D% -I./include -MMD -fPIC -fopenmp, ${CPPFLAGS}}
317 LDFLAGS_clean = ${filter-out -fPIC, ${LDFLAGS}}
318
319 .PHONY: ${pkg}
320 ${pkg}:
321 perl -pe "s'#VERSION'2025.05.28'; \
322 s'#PREFIX'${abs_prefix}'; \
323 s'#CXX\b'${CXX}'; \
324 s'#CXXFLAGS'${CXXFLAGS_clean}'; \
325 s'#CPPFLAGS'${CPPFLAGS_clean}'; \
326 s'#LDFLAGS'${LDFLAGS_clean}'; \
327 s'#LIBS'${LIBS}';" \
328 [email protected] > $@
329
330 #-------------------------------------------------------------------------------
331 # documentation
332 docs: docs/html/index.html
333
334 doc_files = \
335 docs/doxygen/DoxygenLayout.xml \
336 docs/doxygen/doxyfile.conf \
337 docs/doxygen/groups.dox \
338 README.md \
339 INSTALL.md \
340
341 docs/html/index.html: ${headers} ${lib_src} ${tester_src} ${doc_files}
342 doxygen docs/doxygen/doxyfile.conf
343 @echo ========================================
344 cat docs/doxygen/errors.txt
345 @echo ========================================
346 @echo "Documentation available in docs/html/index.html"
347 @echo ========================================
348
349 # sub-directory redirects
350 src/docs: docs
351 test/docs: docs
352
353 #-------------------------------------------------------------------------------
354 # general rules
355 clean: lib/clean test/clean headers/clean
356 ${RM} ${dep}
357
358 distclean: clean
359 ${RM} make.inc include/blas/defines.h
360
361 # Install git hooks
362 hooks = .git/hooks/pre-commit
363
364 hooks: ${hooks}
365
366 .git/hooks/%: tools/hooks/%
367 @if [ -e .git/hooks ]; then \
368 echo cp $< $@ ; \
369 cp $< $@ ; \
370 fi
371
372 %.o: %.hip
373 ${HIPCC} ${HIPCCFLAGS} -c $< -o $@
374
375 %.o: %.cu
376 ${NVCC} ${NVCCFLAGS} -c $< -o $@
377
378 %.o: %.cc
379 ${CXX} ${CXXFLAGS} -c $< -o $@
380
381 # preprocess source
382 %.i: %.cc
383 ${CXX} ${CXXFLAGS} -I${testsweeper_dir} -E $< -o $@
384
385 # preprocess source
386 %.i: %.h
387 ${CXX} ${CXXFLAGS} -I${testsweeper_dir} -E $< -o $@
388
389 # preprocess source
390 %.i: %.hh
391 ${CXX} ${CXXFLAGS} -I${testsweeper_dir} -E $< -o $@
392
393 # precompile header to check for errors
394 %.gch: %.h
395 ${CXX} ${CXXFLAGS} -I${testsweeper_dir} -c $< -o $@
396
397 %.gch: %.hh
398 ${CXX} ${CXXFLAGS} -I${testsweeper_dir} -c $< -o $@
399
400 -include ${dep}
401
402 #-------------------------------------------------------------------------------
403 # debugging
404 echo:
405 @echo "---------- Options"
406 @echo "static = '${static}'"
407 @echo "prefix = '${prefix}'"
408 @echo "abs_prefix = '${abs_prefix}'"
409 @echo "papi = '${papi}'"
410 @echo
411 @echo "---------- Internal variables"
412 @echo "ostype = '${ostype}'"
413 @echo "macos = '${macos}'"
414 @echo "id = '${id}'"
415 @echo "last_id = '${last_id}'"
416 @echo "abi_version = '${abi_version}'"
417 @echo "soversion = '${soversion}'"
418 @echo "cuda = '${cuda}'"
419 @echo "hip = '${hip}'"
420 @echo "sycl = '${sycl}'"
421 @echo
422 @echo "---------- Libraries"
423 @echo "lib_name = ${lib_name}"
424 @echo "lib_a = ${lib_a}"
425 @echo "lib_so = ${lib_so}"
426 @echo "lib = ${lib}"
427 @echo "lib_so_abi = ${lib_so_abi}"
428 @echo "lib_soname = ${lib_soname}"
429 @echo
430 @echo "pkg = ${pkg}"
431 @echo
432 @echo "lib_src = ${lib_src}"
433 @echo
434 @echo "lib_obj = ${lib_obj}"
435 @echo
436 @echo "tester_src = ${tester_src}"
437 @echo
438 @echo "tester_obj = ${tester_obj}"
439 @echo
440 @echo "tester = ${tester}"
441 @echo
442 @echo "dep = ${dep}"
443 @echo
444 @echo "testsweeper_dir = ${testsweeper_dir}"
445 @echo "testsweeper_src = ${testsweeper_src}"
446 @echo "testsweeper = ${testsweeper}"
447 @echo
448 @echo "---------- C++ compiler"
449 @echo "CXX = ${CXX}"
450 @echo "CXXFLAGS = ${CXXFLAGS}"
451 @echo
452 @echo "---------- Link flags"
453 @echo "LD = ${LD}"
454 @echo "LDFLAGS = ${LDFLAGS}"
455 @echo "LIBS = ${LIBS}"
456 @echo "ldflags_shared = ${ldflags_shared}"
457 @echo
458 @echo "TEST_LDFLAGS = ${TEST_LDFLAGS}"
459 @echo "TEST_LIBS = ${TEST_LIBS}"