xref: /libCEED/Makefile (revision 8d713cf6e78a6ffd2518ae96db9cfdbd22a60f79)
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
36*8d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
37*8d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
38*8d713cf6Sjeremylt
3912123fd5Scamierjs# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
407f5ff99bSVeselin DobrevOCCA_DIR ?= ../occa
41f797d7b2Scamierjs
425a9ca9adSVeselin Dobrev# env variable MAGMA_DIR can be used too
435a9ca9adSVeselin DobrevMAGMA_DIR ?= ../magma
445a9ca9adSVeselin Dobrev# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
455a9ca9adSVeselin DobrevCUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
465a9ca9adSVeselin Dobrev               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
4782b77998SStan Tomov
48bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
4912123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
50c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
5132d74c32SThilina Rathnayake
5248fffa06SjeremyltOPT    = -O -g -march=native -ffp-contract=fast
53323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
549f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
551dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
561dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),)
5710da579bSJeremy L Thompson  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
58323c739cSJed Brownelse # gfortran/Intel-style options
5910da579bSJeremy L Thompson  FFLAGS = -cpp     $(OPT) -ffree-form -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
601dc2661bSVeselin Dobrevendif
611b58aefaScamierjs
6232d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1)
6332d74c32SThilina Rathnayake  CFLAGS += -DUNDERSCORE
6432d74c32SThilina Rathnayakeendif
6532d74c32SThilina Rathnayake
66a6f4783aSJed Brownifeq ($(COVERAGE), 1)
67a6f4783aSJed Brown  CFLAGS += --coverage
68a6f4783aSJed Brown  LDFLAGS += --coverage
69a6f4783aSJed Brownendif
70a6f4783aSJed Brown
714dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
724dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
734dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
746ea7c6c1SJed BrownCPPFLAGS = -I./include
75582447c9SJed BrownLDLIBS = -lm
7691b7489eSJed BrownOBJDIR := build
776ea7c6c1SJed BrownLIBDIR := lib
786ea7c6c1SJed Brown
79d5217624SJed Brown# Installation variables
80d5217624SJed Brownprefix ?= /usr/local
81d5217624SJed Brownbindir = $(prefix)/bin
82d5217624SJed Brownlibdir = $(prefix)/lib
83bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
84d5217624SJed Brownincludedir = $(prefix)/include
85d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
86d5217624SJed BrownINSTALL = install
87d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
88d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
89d5217624SJed Brown
903b56482dScamierjs# Get number of processors of the machine
9169762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
923b56482dScamierjs# prepare make options to run in parallel
9382985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
9421ae6867Scamierjs                       --no-print-directory --no-keep-going
9587e762eaSJed Brown
96bfa078e6SJed BrownPROVE ?= prove
973a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
985c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
995c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1009df38c42SVeselin Dobrev
1016ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
10291b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
103d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
1044a2e7687SjeremyltBACKENDS_BUILTIN := /cpu/self/ref /cpu/self/tmpl /cpu/self/blocked
105d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
106bf000209STzanio
107bf000209STzanio# Tests
10857c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
10957c64913Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f))
11091b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1113f3e7340Scamierjsctests    := $(tests)
11232d74c32SThilina Rathnayaketests     += $(tests.f:tests/%.f=$(OBJDIR)/%)
11332d74c32SThilina Rathnayake#examples
114182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
115182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
116182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
117182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
1182158b1b0Sjeremylt#mfemexamples
1192158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
12016c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
121e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c))
122e797ab98SJed Brownpetscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
123e797ab98SJed Brown
12448fffa06Sjeremylt# backends/[ref, template, blocked, avx, occa, magma]
125ae3cba82Scamierjsref.c      := $(sort $(wildcard backends/ref/*.c))
126a718229cSjeremylttemplate.c := $(sort $(wildcard backends/template/*.c))
1279f0427d9SYohanncuda.c     := $(sort $(wildcard backends/cuda/*.c))
1289f0427d9SYohanncuda.cu    := $(sort $(wildcard backends/cuda/*.cu))
1294a2e7687Sjeremyltblocked.c  := $(sort $(wildcard backends/blocked/*.c))
13048fffa06Sjeremyltavx.c      := $(sort $(wildcard backends/avx/*.c))
131*8d713cf6Sjeremyltxsmm.c     := $(sort $(wildcard backends/xsmm/*.c))
132ae3cba82Scamierjsocca.c     := $(sort $(wildcard backends/occa/*.c))
133755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py
134c4acb06bSStan Tomovmagma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
135c4acb06bSStan Tomovmagma_dsrc     := $(wildcard backends/magma/magma_d*.c)
136c4acb06bSStan Tomovmagma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
137c4acb06bSStan Tomovmagma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
138c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
139c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu)
14082985883Scamierjs
1419bdc3d68Scamierjs# Output using the 216-color rules mode
14218a724fcScamierjsrule_file = $(notdir $(1))
14318a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
14418a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
1453c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
146abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
147abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
14818a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
1493c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
15018a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
15118a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
152f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
153abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
15482985883Scamierjs
1559bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
15618a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
15721ae6867Scamierjs
158da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
1599df38c42SVeselin Dobrev.SUFFIXES:
160da72e7fcSJed Brown
16191b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
1629df38c42SVeselin Dobrev
163c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
16414c1ded1SStan Tomov
16591b7489eSJed Brown%/.DIR :
16691b7489eSJed Brown	@mkdir -p $(@D)
16791b7489eSJed Brown	@touch $@
16891b7489eSJed Brown
16991b7489eSJed Brown.PRECIOUS: %/.DIR
17091b7489eSJed Brown
17123072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
17223072ed2SVeselin Dobrev# run 'lib' target in parallel
17323072ed2SVeselin Dobrevall:;@$(MAKE) $(MFLAGS) V=$(V) lib
174d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
175bf3e26f6SVeselin Dobrevinfo:
176bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
177bf3e26f6SVeselin Dobrev	$(info CC         = $(CC))
178bf3e26f6SVeselin Dobrev	$(info FC         = $(FC))
179bf3e26f6SVeselin Dobrev	$(info CPPFLAGS   = $(CPPFLAGS))
180bf3e26f6SVeselin Dobrev	$(info CFLAGS     = $(value CFLAGS))
181bf3e26f6SVeselin Dobrev	$(info FFLAGS     = $(value FFLAGS))
182bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS  = $(value NVCCFLAGS))
183bf3e26f6SVeselin Dobrev	$(info LDFLAGS    = $(value LDFLAGS))
184bf3e26f6SVeselin Dobrev	$(info LDLIBS     = $(LDLIBS))
185bf3e26f6SVeselin Dobrev	$(info OPT        = $(OPT))
186bf3e26f6SVeselin Dobrev	$(info AFLAGS     = $(AFLAGS))
187bf3e26f6SVeselin Dobrev	$(info ASAN       = $(or $(ASAN),(empty)))
188bf3e26f6SVeselin Dobrev	$(info V          = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
189bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
19048fffa06Sjeremylt	$(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx))
191*8d713cf6Sjeremylt	$(info XSMM_DIR   = $(XSMM_DIR)$(call backend_status,/cpu/xsmm/serial /cpu/xsmm/blocked))
192d20f937dSJed Brown	$(info OCCA_DIR   = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
193d20f937dSJed Brown	$(info MAGMA_DIR  = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
194d20f937dSJed Brown	$(info CUDA_DIR   = $(CUDA_DIR)$(call backend_status,/gpu/magma))
195bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
196bf3e26f6SVeselin Dobrev	$(info MFEM_DIR   = $(MFEM_DIR))
197bf3e26f6SVeselin Dobrev	$(info PETSC_DIR  = $(PETSC_DIR))
198bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
199bf3e26f6SVeselin Dobrev	$(info prefix       = $(prefix))
200bf3e26f6SVeselin Dobrev	$(info includedir   = $(value includedir))
201bf3e26f6SVeselin Dobrev	$(info libdir       = $(value libdir))
202bf3e26f6SVeselin Dobrev	$(info okldir       = $(value okldir))
203bf3e26f6SVeselin Dobrev	$(info pkgconfigdir = $(value pkgconfigdir))
204bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
205bf3e26f6SVeselin Dobrev	@true
20623072ed2SVeselin Dobrevinfo-backends:
207d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
20823072ed2SVeselin Dobrev.PHONY: lib all info info-backends
2090e439e50SJed Brown
21024d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
21169762e1fScamierjs
21248fffa06Sjeremylt# Standard Backends
21387174f08SJed Brownlibceed.c += $(ref.c)
214a718229cSjeremyltlibceed.c += $(template.c)
2154a2e7687Sjeremyltlibceed.c += $(blocked.c)
21623072ed2SVeselin Dobrev
21748fffa06Sjeremylt# AVX Backed
21848fffa06SjeremyltAVX_STATUS = Disabled
21948fffa06SjeremyltAVX := $(shell $(CC) $(CFLAGS) -v -E - < /dev/null 2>&1 | grep -c avx)
22048fffa06Sjeremyltifeq ($(AVX),1)
22148fffa06Sjeremylt  AVX_STATUS = Enabled
22248fffa06Sjeremylt  libceed.c += $(avx.c)
22348fffa06Sjeremylt  BACKENDS += /cpu/self/avx
22448fffa06Sjeremyltendif
22548fffa06Sjeremylt
226*8d713cf6Sjeremylt# libXSMM Backends
227*8d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
228*8d713cf6Sjeremylt  $(libceed) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
229*8d713cf6Sjeremylt  $(libceed) : LDLIBS += -lxsmm -ldl -lblas
230*8d713cf6Sjeremylt  libceed.c += $(xsmm.c)
231*8d713cf6Sjeremylt  $(xsmm.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(XSMM_DIR)/include
232*8d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
233*8d713cf6Sjeremyltendif
234*8d713cf6Sjeremylt
23548fffa06Sjeremylt# OCCA Backends
2367f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
237fc377ca6SJed Brown  $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
23812123fd5Scamierjs  $(libceed) : LDLIBS += -locca
23987174f08SJed Brown  libceed.c += $(occa.c)
24087174f08SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include
241a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
24221ae6867Scamierjsendif
24323072ed2SVeselin Dobrev
2449f0427d9SYohann# Cuda Backend
2455a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
2465a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
2475a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
2489f0427d9SYohann  $(libceed) : CFLAGS += -I$(CUDA_DIR)/include
2499f0427d9SYohann  $(libceed) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
2509f0427d9SYohann  $(libceed) : LDLIBS += -lcudart -lnvrtc -lcuda
2519f0427d9SYohann  libceed.c  += $(cuda.c)
2529f0427d9SYohann  libceed.cu += $(cuda.cu)
2539f0427d9SYohann  BACKENDS += /gpu/cuda
2549f0427d9SYohannendif
2559f0427d9SYohann
2569f0427d9SYohann# MAGMA Backend
2579f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
2589f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
2591dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
2601dc2661bSVeselin Dobrev  omp_link = -fopenmp
2611dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
2627692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
2637692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
2647692a9b0SVeselin Dobrev  $(libceed)           : LDLIBS += $(magma_link)
2657692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
266c4acb06bSStan Tomov  libceed.c  += $(magma_allsrc.c)
267c4acb06bSStan Tomov  libceed.cu += $(magma_allsrc.cu)
268c4acb06bSStan Tomov  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
269c4acb06bSStan 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
270ce41f623SJed Brown  BACKENDS += /gpu/magma
27182b77998SStan Tomov  endif
2725a9ca9adSVeselin Dobrevendif
273755585ceSStan Tomov
274ce41f623SJed Brownexport BACKENDS
275ce41f623SJed Brown
276755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c
27729715310SJed Brown%_tmp.c %_cuda.cu : %.c
278755585ceSStan Tomov	$(magma_preprocessor) $<
279755585ceSStan Tomov
28023072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
28123072ed2SVeselin Dobrev$(libceed.o): | info-backends
28223072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
28321ae6867Scamierjs	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
28491b7489eSJed Brown
28558e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
286b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
287ae3cba82Scamierjs
28858e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
289755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
290755585ceSStan Tomov
291b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
29234fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
29378b5556aScamierjs
29432d74c32SThilina Rathnayake$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR
29534fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
29632d74c32SThilina Rathnayake
297182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
29834fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
29991b7489eSJed Brown
300182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
30134fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
302673d494eSThilina Rathnayake
30316c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
30416c6c054SJed Brown	$(MAKE) -C examples/mfem CEED_DIR=`pwd` $*
30516c6c054SJed Brown	mv examples/mfem/$* $@
30616c6c054SJed Brown
3077f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
308e797ab98SJed Brown	$(MAKE) -C examples/petsc CEED_DIR=`pwd` $*
309e797ab98SJed Brown	mv examples/petsc/$* $@
310e797ab98SJed Brown
3112c6ea02fSJed Brown$(tests) $(examples) : $(libceed)
312fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
3134859b599SJed Brown
314dad465e7SJed Brownrun-% : $(OBJDIR)/%
315b5b03409SJed Brown	@tests/tap.sh $(<:build/%=%)
3162158b1b0Sjeremylt# Test core libCEED
317dad465e7SJed Browntest : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%)
3182158b1b0Sjeremylt
3193b56482dScamierjs# run test target in parallel
3206850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
3213b56482dScamierjs# CPU C tests only for backend %
3223f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
3234859b599SJed Brown
324dad465e7SJed Brownprove : $(tests) $(examples)
325a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
326dad465e7SJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%)
3273b56482dScamierjs# run prove target in parallel
3286850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
329bfa078e6SJed Brown
330f9fa8c39Sjeremyltalltests := $(tests) $(examples) $(if $(MFEM_DIR),$(mfemexamples)) $(if $(PETSC_DIR),$(petscexamples))
3317f6cf205SJed Brownprove-all : $(alltests)
3322158b1b0Sjeremylt	$(info Testing backends: $(BACKENDS))
333e797ab98SJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(alltests:$(OBJDIR)/%=%)
3342158b1b0Sjeremylt
3352c6ea02fSJed Brownexamples : $(examples)
3362c6ea02fSJed Brown
3376ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
338d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
339d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
3406ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
3416ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
3420e439e50SJed Brown
343bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
344cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
345cc6ff0d7SJed Brown
346cc6ff0d7SJed Brownokl-cache :
347cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
348cc6ff0d7SJed Brown
349cc6ff0d7SJed Brownokl-clear:
350cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
351a5ba6ca9Scamierjs
352d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
353bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
354bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
3551e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
356f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
3571e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
3581e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
359bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
360d5217624SJed Brown
36123072ed2SVeselin Dobrev.PHONY : cln clean print test tst prove prv examples style install doc okl-cache okl-clear
362d635b4c6Scamierjs
3636e5d1fd9Scamierjscln clean :
364df0ef7e4SVeselin Dobrev	$(RM) -r $(OBJDIR) $(LIBDIR)
365182fbe45STzanio	$(MAKE) -C examples/ceed clean
366f3ea3031SVeselin Dobrev	$(MAKE) -C examples/mfem clean
367182fbe45STzanio	$(MAKE) -C examples/petsc clean
368111c3977SJed Brown	(cd examples/nek5000 && bash make-nek-examples.sh clean)
369c4acb06bSStan Tomov	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
3704859b599SJed Brown
37107838a1cSTzaniodistclean : clean
3728c23e06aSJed Brown	$(RM) -r doc/html
37307838a1cSTzanio
3740ab95609SJed Browndoc :
3757bd3a522STzanio	doxygen Doxyfile
3767bd3a522STzanio
377f2fa494dScamierjsstyle :
3784e3516aeSJed Brown	astyle --style=google --indent=spaces=2 --max-code-length=80 \
3790dbfdfc5SJed Brown            --keep-one-line-statements --keep-one-line-blocks --lineend=linux \
380746e9b11SJed Brown            --suffix=none --preserve-date --formatted \
381a8de75f0Sjeremylt            --exclude=include/ceedf.h --exclude=tests/t310-basis-f.h \
38253b828d7SJed Brown            include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
383a8de75f0Sjeremylt            examples/*/*.[ch] examples/*/*.[ch]pp -i
3840dbfdfc5SJed Brown
3854859b599SJed Brownprint :
3864859b599SJed Brown	@echo $(VAR)=$($(VAR))
387582447c9SJed Brown
3889df38c42SVeselin Dobrevprint-% :
3899df38c42SVeselin Dobrev	$(info [ variable name]: $*)
3909df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
3919df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
3929df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
3939df38c42SVeselin Dobrev	$(info )
3949df38c42SVeselin Dobrev	@true
3959df38c42SVeselin Dobrev
39643fb898aSJed Brown-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d)
397