xref: /libCEED/Makefile (revision 4e79ff5b1769298992419608d32a975e68520b8e)
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
368d713cf6Sjeremylt# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
378d713cf6SjeremyltXSMM_DIR ?= ../libxsmm
388d713cf6Sjeremylt
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
482f4d9adbSJeremy L Thompson# Check for PETSc in ../petsc
492f4d9adbSJeremy L Thompsonifneq ($(wildcard ../petsc/lib/libpetsc.*),)
502f4d9adbSJeremy L Thompson  PETSC_DIR ?= ../petsc
512f4d9adbSJeremy L Thompsonendif
522f4d9adbSJeremy L Thompson
53bf000209STzanio# Warning: SANTIZ options still don't run with /gpu/occa
5412123fd5Scamierjs# export LSAN_OPTIONS=suppressions=.asanignore
55c12ddcb5ScamierjsAFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
5632d74c32SThilina Rathnayake
5748fffa06SjeremyltOPT    = -O -g -march=native -ffp-contract=fast
58323c739cSJed BrownCFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
599f0427d9SYohannNVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
601dc2661bSVeselin Dobrev# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
611dc2661bSVeselin Dobrevifneq ($(filter %xlf %xlf_r,$(FC)),)
6210da579bSJeremy L Thompson  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
63323c739cSJed Brownelse # gfortran/Intel-style options
6410da579bSJeremy L Thompson  FFLAGS = -cpp     $(OPT) -ffree-form -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
651dc2661bSVeselin Dobrevendif
661b58aefaScamierjs
6732d74c32SThilina Rathnayakeifeq ($(UNDERSCORE), 1)
6832d74c32SThilina Rathnayake  CFLAGS += -DUNDERSCORE
6932d74c32SThilina Rathnayakeendif
7032d74c32SThilina Rathnayake
71a6f4783aSJed Brownifeq ($(COVERAGE), 1)
72a6f4783aSJed Brown  CFLAGS += --coverage
73a6f4783aSJed Brown  LDFLAGS += --coverage
74a6f4783aSJed Brownendif
75a6f4783aSJed Brown
764dd6f121ScamierjsCFLAGS += $(if $(ASAN),$(AFLAGS))
774dd6f121ScamierjsFFLAGS += $(if $(ASAN),$(AFLAGS))
784dd6f121ScamierjsLDFLAGS += $(if $(ASAN),$(AFLAGS))
796ea7c6c1SJed BrownCPPFLAGS = -I./include
80582447c9SJed BrownLDLIBS = -lm
8191b7489eSJed BrownOBJDIR := build
826ea7c6c1SJed BrownLIBDIR := lib
836ea7c6c1SJed Brown
84d5217624SJed Brown# Installation variables
85d5217624SJed Brownprefix ?= /usr/local
86d5217624SJed Brownbindir = $(prefix)/bin
87d5217624SJed Brownlibdir = $(prefix)/lib
88bf3e26f6SVeselin Dobrevokldir = $(libdir)/okl
89d5217624SJed Brownincludedir = $(prefix)/include
90d5217624SJed Brownpkgconfigdir = $(libdir)/pkgconfig
91d5217624SJed BrownINSTALL = install
92d5217624SJed BrownINSTALL_PROGRAM = $(INSTALL)
93d5217624SJed BrownINSTALL_DATA = $(INSTALL) -m644
94d5217624SJed Brown
953b56482dScamierjs# Get number of processors of the machine
9669762e1fScamierjsNPROCS := $(shell getconf _NPROCESSORS_ONLN)
973b56482dScamierjs# prepare make options to run in parallel
9882985883ScamierjsMFLAGS := -j $(NPROCS) --warn-undefined-variables \
9921ae6867Scamierjs                       --no-print-directory --no-keep-going
10087e762eaSJed Brown
101bfa078e6SJed BrownPROVE ?= prove
1023a1ec3cdSJed BrownPROVE_OPTS ?= -j $(NPROCS)
1035c719ab0SJed BrownDARWIN := $(filter Darwin,$(shell uname -s))
1045c719ab0SJed BrownSO_EXT := $(if $(DARWIN),dylib,so)
1059df38c42SVeselin Dobrev
1066ea7c6c1SJed Brownceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
10791b7489eSJed Brownlibceed := $(LIBDIR)/libceed.$(SO_EXT)
108d7b241e6Sjeremyltlibceed.c := $(wildcard interface/ceed*.c)
1094a2e7687SjeremyltBACKENDS_BUILTIN := /cpu/self/ref /cpu/self/tmpl /cpu/self/blocked
110d20f937dSJed BrownBACKENDS := $(BACKENDS_BUILTIN)
111bf000209STzanio
112bf000209STzanio# Tests
11357c64913Sjeremylttests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
11457c64913Sjeremylttests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f))
11591b7489eSJed Browntests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
1163f3e7340Scamierjsctests    := $(tests)
11732d74c32SThilina Rathnayaketests     += $(tests.f:tests/%.f=$(OBJDIR)/%)
11832d74c32SThilina Rathnayake#examples
119182fbe45STzanioexamples.c := $(sort $(wildcard examples/ceed/*.c))
120182fbe45STzanioexamples.f := $(sort $(wildcard examples/ceed/*.f))
121182fbe45STzanioexamples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
122182fbe45STzanioexamples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
1232158b1b0Sjeremylt#mfemexamples
1242158b1b0Sjeremyltmfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
12516c6c054SJed Brownmfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
126e797ab98SJed Brownpetscexamples.c := $(sort $(wildcard examples/petsc/*.c))
127e797ab98SJed Brownpetscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
128e797ab98SJed Brown
12948fffa06Sjeremylt# backends/[ref, template, blocked, avx, occa, magma]
130ae3cba82Scamierjsref.c      := $(sort $(wildcard backends/ref/*.c))
131a718229cSjeremylttemplate.c := $(sort $(wildcard backends/template/*.c))
1329f0427d9SYohanncuda.c     := $(sort $(wildcard backends/cuda/*.c))
1339f0427d9SYohanncuda.cu    := $(sort $(wildcard backends/cuda/*.cu))
1344a2e7687Sjeremyltblocked.c  := $(sort $(wildcard backends/blocked/*.c))
13548fffa06Sjeremyltavx.c      := $(sort $(wildcard backends/avx/*.c))
1368d713cf6Sjeremyltxsmm.c     := $(sort $(wildcard backends/xsmm/*.c))
137ae3cba82Scamierjsocca.c     := $(sort $(wildcard backends/occa/*.c))
138755585ceSStan Tomovmagma_preprocessor := python backends/magma/gccm.py
139c4acb06bSStan Tomovmagma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
140c4acb06bSStan Tomovmagma_dsrc     := $(wildcard backends/magma/magma_d*.c)
141c4acb06bSStan Tomovmagma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
142c4acb06bSStan Tomovmagma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
143c4acb06bSStan Tomovmagma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
144c4acb06bSStan Tomovmagma_allsrc.cu:= $(magma_tmp.cu)
14582985883Scamierjs
1469bdc3d68Scamierjs# Output using the 216-color rules mode
14718a724fcScamierjsrule_file = $(notdir $(1))
14818a724fcScamierjsrule_path = $(patsubst %/,%,$(dir $(1)))
14918a724fcScamierjslast_path = $(notdir $(patsubst %/,%,$(dir $(1))))
1503c5d0cdfSJed Brownansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
151abb87f81Scamierjsemacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
152abb87f81Scamierjscolor_out = @if [ -t 1 ]; then \
15318a724fcScamierjs				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
1543c5d0cdfSJed Brown					$(1) $(call ansicolor,$(2)) \
15518a724fcScamierjs					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
15618a724fcScamierjs				printf "  %10s %s\n" $(1) $(2); fi
157f797d7b2Scamierjs# if TERM=dumb, use it, otherwise switch to the term one
158abb87f81Scamierjsoutput = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
15982985883Scamierjs
1609bdc3d68Scamierjs# if V is set to non-nil, turn the verbose mode
16118a724fcScamierjsquiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
16221ae6867Scamierjs
163da72e7fcSJed Brown# Cancel built-in and old-fashioned implicit rules which we don't use
1649df38c42SVeselin Dobrev.SUFFIXES:
165da72e7fcSJed Brown
16691b7489eSJed Brown.SECONDEXPANSION: # to expand $$(@D)/.DIR
1679df38c42SVeselin Dobrev
168c4acb06bSStan Tomov.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
16914c1ded1SStan Tomov
17091b7489eSJed Brown%/.DIR :
17191b7489eSJed Brown	@mkdir -p $(@D)
17291b7489eSJed Brown	@touch $@
17391b7489eSJed Brown
17491b7489eSJed Brown.PRECIOUS: %/.DIR
17591b7489eSJed Brown
17623072ed2SVeselin Dobrevlib: $(libceed) $(ceed.pc)
17723072ed2SVeselin Dobrev# run 'lib' target in parallel
1782f4d9adbSJeremy L Thompsonpar:;@$(MAKE) $(MFLAGS) V=$(V) lib
179d20f937dSJed Brownbackend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
180bf3e26f6SVeselin Dobrevinfo:
181bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
182bf3e26f6SVeselin Dobrev	$(info CC         = $(CC))
183bf3e26f6SVeselin Dobrev	$(info FC         = $(FC))
184bf3e26f6SVeselin Dobrev	$(info CPPFLAGS   = $(CPPFLAGS))
185bf3e26f6SVeselin Dobrev	$(info CFLAGS     = $(value CFLAGS))
186bf3e26f6SVeselin Dobrev	$(info FFLAGS     = $(value FFLAGS))
187bf3e26f6SVeselin Dobrev	$(info NVCCFLAGS  = $(value NVCCFLAGS))
188bf3e26f6SVeselin Dobrev	$(info LDFLAGS    = $(value LDFLAGS))
189bf3e26f6SVeselin Dobrev	$(info LDLIBS     = $(LDLIBS))
190bf3e26f6SVeselin Dobrev	$(info OPT        = $(OPT))
191bf3e26f6SVeselin Dobrev	$(info AFLAGS     = $(AFLAGS))
192bf3e26f6SVeselin Dobrev	$(info ASAN       = $(or $(ASAN),(empty)))
193bf3e26f6SVeselin Dobrev	$(info V          = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
194bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
19548fffa06Sjeremylt	$(info AVX_STATUS = $(AVX_STATUS)$(call backend_status,/cpu/self/avx))
1968d713cf6Sjeremylt	$(info XSMM_DIR   = $(XSMM_DIR)$(call backend_status,/cpu/xsmm/serial /cpu/xsmm/blocked))
197d20f937dSJed Brown	$(info OCCA_DIR   = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
198d20f937dSJed Brown	$(info MAGMA_DIR  = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
199d20f937dSJed Brown	$(info CUDA_DIR   = $(CUDA_DIR)$(call backend_status,/gpu/magma))
200bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
201bf3e26f6SVeselin Dobrev	$(info MFEM_DIR   = $(MFEM_DIR))
202bf3e26f6SVeselin Dobrev	$(info PETSC_DIR  = $(PETSC_DIR))
203bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
204bf3e26f6SVeselin Dobrev	$(info prefix       = $(prefix))
205bf3e26f6SVeselin Dobrev	$(info includedir   = $(value includedir))
206bf3e26f6SVeselin Dobrev	$(info libdir       = $(value libdir))
207bf3e26f6SVeselin Dobrev	$(info okldir       = $(value okldir))
208bf3e26f6SVeselin Dobrev	$(info pkgconfigdir = $(value pkgconfigdir))
209bf3e26f6SVeselin Dobrev	$(info ------------------------------------)
210bf3e26f6SVeselin Dobrev	@true
21123072ed2SVeselin Dobrevinfo-backends:
212d20f937dSJed Brown	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
2132f4d9adbSJeremy L Thompson.PHONY: lib all par info info-backends
2140e439e50SJed Brown
21524d002f4SJed Brown$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
21669762e1fScamierjs
21748fffa06Sjeremylt# Standard Backends
21887174f08SJed Brownlibceed.c += $(ref.c)
219a718229cSjeremyltlibceed.c += $(template.c)
2204a2e7687Sjeremyltlibceed.c += $(blocked.c)
22123072ed2SVeselin Dobrev
22248fffa06Sjeremylt# AVX Backed
22348fffa06SjeremyltAVX_STATUS = Disabled
22448fffa06SjeremyltAVX := $(shell $(CC) $(CFLAGS) -v -E - < /dev/null 2>&1 | grep -c avx)
22548fffa06Sjeremyltifeq ($(AVX),1)
22648fffa06Sjeremylt  AVX_STATUS = Enabled
22748fffa06Sjeremylt  libceed.c += $(avx.c)
22848fffa06Sjeremylt  BACKENDS += /cpu/self/avx
22948fffa06Sjeremyltendif
23048fffa06Sjeremylt
2318d713cf6Sjeremylt# libXSMM Backends
2328d713cf6Sjeremyltifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
2338d713cf6Sjeremylt  $(libceed) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
2348d713cf6Sjeremylt  $(libceed) : LDLIBS += -lxsmm -ldl -lblas
2358d713cf6Sjeremylt  libceed.c += $(xsmm.c)
2368d713cf6Sjeremylt  $(xsmm.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(XSMM_DIR)/include
2378d713cf6Sjeremylt  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
2388d713cf6Sjeremyltendif
2398d713cf6Sjeremylt
24048fffa06Sjeremylt# OCCA Backends
2417f5ff99bSVeselin Dobrevifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
242fc377ca6SJed Brown  $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
24312123fd5Scamierjs  $(libceed) : LDLIBS += -locca
24487174f08SJed Brown  libceed.c += $(occa.c)
24587174f08SJed Brown  $(occa.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -I$(OCCA_DIR)/include
246a953af89SJed Brown  BACKENDS += /cpu/occa /gpu/occa /omp/occa
24721ae6867Scamierjsendif
24823072ed2SVeselin Dobrev
2499f0427d9SYohann# Cuda Backend
2505a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
2515a9ca9adSVeselin DobrevCUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
2525a9ca9adSVeselin Dobrevifneq ($(CUDA_LIB_DIR),)
2539f0427d9SYohann  $(libceed) : CFLAGS += -I$(CUDA_DIR)/include
2549f0427d9SYohann  $(libceed) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
2559f0427d9SYohann  $(libceed) : LDLIBS += -lcudart -lnvrtc -lcuda
2569f0427d9SYohann  libceed.c  += $(cuda.c)
2579f0427d9SYohann  libceed.cu += $(cuda.cu)
2589f0427d9SYohann  BACKENDS += /gpu/cuda
2599f0427d9SYohannendif
2609f0427d9SYohann
2619f0427d9SYohann# MAGMA Backend
2629f0427d9SYohannifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
2639f0427d9SYohann  ifneq ($(CUDA_LIB_DIR),)
2641dc2661bSVeselin Dobrev  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
2651dc2661bSVeselin Dobrev  omp_link = -fopenmp
2661dc2661bSVeselin Dobrev  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
2677692a9b0SVeselin Dobrev  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
2687692a9b0SVeselin Dobrev  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
2697692a9b0SVeselin Dobrev  $(libceed)           : LDLIBS += $(magma_link)
2707692a9b0SVeselin Dobrev  $(tests) $(examples) : LDLIBS += $(magma_link)
271c4acb06bSStan Tomov  libceed.c  += $(magma_allsrc.c)
272c4acb06bSStan Tomov  libceed.cu += $(magma_allsrc.cu)
273c4acb06bSStan Tomov  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) : CFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
274c4acb06bSStan 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
275ce41f623SJed Brown  BACKENDS += /gpu/magma
27682b77998SStan Tomov  endif
2775a9ca9adSVeselin Dobrevendif
278755585ceSStan Tomov
279ce41f623SJed Brownexport BACKENDS
280ce41f623SJed Brown
281755585ceSStan Tomov# generate magma_tmp.c and magma_cuda.cu from magma.c
28229715310SJed Brown%_tmp.c %_cuda.cu : %.c
283755585ceSStan Tomov	$(magma_preprocessor) $<
284755585ceSStan Tomov
28523072ed2SVeselin Dobrevlibceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
28623072ed2SVeselin Dobrev$(libceed.o): | info-backends
28723072ed2SVeselin Dobrev$(libceed) : $(libceed.o) | $$(@D)/.DIR
28821ae6867Scamierjs	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
28991b7489eSJed Brown
29058e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
291b5b03409SJed Brown	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
292ae3cba82Scamierjs
29358e8d3b7SJed Brown$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
294755585ceSStan Tomov	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
295755585ceSStan Tomov
296b5b03409SJed Brown$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
29734fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
29878b5556aScamierjs
29932d74c32SThilina Rathnayake$(OBJDIR)/% : tests/%.f | $$(@D)/.DIR
30034fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
30132d74c32SThilina Rathnayake
302182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
30334fdc922SJed Brown	$(call quiet,LINK.c) -o $@ $(abspath $<) -lceed $(LDLIBS)
30491b7489eSJed Brown
305182fbe45STzanio$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
30634fdc922SJed Brown	$(call quiet,LINK.F) -o $@ $(abspath $<) -lceed $(LDLIBS)
307673d494eSThilina Rathnayake
30816c6c054SJed Brown$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
3092f4d9adbSJeremy L Thompson	$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
3102f4d9adbSJeremy L Thompson	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
31116c6c054SJed Brown	mv examples/mfem/$* $@
31216c6c054SJed Brown
3137f6cf205SJed Brown$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
3142f4d9adbSJeremy L Thompson	$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
3152f4d9adbSJeremy L Thompson	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
316e797ab98SJed Brown	mv examples/petsc/$* $@
317e797ab98SJed Brown
3182c6ea02fSJed Brown$(tests) $(examples) : $(libceed)
319fc377ca6SJed Brown$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
3204859b599SJed Brown
321dad465e7SJed Brownrun-% : $(OBJDIR)/%
322b5b03409SJed Brown	@tests/tap.sh $(<:build/%=%)
3232158b1b0Sjeremylt# Test core libCEED
324dad465e7SJed Browntest : $(tests:$(OBJDIR)/%=run-%) $(examples:$(OBJDIR)/%=run-%)
3252158b1b0Sjeremylt
3263b56482dScamierjs# run test target in parallel
3276850bcb5Scamierjstst : ;@$(MAKE) $(MFLAGS) V=$(V) test
3283b56482dScamierjs# CPU C tests only for backend %
3293f3e7340Scamierjsctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
3304859b599SJed Brown
331dad465e7SJed Brownprove : $(tests) $(examples)
332a5dc8077SJed Brown	$(info Testing backends: $(BACKENDS))
333dad465e7SJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(tests:$(OBJDIR)/%=%) $(examples:$(OBJDIR)/%=%)
3343b56482dScamierjs# run prove target in parallel
3356850bcb5Scamierjsprv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
336bfa078e6SJed Brown
3372f4d9adbSJeremy L Thompsonallexamples := $(examples) $(if $(MFEM_DIR),$(mfemexamples)) $(if $(PETSC_DIR),$(petscexamples))
3382f4d9adbSJeremy L Thompsonalltests := $(tests) $(allexamples)
3397f6cf205SJed Brownprove-all : $(alltests)
3402158b1b0Sjeremylt	$(info Testing backends: $(BACKENDS))
341e797ab98SJed Brown	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(alltests:$(OBJDIR)/%=%)
3422158b1b0Sjeremylt
3432f4d9adbSJeremy L Thompsonall: $(alltests)
3442f4d9adbSJeremy L Thompson
3452f4d9adbSJeremy L Thompsonexamples : $(allexamples)
3462f4d9adbSJeremy L Thompson
3472f4d9adbSJeremy L Thompson# Benchmarks
3482f4d9adbSJeremy L Thompsonallbenchmarks = petsc-bp1 petsc-bp3
349*4e79ff5bSVeselin Dobrevbench_targets = $(addprefix bench-,$(allbenchmarks))
350*4e79ff5bSVeselin Dobrev.PHONY: $(bench_targets) benchmarks
351*4e79ff5bSVeselin Dobrev$(bench_targets): bench-%: $(OBJDIR)/%
3522f4d9adbSJeremy L Thompson	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
353*4e79ff5bSVeselin Dobrevbenchmarks: $(bench_targets)
3542c6ea02fSJed Brown
3556ea7c6c1SJed Brown$(ceed.pc) : pkgconfig-prefix = $(abspath .)
356d5217624SJed Brown$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
357d5217624SJed Brown.INTERMEDIATE : $(OBJDIR)/ceed.pc
3586ea7c6c1SJed Brown%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
3596ea7c6c1SJed Brown	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
3600e439e50SJed Brown
361bf3e26f6SVeselin DobrevOCCA        := $(OCCA_DIR)/bin/occa
362cc6ff0d7SJed BrownOKL_KERNELS := $(wildcard backends/occa/*.okl)
363cc6ff0d7SJed Brown
364cc6ff0d7SJed Brownokl-cache :
365cc6ff0d7SJed Brown	$(OCCA) cache ceed $(OKL_KERNELS)
366cc6ff0d7SJed Brown
367cc6ff0d7SJed Brownokl-clear:
368cc6ff0d7SJed Brown	$(OCCA) clear -y -l ceed
369a5ba6ca9Scamierjs
370d5217624SJed Browninstall : $(libceed) $(OBJDIR)/ceed.pc
371bf3e26f6SVeselin Dobrev	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
372bf3e26f6SVeselin Dobrev	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
3731e25a746SJed Brown	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
374f91e0974SThilina Rathnayake	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
3751e25a746SJed Brown	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
3761e25a746SJed Brown	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
377bf3e26f6SVeselin Dobrev	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
378d5217624SJed Brown
37923072ed2SVeselin Dobrev.PHONY : cln clean print test tst prove prv examples style install doc okl-cache okl-clear
380d635b4c6Scamierjs
3816e5d1fd9Scamierjscln clean :
382df0ef7e4SVeselin Dobrev	$(RM) -r $(OBJDIR) $(LIBDIR)
383182fbe45STzanio	$(MAKE) -C examples/ceed clean
384f3ea3031SVeselin Dobrev	$(MAKE) -C examples/mfem clean
385182fbe45STzanio	$(MAKE) -C examples/petsc clean
386111c3977SJed Brown	(cd examples/nek5000 && bash make-nek-examples.sh clean)
387c4acb06bSStan Tomov	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
3882f4d9adbSJeremy L Thompson	$(RM) -rf benchmarks/*output.txt
3894859b599SJed Brown
39007838a1cSTzaniodistclean : clean
3918c23e06aSJed Brown	$(RM) -r doc/html
39207838a1cSTzanio
3930ab95609SJed Browndoc :
3947bd3a522STzanio	doxygen Doxyfile
3957bd3a522STzanio
396f2fa494dScamierjsstyle :
3974e3516aeSJed Brown	astyle --style=google --indent=spaces=2 --max-code-length=80 \
3980dbfdfc5SJed Brown            --keep-one-line-statements --keep-one-line-blocks --lineend=linux \
399746e9b11SJed Brown            --suffix=none --preserve-date --formatted \
400a8de75f0Sjeremylt            --exclude=include/ceedf.h --exclude=tests/t310-basis-f.h \
40153b828d7SJed Brown            include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
402a8de75f0Sjeremylt            examples/*/*.[ch] examples/*/*.[ch]pp -i
4030dbfdfc5SJed Brown
4044859b599SJed Brownprint :
4054859b599SJed Brown	@echo $(VAR)=$($(VAR))
406582447c9SJed Brown
4079df38c42SVeselin Dobrevprint-% :
4089df38c42SVeselin Dobrev	$(info [ variable name]: $*)
4099df38c42SVeselin Dobrev	$(info [        origin]: $(origin $*))
4109df38c42SVeselin Dobrev	$(info [         value]: $(value $*))
4119df38c42SVeselin Dobrev	$(info [expanded value]: $($*))
4129df38c42SVeselin Dobrev	$(info )
4139df38c42SVeselin Dobrev	@true
4149df38c42SVeselin Dobrev
41543fb898aSJed Brown-include $(libceed.c:%.c=build/%.d) $(tests.c:tests/%.c=build/%.d)
416