xref: /libCEED/Makefile (revision 437c7c9068f3a84dadcfd91d5007d58f42fe2307)
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
142OPT    ?= -O $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
143CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR))
144CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR))
145LIBCXX ?= -lstdc++
146NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC
147ifneq ($(CUDA_ARCH),)
148  NVCCFLAGS += -arch=$(CUDA_ARCH)
149endif
150HIPCCFLAGS ?= $(filter-out $(OMP_SIMD_FLAG),$(OPT)) -fPIC -munsafe-fp-atomics
151ifneq ($(HIP_ARCH),)
152  HIPCCFLAGS += --amdgpu-target=$(HIP_ARCH)
153endif
154FFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
155
156ifeq ($(COVERAGE), 1)
157  CFLAGS += --coverage
158  CXXFLAGS += --coverage
159  CEED_LDFLAGS += --coverage
160endif
161
162CFLAGS += $(if $(ASAN),$(AFLAGS))
163FFLAGS += $(if $(ASAN),$(AFLAGS))
164CEED_LDFLAGS += $(if $(ASAN),$(AFLAGS))
165CPPFLAGS += -I./include
166CEED_LDLIBS = -lm
167OBJDIR := build
168for_install := $(filter install,$(MAKECMDGOALS))
169LIBDIR := $(if $(for_install),$(OBJDIR),lib)
170
171
172# Installation variables
173prefix ?= /usr/local
174bindir = $(prefix)/bin
175libdir = $(prefix)/lib
176includedir = $(prefix)/include
177pkgconfigdir = $(libdir)/pkgconfig
178INSTALL = install
179INSTALL_PROGRAM = $(INSTALL)
180INSTALL_DATA = $(INSTALL) -m644
181
182# Get number of processors of the machine
183NPROCS := $(shell getconf _NPROCESSORS_ONLN)
184# prepare make options to run in parallel
185MFLAGS := -j $(NPROCS) --warn-undefined-variables \
186                       --no-print-directory --no-keep-going
187
188PYTHON ?= python3
189PROVE ?= prove
190PROVE_OPTS ?= -j $(NPROCS)
191DARWIN := $(filter Darwin,$(shell uname -s))
192SO_EXT := $(if $(DARWIN),dylib,so)
193
194ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
195libceed.so := $(LIBDIR)/libceed.$(SO_EXT)
196libceed.a := $(LIBDIR)/libceed.a
197libceed := $(if $(STATIC),$(libceed.a),$(libceed.so))
198CEED_LIBS = -lceed
199libceed.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))
200gallery.c := $(wildcard gallery/*/ceed*.c)
201libceed.c += $(gallery.c)
202libceeds = $(libceed)
203BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
204BACKENDS_MAKE := $(BACKENDS_BUILTIN)
205TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
206
207# Tests
208tests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
209tests.f   := $(if $(FC),$(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90)))
210tests     := $(tests.c:tests/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
211ctests    := $(tests)
212tests     += $(tests.f:tests/%.f90=$(OBJDIR)/%$(EXE_SUFFIX))
213# Examples
214examples.c := $(sort $(wildcard examples/ceed/*.c))
215examples.f := $(if $(FC),$(sort $(wildcard examples/ceed/*.f)))
216examples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%$(EXE_SUFFIX))
217examples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%$(EXE_SUFFIX))
218# MFEM Examples
219mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
220mfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
221# Nek5K Examples
222nekexamples  := $(OBJDIR)/nek-bps
223# PETSc Examples
224petscexamples.c := $(wildcard examples/petsc/*.c)
225petscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
226# Fluid Dynamics Examples
227fluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
228fluidsexamples  := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
229# Solid Mechanics Examples
230solidsexamples.c := $(sort $(wildcard examples/solids/*.c))
231solidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
232
233# Backends/[ref, blocked, memcheck, opt, avx, occa, magma]
234ref.c          := $(sort $(wildcard backends/ref/*.c))
235blocked.c      := $(sort $(wildcard backends/blocked/*.c))
236ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
237opt.c          := $(sort $(wildcard backends/opt/*.c))
238avx.c          := $(sort $(wildcard backends/avx/*.c))
239xsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
240cuda.c         := $(sort $(wildcard backends/cuda/*.c))
241cuda.cpp       := $(sort $(wildcard backends/cuda/*.cpp))
242cuda-ref.c     := $(sort $(wildcard backends/cuda-ref/*.c))
243cuda-ref.cpp   := $(sort $(wildcard backends/cuda-ref/*.cpp))
244cuda-ref.cu    := $(sort $(wildcard backends/cuda-ref/kernels/*.cu))
245cuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
246cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/kernels/*.cu))
247cuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
248cuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
249cuda-gen.cu    := $(sort $(wildcard backends/cuda-gen/kernels/*.cu))
250occa.cpp       := $(sort $(shell find backends/occa -type f -name *.cpp))
251magma.c        := $(sort $(wildcard backends/magma/*.c))
252magma.cpp      := $(sort $(wildcard backends/magma/*.cpp))
253magma.cu       := $(sort $(wildcard backends/magma/kernels/cuda/*.cu))
254magma.hip      := $(sort $(wildcard backends/magma/kernels/hip/*.hip.cpp))
255hip.c          := $(sort $(wildcard backends/hip/*.c))
256hip.cpp        := $(sort $(wildcard backends/hip/*.cpp))
257hip-ref.c      := $(sort $(wildcard backends/hip-ref/*.c))
258hip-ref.cpp    := $(sort $(wildcard backends/hip-ref/*.cpp))
259hip-ref.hip    := $(sort $(wildcard backends/hip-ref/kernels/*.hip.cpp))
260hip-shared.c   := $(sort $(wildcard backends/hip-shared/*.c))
261hip-gen.c      := $(sort $(wildcard backends/hip-gen/*.c))
262hip-gen.cpp    := $(sort $(wildcard backends/hip-gen/*.cpp))
263
264# Quiet, color output
265quiet ?= $($(1))
266
267# Cancel built-in and old-fashioned implicit rules which we don't use
268.SUFFIXES:
269
270.SECONDEXPANSION: # to expand $$(@D)/.DIR
271
272%/.DIR :
273	@mkdir -p $(@D)
274	@touch $@
275
276.PRECIOUS: %/.DIR
277
278lib: $(libceed) $(ceed.pc)
279# run 'lib' target in parallel
280par:;@$(MAKE) $(MFLAGS) V=$(V) lib
281backend_status = $(if $(filter $1,$(BACKENDS_MAKE)), [backends: $1], [not found])
282info:
283	$(info ------------------------------------)
284	$(info CC            = $(CC))
285	$(info CXX           = $(CXX))
286	$(info FC            = $(FC))
287	$(info CPPFLAGS      = $(CPPFLAGS))
288	$(info CFLAGS        = $(value CFLAGS))
289	$(info CXXFLAGS      = $(value CXXFLAGS))
290	$(info FFLAGS        = $(value FFLAGS))
291	$(info NVCCFLAGS     = $(value NVCCFLAGS))
292	$(info HIPCCFLAGS    = $(value HIPCCFLAGS))
293	$(info CEED_LDFLAGS  = $(value CEED_LDFLAGS))
294	$(info CEED_LDLIBS   = $(value CEED_LDLIBS))
295	$(info AR            = $(AR))
296	$(info ARFLAGS       = $(ARFLAGS))
297	$(info OPT           = $(OPT))
298	$(info AFLAGS        = $(AFLAGS))
299	$(info ASAN          = $(or $(ASAN),(empty)))
300	$(info VERBOSE       = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
301	$(info ------------------------------------)
302	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,$(MEMCHK_BACKENDS)))
303	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,$(AVX_BACKENDS)))
304	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,$(XSMM_BACKENDS)))
305	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,$(OCCA_BACKENDS)))
306	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,$(MAGMA_BACKENDS)))
307	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
308	$(info ROCM_DIR       = $(ROCM_DIR)$(call backend_status,$(HIP_BACKENDS)))
309	$(info ------------------------------------)
310	$(info MFEM_DIR      = $(MFEM_DIR))
311	$(info NEK5K_DIR     = $(NEK5K_DIR))
312	$(info PETSC_DIR     = $(PETSC_DIR))
313	$(info ------------------------------------)
314	$(info prefix        = $(prefix))
315	$(info includedir    = $(value includedir))
316	$(info libdir        = $(value libdir))
317	$(info pkgconfigdir  = $(value pkgconfigdir))
318	$(info ------------------------------------)
319	@true
320info-backends:
321	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
322	@true
323info-backends-all:
324	$(info make: 'lib' with backends: $(filter-out $(TEST_BACKENDS),$(BACKENDS)))
325	@true
326
327$(libceed.so) : CEED_LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed.so)))
328
329# Standard Backends
330libceed.c += $(ref.c)
331libceed.c += $(blocked.c)
332libceed.c += $(opt.c)
333
334# Memcheck Backend
335MEMCHK_STATUS = Disabled
336MEMCHK := $(shell echo "$(HASH)include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
337MEMCHK_BACKENDS = /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
338ifeq ($(MEMCHK),1)
339  MEMCHK_STATUS = Enabled
340  libceed.c += $(ceedmemcheck.c)
341  BACKENDS_MAKE += $(MEMCHK_BACKENDS)
342endif
343
344# AVX Backed
345AVX_STATUS = Disabled
346AVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
347AVX := $(filter $(AVX_FLAG),$(shell $(CC) $(CFLAGS:-M%=) -v -E -x c /dev/null 2>&1))
348AVX_BACKENDS = /cpu/self/avx/serial /cpu/self/avx/blocked
349ifneq ($(AVX),)
350  AVX_STATUS = Enabled
351  libceed.c += $(avx.c)
352  BACKENDS_MAKE += $(AVX_BACKENDS)
353endif
354
355# Collect list of libraries and paths for use in linking and pkg-config
356PKG_LIBS =
357# Stubs that will not be RPATH'd
358PKG_STUBS_LIBS =
359
360# libXSMM Backends
361XSMM_BACKENDS = /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
362ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
363  PKG_LIBS += -L$(abspath $(XSMM_DIR))/lib -lxsmm -ldl
364  MKL ?=
365  ifeq (,$(MKL)$(MKLROOT))
366    BLAS_LIB = -lblas
367  else
368    ifneq ($(MKLROOT),)
369      # Some installs put everything inside an intel64 subdirectory, others not
370      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
371      MKL_LINK = -L$(MKL_LIBDIR)
372      PKG_LIB_DIRS += $(MKL_LIBDIR)
373    endif
374    BLAS_LIB = $(MKL_LINK) -Wl,--push-state,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -Wl,--pop-state
375  endif
376  PKG_LIBS += $(BLAS_LIB)
377  libceed.c += $(xsmm.c)
378  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
379  BACKENDS_MAKE += $(XSMM_BACKENDS)
380endif
381
382# OCCA Backends
383OCCA_BACKENDS = /cpu/self/occa
384ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
385  OCCA_MODES := $(shell LD_LIBRARY_PATH=$(OCCA_DIR)/lib $(OCCA_DIR)/bin/occa modes)
386  OCCA_BACKENDS += $(if $(filter OpenMP,$(OCCA_MODES)),/cpu/openmp/occa)
387  OCCA_BACKENDS += $(if $(filter dpcpp,$(OCCA_MODES)),/gpu/dpcpp/occa)
388  OCCA_BACKENDS += $(if $(filter OpenCL,$(OCCA_MODES)),/gpu/opencl/occa)
389  OCCA_BACKENDS += $(if $(filter HIP,$(OCCA_MODES)),/gpu/hip/occa)
390  OCCA_BACKENDS += $(if $(filter CUDA,$(OCCA_MODES)),/gpu/cuda/occa)
391
392  $(libceeds) : CPPFLAGS += -I$(OCCA_DIR)/include
393  PKG_LIBS += -L$(abspath $(OCCA_DIR))/lib -locca
394  LIBCEED_CONTAINS_CXX = 1
395  libceed.cpp += $(occa.cpp)
396  BACKENDS_MAKE += $(OCCA_BACKENDS)
397endif
398
399# CUDA Backends
400ifneq ($(CUDA_DIR),)
401	CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64 lib/x86_64-linux-gnu,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
402	CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
403endif
404CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
405CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/shared /gpu/cuda/gen
406ifneq ($(CUDA_LIB_DIR),)
407  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
408  PKG_LIBS += -L$(abspath $(CUDA_LIB_DIR)) -lcudart -lnvrtc -lcuda -lcublas
409  PKG_STUBS_LIBS += -L$(CUDA_LIB_DIR_STUBS)
410  LIBCEED_CONTAINS_CXX = 1
411  libceed.c     += interface/ceed-cuda.c
412  libceed.c     += $(cuda.c) $(cuda-ref.c) $(cuda-shared.c) $(cuda-gen.c)
413  libceed.cpp   += $(cuda.cpp) $(cuda-ref.cpp) $(cuda-gen.cpp)
414  libceed.cu    += $(cuda-ref.cu) $(cuda-shared.cu) $(cuda-gen.cu)
415  BACKENDS_MAKE += $(CUDA_BACKENDS)
416endif
417
418# HIP Backends
419HIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(ROCM_DIR)/$d/libamdhip64.${SO_EXT}))
420HIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
421HIP_BACKENDS = /gpu/hip/ref /gpu/hip/shared /gpu/hip/gen
422ifneq ($(HIP_LIB_DIR),)
423  $(libceeds) : HIPCCFLAGS += -I./include
424  ifneq ($(CXX), $(HIPCC))
425    CPPFLAGS += $(subst =,,$(shell $(ROCM_DIR)/bin/hipconfig -C))
426  endif
427  $(libceeds) : CPPFLAGS += -I$(ROCM_DIR)/include
428  PKG_LIBS += -L$(abspath $(HIP_LIB_DIR)) -lamdhip64 -lhipblas
429  LIBCEED_CONTAINS_CXX = 1
430  libceed.c     += interface/ceed-hip.c
431  libceed.c     += $(hip.c) $(hip-ref.c) $(hip-shared.c) $(hip-gen.c)
432  libceed.cpp   += $(hip.cpp) $(hip-ref.cpp) $(hip-gen.cpp)
433  libceed.hip   += $(hip-ref.hip)
434  BACKENDS_MAKE += $(HIP_BACKENDS)
435endif
436
437# MAGMA Backend
438ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
439  MAGMA_ARCH=$(shell nm -g $(MAGMA_DIR)/lib/libmagma.* | grep -c "hipblas")
440  ifeq ($(MAGMA_ARCH), 0) #CUDA MAGMA
441    ifneq ($(CUDA_LIB_DIR),)
442      cuda_link = $(if $(STATIC),,-Wl,-rpath,$(CUDA_LIB_DIR)) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
443      omp_link = -fopenmp
444      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
445      magma_link_shared = -L$(MAGMA_DIR)/lib $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
446      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
447      PKG_LIBS += $(magma_link)
448      libceed.c   += $(magma.c)
449      libceed.cpp += $(magma.cpp)
450      libceed.cu  += $(magma.cu)
451      $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
452      $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
453      $(magma.cu:%.cu=$(OBJDIR)/%.o) : CPPFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(CUDA_DIR)/include
454      MAGMA_BACKENDS = /gpu/cuda/magma /gpu/cuda/magma/det
455    endif
456  else  # HIP MAGMA
457    ifneq ($(HIP_LIB_DIR),)
458      HIP_LIB_DIR_MAGMA=$(ROCM_DIR)/lib
459      HIP_INC_DIR_MAGMA=$(ROCM_DIR)/include
460      omp_link = -fopenmp
461      hip_link = $(if $(STATIC),,-Wl,-rpath,$(HIP_LIB_DIR_MAGMA)) -L$(HIP_LIB_DIR_MAGMA) -lhipblas -lhipsparse -lamdhip64
462      magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(hip_link) $(omp_link)
463      magma_link_shared = -L$(MAGMA_DIR)/lib $(hip_link) $(omp_link) $(if $(STATIC),,-Wl,-rpath,$(abspath $(MAGMA_DIR)/lib)) -lmagma
464      magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
465      PKG_LIBS += $(magma_link)
466      libceed.c   += $(magma.c)
467      libceed.cpp += $(magma.cpp)
468      libceed.hip += $(magma.hip)
469      ifneq ($(CXX), $(HIPCC))
470        $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_INC_DIR_MAGMA)/include -DCEED_MAGMA_USE_HIP -DADD_
471        $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : CPPFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_INC_DIR_MAGMA)/include -DCEED_MAGMA_USE_HIP -DADD_
472      else
473        $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_INC_DIR_MAGMA)/include -DCEED_MAGMA_USE_HIP -DADD_
474        $(magma.cpp:%.cpp=$(OBJDIR)/%.o) $(magma.cpp:%=%.tidy) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(HIP_INC_DIR_MAGMA)/include -DCEED_MAGMA_USE_HIP -DADD_
475      endif
476      $(magma.hip:%.hip.cpp=$(OBJDIR)/%.o) : HIPCCFLAGS += -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(HIP_INC_DIR_MAGMA)/include -DCEED_MAGMA_USE_HIP -DADD_
477      MAGMA_BACKENDS = /gpu/hip/magma /gpu/hip/magma/det
478    endif
479  endif
480  LIBCEED_CONTAINS_CXX = 1
481  BACKENDS_MAKE += $(MAGMA_BACKENDS)
482endif
483
484BACKENDS ?= $(BACKENDS_MAKE)
485export BACKENDS
486
487_pkg_ldflags = $(filter -L%,$(PKG_LIBS))
488_pkg_ldlibs = $(filter-out -L%,$(PKG_LIBS))
489$(libceeds) : CEED_LDFLAGS += $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
490$(libceeds) : CEED_LDLIBS += $(_pkg_ldlibs)
491ifeq ($(STATIC),1)
492$(examples) $(tests) : CEED_LDFLAGS += $(EM_LDFLAGS) $(_pkg_ldflags) $(if $(STATIC),,$(_pkg_ldflags:-L%=-Wl,-rpath,%)) $(PKG_STUBS_LIBS)
493$(examples) $(tests) : CEED_LDLIBS += $(_pkg_ldlibs)
494endif
495
496pkgconfig-libs-private = $(PKG_LIBS)
497ifeq ($(LIBCEED_CONTAINS_CXX),1)
498  $(libceeds) : LINK = $(CXX)
499  ifeq ($(STATIC),1)
500    $(examples) $(tests) : CEED_LDLIBS += $(LIBCXX)
501	  pkgconfig-libs-private += $(LIBCXX)
502  endif
503endif
504
505# File names *-weak.c contain weak symbol definitions, which must be listed last
506# when creating shared or static libraries.
507weak_last = $(filter-out %-weak.o,$(1)) $(filter %-weak.o,$(1))
508
509libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o)
510$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
511$(libceed.o): | info-backends
512$(libceed.so) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
513	$(call quiet,LINK) $(LDFLAGS) $(CEED_LDFLAGS) -shared -o $@ $^ $(CEED_LDLIBS) $(LDLIBS)
514
515$(libceed.a) : $(call weak_last,$(libceed.o)) | $$(@D)/.DIR
516	$(call quiet,AR) $(ARFLAGS) $@ $^
517
518$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
519	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
520
521$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
522	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
523
524$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
525	$(call quiet,NVCC) $(filter-out -Wno-unused-function, $(CPPFLAGS)) $(NVCCFLAGS) -c -o $@ $(abspath $<)
526
527$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
528	$(call quiet,HIPCC) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
529
530$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.c | $$(@D)/.DIR
531	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
532
533$(OBJDIR)/%$(EXE_SUFFIX) : tests/%.f90 | $$(@D)/.DIR
534	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
535
536$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.c | $$(@D)/.DIR
537	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
538
539$(OBJDIR)/%$(EXE_SUFFIX) : examples/ceed/%.f | $$(@D)/.DIR
540	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(CEED_LDLIBS) $(LDLIBS)
541
542$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
543	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
544	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
545	cp examples/mfem/$* $@
546
547# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
548#       this single Nek bps file to be built in parallel with other examples,
549#       such as when calling `make prove-all -j2`.
550$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
551	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
552	mv examples/nek/build/bps $(OBJDIR)/bps
553	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
554
555# Several executables have common utilities, but we can't build the utilities
556# from separate submake invocations because they'll compete with each
557# other/corrupt output. So we put it in this utility library, but we don't want
558# to manually list source dependencies up at this level, so we'll just always
559# call recursive make to check that this utility is up to date.
560examples/petsc/libutils.a.PHONY: $(libceed) $(ceed.pc)
561	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` AR=$(AR) ARFLAGS=$(ARFLAGS) \
562	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $(basename $(@F))
563
564$(OBJDIR)/petsc-% : examples/petsc/%.c examples/petsc/libutils.a.PHONY $(libceed) $(ceed.pc) | $$(@D)/.DIR
565	+$(call quiet,MAKE) -C examples/petsc CEED_DIR=`pwd` \
566	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
567	cp examples/petsc/$* $@
568
569$(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
570	+$(call quiet,MAKE) -C examples/fluids CEED_DIR=`pwd` \
571	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
572	cp examples/fluids/$* $@
573
574$(OBJDIR)/solids-% : examples/solids/%.c examples/solids/%.h \
575    examples/solids/problems/*.c examples/solids/src/*.c \
576    examples/solids/include/*.h examples/solids/problems/*.h examples/solids/qfunctions/*.h \
577    $(libceed) $(ceed.pc) | $$(@D)/.DIR
578	+$(call quiet,MAKE) -C examples/solids CEED_DIR=`pwd` \
579	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
580	cp examples/solids/$* $@
581
582$(examples) : $(libceed)
583$(tests) : $(libceed)
584$(tests) $(examples) : override LDFLAGS += $(if $(STATIC),,-Wl,-rpath,$(abspath $(LIBDIR))) -L$(LIBDIR)
585
586run-% : $(OBJDIR)/%
587	@$(PYTHON) tests/junit.py --mode tap $(<:$(OBJDIR)/%=%)
588
589external_examples := \
590	$(if $(MFEM_DIR),$(mfemexamples)) \
591	$(if $(PETSC_DIR),$(petscexamples)) \
592	$(if $(NEK5K_DIR),$(nekexamples)) \
593	$(if $(PETSC_DIR),$(fluidsexamples)) \
594	$(if $(PETSC_DIR),$(solidsexamples))
595
596allexamples = $(examples) $(external_examples)
597
598# The test and prove targets can be controlled via pattern searches.  The
599# default is to run tests and those examples that have no external dependencies.
600# Examples of finer grained control:
601#
602#   make test search='petsc mfem'      # PETSc and MFEM examples
603#   make prove search='t3'             # t3xx series tests
604#   make junit search='ex petsc'       # core ex* and PETSc tests
605search ?= t ex
606realsearch = $(search:%=%%)
607matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
608
609# Test core libCEED
610test : $(matched:$(OBJDIR)/%=run-%)
611
612# Run test target in parallel
613tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
614# CPU C tests only for backend %
615ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
616
617prove : $(matched)
618	$(info Testing backends: $(BACKENDS))
619	$(PROVE) $(PROVE_OPTS) --exec 'tests/junit.py --mode tap' $(matched:$(OBJDIR)/%=%)
620# Run prove target in parallel
621prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
622
623prove-all :
624	+$(MAKE) prove realsearch=%
625
626junit-% : $(OBJDIR)/%
627	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
628
629junit : $(matched:$(OBJDIR)/%=junit-%)
630
631all: $(alltests)
632
633examples : $(allexamples)
634ceedexamples : $(examples)
635nekexamples : $(nekexamples)
636mfemexamples : $(mfemexamples)
637petscexamples : $(petscexamples)
638
639# Benchmarks
640allbenchmarks = petsc-bps
641bench_targets = $(addprefix bench-,$(allbenchmarks))
642.PHONY: $(bench_targets) benchmarks
643$(bench_targets): bench-%: $(OBJDIR)/%
644	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS_MAKE)" -r $(*).sh
645benchmarks: $(bench_targets)
646
647$(ceed.pc) : pkgconfig-prefix = $(abspath .)
648$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
649.INTERMEDIATE : $(OBJDIR)/ceed.pc
650%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
651	@$(SED) \
652	    -e "s:%prefix%:$(pkgconfig-prefix):" \
653	    -e "s:%libs_private%:$(pkgconfig-libs-private):" $< > $@
654
655$(OBJDIR)/interface/ceed-jit-source-root-default.o : CPPFLAGS += -DCEED_JIT_SOUCE_ROOT_DEFAULT="\"$(abspath ./include)/\""
656$(OBJDIR)/interface/ceed-jit-source-root-install.o : CPPFLAGS += -DCEED_JIT_SOUCE_ROOT_DEFAULT="\"$(abspath $(includedir))/\""
657
658install : $(libceed) $(OBJDIR)/ceed.pc
659	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
660	  "$(includedir)/ceed/" "$(includedir)/ceed/jit-source/"\
661	  "$(includedir)/ceed/jit-source/cuda/" "$(includedir)/ceed/jit-source/hip/"\
662	  "$(includedir)/ceed/jit-source/gallery/" "$(libdir)" "$(pkgconfigdir)")
663	$(INSTALL_DATA) include/ceed/ceed.h "$(DESTDIR)$(includedir)/ceed/"
664	$(INSTALL_DATA) include/ceed/types.h "$(DESTDIR)$(includedir)/ceed/"
665	$(INSTALL_DATA) include/ceed/ceed-f32.h "$(DESTDIR)$(includedir)/ceed/"
666	$(INSTALL_DATA) include/ceed/ceed-f64.h "$(DESTDIR)$(includedir)/ceed/"
667	$(INSTALL_DATA) include/ceed/fortran.h "$(DESTDIR)$(includedir)/ceed/"
668	$(INSTALL_DATA) include/ceed/backend.h "$(DESTDIR)$(includedir)/ceed/"
669	$(INSTALL_DATA) include/ceed/cuda.h "$(DESTDIR)$(includedir)/ceed/"
670	$(INSTALL_DATA) include/ceed/hip.h "$(DESTDIR)$(includedir)/ceed/"
671	$(INSTALL_DATA) include/ceed/hash.h "$(DESTDIR)$(includedir)/ceed/"
672	$(INSTALL_DATA) include/ceed/khash.h "$(DESTDIR)$(includedir)/ceed/"
673	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
674	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
675	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
676	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
677	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/cuda/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/cuda/"
678	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
679	$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"
680
681.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
682
683cln clean :
684	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
685	$(call quiet,MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
686	$(call quiet,MAKE) -C python/tests clean
687	$(RM) benchmarks/*output.txt
688
689distclean : clean
690	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
691
692# Documentation
693DOXYGEN ?= doxygen
694doxygen :
695	$(DOXYGEN) -q Doxyfile
696
697doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
698	make -C doc/sphinx $*
699
700doc : doc-html
701
702# Style/Format
703CLANG_FORMAT ?= clang-format
704
705FORMAT_OPTS += -style=file -i
706
707format.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), $(shell git ls-files *.[ch]pp *.[ch]))
708
709format-c  :
710	$(CLANG_FORMAT) $(FORMAT_OPTS) $(format.ch)
711
712AUTOPEP8 = autopep8
713format-py  : AUTOPEP8_ARGS = --in-place --aggressive
714format-py  :
715	@$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py python/tests/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py)
716
717format    : format-c format-py
718
719# Tidy
720CLANG_TIDY ?= clang-tidy
721
722%.c.tidy : %.c
723	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 -I$(CUDA_DIR)/include -I$(ROCM_DIR)/include -DCEED_JIT_SOUCE_ROOT_DEFAULT="\"$(abspath ./include)/\""
724
725%.cpp.tidy : %.cpp
726	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include -I$(ROCM_DIR)/include
727
728tidy-c   : $(libceed.c:%=%.tidy)
729tidy-cpp : $(libceed.cpp:%=%.tidy)
730
731tidy : tidy-c tidy-cpp
732
733ifneq ($(wildcard ../iwyu/*),)
734  IWYU_DIR ?= ../iwyu
735  IWYU_CC  ?= $(IWYU_DIR)/build/bin/include-what-you-use
736endif
737
738# IWYU
739iwyu : CC=$(IWYU_CC)
740iwyu : lib
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