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