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