xref: /libCEED/Makefile (revision 7247fd92a8a86a7e36cba392bcb1b62954e39b1a)
19ba83ac0SJeremy L Thompson# Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
29bca2fcfSJed Brown# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
30d9661cdSTzanio#
49bca2fcfSJed Brown# SPDX-License-Identifier: BSD-2-Clause
50d9661cdSTzanio#
69bca2fcfSJed Brown# This file is part of CEED:  http://github.com/ceed
70d9661cdSTzanio
88baf801dSJeremy L Thompson# ------------------------------------------------------------
98baf801dSJeremy L Thompson# Configuration
108baf801dSJeremy L Thompson# ------------------------------------------------------------
118baf801dSJeremy L Thompson
128baf801dSJeremy L Thompson# config.mk stores cached configuration variables
13b0ab70ddSJed BrownCONFIG ?= config.mk
14b0ab70ddSJed Brown-include $(CONFIG)
158baf801dSJeremy L Thompson
168baf801dSJeremy L Thompson# common.mk holds definitions used in various makefiles throughout the project
17777ff853SJeremy L ThompsonCOMMON ?= common.mk
18777ff853SJeremy L Thompson-include $(COMMON)
191571c99dSValeria Barra
208baf801dSJeremy L Thompson# Quiet, color output
218baf801dSJeremy L Thompsonquiet ?= $($(1))
228baf801dSJeremy L Thompson
238baf801dSJeremy L Thompson# Cancel built-in and old-fashioned implicit rules which we don't use
248baf801dSJeremy L Thompson.SUFFIXES:
258baf801dSJeremy L Thompson
268baf801dSJeremy L Thompson.SECONDEXPANSION: # to expand $$(@D)/.DIR
278baf801dSJeremy L Thompson
288baf801dSJeremy L Thompson%/.DIR :
298baf801dSJeremy L Thompson	@mkdir -p $(@D)
308baf801dSJeremy L Thompson	@touch $@
318baf801dSJeremy L Thompson
328baf801dSJeremy L Thompson.PRECIOUS: %/.DIR
338baf801dSJeremy L Thompson
348baf801dSJeremy L Thompson
3565af418bSJeremy L ThompsonDARWIN := $(filter Darwin,$(shell uname -s))
3665af418bSJeremy L Thompson
3765af418bSJeremy L Thompson
388baf801dSJeremy L Thompson# ------------------------------------------------------------
398baf801dSJeremy L Thompson# Root directories for backend dependencies
408baf801dSJeremy L Thompson# ------------------------------------------------------------
418baf801dSJeremy L Thompson
428baf801dSJeremy L Thompson# XSMM_DIR env variable should point to XSMM main (github.com/hfp/libxsmm)
438baf801dSJeremy L ThompsonXSMM_DIR ?= ../libxsmm
448baf801dSJeremy L Thompson
458baf801dSJeremy L Thompson# Often /opt/cuda or /usr/local/cuda, but sometimes present on machines that don't support CUDA
468baf801dSJeremy L ThompsonCUDA_DIR  ?=
478baf801dSJeremy L ThompsonCUDA_ARCH ?=
488baf801dSJeremy L Thompson
498baf801dSJeremy L Thompson# Often /opt/rocm, but sometimes present on machines that don't support HIP
508baf801dSJeremy L ThompsonROCM_DIR ?=
518baf801dSJeremy L ThompsonHIP_ARCH ?=
528baf801dSJeremy L Thompson
538baf801dSJeremy L Thompson# env variable MAGMA_DIR can be used too
548baf801dSJeremy L ThompsonMAGMA_DIR ?= ../magma
558baf801dSJeremy L Thompson
568baf801dSJeremy L Thompson
578baf801dSJeremy L Thompson# ------------------------------------------------------------
588baf801dSJeremy L Thompson# Compiler flags
598baf801dSJeremy L Thompson# ------------------------------------------------------------
608baf801dSJeremy L Thompson
618baf801dSJeremy L Thompson# Detect user compiler options and set defaults
62dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
636ed738d9SJed Brown  CC = gcc
64dc753d40SJed Brownendif
65241a4b83SYohannifeq (,$(filter-out undefined default,$(origin CXX)))
66241a4b83SYohann  CXX = g++
67241a4b83SYohannendif
68dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
6981c9eb91SStan Tomov  FC = gfortran
70dc753d40SJed Brownendif
71241a4b83SYohannifeq (,$(filter-out undefined default,$(origin LINK)))
72241a4b83SYohann  LINK = $(CC)
73241a4b83SYohannendif
741d013790SJed Brownifeq (,$(filter-out undefined default,$(origin AR)))
751d013790SJed Brown  AR = ar
761d013790SJed Brownendif
771d013790SJed Brownifeq (,$(filter-out undefined default,$(origin ARFLAGS)))
7865af418bSJeremy L Thompson  ARFLAGS = $(if $(DARWIN),cr,crD)
791d013790SJed Brownendif
80196a75e4SJed BrownNVCC ?= $(CUDA_DIR)/bin/nvcc
813c83ce1dSJed BrownNVCC_CXX ?= $(CXX)
82023b8a51Sabdelfattah83HIPCC ?= $(ROCM_DIR)/bin/hipcc
83bd882c8aSJames WrightSYCLCXX ?= $(CXX)
841d013790SJed BrownSED ?= sed
850bd9ac94SJed Brownifneq ($(EMSCRIPTEN),)
860bd9ac94SJed Brown  STATIC = 1
870bd9ac94SJed Brown  EXE_SUFFIX = .wasm
880bd9ac94SJed Brown  EM_LDFLAGS = -s TOTAL_MEMORY=256MB
890bd9ac94SJed Brownendif
90e86995feScamierjs
913b56482dScamierjs# ASAN must be left empty if you don't want to use it
920a7eccc5ScamierjsASAN ?=
936850bcb5Scamierjs
943696039aSJed Brown# These are the values automatically detected here in the makefile. They are
953696039aSJed Brown# augmented with LDFLAGS and LDLIBS from the environment/passed by command line,
963696039aSJed Brown# if any. If the user sets CEED_LDFLAGS or CEED_LDLIBS, they are used *instead
973696039aSJed Brown# of* what we populate here (thus that's advanced usage and not recommended).
983696039aSJed BrownCEED_LDFLAGS ?=
993696039aSJed BrownCEED_LDLIBS  ?=
1007c735608SJed Brown
10132d74c32SThilina RathnayakeUNDERSCORE ?= 1
1021b58aefaScamierjs
1038df0376fSJeremy L Thompson# Verbose mode, V or VERBOSE
1048df0376fSJeremy L ThompsonV ?= $(VERBOSE)
1058df0376fSJeremy L Thompson
106346c77e6SJeremy L Thompson# SANTIZ options
107fb651866SJed BrownAFLAGS ?= -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
10832d74c32SThilina Rathnayake
1098ca0bbaeSjeremylt# Note: Intel oneAPI C/C++ compiler is now icx/icpx
1108de85446SHugh CarsonCC_VENDOR := $(firstword $(filter gcc (GCC) clang cc icc icc_orig oneAPI XL emcc,$(subst -, ,$(shell $(CC) --version))))
1114c4eae0cSSebastian GrimbergCC_VENDOR := $(subst (GCC),gcc,$(subst icc_orig,icc,$(CC_VENDOR)))
1128de85446SHugh CarsonCC_VENDOR := $(if $(filter cc,$(CC_VENDOR)),gcc,$(CC_VENDOR))
1130be03a92SJeremy L ThompsonFC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort ifx XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
11413d950b4SJed Brown
115*7247fd92SHugh Carson# Host architecture for setting appropriate flags
116*7247fd92SHugh CarsonUNAME_M := $(shell uname -m)
117*7247fd92SHugh Carson
11813d950b4SJed Brown# Default extra flags by vendor
119*7247fd92SHugh Carson# GCC: use -march=native only on x86 (where -mcpu doesn't exist); use -mcpu=native elsewhere
120*7247fd92SHugh CarsonMARCHFLAG.gcc           := $(if $(filter x86_64 i%86,$(UNAME_M)),-march=native,-mcpu=native)
12113d950b4SJed BrownMARCHFLAG.clang         := $(MARCHFLAG.gcc)
12213d950b4SJed BrownMARCHFLAG.icc           :=
1230be03a92SJeremy L ThompsonMARCHFLAG.oneAPI        := $(MARCHFLAG.clang)
12413d950b4SJed BrownOMP_SIMD_FLAG.gcc       := -fopenmp-simd
12513d950b4SJed BrownOMP_SIMD_FLAG.clang     := $(OMP_SIMD_FLAG.gcc)
12613d950b4SJed BrownOMP_SIMD_FLAG.icc       := -qopenmp-simd
12758c07c4fSSebastian GrimbergOMP_SIMD_FLAG.oneAPI    := $(OMP_SIMD_FLAG.icc)
12858c07c4fSSebastian GrimbergOMP_FLAG.gcc            := -fopenmp
12958c07c4fSSebastian GrimbergOMP_FLAG.clang          := $(OMP_FLAG.gcc)
13058c07c4fSSebastian GrimbergOMP_FLAG.icc            := -qopenmp
13158c07c4fSSebastian GrimbergOMP_FLAG.oneAPI         := $(OMP_FLAG.icc)
132bd882c8aSJames WrightSYCL_FLAG.gcc           :=
133bd882c8aSJames WrightSYCL_FLAG.clang         := -fsycl
134bd882c8aSJames WrightSYCL_FLAG.icc           :=
1356ca0f394SUmesh UnnikrishnanSYCL_FLAG.oneAPI        := -fsycl -fno-sycl-id-queries-fit-in-int
1360bd9ac94SJed BrownOPT.gcc                 := -g -ffp-contract=fast
13713d950b4SJed BrownOPT.clang               := $(OPT.gcc)
13858c07c4fSSebastian GrimbergOPT.icc                 := $(OPT.gcc)
1390be03a92SJeremy L ThompsonOPT.oneAPI              := $(OPT.clang)
1400bd9ac94SJed BrownOPT.emcc                :=
141d4f9124cSJed BrownCFLAGS.gcc              := $(if $(STATIC),,-fPIC) -std=c11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
1428b45a169SnbeamsCFLAGS.clang            := $(CFLAGS.gcc)
14313d950b4SJed BrownCFLAGS.icc              := $(CFLAGS.gcc)
1440be03a92SJeremy L ThompsonCFLAGS.oneAPI           := $(CFLAGS.clang)
1450bd9ac94SJed BrownCFLAGS.XL               := $(if $(STATIC),,-qpic) -MMD
1460bd9ac94SJed BrownCFLAGS.emcc             := $(CFLAGS.clang)
1470bd9ac94SJed BrownCXXFLAGS.gcc            := $(if $(STATIC),,-fPIC) -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
1488b45a169SnbeamsCXXFLAGS.clang          := $(CXXFLAGS.gcc)
14913d950b4SJed BrownCXXFLAGS.icc            := $(CXXFLAGS.gcc)
1500be03a92SJeremy L ThompsonCXXFLAGS.oneAPI         := $(CXXFLAGS.clang)
1510bd9ac94SJed BrownCXXFLAGS.XL             := $(if $(STATIC),,-qpic) -std=c++11 -MMD
1520bd9ac94SJed BrownCXXFLAGS.emcc           := $(CXXFLAGS.clang)
1530bd9ac94SJed BrownFFLAGS.GNU              := $(if $(STATIC),,-fPIC) -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP
1540bd9ac94SJed BrownFFLAGS.ifort            := $(if $(STATIC),,-fPIC) -cpp
1550be03a92SJeremy L ThompsonFFLAGS.ifx              := $(FFLAGS.ifort)
1560bd9ac94SJed BrownFFLAGS.XL               := $(if $(STATIC),,-qpic) -ffree-form -qpreprocess -qextname -MMD
157cf4a56afSJed Brown
158d9bc9eefSJed Brown# This check works with compilers that use gcc and clang.  It fails with some
159d9bc9eefSJed Brown# compilers; e.g., xlc apparently ignores all options when -E is passed, thus
160d9bc9eefSJed Brown# succeeds with any flags.  Users can pass MARCHFLAG=... if desired.
161d9bc9eefSJed Browncc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1)
16213d950b4SJed BrownMARCHFLAG := $(MARCHFLAG.$(CC_VENDOR))
163f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native)
164f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG))
165b9c05c73SJed Brown
16613d950b4SJed BrownOMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
167f766a8abSJed BrownOMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
168cf4a56afSJed Brown
1692c2ea1dbSJeremy L Thompson# Error checking flags
1702c2ea1dbSJeremy L ThompsonPEDANTIC      ?=
1712c2ea1dbSJeremy L ThompsonPEDANTICFLAGS ?= -Werror -pedantic
1722c2ea1dbSJeremy L Thompson
1738baf801dSJeremy L Thompson# Compiler flags
1740bd9ac94SJed BrownOPT    ?= -O $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
1752c2ea1dbSJeremy L ThompsonCFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
1762c2ea1dbSJeremy L ThompsonCXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
17758c07c4fSSebastian GrimbergFFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
1781d013790SJed BrownLIBCXX ?= -lstdc++
1794f69910bSJed BrownNVCCFLAGS ?= -ccbin $(CXX) -Xcompiler '$(OPT)' -Xcompiler -fPIC
180bd057117Snbeamsifneq ($(CUDA_ARCH),)
181bd057117Snbeams  NVCCFLAGS += -arch=$(CUDA_ARCH)
182bd057117Snbeamsendif
183b3c5430cSnbeamsHIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics
184bd057117Snbeamsifneq ($(HIP_ARCH),)
1855e82904bSJeremy L Thompson  HIPCCFLAGS += --offload-arch=$(HIP_ARCH)
186bd057117Snbeamsendif
187bd882c8aSJames WrightSYCL_FLAG := $(SYCL_FLAG.$(CC_VENDOR))
188bd882c8aSJames WrightSYCLFLAGS ?= $(SYCL_FLAG) -fPIC -std=c++17 $(filter-out -std=c++11,$(CXXFLAGS)) $(filter-out $(OMP_SIMD_FLAG),$(OPT))
18958c07c4fSSebastian Grimberg
19058c07c4fSSebastian GrimbergOPENMP ?=
19158c07c4fSSebastian Grimbergifneq ($(OPENMP),)
19258c07c4fSSebastian Grimberg  OMP_FLAG := $(OMP_FLAG.$(CC_VENDOR))
19358c07c4fSSebastian Grimberg  OMP_FLAG := $(if $(call cc_check_flag,$(OMP_FLAG)),$(OMP_FLAG))
19458c07c4fSSebastian Grimberg  CFLAGS += $(OMP_FLAG)
19558c07c4fSSebastian Grimberg  CEED_LDFLAGS += $(OMP_FLAG)
19658c07c4fSSebastian Grimbergendif
19732d74c32SThilina Rathnayake
198a6f4783aSJed Brownifeq ($(COVERAGE), 1)
199a6f4783aSJed Brown  CFLAGS += --coverage
200568410ffSJeremy L Thompson  CXXFLAGS += --coverage
2013696039aSJed Brown  CEED_LDFLAGS += --coverage
202a6f4783aSJed Brownendif
203a6f4783aSJed Brown
2045766aa57SJeremy L ThompsonCFLAGS += $(if $(ASAN),$(AFLAGS))
2054dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
2063696039aSJed BrownCEED_LDFLAGS += $(if $(ASAN),$(AFLAGS))
20741a90898SJed BrownCPPFLAGS += -I./include
2083696039aSJed BrownCEED_LDLIBS = -lm
20991b7489eSJed BrownOBJDIR := build
21072fa462dSJed Brownfor_install := $(filter install,$(MAKECMDGOALS))
21172fa462dSJed BrownLIBDIR := $(if $(for_install),$(OBJDIR),lib)
21272fa462dSJed Brown
213d5217624SJed Brown# Installation variables
214d5217624SJed Brownprefix ?= /usr/local
215d5217624SJed Brownbindir = $(prefix)/bin
216d5217624SJed Brownlibdir = $(prefix)/lib
217d5217624SJed Brownincludedir = $(prefix)/include
218d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
219d5217624SJed BrownINSTALL = install
220d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
221d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
222d5217624SJed Brown
2233b56482dScamierjs# Get number of processors of the machine
22469762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
2253b56482dScamierjs# prepare make options to run in parallel
22682985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
22721ae6867Scamierjs                       --no-print-directory --no-keep-going
22887e762eaSJed Brown
2298ec9d54bSJed BrownPYTHON ?= python3
230bfa078e6SJed BrownPROVE ?= prove
2313a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
2325c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
2339df38c42SVeselin Dobrev
2346ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
2351d013790SJed Brownlibceed.so := $(LIBDIR)/libceed.$(SO_EXT)
2361d013790SJed Brownlibceed.a := $(LIBDIR)/libceed.a
23778a9fcb6SJeremy L Thompsonlibceed := $(if $(STATIC),$(libceed.a),$(libceed.so))
2387e68d260SJed BrownCEED_LIBS = -lceed
2398e3e54ccSjeremyltlibceeds = $(libceed)
240265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
241422b683aSjeremyltBACKENDS_MAKE := $(BACKENDS_BUILTIN)
242bf000209STzanio
243e797ab98SJed Brown
2448baf801dSJeremy L Thompson# ------------------------------------------------------------
2458baf801dSJeremy L Thompson# Root directories for examples using external libraries
2468baf801dSJeremy L Thompson# ------------------------------------------------------------
2478baf801dSJeremy L Thompson
2488baf801dSJeremy L Thompson# DEAL_II_DIR env variable should point to sibling directory
2498baf801dSJeremy L Thompsonifneq ($(wildcard ../dealii/install/lib/libdeal_II.*),)
2508baf801dSJeremy L Thompson  DEAL_II_DIR ?= ../dealii/install
2518baf801dSJeremy L Thompsonendif
2528baf801dSJeremy L Thompson# Export for deal.II testing
2538baf801dSJeremy L Thompsonexport DEAL_II_DIR
2548baf801dSJeremy L Thompson
2558baf801dSJeremy L Thompson# MFEM_DIR env variable should point to sibling directory
2568baf801dSJeremy L Thompsonifneq ($(wildcard ../mfem/libmfem.*),)
2578baf801dSJeremy L Thompson  MFEM_DIR ?= ../mfem
2588baf801dSJeremy L Thompsonendif
2598baf801dSJeremy L Thompson
2608baf801dSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
2618baf801dSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
2628baf801dSJeremy L Thompson  NEK5K_DIR ?= $(abspath ../Nek5000)
2638baf801dSJeremy L Thompsonendif
2648baf801dSJeremy L Thompson# Exports for NEK5K testing
2658baf801dSJeremy L Thompsonexport CEED_DIR = $(abspath .)
2668baf801dSJeremy L Thompsonexport NEK5K_DIR
2678baf801dSJeremy L ThompsonMPI ?= 1
2688baf801dSJeremy L Thompson
2698baf801dSJeremy L Thompson# Check for PETSc in ../petsc
2708baf801dSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
2718baf801dSJeremy L Thompson  PETSC_DIR ?= ../petsc
2728baf801dSJeremy L Thompsonendif
2738baf801dSJeremy L Thompson
2748baf801dSJeremy L Thompson# ------------------------------------------------------------
2758baf801dSJeremy L Thompson# Build the library (default target)
2768baf801dSJeremy L Thompson# ------------------------------------------------------------
2778baf801dSJeremy L Thompson
2788baf801dSJeremy L Thompsonlib: $(libceed) $(ceed.pc)
2798baf801dSJeremy L Thompson# run 'lib' target in parallel
2808baf801dSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
2818baf801dSJeremy L Thompson
2828baf801dSJeremy L Thompson$(libceed.so) : CEED_LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so)))
2838baf801dSJeremy L Thompson
2848baf801dSJeremy L Thompson# ------------------------------------------------------------
2858baf801dSJeremy L Thompson# Source files
2868baf801dSJeremy L Thompson# ------------------------------------------------------------
2878baf801dSJeremy L Thompson
2888baf801dSJeremy L Thompson# Interface and gallery
289d1503016SJeremy L Thompsonlibceed.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/weak/*.c gallery/*.c))
2908baf801dSJeremy L Thompsongallery.c := $(wildcard gallery/*/ceed*.c)
2918baf801dSJeremy L Thompsonlibceed.c += $(gallery.c)
2928baf801dSJeremy L Thompson
2938baf801dSJeremy L Thompson# Backends
2948baf801dSJeremy L Thompson# - CPU
295ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
29689c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
29789c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
29889c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
29989c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
30089c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
3018baf801dSJeremy L Thompson# - GPU
3029f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
303c9c2c079SJeremy L Thompsoncuda.cpp       := $(sort $(wildcard backends/cuda/*.cpp))
3047fcac036SJeremy L Thompsoncuda-ref.c     := $(sort $(wildcard backends/cuda-ref/*.c))
3057fcac036SJeremy L Thompsoncuda-ref.cpp   := $(sort $(wildcard backends/cuda-ref/*.cpp))
3067fcac036SJeremy L Thompsoncuda-ref.cu    := $(sort $(wildcard backends/cuda-ref/kernels/*.cu))
307c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
308241a4b83SYohanncuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
309241a4b83SYohanncuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
3109a92872bSJeremy L Thompsoncuda-all.c     := interface/ceed-cuda.c $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c)
3119a92872bSJeremy L Thompsoncuda-all.cpp   := $(cuda.cpp) $(cuda-ref.cpp) $(cuda-gen.cpp)
3129a92872bSJeremy L Thompsoncuda-all.cu    := $(cuda-ref.cu)
31330f4f45fSnbeamship.c          := $(sort $(wildcard backends/hip/*.c))
314f0f820a0SJeremy L Thompsonhip.cpp        := $(sort $(wildcard backends/hip/*.cpp))
3157fcac036SJeremy L Thompsonhip-ref.c      := $(sort $(wildcard backends/hip-ref/*.c))
3167fcac036SJeremy L Thompsonhip-ref.cpp    := $(sort $(wildcard backends/hip-ref/*.cpp))
3177fcac036SJeremy L Thompsonhip-ref.hip    := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp))
3187d8d0e25Snbeamship-shared.c   := $(sort $(wildcard backends/hip-shared/*.c))
3197d8d0e25Snbeamship-gen.c      := $(sort $(wildcard backends/hip-gen/*.c))
3207d8d0e25Snbeamship-gen.cpp    := $(sort $(wildcard backends/hip-gen/*.cpp))
3219a92872bSJeremy L Thompsonhip-all.c      := interface/ceed-hip.c $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c)
3229a92872bSJeremy L Thompsonhip-all.cpp    := $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp)
3239a92872bSJeremy L Thompsonhip-all.hip    := $(hip-ref.hip)
324bd882c8aSJames Wrightsycl-core.cpp  := $(sort $(wildcard backends/sycl/*.sycl.cpp))
325bd882c8aSJames Wrightsycl-ref.cpp   := $(sort $(wildcard backends/sycl-ref/*.sycl.cpp))
326bd882c8aSJames Wrightsycl-shared.cpp:= $(sort $(wildcard backends/sycl-shared/*.sycl.cpp))
3276ca0f394SUmesh Unnikrishnansycl-gen.cpp   := $(sort $(wildcard backends/sycl-gen/*.sycl.cpp))
3288baf801dSJeremy L Thompsonmagma.c        := $(sort $(wildcard backends/magma/*.c))
3298baf801dSJeremy L Thompsonmagma.cpp      := $(sort $(wildcard backends/magma/*.cpp))
33082985883Scamierjs
3318baf801dSJeremy L Thompson# Tests
3328baf801dSJeremy L Thompsontests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
3338baf801dSJeremy L Thompsontests.f := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)))
3348baf801dSJeremy L Thompsontests   := $(tests.c:tests/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
3358baf801dSJeremy L Thompsonctests  := $(tests)
3368baf801dSJeremy L Thompsontests   += $(tests.f:tests/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
33721ae6867Scamierjs
3388baf801dSJeremy L Thompson# Examples
3398baf801dSJeremy L Thompsonexamples.c := $(sort $(wildcard examples/ceed/*.c))
340860dc821SJeremy L Thompsonexamples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f90)))
3418baf801dSJeremy L Thompsonexamples   := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
342860dc821SJeremy L Thompsonexamples   += $(examples.f:examples/ceed/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
343da72e7fcSJed Brown
3448baf801dSJeremy L Thompson# deal.II Examples
3458baf801dSJeremy L Thompsondealiiexamples := $(OBJDIR)/dealii-bps
3469df38c42SVeselin Dobrev
3478baf801dSJeremy L Thompson# MFEM Examples
3488baf801dSJeremy L Thompsonmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
3498baf801dSJeremy L Thompsonmfemexamples     := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
35091b7489eSJed Brown
3518baf801dSJeremy L Thompson# Nek5K Examples
3528baf801dSJeremy L Thompsonnekexamples := $(OBJDIR)/nek-bps
35391b7489eSJed Brown
3542027fb9dSSirAlienTheGreat# Rust QFunction Examples
3552027fb9dSSirAlienTheGreatrustqfunctions.c       := $(sort $(wildcard examples/rust-qfunctions/*.c))
3562027fb9dSSirAlienTheGreatrustqfunctionsexamples := $(rustqfunctions.c:examples/rust-qfunctions/%.c=$(OBJDIR)/rustqfunctions-%)
3572027fb9dSSirAlienTheGreat
3588baf801dSJeremy L Thompson# PETSc Examples
3598baf801dSJeremy L Thompsonpetscexamples.c := $(wildcard examples/petsc/*.c)
3608baf801dSJeremy L Thompsonpetscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
3618baf801dSJeremy L Thompson
3628baf801dSJeremy L Thompson# Fluid Dynamics Example
3638baf801dSJeremy L Thompsonfluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
3648baf801dSJeremy L Thompsonfluidsexamples   := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
3658baf801dSJeremy L Thompson
3668baf801dSJeremy L Thompson# Solid Mechanics Example
3678baf801dSJeremy L Thompsonsolidsexamples.c := $(sort $(wildcard examples/solids/*.c))
3688baf801dSJeremy L Thompsonsolidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
3698baf801dSJeremy L Thompson
3708baf801dSJeremy L Thompson
3718baf801dSJeremy L Thompson# ------------------------------------------------------------
3728baf801dSJeremy L Thompson# View configuration options
3738baf801dSJeremy L Thompson# ------------------------------------------------------------
3748baf801dSJeremy L Thompson
375422b683aSjeremyltbackend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found])
3768baf801dSJeremy L Thompson
377a5ef5560SJeremy L Thompsoninfo-basic:
378a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
379a5ef5560SJeremy L Thompson	$(info |     ___ __    ______________________  |)
380a5ef5560SJeremy L Thompson	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
381a5ef5560SJeremy L Thompson	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
382a5ef5560SJeremy L Thompson	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
383a5ef5560SJeremy L Thompson	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
384a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
385a5ef5560SJeremy L Thompson	$(info )
386a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
387a5ef5560SJeremy L Thompson	$(info )
388a5ef5560SJeremy L Thompson	$(info Built-in Backends:)
389a5ef5560SJeremy L Thompson	$(info   $(BACKENDS_BUILTIN))
390a5ef5560SJeremy L Thompson	$(info )
391a5ef5560SJeremy L Thompson	$(info Additional Backends:)
392a5ef5560SJeremy L Thompson	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
393a5ef5560SJeremy L Thompson	$(info )
394a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
395a5ef5560SJeremy L Thompson	$(info )
396a5ef5560SJeremy L Thompson	@true
397a5ef5560SJeremy L Thompson
398bf3e26f6SVeselin Dobrevinfo:
399a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
400a5ef5560SJeremy L Thompson	$(info |     ___ __    ______________________  |)
401a5ef5560SJeremy L Thompson	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
402a5ef5560SJeremy L Thompson	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
403a5ef5560SJeremy L Thompson	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
404a5ef5560SJeremy L Thompson	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
405a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
406a5ef5560SJeremy L Thompson	$(info )
407a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
408a5ef5560SJeremy L Thompson	$(info )
409a5ef5560SJeremy L Thompson	$(info Built-in Backends:)
410a5ef5560SJeremy L Thompson	$(info   $(BACKENDS_BUILTIN))
411a5ef5560SJeremy L Thompson	$(info )
412a5ef5560SJeremy L Thompson	$(info Additional Backends:)
413a5ef5560SJeremy L Thompson	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
414a5ef5560SJeremy L Thompson	$(info )
415a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
416a5ef5560SJeremy L Thompson	$(info )
417a5ef5560SJeremy L Thompson	$(info Compiler Flags:)
418bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
419241a4b83SYohann	$(info CXX           = $(CXX))
420bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
421bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
4224e62717cSJames Wright	$(info CFLAGS        = $(CFLAGS))
4234e62717cSJames Wright	$(info CXXFLAGS      = $(CXXFLAGS))
4244e62717cSJames Wright	$(info FFLAGS        = $(FFLAGS))
4254e62717cSJames Wright	$(info NVCCFLAGS     = $(NVCCFLAGS))
4264e62717cSJames Wright	$(info HIPCCFLAGS    = $(HIPCCFLAGS))
4274e62717cSJames Wright	$(info SYCLFLAGS     = $(SYCLFLAGS))
4284e62717cSJames Wright	$(info CEED_LDFLAGS  = $(CEED_LDFLAGS))
4294e62717cSJames Wright	$(info CEED_LDLIBS   = $(CEED_LDLIBS))
4301d013790SJed Brown	$(info AR            = $(AR))
4311d013790SJed Brown	$(info ARFLAGS       = $(ARFLAGS))
432bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
433bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
434bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
4358df0376fSJeremy L Thompson	$(info VERBOSE       = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
436a5ef5560SJeremy L Thompson	$(info )
437a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
438a5ef5560SJeremy L Thompson	$(info )
439a5ef5560SJeremy L Thompson	$(info Backend Dependencies:)
440ae945beaSJeremy L Thompson	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS)))
441ae945beaSJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS)))
442ae945beaSJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS)))
443ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
444023b8a51Sabdelfattah83	$(info ROCM_DIR      = $(ROCM_DIR)$(call backend_status,$(HIP_BACKENDS)))
445bd882c8aSJames Wright	$(info SYCL_DIR      = $(SYCL_DIR)$(call backend_status,$(SYCL_BACKENDS)))
446a5ef5560SJeremy L Thompson	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS)))
447a5ef5560SJeremy L Thompson	$(info )
448a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
449a5ef5560SJeremy L Thompson	$(info )
450a5ef5560SJeremy L Thompson	$(info Example Dependencies:)
451bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
4524d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
453bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
4548c81f8b0SPeter Munch	$(info DEAL_II_DIR   = $(DEAL_II_DIR))
455a5ef5560SJeremy L Thompson	$(info )
456a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
457a5ef5560SJeremy L Thompson	$(info )
458a5ef5560SJeremy L Thompson	$(info Install Options:)
459bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
460bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
461bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
462bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
463a5ef5560SJeremy L Thompson	$(info )
464a5ef5560SJeremy L Thompson	$(info -----------------------------------------)
465c2d180adSJeremy L Thompson	$(info )
466c2d180adSJeremy L Thompson	$(info Git:)
467c2d180adSJeremy L Thompson	$(info describe      = $(GIT_DESCRIBE))
468c2d180adSJeremy L Thompson	$(info )
469c2d180adSJeremy L Thompson	$(info -----------------------------------------)
470bf3e26f6SVeselin Dobrev	@true
4718baf801dSJeremy L Thompson
47223072ed2SVeselin Dobrevinfo-backends:
473d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
474422b683aSjeremylt	@true
4758baf801dSJeremy L Thompson
476422b683aSjeremyltinfo-backends-all:
4777b64fac9SJeremy L Thompson	$(info make: 'lib' with backends: $(BACKENDS))
478422b683aSjeremylt	@true
4790e439e50SJed Brown
4808baf801dSJeremy L Thompson
4818baf801dSJeremy L Thompson# ------------------------------------------------------------
4828baf801dSJeremy L Thompson# Backends
4838baf801dSJeremy L Thompson# ------------------------------------------------------------
48469762e1fScamierjs
48548fffa06Sjeremylt# Standard Backends
48687174f08SJed Brownlibceed.c += $(ref.c)
4874a2e7687Sjeremyltlibceed.c += $(blocked.c)
48889c6efa4Sjeremyltlibceed.c += $(opt.c)
48923072ed2SVeselin Dobrev
4905120064bSJeremy L Thompson# Memcheck Backends
491bdc3149dSjeremyltMEMCHK_STATUS   = Disabled
4926b5c14f7SJed BrownMEMCHK         := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
493ae945beaSJeremy L ThompsonMEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
494bdc3149dSjeremyltifeq ($(MEMCHK),1)
495bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
496fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
497422b683aSjeremylt  BACKENDS_MAKE += $(MEMCHK_BACKENDS)
498fc7cf9a0Sjeremyltendif
499fc7cf9a0Sjeremylt
5005120064bSJeremy L Thompson# AVX Backeds
50148fffa06SjeremyltAVX_STATUS   = Disabled
502cf4a56afSJed BrownAVX_FLAG    := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
50359e56409SJed BrownAVX         := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS:-M%=) -v -E -x c /dev/null 2>&1))
504ae945beaSJeremy L ThompsonAVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked
505cf4a56afSJed Brownifneq ($(AVX),)
50648fffa06Sjeremylt  AVX_STATUS = Enabled
50748fffa06Sjeremylt  libceed.c += $(avx.c)
508422b683aSjeremylt  BACKENDS_MAKE += $(AVX_BACKENDS)
50948fffa06Sjeremyltendif
51048fffa06Sjeremylt
5111d013790SJed Brown# Collect list of libraries and paths for use in linking and pkg-config
5121d013790SJed BrownPKG_LIBS =
5137c735608SJed Brown# Stubs that will not be RPATH'd
5147c735608SJed BrownPKG_STUBS_LIBS =
5151d013790SJed Brown
5168d713cf6Sjeremylt# libXSMM Backends
517ae945beaSJeremy L ThompsonXSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
5188d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
5194548da4eSSebastian Grimberg  PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm
52000723591Sjeremylt  MKL ?=
52100723591Sjeremylt  ifeq (,$(MKL)$(MKLROOT))
5224548da4eSSebastian Grimberg    BLAS_LIB ?= -lblas -ldl
5235462ed45Sjeremylt  else
52472e1b2f7SJeremy L Thompson    ifneq ($(MKLROOT),)
525ff56800aSJed Brown      # Some installs put everything inside an intel64 subdirectory, others not
526ff56800aSJed Brown      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
5271d013790SJed Brown      MKL_LINK = -L$(MKL_LIBDIR)
52872e1b2f7SJeremy L Thompson    endif
5294548da4eSSebastian Grimberg    BLAS_LIB ?= $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state
5305462ed45Sjeremylt  endif
5311d013790SJed Brown  PKG_LIBS += $(BLAS_LIB)
5328d713cf6Sjeremylt  libceed.c += $(xsmm.c)
533683faae0SJed Brown  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
534422b683aSjeremylt  BACKENDS_MAKE += $(XSMM_BACKENDS)
5358d713cf6Sjeremyltendif
5368d713cf6Sjeremylt
53786a4271fSThilina Rathnayake# CUDA Backends
53868c150f8SJed Brownifneq ($(CUDA_DIR),)
53968c150f8SJed Brown  CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64 lib/x86_64-linux-gnu,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
5405a9ca9adSVeselin Dobrev  CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
54168c150f8SJed Brownendif
5423dd0010eSvaleriabarraCUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
543461525f5SNatalie BeamsCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
5445a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
5459d77422eSJed Brown  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
5461d013790SJed Brown  PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas
5477c735608SJed Brown  PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS)
5481d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
549af7ca75eSjeremylt  libceed.c     += interface/ceed-cuda.c
5509a92872bSJeremy L Thompson  libceed.c     += $(cuda-all.c)
5519a92872bSJeremy L Thompson  libceed.cpp   += $(cuda-all.cpp)
5529a92872bSJeremy L Thompson  libceed.cu    += $(cuda-all.cu)
553422b683aSjeremylt  BACKENDS_MAKE += $(CUDA_BACKENDS)
5549f0427d9SYohannendif
5559f0427d9SYohann
55630f4f45fSnbeams# HIP Backends
557023b8a51Sabdelfattah83HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(ROCM_DIR)/$d/libamdhip64.${SO_EXT}))
55830f4f45fSnbeamsHIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
5597d8d0e25SnbeamsHIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen
56030f4f45fSnbeamsifneq ($(HIP_LIB_DIR),)
561f150ce52SJed Brown  HIPCONFIG_CPPFLAGS := $(subst =,,$(shell $(ROCM_DIR)/bin/hipconfig -C))
562f150ce52SJed Brown  $(hip-all.c:%.c=$(OBJDIR)/%.o) $(hip-all.c:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
56330f4f45fSnbeams  ifneq ($(CXX), $(HIPCC))
564f150ce52SJed Brown    $(hip-all.cpp:%.cpp=$(OBJDIR)/%.o) $(hip-all.cpp:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
56530f4f45fSnbeams  endif
5661d013790SJed Brown  PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas
5671d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
568f150ce52SJed Brown  libceed.c     += $(hip-all.c)
569f150ce52SJed Brown  libceed.cpp   += $(hip-all.cpp)
5709a92872bSJeremy L Thompson  libceed.hip   += $(hip-all.hip)
571422b683aSjeremylt  BACKENDS_MAKE += $(HIP_BACKENDS)
57230f4f45fSnbeamsendif
57330f4f45fSnbeams
574bd882c8aSJames Wright# SYCL Backends
5756ca0f394SUmesh UnnikrishnanSYCL_BACKENDS = /gpu/sycl/ref /gpu/sycl/shared /gpu/sycl/gen
576bd882c8aSJames Wrightifneq ($(SYCL_DIR),)
577bd882c8aSJames Wright  SYCL_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(SYCL_DIR)/$d/libsycl.${SO_EXT}))
578bd882c8aSJames Wright  SYCL_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(SYCL_LIB_DIR))))
579bd882c8aSJames Wrightendif
580bd882c8aSJames Wrightifneq ($(SYCL_LIB_DIR),)
581bd882c8aSJames Wright  PKG_LIBS += $(SYCL_FLAG) -lze_loader
582bd882c8aSJames Wright  LIBCEED_CONTAINS_CXX = 1
5836ca0f394SUmesh Unnikrishnan  libceed.sycl  += $(sycl-core.cpp) $(sycl-ref.cpp) $(sycl-shared.cpp) $(sycl-gen.cpp)
584bd882c8aSJames Wright  BACKENDS_MAKE += $(SYCL_BACKENDS)
585bd882c8aSJames Wrightendif
586bd882c8aSJames Wright
5875120064bSJeremy L Thompson# MAGMA Backends
5889f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
58945f29434Snbeams  MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas")
59045f29434Snbeams  ifeq ($(MAGMA_ARCH), 0)  # CUDA MAGMA
5919f0427d9SYohann    ifneq ($(CUDA_LIB_DIR),)
592dacf7c88SJed Brown      cuda_link = $(if $(STATIC),,-Wl,-rpath,$(CUDA_LIB_DIR)) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
5931dc2661bSVeselin Dobrev      omp_link = -fopenmp
5941dc2661bSVeselin Dobrev      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
595dacf7c88SJed Brown      magma_link_shared = -L$(MAGMA_DIR)/lib $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
5967692a9b0SVeselin Dobrev      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
5971d013790SJed Brown      PKG_LIBS += $(magma_link)
598a07e8cf1SNatalie Beams      libceed.c   += $(magma.c)
5992dc3fb5fSabdelfattah83      libceed.cpp += $(magma.cpp)
600a07e8cf1SNatalie Beams      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
6012dc3fb5fSabdelfattah83      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
60240461fa4Snbeams      MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det
60345f29434Snbeams    endif
60445f29434Snbeams  else  # HIP MAGMA
605969f2b10Snbeams    ifneq ($(HIP_LIB_DIR),)
606969f2b10Snbeams      omp_link = -fopenmp
607ae93e896SSebastian Grimberg      hip_link = $(if $(STATIC),,-Wl,-rpath,$(HIP_LIB_DIR)) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64
608969f2b10Snbeams      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link)
609023b8a51Sabdelfattah83      magma_link_shared = -L$(MAGMA_DIR)/lib $(hip_link) $(omp_link) $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
610969f2b10Snbeams      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
6111d013790SJed Brown      PKG_LIBS += $(magma_link)
612969f2b10Snbeams      libceed.c   += $(magma.c)
6132dc3fb5fSabdelfattah83      libceed.cpp += $(magma.cpp)
614ae93e896SSebastian Grimberg      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
615ae93e896SSebastian Grimberg      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
61640461fa4Snbeams      MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det
617969f2b10Snbeams    endif
61882b77998SStan Tomov  endif
6191d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
620422b683aSjeremylt  BACKENDS_MAKE += $(MAGMA_BACKENDS)
6215a9ca9adSVeselin Dobrevendif
622755585ceSStan Tomov
6235de894e4SJeremy L ThompsonBACKENDS ?= $(BACKENDS_MAKE)
624ce41f623SJed Brownexport BACKENDS
625ce41f623SJed Brown
6268baf801dSJeremy L Thompson
6278baf801dSJeremy L Thompson# ------------------------------------------------------------
6288baf801dSJeremy L Thompson# Linker Flags
6298baf801dSJeremy L Thompson# ------------------------------------------------------------
630baef4b7aSJeremy L Thompson
6311d013790SJed Brown_pkg_ldflags = $(filter -L%,$(PKG_LIBS))
6321d013790SJed Brown_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS))
633dacf7c88SJed Brown$(libceeds) : CEED_LDFLAGS += $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
6343696039aSJed Brown$(libceeds) : CEED_LDLIBS += $(_pkg_ldlibs)
6351d013790SJed Brownifeq ($(STATIC),1)
6360bd9ac94SJed Brown  $(examples) $(tests) : CEED_LDFLAGS += $(EM_LDFLAGS) $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
6373696039aSJed Brown  $(examples) $(tests) : CEED_LDLIBS += $(_pkg_ldlibs)
6381d013790SJed Brownendif
6391d013790SJed Brown
6401d013790SJed Brownpkgconfig-libs-private = $(PKG_LIBS)
6411d013790SJed Brownifeq ($(LIBCEED_CONTAINS_CXX),1)
6421d013790SJed Brown  $(libceeds) : LINK = $(CXX)
6431d013790SJed Brown  ifeq ($(STATIC),1)
6443696039aSJed Brown    $(examples) $(tests) : CEED_LDLIBS += $(LIBCXX)
6451d013790SJed Brown    pkgconfig-libs-private += $(LIBCXX)
6461d013790SJed Brown  endif
6471d013790SJed Brownendif
6481d013790SJed Brown
6498baf801dSJeremy L Thompson
6508baf801dSJeremy L Thompson# ------------------------------------------------------------
6518baf801dSJeremy L Thompson# Building core library components
6528baf801dSJeremy L Thompson# ------------------------------------------------------------
6538baf801dSJeremy L Thompson
6541d013790SJed Brown# File names *-weak.c contain weak symbol definitions, which must be listed last
6551d013790SJed Brown# when creating shared or static libraries.
6561d013790SJed Brownweak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1))
6571d013790SJed Brown
658bd882c8aSJames Wrightlibceed.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)
6594c7bddedSJed Brown$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
66023072ed2SVeselin Dobrev$(libceed.o): | info-backends
6611d013790SJed Brown$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
6623696039aSJed Brown	$(call quiet,LINK) $(LDFLAGS) $(CEED_LDFLAGS) -shared -o $@ $^ $(CEED_LDLIBS) $(LDLIBS)
66391b7489eSJed Brown
6641d013790SJed Brown$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
6651d013790SJed Brown	$(call quiet,AR) $(ARFLAGS) $@ $^
6661d013790SJed Brown
66758e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
668944f002eSJeremy L Thompson	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $(abspath $<)
669ae3cba82Scamierjs
670241a4b83SYohann$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
671241a4b83SYohann	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
672241a4b83SYohann
67358e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
674777ff853SJeremy L Thompson	$(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<)
675755585ceSStan Tomov
676cfb6011cSnbeams$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
677f150ce52SJed Brown	$(call quiet,HIPCC) $(CPPFLAGS) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
67830f4f45fSnbeams
679bd882c8aSJames Wright$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
680bd882c8aSJames Wright	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
681bd882c8aSJames Wright
6826ca0f394SUmesh Unnikrishnan$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
6836ca0f394SUmesh Unnikrishnan	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
6846ca0f394SUmesh Unnikrishnan
685e3e35afdSJed Brown$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.c | $$(@D)/.DIR
686255dad32SJeremy L Thompson	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) -I./tests/test-include
68778b5556aScamierjs
688e3e35afdSJed Brown$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.f90 | $$(@D)/.DIR
6893696039aSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
69032d74c32SThilina Rathnayake
691e3e35afdSJed Brown$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.c | $$(@D)/.DIR
6923696039aSJed Brown	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
69391b7489eSJed Brown
694860dc821SJeremy L Thompson$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.f90 | $$(@D)/.DIR
6953696039aSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
696673d494eSThilina Rathnayake
6978baf801dSJeremy L Thompson
6988baf801dSJeremy L Thompson# ------------------------------------------------------------
6998baf801dSJeremy L Thompson# Building examples
7008baf801dSJeremy L Thompson# ------------------------------------------------------------
7018baf801dSJeremy L Thompson
7028baf801dSJeremy L Thompson# deal.II
7038baf801dSJeremy L Thompson# Note: Invoking deal.II's CMAKE build system here
7048baf801dSJeremy L Thompson$(OBJDIR)/dealii-bps : examples/deal.II/*.cc examples/deal.II/*.h $(libceed) | $$(@D)/.DIR
7058baf801dSJeremy L Thompson	mkdir -p examples/deal.II/build
7068baf801dSJeremy L Thompson	cmake -B examples/deal.II/build -S examples/deal.II -DDEAL_II_DIR=$(DEAL_II_DIR) -DCEED_DIR=$(PWD)
7078baf801dSJeremy L Thompson	+$(call quiet,MAKE) -C examples/deal.II/build
7088baf801dSJeremy L Thompson	cp examples/deal.II/build/bps $(OBJDIR)/dealii-bps
7098baf801dSJeremy L Thompson
7108baf801dSJeremy L Thompson# MFEM
71116c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
712c4216f28SJed Brown	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
713722eb117SJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
714636cccdbSjeremylt	cp examples/mfem/$* $@
71516c6c054SJed Brown
7168baf801dSJeremy L Thompson# Nek5000
71786a4271fSThilina Rathnayake# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
71886a4271fSThilina Rathnayake#       this single Nek bps file to be built in parallel with other examples,
71986a4271fSThilina Rathnayake#       such as when calling `make prove-all -j2`.
72086a4271fSThilina Rathnayake$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
72186a4271fSThilina Rathnayake	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
72286a4271fSThilina Rathnayake	mv examples/nek/build/bps $(OBJDIR)/bps
72386a4271fSThilina Rathnayake	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
72486a4271fSThilina Rathnayake
7252027fb9dSSirAlienTheGreat# Rust QFunctions
7262027fb9dSSirAlienTheGreat$(OBJDIR)/rustqfunctions-% : examples/rust-qfunctions/%.c $(libceed) | $$(@D)/.DIR
7272027fb9dSSirAlienTheGreat	+$(MAKE) -C examples/rust-qfunctions CEED_DIR=`pwd`
7282027fb9dSSirAlienTheGreat	cp examples/rust-qfunctions/$* $@
7292027fb9dSSirAlienTheGreat
7308baf801dSJeremy L Thompson# PETSc
731386a09edSJed Brown# Several executables have common utilities, but we can't build the utilities
732386a09edSJed Brown# from separate submake invocations because they'll compete with each
733386a09edSJed Brown# other/corrupt output. So we put it in this utility library, but we don't want
734386a09edSJed Brown# to manually list source dependencies up at this level, so we'll just always
735386a09edSJed Brown# call recursive make to check that this utility is up to date.
736386a09edSJed Brownexamples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc)
737386a09edSJed Brown	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \
738386a09edSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F))
739386a09edSJed Brown
740386a09edSJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR
741386a09edSJed Brown	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \
742f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
743636cccdbSjeremylt	cp examples/petsc/$* $@
744e797ab98SJed Brown
7458baf801dSJeremy L Thompson# Fluid dynamics proxy application
7463e0c2f3fSJeremy L Thompson$(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
7479aeb05eaSJed Brown	+$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \
748f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
749636cccdbSjeremylt	cp examples/fluids/$* $@
750ccaff030SJeremy L Thompson
7518baf801dSJeremy L Thompson# Solid mechanics proxy application
752b571f289SJed Brown$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
753b571f289SJed Brown    examples/solids/problems/*.c examples/solids/src/*.c \
754b571f289SJed Brown    examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \
755b571f289SJed Brown    $(libceed) $(ceed.pc) | $$(@D)/.DIR
7569aeb05eaSJed Brown	+$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \
757722eb117SJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
758636cccdbSjeremylt	cp examples/solids/$* $@
7592774d5cbSJeremy L Thompson
7608baf801dSJeremy L Thompsonexamples      : $(allexamples)
7618baf801dSJeremy L Thompsonceedexamples  : $(examples)
7628baf801dSJeremy L Thompsonnekexamples   : $(nekexamples)
7638baf801dSJeremy L Thompsonmfemexamples  : $(mfemexamples)
7648baf801dSJeremy L Thompsonpetscexamples : $(petscexamples)
7658baf801dSJeremy L Thompson
7662027fb9dSSirAlienTheGreatrustqfunctionsexamples : $(rustqfunctionsexamples)
7672027fb9dSSirAlienTheGreat
7688baf801dSJeremy L Thompsonexternal_examples := \
7698baf801dSJeremy L Thompson	$(if $(MFEM_DIR),$(mfemexamples)) \
7708baf801dSJeremy L Thompson	$(if $(PETSC_DIR),$(petscexamples)) \
7718baf801dSJeremy L Thompson	$(if $(NEK5K_DIR),$(nekexamples)) \
7728baf801dSJeremy L Thompson	$(if $(DEAL_II_DIR),$(dealiiexamples)) \
7738baf801dSJeremy L Thompson	$(if $(PETSC_DIR),$(fluidsexamples)) \
7742027fb9dSSirAlienTheGreat	$(if $(PETSC_DIR),$(solidsexamples)) \
7756ca7e175SJeremy L Thompson	$(if $(or $(RUST_QF),$(GPU_CLANG)),$(rustqfunctionsexamples))
7768baf801dSJeremy L Thompson
7778baf801dSJeremy L Thompsonallexamples = $(examples) $(external_examples)
7788baf801dSJeremy L Thompson
779265be9c8Sjeremylt$(examples) : $(libceed)
7808e3e54ccSjeremylt$(tests) : $(libceed)
781dacf7c88SJed Brown$(tests) $(examples) : override LDFLAGS += $(if $(STATIC),,-Wl,-rpath,$(abspath $(LIBDIR))) -L$(LIBDIR)
7824859b599SJed Brown
7838baf801dSJeremy L Thompson
7848baf801dSJeremy L Thompson# ------------------------------------------------------------
7858baf801dSJeremy L Thompson# Testing
7868baf801dSJeremy L Thompson# ------------------------------------------------------------
7878baf801dSJeremy L Thompson
7881b16049aSZach Atkins# Set number processes for testing
7891b16049aSZach AtkinsNPROC_TEST ?= 1
7901b16049aSZach Atkinsexport NPROC_TEST
7911b16049aSZach Atkins
79219868e18SZach Atkins# Set pool size for testing
79319868e18SZach AtkinsNPROC_POOL ?= 1
79419868e18SZach Atkinsexport NPROC_POOL
79519868e18SZach Atkins
796dad465e7SJed Brownrun-% : $(OBJDIR)/%
797f36e7531SZach Atkins	@$(PYTHON) tests/junit.py --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%)
798686de4acSJed Brown
799686de4acSJed Brown# The test and prove targets can be controlled via pattern searches.  The
800686de4acSJed Brown# default is to run tests and those examples that have no external dependencies.
801686de4acSJed Brown# Examples of finer grained control:
802686de4acSJed Brown#
803686de4acSJed Brown#   make test search='petsc mfem'      # PETSc and MFEM examples
804686de4acSJed Brown#   make prove search='t3'             # t3xx series tests
805686de4acSJed Brown#   make junit search='ex petsc'       # core ex* and PETSc tests
806686de4acSJed Brownsearch ?= t ex
807686de4acSJed Brownrealsearch = $(search:%=%%)
808686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
809f36e7531SZach Atkinssubsearch ?= .*
8101b16049aSZach AtkinsJUNIT_BATCH ?= ''
811686de4acSJed Brown
8122158b1b0Sjeremylt# Test core libCEED
813686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%)
8142158b1b0Sjeremylt
81586a4271fSThilina Rathnayake# Run test target in parallel
8166850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
8173b56482dScamierjs# CPU C tests only for backend %
8183f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
8194859b599SJed Brown
8208baf801dSJeremy L Thompson# Testing with TAP format
8218baf801dSJeremy L Thompson# https://testanything.org/tap-specification.html
82286a4271fSThilina Rathnayakeprove : $(matched)
823a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
824f36e7531SZach Atkins	$(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py' $(matched:$(OBJDIR)/%=%) :: --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)'
82586a4271fSThilina Rathnayake# Run prove target in parallel
8266850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
827bfa078e6SJed Brown
828686de4acSJed Brownprove-all :
829686de4acSJed Brown	+$(MAKE) prove realsearch=%
830686de4acSJed Brown
8318ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
832f36e7531SZach Atkins	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' --junit-batch $(JUNIT_BATCH) $(<:$(OBJDIR)/%=%)
8338ec9d54bSJed Brown
83476174befSjeremyltjunit : $(matched:$(OBJDIR)/%=junit-%)
8358ec9d54bSJed Brown
8362f4d9adbSJeremy L Thompsonall: $(alltests)
8372f4d9adbSJeremy L Thompson
8382f4d9adbSJeremy L Thompson# Benchmarks
8390c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps
8404e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
8414e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
8424e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
8437b64fac9SJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
8444e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
8452c6ea02fSJed Brown
8466ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
847d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
848d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
8496ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
8501d013790SJed Brown	@$(SED) \
8511d013790SJed Brown	    -e "s:%prefix%:$(pkgconfig-prefix):" \
8525ad1e4caSJeremy L Thompson	    -e "s:%opt%:$(OPT):" \
8531d013790SJed Brown	    -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@
8540e439e50SJed Brown
8552b0143a5SJeremy L ThompsonGIT_DESCRIBE = $(shell git -c safe.directory=$PWD describe --always --dirty 2>/dev/null || printf "unknown\n")
8564f69910bSJed Brown
857944f002eSJeremy L Thompson$(OBJDIR)/interface/ceed-config.o: Makefile
858944f002eSJeremy L Thompson$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\""
859944f002eSJeremy L Thompson$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
8604f69910bSJed Brown
8616ed4cbd1SJeremy L Thompson$(OBJDIR)/interface/ceed-jit-source-root-default.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\""
8626ed4cbd1SJeremy L Thompson$(OBJDIR)/interface/ceed-jit-source-root-install.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath $(includedir))/\""
8635766aa57SJeremy L Thompson
8648baf801dSJeremy L Thompson
8658baf801dSJeremy L Thompson# ------------------------------------------------------------
8668baf801dSJeremy L Thompson# Installation
8678baf801dSJeremy L Thompson# ------------------------------------------------------------
868baef4b7aSJeremy L Thompson
869d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
870bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
871a0154adeSJed Brown	  "$(includedir)/ceed/" "$(includedir)/ceed/jit-source/"\
872a0154adeSJed Brown	  "$(includedir)/ceed/jit-source/cuda/" "$(includedir)/ceed/jit-source/hip/"\
873ae93e896SSebastian Grimberg	  "$(includedir)/ceed/jit-source/gallery/" "$(includedir)/ceed/jit-source/magma/"\
874ae93e896SSebastian Grimberg	  "$(includedir)/ceed/jit-source/sycl/" "$(libdir)" "$(pkgconfigdir)")
875ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/"
87652b0e563SJeremy L Thompson	$(INSTALL_DATA) include/ceed/deprecated.h "$(DESTDIR)$(includedir)/ceed/"
877c9c2c079SJeremy L Thompson	$(INSTALL_DATA) include/ceed/types.h "$(DESTDIR)$(includedir)/ceed/"
87880a9ef05SNatalie Beams	$(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/"
87980a9ef05SNatalie Beams	$(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/"
880ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/"
881ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/"
882ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/"
883ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/"
8841e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
8851e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
886ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
887ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
888a0154adeSJed Brown	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/cuda/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/cuda/"
889a0154adeSJed Brown	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
890a0154adeSJed Brown	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"
891ae93e896SSebastian Grimberg	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/magma/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/magma/"
892ae93e896SSebastian Grimberg	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/sycl/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/sycl/"
893d5217624SJed Brown
894d635b4c6Scamierjs
8958baf801dSJeremy L Thompson# ------------------------------------------------------------
8968baf801dSJeremy L Thompson# Cleaning
8978baf801dSJeremy L Thompson# ------------------------------------------------------------
898baef4b7aSJeremy L Thompson
8996e5d1fd9Scamierjscln clean :
9005cd88e3aSjeremylt	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
9019aeb05eaSJed Brown	$(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
9029aeb05eaSJed Brown	$(call quiet,MAKE) -C python/tests clean
903196a75e4SJed Brown	$(RM) benchmarks/*output.txt
9049b5f41c8SJeremy L Thompson	$(RM) -rf temp
9054859b599SJed Brown
90607838a1cSTzaniodistclean : clean
90721d92382SJed Brown	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
90807838a1cSTzanio
9098baf801dSJeremy L Thompson
9108baf801dSJeremy L Thompson# ------------------------------------------------------------
9112b730f8bSJeremy L Thompson# Documentation
9128baf801dSJeremy L Thompson# ------------------------------------------------------------
913baef4b7aSJeremy L Thompson
9144c4400c7SValeria BarraDOXYGEN ?= doxygen
9155cd6c1fbSSebastian Grimberg
9164c4400c7SValeria Barradoxygen :
91763be1c69SJed Brown	$(DOXYGEN) -q Doxyfile
9184c4400c7SValeria Barra
91974c2e4b1SJed Browndoc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
9204c4400c7SValeria Barra	make -C doc/sphinx $*
9214c4400c7SValeria Barra
9224c4400c7SValeria Barradoc : doc-html
9237bd3a522STzanio
9248baf801dSJeremy L Thompson
9258baf801dSJeremy L Thompson# ------------------------------------------------------------
9268baf801dSJeremy L Thompson# Linting utilities
9278baf801dSJeremy L Thompson# ------------------------------------------------------------
9288baf801dSJeremy L Thompson
9292b730f8bSJeremy L Thompson# Style/Format
9302b730f8bSJeremy L ThompsonCLANG_FORMAT      ?= clang-format
9315cd6c1fbSSebastian GrimbergCLANG_FORMAT_OPTS += -style=file -i
9325cd6c1fbSSebastian GrimbergAUTOPEP8          ?= autopep8
9332fee3251SSebastian GrimbergAUTOPEP8_OPTS     += --in-place --aggressive --max-line-length 120
9342b730f8bSJeremy L Thompson
935860dc821SJeremy L Thompsonformat.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h) $(wildcard examples/ceed/ex*-f.h), $(shell git ls-files '*.[ch]pp' '*.[ch]' '*.cu'))
9362fee3251SSebastian Grimbergformat.py := $(filter-out tests/junit-xml/junit_xml/__init__.py, $(shell git ls-files '*.py'))
937b9d14e73SJeremy L Thompsonformat.ot := $(filter-out doc/sphinx/source/CODE_OF_CONDUCT.md doc/sphinx/source/CONTRIBUTING.md, $(shell git ls-files '*.md' '*.f90'))
9382b730f8bSJeremy L Thompson
9392b730f8bSJeremy L Thompsonformat-c  :
9405cd6c1fbSSebastian Grimberg	$(CLANG_FORMAT) $(CLANG_FORMAT_OPTS) $(format.ch)
9410dbfdfc5SJed Brown
9422b730f8bSJeremy L Thompsonformat-py :
9435cd6c1fbSSebastian Grimberg	$(AUTOPEP8) $(AUTOPEP8_OPTS) $(format.py)
9447a7b0fa3SJed Brown
945b9d14e73SJeremy L Thompsonformat-ot:
946b9d14e73SJeremy L Thompson	@$(SED) -r 's/\s+$$//' -i $(format.ot)
947b9d14e73SJeremy L Thompson
948b9d14e73SJeremy L Thompsonformat    : format-c format-py format-ot
9498c210c3eSJeremy L Thompson
9508c210c3eSJeremy L Thompson# Vermin - python version requirements
9518c210c3eSJeremy L ThompsonVERMIN            ?= vermin
9522c835e80SZach AtkinsVERMIN_OPTS       += -t=3.8- --violations
9538c210c3eSJeremy L Thompson
9548c210c3eSJeremy L Thompsonvermin    :
9558c210c3eSJeremy L Thompson	$(VERMIN) $(VERMIN_OPTS) $(format.py)
9567a7b0fa3SJed Brown
9572b730f8bSJeremy L Thompson# Tidy
958683faae0SJed BrownCLANG_TIDY ?= clang-tidy
9599647a07eSDavid Medina
960683faae0SJed Brown%.c.tidy : %.c
961d4f9124cSJed Brown	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\"" -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\"" -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
962683faae0SJed Brown
9639647a07eSDavid Medina%.cpp.tidy : %.cpp
964346c77e6SJeremy L Thompson	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include
9659647a07eSDavid Medina
9662b730f8bSJeremy L Thompsontidy-c   : $(libceed.c:%=%.tidy)
9672b730f8bSJeremy L Thompsontidy-cpp : $(libceed.cpp:%=%.tidy)
9689647a07eSDavid Medina
9692b730f8bSJeremy L Thompsontidy : tidy-c tidy-cpp
970683faae0SJed Brown
97149aac155SJeremy L Thompson# Include-What-You-Use
972db52d626SJeremy L Thompsonifneq ($(wildcard ../iwyu/*),)
973db52d626SJeremy L Thompson  IWYU_DIR ?= ../iwyu
9749c06f60aSJeremy L Thompson  IWYU_CC  ?= $(IWYU_DIR)/build/bin/include-what-you-use
975db52d626SJeremy L Thompsonendif
97649aac155SJeremy L Thompsoniwyu :
97749aac155SJeremy L Thompson	$(MAKE) -B CC=$(IWYU_CC)
978db52d626SJeremy L Thompson
9798baf801dSJeremy L Thompson
9808baf801dSJeremy L Thompson# ------------------------------------------------------------
9818baf801dSJeremy L Thompson# Variable printing for debugging
9828baf801dSJeremy L Thompson# ------------------------------------------------------------
9838baf801dSJeremy L Thompson
9844859b599SJed Brownprint :
9854859b599SJed Brown	@echo $(VAR)=$($(VAR))
986582447c9SJed Brown
9879df38c42SVeselin Dobrevprint-% :
9889df38c42SVeselin Dobrev	$(info [ variable name]: $*)
9899df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
9907bcc1ce4SJed Brown	$(info [        flavor]: $(flavor $*))
9919df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
9929df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
9939df38c42SVeselin Dobrev	$(info )
9949df38c42SVeselin Dobrev	@true
9959df38c42SVeselin Dobrev
9968baf801dSJeremy L Thompson
9978baf801dSJeremy L Thompson# ------------------------------------------------------------
9988baf801dSJeremy L Thompson# Configuration caching
9998baf801dSJeremy L Thompson# ------------------------------------------------------------
1000baef4b7aSJeremy L Thompson
1001b0ab70ddSJed Brown# "make configure" detects any variables passed on the command line or
1002b0ab70ddSJed Brown# previously set in config.mk, caching them in config.mk as simple
1003b0ab70ddSJed Brown# (:=) variables.  Variables set in config.mk or on the command line
1004b0ab70ddSJed Brown# take precedence over the defaults provided in the file.  Typical
1005b0ab70ddSJed Brown# usage:
1006d3c6b40fSJed Brown#
1007d3c6b40fSJed Brown#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
1008d3c6b40fSJed Brown#   make
1009d3c6b40fSJed Brown#   make prove
1010b0ab70ddSJed Brown#
1011b0ab70ddSJed Brown# The values in the file can be updated by passing them on the command
1012b0ab70ddSJed Brown# line, e.g.,
1013b0ab70ddSJed Brown#
1014b0ab70ddSJed Brown#   make configure CC=/path/to/other/clang
1015b0ab70ddSJed Brown
1016b0ab70ddSJed Brown# All variables to consider for caching
101730f4f45fSnbeamsCONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \
1018bd882c8aSJames Wright  OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS SYCLFLAGS \
10191d013790SJed Brown  AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \
1020346c77e6SJeremy L Thompson  MAGMA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR ROCM_DIR HIP_ARCH SYCL_DIR
1021b0ab70ddSJed Brown
1022b0ab70ddSJed Brown# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
1023b0ab70ddSJed Brown# was set on the command line or in config.mk (where it will appear as
1024b0ab70ddSJed Brown# a simple variable).
1025b0ab70ddSJed Brownneeds_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
1026b0ab70ddSJed Brown
1027d3c6b40fSJed Brownconfigure :
1028b0ab70ddSJed Brown	$(file > $(CONFIG))
1029b0ab70ddSJed Brown	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
1030b0ab70ddSJed Brown	@echo "Configuration cached in $(CONFIG):"
1031b0ab70ddSJed Brown	@cat $(CONFIG)
1032d3c6b40fSJed Brown
10338baf801dSJeremy L Thompson
10348baf801dSJeremy L Thompson# ------------------------------------------------------------
10358baf801dSJeremy L Thompson# Building Python wheels for deployment
10368baf801dSJeremy L Thompson# ------------------------------------------------------------
1037baef4b7aSJeremy L Thompson
103861130325SJed Brownwheel : export MARCHFLAG = -march=generic
103961130325SJed Brownwheel : export WHEEL_PLAT = manylinux2010_x86_64
104037c134eaSJed Brownwheel :
1041dabe13fcSJed Brown	docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \
104261130325SJed Brown	  -e MARCHFLAG -e WHEEL_PLAT \
104361130325SJed Brown	  quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh
1044d3c6b40fSJed Brown
10458baf801dSJeremy L Thompson# ------------------------------------------------------------
10468baf801dSJeremy L Thompson# Phony targets
10478baf801dSJeremy L Thompson# ------------------------------------------------------------
1048baef4b7aSJeremy L Thompson
10498baf801dSJeremy L Thompson# These targets are not files but rather commands to run
10508baf801dSJeremy L Thompson.PHONY : all cln clean doxygen doc format lib install par print test tst prove prv prove-all junit examples tidy iwyu info info-backends info-backends-all configure wheel
10518baf801dSJeremy L Thompson
105237c134eaSJed Brown
105337c134eaSJed Brown# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container
105437c134eaSJed Brown-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d))
1055