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