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