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