xref: /libCEED/Makefile (revision a44bca27e5d331f553a82497b0c34f31883da506)
1# Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2# All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# This file is part of CEED:  http://github.com/ceed
7
8# ------------------------------------------------------------
9# Configuration
10# ------------------------------------------------------------
11
12# config.mk stores cached configuration variables
13CONFIG ?= config.mk
14-include $(CONFIG)
15
16# common.mk holds definitions used in various makefiles throughout the project
17COMMON ?= common.mk
18-include $(COMMON)
19
20# Quiet, color output
21quiet ?= $($(1))
22
23# Cancel built-in and old-fashioned implicit rules which we don't use
24.SUFFIXES:
25
26.SECONDEXPANSION: # to expand $$(@D)/.DIR
27
28%/.DIR :
29	@mkdir -p $(@D)
30	@touch $@
31
32.PRECIOUS: %/.DIR
33
34
35DARWIN := $(filter Darwin,$(shell uname -s))
36
37
38# ------------------------------------------------------------
39# Root directories for backend dependencies
40# ------------------------------------------------------------
41
42# XSMM_DIR env variable should point to XSMM main (github.com/hfp/libxsmm)
43XSMM_DIR ?= ../libxsmm
44
45# Often /opt/cuda or /usr/local/cuda, but sometimes present on machines that don't support CUDA
46CUDA_DIR  ?=
47CUDA_ARCH ?=
48
49# Often /opt/rocm, but sometimes present on machines that don't support HIP
50ROCM_DIR ?=
51HIP_ARCH ?=
52
53# env variable MAGMA_DIR can be used too
54MAGMA_DIR ?= ../magma
55
56
57# ------------------------------------------------------------
58# Compiler flags
59# ------------------------------------------------------------
60
61# Detect user compiler options and set defaults
62ifeq (,$(filter-out undefined default,$(origin CC)))
63  CC = gcc
64endif
65ifeq (,$(filter-out undefined default,$(origin CXX)))
66  CXX = g++
67endif
68ifeq (,$(filter-out undefined default,$(origin FC)))
69  FC = gfortran
70endif
71ifeq (,$(filter-out undefined default,$(origin LINK)))
72  LINK = $(CC)
73endif
74ifeq (,$(filter-out undefined default,$(origin AR)))
75  AR = ar
76endif
77ifeq (,$(filter-out undefined default,$(origin ARFLAGS)))
78  ARFLAGS = $(if $(DARWIN),cr,crD)
79endif
80NVCC ?= $(CUDA_DIR)/bin/nvcc
81NVCC_CXX ?= $(CXX)
82HIPCC ?= $(ROCM_DIR)/bin/hipcc
83SYCLCXX ?= $(CXX)
84SED ?= sed
85ifneq ($(EMSCRIPTEN),)
86  STATIC = 1
87  EXE_SUFFIX = .wasm
88  EM_LDFLAGS = -s TOTAL_MEMORY=256MB
89endif
90
91# ASAN must be left empty if you don't want to use it
92ASAN ?=
93
94# These are the values automatically detected here in the makefile. They are
95# augmented with LDFLAGS and LDLIBS from the environment/passed by command line,
96# if any. If the user sets CEED_LDFLAGS or CEED_LDLIBS, they are used *instead
97# of* what we populate here (thus that's advanced usage and not recommended).
98CEED_LDFLAGS ?=
99CEED_LDLIBS  ?=
100
101UNDERSCORE ?= 1
102
103# Verbose mode, V or VERBOSE
104V ?= $(VERBOSE)
105
106# SANTIZ options
107AFLAGS ?= -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
108
109# Note: Intel oneAPI C/C++ compiler is now icx/icpx
110CC_VENDOR := $(firstword $(filter gcc (GCC) clang cc icc icc_orig oneAPI XL emcc,$(subst -, ,$(shell $(CC) --version))))
111CC_VENDOR := $(subst (GCC),gcc,$(subst icc_orig,icc,$(CC_VENDOR)))
112CC_VENDOR := $(if $(filter cc,$(CC_VENDOR)),gcc,$(CC_VENDOR))
113FC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort ifx XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
114
115# Default extra flags by vendor
116MARCHFLAG.gcc           := -march=native
117MARCHFLAG.clang         := $(MARCHFLAG.gcc)
118MARCHFLAG.icc           :=
119MARCHFLAG.oneAPI        := $(MARCHFLAG.clang)
120OMP_SIMD_FLAG.gcc       := -fopenmp-simd
121OMP_SIMD_FLAG.clang     := $(OMP_SIMD_FLAG.gcc)
122OMP_SIMD_FLAG.icc       := -qopenmp-simd
123OMP_SIMD_FLAG.oneAPI    := $(OMP_SIMD_FLAG.icc)
124OMP_FLAG.gcc            := -fopenmp
125OMP_FLAG.clang          := $(OMP_FLAG.gcc)
126OMP_FLAG.icc            := -qopenmp
127OMP_FLAG.oneAPI         := $(OMP_FLAG.icc)
128SYCL_FLAG.gcc           :=
129SYCL_FLAG.clang         := -fsycl
130SYCL_FLAG.icc           :=
131SYCL_FLAG.oneAPI        := -fsycl -fno-sycl-id-queries-fit-in-int
132OPT.gcc                 := -g -ffp-contract=fast
133OPT.clang               := $(OPT.gcc)
134OPT.icc                 := $(OPT.gcc)
135OPT.oneAPI              := $(OPT.clang)
136OPT.emcc                :=
137CFLAGS.gcc              := $(if $(STATIC),,-fPIC) -std=c11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
138CFLAGS.clang            := $(CFLAGS.gcc)
139CFLAGS.icc              := $(CFLAGS.gcc)
140CFLAGS.oneAPI           := $(CFLAGS.clang)
141CFLAGS.XL               := $(if $(STATIC),,-qpic) -MMD
142CFLAGS.emcc             := $(CFLAGS.clang)
143CXXFLAGS.gcc            := $(if $(STATIC),,-fPIC) -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
144CXXFLAGS.clang          := $(CXXFLAGS.gcc)
145CXXFLAGS.icc            := $(CXXFLAGS.gcc)
146CXXFLAGS.oneAPI         := $(CXXFLAGS.clang)
147CXXFLAGS.XL             := $(if $(STATIC),,-qpic) -std=c++11 -MMD
148CXXFLAGS.emcc           := $(CXXFLAGS.clang)
149FFLAGS.GNU              := $(if $(STATIC),,-fPIC) -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP
150FFLAGS.ifort            := $(if $(STATIC),,-fPIC) -cpp
151FFLAGS.ifx              := $(FFLAGS.ifort)
152FFLAGS.XL               := $(if $(STATIC),,-qpic) -ffree-form -qpreprocess -qextname -MMD
153
154# This check works with compilers that use gcc and clang.  It fails with some
155# compilers; e.g., xlc apparently ignores all options when -E is passed, thus
156# succeeds with any flags.  Users can pass MARCHFLAG=... if desired.
157cc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1)
158MARCHFLAG := $(MARCHFLAG.$(CC_VENDOR))
159MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native)
160MARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG))
161
162OMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
163OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
164
165# Error checking flags
166PEDANTIC      ?=
167PEDANTICFLAGS ?= -Werror -pedantic
168
169# Compiler flags
170OPT    ?= -O $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
171CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
172CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
173FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
174LIBCXX ?= -lstdc++
175NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler '$(OPT)' -Xcompiler -fPIC
176ifneq ($(CUDA_ARCH),)
177  NVCCFLAGS += -arch=$(CUDA_ARCH)
178endif
179HIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics
180ifneq ($(HIP_ARCH),)
181  HIPCCFLAGS += --offload-arch=$(HIP_ARCH)
182endif
183SYCL_FLAG := $(SYCL_FLAG.$(CC_VENDOR))
184SYCLFLAGS ?= $(SYCL_FLAG) -fPIC -std=c++17 $(filter-out -std=c++11,$(CXXFLAGS)) $(filter-out $(OMP_SIMD_FLAG),$(OPT))
185
186OPENMP ?=
187ifneq ($(OPENMP),)
188  OMP_FLAG := $(OMP_FLAG.$(CC_VENDOR))
189  OMP_FLAG := $(if $(call cc_check_flag,$(OMP_FLAG)),$(OMP_FLAG))
190  CFLAGS += $(OMP_FLAG)
191  CEED_LDFLAGS += $(OMP_FLAG)
192endif
193
194ifeq ($(COVERAGE), 1)
195  CFLAGS += --coverage
196  CXXFLAGS += --coverage
197  CEED_LDFLAGS += --coverage
198endif
199
200CFLAGS += $(if $(ASAN),$(AFLAGS))
201FFLAGS += $(if $(ASAN),$(AFLAGS))
202CEED_LDFLAGS += $(if $(ASAN),$(AFLAGS))
203CPPFLAGS += -I./include
204CEED_LDLIBS = -lm
205OBJDIR := build
206for_install := $(filter install,$(MAKECMDGOALS))
207LIBDIR := $(if $(for_install),$(OBJDIR),lib)
208
209# Installation variables
210prefix ?= /usr/local
211bindir = $(prefix)/bin
212libdir = $(prefix)/lib
213includedir = $(prefix)/include
214pkgconfigdir = $(libdir)/pkgconfig
215INSTALL = install
216INSTALL_PROGRAM = $(INSTALL)
217INSTALL_DATA = $(INSTALL) -m644
218
219# Get number of processors of the machine
220NPROCS := $(shell getconf _NPROCESSORS_ONLN)
221# prepare make options to run in parallel
222MFLAGS := -j $(NPROCS) --warn-undefined-variables \
223                       --no-print-directory --no-keep-going
224
225PYTHON ?= python3
226PROVE ?= prove
227PROVE_OPTS ?= -j $(NPROCS)
228SO_EXT := $(if $(DARWIN),dylib,so)
229
230ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
231libceed.so := $(LIBDIR)/libceed.$(SO_EXT)
232libceed.a := $(LIBDIR)/libceed.a
233libceed := $(if $(STATIC),$(libceed.a),$(libceed.so))
234CEED_LIBS = -lceed
235libceeds = $(libceed)
236BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
237BACKENDS_MAKE := $(BACKENDS_BUILTIN)
238
239
240# ------------------------------------------------------------
241# Root directories for examples using external libraries
242# ------------------------------------------------------------
243
244# DEAL_II_DIR env variable should point to sibling directory
245ifneq ($(wildcard ../dealii/install/lib/libdeal_II.*),)
246  DEAL_II_DIR ?= ../dealii/install
247endif
248# Export for deal.II testing
249export DEAL_II_DIR
250
251# MFEM_DIR env variable should point to sibling directory
252ifneq ($(wildcard ../mfem/libmfem.*),)
253  MFEM_DIR ?= ../mfem
254endif
255
256# NEK5K_DIR env variable should point to sibling directory
257ifneq ($(wildcard ../Nek5000/*),)
258  NEK5K_DIR ?= $(abspath ../Nek5000)
259endif
260# Exports for NEK5K testing
261export CEED_DIR = $(abspath .)
262export NEK5K_DIR
263MPI ?= 1
264
265# Check for PETSc in ../petsc
266ifneq ($(wildcard ../petsc/lib/libpetsc.*),)
267  PETSC_DIR ?= ../petsc
268endif
269
270# ------------------------------------------------------------
271# Build the library (default target)
272# ------------------------------------------------------------
273
274lib: $(libceed) $(ceed.pc)
275# run 'lib' target in parallel
276par:;@$(MAKE) $(MFLAGS) V=$(V) lib
277
278$(libceed.so) : CEED_LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so)))
279
280# ------------------------------------------------------------
281# Source files
282# ------------------------------------------------------------
283
284# Interface and gallery
285libceed.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))
286gallery.c := $(wildcard gallery/*/ceed*.c)
287libceed.c += $(gallery.c)
288
289# Backends
290# - CPU
291ref.c          := $(sort $(wildcard backends/ref/*.c))
292blocked.c      := $(sort $(wildcard backends/blocked/*.c))
293ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
294opt.c          := $(sort $(wildcard backends/opt/*.c))
295avx.c          := $(sort $(wildcard backends/avx/*.c))
296xsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
297# - GPU
298cuda.c         := $(sort $(wildcard backends/cuda/*.c))
299cuda.cpp       := $(sort $(wildcard backends/cuda/*.cpp))
300cuda-ref.c     := $(sort $(wildcard backends/cuda-ref/*.c))
301cuda-ref.cpp   := $(sort $(wildcard backends/cuda-ref/*.cpp))
302cuda-ref.cu    := $(sort $(wildcard backends/cuda-ref/kernels/*.cu))
303cuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
304cuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
305cuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
306cuda-all.c     := interface/ceed-cuda.c $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c)
307cuda-all.cpp   := $(cuda.cpp) $(cuda-ref.cpp) $(cuda-gen.cpp)
308cuda-all.cu    := $(cuda-ref.cu)
309hip.c          := $(sort $(wildcard backends/hip/*.c))
310hip.cpp        := $(sort $(wildcard backends/hip/*.cpp))
311hip-ref.c      := $(sort $(wildcard backends/hip-ref/*.c))
312hip-ref.cpp    := $(sort $(wildcard backends/hip-ref/*.cpp))
313hip-ref.hip    := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp))
314hip-shared.c   := $(sort $(wildcard backends/hip-shared/*.c))
315hip-gen.c      := $(sort $(wildcard backends/hip-gen/*.c))
316hip-gen.cpp    := $(sort $(wildcard backends/hip-gen/*.cpp))
317hip-all.c      := interface/ceed-hip.c $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c)
318hip-all.cpp    := $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp)
319hip-all.hip    := $(hip-ref.hip)
320sycl-core.cpp  := $(sort $(wildcard backends/sycl/*.sycl.cpp))
321sycl-ref.cpp   := $(sort $(wildcard backends/sycl-ref/*.sycl.cpp))
322sycl-shared.cpp:= $(sort $(wildcard backends/sycl-shared/*.sycl.cpp))
323sycl-gen.cpp   := $(sort $(wildcard backends/sycl-gen/*.sycl.cpp))
324magma.c        := $(sort $(wildcard backends/magma/*.c))
325magma.cpp      := $(sort $(wildcard backends/magma/*.cpp))
326
327# Tests
328tests.c := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
329tests.f := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)))
330tests   := $(tests.c:tests/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
331ctests  := $(tests)
332tests   += $(tests.f:tests/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
333
334# Examples
335examples.c := $(sort $(wildcard examples/ceed/*.c))
336examples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f90)))
337examples   := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
338examples   += $(examples.f:examples/ceed/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
339
340# deal.II Examples
341dealiiexamples.cc := $(sort $(wildcard examples/deal.II/*.cc))
342dealiiexamples    := $(dealiiexamples.cc:examples/deal.II/%.cc=$(OBJDIR)/dealii-%)
343
344# MFEM Examples
345mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
346mfemexamples     := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
347
348# Nek5K Examples
349nekexamples := $(OBJDIR)/nek-bps
350
351# Rust QFunction Examples
352rustqfunctions.c       := $(sort $(wildcard examples/rust-qfunctions/*.c))
353rustqfunctionsexamples := $(rustqfunctions.c:examples/rust-qfunctions/%.c=$(OBJDIR)/rustqfunctions-%)
354
355# PETSc Examples
356petscexamples.c := $(wildcard examples/petsc/*.c)
357petscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
358
359# Fluid Dynamics Example
360fluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
361fluidsexamples   := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
362
363# Solid Mechanics Example
364solidsexamples.c := $(sort $(wildcard examples/solids/*.c))
365solidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
366
367
368# ------------------------------------------------------------
369# View configuration options
370# ------------------------------------------------------------
371
372backend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found])
373
374info-basic:
375	$(info -----------------------------------------)
376	$(info |     ___ __    ______________________  |)
377	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
378	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
379	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
380	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
381	$(info -----------------------------------------)
382	$(info )
383	$(info -----------------------------------------)
384	$(info )
385	$(info Built-in Backends:)
386	$(info   $(BACKENDS_BUILTIN))
387	$(info )
388	$(info Additional Backends:)
389	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
390	$(info )
391	$(info -----------------------------------------)
392	$(info )
393	@true
394
395info:
396	$(info -----------------------------------------)
397	$(info |     ___ __    ______________________  |)
398	$(info |    / (_) /_  / ____/ ____/ ____/ __ \ |)
399	$(info |   / / / __ \/ /   / __/ / __/ / / / / |)
400	$(info |  / / / /_/ / /___/ /___/ /___/ /_/ /  |)
401	$(info | /_/_/_.___/\____/_____/_____/_____/   |)
402	$(info -----------------------------------------)
403	$(info )
404	$(info -----------------------------------------)
405	$(info )
406	$(info Built-in Backends:)
407	$(info   $(BACKENDS_BUILTIN))
408	$(info )
409	$(info Additional Backends:)
410	$(info   $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
411	$(info )
412	$(info -----------------------------------------)
413	$(info )
414	$(info Compiler Flags:)
415	$(info CC            = $(CC))
416	$(info CXX           = $(CXX))
417	$(info FC            = $(FC))
418	$(info CPPFLAGS      = $(CPPFLAGS))
419	$(info CFLAGS        = $(CFLAGS))
420	$(info CXXFLAGS      = $(CXXFLAGS))
421	$(info FFLAGS        = $(FFLAGS))
422	$(info NVCCFLAGS     = $(NVCCFLAGS))
423	$(info HIPCCFLAGS    = $(HIPCCFLAGS))
424	$(info SYCLFLAGS     = $(SYCLFLAGS))
425	$(info CEED_LDFLAGS  = $(CEED_LDFLAGS))
426	$(info CEED_LDLIBS   = $(CEED_LDLIBS))
427	$(info AR            = $(AR))
428	$(info ARFLAGS       = $(ARFLAGS))
429	$(info OPT           = $(OPT))
430	$(info AFLAGS        = $(AFLAGS))
431	$(info ASAN          = $(or $(ASAN),(empty)))
432	$(info VERBOSE       = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
433	$(info )
434	$(info -----------------------------------------)
435	$(info )
436	$(info Backend Dependencies:)
437	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS)))
438	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS)))
439	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS)))
440	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
441	$(info ROCM_DIR      = $(ROCM_DIR)$(call backend_status,$(HIP_BACKENDS)))
442	$(info SYCL_DIR      = $(SYCL_DIR)$(call backend_status,$(SYCL_BACKENDS)))
443	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS)))
444	$(info )
445	$(info -----------------------------------------)
446	$(info )
447	$(info Example Dependencies:)
448	$(info MFEM_DIR      = $(MFEM_DIR))
449	$(info NEK5K_DIR     = $(NEK5K_DIR))
450	$(info PETSC_DIR     = $(PETSC_DIR))
451	$(info DEAL_II_DIR   = $(DEAL_II_DIR))
452	$(info )
453	$(info -----------------------------------------)
454	$(info )
455	$(info Install Options:)
456	$(info prefix        = $(prefix))
457	$(info includedir    = $(value includedir))
458	$(info libdir        = $(value libdir))
459	$(info pkgconfigdir  = $(value pkgconfigdir))
460	$(info )
461	$(info -----------------------------------------)
462	$(info )
463	$(info Git:)
464	$(info describe      = $(GIT_DESCRIBE))
465	$(info )
466	$(info -----------------------------------------)
467	@true
468
469info-backends:
470	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
471	@true
472
473info-backends-all:
474	$(info make: 'lib' with backends: $(BACKENDS))
475	@true
476
477
478# ------------------------------------------------------------
479# Backends
480# ------------------------------------------------------------
481
482# Standard Backends
483libceed.c += $(ref.c)
484libceed.c += $(blocked.c)
485libceed.c += $(opt.c)
486
487# Memcheck Backends
488MEMCHK_STATUS   = Disabled
489MEMCHK         := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
490MEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
491ifeq ($(MEMCHK),1)
492  MEMCHK_STATUS = Enabled
493  libceed.c += $(ceedmemcheck.c)
494  BACKENDS_MAKE += $(MEMCHK_BACKENDS)
495endif
496
497# AVX Backeds
498AVX_STATUS   = Disabled
499AVX_FLAG    := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
500AVX         := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS:-M%=) -v -E -x c /dev/null 2>&1))
501AVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked
502ifneq ($(AVX),)
503  AVX_STATUS = Enabled
504  libceed.c += $(avx.c)
505  BACKENDS_MAKE += $(AVX_BACKENDS)
506endif
507
508# Collect list of libraries and paths for use in linking and pkg-config
509PKG_LIBS =
510# Stubs that will not be RPATH'd
511PKG_STUBS_LIBS =
512
513# libXSMM Backends
514XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
515ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
516  PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm
517  MKL ?=
518  ifeq (,$(MKL)$(MKLROOT))
519    BLAS_LIB ?= -lblas -ldl
520  else
521    ifneq ($(MKLROOT),)
522      # Some installs put everything inside an intel64 subdirectory, others not
523      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
524      MKL_LINK = -L$(MKL_LIBDIR)
525    endif
526    BLAS_LIB ?= $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state
527  endif
528  PKG_LIBS += $(BLAS_LIB)
529  libceed.c += $(xsmm.c)
530  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
531  BACKENDS_MAKE += $(XSMM_BACKENDS)
532endif
533
534# CUDA Backends
535ifneq ($(CUDA_DIR),)
536  CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64 lib/x86_64-linux-gnu,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
537  CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
538endif
539CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
540CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
541ifneq ($(CUDA_LIB_DIR),)
542  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
543  PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas
544  PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS)
545  LIBCEED_CONTAINS_CXX = 1
546  libceed.c     += interface/ceed-cuda.c
547  libceed.c     += $(cuda-all.c)
548  libceed.cpp   += $(cuda-all.cpp)
549  libceed.cu    += $(cuda-all.cu)
550  BACKENDS_MAKE += $(CUDA_BACKENDS)
551endif
552
553# HIP Backends
554HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(ROCM_DIR)/$d/libamdhip64.${SO_EXT}))
555HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
556HIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen
557ifneq ($(HIP_LIB_DIR),)
558  HIPCONFIG_CPPFLAGS := $(subst =,,$(shell $(ROCM_DIR)/bin/hipconfig -C))
559  $(hip-all.c:%.c=$(OBJDIR)/%.o) $(hip-all.c:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
560  ifneq ($(CXX), $(HIPCC))
561    $(hip-all.cpp:%.cpp=$(OBJDIR)/%.o) $(hip-all.cpp:%=%.tidy): CPPFLAGS += $(HIPCONFIG_CPPFLAGS)
562  endif
563  PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas
564  LIBCEED_CONTAINS_CXX = 1
565  libceed.c     += $(hip-all.c)
566  libceed.cpp   += $(hip-all.cpp)
567  libceed.hip   += $(hip-all.hip)
568  BACKENDS_MAKE += $(HIP_BACKENDS)
569endif
570
571# SYCL Backends
572SYCL_BACKENDS = /gpu/sycl/ref /gpu/sycl/shared /gpu/sycl/gen
573ifneq ($(SYCL_DIR),)
574  SYCL_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(SYCL_DIR)/$d/libsycl.${SO_EXT}))
575  SYCL_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(SYCL_LIB_DIR))))
576endif
577ifneq ($(SYCL_LIB_DIR),)
578  PKG_LIBS += $(SYCL_FLAG) -lze_loader
579  LIBCEED_CONTAINS_CXX = 1
580  libceed.sycl  += $(sycl-core.cpp) $(sycl-ref.cpp) $(sycl-shared.cpp) $(sycl-gen.cpp)
581  BACKENDS_MAKE += $(SYCL_BACKENDS)
582endif
583
584# MAGMA Backends
585ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
586  MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas")
587  ifeq ($(MAGMA_ARCH), 0)  # CUDA MAGMA
588    ifneq ($(CUDA_LIB_DIR),)
589      cuda_link = $(if $(STATIC),,-Wl,-rpath,$(CUDA_LIB_DIR)) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
590      omp_link = -fopenmp
591      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
592      magma_link_shared = -L$(MAGMA_DIR)/lib $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
593      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
594      PKG_LIBS += $(magma_link)
595      libceed.c   += $(magma.c)
596      libceed.cpp += $(magma.cpp)
597      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
598      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
599      MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det
600    endif
601  else  # HIP MAGMA
602    ifneq ($(HIP_LIB_DIR),)
603      omp_link = -fopenmp
604      hip_link = $(if $(STATIC),,-Wl,-rpath,$(HIP_LIB_DIR)) -L$(HIP_LIB_DIR) -lhipblas -lhipsparse -lamdhip64
605      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link)
606      magma_link_shared = -L$(MAGMA_DIR)/lib $(hip_link) $(omp_link) $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
607      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
608      PKG_LIBS += $(magma_link)
609      libceed.c   += $(magma.c)
610      libceed.cpp += $(magma.cpp)
611      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
612      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += $(HIPCONFIG_CPPFLAGS) -I$(MAGMA_DIR)/include -I$(ROCM_DIR)/include -DCEED_MAGMA_USE_HIP -DADD_
613      MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det
614    endif
615  endif
616  LIBCEED_CONTAINS_CXX = 1
617  BACKENDS_MAKE += $(MAGMA_BACKENDS)
618endif
619
620BACKENDS ?= $(BACKENDS_MAKE)
621export BACKENDS
622
623
624# ------------------------------------------------------------
625# Linker Flags
626# ------------------------------------------------------------
627
628_pkg_ldflags = $(filter -L%,$(PKG_LIBS))
629_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS))
630$(libceeds) : CEED_LDFLAGS += $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
631$(libceeds) : CEED_LDLIBS += $(_pkg_ldlibs)
632ifeq ($(STATIC),1)
633  $(examples) $(tests) : CEED_LDFLAGS += $(EM_LDFLAGS) $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
634  $(examples) $(tests) : CEED_LDLIBS += $(_pkg_ldlibs)
635endif
636
637pkgconfig-libs-private = $(PKG_LIBS)
638ifeq ($(LIBCEED_CONTAINS_CXX),1)
639  $(libceeds) : LINK = $(CXX)
640  ifeq ($(STATIC),1)
641    $(examples) $(tests) : CEED_LDLIBS += $(LIBCXX)
642    pkgconfig-libs-private += $(LIBCXX)
643  endif
644endif
645
646
647# ------------------------------------------------------------
648# Building core library components
649# ------------------------------------------------------------
650
651# File names *-weak.c contain weak symbol definitions, which must be listed last
652# when creating shared or static libraries.
653weak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1))
654
655libceed.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)
656$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
657$(libceed.o): | info-backends
658$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
659	$(call quiet,LINK) $(LDFLAGS) $(CEED_LDFLAGS) -shared -o $@ $^ $(CEED_LDLIBS) $(LDLIBS)
660
661$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
662	$(call quiet,AR) $(ARFLAGS) $@ $^
663
664$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
665	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $(abspath $<)
666
667$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
668	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
669
670$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
671	$(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<)
672
673$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
674	$(call quiet,HIPCC) $(CPPFLAGS) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
675
676$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
677	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
678
679$(OBJDIR)/%.o : $(CURDIR)/%.sycl.cpp | $$(@D)/.DIR
680	$(call quiet,SYCLCXX) $(SYCLFLAGS) $(CPPFLAGS) -c -o $@ $(abspath $<)
681
682$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.c | $$(@D)/.DIR
683	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS) -I./tests/test-include
684
685$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.f90 | $$(@D)/.DIR
686	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
687
688$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.c | $$(@D)/.DIR
689	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
690
691$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.f90 | $$(@D)/.DIR
692	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
693
694
695# ------------------------------------------------------------
696# Building examples
697# ------------------------------------------------------------
698
699# deal.II
700# Note: Invoking deal.II's CMAKE build system here
701$(OBJDIR)/dealii-% : examples/deal.II/*.cc examples/deal.II/*.h $(libceed) | $$(@D)/.DIR
702	mkdir -p examples/deal.II/build
703	cmake -B examples/deal.II/build -S examples/deal.II -DDEAL_II_DIR=$(DEAL_II_DIR) -DCEED_DIR=$(PWD)
704	+$(call quiet,MAKE) -C examples/deal.II/build
705	cp examples/deal.II/build/$* $@
706
707# MFEM
708$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
709	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
710	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
711	cp examples/mfem/$* $@
712
713# Nek5000
714# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
715#       this single Nek bps file to be built in parallel with other examples,
716#       such as when calling `make prove-all -j2`.
717$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
718	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
719	mv examples/nek/build/bps $(OBJDIR)/bps
720	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
721
722# Rust QFunctions
723$(OBJDIR)/rustqfunctions-% : examples/rust-qfunctions/%.c $(libceed) | $$(@D)/.DIR
724	+$(MAKE) -C examples/rust-qfunctions CEED_DIR=`pwd`
725	cp examples/rust-qfunctions/$* $@
726
727# PETSc
728# Several executables have common utilities, but we can't build the utilities
729# from separate submake invocations because they'll compete with each
730# other/corrupt output. So we put it in this utility library, but we don't want
731# to manually list source dependencies up at this level, so we'll just always
732# call recursive make to check that this utility is up to date.
733examples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc)
734	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \
735	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F))
736
737$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR
738	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \
739	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
740	cp examples/petsc/$* $@
741
742# Fluid dynamics proxy application
743$(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
744	+$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \
745	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
746	cp examples/fluids/$* $@
747
748# Solid mechanics proxy application
749$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
750    examples/solids/problems/*.c examples/solids/src/*.c \
751    examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \
752    $(libceed) $(ceed.pc) | $$(@D)/.DIR
753	+$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \
754	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
755	cp examples/solids/$* $@
756
757examples      : $(allexamples)
758ceedexamples  : $(examples)
759nekexamples   : $(nekexamples)
760mfemexamples  : $(mfemexamples)
761petscexamples : $(petscexamples)
762
763rustqfunctionsexamples : $(rustqfunctionsexamples)
764
765external_examples := \
766	$(if $(MFEM_DIR),$(mfemexamples)) \
767	$(if $(PETSC_DIR),$(petscexamples)) \
768	$(if $(NEK5K_DIR),$(nekexamples)) \
769	$(if $(DEAL_II_DIR),$(dealiiexamples)) \
770	$(if $(PETSC_DIR),$(fluidsexamples)) \
771	$(if $(PETSC_DIR),$(solidsexamples)) \
772	$(if $(or $(RUST_QF),$(GPU_CLANG)),$(rustqfunctionsexamples))
773
774allexamples = $(examples) $(external_examples)
775
776$(examples) : $(libceed)
777$(tests) : $(libceed)
778$(tests) $(examples) : override LDFLAGS += $(if $(STATIC),,-Wl,-rpath,$(abspath $(LIBDIR))) -L$(LIBDIR)
779
780
781# ------------------------------------------------------------
782# Testing
783# ------------------------------------------------------------
784
785# Set number processes for testing
786NPROC_TEST ?= 1
787export NPROC_TEST
788
789# Set pool size for testing
790NPROC_POOL ?= 1
791export NPROC_POOL
792
793run-% : $(OBJDIR)/%
794	@$(PYTHON) tests/junit.py --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%)
795
796# The test and prove targets can be controlled via pattern searches.  The
797# default is to run tests and those examples that have no external dependencies.
798# Examples of finer grained control:
799#
800#   make test search='petsc mfem'      # PETSc and MFEM examples
801#   make prove search='t3'             # t3xx series tests
802#   make junit search='ex petsc'       # core ex* and PETSc tests
803search ?= t ex
804realsearch = $(search:%=%%)
805matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
806subsearch ?= .*
807JUNIT_BATCH ?= ''
808
809# Test core libCEED
810test : $(matched:$(OBJDIR)/%=run-%)
811
812# Run test target in parallel
813tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
814# CPU C tests only for backend %
815ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
816
817# Testing with TAP format
818# https://testanything.org/tap-specification.html
819prove : $(matched)
820	$(info Testing backends: $(BACKENDS))
821	$(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py' $(matched:$(OBJDIR)/%=%) :: --mode tap --ceed-backends $(BACKENDS) --nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)'
822# Run prove target in parallel
823prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
824
825prove-all :
826	+$(MAKE) prove realsearch=%
827
828junit-% : $(OBJDIR)/%
829	@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)/%=%)
830
831junit : $(matched:$(OBJDIR)/%=junit-%)
832
833all: $(alltests)
834
835# Benchmarks
836allbenchmarks = petsc-bps
837bench_targets = $(addprefix bench-,$(allbenchmarks))
838.PHONY: $(bench_targets) benchmarks
839$(bench_targets): bench-%: $(OBJDIR)/%
840	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
841benchmarks: $(bench_targets)
842
843$(ceed.pc) : pkgconfig-prefix = $(abspath .)
844$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
845.INTERMEDIATE : $(OBJDIR)/ceed.pc
846%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
847	@$(SED) \
848	    -e "s:%prefix%:$(pkgconfig-prefix):" \
849	    -e "s:%opt%:$(OPT):" \
850	    -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@
851
852GIT_DESCRIBE = $(shell git -c safe.directory=$PWD describe --always --dirty 2>/dev/null || printf "unknown\n")
853
854$(OBJDIR)/interface/ceed-config.o: Makefile
855$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_GIT_VERSION="\"$(GIT_DESCRIBE)\""
856$(OBJDIR)/interface/ceed-config.o: CONFIGFLAGS += -DCEED_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
857
858$(OBJDIR)/interface/ceed-jit-source-root-default.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath ./include)/\""
859$(OBJDIR)/interface/ceed-jit-source-root-install.o : CPPFLAGS += -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"$(abspath $(includedir))/\""
860
861
862# ------------------------------------------------------------
863# Installation
864# ------------------------------------------------------------
865
866install : $(libceed) $(OBJDIR)/ceed.pc
867	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
868	  "$(includedir)/ceed/" "$(includedir)/ceed/jit-source/"\
869	  "$(includedir)/ceed/jit-source/cuda/" "$(includedir)/ceed/jit-source/hip/"\
870	  "$(includedir)/ceed/jit-source/gallery/" "$(includedir)/ceed/jit-source/magma/"\
871	  "$(includedir)/ceed/jit-source/sycl/" "$(libdir)" "$(pkgconfigdir)")
872	$(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/"
873	$(INSTALL_DATA) include/ceed/deprecated.h "$(DESTDIR)$(includedir)/ceed/"
874	$(INSTALL_DATA) include/ceed/types.h "$(DESTDIR)$(includedir)/ceed/"
875	$(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/"
876	$(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/"
877	$(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/"
878	$(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/"
879	$(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/"
880	$(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/"
881	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
882	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
883	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
884	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
885	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/cuda/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/cuda/"
886	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
887	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"
888	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/magma/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/magma/"
889	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/sycl/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/sycl/"
890
891
892# ------------------------------------------------------------
893# Cleaning
894# ------------------------------------------------------------
895
896cln clean :
897	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
898	$(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
899	$(call quiet,MAKE) -C python/tests clean
900	$(RM) benchmarks/*output.txt
901	$(RM) -rf temp
902
903distclean : clean
904	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
905
906
907# ------------------------------------------------------------
908# Documentation
909# ------------------------------------------------------------
910
911DOXYGEN ?= doxygen
912
913doxygen :
914	$(DOXYGEN) -q Doxyfile
915
916doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
917	make -C doc/sphinx $*
918
919doc : doc-html
920
921
922# ------------------------------------------------------------
923# Linting utilities
924# ------------------------------------------------------------
925
926# Style/Format
927CLANG_FORMAT      ?= clang-format
928CLANG_FORMAT_OPTS += -style=file -i
929AUTOPEP8          ?= autopep8
930AUTOPEP8_OPTS     += --in-place --aggressive --max-line-length 120
931
932format.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'))
933format.py := $(filter-out tests/junit-xml/junit_xml/__init__.py, $(shell git ls-files '*.py'))
934format.ot := $(filter-out doc/sphinx/source/CODE_OF_CONDUCT.md doc/sphinx/source/CONTRIBUTING.md, $(shell git ls-files '*.md' '*.f90'))
935
936format-c  :
937	$(CLANG_FORMAT) $(CLANG_FORMAT_OPTS) $(format.ch)
938
939format-py :
940	$(AUTOPEP8) $(AUTOPEP8_OPTS) $(format.py)
941
942format-ot:
943	@$(SED) -r 's/\s+$$//' -i $(format.ot)
944
945format    : format-c format-py format-ot
946
947# Vermin - python version requirements
948VERMIN            ?= vermin
949VERMIN_OPTS       += -t=3.8- --violations
950
951vermin    :
952	$(VERMIN) $(VERMIN_OPTS) $(format.py)
953
954# Tidy
955CLANG_TIDY ?= clang-tidy
956
957%.c.tidy : %.c
958	$(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)))\""
959
960%.cpp.tidy : %.cpp
961	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include
962
963tidy-c   : $(libceed.c:%=%.tidy)
964tidy-cpp : $(libceed.cpp:%=%.tidy)
965
966tidy : tidy-c tidy-cpp
967
968# Include-What-You-Use
969ifneq ($(wildcard ../iwyu/*),)
970  IWYU_DIR ?= ../iwyu
971  IWYU_CC  ?= $(IWYU_DIR)/build/bin/include-what-you-use
972endif
973iwyu :
974	$(MAKE) -B CC=$(IWYU_CC)
975
976
977# ------------------------------------------------------------
978# Variable printing for debugging
979# ------------------------------------------------------------
980
981print :
982	@echo $(VAR)=$($(VAR))
983
984print-% :
985	$(info [ variable name]: $*)
986	$(info [        origin]: $(origin $*))
987	$(info [        flavor]: $(flavor $*))
988	$(info [         value]: $(value $*))
989	$(info [expanded value]: $($*))
990	$(info )
991	@true
992
993
994# ------------------------------------------------------------
995# Configuration caching
996# ------------------------------------------------------------
997
998# "make configure" detects any variables passed on the command line or
999# previously set in config.mk, caching them in config.mk as simple
1000# (:=) variables.  Variables set in config.mk or on the command line
1001# take precedence over the defaults provided in the file.  Typical
1002# usage:
1003#
1004#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
1005#   make
1006#   make prove
1007#
1008# The values in the file can be updated by passing them on the command
1009# line, e.g.,
1010#
1011#   make configure CC=/path/to/other/clang
1012
1013# All variables to consider for caching
1014CONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \
1015  OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS SYCLFLAGS \
1016  AR ARFLAGS LDFLAGS LDLIBS LIBCXX SED \
1017  MAGMA_DIR XSMM_DIR CUDA_DIR CUDA_ARCH MFEM_DIR PETSC_DIR NEK5K_DIR ROCM_DIR HIP_ARCH SYCL_DIR
1018
1019# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
1020# was set on the command line or in config.mk (where it will appear as
1021# a simple variable).
1022needs_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
1023
1024configure :
1025	$(file > $(CONFIG))
1026	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
1027	@echo "Configuration cached in $(CONFIG):"
1028	@cat $(CONFIG)
1029
1030
1031# ------------------------------------------------------------
1032# Building Python wheels for deployment
1033# ------------------------------------------------------------
1034
1035wheel : export MARCHFLAG = -march=generic
1036wheel : export WHEEL_PLAT = manylinux2010_x86_64
1037wheel :
1038	docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \
1039	  -e MARCHFLAG -e WHEEL_PLAT \
1040	  quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh
1041
1042# ------------------------------------------------------------
1043# Phony targets
1044# ------------------------------------------------------------
1045
1046# These targets are not files but rather commands to run
1047.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
1048
1049
1050# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container
1051-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d))
1052