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