xref: /libCEED/Makefile (revision 567e4d0ab437eaa702c2bbae9fd5bc127fbdb57b)
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)
117BACKENDS_BUILTIN := /cpu/self/ref/serial /cpu/self/ref/blocked /cpu/self/opt/serial /cpu/self/opt/blocked
118BACKENDS := $(BACKENDS_BUILTIN)
119
120# Tests
121tests.c   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.c))
122tests.f   := $(sort $(wildcard tests/t[0-9][0-9][0-9]-*.f90))
123tests     := $(tests.c:tests/%.c=$(OBJDIR)/%)
124ctests    := $(tests)
125tests     += $(tests.f:tests/%.f90=$(OBJDIR)/%)
126#examples
127examples.c := $(sort $(wildcard examples/ceed/*.c))
128examples.f := $(sort $(wildcard examples/ceed/*.f))
129examples  := $(examples.c:examples/ceed/%.c=$(OBJDIR)/%)
130examples  += $(examples.f:examples/ceed/%.f=$(OBJDIR)/%)
131#mfemexamples
132mfemexamples.cpp := $(sort $(wildcard examples/mfem/*.cpp))
133mfemexamples  := $(mfemexamples.cpp:examples/mfem/%.cpp=$(OBJDIR)/mfem-%)
134#nekexamples
135nekexamples.usr := $(sort $(wildcard examples/nek5000/*.usr))
136nekexamples  := $(nekexamples.usr:examples/nek5000/%.usr=$(OBJDIR)/nek-%)
137#petscexamples
138petscexamples.c := $(sort $(wildcard examples/petsc/*.c))
139petscexamples  := $(petscexamples.c:examples/petsc/%.c=$(OBJDIR)/petsc-%)
140#navierstokesexample
141navierstokesexample.c := $(sort $(wildcard examples/navier-stokes/*.c))
142navierstokesexample  := $(navierstokesexample.c:examples/navier-stokes/%.c=$(OBJDIR)/navier-stokes-%)
143
144# backends/[ref, blocked, template, memcheck, opt, avx, occa, magma]
145ref.c          := $(sort $(wildcard backends/ref/*.c))
146blocked.c      := $(sort $(wildcard backends/blocked/*.c))
147template.c     := $(sort $(wildcard backends/template/*.c))
148ceedmemcheck.c := $(sort $(wildcard backends/memcheck/*.c))
149opt.c          := $(sort $(wildcard backends/opt/*.c))
150avx.c          := $(sort $(wildcard backends/avx/*.c))
151xsmm.c         := $(sort $(wildcard backends/xsmm/*.c))
152cuda.c         := $(sort $(wildcard backends/cuda/*.c))
153cuda.cu        := $(sort $(wildcard backends/cuda/*.cu))
154cuda-reg.c     := $(sort $(wildcard backends/cuda-reg/*.c))
155cuda-reg.cu    := $(sort $(wildcard backends/cuda-reg/*.cu))
156cuda-shared.c  := $(sort $(wildcard backends/cuda-shared/*.c))
157cuda-shared.cu := $(sort $(wildcard backends/cuda-shared/*.cu))
158occa.c         := $(sort $(wildcard backends/occa/*.c))
159magma_preprocessor := python backends/magma/gccm.py
160magma_pre_src  := $(filter-out %_tmp.c, $(wildcard backends/magma/ceed-*.c))
161magma_dsrc     := $(wildcard backends/magma/magma_d*.c)
162magma_tmp.c    := $(magma_pre_src:%.c=%_tmp.c)
163magma_tmp.cu   := $(magma_pre_src:%.c=%_cuda.cu)
164magma_allsrc.c := $(magma_dsrc) $(magma_tmp.c)
165magma_allsrc.cu:= $(magma_tmp.cu)
166
167# Output using the 216-color rules mode
168rule_file = $(notdir $(1))
169rule_path = $(patsubst %/,%,$(dir $(1)))
170last_path = $(notdir $(patsubst %/,%,$(dir $(1))))
171ansicolor = $(shell echo $(call last_path,$(1)) | cksum | cut -b1-2 | xargs -IS expr 2 \* S + 17)
172emacs_out = @printf "  %10s %s/%s\n" $(1) $(call rule_path,$(2)) $(call rule_file,$(2))
173color_out = @if [ -t 1 ]; then \
174				printf "  %10s \033[38;5;%d;1m%s\033[m/%s\n" \
175					$(1) $(call ansicolor,$(2)) \
176					$(call rule_path,$(2)) $(call rule_file,$(2)); else \
177				printf "  %10s %s\n" $(1) $(2); fi
178# if TERM=dumb, use it, otherwise switch to the term one
179output = $(if $(TERM:dumb=),$(call color_out,$1,$2),$(call emacs_out,$1,$2))
180
181# if V is set to non-nil, turn the verbose mode
182quiet = $(if $(V),$($(1)),$(call output,$1,$@);$($(1)))
183
184# Cancel built-in and old-fashioned implicit rules which we don't use
185.SUFFIXES:
186
187.SECONDEXPANSION: # to expand $$(@D)/.DIR
188
189.SECONDARY: $(magma_tmp.c) $(magma_tmp.cu)
190
191%/.DIR :
192	@mkdir -p $(@D)
193	@touch $@
194
195.PRECIOUS: %/.DIR
196
197lib: $(libceed) $(ceed.pc)
198# run 'lib' target in parallel
199par:;@$(MAKE) $(MFLAGS) V=$(V) lib
200backend_status = $(if $(filter $1,$(BACKENDS)), [backends: $1], [not found])
201info:
202	$(info ------------------------------------)
203	$(info CC            = $(CC))
204	$(info FC            = $(FC))
205	$(info CPPFLAGS      = $(CPPFLAGS))
206	$(info CFLAGS        = $(value CFLAGS))
207	$(info FFLAGS        = $(value FFLAGS))
208	$(info NVCCFLAGS     = $(value NVCCFLAGS))
209	$(info LDFLAGS       = $(value LDFLAGS))
210	$(info LDLIBS        = $(LDLIBS))
211	$(info OPT           = $(OPT))
212	$(info AFLAGS        = $(AFLAGS))
213	$(info ASAN          = $(or $(ASAN),(empty)))
214	$(info V             = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
215	$(info ------------------------------------)
216	$(info MEMCHK_STATUS = $(MEMCHK_STATUS)$(call backend_status,/cpu/self/ref/memcheck))
217	$(info AVX_STATUS    = $(AVX_STATUS)$(call backend_status,/cpu/self/avx/serial /cpu/self/avx/blocked))
218	$(info XSMM_DIR      = $(XSMM_DIR)$(call backend_status,/cpu/self/xsmm/serial /cpu/self/xsmm/blocked))
219	$(info OCCA_DIR      = $(OCCA_DIR)$(call backend_status,/cpu/occa /gpu/occa /omp/occa))
220	$(info MAGMA_DIR     = $(MAGMA_DIR)$(call backend_status,/gpu/magma))
221	$(info CUDA_DIR      = $(CUDA_DIR)$(call backend_status,$(CUDA_BACKENDS)))
222	$(info ------------------------------------)
223	$(info MFEM_DIR      = $(MFEM_DIR))
224	$(info NEK5K_DIR     = $(NEK5K_DIR))
225	$(info PETSC_DIR     = $(PETSC_DIR))
226	$(info ------------------------------------)
227	$(info prefix        = $(prefix))
228	$(info includedir    = $(value includedir))
229	$(info libdir        = $(value libdir))
230	$(info okldir        = $(value okldir))
231	$(info pkgconfigdir  = $(value pkgconfigdir))
232	$(info ------------------------------------)
233	@true
234info-backends:
235	$(info make: 'lib' with optional backends: $(filter-out $(BACKENDS_BUILTIN),$(BACKENDS)))
236.PHONY: lib all par info info-backends
237
238$(libceed) : LDFLAGS += $(if $(DARWIN), -install_name @rpath/$(notdir $(libceed)))
239
240# Standard Backends
241libceed.c += $(ref.c)
242libceed.c += $(blocked.c)
243libceed.c += $(opt.c)
244
245# Testing Backends
246test_backends.c := $(template.c)
247TEST_BACKENDS := /cpu/self/tmpl /cpu/self/tmpl/sub
248
249# Memcheck Backend
250MEMCHK_STATUS = Disabled
251MEMCHK := $(shell echo "\#include <valgrind/memcheck.h>" | $(CC) $(CPPFLAGS) -E - >/dev/null 2>&1 && echo 1)
252ifeq ($(MEMCHK),1)
253  MEMCHK_STATUS = Enabled
254  libceed.c += $(ceedmemcheck.c)
255  BACKENDS += /cpu/self/ref/memcheck
256endif
257
258# AVX Backed
259AVX_STATUS = Disabled
260AVX := $(shell $(CC) $(OPT) -v -E - < /dev/null 2>&1 | grep -c avx)
261ifeq ($(AVX),1)
262  AVX_STATUS = Enabled
263  libceed.c += $(avx.c)
264  BACKENDS += /cpu/self/avx/serial /cpu/self/avx/blocked
265endif
266
267# libXSMM Backends
268ifneq ($(wildcard $(XSMM_DIR)/lib/libxsmm.*),)
269  $(libceed) : LDFLAGS += -L$(XSMM_DIR)/lib -Wl,-rpath,$(abspath $(XSMM_DIR)/lib)
270  $(libceed) : LDLIBS += -lxsmm -ldl
271  MKL ?= 0
272  ifneq (0,$(MKL))
273    $(libceed) : LDLIBS += -mkl
274  else
275    $(libceed) : LDLIBS += -lblas
276  endif
277  libceed.c += $(xsmm.c)
278  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
279  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
280endif
281
282# OCCA Backends
283ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
284  $(libceed) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
285  $(libceed) : LDLIBS += -locca
286  libceed.c += $(occa.c)
287  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
288  BACKENDS += /cpu/occa /gpu/occa /omp/occa
289endif
290
291# Cuda Backend
292CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
293CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
294CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared
295ifneq ($(CUDA_LIB_DIR),)
296  $(libceed) : CFLAGS += -I$(CUDA_DIR)/include
297  $(libceed) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
298  $(libceed) : LDLIBS += -lcudart -lnvrtc -lcuda
299  libceed.c  += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c)
300  libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu)
301  BACKENDS += $(CUDA_BACKENDS)
302endif
303
304# MAGMA Backend
305ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
306  ifneq ($(CUDA_LIB_DIR),)
307  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
308  omp_link = -fopenmp
309  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
310  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
311  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
312  $(libceed)           : LDLIBS += $(magma_link)
313  $(tests) $(examples) : LDLIBS += $(magma_link)
314  libceed.c  += $(magma_allsrc.c)
315  libceed.cu += $(magma_allsrc.cu)
316  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
317  $(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
318  BACKENDS += /gpu/magma
319  endif
320endif
321
322export BACKENDS
323
324# generate magma_tmp.c and magma_cuda.cu from magma.c
325%_tmp.c %_cuda.cu : %.c
326	$(magma_preprocessor) $<
327
328libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
329$(libceed.o): | info-backends
330$(libceed) : $(libceed.o) | $$(@D)/.DIR
331	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
332
333$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
334	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
335
336$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
337	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
338
339$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
340	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
341
342$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
343	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
344
345$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
346	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
347
348$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
349	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
350
351$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
352	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
353	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
354	mv examples/mfem/$* $@
355
356$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
357	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
358	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
359	mv examples/petsc/$* $@
360
361$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
362	+$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
363	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
364	mv examples/navier-stokes/$* $@
365
366libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
367$(libceed_test) : $(libceed)
368$(libceed_test) : $(libceed_test.o) | $$(@D)/.DIR
369	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
370
371$(examples) : $(libceed)
372$(tests) : $(libceed) $(libceed_test)
373$(tests) : CEED_LIBS += -lceed_test
374$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
375
376run-t% : BACKENDS += $(TEST_BACKENDS)
377run-% : $(OBJDIR)/%
378	@tests/tap.sh $(<:$(OBJDIR)/%=%)
379
380external_examples := \
381	$(if $(MFEM_DIR),$(mfemexamples)) \
382	$(if $(PETSC_DIR),$(petscexamples)) \
383	$(if $(NEK5K_DIR),$(nekexamples))
384
385allexamples = $(examples) $(external_examples)
386
387# The test and prove targets can be controlled via pattern searches.  The
388# default is to run tests and those examples that have no external dependencies.
389# Examples of finer grained control:
390#
391#   make test search='petsc mfem'      # PETSc and MFEM examples
392#   make prove search='t3'             # t3xx series tests
393#   make junit search='ex petsc'       # core ex* and PETSc tests
394search ?= t ex
395realsearch = $(search:%=%%)
396matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
397# Work around Nek examples not having normal targets
398matched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests)
399
400# Test core libCEED
401test : $(matched:$(OBJDIR)/%=run-%)
402
403# run test target in parallel
404tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
405# CPU C tests only for backend %
406ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
407
408prove : BACKENDS += $(TEST_BACKENDS)
409prove : $(matched_prereq)
410	$(info Testing backends: $(BACKENDS))
411	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
412# run prove target in parallel
413prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
414
415prepnektests:
416	(export CC FC && cd examples && make prepnektests)
417
418prove-all :
419	+$(MAKE) prove realsearch=%
420
421junit-t% : BACKENDS += $(TEST_BACKENDS)
422junit-% : $(OBJDIR)/%
423	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
424
425junit : $(alltests:$(OBJDIR)/%=junit-%)
426
427all: $(alltests)
428
429examples : $(allexamples)
430
431# Benchmarks
432allbenchmarks = petsc-bp1 petsc-bp3
433bench_targets = $(addprefix bench-,$(allbenchmarks))
434.PHONY: $(bench_targets) benchmarks
435$(bench_targets): bench-%: $(OBJDIR)/%
436	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
437benchmarks: $(bench_targets)
438
439$(ceed.pc) : pkgconfig-prefix = $(abspath .)
440$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
441.INTERMEDIATE : $(OBJDIR)/ceed.pc
442%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
443	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
444
445OCCA        := $(OCCA_DIR)/bin/occa
446OKL_KERNELS := $(wildcard backends/occa/*.okl)
447
448okl-cache :
449	$(OCCA) cache ceed $(OKL_KERNELS)
450
451okl-clear:
452	$(OCCA) clear -y -l ceed
453
454install : $(libceed) $(OBJDIR)/ceed.pc
455	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
456	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
457	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
458	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
459	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
460	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
461	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
462
463.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
464
465cln clean :
466	$(RM) -r $(OBJDIR) $(LIBDIR)
467	$(MAKE) -C examples clean
468	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
469	$(RM) -rf benchmarks/*output.txt
470
471distclean : clean
472	$(RM) -r doc/html
473
474doc :
475	doxygen Doxyfile
476
477style :
478	@astyle --options=.astylerc \
479          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
480            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
481              examples/*/*.[ch] examples/*/*.[ch]pp))
482
483CLANG_TIDY ?= clang-tidy
484%.c.tidy : %.c
485	$(CLANG_TIDY) $^ -- $(CPPFLAGS)
486
487tidy : $(libceed.c:%=%.tidy)
488
489print :
490	@echo $(VAR)=$($(VAR))
491
492print-% :
493	$(info [ variable name]: $*)
494	$(info [        origin]: $(origin $*))
495	$(info [         value]: $(value $*))
496	$(info [expanded value]: $($*))
497	$(info )
498	@true
499
500-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
501