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