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