xref: /libCEED/Makefile (revision 04743b7b5fe0104955757737fc8974a8dd7b80ea)
10c784865Scamierjs# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20c784865Scamierjs# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30c784865Scamierjs# All Rights reserved. See files LICENSE and NOTICE for details.
40d9661cdSTzanio#
50d9661cdSTzanio# This file is part of CEED, a collection of benchmarks, miniapps, software
60d9661cdSTzanio# libraries and APIs for efficient high-order finite element and spectral
70d9661cdSTzanio# element discretizations for exascale applications. For more information and
83d8e8822SJeremy L Thompson# source code availability see http://github.com/ceed
90d9661cdSTzanio#
100d9661cdSTzanio# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d9661cdSTzanio# a collaborative effort of two U.S. Department of Energy organizations (Office
120d9661cdSTzanio# of Science and the National Nuclear Security Administration) responsible for
130d9661cdSTzanio# the planning and preparation of a capable exascale ecosystem, including
140d9661cdSTzanio# software, applications, hardware, advanced system engineering and early
150d9661cdSTzanio# testbed platforms, in support of the nation's exascale computing imperative.
160d9661cdSTzanio
17b0ab70ddSJed BrownCONFIG ?= config.mk
18b0ab70ddSJed Brown-include $(CONFIG)
19777ff853SJeremy L ThompsonCOMMON ?= common.mk
20777ff853SJeremy L Thompson-include $(COMMON)
211571c99dSValeria Barra
22dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
236ed738d9SJed Brown  CC = gcc
24dc753d40SJed Brownendif
25241a4b83SYohannifeq (,$(filter-out undefined default,$(origin CXX)))
26241a4b83SYohann  CXX = g++
27241a4b83SYohannendif
28dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
2981c9eb91SStan Tomov  FC = gfortran
30dc753d40SJed Brownendif
31241a4b83SYohannifeq (,$(filter-out undefined default,$(origin LINK)))
32241a4b83SYohann  LINK = $(CC)
33241a4b83SYohannendif
341d013790SJed Brownifeq (,$(filter-out undefined default,$(origin AR)))
351d013790SJed Brown  AR = ar
361d013790SJed Brownendif
371d013790SJed Brownifeq (,$(filter-out undefined default,$(origin ARFLAGS)))
381d013790SJed Brown  ARFLAGS = crD
391d013790SJed Brownendif
40196a75e4SJed BrownNVCC ?= $(CUDA_DIR)/bin/nvcc
413c83ce1dSJed BrownNVCC_CXX ?= $(CXX)
4230f4f45fSnbeamsHIPCC ?= $(HIP_DIR)/bin/hipcc
431d013790SJed BrownSED ?= sed
44e86995feScamierjs
453b56482dScamierjs# ASAN must be left empty if you don't want to use it
460a7eccc5ScamierjsASAN ?=
476850bcb5Scamierjs
487c735608SJed Brown# Allow users to customize LDFLAGS (libceed appends directly to this variable)
497c735608SJed Brownoverride LDFLAGS := $(LDFLAGS)
507c735608SJed Brown
5132d74c32SThilina RathnayakeUNDERSCORE ?= 1
521b58aefaScamierjs
538df0376fSJeremy L Thompson# Verbose mode, V or VERBOSE
548df0376fSJeremy L ThompsonV ?= $(VERBOSE)
558df0376fSJeremy L Thompson
56f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory
57bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),)
589ba53df8Sjeremylt  MFEM_DIR ?= ../mfem
59f9fa8c39Sjeremyltendif
60f9fa8c39Sjeremylt
614d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
624d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
6386a4271fSThilina Rathnayake  NEK5K_DIR ?= $(abspath ../Nek5000)
644d1cd9fcSJeremy L Thompsonendif
6586a4271fSThilina Rathnayakeexport NEK5K_DIR
6686a4271fSThilina RathnayakeMPI ?= 1
6786a4271fSThilina Rathnayake
6886a4271fSThilina Rathnayake# CEED_DIR env for NEK5K testing
6986a4271fSThilina Rathnayakeexport CEED_DIR = $(abspath .)
704d1cd9fcSJeremy L Thompson
718d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
728d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
738d713cf6Sjeremylt
7412123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
757f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
76f797d7b2Scamierjs
775a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
78ab352fbeSnbeamsMAGMA_DIR ?= ../magma
7996f2f974SJed Brown
80952aa241SJed Brown# Often /opt/cuda or /usr/local/cuda, but sometimes present on machines that don't support CUDA
8196f2f974SJed BrownCUDA_DIR  ?=
82bd057117SnbeamsCUDA_ARCH ?=
8396f2f974SJed Brown
8496f2f974SJed Brown# Often /opt/rocm, but sometimes present on machines that don't support HIP
8596f2f974SJed BrownHIP_DIR ?=
86bd057117SnbeamsHIP_ARCH ?=
8782b77998SStan Tomov
882f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
892f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
902f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
912f4d9adbSJeremy L Thompsonendif
922f4d9adbSJeremy L Thompson
93bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
9412123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
95c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
9632d74c32SThilina Rathnayake
978ca0bbaeSjeremylt# Note: Intel oneAPI C/C++ compiler is now icx/icpx
98f0d101d5SJed BrownCC_VENDOR := $(subst oneAPI,icc,$(firstword $(filter gcc clang icc oneAPI XL,$(subst -, ,$(shell $(CC) --version)))))
9980a9ef05SNatalie BeamsFC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
10013d950b4SJed Brown
10113d950b4SJed Brown# Default extra flags by vendor
10213d950b4SJed BrownMARCHFLAG.gcc           := -march=native
10313d950b4SJed BrownMARCHFLAG.clang         := $(MARCHFLAG.gcc)
10413d950b4SJed BrownMARCHFLAG.icc           :=
10513d950b4SJed BrownOMP_SIMD_FLAG.gcc       := -fopenmp-simd
10613d950b4SJed BrownOMP_SIMD_FLAG.clang     := $(OMP_SIMD_FLAG.gcc)
10713d950b4SJed BrownOMP_SIMD_FLAG.icc       := -qopenmp-simd
10813d950b4SJed BrownOPT.gcc                 := -ffp-contract=fast
10913d950b4SJed BrownOPT.clang               := $(OPT.gcc)
110a52c4238SnbeamsCFLAGS.gcc              := -fPIC -std=c99 -Wall -Wextra -Wno-unused-parameter -MMD -MP
1118b45a169SnbeamsCFLAGS.clang            := $(CFLAGS.gcc)
11213d950b4SJed BrownCFLAGS.icc              := $(CFLAGS.gcc)
11313d950b4SJed BrownCFLAGS.XL               := -qpic -MMD
114a52c4238SnbeamsCXXFLAGS.gcc            := -fPIC -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
1158b45a169SnbeamsCXXFLAGS.clang          := $(CXXFLAGS.gcc)
11613d950b4SJed BrownCXXFLAGS.icc            := $(CXXFLAGS.gcc)
117a76e5e8dSVeselin DobrevCXXFLAGS.XL             := -qpic -std=c++11 -MMD
11813d950b4SJed BrownFFLAGS.GNU              := -fPIC -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP
11913d950b4SJed BrownFFLAGS.ifort            := -fPIC -cpp
12013d950b4SJed BrownFFLAGS.XL               := -qpic -ffree-form -qpreprocess -qextname -MMD
121cf4a56afSJed Brown
122d9bc9eefSJed Brown# This check works with compilers that use gcc and clang.  It fails with some
123d9bc9eefSJed Brown# compilers; e.g., xlc apparently ignores all options when -E is passed, thus
124d9bc9eefSJed Brown# succeeds with any flags.  Users can pass MARCHFLAG=... if desired.
125d9bc9eefSJed Browncc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1)
12613d950b4SJed BrownMARCHFLAG := $(MARCHFLAG.$(CC_VENDOR))
127f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native)
128f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG))
129b9c05c73SJed Brown
13013d950b4SJed BrownOMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
131f766a8abSJed BrownOMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
132cf4a56afSJed Brown
13313d950b4SJed BrownOPT    ?= -O -g $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
13413d950b4SJed BrownCFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR))
13513d950b4SJed BrownCXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR))
1361d013790SJed BrownLIBCXX ?= -lstdc++
137b0ab70ddSJed BrownNVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC
138bd057117Snbeamsifneq ($(CUDA_ARCH),)
139bd057117Snbeams  NVCCFLAGS += -arch=$(CUDA_ARCH)
140bd057117Snbeamsendif
141b3c5430cSnbeamsHIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics
142bd057117Snbeamsifneq ($(HIP_ARCH),)
143bd057117Snbeams  HIPCCFLAGS += --amdgpu-target=$(HIP_ARCH)
144bd057117Snbeamsendif
14513d950b4SJed BrownFFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
14632d74c32SThilina Rathnayake
147a6f4783aSJed Brownifeq ($(COVERAGE), 1)
148a6f4783aSJed Brown  CFLAGS += --coverage
149568410ffSJeremy L Thompson  CXXFLAGS += --coverage
150*04743b7bSJeremy L Thompson  override LDFLAGS += --coverage
151a6f4783aSJed Brownendif
152a6f4783aSJed Brown
1534dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
1544dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
155*04743b7bSJeremy L Thompsonoverride LDFLAGS += $(if $(ASAN),$(AFLAGS))
15641a90898SJed BrownCPPFLAGS += -I./include
157582447c9SJed BrownLDLIBS = -lm
15891b7489eSJed BrownOBJDIR := build
1596ea7c6c1SJed BrownLIBDIR := lib
1606ea7c6c1SJed Brown
161d5217624SJed Brown# Installation variables
162d5217624SJed Brownprefix ?= /usr/local
163d5217624SJed Brownbindir = $(prefix)/bin
164d5217624SJed Brownlibdir = $(prefix)/lib
165d5217624SJed Brownincludedir = $(prefix)/include
166d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
167d5217624SJed BrownINSTALL = install
168d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
169d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
170d5217624SJed Brown
1713b56482dScamierjs# Get number of processors of the machine
17269762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
1733b56482dScamierjs# prepare make options to run in parallel
17482985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
17521ae6867Scamierjs                       --no-print-directory --no-keep-going
17687e762eaSJed Brown
1778ec9d54bSJed BrownPYTHON ?= python3
178bfa078e6SJed BrownPROVE ?= prove
1793a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1805c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1815c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1829df38c42SVeselin Dobrev
1836ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
1841d013790SJed Brownlibceed.so := $(LIBDIR)/libceed.$(SO_EXT)
1851d013790SJed Brownlibceed.a := $(LIBDIR)/libceed.a
1861d013790SJed Brownlibceed := $(if $(STATIC),$(libceed.a),$(libceed.so))
1877e68d260SJed BrownCEED_LIBS = -lceed
1881d013790SJed Brownlibceed.c := $(filter-out interface/ceed-cuda.c interface/ceed-hip.c, $(wildcard interface/ceed*.c backends/*.c gallery/*.c))
189288c0443SJeremy L Thompsongallery.c := $(wildcard gallery/*/ceed*.c)
190288c0443SJeremy L Thompsonlibceed.c += $(gallery.c)
1918e3e54ccSjeremyltlibceeds = $(libceed)
192265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
193422b683aSjeremyltBACKENDS_MAKE := $(BACKENDS_BUILTIN)
194422b683aSjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
195bf000209STzanio
196bf000209STzanio# Tests
19757c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
19880a9ef05SNatalie Beamstests.f   := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)))
19991b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
2003f3e7340Scamierjsctests    := $(tests)
2018980d4a7Sjeremylttests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
20286a4271fSThilina Rathnayake# Examples
203182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
20480a9ef05SNatalie Beamsexamples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f)))
205182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
206182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
20786a4271fSThilina Rathnayake# MFEM Examples
2082158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
20916c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
21086a4271fSThilina Rathnayake# Nek5K Examples
21186a4271fSThilina Rathnayakenekexamples  := $(OBJDIR)/nek-bps
21286a4271fSThilina Rathnayake# PETSc Examples
2136f87d196Sjeremyltpetscexamples.c := $(wildcard examples/petsc/*.c)
214e797ab98SJed Brownpetscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
215ccaff030SJeremy L Thompson# Fluid Dynamics Examples
216ccaff030SJeremy L Thompsonfluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
217ccaff030SJeremy L Thompsonfluidsexamples  := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
218ccaff030SJeremy L Thompson# Solid Mechanics Examples
219ccaff030SJeremy L Thompsonsolidsexamples.c := $(sort $(wildcard examples/solids/*.c))
220ccaff030SJeremy L Thompsonsolidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
221e797ab98SJed Brown
2228e3e54ccSjeremylt# Backends/[ref, blocked, memcheck, opt, avx, occa, magma]
223ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
22489c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
22589c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
22689c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
22789c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
22889c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
2299f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
2307fcac036SJeremy L Thompsoncuda-ref.c     := $(sort $(wildcard backends/cuda-ref/*.c))
2317fcac036SJeremy L Thompsoncuda-ref.cpp   := $(sort $(wildcard backends/cuda-ref/*.cpp))
2327fcac036SJeremy L Thompsoncuda-ref.cu    := $(sort $(wildcard backends/cuda-ref/kernels/*.cu))
233c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
234b2573fe1SJeremy L Thompsoncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/kernels/*.cu))
235241a4b83SYohanncuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
236241a4b83SYohanncuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
237b2573fe1SJeremy L Thompsoncuda-gen.cu    := $(sort $(wildcard backends/cuda-gen/kernels/*.cu))
2389647a07eSDavid Medinaocca.cpp       := $(sort $(shell find backends/occa -type f -name *.cpp))
239a07e8cf1SNatalie Beamsmagma.c        := $(sort $(wildcard backends/magma/*.c))
240969f2b10Snbeamsmagma.cu       := $(sort $(wildcard backends/magma/kernels/cuda/*.cu))
241969f2b10Snbeamsmagma.hip      := $(sort $(wildcard backends/magma/kernels/hip/*.hip.cpp))
24230f4f45fSnbeamship.c          := $(sort $(wildcard backends/hip/*.c))
243f0f820a0SJeremy L Thompsonhip.cpp        := $(sort $(wildcard backends/hip/*.cpp))
2447fcac036SJeremy L Thompsonhip-ref.c      := $(sort $(wildcard backends/hip-ref/*.c))
2457fcac036SJeremy L Thompsonhip-ref.cpp    := $(sort $(wildcard backends/hip-ref/*.cpp))
2467fcac036SJeremy L Thompsonhip-ref.hip    := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp))
2477d8d0e25Snbeamship-shared.c   := $(sort $(wildcard backends/hip-shared/*.c))
2487d8d0e25Snbeamship-gen.c      := $(sort $(wildcard backends/hip-gen/*.c))
2497d8d0e25Snbeamship-gen.cpp    := $(sort $(wildcard backends/hip-gen/*.cpp))
25082985883Scamierjs
251777ff853SJeremy L Thompson# Quiet, color output
252777ff853SJeremy L Thompsonquiet ?= $($(1))
25321ae6867Scamierjs
254da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
2559df38c42SVeselin Dobrev.SUFFIXES:
256da72e7fcSJed Brown
25791b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
2589df38c42SVeselin Dobrev
25991b7489eSJed Brown%/.DIR :
26091b7489eSJed Brown	@mkdir -p $(@D)
26191b7489eSJed Brown	@touch $@
26291b7489eSJed Brown
26391b7489eSJed Brown.PRECIOUS: %/.DIR
26491b7489eSJed Brown
26523072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
26623072ed2SVeselin Dobrev# run 'lib' target in parallel
2672f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
268422b683aSjeremyltbackend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found])
269bf3e26f6SVeselin Dobrevinfo:
270bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
271bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
272241a4b83SYohann	$(info CXX           = $(CXX))
273bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
274bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
275bf3e26f6SVeselin Dobrev	$(info CFLAGS        = $(value CFLAGS))
276241a4b83SYohann	$(info CXXFLAGS      = $(value CXXFLAGS))
277bf3e26f6SVeselin Dobrev	$(info FFLAGS        = $(value FFLAGS))
278bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS     = $(value NVCCFLAGS))
279b7a997cfSjeremylt	$(info HIPCCFLAGS    = $(value HIPCCFLAGS))
280bf3e26f6SVeselin Dobrev	$(info LDFLAGS       = $(value LDFLAGS))
281bf3e26f6SVeselin Dobrev	$(info LDLIBS        = $(LDLIBS))
2821d013790SJed Brown	$(info AR            = $(AR))
2831d013790SJed Brown	$(info ARFLAGS       = $(ARFLAGS))
284bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
285bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
286bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
2878df0376fSJeremy L Thompson	$(info VERBOSE       = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
288bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
289ae945beaSJeremy L Thompson	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS)))
290ae945beaSJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS)))
291ae945beaSJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS)))
2929647a07eSDavid Medina	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,$(OCCA_BACKENDS)))
29340461fa4Snbeams	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS)))
294ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
29530f4f45fSnbeams	$(info HIP_DIR       = $(HIP_DIR)$(call backend_status,$(HIP_BACKENDS)))
296bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
297bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
2984d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
299bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
300bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
301bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
302bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
303bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
304bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
305bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
306bf3e26f6SVeselin Dobrev	@true
30723072ed2SVeselin Dobrevinfo-backends:
308d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
309422b683aSjeremylt	@true
310422b683aSjeremyltinfo-backends-all:
311422b683aSjeremylt	$(info make: 'lib' with backends: $(filter-out $(TEST_BACKENDS),$(BACKENDS)))
312422b683aSjeremylt	@true
3130e439e50SJed Brown
314*04743b7bSJeremy L Thompson$(libceed.so) : override LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so)))
31569762e1fScamierjs
31648fffa06Sjeremylt# Standard Backends
31787174f08SJed Brownlibceed.c += $(ref.c)
3184a2e7687Sjeremyltlibceed.c += $(blocked.c)
31989c6efa4Sjeremyltlibceed.c += $(opt.c)
32023072ed2SVeselin Dobrev
321fc7cf9a0Sjeremylt# Memcheck Backend
322bdc3149dSjeremyltMEMCHK_STATUS = Disabled
3236b5c14f7SJed BrownMEMCHK := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
324ae945beaSJeremy L ThompsonMEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
325bdc3149dSjeremyltifeq ($(MEMCHK),1)
326bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
327fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
328422b683aSjeremylt  BACKENDS_MAKE += $(MEMCHK_BACKENDS)
329fc7cf9a0Sjeremyltendif
330fc7cf9a0Sjeremylt
33148fffa06Sjeremylt# AVX Backed
33248fffa06SjeremyltAVX_STATUS = Disabled
333cf4a56afSJed BrownAVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
334130eedf9SJed BrownAVX := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS) -v -E -x c /dev/null 2>&1))
335ae945beaSJeremy L ThompsonAVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked
336cf4a56afSJed Brownifneq ($(AVX),)
33748fffa06Sjeremylt  AVX_STATUS = Enabled
33848fffa06Sjeremylt  libceed.c += $(avx.c)
339422b683aSjeremylt  BACKENDS_MAKE += $(AVX_BACKENDS)
34048fffa06Sjeremyltendif
34148fffa06Sjeremylt
3421d013790SJed Brown# Collect list of libraries and paths for use in linking and pkg-config
3431d013790SJed BrownPKG_LIBS =
3447c735608SJed Brown# Stubs that will not be RPATH'd
3457c735608SJed BrownPKG_STUBS_LIBS =
3461d013790SJed Brown
3478d713cf6Sjeremylt# libXSMM Backends
348ae945beaSJeremy L ThompsonXSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
3498d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
3501d013790SJed Brown  PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm -ldl
35100723591Sjeremylt  MKL ?=
35200723591Sjeremylt  ifeq (,$(MKL)$(MKLROOT))
353c0ea1048SJed Brown    BLAS_LIB = -lblas
3545462ed45Sjeremylt  else
35572e1b2f7SJeremy L Thompson    ifneq ($(MKLROOT),)
356ff56800aSJed Brown      # Some installs put everything inside an intel64 subdirectory, others not
357ff56800aSJed Brown      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
3581d013790SJed Brown      MKL_LINK = -L$(MKL_LIBDIR)
3591d013790SJed Brown      PKG_LIB_DIRS += $(MKL_LIBDIR)
36072e1b2f7SJeremy L Thompson    endif
3611d013790SJed Brown    BLAS_LIB = $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state
3625462ed45Sjeremylt  endif
3631d013790SJed Brown  PKG_LIBS += $(BLAS_LIB)
3648d713cf6Sjeremylt  libceed.c += $(xsmm.c)
365683faae0SJed Brown  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
366422b683aSjeremylt  BACKENDS_MAKE += $(XSMM_BACKENDS)
3678d713cf6Sjeremyltendif
3688d713cf6Sjeremylt
36948fffa06Sjeremylt# OCCA Backends
37028688798SjeremyltOCCA_BACKENDS = /cpu/self/occa
3717f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
3729647a07eSDavid Medina  OCCA_MODES := $(shell $(OCCA_DIR)/bin/occa modes)
37328688798Sjeremylt  OCCA_BACKENDS += $(if $(filter OpenMP,$(OCCA_MODES)),/cpu/openmp/occa)
37428688798Sjeremylt# OCCA_BACKENDS += $(if $(filter OpenCL,$(OCCA_MODES)),/gpu/opencl/occa)
37528688798Sjeremylt  OCCA_BACKENDS += $(if $(filter HIP,$(OCCA_MODES)),/gpu/hip/occa)
37628688798Sjeremylt  OCCA_BACKENDS += $(if $(filter CUDA,$(OCCA_MODES)),/gpu/cuda/occa)
3779647a07eSDavid Medina
3789647a07eSDavid Medina  $(libceeds) : CPPFLAGS += -I$(OCCA_DIR)/include
3791d013790SJed Brown  PKG_LIBS += -L$(abspath $(OCCA_DIR))/lib -locca
3801d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
3819647a07eSDavid Medina  libceed.cpp += $(occa.cpp)
382422b683aSjeremylt  BACKENDS_MAKE += $(OCCA_BACKENDS)
38321ae6867Scamierjsendif
38423072ed2SVeselin Dobrev
38586a4271fSThilina Rathnayake# CUDA Backends
3865a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
3875a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
3883dd0010eSvaleriabarraCUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
389461525f5SNatalie BeamsCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
3905a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
3919d77422eSJed Brown  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
3921d013790SJed Brown  PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas
3937c735608SJed Brown  PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS)
3941d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
395af7ca75eSjeremylt  libceed.c     += interface/ceed-cuda.c
3967fcac036SJeremy L Thompson  libceed.c     += $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c)
3977fcac036SJeremy L Thompson  libceed.cpp   += $(cuda-ref.cpp) $(cuda-gen.cpp)
3987fcac036SJeremy L Thompson  libceed.cu    += $(cuda-ref.cu) $(cuda-shared.cu) $(cuda-gen.cu)
399422b683aSjeremylt  BACKENDS_MAKE += $(CUDA_BACKENDS)
4009f0427d9SYohannendif
4019f0427d9SYohann
40230f4f45fSnbeams# HIP Backends
403d409f5cbSNatalie BeamsHIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(HIP_DIR)/$d/libamdhip64.${SO_EXT}))
40430f4f45fSnbeamsHIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
4057d8d0e25SnbeamsHIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen
40630f4f45fSnbeamsifneq ($(HIP_LIB_DIR),)
4073f9cf3a4Snbeams  $(libceeds) : HIPCCFLAGS += -I./include
40830f4f45fSnbeams  ifneq ($(CXX), $(HIPCC))
409cdd1636dSnbeams    CPPFLAGS += $(subst =,,$(shell $(HIP_DIR)/bin/hipconfig -C))
41030f4f45fSnbeams  endif
4117d8d0e25Snbeams  $(libceeds) : CPPFLAGS += -I$(HIP_DIR)/include
4121d013790SJed Brown  PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas
4131d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
414af7ca75eSjeremylt  libceed.c     += interface/ceed-hip.c
4157fcac036SJeremy L Thompson  libceed.c     += $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c)
4167fcac036SJeremy L Thompson  libceed.cpp   += $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp)
4177fcac036SJeremy L Thompson  libceed.hip   += $(hip-ref.hip)
418422b683aSjeremylt  BACKENDS_MAKE += $(HIP_BACKENDS)
41930f4f45fSnbeamsendif
42030f4f45fSnbeams
4219f0427d9SYohann# MAGMA Backend
4229f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
42345f29434Snbeams  MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas")
42445f29434Snbeams  ifeq ($(MAGMA_ARCH), 0) #CUDA MAGMA
4259f0427d9SYohann    ifneq ($(CUDA_LIB_DIR),)
4261dc2661bSVeselin Dobrev      cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
4271dc2661bSVeselin Dobrev      omp_link = -fopenmp
4281dc2661bSVeselin Dobrev      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
4297692a9b0SVeselin Dobrev      magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
4307692a9b0SVeselin Dobrev      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
4311d013790SJed Brown      PKG_LIBS += $(magma_link)
432a07e8cf1SNatalie Beams      libceed.c  += $(magma.c)
433a07e8cf1SNatalie Beams      libceed.cu += $(magma.cu)
434a07e8cf1SNatalie Beams      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
435a11a3c55Snbeams      $(magma.cu:%.cu=$(OBJDIR)/%.o) : CPPFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(CUDA_DIR)/include
43640461fa4Snbeams      MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det
43745f29434Snbeams    endif
43845f29434Snbeams  else  # HIP MAGMA
439969f2b10Snbeams    ifneq ($(HIP_LIB_DIR),)
440969f2b10Snbeams      hip_link = -Wl,-rpath,$(HIP_LIB_DIR) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64
441969f2b10Snbeams      omp_link = -fopenmp
442969f2b10Snbeams      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link)
443969f2b10Snbeams      magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
444969f2b10Snbeams      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
4451d013790SJed Brown      PKG_LIBS += $(magma_link)
446969f2b10Snbeams      libceed.c  += $(magma.c)
447969f2b10Snbeams      libceed.hip += $(magma.hip)
448969f2b10Snbeams      ifneq ($(CXX), $(HIPCC))
449969f2b10Snbeams        $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_DIR)/include -DHAVE_HIP -DADD_
450969f2b10Snbeams      else
451969f2b10Snbeams        $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_DIR)/include -DHAVE_HIP -DADD_
452969f2b10Snbeams      endif
453a11a3c55Snbeams      $(magma.hip:%.hip.cpp=$(OBJDIR)/%.o) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(HIP_DIR)/include -DHAVE_HIP -DADD_
45440461fa4Snbeams      MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det
455969f2b10Snbeams    endif
45682b77998SStan Tomov  endif
4571d013790SJed Brown  LIBCEED_CONTAINS_CXX = 1
458422b683aSjeremylt  BACKENDS_MAKE += $(MAGMA_BACKENDS)
4595a9ca9adSVeselin Dobrevendif
460755585ceSStan Tomov
4615de894e4SJeremy L ThompsonBACKENDS ?= $(BACKENDS_MAKE)
462ce41f623SJed Brownexport BACKENDS
463ce41f623SJed Brown
4641d013790SJed Brown_pkg_ldflags = $(filter -L%,$(PKG_LIBS))
4651d013790SJed Brown_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS))
466*04743b7bSJeremy L Thompson$(libceeds) : override LDFLAGS += $(_pkg_ldflags) $(_pkg_ldflags:-L%=-Wl,-rpath,%) $(PKG_STUBS_LIBS)
4671d013790SJed Brown$(libceeds) : LDLIBS += $(_pkg_ldlibs)
4681d013790SJed Brownifeq ($(STATIC),1)
469*04743b7bSJeremy L Thompson$(examples) $(tests) : override LDFLAGS += $(_pkg_ldflags) $(_pkg_ldflags:-L%=-Wl,-rpath,%) $(PKG_STUBS_LIBS)
4701d013790SJed Brown$(examples) $(tests) : LDLIBS += $(_pkg_ldlibs)
4711d013790SJed Brownendif
4721d013790SJed Brown
4731d013790SJed Brownpkgconfig-libs-private = $(PKG_LIBS)
4741d013790SJed Brownifeq ($(LIBCEED_CONTAINS_CXX),1)
4751d013790SJed Brown  $(libceeds) : LINK = $(CXX)
4761d013790SJed Brown  ifeq ($(STATIC),1)
4771d013790SJed Brown    $(examples) $(tests) : LDLIBS += $(LIBCXX)
4781d013790SJed Brown	  pkgconfig-libs-private += $(LIBCXX)
4791d013790SJed Brown  endif
4801d013790SJed Brownendif
4811d013790SJed Brown
4821d013790SJed Brown# File names *-weak.c contain weak symbol definitions, which must be listed last
4831d013790SJed Brown# when creating shared or static libraries.
4841d013790SJed Brownweak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1))
4851d013790SJed Brown
486cfb6011cSnbeamslibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o)
4874c7bddedSJed Brown$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
48823072ed2SVeselin Dobrev$(libceed.o): | info-backends
4891d013790SJed Brown$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
490241a4b83SYohann	$(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
49191b7489eSJed Brown
4921d013790SJed Brown$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
4931d013790SJed Brown	$(call quiet,AR) $(ARFLAGS) $@ $^
4941d013790SJed Brown
49558e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
496b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
497ae3cba82Scamierjs
498241a4b83SYohann$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
499241a4b83SYohann	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
500241a4b83SYohann
50158e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
502777ff853SJeremy L Thompson	$(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<)
503755585ceSStan Tomov
504cfb6011cSnbeams$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
50530f4f45fSnbeams	$(call quiet,HIPCC) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
50630f4f45fSnbeams
507b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
508843fcb4bSJed Brown	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
50978b5556aScamierjs
5108980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
511843fcb4bSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
51232d74c32SThilina Rathnayake
513182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
514843fcb4bSJed Brown	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
51591b7489eSJed Brown
516182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
517843fcb4bSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
518673d494eSThilina Rathnayake
51916c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
520c4216f28SJed Brown	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
521722eb117SJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
522636cccdbSjeremylt	cp examples/mfem/$* $@
52316c6c054SJed Brown
52486a4271fSThilina Rathnayake# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
52586a4271fSThilina Rathnayake#       this single Nek bps file to be built in parallel with other examples,
52686a4271fSThilina Rathnayake#       such as when calling `make prove-all -j2`.
52786a4271fSThilina Rathnayake$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
52886a4271fSThilina Rathnayake	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
52986a4271fSThilina Rathnayake	mv examples/nek/build/bps $(OBJDIR)/bps
53086a4271fSThilina Rathnayake	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
53186a4271fSThilina Rathnayake
532386a09edSJed Brown# Several executables have common utilities, but we can't build the utilities
533386a09edSJed Brown# from separate submake invocations because they'll compete with each
534386a09edSJed Brown# other/corrupt output. So we put it in this utility library, but we don't want
535386a09edSJed Brown# to manually list source dependencies up at this level, so we'll just always
536386a09edSJed Brown# call recursive make to check that this utility is up to date.
537386a09edSJed Brownexamples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc)
538386a09edSJed Brown	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \
539386a09edSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F))
540386a09edSJed Brown
541386a09edSJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR
542386a09edSJed Brown	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \
543f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
544636cccdbSjeremylt	cp examples/petsc/$* $@
545e797ab98SJed Brown
546b868981dSJed Brown$(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
5479aeb05eaSJed Brown	+$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \
548f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
549636cccdbSjeremylt	cp examples/fluids/$* $@
550ccaff030SJeremy L Thompson
551b571f289SJed Brown$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
552b571f289SJed Brown    examples/solids/problems/*.c examples/solids/src/*.c \
553b571f289SJed Brown    examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \
554b571f289SJed Brown    $(libceed) $(ceed.pc) | $$(@D)/.DIR
5559aeb05eaSJed Brown	+$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \
556722eb117SJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
557636cccdbSjeremylt	cp examples/solids/$* $@
5582774d5cbSJeremy L Thompson
559265be9c8Sjeremylt$(examples) : $(libceed)
5608e3e54ccSjeremylt$(tests) : $(libceed)
561*04743b7bSJeremy L Thompson$(tests) $(examples) : override LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
5624859b599SJed Brown
563dad465e7SJed Brownrun-% : $(OBJDIR)/%
564d1f7f8d3SJed Brown	@tests/tap.sh $(<:$(OBJDIR)/%=%)
565686de4acSJed Brown
566686de4acSJed Brownexternal_examples := \
567686de4acSJed Brown	$(if $(MFEM_DIR),$(mfemexamples)) \
568686de4acSJed Brown	$(if $(PETSC_DIR),$(petscexamples)) \
569b974e86eSJed Brown	$(if $(NEK5K_DIR),$(nekexamples)) \
570ccaff030SJeremy L Thompson	$(if $(PETSC_DIR),$(fluidsexamples)) \
571ccaff030SJeremy L Thompson	$(if $(PETSC_DIR),$(solidsexamples))
572686de4acSJed Brown
573686de4acSJed Brownallexamples = $(examples) $(external_examples)
574686de4acSJed Brown
575686de4acSJed Brown# The test and prove targets can be controlled via pattern searches.  The
576686de4acSJed Brown# default is to run tests and those examples that have no external dependencies.
577686de4acSJed Brown# Examples of finer grained control:
578686de4acSJed Brown#
579686de4acSJed Brown#   make test search='petsc mfem'      # PETSc and MFEM examples
580686de4acSJed Brown#   make prove search='t3'             # t3xx series tests
581686de4acSJed Brown#   make junit search='ex petsc'       # core ex* and PETSc tests
582686de4acSJed Brownsearch ?= t ex
583686de4acSJed Brownrealsearch = $(search:%=%%)
584686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
585686de4acSJed Brown
5862158b1b0Sjeremylt# Test core libCEED
587686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%)
5882158b1b0Sjeremylt
58986a4271fSThilina Rathnayake# Run test target in parallel
5906850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
5913b56482dScamierjs# CPU C tests only for backend %
5923f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
5934859b599SJed Brown
59486a4271fSThilina Rathnayakeprove : $(matched)
595a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
596686de4acSJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
59786a4271fSThilina Rathnayake# Run prove target in parallel
5986850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
599bfa078e6SJed Brown
600686de4acSJed Brownprove-all :
601686de4acSJed Brown	+$(MAKE) prove realsearch=%
602686de4acSJed Brown
6038ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
604bdb0bdbbSJed Brown	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
6058ec9d54bSJed Brown
60676174befSjeremyltjunit : $(matched:$(OBJDIR)/%=junit-%)
6078ec9d54bSJed Brown
6082f4d9adbSJeremy L Thompsonall: $(alltests)
6092f4d9adbSJeremy L Thompson
6102f4d9adbSJeremy L Thompsonexamples : $(allexamples)
61186a4271fSThilina Rathnayakeceedexamples : $(examples)
61286a4271fSThilina Rathnayakenekexamples : $(nekexamples)
61386a4271fSThilina Rathnayakemfemexamples : $(mfemexamples)
61486a4271fSThilina Rathnayakepetscexamples : $(petscexamples)
6152f4d9adbSJeremy L Thompson
6162f4d9adbSJeremy L Thompson# Benchmarks
6170c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps
6184e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
6194e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
6204e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
621422b683aSjeremylt	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS_MAKE)" -r $(*).sh
6224e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
6232c6ea02fSJed Brown
6246ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
625d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
626d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
6276ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
6281d013790SJed Brown	@$(SED) \
6291d013790SJed Brown	    -e "s:%prefix%:$(pkgconfig-prefix):" \
6301d013790SJed Brown	    -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@
6310e439e50SJed Brown
632d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
633bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
634ec3da8bcSJed Brown	  "$(includedir)/ceed/" "$(libdir)" "$(pkgconfigdir)")
635ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/"
63680a9ef05SNatalie Beams	$(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/"
63780a9ef05SNatalie Beams	$(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/"
638ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/"
639ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/"
640ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/"
641ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/"
642ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/hash.h "$(DESTDIR)$(includedir)/ceed/"
643ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed/khash.h "$(DESTDIR)$(includedir)/ceed/"
6441e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
6451e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
646ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
647ec3da8bcSJed Brown	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
648d5217624SJed Brown
649db52d626SJeremy L Thompson.PHONY : all cln clean doxygen doc lib install par print test tst prove prv prove-all junit examples style style-c style-py tidy iwyu info info-backends info-backends-all
650d635b4c6Scamierjs
6516e5d1fd9Scamierjscln clean :
6525cd88e3aSjeremylt	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
6539aeb05eaSJed Brown	$(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
6549aeb05eaSJed Brown	$(call quiet,MAKE) -C python/tests clean
655196a75e4SJed Brown	$(RM) benchmarks/*output.txt
6564859b599SJed Brown
65707838a1cSTzaniodistclean : clean
65821d92382SJed Brown	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
65907838a1cSTzanio
6604c4400c7SValeria BarraDOXYGEN ?= doxygen
6614c4400c7SValeria Barradoxygen :
66263be1c69SJed Brown	$(DOXYGEN) -q Doxyfile
6634c4400c7SValeria Barra
66474c2e4b1SJed Browndoc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
6654c4400c7SValeria Barra	make -C doc/sphinx $*
6664c4400c7SValeria Barra
6674c4400c7SValeria Barradoc : doc-html
6687bd3a522STzanio
6697a7b0fa3SJed Brownstyle-c :
67020b73d85SJed Brown	@astyle --options=.astylerc \
671752c3701SJeremy L Thompson          $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), \
67220b73d85SJed Brown            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
673ccaff030SJeremy L Thompson              examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch]))
6740dbfdfc5SJed Brown
6757a7b0fa3SJed BrownAUTOPEP8 = autopep8
6767a7b0fa3SJed Brownstyle-py : AUTOPEP8_ARGS = --in-place --aggressive
6777a7b0fa3SJed Brownstyle-py :
67893dee7faSjeremylt	@$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py python/tests/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py)
6797a7b0fa3SJed Brown
6807a7b0fa3SJed Brownstyle : style-c style-py
6817a7b0fa3SJed Brown
682683faae0SJed BrownCLANG_TIDY ?= clang-tidy
6839647a07eSDavid Medina
684683faae0SJed Brown%.c.tidy : %.c
685ccf1f208Snbeams	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 -I$(CUDA_DIR)/include -I$(HIP_DIR)/include
686683faae0SJed Brown
6879647a07eSDavid Medina%.cpp.tidy : %.cpp
688ccf1f208Snbeams	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include -I$(HIP_DIR)/include
6899647a07eSDavid Medina
6909647a07eSDavid Medinatidy_c   : $(libceed.c:%=%.tidy)
6919647a07eSDavid Medinatidy_cpp : $(libceed.cpp:%=%.tidy)
6929647a07eSDavid Medina
6939647a07eSDavid Medinatidy : tidy_c tidy_cpp
694683faae0SJed Brown
695db52d626SJeremy L Thompsonifneq ($(wildcard ../iwyu/*),)
696db52d626SJeremy L Thompson  IWYU_DIR ?= ../iwyu
6979c06f60aSJeremy L Thompson  IWYU_CC  ?= $(IWYU_DIR)/build/bin/include-what-you-use
698db52d626SJeremy L Thompsonendif
699db52d626SJeremy L Thompson
7009c06f60aSJeremy L Thompsoniwyu : CC=$(IWYU_CC)
7019c06f60aSJeremy L Thompsoniwyu : lib
702db52d626SJeremy L Thompson
7034859b599SJed Brownprint :
7044859b599SJed Brown	@echo $(VAR)=$($(VAR))
705582447c9SJed Brown
7069df38c42SVeselin Dobrevprint-% :
7079df38c42SVeselin Dobrev	$(info [ variable name]: $*)
7089df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
7097bcc1ce4SJed Brown	$(info [        flavor]: $(flavor $*))
7109df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
7119df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
7129df38c42SVeselin Dobrev	$(info )
7139df38c42SVeselin Dobrev	@true
7149df38c42SVeselin Dobrev
715b0ab70ddSJed Brown# "make configure" detects any variables passed on the command line or
716b0ab70ddSJed Brown# previously set in config.mk, caching them in config.mk as simple
717b0ab70ddSJed Brown# (:=) variables.  Variables set in config.mk or on the command line
718b0ab70ddSJed Brown# take precedence over the defaults provided in the file.  Typical
719b0ab70ddSJed Brown# usage:
720d3c6b40fSJed Brown#
721d3c6b40fSJed Brown#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
722d3c6b40fSJed Brown#   make
723d3c6b40fSJed Brown#   make prove
724b0ab70ddSJed Brown#
725b0ab70ddSJed Brown# The values in the file can be updated by passing them on the command
726b0ab70ddSJed Brown# line, e.g.,
727b0ab70ddSJed Brown#
728b0ab70ddSJed Brown#   make configure CC=/path/to/other/clang
729b0ab70ddSJed Brown
730b0ab70ddSJed Brown# All variables to consider for caching
73130f4f45fSnbeamsCONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \
73230f4f45fSnbeams	OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS \
7331d013790SJed Brown	AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \
734aa8cce74SJed Brown	MAGMA_DIR OCCA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR HIP_DIR HIP_ARCH
735b0ab70ddSJed Brown
736b0ab70ddSJed Brown# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
737b0ab70ddSJed Brown# was set on the command line or in config.mk (where it will appear as
738b0ab70ddSJed Brown# a simple variable).
739b0ab70ddSJed Brownneeds_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
740b0ab70ddSJed Brown
741d3c6b40fSJed Brownconfigure :
742b0ab70ddSJed Brown	$(file > $(CONFIG))
743b0ab70ddSJed Brown	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
744b0ab70ddSJed Brown	@echo "Configuration cached in $(CONFIG):"
745b0ab70ddSJed Brown	@cat $(CONFIG)
746d3c6b40fSJed Brown
74761130325SJed Brownwheel : export MARCHFLAG = -march=generic
74861130325SJed Brownwheel : export WHEEL_PLAT = manylinux2010_x86_64
74937c134eaSJed Brownwheel :
750dabe13fcSJed Brown	docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \
75161130325SJed Brown		-e MARCHFLAG -e WHEEL_PLAT \
75261130325SJed Brown		quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh
753d3c6b40fSJed Brown
75437c134eaSJed Brown.PHONY : configure wheel
75537c134eaSJed Brown
75637c134eaSJed Brown# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container
75737c134eaSJed Brown-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d))
758