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