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