xref: /libCEED/Makefile (revision 1226057fa73c3103b35a2a43c7485643e405a91e)
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    BLAS_LIB = -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl
278  else
279    BLAS_LIB = -lblas
280  endif
281  $(libceeds) : LDLIBS += $(BLAS_LIB)
282  libceed.c += $(xsmm.c)
283  $(xsmm.c:%.c=$(OBJDIR)/%.o) $(xsmm.c:%=%.tidy) : CPPFLAGS += -I$(XSMM_DIR)/include
284  BACKENDS += /cpu/self/xsmm/serial /cpu/self/xsmm/blocked
285endif
286
287# OCCA Backends
288ifneq ($(wildcard $(OCCA_DIR)/lib/libocca.*),)
289  $(libceeds) : LDFLAGS += -L$(OCCA_DIR)/lib -Wl,-rpath,$(abspath $(OCCA_DIR)/lib)
290  $(libceeds) : LDLIBS += -locca
291  libceed.c += $(occa.c)
292  $(occa.c:%.c=$(OBJDIR)/%.o) $(occa.c:%=%.tidy) : CPPFLAGS += -I$(OCCA_DIR)/include
293  BACKENDS += /cpu/occa /gpu/occa /omp/occa
294endif
295
296# Cuda Backend
297CUDA_LIB_DIR := $(wildcard $(foreach d,lib lib64,$(CUDA_DIR)/$d/libcudart.${SO_EXT}))
298CUDA_LIB_DIR := $(patsubst %/,%,$(dir $(firstword $(CUDA_LIB_DIR))))
299CUDA_LIB_DIR_STUBS := $(CUDA_LIB_DIR)/stubs
300CUDA_BACKENDS = /gpu/cuda/ref /gpu/cuda/reg /gpu/cuda/shared
301ifneq ($(CUDA_LIB_DIR),)
302  $(libceeds) : CPPFLAGS += -I$(CUDA_DIR)/include
303  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR) -Wl,-rpath,$(abspath $(CUDA_LIB_DIR))
304  $(libceeds) : LDFLAGS += -L$(CUDA_LIB_DIR_STUBS)
305  $(libceeds) : LDLIBS += -lcudart -lnvrtc -lcuda
306  libceed.c  += $(cuda.c) $(cuda-reg.c) $(cuda-shared.c)
307  libceed.cu += $(cuda.cu) $(cuda-reg.cu) $(cuda-shared.cu)
308  BACKENDS += $(CUDA_BACKENDS)
309endif
310
311# MAGMA Backend
312ifneq ($(wildcard $(MAGMA_DIR)/lib/libmagma.*),)
313  ifneq ($(CUDA_LIB_DIR),)
314  cuda_link = -Wl,-rpath,$(CUDA_LIB_DIR) -L$(CUDA_LIB_DIR) -lcublas -lcusparse -lcudart
315  omp_link = -fopenmp
316  magma_link_static = -L$(MAGMA_DIR)/lib -lmagma $(cuda_link) $(omp_link)
317  magma_link_shared = -L$(MAGMA_DIR)/lib -Wl,-rpath,$(abspath $(MAGMA_DIR)/lib) -lmagma
318  magma_link := $(if $(wildcard $(MAGMA_DIR)/lib/libmagma.${SO_EXT}),$(magma_link_shared),$(magma_link_static))
319  $(libceeds)           : LDLIBS += $(magma_link)
320  $(tests) $(examples) : LDLIBS += $(magma_link)
321  libceed.c  += $(magma_allsrc.c)
322  libceed.cu += $(magma_allsrc.cu)
323  $(magma_allsrc.c:%.c=$(OBJDIR)/%.o) $(magma_allsrc.c:%=%.tidy) : CPPFLAGS += -DADD_ -I$(MAGMA_DIR)/include -I$(CUDA_DIR)/include
324  $(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
325  BACKENDS += /gpu/magma
326  endif
327endif
328
329export BACKENDS
330
331# generate magma_tmp.c and magma_cuda.cu from magma.c
332%_tmp.c %_cuda.cu : %.c
333	$(magma_preprocessor) $<
334
335libceed.o = $(libceed.c:%.c=$(OBJDIR)/%.o) $(libceed.cu:%.cu=$(OBJDIR)/%.o)
336$(libceed.o): | info-backends
337$(libceed) : $(libceed.o) | $$(@D)/.DIR
338	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
339
340$(OBJDIR)/%.o : $(CURDIR)/%.c | $$(@D)/.DIR
341	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(abspath $<)
342
343$(OBJDIR)/%.o : $(CURDIR)/%.cu | $$(@D)/.DIR
344	$(call quiet,NVCC) $(CPPFLAGS) $(NVCCFLAGS) -c -o $@ $(abspath $<)
345
346$(OBJDIR)/% : tests/%.c | $$(@D)/.DIR
347	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
348
349$(OBJDIR)/% : tests/%.f90 | $$(@D)/.DIR
350	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
351
352$(OBJDIR)/% : examples/ceed/%.c | $$(@D)/.DIR
353	$(call quiet,LINK.c) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
354
355$(OBJDIR)/% : examples/ceed/%.f | $$(@D)/.DIR
356	$(call quiet,LINK.F) -o $@ $(abspath $<) $(CEED_LIBS) $(LDLIBS)
357
358$(OBJDIR)/mfem-% : examples/mfem/%.cpp $(libceed) | $$(@D)/.DIR
359	+$(MAKE) -C examples/mfem CEED_DIR=`pwd` \
360	  MFEM_DIR="$(abspath $(MFEM_DIR))" $*
361	mv examples/mfem/$* $@
362
363$(OBJDIR)/petsc-% : examples/petsc/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
364	+$(MAKE) -C examples/petsc CEED_DIR=`pwd` \
365	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
366	mv examples/petsc/$* $@
367
368$(OBJDIR)/navier-stokes-% : examples/navier-stokes/%.c $(libceed) $(ceed.pc) | $$(@D)/.DIR
369	+$(MAKE) -C examples/navier-stokes CEED_DIR=`pwd` \
370	  PETSC_DIR="$(abspath $(PETSC_DIR))" $*
371	mv examples/navier-stokes/$* $@
372
373libceed_test.o = $(test_backends.c:%.c=$(OBJDIR)/%.o)
374$(libceed_test) : $(libceed.o) $(libceed_test.o) | $$(@D)/.DIR
375	$(call quiet,CC) $(LDFLAGS) -shared -o $@ $^ $(LDLIBS)
376
377$(examples) : $(libceed)
378$(tests) : $(libceed_test)
379$(tests) : CEED_LIBS = -lceed_test
380$(tests) $(examples) : LDFLAGS += -Wl,-rpath,$(abspath $(LIBDIR)) -L$(LIBDIR)
381
382run-t% : BACKENDS += $(TEST_BACKENDS)
383run-% : $(OBJDIR)/%
384	@tests/tap.sh $(<:$(OBJDIR)/%=%)
385
386external_examples := \
387	$(if $(MFEM_DIR),$(mfemexamples)) \
388	$(if $(PETSC_DIR),$(petscexamples)) \
389	$(if $(NEK5K_DIR),$(nekexamples))
390
391allexamples = $(examples) $(external_examples)
392
393# The test and prove targets can be controlled via pattern searches.  The
394# default is to run tests and those examples that have no external dependencies.
395# Examples of finer grained control:
396#
397#   make test search='petsc mfem'      # PETSc and MFEM examples
398#   make prove search='t3'             # t3xx series tests
399#   make junit search='ex petsc'       # core ex* and PETSc tests
400search ?= t ex
401realsearch = $(search:%=%%)
402matched = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(allexamples)))
403# Work around Nek examples not having normal targets
404matched_prereq = $(filter-out $(OBJDIR)/nek%,$(matched)) $(if $(findstring nek,$(matched)),prepnektests)
405
406# Test core libCEED
407test : $(matched:$(OBJDIR)/%=run-%)
408
409# run test target in parallel
410tst : ;@$(MAKE) $(MFLAGS) V=$(V) test
411# CPU C tests only for backend %
412ctc-% : $(ctests);@$(foreach tst,$(ctests),$(tst) /cpu/$*;)
413
414prove : BACKENDS += $(TEST_BACKENDS)
415prove : $(matched_prereq)
416	$(info Testing backends: $(BACKENDS))
417	$(PROVE) $(PROVE_OPTS) --exec 'tests/tap.sh' $(matched:$(OBJDIR)/%=%)
418# run prove target in parallel
419prv : ;@$(MAKE) $(MFLAGS) V=$(V) prove
420
421prepnektests:
422	(export CC FC && cd examples && make prepnektests)
423
424prove-all :
425	+$(MAKE) prove realsearch=%
426
427junit-t% : BACKENDS += $(TEST_BACKENDS)
428junit-% : $(OBJDIR)/%
429	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py $(<:$(OBJDIR)/%=%)
430
431junit : $(matched:$(OBJDIR)/%=junit-%)
432
433all: $(alltests)
434
435examples : $(allexamples)
436
437# Benchmarks
438allbenchmarks = petsc-bps
439bench_targets = $(addprefix bench-,$(allbenchmarks))
440.PHONY: $(bench_targets) benchmarks
441$(bench_targets): bench-%: $(OBJDIR)/%
442	cd benchmarks && ./benchmark.sh --ceed "$(BACKENDS)" -r $(*).sh
443benchmarks: $(bench_targets)
444
445$(ceed.pc) : pkgconfig-prefix = $(abspath .)
446$(OBJDIR)/ceed.pc : pkgconfig-prefix = $(prefix)
447.INTERMEDIATE : $(OBJDIR)/ceed.pc
448%/ceed.pc : ceed.pc.template | $$(@D)/.DIR
449	@sed "s:%prefix%:$(pkgconfig-prefix):" $< > $@
450
451OCCA        := $(OCCA_DIR)/bin/occa
452OKL_KERNELS := $(wildcard backends/occa/*.okl)
453
454okl-cache :
455	$(OCCA) cache ceed $(OKL_KERNELS)
456
457okl-clear:
458	$(OCCA) clear -y -l ceed
459
460install : $(libceed) $(OBJDIR)/ceed.pc
461	$(INSTALL) -d $(addprefix $(if $(DESTDIR),"$(DESTDIR)"),"$(includedir)"\
462	  "$(libdir)" "$(pkgconfigdir)" $(if $(OCCA_ON),"$(okldir)"))
463	$(INSTALL_DATA) include/ceed.h "$(DESTDIR)$(includedir)/"
464	$(INSTALL_DATA) include/ceedf.h "$(DESTDIR)$(includedir)/"
465	$(INSTALL_DATA) $(libceed) "$(DESTDIR)$(libdir)/"
466	$(INSTALL_DATA) $(OBJDIR)/ceed.pc "$(DESTDIR)$(pkgconfigdir)/"
467	$(if $(OCCA_ON),$(INSTALL_DATA) $(OKL_KERNELS) "$(DESTDIR)$(okldir)/")
468
469.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
470
471cln clean :
472	$(RM) -r $(OBJDIR) $(LIBDIR)
473	$(MAKE) -C examples clean
474	$(RM) $(magma_tmp.c) $(magma_tmp.cu) backends/magma/*~ backends/magma/*.o
475	$(RM) benchmarks/*output.txt
476
477distclean : clean
478	$(RM) -r doc/html config.mk
479
480doc :
481	doxygen Doxyfile
482
483style :
484	@astyle --options=.astylerc \
485          $(filter-out include/ceedf.h tests/t310-basis-f.h, \
486            $(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
487              examples/*/*.[ch] examples/*/*.[ch]pp))
488
489CLANG_TIDY ?= clang-tidy
490%.c.tidy : %.c
491	$(CLANG_TIDY) $^ -- $(CPPFLAGS)
492
493tidy : $(libceed.c:%=%.tidy)
494
495print :
496	@echo $(VAR)=$($(VAR))
497
498print-% :
499	$(info [ variable name]: $*)
500	$(info [        origin]: $(origin $*))
501	$(info [         value]: $(value $*))
502	$(info [expanded value]: $($*))
503	$(info )
504	@true
505
506# "make configure" will autodetect any variables not passed on the
507# command line, caching the result in config.mk to be used on any
508# subsequent invocations of make.  For example,
509#
510#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
511#   make
512#   make prove
513configure :
514	@: > config.mk
515	@echo "CC = $(CC)" | tee -a config.mk
516	@echo "FC = $(FC)" | tee -a config.mk
517	@echo "NVCC = $(NVCC)" | tee -a config.mk
518	@echo "CFLAGS = $(CFLAGS)" | tee -a config.mk
519	@echo "CPPFLAGS = $(CPPFLAGS)" | tee -a config.mk
520	@echo "FFLAGS = $(FFLAGS)" | tee -a config.mk
521	@echo "LDFLAGS = $(LDFLAGS)" | tee -a config.mk
522	@echo "LDLIBS = $(LDLIBS)" | tee -a config.mk
523	@echo "MAGMA_DIR = $(MAGMA_DIR)" | tee -a config.mk
524	@echo "XSMM_DIR = $(XSMM_DIR)" | tee -a config.mk
525	@echo "CUDA_DIR = $(CUDA_DIR)" | tee -a config.mk
526	@echo "MFEM_DIR = $(MFEM_DIR)" | tee -a config.mk
527	@echo "PETSC_DIR = $(PETSC_DIR)" | tee -a config.mk
528	@echo "NEK5K_DIR = $(NEK5K_DIR)" | tee -a config.mk
529	@echo "Configuration cached in config.mk"
530
531.PHONY : configure
532
533-include $(libceed.c:%.c=$(OBJDIR)/%.d) $(tests.c:tests/%.c=$(OBJDIR)/%.d)
534