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