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