xref: /libCEED/Makefile (revision b0f67a9c1aeeb4d82b4724afaae1227ff4e81f15)
1# Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# This file is part of CEED:  http://github.com/ceed
7
8# ------------------------------------------------------------
9# Configuration
10# ------------------------------------------------------------
11
12# config.mk stores cached configuration variables
13CONFIG ?= config.mk
14-include $(CONFIG)
15
16# common.mk holds definitions used in various makefiles throughout the project
17COMMON ?= common.mk
18-include $(COMMON)
19
20# Quiet, color output
21quiet ?= $($(1))
22
23# Cancel built-in and old-fashioned implicit rules which we don't use
24.SUFFIXES:
25
26.SECONDEXPANSION: # to expand $$(@D)/.DIR
27
28%/.DIR :
29	@mkdir -p $(@D)
30	@touch $@
31
32.PRECIOUS: %/.DIR
33
34
35# ------------------------------------------------------------
36# Root directories for backend dependencies
37# ------------------------------------------------------------
38
39# XSMM_DIR env variable should point to XSMM main (github.com/hfp/libxsmm)
40XSMM_DIR ?= ../libxsmm
41
42# Often /opt/cuda or /usr/local/cuda, but sometimes present on machines that don't support CUDA
43CUDA_DIR  ?=
44CUDA_ARCH ?=
45
46# Often /opt/rocm, but sometimes present on machines that don't support HIP
47ROCM_DIR ?=
48HIP_ARCH ?=
49
50# env variable MAGMA_DIR can be used too
51MAGMA_DIR ?= ../magma
52
53
54# ------------------------------------------------------------
55# Compiler flags
56# ------------------------------------------------------------
57
58# Detect user compiler options and set defaults
59ifeq (,$(filter-out undefined default,$(origin CC)))
60  CC = gcc
61endif
62ifeq (,$(filter-out undefined default,$(origin CXX)))
63  CXX = g++
64endif
65ifeq (,$(filter-out undefined default,$(origin FC)))
66  FC = gfortran
67endif
68ifeq (,$(filter-out undefined default,$(origin LINK)))
69  LINK = $(CC)
70endif
71ifeq (,$(filter-out undefined default,$(origin AR)))
72  AR = ar
73endif
74ifeq (,$(filter-out undefined default,$(origin ARFLAGS)))
75  ARFLAGS = crD
76endif
77NVCC ?= $(CUDA_DIR)/bin/nvcc
78NVCC_CXX ?= $(CXX)
79HIPCC ?= $(ROCM_DIR)/bin/hipcc
80SYCLCXX ?= $(CXX)
81SED ?= sed
82ifneq ($(EMSCRIPTEN),)
83  STATIC = 1
84  EXE_SUFFIX = .wasm
85  EM_LDFLAGS = -s TOTAL_MEMORY=256MB
86endif
87
88# ASAN must be left empty if you don't want to use it
89ASAN ?=
90
91# These are the values automatically detected here in the makefile. They are
92# augmented with LDFLAGS and LDLIBS from the environment/passed by command line,
93# if any. If the user sets CEED_LDFLAGS or CEED_LDLIBS, they are used *instead
94# of* what we populate here (thus that's advanced usage and not recommended).
95CEED_LDFLAGS ?=
96CEED_LDLIBS  ?=
97
98UNDERSCORE ?= 1
99
100# Verbose mode, V or VERBOSE
101V ?= $(VERBOSE)
102
103# SANTIZ options
104AFLAGS ?= -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
105
106# Note: Intel oneAPI C/C++ compiler is now icx/icpx
107CC_VENDOR := $(firstword $(filter gcc (GCC) clang cc icc icc_orig oneAPI XL emcc,$(subst -, ,$(shell $(CC) --version))))
108CC_VENDOR := $(subst (GCC),gcc,$(subst icc_orig,icc,$(CC_VENDOR)))
109CC_VENDOR := $(if $(filter cc,$(CC_VENDOR)),gcc,$(CC_VENDOR))
110FC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort ifx XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
111
112# Default extra flags by vendor
113MARCHFLAG.gcc           := -march=native
114MARCHFLAG.clang         := $(MARCHFLAG.gcc)
115MARCHFLAG.icc           :=
116MARCHFLAG.oneAPI        := $(MARCHFLAG.clang)
117OMP_SIMD_FLAG.gcc       := -fopenmp-simd
118OMP_SIMD_FLAG.clang     := $(OMP_SIMD_FLAG.gcc)
119OMP_SIMD_FLAG.icc       := -qopenmp-simd
120OMP_SIMD_FLAG.oneAPI    := $(OMP_SIMD_FLAG.icc)
121OMP_FLAG.gcc            := -fopenmp
122OMP_FLAG.clang          := $(OMP_FLAG.gcc)
123OMP_FLAG.icc            := -qopenmp
124OMP_FLAG.oneAPI         := $(OMP_FLAG.icc)
125SYCL_FLAG.gcc           :=
126SYCL_FLAG.clang         := -fsycl
127SYCL_FLAG.icc           :=
128SYCL_FLAG.oneAPI        := -fsycl -fno-sycl-id-queries-fit-in-int
129OPT.gcc                 := -g -ffp-contract=fast
130OPT.clang               := $(OPT.gcc)
131OPT.icc                 := $(OPT.gcc)
132OPT.oneAPI              := $(OPT.clang)
133OPT.emcc                :=
134CFLAGS.gcc              := $(if $(STATIC),,-fPIC) -std=c11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
135CFLAGS.clang            := $(CFLAGS.gcc)
136CFLAGS.icc              := $(CFLAGS.gcc)
137CFLAGS.oneAPI           := $(CFLAGS.clang)
138CFLAGS.XL               := $(if $(STATIC),,-qpic) -MMD
139CFLAGS.emcc             := $(CFLAGS.clang)
140CXXFLAGS.gcc            := $(if $(STATIC),,-fPIC) -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
141CXXFLAGS.clang          := $(CXXFLAGS.gcc)
142CXXFLAGS.icc            := $(CXXFLAGS.gcc)
143CXXFLAGS.oneAPI         := $(CXXFLAGS.clang)
144CXXFLAGS.XL             := $(if $(STATIC),,-qpic) -std=c++11 -MMD
145CXXFLAGS.emcc           := $(CXXFLAGS.clang)
146FFLAGS.GNU              := $(if $(STATIC),,-fPIC) -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP
147FFLAGS.ifort            := $(if $(STATIC),,-fPIC) -cpp
148FFLAGS.ifx              := $(FFLAGS.ifort)
149FFLAGS.XL               := $(if $(STATIC),,-qpic) -ffree-form -qpreprocess -qextname -MMD
150
151# This check works with compilers that use gcc and clang.  It fails with some
152# compilers; e.g., xlc apparently ignores all options when -E is passed, thus
153# succeeds with any flags.  Users can pass MARCHFLAG=... if desired.
154cc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1)
155MARCHFLAG := $(MARCHFLAG.$(CC_VENDOR))
156MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native)
157MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG))
158
159OMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
160OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
161
162# Error checking flags
163PEDANTIC      ?=
164PEDANTICFLAGS ?= -Werror -pedantic
165
166# Compiler flags
167OPT    ?= -O $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
168CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
169CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
170FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
171LIBCXX ?= -lstdc++
172NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler '$(OPT)' -Xcompiler -fPIC
173ifneq ($(CUDA_ARCH),)
174  NVCCFLAGS += -arch=$(CUDA_ARCH)
175endif
176HIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics
177ifneq ($(HIP_ARCH),)
178  HIPCCFLAGS += --offload-arch=$(HIP_ARCH)
179endif
180SYCL_FLAG := $(SYCL_FLAG.$(CC_VENDOR))
181SYCLFLAGS ?= $(SYCL_FLAG) -fPIC -std=c++17 $(filter-out -std=c++11,$(CXXFLAGS)) $(filter-out $(OMP_SIMD_FLAG),$(OPT))
182
183OPENMP ?=
184ifneq ($(OPENMP),)
185  OMP_FLAG := $(OMP_FLAG.$(CC_VENDOR))
186  OMP_FLAG := $(if $(call cc_check_flag,$(OMP_FLAG)),$(OMP_FLAG))
187  CFLAGS += $(OMP_FLAG)
188  CEED_LDFLAGS += $(OMP_FLAG)
189endif
190
191ifeq ($(COVERAGE), 1)
192  CFLAGS += --coverage
193  CXXFLAGS += --coverage
194  CEED_LDFLAGS += --coverage
195endif
196
197CFLAGS += $(if $(ASAN),$(AFLAGS))
198FFLAGS += $(if $(ASAN),$(AFLAGS))
199CEED_LDFLAGS += $(if $(ASAN),$(AFLAGS))
200CPPFLAGS += -I./include
201CEED_LDLIBS = -lm
202OBJDIR := build
203for_install := $(filter install,$(MAKECMDGOALS))
204LIBDIR := $(if $(for_install),$(OBJDIR),lib)
205
206# Installation variables
207prefix ?= /usr/local
208bindir = $(prefix)/bin
209libdir = $(prefix)/lib
210includedir = $(prefix)/include
211pkgconfigdir = $(libdir)/pkgconfig
212INSTALL = install
213INSTALL_PROGRAM = $(INSTALL)
214INSTALL_DATA = $(INSTALL) -m644
215
216# Get number of processors of the machine
217NPROCS := $(shell getconf _NPROCESSORS_ONLN)
218# prepare make options to run in parallel
219MFLAGS := -j $(NPROCS) --warn-undefined-variables \
220                       --no-print-directory --no-keep-going
221
222PYTHON ?= python3
223PROVE ?= prove
224PROVE_OPTS ?= -j $(NPROCS)
225DARWIN := $(filter Darwin,$(shell uname -s))
226SO_EXT := $(if $(DARWIN),dylib,so)
227
228ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
229libceed.so := $(LIBDIR)/libceed.$(SO_EXT)
230libceed.a := $(LIBDIR)/libceed.a
231libceed := $(if $(STATIC),$(libceed.a),$(libceed.so))
232CEED_LIBS = -lceed
233libceeds = $(libceed)
234BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
235BACKENDS_MAKE := $(BACKENDS_BUILTIN)
236
237
238# ------------------------------------------------------------
239# Root directories for examples using external libraries
240# ------------------------------------------------------------
241
242# DEAL_II_DIR env variable should point to sibling directory
243ifneq ($(wildcard ../dealii/install/lib/libdeal_II.*),)
244  DEAL_II_DIR ?= ../dealii/install
245endif
246# Export for deal.II testing
247export DEAL_II_DIR
248
249# MFEM_DIR env variable should point to sibling directory
250ifneq ($(wildcard ../mfem/libmfem.*),)
251  MFEM_DIR ?= ../mfem
252endif
253
254# NEK5K_DIR env variable should point to sibling directory
255ifneq ($(wildcard ../Nek5000/*),)
256  NEK5K_DIR ?= $(abspath ../Nek5000)
257endif
258# Exports for NEK5K testing
259export CEED_DIR = $(abspath .)
260export NEK5K_DIR
261MPI ?= 1
262
263# Check for PETSc in ../petsc
264ifneq ($(wildcard ../petsc/lib/libpetsc.*),)
265  PETSC_DIR ?= ../petsc
266endif
267
268# ------------------------------------------------------------
269# Build the library (default target)
270# ------------------------------------------------------------
271
272lib: $(libceed) $(ceed.pc)
273# run 'lib' target in parallel
274par:;@$(MAKE) $(MFLAGS) V=$(V) lib
275
276$(libceed.so) : CEED_LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so)))
277
278# ------------------------------------------------------------
279# Source files
280# ------------------------------------------------------------
281
282# Interface and gallery
283libceed.c := $(filter-out interface/ceed-cuda.c interface/ceed-hip.c interface/ceed-jit-source-root-$(if $(for_install),default,install).c, $(wildcard interface/ceed*.c backends/*.c gallery/*.c))
284gallery.c := $(wildcard gallery/*/ceed*.c)
285libceed.c += $(gallery.c)
286
287# Backends
288# - CPU
289ref.c          := $(sort $(wildcard backends/ref/*.c))
290blocked.c      := $(sort $(wildcard backends/blocked/*.c))
291ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
292opt.c          := $(sort $(wildcard backends/opt/*.c))
293avx.c          := $(sort $(wildcard backends/avx/*.c))
294xsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
295# - GPU
296cuda.c         := $(sort $(wildcard backends/cuda/*.c))
297cuda.cpp       := $(sort $(wildcard backends/cuda/*.cpp))
298cuda-ref.c     := $(sort $(wildcard backends/cuda-ref/*.c))
299cuda-ref.cpp   := $(sort $(wildcard backends/cuda-ref/*.cpp))
300cuda-ref.cu    := $(sort $(wildcard backends/cuda-ref/kernels/*.cu))
301cuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
302cuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
303cuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
304cuda-all.c     := interface/ceed-cuda.c $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c)
305cuda-all.cpp   := $(cuda.cpp) $(cuda-ref.cpp) $(cuda-gen.cpp)
306cuda-all.cu    := $(cuda-ref.cu)
307hip.c          := $(sort $(wildcard backends/hip/*.c))
308hip.cpp        := $(sort $(wildcard backends/hip/*.cpp))
309hip-ref.c      := $(sort $(wildcard backends/hip-ref/*.c))
310hip-ref.cpp    := $(sort $(wildcard backends/hip-ref/*.cpp))
311hip-ref.hip    := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp))
312hip-shared.c   := $(sort $(wildcard backends/hip-shared/*.c))
313hip-gen.c      := $(sort $(wildcard backends/hip-gen/*.c))
314hip-gen.cpp    := $(sort $(wildcard backends/hip-gen/*.cpp))
315hip-all.c      := interface/ceed-hip.c $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c)
316hip-all.cpp    := $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp)
317hip-all.hip    := $(hip-ref.hip)
318sycl-core.cpp  := $(sort $(wildcard backends/sycl/*.sycl.cpp))
319sycl-ref.cpp   := $(sort $(wildcard backends/sycl-ref/*.sycl.cpp))
320sycl-shared.cpp:= $(sort $(wildcard backends/sycl-shared/*.sycl.cpp))
321sycl-gen.cpp   := $(sort $(wildcard backends/sycl-gen/*.sycl.cpp))
322magma.c        := $(sort $(wildcard backends/magma/*.c))
323magma.cpp      := $(sort $(wildcard backends/magma/*.cpp))
324
325# Tests
326tests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
327tests.f := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)))
328tests   := $(tests.c:tests/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
329ctests  := $(tests)
330tests   += $(tests.f:tests/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
331
332# Examples
333examples.c := $(sort $(wildcard examples/ceed/*.c))
334examples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f)))
335examples   := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
336examples   += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%$(EXE_SUFFIX))
337
338# deal.II Examples
339dealiiexamples := $(OBJDIR)/dealii-bps
340
341# MFEM Examples
342mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
343mfemexamples     := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
344
345# Nek5K Examples
346nekexamples := $(OBJDIR)/nek-bps
347
348# Rust QFunction Examples
349rustqfunctions.c       := $(sort $(wildcard examples/rust-qfunctions/*.c))
350rustqfunctionsexamples := $(rustqfunctions.c:examples/rust-qfunctions/%.c=$(OBJDIR)/rustqfunctions-%)
351
352# PETSc Examples
353petscexamples.c := $(wildcard examples/petsc/*.c)
354petscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
355
356# Fluid Dynamics Example
357fluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
358fluidsexamples   := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
359
360# Solid Mechanics Example
361solidsexamples.c := $(sort $(wildcard examples/solids/*.c))
362solidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
363
364
365# ------------------------------------------------------------
366# View configuration options
367# ------------------------------------------------------------
368
369backend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found])
370
371info-basic:
372	$(info -----------------------------------------)
373	$(info |     ___ __    ______________________  |)
374	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
375	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
376	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
377	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
378	$(info -----------------------------------------)
379	$(info )
380	$(info -----------------------------------------)
381	$(info )
382	$(info Built-in Backends:)
383	$(info   $(BACKENDS_BUILTIN))
384	$(info )
385	$(info Additional Backends:)
386	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
387	$(info )
388	$(info -----------------------------------------)
389	$(info )
390	@true
391
392info:
393	$(info -----------------------------------------)
394	$(info |     ___ __    ______________________  |)
395	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
396	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
397	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
398	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
399	$(info -----------------------------------------)
400	$(info )
401	$(info -----------------------------------------)
402	$(info )
403	$(info Built-in Backends:)
404	$(info   $(BACKENDS_BUILTIN))
405	$(info )
406	$(info Additional Backends:)
407	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
408	$(info )
409	$(info -----------------------------------------)
410	$(info )
411	$(info Compiler Flags:)
412	$(info CC            = $(CC))
413	$(info CXX           = $(CXX))
414	$(info FC            = $(FC))
415	$(info CPPFLAGS      = $(CPPFLAGS))
416	$(info CFLAGS        = $(CFLAGS))
417	$(info CXXFLAGS      = $(CXXFLAGS))
418	$(info FFLAGS        = $(FFLAGS))
419	$(info NVCCFLAGS     = $(NVCCFLAGS))
420	$(info HIPCCFLAGS    = $(HIPCCFLAGS))
421	$(info SYCLFLAGS     = $(SYCLFLAGS))
422	$(info CEED_LDFLAGS  = $(CEED_LDFLAGS))
423	$(info CEED_LDLIBS   = $(CEED_LDLIBS))
424	$(info AR            = $(AR))
425	$(info ARFLAGS       = $(ARFLAGS))
426	$(info OPT           = $(OPT))
427	$(info AFLAGS        = $(AFLAGS))
428	$(info ASAN          = $(or $(ASAN),(empty)))
429	$(info VERBOSE       = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
430	$(info )
431	$(info -----------------------------------------)
432	$(info )
433	$(info Backend Dependencies:)
434	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS)))
435	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS)))
436	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS)))
437	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
438	$(info ROCM_DIR      = $(ROCM_DIR)$(call backend_status,$(HIP_BACKENDS)))
439	$(info SYCL_DIR      = $(SYCL_DIR)$(call backend_status,$(SYCL_BACKENDS)))
440	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS)))
441	$(info )
442	$(info -----------------------------------------)
443	$(info )
444	$(info Example Dependencies:)
445	$(info MFEM_DIR      = $(MFEM_DIR))
446	$(info NEK5K_DIR     = $(NEK5K_DIR))
447	$(info PETSC_DIR     = $(PETSC_DIR))
448	$(info DEAL_II_DIR   = $(DEAL_II_DIR))
449	$(info )
450	$(info -----------------------------------------)
451	$(info )
452	$(info Install Options:)
453	$(info prefix        = $(prefix))
454	$(info includedir    = $(value includedir))
455	$(info libdir        = $(value libdir))
456	$(info pkgconfigdir  = $(value pkgconfigdir))
457	$(info )
458	$(info -----------------------------------------)
459	$(info )
460	$(info Git:)
461	$(info describe      = $(GIT_DESCRIBE))
462	$(info )
463	$(info -----------------------------------------)
464	@true
465
466info-backends:
467	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
468	@true
469
470info-backends-all:
471	$(info make: 'lib' with backends: $(BACKENDS))
472	@true
473
474
475# ------------------------------------------------------------
476# Backends
477# ------------------------------------------------------------
478
479# Standard Backends
480libceed.c += $(ref.c)
481libceed.c += $(blocked.c)
482libceed.c += $(opt.c)
483
484# Memcheck Backends
485MEMCHK_STATUS   = Disabled
486MEMCHK         := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
487MEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
488ifeq ($(MEMCHK),1)
489  MEMCHK_STATUS = Enabled
490  libceed.c += $(ceedmemcheck.c)
491  BACKENDS_MAKE += $(MEMCHK_BACKENDS)
492endif
493
494# AVX Backeds
495AVX_STATUS   = Disabled
496AVX_FLAG    := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
497AVX         := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS:-M%=) -v -E -x c /dev/null 2>&1))
498AVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked
499ifneq ($(AVX),)
500  AVX_STATUS = Enabled
501  libceed.c += $(avx.c)
502  BACKENDS_MAKE += $(AVX_BACKENDS)
503endif
504
505# Collect list of libraries and paths for use in linking and pkg-config
506PKG_LIBS =
507# Stubs that will not be RPATH'd
508PKG_STUBS_LIBS =
509
510# libXSMM Backends
511XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
512ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
513  PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm
514  MKL ?=
515  ifeq (,$(MKL)$(MKLROOT))
516    BLAS_LIB ?= -lblas -ldl
517  else
518    ifneq ($(MKLROOT),)
519      # Some installs put everything inside an intel64 subdirectory, others not
520      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
521      MKL_LINK = -L$(MKL_LIBDIR)
522    endif
523    BLAS_LIB ?= $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state
524  endif
525  PKG_LIBS += $(BLAS_LIB)
526  libceed.c += $(xsmm.c)
527  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
528  BACKENDS_MAKE += $(XSMM_BACKENDS)
529endif
530
531# CUDA Backends
532ifneq ($(CUDA_DIR),)
533  CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64 lib/x86_64-linux-gnu,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
534  CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
535endif
536CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
537CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
538ifneq ($(CUDA_LIB_DIR),)
539  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
540  PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas
541  PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS)
542  LIBCEED_CONTAINS_CXX = 1
543  libceed.c     += interface/ceed-cuda.c
544  libceed.c     += $(cuda-all.c)
545  libceed.cpp   += $(cuda-all.cpp)
546  libceed.cu    += $(cuda-all.cu)
547  BACKENDS_MAKE += $(CUDA_BACKENDS)
548endif
549
550# HIP Backends
551HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(ROCM_DIR)/$d/libamdhip64.${SO_EXT}))
552HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
553HIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen
554ifneq ($(HIP_LIB_DIR),)
555  HIPCONFIG_CPPFLAGS := $(subst =,,$(shell $(ROCM_DIR)/bin/hipconfig -C))
556  $(hip-all.c:%.c=$(OBJDIR)/%.o) $(hip-all.c:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
557  ifneq ($(CXX), $(HIPCC))
558    $(hip-all.cpp:%.cpp=$(OBJDIR)/%.o) $(hip-all.cpp:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
559  endif
560  PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas
561  LIBCEED_CONTAINS_CXX = 1
562  libceed.c     += $(hip-all.c)
563  libceed.cpp   += $(hip-all.cpp)
564  libceed.hip   += $(hip-all.hip)
565  BACKENDS_MAKE += $(HIP_BACKENDS)
566endif
567
568# SYCL Backends
569SYCL_BACKENDS = /gpu/sycl/ref /gpu/sycl/shared /gpu/sycl/gen
570ifneq ($(SYCL_DIR),)
571  SYCL_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(SYCL_DIR)/$d/libsycl.${SO_EXT}))
572  SYCL_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(SYCL_LIB_DIR))))
573endif
574ifneq ($(SYCL_LIB_DIR),)
575  PKG_LIBS += $(SYCL_FLAG) -lze_loader
576  LIBCEED_CONTAINS_CXX = 1
577  libceed.sycl  += $(sycl-core.cpp) $(sycl-ref.cpp) $(sycl-shared.cpp) $(sycl-gen.cpp)
578  BACKENDS_MAKE += $(SYCL_BACKENDS)
579endif
580
581# MAGMA Backends
582ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
583  MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas")
584  ifeq ($(MAGMA_ARCH), 0)  # CUDA MAGMA
585    ifneq ($(CUDA_LIB_DIR),)
586      cuda_link = $(if $(STATIC),,-Wl,-rpath,$(CUDA_LIB_DIR)) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
587      omp_link = -fopenmp
588      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
589      magma_link_shared = -L$(MAGMA_DIR)/lib $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
590      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
591      PKG_LIBS += $(magma_link)
592      libceed.c   += $(magma.c)
593      libceed.cpp += $(magma.cpp)
594      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
595      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
596      MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det
597    endif
598  else  # HIP MAGMA
599    ifneq ($(HIP_LIB_DIR),)
600      omp_link = -fopenmp
601      hip_link = $(if $(STATIC),,-Wl,-rpath,$(HIP_LIB_DIR)) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64
602      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link)
603      magma_link_shared = -L$(MAGMA_DIR)/lib $(hip_link) $(omp_link) $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
604      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
605      PKG_LIBS += $(magma_link)
606      libceed.c   += $(magma.c)
607      libceed.cpp += $(magma.cpp)
608      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
609      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
610      MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det
611    endif
612  endif
613  LIBCEED_CONTAINS_CXX = 1
614  BACKENDS_MAKE += $(MAGMA_BACKENDS)
615endif
616
617BACKENDS ?= $(BACKENDS_MAKE)
618export BACKENDS
619
620
621# ------------------------------------------------------------
622# Linker Flags
623# ------------------------------------------------------------
624
625_pkg_ldflags = $(filter -L%,$(PKG_LIBS))
626_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS))
627$(libceeds) : CEED_LDFLAGS += $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
628$(libceeds) : CEED_LDLIBS += $(_pkg_ldlibs)
629ifeq ($(STATIC),1)
630  $(examples) $(tests) : CEED_LDFLAGS += $(EM_LDFLAGS) $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
631  $(examples) $(tests) : CEED_LDLIBS += $(_pkg_ldlibs)
632endif
633
634pkgconfig-libs-private = $(PKG_LIBS)
635ifeq ($(LIBCEED_CONTAINS_CXX),1)
636  $(libceeds) : LINK = $(CXX)
637  ifeq ($(STATIC),1)
638    $(examples) $(tests) : CEED_LDLIBS += $(LIBCXX)
639    pkgconfig-libs-private += $(LIBCXX)
640  endif
641endif
642
643
644# ------------------------------------------------------------
645# Building core library components
646# ------------------------------------------------------------
647
648# File names *-weak.c contain weak symbol definitions, which must be listed last
649# when creating shared or static libraries.
650weak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1))
651
652libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o) $(libceed.sycl:%.sycl.cpp=$(OBJDIR)/%.o)
653$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
654$(libceed.o): | info-backends
655$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
656	$(call quiet,LINK) $(LDFLAGS) $(CEED_LDFLAGS) -shared -o $@ $^ $(CEED_LDLIBS) $(LDLIBS)
657
658$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
659	$(call quiet,AR) $(ARFLAGS) $@ $^
660
661$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
662	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $(abspath $<)
663
664$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
665	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
666
667$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
668	$(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<)
669
670$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
671	$(call quiet,HIPCC) $(CPPFLAGS) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
672
673$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
674	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
675
676$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
677	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
678
679$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.c | $$(@D)/.DIR
680	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) -I./tests/test-include
681
682$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.f90 | $$(@D)/.DIR
683	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
684
685$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.c | $$(@D)/.DIR
686	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
687
688$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.f | $$(@D)/.DIR
689	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
690
691
692# ------------------------------------------------------------
693# Building examples
694# ------------------------------------------------------------
695
696# deal.II
697# Note: Invoking deal.II's CMAKE build system here
698$(OBJDIR)/dealii-bps : examples/deal.II/*.cc examples/deal.II/*.h $(libceed) | $$(@D)/.DIR
699	mkdir -p examples/deal.II/build
700	cmake -B examples/deal.II/build -S examples/deal.II -DDEAL_II_DIR=$(DEAL_II_DIR) -DCEED_DIR=$(PWD)
701	+$(call quiet,MAKE) -C examples/deal.II/build
702	cp examples/deal.II/build/bps $(OBJDIR)/dealii-bps
703
704# MFEM
705$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
706	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
707	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
708	cp examples/mfem/$* $@
709
710# Nek5000
711# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
712#       this single Nek bps file to be built in parallel with other examples,
713#       such as when calling `make prove-all -j2`.
714$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
715	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
716	mv examples/nek/build/bps $(OBJDIR)/bps
717	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
718
719# Rust QFunctions
720$(OBJDIR)/rustqfunctions-% : examples/rust-qfunctions/%.c $(libceed) | $$(@D)/.DIR
721	+$(MAKE) -C examples/rust-qfunctions CEED_DIR=`pwd`
722	cp examples/rust-qfunctions/$* $@
723
724# PETSc
725# Several executables have common utilities, but we can't build the utilities
726# from separate submake invocations because they'll compete with each
727# other/corrupt output. So we put it in this utility library, but we don't want
728# to manually list source dependencies up at this level, so we'll just always
729# call recursive make to check that this utility is up to date.
730examples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc)
731	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \
732	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F))
733
734$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR
735	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \
736	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
737	cp examples/petsc/$* $@
738
739# Fluid dynamics proxy application
740$(OBJDIR)/fluids-% : examples/fluids/%.c examples/fluids/src/*.c examples/fluids/*.h examples/fluids/include/*.h examples/fluids/problems/*.c examples/fluids/qfunctions/*.h $(libceed) $(ceed.pc) examples/fluids/Makefile | $$(@D)/.DIR
741	+$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \
742	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
743	cp examples/fluids/$* $@
744
745# Solid mechanics proxy application
746$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
747    examples/solids/problems/*.c examples/solids/src/*.c \
748    examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \
749    $(libceed) $(ceed.pc) | $$(@D)/.DIR
750	+$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \
751	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
752	cp examples/solids/$* $@
753
754examples      : $(allexamples)
755ceedexamples  : $(examples)
756nekexamples   : $(nekexamples)
757mfemexamples  : $(mfemexamples)
758petscexamples : $(petscexamples)
759
760rustqfunctionsexamples : $(rustqfunctionsexamples)
761
762external_examples := \
763	$(if $(MFEM_DIR),$(mfemexamples)) \
764	$(if $(PETSC_DIR),$(petscexamples)) \
765	$(if $(NEK5K_DIR),$(nekexamples)) \
766	$(if $(DEAL_II_DIR),$(dealiiexamples)) \
767	$(if $(PETSC_DIR),$(fluidsexamples)) \
768	$(if $(PETSC_DIR),$(solidsexamples)) \
769	$(if $(or $(RUST_QF),$(GPU_CLANG)),$(rustqfunctionsexamples))
770
771allexamples = $(examples) $(external_examples)
772
773$(examples) : $(libceed)
774$(tests) : $(libceed)
775$(tests) $(examples) : override LDFLAGS += $(if $(STATIC),,-Wl,-rpath,$(abspath $(LIBDIR))) -L$(LIBDIR)
776
777
778# ------------------------------------------------------------
779# Testing
780# ------------------------------------------------------------
781
782# Set number processes for testing
783NPROC_TEST ?= 1
784export NPROC_TEST
785
786# Set pool size for testing
787NPROC_POOL ?= 1
788export NPROC_POOL
789
790run-% : $(OBJDIR)/%
791	@$(PYTHON) tests/junit.py --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%)
792
793# The test and prove targets can be controlled via pattern searches.  The
794# default is to run tests and those examples that have no external dependencies.
795# Examples of finer grained control:
796#
797#   make test search='petsc mfem'      # PETSc and MFEM examples
798#   make prove search='t3'             # t3xx series tests
799#   make junit search='ex petsc'       # core ex* and PETSc tests
800search ?= t ex
801realsearch = $(search:%=%%)
802matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
803subsearch ?= .*
804JUNIT_BATCH ?= ''
805
806# Test core libCEED
807test : $(matched:$(OBJDIR)/%=run-%)
808
809# Run test target in parallel
810tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
811# CPU C tests only for backend %
812ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
813
814# Testing with TAP format
815# https://testanything.org/tap-specification.html
816prove : $(matched)
817	$(info Testing backends: $(BACKENDS))
818	$(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py' $(matched:$(OBJDIR)/%=%) :: --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)'
819# Run prove target in parallel
820prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
821
822prove-all :
823	+$(MAKE) prove realsearch=%
824
825junit-% : $(OBJDIR)/%
826	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' --junit-batch $(JUNIT_BATCH) $(<:$(OBJDIR)/%=%)
827
828junit : $(matched:$(OBJDIR)/%=junit-%)
829
830all: $(alltests)
831
832# Benchmarks
833allbenchmarks = petsc-bps
834bench_targets = $(addprefix bench-,$(allbenchmarks))
835.PHONY: $(bench_targets) benchmarks
836$(bench_targets): bench-%: $(OBJDIR)/%
837	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
838benchmarks: $(bench_targets)
839
840$(ceed.pc) : pkgconfig-prefix = $(abspath .)
841$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
842.INTERMEDIATE : $(OBJDIR)/ceed.pc
843%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
844	@$(SED) \
845	    -e "s:%prefix%:$(pkgconfig-prefix):" \
846	    -e "s:%opt%:$(OPT):" \
847	    -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@
848
849GIT_DESCRIBE = $(shell git -c safe.directory=$PWD describe --always --dirty 2>/dev/null || printf "unknown\n")
850
851$(OBJDIR)/interface/ceed-config.o: Makefile
852$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\""
853$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
854
855$(OBJDIR)/interface/ceed-jit-source-root-default.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\""
856$(OBJDIR)/interface/ceed-jit-source-root-install.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath $(includedir))/\""
857
858
859# ------------------------------------------------------------
860# Installation
861# ------------------------------------------------------------
862
863install : $(libceed) $(OBJDIR)/ceed.pc
864	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
865	  "$(includedir)/ceed/" "$(includedir)/ceed/jit-source/"\
866	  "$(includedir)/ceed/jit-source/cuda/" "$(includedir)/ceed/jit-source/hip/"\
867	  "$(includedir)/ceed/jit-source/gallery/" "$(includedir)/ceed/jit-source/magma/"\
868	  "$(includedir)/ceed/jit-source/sycl/" "$(libdir)" "$(pkgconfigdir)")
869	$(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/"
870	$(INSTALL_DATA) include/ceed/deprecated.h "$(DESTDIR)$(includedir)/ceed/"
871	$(INSTALL_DATA) include/ceed/types.h "$(DESTDIR)$(includedir)/ceed/"
872	$(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/"
873	$(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/"
874	$(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/"
875	$(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/"
876	$(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/"
877	$(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/"
878	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
879	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
880	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
881	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
882	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/cuda/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/cuda/"
883	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
884	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"
885	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/magma/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/magma/"
886	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/sycl/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/sycl/"
887
888
889# ------------------------------------------------------------
890# Cleaning
891# ------------------------------------------------------------
892
893cln clean :
894	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
895	$(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
896	$(call quiet,MAKE) -C python/tests clean
897	$(RM) benchmarks/*output.txt
898	$(RM) -rf temp
899
900distclean : clean
901	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
902
903
904# ------------------------------------------------------------
905# Documentation
906# ------------------------------------------------------------
907
908DOXYGEN ?= doxygen
909
910doxygen :
911	$(DOXYGEN) -q Doxyfile
912
913doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
914	make -C doc/sphinx $*
915
916doc : doc-html
917
918
919# ------------------------------------------------------------
920# Linting utilities
921# ------------------------------------------------------------
922
923# Style/Format
924CLANG_FORMAT      ?= clang-format
925CLANG_FORMAT_OPTS += -style=file -i
926AUTOPEP8          ?= autopep8
927AUTOPEP8_OPTS     += --in-place --aggressive --max-line-length 120
928
929format.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), $(shell git ls-files '*.[ch]pp' '*.[ch]' '*.cu'))
930format.py := $(filter-out tests/junit-xml/junit_xml/__init__.py, $(shell git ls-files '*.py'))
931format.ot := $(filter-out doc/sphinx/source/CODE_OF_CONDUCT.md doc/sphinx/source/CONTRIBUTING.md, $(shell git ls-files '*.md' '*.f90'))
932
933format-c  :
934	$(CLANG_FORMAT) $(CLANG_FORMAT_OPTS) $(format.ch)
935
936format-py :
937	$(AUTOPEP8) $(AUTOPEP8_OPTS) $(format.py)
938
939format-ot:
940	@$(SED) -r 's/\s+$$//' -i $(format.ot)
941
942format    : format-c format-py format-ot
943
944# Vermin - python version requirements
945VERMIN            ?= vermin
946VERMIN_OPTS       += -t=3.8- --violations
947
948vermin    :
949	$(VERMIN) $(VERMIN_OPTS) $(format.py)
950
951# Tidy
952CLANG_TIDY ?= clang-tidy
953
954%.c.tidy : %.c
955	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\"" -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\"" -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
956
957%.cpp.tidy : %.cpp
958	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include
959
960tidy-c   : $(libceed.c:%=%.tidy)
961tidy-cpp : $(libceed.cpp:%=%.tidy)
962
963tidy : tidy-c tidy-cpp
964
965# Include-What-You-Use
966ifneq ($(wildcard ../iwyu/*),)
967  IWYU_DIR ?= ../iwyu
968  IWYU_CC  ?= $(IWYU_DIR)/build/bin/include-what-you-use
969endif
970iwyu :
971	$(MAKE) -B CC=$(IWYU_CC)
972
973
974# ------------------------------------------------------------
975# Variable printing for debugging
976# ------------------------------------------------------------
977
978print :
979	@echo $(VAR)=$($(VAR))
980
981print-% :
982	$(info [ variable name]: $*)
983	$(info [        origin]: $(origin $*))
984	$(info [        flavor]: $(flavor $*))
985	$(info [         value]: $(value $*))
986	$(info [expanded value]: $($*))
987	$(info )
988	@true
989
990
991# ------------------------------------------------------------
992# Configuration caching
993# ------------------------------------------------------------
994
995# "make configure" detects any variables passed on the command line or
996# previously set in config.mk, caching them in config.mk as simple
997# (:=) variables.  Variables set in config.mk or on the command line
998# take precedence over the defaults provided in the file.  Typical
999# usage:
1000#
1001#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
1002#   make
1003#   make prove
1004#
1005# The values in the file can be updated by passing them on the command
1006# line, e.g.,
1007#
1008#   make configure CC=/path/to/other/clang
1009
1010# All variables to consider for caching
1011CONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \
1012  OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS SYCLFLAGS \
1013  AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \
1014  MAGMA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR ROCM_DIR HIP_ARCH SYCL_DIR
1015
1016# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
1017# was set on the command line or in config.mk (where it will appear as
1018# a simple variable).
1019needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
1020
1021configure :
1022	$(file > $(CONFIG))
1023	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
1024	@echo "Configuration cached in $(CONFIG):"
1025	@cat $(CONFIG)
1026
1027
1028# ------------------------------------------------------------
1029# Building Python wheels for deployment
1030# ------------------------------------------------------------
1031
1032wheel : export MARCHFLAG = -march=generic
1033wheel : export WHEEL_PLAT = manylinux2010_x86_64
1034wheel :
1035	docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \
1036	  -e MARCHFLAG -e WHEEL_PLAT \
1037	  quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh
1038
1039# ------------------------------------------------------------
1040# Phony targets
1041# ------------------------------------------------------------
1042
1043# These targets are not files but rather commands to run
1044.PHONY : all cln clean doxygen doc format lib install par print test tst prove prv prove-all junit examples tidy iwyu info info-backends info-backends-all configure wheel
1045
1046
1047# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container
1048-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d))
1049