xref: /libCEED/Makefile (revision b8fb44e70239e4a381e84fa0aa38c645356e7ef8)
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
17dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin CC)))
186ed738d9SJed Brown  CC = gcc
19dc753d40SJed Brownendif
20dc753d40SJed Brownifeq (,$(filter-out undefined default,$(origin FC)))
2181c9eb91SStan Tomov  FC = gfortran
22dc753d40SJed Brownendif
237692a9b0SVeselin DobrevNVCC = $(CUDA_DIR)/bin/nvcc
24e86995feScamierjs
253b56482dScamierjs# ASAN must be left empty if you don't want to use it
260a7eccc5ScamierjsASAN ?=
276850bcb5Scamierjs
28e86995feScamierjsLDFLAGS ?=
2932d74c32SThilina RathnayakeUNDERSCORE ?= 1
301b58aefaScamierjs
31f9fa8c39Sjeremylt# MFEM_DIR env variable should point to sibling directory
32bf3e26f6SVeselin Dobrevifneq ($(wildcard ../mfem/libmfem.*),)
339ba53df8Sjeremylt  MFEM_DIR ?= ../mfem
34f9fa8c39Sjeremyltendif
35f9fa8c39Sjeremylt
364d1cd9fcSJeremy L Thompson# NEK5K_DIR env variable should point to sibling directory
374d1cd9fcSJeremy L Thompsonifneq ($(wildcard ../Nek5000/*),)
384d1cd9fcSJeremy L Thompson  NEK5K_DIR ?= ../Nek5000
394d1cd9fcSJeremy L Thompsonendif
404d1cd9fcSJeremy L Thompson
418d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
428d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
438d713cf6Sjeremylt
4412123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
457f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
46f797d7b2Scamierjs
475a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
485a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma
495a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
505a9ca9adSVeselin DobrevCUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
515a9ca9adSVeselin Dobrev               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
5282b77998SStan Tomov
532f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
542f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
552f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
562f4d9adbSJeremy L Thompsonendif
572f4d9adbSJeremy L Thompson
58bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
5912123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
60c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
6132d74c32SThilina Rathnayake
622774d5cbSJeremy L ThompsonOPT    = -O -g -march=native -ffp-contract=fast -fopenmp-simd
63323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
649f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
651dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
661dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),)
6710da579bSJeremy L Thompson  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
68323c739cSJed Brownelse # gfortran/Intel-style options
698980d4a7Sjeremylt  FFLAGS = -cpp     $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
701dc2661bSVeselin Dobrevendif
711b58aefaScamierjs
7232d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1)
7332d74c32SThilina Rathnayake  CFLAGS += -DUNDERSCORE
7432d74c32SThilina Rathnayakeendif
7532d74c32SThilina Rathnayake
76a6f4783aSJed Brownifeq ($(COVERAGE), 1)
77a6f4783aSJed Brown  CFLAGS += --coverage
78a6f4783aSJed Brown  LDFLAGS += --coverage
79a6f4783aSJed Brownendif
80a6f4783aSJed Brown
814dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
824dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
834dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
846ea7c6c1SJed BrownCPPFLAGS = -I./include
85582447c9SJed BrownLDLIBS = -lm
8691b7489eSJed BrownOBJDIR := build
876ea7c6c1SJed BrownLIBDIR := lib
886ea7c6c1SJed Brown
89d5217624SJed Brown# Installation variables
90d5217624SJed Brownprefix ?= /usr/local
91d5217624SJed Brownbindir = $(prefix)/bin
92d5217624SJed Brownlibdir = $(prefix)/lib
93bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
94d5217624SJed Brownincludedir = $(prefix)/include
95d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
96d5217624SJed BrownINSTALL = install
97d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
98d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
99d5217624SJed Brown
1003b56482dScamierjs# Get number of processors of the machine
10169762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
1023b56482dScamierjs# prepare make options to run in parallel
10382985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
10421ae6867Scamierjs                       --no-print-directory --no-keep-going
10587e762eaSJed Brown
1068ec9d54bSJed BrownPYTHON ?= python3
107bfa078e6SJed BrownPROVE ?= prove
1083a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1095c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1105c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1119df38c42SVeselin Dobrev
1126ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
11391b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
114d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
11589c6efa4SjeremyltBACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked /cpu/self/tmpl
116d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
117bf000209STzanio
118bf000209STzanio# Tests
11957c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
1208980d4a7Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
12191b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1223f3e7340Scamierjsctests    := $(tests)
1238980d4a7Sjeremylttests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
12432d74c32SThilina Rathnayake#examples
125182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
126182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
127182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
128182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
1292158b1b0Sjeremylt#mfemexamples
1302158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
13116c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
1324d1cd9fcSJeremy L Thompson#nekexamples
1334d1cd9fcSJeremy L Thompsonnekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr))
1344d1cd9fcSJeremy L Thompsonnekexamples  := $(nekexamples.usr:examples/nek5000/%.usr=nek-%)
1354d1cd9fcSJeremy L Thompson#petscexamples
136e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c))
137e797ab98SJed Brownpetscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
1382774d5cbSJeremy L Thompson#navierstokesexample
1392774d5cbSJeremy L Thompsonnavierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c))
1402774d5cbSJeremy L Thompsonnavierstokesexample  := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%)
141e797ab98SJed Brown
14289c6efa4Sjeremylt# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
143ae3cba82Scamierjsref.c          := $(sort $(wildcard backends/ref/*.c))
14489c6efa4Sjeremyltblocked.c      := $(sort $(wildcard backends/blocked/*.c))
145a718229cSjeremylttemplate.c     := $(sort $(wildcard backends/template/*.c))
14689c6efa4Sjeremyltceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
14789c6efa4Sjeremyltopt.c          := $(sort $(wildcard backends/opt/*.c))
14889c6efa4Sjeremyltavx.c          := $(sort $(wildcard backends/avx/*.c))
14989c6efa4Sjeremyltxsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
1509f0427d9SYohanncuda.c         := $(sort $(wildcard backends/cuda/*.c))
1519f0427d9SYohanncuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
15255ae60f9SYohanncuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
15355ae60f9SYohanncuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
154c532df63SYohanncuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
155c532df63SYohanncuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
156ae3cba82Scamierjsocca.c         := $(sort $(wildcard backends/occa/*.c))
157755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py
158c4acb06bSStan Tomovmagma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
159c4acb06bSStan Tomovmagma_dsrc     := $(wildcard backends/magma/magma_d*.c)
160c4acb06bSStan Tomovmagma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
161c4acb06bSStan Tomovmagma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
162c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
163c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu)
16482985883Scamierjs
1659bdc3d68Scamierjs# Output using the 216-color rules mode
16618a724fcScamierjsrule_file = $(notdir $(1))
16718a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
16818a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
1693c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
170abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
171abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
17218a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
1733c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
17418a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
17518a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
176f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
177abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
17882985883Scamierjs
1799bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
18018a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
18121ae6867Scamierjs
182da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
1839df38c42SVeselin Dobrev.SUFFIXES:
184da72e7fcSJed Brown
18591b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
1869df38c42SVeselin Dobrev
187c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
18814c1ded1SStan Tomov
18991b7489eSJed Brown%/.DIR :
19091b7489eSJed Brown	@mkdir -p $(@D)
19191b7489eSJed Brown	@touch $@
19291b7489eSJed Brown
19391b7489eSJed Brown.PRECIOUS: %/.DIR
19491b7489eSJed Brown
19523072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
19623072ed2SVeselin Dobrev# run 'lib' target in parallel
1972f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
198d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
199bf3e26f6SVeselin Dobrevinfo:
200bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
201bf3e26f6SVeselin Dobrev	$(info CC            = $(CC))
202bf3e26f6SVeselin Dobrev	$(info FC            = $(FC))
203bf3e26f6SVeselin Dobrev	$(info CPPFLAGS      = $(CPPFLAGS))
204bf3e26f6SVeselin Dobrev	$(info CFLAGS        = $(value CFLAGS))
205bf3e26f6SVeselin Dobrev	$(info FFLAGS        = $(value FFLAGS))
206bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS     = $(value NVCCFLAGS))
207bf3e26f6SVeselin Dobrev	$(info LDFLAGS       = $(value LDFLAGS))
208bf3e26f6SVeselin Dobrev	$(info LDLIBS        = $(LDLIBS))
209bf3e26f6SVeselin Dobrev	$(info OPT           = $(OPT))
210bf3e26f6SVeselin Dobrev	$(info AFLAGS        = $(AFLAGS))
211bf3e26f6SVeselin Dobrev	$(info ASAN          = $(or $(ASAN),(empty)))
212bf3e26f6SVeselin Dobrev	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
213bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
214bdc3149dSjeremylt	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck))
21584a01de5SJeremy L Thompson	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
21684a01de5SJeremy L Thompson	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
217d20f937dSJed Brown	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
218d20f937dSJed Brown	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
219ab9cabdeSVeselin Dobrev	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
220bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
221bf3e26f6SVeselin Dobrev	$(info MFEM_DIR      = $(MFEM_DIR))
2224d1cd9fcSJeremy L Thompson	$(info NEK5K_DIR     = $(NEK5K_DIR))
223bf3e26f6SVeselin Dobrev	$(info PETSC_DIR     = $(PETSC_DIR))
224bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
225bf3e26f6SVeselin Dobrev	$(info prefix        = $(prefix))
226bf3e26f6SVeselin Dobrev	$(info includedir    = $(value includedir))
227bf3e26f6SVeselin Dobrev	$(info libdir        = $(value libdir))
228bf3e26f6SVeselin Dobrev	$(info okldir        = $(value okldir))
229bf3e26f6SVeselin Dobrev	$(info pkgconfigdir  = $(value pkgconfigdir))
230bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
231bf3e26f6SVeselin Dobrev	@true
23223072ed2SVeselin Dobrevinfo-backends:
233d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
2342f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends
2350e439e50SJed Brown
23624d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
23769762e1fScamierjs
23848fffa06Sjeremylt# Standard Backends
23987174f08SJed Brownlibceed.c += $(ref.c)
240a718229cSjeremyltlibceed.c += $(template.c)
2414a2e7687Sjeremyltlibceed.c += $(blocked.c)
24289c6efa4Sjeremyltlibceed.c += $(opt.c)
24323072ed2SVeselin Dobrev
244fc7cf9a0Sjeremylt# Memcheck Backend
245bdc3149dSjeremyltMEMCHK_STATUS = Disabled
246*b8fb44e7SJed BrownMEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
247bdc3149dSjeremyltifeq ($(MEMCHK),1)
248bdc3149dSjeremylt  MEMCHK_STATUS = Enabled
249fc7cf9a0Sjeremylt  libceed.c += $(ceedmemcheck.c)
250fc7cf9a0Sjeremylt  BACKENDS += /cpu/self/ref/memcheck
251fc7cf9a0Sjeremyltendif
252fc7cf9a0Sjeremylt
25348fffa06Sjeremylt# AVX Backed
25448fffa06SjeremyltAVX_STATUS = Disabled
2555efe2378SjeremyltAVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c avx)
25648fffa06Sjeremyltifeq ($(AVX),1)
25748fffa06Sjeremylt  AVX_STATUS = Enabled
25848fffa06Sjeremylt  libceed.c += $(avx.c)
25984a01de5SJeremy L Thompson  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
26048fffa06Sjeremyltendif
26148fffa06Sjeremylt
2628d713cf6Sjeremylt# libXSMM Backends
2638d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
2648d713cf6Sjeremylt  $(libceed) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
265724a7164Sjeremylt  $(libceed) : LDLIBS += -lxsmm -ldl
266724a7164Sjeremylt  MKL ?= 0
267724a7164Sjeremylt  ifneq (0,$(MKL))
268724a7164Sjeremylt    $(libceed) : LDLIBS += -mkl
269724a7164Sjeremylt  else
270724a7164Sjeremylt    $(libceed) : LDLIBS += -lblas
271724a7164Sjeremylt  endif
2728d713cf6Sjeremylt  libceed.c += $(xsmm.c)
2738d713cf6Sjeremylt  $(xsmm.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(XSMM_DIR)/include
2748d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
2758d713cf6Sjeremyltendif
2768d713cf6Sjeremylt
27748fffa06Sjeremylt# OCCA Backends
2787f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
279fc377ca6SJed Brown  $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
28012123fd5Scamierjs  $(libceed) : LDLIBS += -locca
28187174f08SJed Brown  libceed.c += $(occa.c)
28287174f08SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include
283a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
28421ae6867Scamierjsendif
28523072ed2SVeselin Dobrev
2869f0427d9SYohann# Cuda Backend
2875a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
2885a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
289c532df63SYohannCUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared
2905a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
2919f0427d9SYohann  $(libceed) : CFLAGS += -I$(CUDA_DIR)/include
2929f0427d9SYohann  $(libceed) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
2939f0427d9SYohann  $(libceed) : LDLIBS += -lcudart -lnvrtc -lcuda
294c532df63SYohann  libceed.c  += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c)
295c532df63SYohann  libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu)
296ab9cabdeSVeselin Dobrev  BACKENDS += $(CUDA_BACKENDS)
2979f0427d9SYohannendif
2989f0427d9SYohann
2999f0427d9SYohann# MAGMA Backend
3009f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
3019f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
3021dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
3031dc2661bSVeselin Dobrev  omp_link = -fopenmp
3041dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
3057692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
3067692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
3077692a9b0SVeselin Dobrev  $(libceed)           : LDLIBS += $(magma_link)
3087692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
309c4acb06bSStan Tomov  libceed.c  += $(magma_allsrc.c)
310c4acb06bSStan Tomov  libceed.cu += $(magma_allsrc.cu)
311c4acb06bSStan Tomov  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
312c4acb06bSStan Tomov  $(magma_allsrc.cu:%.cu=$(OBJDIR)/%.o) : NVCCFLAGS += --compiler-options=-fPIC -DADD_ -I$(MAGMA_DIR)/include -I$(MAGMA_DIR)/magmablas -I$(MAGMA_DIR)/control -I$(CUDA_DIR)/include
313ce41f623SJed Brown  BACKENDS += /gpu/magma
31482b77998SStan Tomov  endif
3155a9ca9adSVeselin Dobrevendif
316755585ceSStan Tomov
317ce41f623SJed Brownexport BACKENDS
318ce41f623SJed Brown
319755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c
32029715310SJed Brown%_tmp.c %_cuda.cu : %.c
321755585ceSStan Tomov	$(magma_preprocessor) $<
322755585ceSStan Tomov
32323072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
32423072ed2SVeselin Dobrev$(libceed.o): | info-backends
32523072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
32621ae6867Scamierjs	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
32791b7489eSJed Brown
32858e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
329b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
330ae3cba82Scamierjs
33158e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
332755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
333755585ceSStan Tomov
334b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
33534fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
33678b5556aScamierjs
3378980d4a7Sjeremylt$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
33834fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
33932d74c32SThilina Rathnayake
340182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
34134fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
34291b7489eSJed Brown
343182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
34434fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
345673d494eSThilina Rathnayake
34616c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
3472f4d9adbSJeremy L Thompson	$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
3482f4d9adbSJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
34916c6c054SJed Brown	mv examples/mfem/$* $@
35016c6c054SJed Brown
3517f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
3522f4d9adbSJeremy L Thompson	$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
3532f4d9adbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
354e797ab98SJed Brown	mv examples/petsc/$* $@
355e797ab98SJed Brown
3562774d5cbSJeremy L Thompson$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
3572774d5cbSJeremy L Thompson	$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
3582774d5cbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
3592774d5cbSJeremy L Thompson	mv examples/navier-stokes/$* $@
3602774d5cbSJeremy L Thompson
3612c6ea02fSJed Brown$(tests) $(examples) : $(libceed)
362fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
3634859b599SJed Brown
364dad465e7SJed Brownrun-% : $(OBJDIR)/%
365d1f7f8d3SJed Brown	@tests/tap.sh $(<:$(OBJDIR)/%=%)
3662158b1b0Sjeremylt# Test core libCEED
367dad465e7SJed Browntest : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%)
3682158b1b0Sjeremylt
3693b56482dScamierjs# run test target in parallel
3706850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
3713b56482dScamierjs# CPU C tests only for backend %
3723f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
3734859b599SJed Brown
374dad465e7SJed Brownprove : $(tests) $(examples)
375a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
376dad465e7SJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%)
3773b56482dScamierjs# run prove target in parallel
3786850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
379bfa078e6SJed Brown
3802f4d9adbSJeremy L Thompsonallexamples := $(examples) $(if $(MFEM_DIR),$(mfemexamples)) $(if $(PETSC_DIR),$(petscexamples))
3812f4d9adbSJeremy L Thompsonalltests := $(tests) $(allexamples)
3824d1cd9fcSJeremy L Thompsonfulltestlist = $(alltests) $(if $(NEK5K_DIR), $(nekexamples))
3834d1cd9fcSJeremy L Thompsonprepnektests:
3844d1cd9fcSJeremy L Thompson	(export CC FC && cd examples && make prepnektests)
3854d1cd9fcSJeremy L Thompsonprove-all : $(alltests) $(if $(NEK5K_DIR), prepnektests)
3862158b1b0Sjeremylt	$(info Testing backends: $(BACKENDS))
3874d1cd9fcSJeremy L Thompson	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(fulltestlist:$(OBJDIR)/%=%)
3882158b1b0Sjeremylt
3898ec9d54bSJed Brownjunit-% : $(OBJDIR)/%
390bdb0bdbbSJed Brown	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
3918ec9d54bSJed Brown
3928ec9d54bSJed Brownjunit : $(alltests:$(OBJDIR)/%=junit-%)
3938ec9d54bSJed Brown
3942f4d9adbSJeremy L Thompsonall: $(alltests)
3952f4d9adbSJeremy L Thompson
3962f4d9adbSJeremy L Thompsonexamples : $(allexamples)
3972f4d9adbSJeremy L Thompson
3982f4d9adbSJeremy L Thompson# Benchmarks
3992f4d9adbSJeremy L Thompsonallbenchmarks = petsc-bp1 petsc-bp3
4004e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
4014e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
4024e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
4032f4d9adbSJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
4044e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
4052c6ea02fSJed Brown
4066ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
407d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
408d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
4096ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
4106ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
4110e439e50SJed Brown
412bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
413cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
414cc6ff0d7SJed Brown
415cc6ff0d7SJed Brownokl-cache :
416cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
417cc6ff0d7SJed Brown
418cc6ff0d7SJed Brownokl-clear:
419cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
420a5ba6ca9Scamierjs
421d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
422bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
423bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
4241e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
425f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
4261e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
4271e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
428bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
429d5217624SJed Brown
4308ec9d54bSJed Brown.PHONY : cln clean doc lib install all print test tst prove prv prove-all junit examples style okl-cache okl-clear info info-backends
431d635b4c6Scamierjs
4326e5d1fd9Scamierjscln clean :
433df0ef7e4SVeselin Dobrev	$(RM) -r $(OBJDIR) $(LIBDIR)
4342774d5cbSJeremy L Thompson	$(MAKE) -C examples clean
435c4acb06bSStan Tomov	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
4362f4d9adbSJeremy L Thompson	$(RM) -rf benchmarks/*output.txt
4374859b599SJed Brown
43807838a1cSTzaniodistclean : clean
4398c23e06aSJed Brown	$(RM) -r doc/html
44007838a1cSTzanio
4410ab95609SJed Browndoc :
4427bd3a522STzanio	doxygen Doxyfile
4437bd3a522STzanio
444f2fa494dScamierjsstyle :
44520b73d85SJed Brown	@astyle --options=.astylerc \
44620b73d85SJed Brown          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
44720b73d85SJed Brown            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
44820b73d85SJed Brown              examples/*/*.[ch] examples/*/*.[ch]pp))
4490dbfdfc5SJed Brown
4504859b599SJed Brownprint :
4514859b599SJed Brown	@echo $(VAR)=$($(VAR))
452582447c9SJed Brown
4539df38c42SVeselin Dobrevprint-% :
4549df38c42SVeselin Dobrev	$(info [ variable name]: $*)
4559df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
4569df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
4579df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
4589df38c42SVeselin Dobrev	$(info )
4599df38c42SVeselin Dobrev	@true
4609df38c42SVeselin Dobrev
461d1f7f8d3SJed Brown-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
462