xref: /libCEED/Makefile (revision cfb6011c9806ecc9346fa1da351e922dcf03717b)
10c784865Scamierjs# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20c784865Scamierjs# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30c784865Scamierjs# All Rights reserved. See files LICENSE and NOTICE for details.
40d9661cdSTzanio#
50d9661cdSTzanio# This file is part of CEED, a collection of benchmarks, miniapps, software
60d9661cdSTzanio# libraries and APIs for efficient high-order finite element and spectral
70d9661cdSTzanio# element discretizations for exascale applications. For more information and
80d9661cdSTzanio# source code availability see http://github.com/ceed.
90d9661cdSTzanio#
100d9661cdSTzanio# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d9661cdSTzanio# a collaborative effort of two U.S. Department of Energy organizations (Office
120d9661cdSTzanio# of Science and the National Nuclear Security Administration) responsible for
130d9661cdSTzanio# the planning and preparation of a capable exascale ecosystem, including
140d9661cdSTzanio# software, applications, hardware, advanced system engineering and early
150d9661cdSTzanio# testbed platforms, in support of the nation's exascale computing imperative.
160d9661cdSTzanio
17b0ab70ddSJed BrownCONFIG ?= config.mk
18b0ab70ddSJed Brown-include $(CONFIG)
191571c99dSValeria Barra
20dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
216ed738d9SJed Brown  CC = gcc
22dc753d40SJed Brownendif
23241a4b83SYohannifeq (,$(filter-out undefined default,$(origin CXX)))
24241a4b83SYohann  CXX = g++
25241a4b83SYohannendif
26dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
2781c9eb91SStan Tomov  FC = gfortran
28dc753d40SJed Brownendif
29241a4b83SYohannifeq (,$(filter-out undefined default,$(origin LINK)))
30241a4b83SYohann  LINK = $(CC)
31241a4b83SYohannendif
32196a75e4SJed BrownNVCC ?= $(CUDA_DIR)/bin/nvcc
333c83ce1dSJed BrownNVCC_CXX ?= $(CXX)
3430f4f45fSnbeamsHIPCC ?= $(HIP_DIR)/bin/hipcc
35e86995feScamierjs
363b56482dScamierjs# ASAN must be left empty if you don't want to use it
370a7eccc5ScamierjsASAN ?=
386850bcb5Scamierjs
39e86995feScamierjsLDFLAGS ?=
4032d74c32SThilina RathnayakeUNDERSCORE ?= 1
411b58aefaScamierjs
42f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory
43bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),)
449ba53df8Sjeremylt  MFEM_DIR ?= ../mfem
45f9fa8c39Sjeremyltendif
46f9fa8c39Sjeremylt
474d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
484d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
4986a4271fSThilina Rathnayake  NEK5K_DIR ?= $(abspath ../Nek5000)
504d1cd9fcSJeremy L Thompsonendif
5186a4271fSThilina Rathnayakeexport NEK5K_DIR
5286a4271fSThilina RathnayakeMPI ?= 1
5386a4271fSThilina Rathnayake
5486a4271fSThilina Rathnayake# CEED_DIR env for NEK5K testing
5586a4271fSThilina Rathnayakeexport CEED_DIR = $(abspath .)
564d1cd9fcSJeremy L Thompson
578d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
588d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
598d713cf6Sjeremylt
6012123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
617f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
62f797d7b2Scamierjs
635a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
64ab352fbeSnbeamsMAGMA_DIR ?= ../magma
655a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
66ab352fbeSnbeamsCUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
675a9ca9adSVeselin Dobrev               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
6830f4f45fSnbeamsHIP_DIR ?= /opt/rocm/hip
6982b77998SStan Tomov
702f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
712f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
722f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
732f4d9adbSJeremy L Thompsonendif
742f4d9adbSJeremy L Thompson
75bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
7612123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
77c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
7832d74c32SThilina Rathnayake
79c7f533e0SJed BrownCC_VENDOR := $(patsubst gcc%,gcc,$(firstword $(filter gcc% clang icc XL,$(shell $(CC) --version))))
8013d950b4SJed BrownFC_VENDOR := $(firstword $(filter GNU ifort XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion)))
8113d950b4SJed Brown
8213d950b4SJed Brown# Default extra flags by vendor
8313d950b4SJed BrownMARCHFLAG.gcc           := -march=native
8413d950b4SJed BrownMARCHFLAG.clang         := $(MARCHFLAG.gcc)
8513d950b4SJed BrownMARCHFLAG.icc           :=
8613d950b4SJed BrownOMP_SIMD_FLAG.gcc       := -fopenmp-simd
8713d950b4SJed BrownOMP_SIMD_FLAG.clang     := $(OMP_SIMD_FLAG.gcc)
8813d950b4SJed BrownOMP_SIMD_FLAG.icc       := -qopenmp-simd
8913d950b4SJed BrownOPT.gcc                 := -ffp-contract=fast
9013d950b4SJed BrownOPT.clang               := $(OPT.gcc)
9113d950b4SJed BrownCFLAGS.gcc              := -fPIC -std=c99 -Wall -Wextra -Wno-unused-parameter -MMD -MP
9213d950b4SJed BrownCFLAGS.clang            := $(CFLAGS.gcc)
9313d950b4SJed BrownCFLAGS.icc              := $(CFLAGS.gcc)
9413d950b4SJed BrownCFLAGS.XL               := -qpic -MMD
9513d950b4SJed BrownCXXFLAGS.gcc            := -fPIC -std=c++11 -Wall -Wextra -Wno-unused-parameter -MMD -MP
9613d950b4SJed BrownCXXFLAGS.clang          := $(CXXFLAGS.gcc)
9713d950b4SJed BrownCXXFLAGS.icc            := $(CXXFLAGS.gcc)
9813d950b4SJed BrownCXXFLAGS.XL             := -qpic -MMD
9913d950b4SJed BrownFFLAGS.GNU              := -fPIC -cpp -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -MMD -MP
10013d950b4SJed BrownFFLAGS.ifort            := -fPIC -cpp
10113d950b4SJed BrownFFLAGS.XL               := -qpic -ffree-form -qpreprocess -qextname -MMD
102cf4a56afSJed Brown
103d9bc9eefSJed Brown# This check works with compilers that use gcc and clang.  It fails with some
104d9bc9eefSJed Brown# compilers; e.g., xlc apparently ignores all options when -E is passed, thus
105d9bc9eefSJed Brown# succeeds with any flags.  Users can pass MARCHFLAG=... if desired.
106d9bc9eefSJed Browncc_check_flag = $(shell $(CC) -E -Werror $(1) -x c /dev/null > /dev/null 2>&1 && echo 1)
10713d950b4SJed BrownMARCHFLAG := $(MARCHFLAG.$(CC_VENDOR))
108f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG),-mcpu=native)
109f766a8abSJed BrownMARCHFLAG := $(if $(call cc_check_flag,$(MARCHFLAG)),$(MARCHFLAG))
110b9c05c73SJed Brown
11113d950b4SJed BrownOMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
112f766a8abSJed BrownOMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
113cf4a56afSJed Brown
11413d950b4SJed BrownOPT    ?= -O -g $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
11513d950b4SJed BrownCFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR))
11613d950b4SJed BrownCXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR))
117b0ab70ddSJed BrownNVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC
1184b1a2981SnbeamsHIPCCFLAGS ?= $(OPT) -fPIC
11913d950b4SJed BrownFFLAGS ?= $(OPT) $(FFLAGS.$(FC_VENDOR))
12032d74c32SThilina Rathnayake
121a6f4783aSJed Brownifeq ($(COVERAGE), 1)
122a6f4783aSJed Brown  CFLAGS += --coverage
123a6f4783aSJed Brown  LDFLAGS += --coverage
124a6f4783aSJed Brownendif
125a6f4783aSJed Brown
1264dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
1274dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
1284dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
12941a90898SJed BrownCPPFLAGS += -I./include
130582447c9SJed BrownLDLIBS = -lm
13191b7489eSJed BrownOBJDIR := build
1326ea7c6c1SJed BrownLIBDIR := lib
1336ea7c6c1SJed Brown
134d5217624SJed Brown# Installation variables
135d5217624SJed Brownprefix ?= /usr/local
136d5217624SJed Brownbindir = $(prefix)/bin
137d5217624SJed Brownlibdir = $(prefix)/lib
138bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
139d5217624SJed Brownincludedir = $(prefix)/include
140d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
141d5217624SJed BrownINSTALL = install
142d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
143d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
144d5217624SJed Brown
1453b56482dScamierjs# Get number of processors of the machine
14669762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
1473b56482dScamierjs# prepare make options to run in parallel
14882985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
14921ae6867Scamierjs                       --no-print-directory --no-keep-going
15087e762eaSJed Brown
1518ec9d54bSJed BrownPYTHON ?= python3
152bfa078e6SJed BrownPROVE ?= prove
1533a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1545c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1555c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1569df38c42SVeselin Dobrev
1576ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
15891b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
1597e68d260SJed BrownCEED_LIBS = -lceed
160d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
161288c0443SJeremy L Thompsongallery.c := $(wildcard gallery/*/ceed*.c)
162288c0443SJeremy L Thompsonlibceed.c += $(gallery.c)
163265be9c8Sjeremyltlibceed_test := $(LIBDIR)/libceed_test.$(SO_EXT)
16476af460cSJed Brownlibceeds = $(libceed) $(libceed_test)
165265be9c8SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
166d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
167bf000209STzanio
168bf000209STzanio# Tests
16957c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
1708980d4a7Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
17191b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1723f3e7340Scamierjsctests    := $(tests)
1738980d4a7Sjeremylttests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
17486a4271fSThilina Rathnayake# Examples
175182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
176182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
177182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
178182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
17986a4271fSThilina Rathnayake# MFEM Examples
1802158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
18116c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
18286a4271fSThilina Rathnayake# Nek5K Examples
18386a4271fSThilina Rathnayakenekexamples  := $(OBJDIR)/nek-bps
18486a4271fSThilina Rathnayake# PETSc Examples
1856f87d196Sjeremyltpetscexamples.c := $(wildcard examples/petsc/*.c)
186e797ab98SJed Brownpetscexamples   := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
187ccaff030SJeremy L Thompson# Fluid Dynamics Examples
188ccaff030SJeremy L Thompsonfluidsexamples.c := $(sort $(wildcard examples/fluids/*.c))
189ccaff030SJeremy L Thompsonfluidsexamples  := $(fluidsexamples.c:examples/fluids/%.c=$(OBJDIR)/fluids-%)
190ccaff030SJeremy L Thompson# Solid Mechanics Examples
191ccaff030SJeremy L Thompsonsolidsexamples.c := $(sort $(wildcard examples/solids/*.c))
192ccaff030SJeremy L Thompsonsolidsexamples   := $(solidsexamples.c:examples/solids/%.c=$(OBJDIR)/solids-%)
193e797ab98SJed Brown
19486a4271fSThilina Rathnayake# Backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
195ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
19689c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
197a718229cSjeremylttemplate.c     := $(sort $(wildcard backends/template/*.c))
19889c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
19989c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
20089c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
20189c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
2029f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
2034d537eeaSYohanncuda.cpp       := $(sort $(wildcard backends/cuda/*.cpp))
2049f0427d9SYohanncuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
20555ae60f9SYohanncuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
20655ae60f9SYohanncuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
207c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
208c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
209241a4b83SYohanncuda-gen.c     := $(sort $(wildcard backends/cuda-gen/*.c))
210241a4b83SYohanncuda-gen.cpp   := $(sort $(wildcard backends/cuda-gen/*.cpp))
211241a4b83SYohanncuda-gen.cu    := $(sort $(wildcard backends/cuda-gen/*.cu))
212ae3cba82Scamierjsocca.c         := $(sort $(wildcard backends/occa/*.c))
213a07e8cf1SNatalie Beamsmagma.c        := $(sort $(wildcard backends/magma/*.c))
214a07e8cf1SNatalie Beamsmagma.cu       := $(sort $(wildcard backends/magma/*.cu))
215*cfb6011cSnbeamship.hip        := $(sort $(wildcard backends/hip/*.hip.cpp))
216*cfb6011cSnbeamship.cpp        := $(sort $(filter-out $(hip.hip),$(wildcard backends/hip/*.cpp)))
21730f4f45fSnbeamship.c          := $(sort $(wildcard backends/hip/*.c))
21882985883Scamierjs
2199bdc3d68Scamierjs# Output using the 216-color rules mode
22018a724fcScamierjsrule_file = $(notdir $(1))
22118a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
22218a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
2233c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
224abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
225abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
22618a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
2273c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
22818a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
22918a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
230f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
231abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
23282985883Scamierjs
2339bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
23418a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
23521ae6867Scamierjs
236da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
2379df38c42SVeselin Dobrev.SUFFIXES:
238da72e7fcSJed Brown
23991b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
2409df38c42SVeselin Dobrev
24191b7489eSJed Brown%/.DIR :
24291b7489eSJed Brown	@mkdir -p $(@D)
24391b7489eSJed Brown	@touch $@
24491b7489eSJed Brown
24591b7489eSJed Brown.PRECIOUS: %/.DIR
24691b7489eSJed Brown
24723072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
24823072ed2SVeselin Dobrev# run 'lib' target in parallel
2492f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
250d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
251bf3e26f6SVeselin Dobrevinfo:
252bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
253bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
254241a4b83SYohann	$(info CXX           = $(CXX))
255bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
256bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
257bf3e26f6SVeselin Dobrev	$(info CFLAGS        = $(value CFLAGS))
258241a4b83SYohann	$(info CXXFLAGS      = $(value CXXFLAGS))
259bf3e26f6SVeselin Dobrev	$(info FFLAGS        = $(value FFLAGS))
260bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS     = $(value NVCCFLAGS))
261bf3e26f6SVeselin Dobrev	$(info LDFLAGS       = $(value LDFLAGS))
262bf3e26f6SVeselin Dobrev	$(info LDLIBS        = $(LDLIBS))
263bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
264bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
265bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
266bf3e26f6SVeselin Dobrev	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
267bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
2681ef3f58fSjeremylt	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/memcheck/serial /cpu/sef/memcheck/blocked))
26984a01de5SJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
27084a01de5SJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
271d20f937dSJed Brown	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
272cb23e90cSJeremy L Thompson	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma /gpu/magma/det))
273ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
27430f4f45fSnbeams	$(info HIP_DIR       = $(HIP_DIR)$(call backend_status,$(HIP_BACKENDS)))
275bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
276bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
2774d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
278bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
279bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
280bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
281bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
282bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
283bf3e26f6SVeselin Dobrev	$(info okldir        = $(value okldir))
284bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
285bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
286bf3e26f6SVeselin Dobrev	@true
28723072ed2SVeselin Dobrevinfo-backends:
288d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
2892f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends
2900e439e50SJed Brown
29124d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
29276af460cSJed Brown$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test)))
29369762e1fScamierjs
29448fffa06Sjeremylt# Standard Backends
29587174f08SJed Brownlibceed.c += $(ref.c)
2964a2e7687Sjeremyltlibceed.c += $(blocked.c)
29789c6efa4Sjeremyltlibceed.c += $(opt.c)
29823072ed2SVeselin Dobrev
299265be9c8Sjeremylt# Testing Backends
300265be9c8Sjeremylttest_backends.c := $(template.c)
301265be9c8SjeremyltTEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
302265be9c8Sjeremylt
303fc7cf9a0Sjeremylt# Memcheck Backend
304bdc3149dSjeremyltMEMCHK_STATUS = Disabled
305b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
306bdc3149dSjeremyltifeq ($(MEMCHK),1)
307bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
308fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
3091ef3f58fSjeremylt  BACKENDS += /cpu/self/memcheck/serial /cpu/self/memcheck/blocked
310fc7cf9a0Sjeremyltendif
311fc7cf9a0Sjeremylt
31248fffa06Sjeremylt# AVX Backed
31348fffa06SjeremyltAVX_STATUS = Disabled
314cf4a56afSJed BrownAVX_FLAG := $(if $(filter clang,$(CC_VENDOR)),+avx,-mavx)
315cf4a56afSJed BrownAVX := $(filter $(AVX_FLAG),$(shell $(CC) $(OPT) -v -E -x c /dev/null 2>&1))
316cf4a56afSJed Brownifneq ($(AVX),)
31748fffa06Sjeremylt  AVX_STATUS = Enabled
31848fffa06Sjeremylt  libceed.c += $(avx.c)
31984a01de5SJeremy L Thompson  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
32048fffa06Sjeremyltendif
32148fffa06Sjeremylt
3228d713cf6Sjeremylt# libXSMM Backends
3238d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
32476af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
32576af460cSJed Brown  $(libceeds) : LDLIBS += -lxsmm -ldl
32600723591Sjeremylt  MKL ?=
32700723591Sjeremylt  ifeq (,$(MKL)$(MKLROOT))
328c0ea1048SJed Brown    BLAS_LIB = -lblas
3295462ed45Sjeremylt  else
33072e1b2f7SJeremy L Thompson    ifneq ($(MKLROOT),)
331ff56800aSJed Brown      # Some installs put everything inside an intel64 subdirectory, others not
332ff56800aSJed Brown      MKL_LIBDIR = $(dir $(firstword $(wildcard $(MKLROOT)/lib/intel64/libmkl_sequential.* $(MKLROOT)/lib/libmkl_sequential.*)))
333ff56800aSJed Brown      MKL_LINK = -L$(MKL_LIBDIR) -Wl,-rpath,$(MKL_LIBDIR)
33472e1b2f7SJeremy L Thompson    endif
3357b49ae6cSjeremylt    BLAS_LIB = $(MKL_LINK) -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
3365462ed45Sjeremylt  endif
337c0ea1048SJed Brown  $(libceeds) : LDLIBS += $(BLAS_LIB)
3388d713cf6Sjeremylt  libceed.c += $(xsmm.c)
339683faae0SJed Brown  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
3408d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
3418d713cf6Sjeremyltendif
3428d713cf6Sjeremylt
34348fffa06Sjeremylt# OCCA Backends
3447f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
34576af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
34676af460cSJed Brown  $(libceeds) : LDLIBS += -locca
34787174f08SJed Brown  libceed.c += $(occa.c)
348683faae0SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
349a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
35021ae6867Scamierjsendif
35123072ed2SVeselin Dobrev
35286a4271fSThilina Rathnayake# CUDA Backends
3535a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
3545a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
3553dd0010eSvaleriabarraCUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
356241a4b83SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared /gpu/cuda/gen
3575a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
3589d77422eSJed Brown  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
35976af460cSJed Brown  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
36048e4fcd3SJeremy L Thompson  $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda -lcublas
361241a4b83SYohann  $(libceeds) : LINK = $(CXX)
362241a4b83SYohann  libceed.c   += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c) $(cuda-gen.c)
3634d537eeaSYohann  libceed.cpp += $(cuda.cpp) $(cuda-gen.cpp)
364241a4b83SYohann  libceed.cu  += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu) $(cuda-gen.cu)
365ab9cabdeSVeselin Dobrev  BACKENDS += $(CUDA_BACKENDS)
3669f0427d9SYohannendif
3679f0427d9SYohann
36830f4f45fSnbeams# HIP Backends
36930f4f45fSnbeamsROCM_DIR = $(HIP_DIR)/..
37030f4f45fSnbeamsHIP_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(HIP_DIR)/$d/libhiprtc.${SO_EXT}))
37130f4f45fSnbeamsHIP_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(HIP_LIB_DIR))))
37230f4f45fSnbeamsHIP_BACKENDS = /gpu/hip/ref
37330f4f45fSnbeamsifneq ($(HIP_LIB_DIR),)
3743f9cf3a4Snbeams  $(libceeds) : HIPCCFLAGS += -I./include
37530f4f45fSnbeams  ifneq ($(CXX), $(HIPCC))
376cdd1636dSnbeams    CPPFLAGS += $(subst =,,$(shell $(HIP_DIR)/bin/hipconfig -C))
37730f4f45fSnbeams  endif
3784b1a2981Snbeams  CPPFLAGS += -I$(ROCM_DIR)/hipblas/include -Wno-unused-function
379a233dbfeSnbeams  $(libceeds) : LDFLAGS += -L$(HIP_LIB_DIR) -Wl,-rpath,$(abspath $(HIP_LIB_DIR))
3803f9cf3a4Snbeams  $(libceeds) : LDFLAGS += -L$(ROCM_DIR)/hipblas/lib -Wl,-rpath,$(abspath $(ROCM_DIR)/hipblas/lib)
3813f9cf3a4Snbeams  $(libceeds) : LDLIBS += -lhip_hcc -lhiprtc -lhipblas
38230f4f45fSnbeams  $(libceeds) : LINK = $(CXX)
38330f4f45fSnbeams  libceed.hip += $(hip.hip)
38430f4f45fSnbeams  libceed.cpp += $(hip.cpp)
38530f4f45fSnbeams  libceed.c   += $(hip.c)
38630f4f45fSnbeams  BACKENDS += $(HIP_BACKENDS)
38730f4f45fSnbeamsendif
38830f4f45fSnbeams
3899f0427d9SYohann# MAGMA Backend
3909f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
3919f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
3921dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
3931dc2661bSVeselin Dobrev  omp_link = -fopenmp
3941dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
3957692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
3967692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
39776af460cSJed Brown  $(libceeds)           : LDLIBS += $(magma_link)
3987692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
399a07e8cf1SNatalie Beams  libceed.c  += $(magma.c)
400a07e8cf1SNatalie Beams  libceed.cu += $(magma.cu)
401a07e8cf1SNatalie Beams  $(magma.c:%.c=$(OBJDIR)/%.o) $(magma.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
402a07e8cf1SNatalie Beams  $(magma.cu:%.cu=$(OBJDIR)/%.o) : CPPFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include
403cb23e90cSJeremy L Thompson  BACKENDS += /gpu/magma /gpu/magma/det
40482b77998SStan Tomov  endif
4055a9ca9adSVeselin Dobrevendif
406755585ceSStan Tomov
407ce41f623SJed Brownexport BACKENDS
408ce41f623SJed Brown
409*cfb6011cSnbeamslibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cpp:%.cpp=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o) $(libceed.hip:%.hip.cpp=$(OBJDIR)/%.o)
4104c7bddedSJed Brown$(filter %fortran.o,$(libceed.o)) : CPPFLAGS += $(if $(filter 1,$(UNDERSCORE)),-DUNDERSCORE)
41123072ed2SVeselin Dobrev$(libceed.o): | info-backends
41223072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
413241a4b83SYohann	$(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
41491b7489eSJed Brown
41558e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
416b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
417ae3cba82Scamierjs
418241a4b83SYohann$(OBJDIR)/%.o : $(CURDIR)/%.cpp | $$(@D)/.DIR
419241a4b83SYohann	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
420241a4b83SYohann
42158e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
422755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
423755585ceSStan Tomov
424*cfb6011cSnbeams$(OBJDIR)/%.o : $(CURDIR)/%.hip.cpp | $$(@D)/.DIR
42530f4f45fSnbeams	$(call quiet,HIPCC) $(HIPCCFLAGS) -c -o $@ $(abspath $<)
42630f4f45fSnbeams
427b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
428843fcb4bSJed Brown	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
42978b5556aScamierjs
4308980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
431843fcb4bSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
43232d74c32SThilina Rathnayake
433182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
434843fcb4bSJed Brown	$(call quiet,LINK.c) $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
43591b7489eSJed Brown
436182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
437843fcb4bSJed Brown	$(call quiet,LINK.F) -DSOURCE_DIR='"$(abspath $(<D))/"' $(CEED_LDFLAGS) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
438673d494eSThilina Rathnayake
43916c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
440c4216f28SJed Brown	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
441722eb117SJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" CXX=$(CXX) $*
44216c6c054SJed Brown	mv examples/mfem/$* $@
44316c6c054SJed Brown
44486a4271fSThilina Rathnayake# Note: Multiple Nek files cannot be built in parallel. The '+' here enables
44586a4271fSThilina Rathnayake#       this single Nek bps file to be built in parallel with other examples,
44686a4271fSThilina Rathnayake#       such as when calling `make prove-all -j2`.
44786a4271fSThilina Rathnayake$(OBJDIR)/nek-bps : examples/nek/bps/bps.usr examples/nek/nek-examples.sh $(libceed) | $$(@D)/.DIR
44886a4271fSThilina Rathnayake	+$(MAKE) -C examples MPI=$(MPI) CEED_DIR=`pwd` NEK5K_DIR="$(abspath $(NEK5K_DIR))" nek
44986a4271fSThilina Rathnayake	mv examples/nek/build/bps $(OBJDIR)/bps
45086a4271fSThilina Rathnayake	cp examples/nek/nek-examples.sh $(OBJDIR)/nek-bps
45186a4271fSThilina Rathnayake
4527f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
453c4216f28SJed Brown	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
454f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
455e797ab98SJed Brown	mv examples/petsc/$* $@
456e797ab98SJed Brown
457ccaff030SJeremy L Thompson$(OBJDIR)/fluids-% : examples/fluids/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
458ccaff030SJeremy L Thompson	+$(MAKE) -C examples/fluids CEED_DIR=`pwd` \
459f766a8abSJed Brown	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
460ccaff030SJeremy L Thompson	mv examples/fluids/$* $@
461ccaff030SJeremy L Thompson
462ccaff030SJeremy L Thompson$(OBJDIR)/solids-% : examples/solids/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
463ccaff030SJeremy L Thompson	+$(MAKE) -C examples/solids CEED_DIR=`pwd` \
464722eb117SJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" OPT="$(OPT)" $*
465ccaff030SJeremy L Thompson	mv examples/solids/$* $@
4662774d5cbSJeremy L Thompson
467567e4d0aSJed Brownlibceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
46876af460cSJed Brown$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR
469241a4b83SYohann	$(call quiet,LINK) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
470265be9c8Sjeremylt
471265be9c8Sjeremylt$(examples) : $(libceed)
47276af460cSJed Brown$(tests) : $(libceed_test)
47376af460cSJed Brown$(tests) : CEED_LIBS = -lceed_test
474fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
4754859b599SJed Brown
476686de4acSJed Brownrun-t% : BACKENDS += $(TEST_BACKENDS)
477dad465e7SJed Brownrun-% : $(OBJDIR)/%
478d1f7f8d3SJed Brown	@tests/tap.sh $(<:$(OBJDIR)/%=%)
479686de4acSJed Brown
480686de4acSJed Brownexternal_examples := \
481686de4acSJed Brown	$(if $(MFEM_DIR),$(mfemexamples)) \
482686de4acSJed Brown	$(if $(PETSC_DIR),$(petscexamples)) \
483b974e86eSJed Brown	$(if $(NEK5K_DIR),$(nekexamples)) \
484ccaff030SJeremy L Thompson	$(if $(PETSC_DIR),$(fluidsexamples)) \
485ccaff030SJeremy L Thompson	$(if $(PETSC_DIR),$(solidsexamples))
486686de4acSJed Brown
487686de4acSJed Brownallexamples = $(examples) $(external_examples)
488686de4acSJed Brown
489686de4acSJed Brown# The test and prove targets can be controlled via pattern searches.  The
490686de4acSJed Brown# default is to run tests and those examples that have no external dependencies.
491686de4acSJed Brown# Examples of finer grained control:
492686de4acSJed Brown#
493686de4acSJed Brown#   make test search='petsc mfem'      # PETSc and MFEM examples
494686de4acSJed Brown#   make prove search='t3'             # t3xx series tests
495686de4acSJed Brown#   make junit search='ex petsc'       # core ex* and PETSc tests
496686de4acSJed Brownsearch ?= t ex
497686de4acSJed Brownrealsearch = $(search:%=%%)
498686de4acSJed Brownmatched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
499686de4acSJed Brown
5002158b1b0Sjeremylt# Test core libCEED
501686de4acSJed Browntest : $(matched:$(OBJDIR)/%=run-%)
5022158b1b0Sjeremylt
50386a4271fSThilina Rathnayake# Run test target in parallel
5046850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
5053b56482dScamierjs# CPU C tests only for backend %
5063f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
5074859b599SJed Brown
508686de4acSJed Brownprove : BACKENDS += $(TEST_BACKENDS)
50986a4271fSThilina Rathnayakeprove : $(matched)
510a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
511686de4acSJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
51286a4271fSThilina Rathnayake# Run prove target in parallel
5136850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
514bfa078e6SJed Brown
515686de4acSJed Brownprove-all :
516686de4acSJed Brown	+$(MAKE) prove realsearch=%
517686de4acSJed Brown
518686de4acSJed Brownjunit-t% : BACKENDS += $(TEST_BACKENDS)
5198ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
520bdb0bdbbSJed Brown	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
5218ec9d54bSJed Brown
52276174befSjeremyltjunit : $(matched:$(OBJDIR)/%=junit-%)
5238ec9d54bSJed Brown
5242f4d9adbSJeremy L Thompsonall: $(alltests)
5252f4d9adbSJeremy L Thompson
5262f4d9adbSJeremy L Thompsonexamples : $(allexamples)
52786a4271fSThilina Rathnayakeceedexamples : $(examples)
52886a4271fSThilina Rathnayakenekexamples : $(nekexamples)
52986a4271fSThilina Rathnayakemfemexamples : $(mfemexamples)
53086a4271fSThilina Rathnayakepetscexamples : $(petscexamples)
5312f4d9adbSJeremy L Thompson
5322f4d9adbSJeremy L Thompson# Benchmarks
5330c59ef15SJeremy L Thompsonallbenchmarks = petsc-bps
5344e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
5354e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
5364e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
5372f4d9adbSJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
5384e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
5392c6ea02fSJed Brown
5406ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
541d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
542d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
5436ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
5446ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
5450e439e50SJed Brown
546bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
547cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
548cc6ff0d7SJed Brown
549cc6ff0d7SJed Brownokl-cache :
550cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
551cc6ff0d7SJed Brown
552cc6ff0d7SJed Brownokl-clear:
553cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
554a5ba6ca9Scamierjs
555d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
556bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
557bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
5581e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
559f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
5601e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
5611e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
562bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
563d5217624SJed Brown
5647a7b0fa3SJed Brown.PHONY : cln clean doxygen doc lib install all print test tst prove prv prove-all junit examples style style-c style-py tidy okl-cache okl-clear info info-backends
565d635b4c6Scamierjs
5666e5d1fd9Scamierjscln clean :
5675cd88e3aSjeremylt	$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
56886a4271fSThilina Rathnayake	$(MAKE) -C examples clean NEK5K_DIR="$(abspath $(NEK5K_DIR))"
5695cd88e3aSjeremylt	$(MAKE) -C tests/python clean
570196a75e4SJed Brown	$(RM) benchmarks/*output.txt
5714859b599SJed Brown
57207838a1cSTzaniodistclean : clean
57321d92382SJed Brown	$(RM) -r doc/html doc/sphinx/build $(CONFIG)
57407838a1cSTzanio
5754c4400c7SValeria BarraDOXYGEN ?= doxygen
5764c4400c7SValeria Barradoxygen :
5774c4400c7SValeria Barra	$(DOXYGEN) Doxyfile
5784c4400c7SValeria Barra
579b4d76956SJed Browndoc-html doc-latexpdf doc-epub : doc-% : doxygen
5804c4400c7SValeria Barra	make -C doc/sphinx $*
5814c4400c7SValeria Barra
5824c4400c7SValeria Barradoc : doc-html
5837bd3a522STzanio
5847a7b0fa3SJed Brownstyle-c :
58520b73d85SJed Brown	@astyle --options=.astylerc \
586cb0b5415Sjeremylt          $(filter-out include/ceedf.h tests/t320-basis-f.h, \
58720b73d85SJed Brown            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
588ccaff030SJeremy L Thompson              examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch]))
5890dbfdfc5SJed Brown
5907a7b0fa3SJed BrownAUTOPEP8 = autopep8
5917a7b0fa3SJed Brownstyle-py : AUTOPEP8_ARGS = --in-place --aggressive
5927a7b0fa3SJed Brownstyle-py :
593dec49e00SJed Brown	@$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py tests/python**/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py)
5947a7b0fa3SJed Brown
5957a7b0fa3SJed Brownstyle : style-c style-py
5967a7b0fa3SJed Brown
597683faae0SJed BrownCLANG_TIDY ?= clang-tidy
598683faae0SJed Brown%.c.tidy : %.c
5994c0d97c4SJeremy L Thompson	$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c99 -I$(CUDA_DIR)/include
600683faae0SJed Brown
601683faae0SJed Browntidy : $(libceed.c:%=%.tidy)
602683faae0SJed Brown
6034859b599SJed Brownprint :
6044859b599SJed Brown	@echo $(VAR)=$($(VAR))
605582447c9SJed Brown
6069df38c42SVeselin Dobrevprint-% :
6079df38c42SVeselin Dobrev	$(info [ variable name]: $*)
6089df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
6097bcc1ce4SJed Brown	$(info [        flavor]: $(flavor $*))
6109df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
6119df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
6129df38c42SVeselin Dobrev	$(info )
6139df38c42SVeselin Dobrev	@true
6149df38c42SVeselin Dobrev
615b0ab70ddSJed Brown# "make configure" detects any variables passed on the command line or
616b0ab70ddSJed Brown# previously set in config.mk, caching them in config.mk as simple
617b0ab70ddSJed Brown# (:=) variables.  Variables set in config.mk or on the command line
618b0ab70ddSJed Brown# take precedence over the defaults provided in the file.  Typical
619b0ab70ddSJed Brown# usage:
620d3c6b40fSJed Brown#
621d3c6b40fSJed Brown#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
622d3c6b40fSJed Brown#   make
623d3c6b40fSJed Brown#   make prove
624b0ab70ddSJed Brown#
625b0ab70ddSJed Brown# The values in the file can be updated by passing them on the command
626b0ab70ddSJed Brown# line, e.g.,
627b0ab70ddSJed Brown#
628b0ab70ddSJed Brown#   make configure CC=/path/to/other/clang
629b0ab70ddSJed Brown
630b0ab70ddSJed Brown# All variables to consider for caching
63130f4f45fSnbeamsCONFIG_VARS = CC CXX FC NVCC NVCC_CXX HIPCC \
63230f4f45fSnbeams	OPT CFLAGS CPPFLAGS CXXFLAGS FFLAGS NVCCFLAGS HIPCCFLAGS \
633b0ab70ddSJed Brown	LDFLAGS LDLIBS \
63430f4f45fSnbeams	MAGMA_DIR XSMM_DIR CUDA_DIR MFEM_DIR PETSC_DIR NEK5K_DIR HIP_DIR
635b0ab70ddSJed Brown
636b0ab70ddSJed Brown# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
637b0ab70ddSJed Brown# was set on the command line or in config.mk (where it will appear as
638b0ab70ddSJed Brown# a simple variable).
639b0ab70ddSJed Brownneeds_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
640b0ab70ddSJed Brown
641d3c6b40fSJed Brownconfigure :
642b0ab70ddSJed Brown	$(file > $(CONFIG))
643b0ab70ddSJed Brown	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
644b0ab70ddSJed Brown	@echo "Configuration cached in $(CONFIG):"
645b0ab70ddSJed Brown	@cat $(CONFIG)
646d3c6b40fSJed Brown
64761130325SJed Brownwheel : export MARCHFLAG = -march=generic
64861130325SJed Brownwheel : export WHEEL_PLAT = manylinux2010_x86_64
64937c134eaSJed Brownwheel :
650dabe13fcSJed Brown	docker run -it --user $(shell id -u):$(shell id -g) --rm -v $(PWD):/io -w /io \
65161130325SJed Brown		-e MARCHFLAG -e WHEEL_PLAT \
65261130325SJed Brown		quay.io/pypa/$(WHEEL_PLAT) python/make-wheels.sh
653d3c6b40fSJed Brown
65437c134eaSJed Brown.PHONY : configure wheel
65537c134eaSJed Brown
65637c134eaSJed Brown# Include *.d deps when not -B = --always-make: useful if the paths are wonky in a container
65737c134eaSJed Brown-include $(if $(filter B,$(MAKEFLAGS)),,$(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d))
658