xref: /libCEED/Makefile (revision 77538c7a52d88968637ef790cd8ce9bc8a82950b)
1# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3# All Rights reserved. See files LICENSE and NOTICE for details.
4#
5# This file is part of CEED, a collection of benchmarks, miniapps, software
6# libraries and APIs for efficient high-order finite element and spectral
7# element discretizations for exascale applications. For more information and
8# source code availability see http://github.com/ceed.
9#
10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11# a collaborative effort of two U.S. Department of Energy organizations (Office
12# of Science and the National Nuclear Security Administration) responsible for
13# the planning and preparation of a capable exascale ecosystem, including
14# software, applications, hardware, advanced system engineering and early
15# testbed platforms, in support of the nation's exascale computing imperative.
16
17-include config.mk
18
19ifeq (,$(filter-out undefined default,$(origin CC)))
20  CC = gcc
21endif
22ifeq (,$(filter-out undefined default,$(origin FC)))
23  FC = gfortran
24endif
25NVCC ?= $(CUDA_DIR)/bin/nvcc
26
27# ASAN must be left empty if you don't want to use it
28ASAN ?=
29
30LDFLAGS ?=
31UNDERSCORE ?= 1
32
33# MFEM_DIR env variable should point to sibling directory
34ifneq ($(wildcard ../mfem/libmfem.*),)
35  MFEM_DIR ?= ../mfem
36endif
37
38# NEK5K_DIR env variable should point to sibling directory
39ifneq ($(wildcard ../Nek5000/*),)
40  NEK5K_DIR ?= ../Nek5000
41endif
42
43# XSMM_DIR env variable should point to XSMM master (github.com/hfp/libxsmm)
44XSMM_DIR ?= ../libxsmm
45
46# OCCA_DIR env variable should point to OCCA master (github.com/libocca/occa)
47OCCA_DIR ?= ../occa
48
49# env variable MAGMA_DIR can be used too
50MAGMA_DIR ?= ../magma
51# If CUDA_DIR is not set, check for nvcc, or resort to /usr/local/cuda
52CUDA_DIR  ?= $(or $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir \
53               $(shell which nvcc 2> /dev/null))))),/usr/local/cuda)
54
55# Check for PETSc in ../petsc
56ifneq ($(wildcard ../petsc/lib/libpetsc.*),)
57  PETSC_DIR ?= ../petsc
58endif
59
60# Warning: SANTIZ options still don't run with /gpu/occa
61# export LSAN_OPTIONS=suppressions=.asanignore
62AFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
63
64OPT    = -O -g -march=native -ffp-contract=fast -fopenmp-simd
65CFLAGS = -std=c99 $(OPT) -Wall -Wextra -Wno-unused-parameter -fPIC -MMD -MP
66NVCCFLAGS = -Xcompiler "$(OPT)" -Xcompiler -fPIC
67# If using the IBM XL Fortran (xlf) replace FFLAGS appropriately:
68ifneq ($(filter %xlf %xlf_r,$(FC)),)
69  FFLAGS = $(OPT) -ffree-form -qpreprocess -qextname -qpic -MMD
70else # gfortran/Intel-style options
71  FFLAGS = -cpp     $(OPT) -Wall -Wextra -Wno-unused-parameter -Wno-unused-dummy-argument -fPIC -MMD -MP
72endif
73
74ifeq ($(UNDERSCORE), 1)
75  CFLAGS += -DUNDERSCORE
76endif
77
78ifeq ($(COVERAGE), 1)
79  CFLAGS += --coverage
80  LDFLAGS += --coverage
81endif
82
83CFLAGS += $(if $(ASAN),$(AFLAGS))
84FFLAGS += $(if $(ASAN),$(AFLAGS))
85LDFLAGS += $(if $(ASAN),$(AFLAGS))
86CPPFLAGS = -I./include
87LDLIBS = -lm
88OBJDIR := build
89LIBDIR := lib
90
91# Installation variables
92prefix ?= /usr/local
93bindir = $(prefix)/bin
94libdir = $(prefix)/lib
95okldir = $(libdir)/okl
96includedir = $(prefix)/include
97pkgconfigdir = $(libdir)/pkgconfig
98INSTALL = install
99INSTALL_PROGRAM = $(INSTALL)
100INSTALL_DATA = $(INSTALL) -m644
101
102# Get number of processors of the machine
103NPROCS := $(shell getconf _NPROCESSORS_ONLN)
104# prepare make options to run in parallel
105MFLAGS := -j $(NPROCS) --warn-undefined-variables \
106                       --no-print-directory --no-keep-going
107
108PYTHON ?= python3
109PROVE ?= prove
110PROVE_OPTS ?= -j $(NPROCS)
111DARWIN := $(filter Darwin,$(shell uname -s))
112SO_EXT := $(if $(DARWIN),dylib,so)
113
114ceed.pc := $(LIBDIR)/pkgconfig/ceed.pc
115libceed := $(LIBDIR)/libceed.$(SO_EXT)
116CEED_LIBS = -lceed
117libceed.c := $(wildcard interface/ceed*.c)
118libceed_test := $(LIBDIR)/libceed_test.$(SO_EXT)
119libceeds = $(libceed) $(libceed_test)
120BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
121BACKENDS := $(BACKENDS_BUILTIN)
122
123# Tests
124tests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
125tests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
126tests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
127ctests    := $(tests)
128tests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
129#examples
130examples.c := $(sort $(wildcard examples/ceed/*.c))
131examples.f := $(sort $(wildcard examples/ceed/*.f))
132examples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
133examples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
134#mfemexamples
135mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
136mfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
137#nekexamples
138nekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr))
139nekexamples  := $(nekexamples.usr:examples/nek5000/%.usr=$(OBJDIR)/nek-%)
140#petscexamples
141petscexamples.c := $(sort $(wildcard examples/petsc/*.c))
142petscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
143#navierstokesexample
144navierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c))
145navierstokesexample  := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%)
146
147# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
148ref.c          := $(sort $(wildcard backends/ref/*.c))
149blocked.c      := $(sort $(wildcard backends/blocked/*.c))
150template.c     := $(sort $(wildcard backends/template/*.c))
151ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
152opt.c          := $(sort $(wildcard backends/opt/*.c))
153avx.c          := $(sort $(wildcard backends/avx/*.c))
154xsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
155cuda.c         := $(sort $(wildcard backends/cuda/*.c))
156cuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
157cuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
158cuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
159cuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
160cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
161occa.c         := $(sort $(wildcard backends/occa/*.c))
162magma_preprocessor := python backends/magma/gccm.py
163magma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
164magma_dsrc     := $(wildcard backends/magma/magma_d*.c)
165magma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
166magma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
167magma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
168magma_allsrc.cu:= $(magma_tmp.cu)
169
170# Output using the 216-color rules mode
171rule_file = $(notdir $(1))
172rule_path = $(patsubst %/,%,$(dir $(1)))
173last_path = $(notdir $(patsubst %/,%,$(dir $(1))))
174ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
175emacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
176color_out = @if [ -t 1 ]; then \
177				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
178					$(1) $(call ansicolor,$(2)) \
179					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
180				printf "  %10s %s\n" $(1) $(2); fi
181# if TERM=dumb, use it, otherwise switch to the term one
182output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
183
184# if V is set to non-nil, turn the verbose mode
185quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
186
187# Cancel built-in and old-fashioned implicit rules which we don't use
188.SUFFIXES:
189
190.SECONDEXPANSION: # to expand $$(@D)/.DIR
191
192.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
193
194%/.DIR :
195	@mkdir -p $(@D)
196	@touch $@
197
198.PRECIOUS: %/.DIR
199
200lib: $(libceed) $(ceed.pc)
201# run 'lib' target in parallel
202par:;@$(MAKE) $(MFLAGS) V=$(V) lib
203backend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
204info:
205	$(info ------------------------------------)
206	$(info CC            = $(CC))
207	$(info FC            = $(FC))
208	$(info CPPFLAGS      = $(CPPFLAGS))
209	$(info CFLAGS        = $(value CFLAGS))
210	$(info FFLAGS        = $(value FFLAGS))
211	$(info NVCCFLAGS     = $(value NVCCFLAGS))
212	$(info LDFLAGS       = $(value LDFLAGS))
213	$(info LDLIBS        = $(LDLIBS))
214	$(info OPT           = $(OPT))
215	$(info AFLAGS        = $(AFLAGS))
216	$(info ASAN          = $(or $(ASAN),(empty)))
217	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
218	$(info ------------------------------------)
219	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck))
220	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
221	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
222	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
223	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
224	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
225	$(info ------------------------------------)
226	$(info MFEM_DIR      = $(MFEM_DIR))
227	$(info NEK5K_DIR     = $(NEK5K_DIR))
228	$(info PETSC_DIR     = $(PETSC_DIR))
229	$(info ------------------------------------)
230	$(info prefix        = $(prefix))
231	$(info includedir    = $(value includedir))
232	$(info libdir        = $(value libdir))
233	$(info okldir        = $(value okldir))
234	$(info pkgconfigdir  = $(value pkgconfigdir))
235	$(info ------------------------------------)
236	@true
237info-backends:
238	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
239.PHONY: lib all par info info-backends
240
241$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
242$(libceed_test) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed_test)))
243
244# Standard Backends
245libceed.c += $(ref.c)
246libceed.c += $(blocked.c)
247libceed.c += $(opt.c)
248
249# Testing Backends
250test_backends.c := $(template.c)
251TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
252
253# Memcheck Backend
254MEMCHK_STATUS = Disabled
255MEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
256ifeq ($(MEMCHK),1)
257  MEMCHK_STATUS = Enabled
258  libceed.c += $(ceedmemcheck.c)
259  BACKENDS += /cpu/self/ref/memcheck
260endif
261
262# AVX Backed
263AVX_STATUS = Disabled
264AVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c ' -mavx')
265ifeq ($(AVX),1)
266  AVX_STATUS = Enabled
267  libceed.c += $(avx.c)
268  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
269endif
270
271# libXSMM Backends
272ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
273  $(libceeds) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
274  $(libceeds) : LDLIBS += -lxsmm -ldl
275  MKL ?= 0
276  ifneq (0,$(MKL))
277    $(libceeds) : LDLIBS += -mkl
278  else
279    $(libceeds) : LDLIBS += -lblas
280  endif
281  libceed.c += $(xsmm.c)
282  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
283  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
284endif
285
286# OCCA Backends
287ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
288  $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
289  $(libceeds) : LDLIBS += -locca
290  libceed.c += $(occa.c)
291  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
292  BACKENDS += /cpu/occa /gpu/occa /omp/occa
293endif
294
295# Cuda Backend
296CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
297CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
298CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
299CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared
300ifneq ($(CUDA_LIB_DIR),)
301  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
302  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
303  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR_STUBS)
304  $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda
305  libceed.c  += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c)
306  libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu)
307  BACKENDS += $(CUDA_BACKENDS)
308endif
309
310# MAGMA Backend
311ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
312  ifneq ($(CUDA_LIB_DIR),)
313  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
314  omp_link = -fopenmp
315  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
316  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
317  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
318  $(libceeds)           : LDLIBS += $(magma_link)
319  $(tests) $(examples) : LDLIBS += $(magma_link)
320  libceed.c  += $(magma_allsrc.c)
321  libceed.cu += $(magma_allsrc.cu)
322  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
323  $(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
324  BACKENDS += /gpu/magma
325  endif
326endif
327
328export BACKENDS
329
330# generate magma_tmp.c and magma_cuda.cu from magma.c
331%_tmp.c %_cuda.cu : %.c
332	$(magma_preprocessor) $<
333
334libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
335$(libceed.o): | info-backends
336$(libceed) : $(libceed.o) | $$(@D)/.DIR
337	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
338
339$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
340	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
341
342$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
343	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
344
345$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
346	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
347
348$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
349	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
350
351$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
352	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
353
354$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
355	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
356
357$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
358	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
359	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
360	mv examples/mfem/$* $@
361
362$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
363	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
364	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
365	mv examples/petsc/$* $@
366
367$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
368	+$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
369	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
370	mv examples/navier-stokes/$* $@
371
372libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
373$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR
374	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
375
376$(examples) : $(libceed)
377$(tests) : $(libceed_test)
378$(tests) : CEED_LIBS = -lceed_test
379$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
380
381run-t% : BACKENDS += $(TEST_BACKENDS)
382run-% : $(OBJDIR)/%
383	@tests/tap.sh $(<:$(OBJDIR)/%=%)
384
385external_examples := \
386	$(if $(MFEM_DIR),$(mfemexamples)) \
387	$(if $(PETSC_DIR),$(petscexamples)) \
388	$(if $(NEK5K_DIR),$(nekexamples))
389
390allexamples = $(examples) $(external_examples)
391
392# The test and prove targets can be controlled via pattern searches.  The
393# default is to run tests and those examples that have no external dependencies.
394# Examples of finer grained control:
395#
396#   make test search='petsc mfem'      # PETSc and MFEM examples
397#   make prove search='t3'             # t3xx series tests
398#   make junit search='ex petsc'       # core ex* and PETSc tests
399search ?= t ex
400realsearch = $(search:%=%%)
401matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
402# Work around Nek examples not having normal targets
403matched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests)
404
405# Test core libCEED
406test : $(matched:$(OBJDIR)/%=run-%)
407
408# run test target in parallel
409tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
410# CPU C tests only for backend %
411ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
412
413prove : BACKENDS += $(TEST_BACKENDS)
414prove : $(matched_prereq)
415	$(info Testing backends: $(BACKENDS))
416	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
417# run prove target in parallel
418prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
419
420prepnektests:
421	(export CC FC && cd examples && make prepnektests)
422
423prove-all :
424	+$(MAKE) prove realsearch=%
425
426junit-t% : BACKENDS += $(TEST_BACKENDS)
427junit-% : $(OBJDIR)/%
428	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
429
430junit : $(matched:$(OBJDIR)/%=junit-%)
431
432all: $(alltests)
433
434examples : $(allexamples)
435
436# Benchmarks
437allbenchmarks = petsc-bps
438bench_targets = $(addprefix bench-,$(allbenchmarks))
439.PHONY: $(bench_targets) benchmarks
440$(bench_targets): bench-%: $(OBJDIR)/%
441	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
442benchmarks: $(bench_targets)
443
444$(ceed.pc) : pkgconfig-prefix = $(abspath .)
445$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
446.INTERMEDIATE : $(OBJDIR)/ceed.pc
447%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
448	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
449
450OCCA        := $(OCCA_DIR)/bin/occa
451OKL_KERNELS := $(wildcard backends/occa/*.okl)
452
453okl-cache :
454	$(OCCA) cache ceed $(OKL_KERNELS)
455
456okl-clear:
457	$(OCCA) clear -y -l ceed
458
459install : $(libceed) $(OBJDIR)/ceed.pc
460	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
461	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
462	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
463	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
464	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
465	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
466	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
467
468.PHONY : cln clean doc lib install all print test tst prove prv prove-all junit examples style tidy okl-cache okl-clear info info-backends
469
470cln clean :
471	$(RM) -r $(OBJDIR) $(LIBDIR)
472	$(MAKE) -C examples clean
473	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
474	$(RM) benchmarks/*output.txt
475
476distclean : clean
477	$(RM) -r doc/html config.mk
478
479doc :
480	doxygen Doxyfile
481
482style :
483	@astyle --options=.astylerc \
484          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
485            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
486              examples/*/*.[ch] examples/*/*.[ch]pp))
487
488CLANG_TIDY ?= clang-tidy
489%.c.tidy : %.c
490	$(CLANG_TIDY) $^ -- $(CPPFLAGS)
491
492tidy : $(libceed.c:%=%.tidy)
493
494print :
495	@echo $(VAR)=$($(VAR))
496
497print-% :
498	$(info [ variable name]: $*)
499	$(info [        origin]: $(origin $*))
500	$(info [         value]: $(value $*))
501	$(info [expanded value]: $($*))
502	$(info )
503	@true
504
505# "make configure" will autodetect any variables not passed on the
506# command line, caching the result in config.mk to be used on any
507# subsequent invocations of make.  For example,
508#
509#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
510#   make
511#   make prove
512configure :
513	@: > config.mk
514	@echo "CC = $(CC)" | tee -a config.mk
515	@echo "FC = $(FC)" | tee -a config.mk
516	@echo "NVCC = $(NVCC)" | tee -a config.mk
517	@echo "CFLAGS = $(CFLAGS)" | tee -a config.mk
518	@echo "CPPFLAGS = $(CPPFLAGS)" | tee -a config.mk
519	@echo "FFLAGS = $(FFLAGS)" | tee -a config.mk
520	@echo "LDFLAGS = $(LDFLAGS)" | tee -a config.mk
521	@echo "LDLIBS = $(LDLIBS)" | tee -a config.mk
522	@echo "MAGMA_DIR = $(MAGMA_DIR)" | tee -a config.mk
523	@echo "XSMM_DIR = $(XSMM_DIR)" | tee -a config.mk
524	@echo "CUDA_DIR = $(CUDA_DIR)" | tee -a config.mk
525	@echo "MFEM_DIR = $(MFEM_DIR)" | tee -a config.mk
526	@echo "PETSC_DIR = $(PETSC_DIR)" | tee -a config.mk
527	@echo "NEK5K_DIR = $(NEK5K_DIR)" | tee -a config.mk
528	@echo "Configuration cached in config.mk"
529
530.PHONY : configure
531
532-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
533