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