xref: /honee/Makefile (revision 7ecf6641c340caefd7fa9f7fc7a6efebf89ae19d)
10006be33SJames WrightCONFIG ?= config.mk
2066464baSJames Wright-include $(CONFIG)
30006be33SJames WrightCOMMON ?= common.mk
44f863122SJeremy L Thompson-include $(COMMON)
54f863122SJeremy L Thompson
60006be33SJames Wrightpkgconf-path = $(if $(wildcard $(1)/$(2).pc),$(1)/$(2).pc,$(2))
7ea10196cSJeremy L Thompson
80006be33SJames Wright# Library dependencies
90006be33SJames Wright# Note: PETSC_ARCH can be undefined or empty for installations which do not use
100006be33SJames Wright#       PETSC_ARCH - for example when using PETSc installed through Spack.
110006be33SJames Wrightifneq ($(wildcard ../petsc/lib/libpetsc.*),)
120006be33SJames Wright  PETSC_DIR ?= ../petsc
130006be33SJames Wrightendif
140006be33SJames Wrightpetsc.pc := $(call pkgconf-path,$(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig,petsc)
150006be33SJames Wright
160006be33SJames WrightCEED_DIR ?= $(if $(wildcard $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/ceed.pc),$(PETSC_DIR)/$(PETSC_ARCH),../libCEED)
170006be33SJames Wrightceed.pc  := $(call pkgconf-path,$(CEED_DIR)/lib/pkgconfig,ceed)
180006be33SJames Wright
19a39fefe2SJeremy L Thompsonpkgconf   = $(shell pkg-config $(if $(STATIC),--static) $1 | $(SED) -e 's/^"//g' -e 's/"$$//g')
200006be33SJames Wright
210006be33SJames Wright# Error checking flags
220006be33SJames WrightPEDANTIC      ?=
230006be33SJames WrightPEDANTICFLAGS ?= -Werror -pedantic
240006be33SJames Wright
250006be33SJames WrightCC        = $(call pkgconf, --variable=ccompiler $(petsc.pc) $(ceed.pc))
26a515125bSLeila GhaffariCFLAGS    = -std=c99 \
270006be33SJames Wright  $(call pkgconf, --variable=cflags_extra $(petsc.pc)) \
280006be33SJames Wright  $(call pkgconf, --cflags-only-other $(petsc.pc)) \
2900906fedSJames Wright  $(OPT) \
3000906fedSJames Wright  $(if $(PEDANTIC),$(PEDANTICFLAGS))
310006be33SJames WrightCPPFLAGS  = $(call pkgconf, --cflags-only-I $(petsc.pc) $(ceed.pc)) \
3200906fedSJames Wright  $(call pkgconf, --variable=cflags_dep $(petsc.pc)) \
3300906fedSJames Wright  $(if $(PEDANTIC),$(PEDANTICFLAGS))
3400906fedSJames WrightCXX       = $(call pkgconf, --variable=cxxcompiler $(petsc.pc) $(ceed.pc)) $(if $(PEDANTIC),$(PEDANTICFLAGS))
354c07ec22SJames WrightCXXFLAGS  = -std=c++17 -Wno-deprecated -Wno-tautological-compare
360006be33SJames WrightLDFLAGS   = $(call pkgconf, --libs-only-L --libs-only-other $(petsc.pc) $(ceed.pc))
370006be33SJames WrightLDFLAGS  += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))%, $(call pkgconf, --libs-only-L $(petsc.pc) $(ceed.pc)))
380006be33SJames WrightLDLIBS    = $(call pkgconf, --libs-only-l $(petsc.pc) $(ceed.pc)) -lm -lstdc++
39ea10196cSJeremy L Thompson
404c07ec22SJames Wright# ASAN must be left empty if you don't want to use it
414c07ec22SJames WrightASAN    ?=
420006be33SJames Wright
434c07ec22SJames WrightAFLAGS  ?= -fsanitize=address
447df379d9SJames WrightCFLAGS  += $(if $(ASAN),$(AFLAGS))
457df379d9SJames WrightFFLAGS  += $(if $(ASAN),$(AFLAGS))
467df379d9SJames WrightLDFLAGS += $(if $(ASAN),$(AFLAGS))
470006be33SJames Wright
4845101827SJames WrightCPPFLAGS += -I./include
497df379d9SJames Wright
50a39fefe2SJeremy L Thompson# External tools
51a39fefe2SJeremy L ThompsonPYTHON   ?= python3
52a39fefe2SJeremy L ThompsonSED      ?= sed
53a39fefe2SJeremy L Thompson
544c07ec22SJames Wright# LibTorch
554c07ec22SJames WrightUSE_TORCH ?=
564c07ec22SJames Wrightifeq ($(USE_TORCH),1)
57a39fefe2SJeremy L Thompson  libtorch.pc := $(shell $(PYTHON) ./pytorch_pkgconfig.py)
584c07ec22SJames Wright  CPPFLAGS    += $(call pkgconf, --cflags-only-I $(libtorch.pc))
594c07ec22SJames Wright  CXXFLAGS    += $(call pkgconf, --cflags-only-other $(libtorch.pc))
604c07ec22SJames Wright  LDFLAGS     += $(call pkgconf, --libs-only-L --libs-only-other $(libtorch.pc))
610006be33SJames Wright  LDFLAGS     += $(patsubst -L%, $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))%, $(call pkgconf, --libs-only-L $(libtorch.pc)))
624c07ec22SJames Wright  LDLIBS      += $(call pkgconf, --libs-only-l $(libtorch.pc))
634c07ec22SJames Wright
644c07ec22SJames Wright  src.cpp += $(sort $(wildcard $(PROBLEMDIR)/torch/*.cpp))
654c07ec22SJames Wright  src.c   += $(sort $(wildcard $(PROBLEMDIR)/torch/*.c))
664c07ec22SJames Wright
674c07ec22SJames Wright  # Intel Pytorch EXtension (IPEX)
684c07ec22SJames Wright  IPEX_DIR ?=
694c07ec22SJames Wright  ifdef IPEX_DIR
704c07ec22SJames Wright      LDFLAGS += -L$(IPEX_DIR)/lib/
714c07ec22SJames Wright      LDFLAGS += -Wl,-rpath,$(IPEX_DIR)/lib/
724c07ec22SJames Wright      LDLIBS  += -lintel-ext-pt-gpu
734c07ec22SJames Wright  endif
744c07ec22SJames Wrightendif
754c07ec22SJames Wright
764c07ec22SJames Wright# Source Files
77a515125bSLeila GhaffariOBJDIR := build
78a515125bSLeila GhaffariSRCDIR := src
79a515125bSLeila GhaffariPROBLEMDIR := problems
80ea10196cSJeremy L Thompson
81dae7673aSJames Wrightsrc.c := examples/navierstokes.c $(filter-out $(wildcard **/smartsim/*), $(sort $(wildcard $(PROBLEMDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/*.c)) $(sort $(wildcard $(SRCDIR)/**/*.c)))
824c07ec22SJames Wrightsrc.o = $(src.c:%.c=$(OBJDIR)/%.o) $(src.cpp:%.cpp=$(OBJDIR)/%.o)
83a515125bSLeila Ghaffari
849e6f9b5eSJames Wright# Path to install directory for SmartRedis. Example: /software/smartredis/install
859e6f9b5eSJames WrightSMARTREDIS_DIR ?=
869e6f9b5eSJames Wrightifdef SMARTREDIS_DIR
8748969772SJames Wright	CPPFLAGS += -I$(SMARTREDIS_DIR)/include
8848969772SJames Wright	LDFLAGS += -L$(SMARTREDIS_DIR)/lib $(call pkgconf, --variable=ldflag_rpath $(petsc.pc))$(SMARTREDIS_DIR)/lib
8948969772SJames Wright	LDLIBS +=  -lsmartredis
909e6f9b5eSJames Wright	src.c += $(sort $(wildcard $(SRCDIR)/smartsim/*.c))
919e6f9b5eSJames Wrightendif
922120e86cSJeremy L Thompson
93947fa354SJeremy L Thompsonall: navierstokes
942120e86cSJeremy L Thompson
952120e86cSJeremy L Thompson# Diagnostic information
962120e86cSJeremy L Thompsoninfo-basic:
972120e86cSJeremy L Thompson	$(info -----------------------------------------)
982120e86cSJeremy L Thompson	$(info |      __  ______  _   ______________   |)
992120e86cSJeremy L Thompson	$(info |     / / / / __ \/ | / / ____/ ____/   |)
1002120e86cSJeremy L Thompson	$(info |    / /_/ / / / /  |/ / __/ / __/      |)
1012120e86cSJeremy L Thompson	$(info |   / __  / /_/ / /|  / /___/ /___      |)
1022120e86cSJeremy L Thompson	$(info |  /_/ /_/\____/_/ |_/_____/_____/      |)
1032120e86cSJeremy L Thompson	$(info -----------------------------------------)
1042120e86cSJeremy L Thompson	$(info )
1052120e86cSJeremy L Thompson	$(info -----------------------------------------)
1062120e86cSJeremy L Thompson	$(info )
1072120e86cSJeremy L Thompson	$(info Dependencies:)
1082120e86cSJeremy L Thompson	$(info CEED_DIR       = $(CEED_DIR))
1092120e86cSJeremy L Thompson	$(info PETSC_DIR      = $(PETSC_DIR))
1102120e86cSJeremy L Thompson	$(info PETSC_ARCH     = $(PETSC_ARCH))
1112120e86cSJeremy L Thompson	$(info )
1122120e86cSJeremy L Thompson	$(info Optional Dependencies:)
1132120e86cSJeremy L Thompson	$(info SMARTREDIS_DIR = $(or $(SMARTREDIS_DIR),(not found)))
1142120e86cSJeremy L Thompson	$(info USE_TORCH      = $(USE_TORCH))
1152120e86cSJeremy L Thompson	$(info )
1162120e86cSJeremy L Thompson	$(info -----------------------------------------)
1172120e86cSJeremy L Thompson	$(info )
1182120e86cSJeremy L Thompson	@true
1192120e86cSJeremy L Thompson
1202120e86cSJeremy L Thompsoninfo:
1212120e86cSJeremy L Thompson	$(info -----------------------------------------)
1222120e86cSJeremy L Thompson	$(info |      __  ______  _   ______________   |)
1232120e86cSJeremy L Thompson	$(info |     / / / / __ \/ | / / ____/ ____/   |)
1242120e86cSJeremy L Thompson	$(info |    / /_/ / / / /  |/ / __/ / __/      |)
1252120e86cSJeremy L Thompson	$(info |   / __  / /_/ / /|  / /___/ /___      |)
1262120e86cSJeremy L Thompson	$(info |  /_/ /_/\____/_/ |_/_____/_____/      |)
1272120e86cSJeremy L Thompson	$(info -----------------------------------------)
1282120e86cSJeremy L Thompson	$(info )
1292120e86cSJeremy L Thompson	$(info -----------------------------------------)
1302120e86cSJeremy L Thompson	$(info )
1312120e86cSJeremy L Thompson	$(info Dependencies:)
1322120e86cSJeremy L Thompson	$(info CEED_DIR        = $(CEED_DIR))
1332120e86cSJeremy L Thompson	$(info PETSC_DIR       = $(PETSC_DIR))
1342120e86cSJeremy L Thompson	$(info PETSC_ARCH      = $(PETSC_ARCH))
1352120e86cSJeremy L Thompson	$(info )
1362120e86cSJeremy L Thompson	$(info Optional Dependencies:)
1372120e86cSJeremy L Thompson	$(info SMARTREDIS_DIR = $(or $(SMARTREDIS_DIR),(not found)))
1382120e86cSJeremy L Thompson	$(info USE_TORCH      = $(USE_TORCH))
1392120e86cSJeremy L Thompson	$(info )
1402120e86cSJeremy L Thompson	$(info -----------------------------------------)
1412120e86cSJeremy L Thompson	$(info )
1422120e86cSJeremy L Thompson	$(info Build Options:)
1432120e86cSJeremy L Thompson	$(info CC              = $(CC))
1442120e86cSJeremy L Thompson	$(info CFLAGS          = $(CFLAGS))
1452120e86cSJeremy L Thompson	$(info CPPFLAGS        = $(CPPFLAGS))
1462120e86cSJeremy L Thompson	$(info LDFLAGS         = $(LDFLAGS))
1472120e86cSJeremy L Thompson	$(info LDLIBS          = $(LDLIBS))
1482120e86cSJeremy L Thompson	$(info AR              = $(AR))
1492120e86cSJeremy L Thompson	$(info ARFLAGS         = $(ARFLAGS))
1502120e86cSJeremy L Thompson	$(info OPT             = $(OPT))
1512120e86cSJeremy L Thompson	$(info AFLAGS          = $(AFLAGS))
1522120e86cSJeremy L Thompson	$(info ASAN            = $(or $(ASAN),(empty)))
1532120e86cSJeremy L Thompson	$(info VERBOSE         = $(or $(V),(empty)) [verbose=$(if $(V),on,off)])
1542120e86cSJeremy L Thompson	$(info )
1552120e86cSJeremy L Thompson	$(info -----------------------------------------)
1562120e86cSJeremy L Thompson	$(info )
1572120e86cSJeremy L Thompson	$(info Format and Style Options:)
1582120e86cSJeremy L Thompson	$(info CLANG_FORMAT    = $(CLANG_FORMAT))
1592120e86cSJeremy L Thompson	$(info FORMAT_OPTS     = $(FORMAT_OPTS))
1602120e86cSJeremy L Thompson	$(info CLANG_TIDY      = $(CLANG_TIDY))
1612120e86cSJeremy L Thompson	$(info TIDY_OPTS       = $(TIDY_OPTS))
1622120e86cSJeremy L Thompson	$(info TIDY_FILE_OPTS  = $(TIDY_FILE_OPTS))
1632120e86cSJeremy L Thompson	$(info )
1642120e86cSJeremy L Thompson	$(info -----------------------------------------)
1652120e86cSJeremy L Thompson	$(info )
166a5677b81SMohi	$(info Git:)
167a5677b81SMohi	$(info describe        = $(GIT_DESCRIBE))
168a5677b81SMohi	$(info )
169a5677b81SMohi	$(info -----------------------------------------)
170a5677b81SMohi	$(info )
1712120e86cSJeremy L Thompson	@true
1729e6f9b5eSJames Wright
173d9688174SJeremy L Thompson# Get number of processors of the machine
174d9688174SJeremy L ThompsonNPROCS := $(shell getconf _NPROCESSORS_ONLN)
175d9688174SJeremy L Thompson# prepare make options to run in parallel
176d9688174SJeremy L ThompsonMFLAGS := -j $(NPROCS) --warn-undefined-variables \
177d9688174SJeremy L Thompson                       --no-print-directory --no-keep-going
178d9688174SJeremy L Thompson
1790006be33SJames Wright$(OBJDIR)/navierstokes: $(src.o) | navierstokes
1800006be33SJames Wrightnavierstokes: $(src.o) | $(petsc.pc) $(ceed.pc)
1810006be33SJames Wright	$(call quiet,LINK.o) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $(OBJDIR)/$@
182a515125bSLeila Ghaffari
183a515125bSLeila Ghaffari.SECONDEXPANSION: # to expand $$(@D)/.DIR
184a515125bSLeila Ghaffari%/.DIR :
185a515125bSLeila Ghaffari	@mkdir -p $(@D)
186a515125bSLeila Ghaffari	@touch $@
187ea10196cSJeremy L Thompson
1884f863122SJeremy L Thompson# Quiet, color output
1894f863122SJeremy L Thompsonquiet ?= $($(1))
1904f863122SJeremy L Thompson
191a5677b81SMohi# Inject Git/version macros when compiling honee-version.c
1922ef6950eSJames WrightGIT_DESCRIBE := $(shell git -c safe.directory=$PWD describe --always --dirty 2>/dev/null || printf "unknown\n")
193a5677b81SMohi
194a5677b81SMohi$(OBJDIR)/src/honee-config.o: Makefile
195a5677b81SMohi$(OBJDIR)/src/honee-config.o src/honee-config.c.tidy: CONFIGFLAGS += -DHONEE_GIT_VERSION="\"$(GIT_DESCRIBE)\""
196a5677b81SMohi$(OBJDIR)/src/honee-config.o src/honee-config.c.tidy: CONFIGFLAGS += -DHONEE_BUILD_CONFIGURATION="\"// Build Configuration:$(foreach v,$(CONFIG_VARS),\n$(v) = $($(v)))\""
197a5677b81SMohi
198b03da087SJames Wright$(OBJDIR)/%.o : %.c | $$(@D)/.DIR
199a5677b81SMohi	$(call quiet,CC) $(CPPFLAGS) $(CFLAGS) $(CONFIGFLAGS) -c -o $@ $(abspath $<)
200a515125bSLeila Ghaffari
201b03da087SJames Wright$(OBJDIR)/%.o : %.cpp | $$(@D)/.DIR
2024c07ec22SJames Wright	$(call quiet,CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(abspath $<)
2034c07ec22SJames Wright
2040006be33SJames Wrightprint: $(petsc.pc) $(ceed.pc)
205ea10196cSJeremy L Thompson	$(info CC      : $(CC))
206ea10196cSJeremy L Thompson	$(info CFLAGS  : $(CFLAGS))
207ea10196cSJeremy L Thompson	$(info CPPFLAGS: $(CPPFLAGS))
208ea10196cSJeremy L Thompson	$(info LDFLAGS : $(LDFLAGS))
209ea10196cSJeremy L Thompson	$(info LDLIBS  : $(LDLIBS))
210ea10196cSJeremy L Thompson	$(info OPT     : $(OPT))
211ea10196cSJeremy L Thompson	@true
212ea10196cSJeremy L Thompson
2130e8fe9d5SJames Wrightprint-% :
2140e8fe9d5SJames Wright	$(info [ variable name]: $*)
2150e8fe9d5SJames Wright	$(info [        origin]: $(origin $*))
2160e8fe9d5SJames Wright	$(info [        flavor]: $(flavor $*))
2170e8fe9d5SJames Wright	$(info [         value]: $(value $*))
2180e8fe9d5SJames Wright	$(info [expanded value]: $($*))
2190e8fe9d5SJames Wright	$(info )
2200e8fe9d5SJames Wright	@true
2210e8fe9d5SJames Wright
222ea10196cSJeremy L Thompsonclean:
223a515125bSLeila Ghaffari	$(RM) -r $(OBJDIR) navierstokes *.vtu *.bin* *.csv *.png
224ea10196cSJeremy L Thompson
2250006be33SJames Wright$(petsc.pc):
226ea10196cSJeremy L Thompson	$(if $(wildcard $@),,$(error \
227ea10196cSJeremy L Thompson	  PETSc config not found. Please set PETSC_DIR and PETSC_ARCH))
228ea10196cSJeremy L Thompson
229ea10196cSJeremy L Thompson.PHONY: all print clean
230ea10196cSJeremy L Thompson
231aa34f9e7SJames Wright# Define test files
232149fb536SJames Wrightexamples.c     := $(sort $(wildcard examples/*.c))
233149fb536SJames Wrightexamples       := $(examples.c:examples/%.c=$(OBJDIR)/%)
23467f3e659SJames Wrighttests.smartsim := test-smartsim
23567f3e659SJames Wrighttests          += $(tests.smartsim:%=$(OBJDIR)/%)
2360006be33SJames Wright
23767f3e659SJames Wright$(tests.smartsim:%=$(OBJDIR)/%): $(OBJDIR)/navierstokes
2380006be33SJames Wright
239965d9f74SJames Wright# Documentation
240965d9f74SJames WrightDOXYGEN ?= doxygen
241965d9f74SJames WrightDOXYGENOPTS ?= -q
242965d9f74SJames Wrightdoxygen :
243965d9f74SJames Wright	$(DOXYGEN) $(DOXYGENOPTS) Doxyfile
244965d9f74SJames Wright
245965d9f74SJames WrightSPHINXOPTS      =
246965d9f74SJames WrightSPHINXBUILD     = sphinx-build
247965d9f74SJames WrightSPHINXAUTOBUILD = sphinx-autobuild
24867f3e659SJames WrightSPHINXPROJ      = HONEE
249965d9f74SJames WrightSPHINXBUILDDIR  = doc/build
250965d9f74SJames Wright
251965d9f74SJames Wrightdoc-html doc-dirhtml doc-latexpdf doc-epub doc-help : doc-% : doxygen
252965d9f74SJames Wright	@$(SPHINXBUILD) -M $* . "$(SPHINXBUILDDIR)" $(SPHINXOPTS)
253965d9f74SJames Wright
254965d9f74SJames Wrightdoc-livehtml : doxygen
255965d9f74SJames Wright	@$(SPHINXAUTOBUILD) . "$(SPHINXBUILDDIR)" $(SPHINXOPTS)
256965d9f74SJames Wright
257965d9f74SJames Wrightdoc : doc-html
258965d9f74SJames Wright
259965d9f74SJames Wrightdoc-clean:
260965d9f74SJames Wright	$(RM) -r doc/html doc/build
261965d9f74SJames Wright
262a39fefe2SJeremy L Thompson# Tidy
263a39fefe2SJeremy L ThompsonCLANG_TIDY     ?= clang-tidy
264a39fefe2SJeremy L ThompsonTIDY_OPTS      ?= --quiet
265a5677b81SMohiTIDY_FILE_OPTS += $(CPPFLAGS) $(CONFIGFLAGS) --std=c99
266a39fefe2SJeremy L Thompson
267a39fefe2SJeremy L Thompson%.c.tidy : %.c
268a39fefe2SJeremy L Thompson	$(call quiet,CLANG_TIDY) $(TIDY_OPTS) $^ -- $(TIDY_FILE_OPTS)
269a39fefe2SJeremy L Thompson
270a39fefe2SJeremy L Thompsontidy-c   : $(src.c:%=%.tidy)
271a39fefe2SJeremy L Thompson
272a39fefe2SJeremy L Thompsontidy     : tidy-c
273a39fefe2SJeremy L Thompson
274a39fefe2SJeremy L Thompson# Style
275a39fefe2SJeremy L ThompsonCLANG_FORMAT  ?= clang-format
276a39fefe2SJeremy L ThompsonFORMAT_OPTS   += -style=file -i
277a39fefe2SJeremy L ThompsonAUTOPEP8      ?= autopep8
278a39fefe2SJeremy L ThompsonAUTOPEP8_OPTS += --in-place --aggressive --max-line-length 120
279a39fefe2SJeremy L ThompsonSED_FMT_OPTS  += -r 's/\s+$$//' -i
280a39fefe2SJeremy L Thompson
281a39fefe2SJeremy L Thompson%.format : %
282a39fefe2SJeremy L Thompson	$(call quiet,CLANG_FORMAT) $(FORMAT_OPTS) $^
283a39fefe2SJeremy L Thompson
28442aed787SJames Wrightformat.ch := $(shell git ls-files '*.[ch]pp' '*.[ch]')
285a39fefe2SJeremy L Thompsonformat.py := $(filter-out tests/junit-xml/junit_xml/__init__.py, $(shell git ls-files '*.py'))
28642aed787SJames Wrightformat.ot := $(shell git ls-files '*.md')
287a39fefe2SJeremy L Thompson
288a39fefe2SJeremy L Thompsonformat-c  :
289a39fefe2SJeremy L Thompson	$(call quiet,CLANG_FORMAT) $(FORMAT_OPTS) $(format.ch)
290a39fefe2SJeremy L Thompson
291a39fefe2SJeremy L Thompsonformat-py :
292a39fefe2SJeremy L Thompson	$(call quiet,AUTOPEP8) $(AUTOPEP8_OPTS) $(format.py)
293a39fefe2SJeremy L Thompson
294a39fefe2SJeremy L Thompsonformat-ot :
295a39fefe2SJeremy L Thompson	$(call quiet,SED) $(SED_FMT_OPTS) $(format.ot)
296a39fefe2SJeremy L Thompson
297a39fefe2SJeremy L Thompsonformat    : format-c format-py format-ot
298a39fefe2SJeremy L Thompson
2990006be33SJames Wright# Testing
3000006be33SJames Wrightifeq ($(COVERAGE), 1)
3010006be33SJames Wright  CFLAGS  += --coverage
3020006be33SJames Wright  LDFLAGS += --coverage
3030006be33SJames Wrightendif
3040006be33SJames Wright
3050006be33SJames WrightPROVE      ?= prove
3060006be33SJames WrightPROVE_OPTS ?= -j $(NPROCS)
3070006be33SJames Wright
3080006be33SJames Wright# Set libCEED backends for testing
3090006be33SJames WrightCEED_BACKENDS ?= /cpu/self
3100006be33SJames Wrightexport CEED_BACKENDS
3110006be33SJames Wright
3120006be33SJames Wright# Set number processes for testing
3130006be33SJames WrightNPROC_TEST ?= 1
3140006be33SJames Wrightexport NPROC_TEST
3150006be33SJames Wright
3160006be33SJames Wright# Set pool size for testing
3170006be33SJames WrightNPROC_POOL ?= 1
3180006be33SJames Wrightexport NPROC_POOL
3190006be33SJames Wright
3200006be33SJames WrightJUNIT_BATCH ?= ''
3210006be33SJames Wright
3220006be33SJames Wrightrun-% : $(OBJDIR)/%
323e45c6f40SZach Atkins	@$(PYTHON) tests/junit.py --ceed-backends $(CEED_BACKENDS) --mode tap $(if $(SMARTREDIS_DIR),--smartredis-dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has-torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%)
3240006be33SJames Wright
3250006be33SJames Wright# The test and prove targets can be controlled via pattern searches. The default
3260006be33SJames Wright# is to run all tests and examples. Examples of finer grained control:
3270006be33SJames Wright#
3280006be33SJames Wright#   make prove search='t3'    # t3xx series tests
3290006be33SJames Wright#   make junit search='t ex'  # core tests and examples
3300006be33SJames Wrightsearch    ?= navierstokes
331e45c6f40SZach Atkinssubsearch ?= .*
3320006be33SJames Wrightrealsearch = $(search:%=%%)
3330006be33SJames Wrightmatched    = $(foreach pattern,$(realsearch),$(filter $(OBJDIR)/$(pattern),$(tests) $(examples)))
3340006be33SJames Wright
3350006be33SJames Wright# Test
3360006be33SJames Wrighttest    : $(matched:$(OBJDIR)/%=run-%)
3370006be33SJames Wright
3380006be33SJames Wrighttst     : ;@$(MAKE) $(MFLAGS) V=$(V) test
3390006be33SJames Wright
3400006be33SJames Wright# Test with TAP output
3410006be33SJames Wrightprove   : $(matched)
3420006be33SJames Wright	$(info Running unit tests)
3430006be33SJames Wright	$(info - Testing with libCEED backends: $(CEED_BACKENDS))
3440006be33SJames Wright	$(info - Testing on $(NPROC_TEST) processes)
345e45c6f40SZach Atkins	$(PROVE) $(PROVE_OPTS) --exec '$(PYTHON) tests/junit.py' $(matched:$(OBJDIR)/%=%) :: --ceed-backends $(CEED_BACKENDS) --mode tap $(if $(SMARTREDIS_DIR),--smartredis-dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has-torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)'
3460006be33SJames Wright
3470006be33SJames Wrightprv     : ;@$(MAKE) $(MFLAGS) V=$(V) prove
3480006be33SJames Wright
3490006be33SJames Wrightprove-all :
3500006be33SJames Wright	+$(MAKE) prove realsearch=%
3510006be33SJames Wright
3520006be33SJames Wright# Test with JUNIT output
3530006be33SJames Wrightjunit-% : $(OBJDIR)/%
354e45c6f40SZach Atkins	@printf "  %10s %s\n" TEST $(<:$(OBJDIR)/%=%); $(PYTHON) tests/junit.py --junit-batch $(JUNIT_BATCH) --ceed-backends $(CEED_BACKENDS) $(if $(SMARTREDIS_DIR),--smartredis-dir $(SMARTREDIS_DIR) ) $(if $(USE_TORCH),--has-torch $(USE_TORCH) )--nproc $(NPROC_TEST) --pool-size $(NPROC_POOL) --search '$(subsearch)' $(<:$(OBJDIR)/%=%)
3550006be33SJames Wright
3560006be33SJames Wrightjunit   : $(matched:$(OBJDIR)/%=junit-%)
3570006be33SJames Wright
3580006be33SJames Wright
3590006be33SJames Wright# Configure
3600006be33SJames Wright# "make configure" detects any variables passed on the command line or
3610006be33SJames Wright# previously set in config.mk, caching them in config.mk as simple
3620006be33SJames Wright# (:=) variables.  Variables set in config.mk or on the command line
3630006be33SJames Wright# take precedence over the defaults provided in the file.  Typical
3640006be33SJames Wright# usage:
3650006be33SJames Wright#
3660006be33SJames Wright#   make configure CC=/path/to/my/cc CUDA_DIR=/opt/cuda
3670006be33SJames Wright#   make
3680006be33SJames Wright#   make prove
3690006be33SJames Wright#
3700006be33SJames Wright# The values in the file can be updated by passing them on the command
3710006be33SJames Wright# line, e.g.,
3720006be33SJames Wright#
3730006be33SJames Wright#   make configure CC=/path/to/other/clang
3740006be33SJames Wright
3750006be33SJames Wright# All variables to consider for caching
376362ddf03SJames WrightCONFIG_VARS = CEED_DIR PETSC_DIR PETSC_ARCH OPT CFLAGS CPPFLAGS AR ARFLAGS LDFLAGS LDLIBS SED USE_TORCH SMARTREDIS_DIR
3770006be33SJames Wright
3780006be33SJames Wright# $(call needs_save,CFLAGS) returns true (a nonempty string) if CFLAGS
3790006be33SJames Wright# was set on the command line or in config.mk (where it will appear as
3800006be33SJames Wright# a simple variable).
3810006be33SJames Wrightneeds_save = $(or $(filter command line,$(origin $(1))),$(filter simple,$(flavor $(1))))
3820006be33SJames Wright
3830006be33SJames Wrightconfigure :
3840006be33SJames Wright	$(file > $(CONFIG))
3850006be33SJames Wright	$(foreach v,$(CONFIG_VARS),$(if $(call needs_save,$(v)),$(file >> $(CONFIG),$(v) := $($(v)))))
3860006be33SJames Wright	@echo "Configuration cached in $(CONFIG):"
3870006be33SJames Wright	@cat $(CONFIG)
388a515125bSLeila Ghaffari
389*1efe7de2SJames Wright
390*1efe7de2SJames WrightGITSRC = '*.[chF]' '*.hpp' '*.cpp' '*.cxx'
391*1efe7de2SJames WrightcheckbadSource:
392*1efe7de2SJames Wright	@git --no-pager grep -n -P 'self\.gitcommit' -- config/BuildSystem/config/packages | grep 'origin/' ; if [[ "$$?" == "0" ]]; then echo "Error: Do not use a branch name in a configure package file"; false; fi
393*1efe7de2SJames Wright	-@${RM} -f checkbadSource.out
394*1efe7de2SJames Wright	-@touch checkbadSource.out
395*1efe7de2SJames Wright	-@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/check_header_guard.py --action=check --kind=pragma_once -- ./src ./include >> checkbadSource.out
396*1efe7de2SJames Wright	-@echo "----- Double blank lines in file -----------------------------------" >> checkbadSource.out
397*1efe7de2SJames Wright	-@git --no-pager grep -n -P '^$$' -- ${GITSRC} > doublelinecheck.out
398*1efe7de2SJames Wright	-@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/doublelinecheck.py doublelinecheck.out >> checkbadSource.out
399*1efe7de2SJames Wright	-@${RM} -f doublelinecheck.out
400*1efe7de2SJames Wright	-@echo "----- Tabs in file -------------------------------------------------" >> checkbadSource.out
401*1efe7de2SJames Wright	-@git --no-pager grep -n -P '\t' -- ${GITSRC} >> checkbadSource.out;true
402*1efe7de2SJames Wright	-@echo "----- Tabs in makefiles --------------------------------------------" >> checkbadSource.out
403*1efe7de2SJames Wright	-@git --no-pager grep -n -P '[ ]*[#A-Za-z0-9][ :=_A-Za-z0-9]*\t' -- makefile  >> checkbadSource.out;true
404*1efe7de2SJames Wright	-@echo "----- White space at end of line -----------------------------------" >> checkbadSource.out
405*1efe7de2SJames Wright	-@git --no-pager grep -n -P ' $$' -- ${GITSRC} >> checkbadSource.out;true
406*1efe7de2SJames Wright	-@echo "----- Two ;; -------------------------------------------------------" >> checkbadSource.out
407*1efe7de2SJames Wright	-@git --no-pager grep -n -P -e ';;' -- ${GITSRC} | grep -v ' for (' >> checkbadSource.out;true
408*1efe7de2SJames Wright	-@echo "----- PetscCall for an MPI error code ------------------------------" >> checkbadSource.out
409*1efe7de2SJames Wright	-@git --no-pager grep -n -P -e 'PetscCall\(MPI[U]*_\w*\(.*\)\);' -- ${GITSRC} | grep -Ev 'MPIU_File' >> checkbadSource.out;true
410*1efe7de2SJames Wright	-@echo "----- DOS file (with DOS newlines) ---------------------------------" >> checkbadSource.out
411*1efe7de2SJames Wright	-@git --no-pager grep -n -P '\r' -- ${GITSRC} >> checkbadSource.out;true
412*1efe7de2SJames Wright	-@echo "----- { before SETERRQ ---------------------------------------------" >> checkbadSource.out
413*1efe7de2SJames Wright	-@git --no-pager grep -n -P '{SETERRQ' -- ${GITSRC} >> checkbadSource.out;true
414*1efe7de2SJames Wright	-@echo "----- PetscCall following SETERRQ ----------------------------------" >> checkbadSource.out
415*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'SETERRQ' -- ${GITSRC} | grep ";PetscCall" >> checkbadSource.out;true
416*1efe7de2SJames Wright	-@echo "----- SETERRQ() without defined error code -------------------------" >> checkbadSource.out
417*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'SETERRQ\((?!\))' -- ${GITSRC} | grep -v PETSC_ERR  | grep " if " | grep -v "__VA_ARGS__" | grep -v "then;" | grep -v flow.c >> checkbadSource.out;true
418*1efe7de2SJames Wright	-@echo "----- SETERRQ() with trailing newline ------------------------------" >> checkbadSource.out
419*1efe7de2SJames Wright	-@git --no-pager grep -n -P "SETERRQ[1-9]?.*\\\n\"" -- ${GITSRC} >> checkbadSource.out;true
420*1efe7de2SJames Wright	-@echo "----- Using if (condition) SETERRQ(...) instead of PetscCheck() ----" >> checkbadSource.out
421*1efe7de2SJames Wright	-@git --no-pager grep -n -P ' if +(.*) *SETERRQ' -- ${GITSRC} | grep -v 'PetscUnlikelyDebug' | grep -v 'petscerror.h' | grep -v "then;" | grep -v "__VA_ARGS__"  >> checkbadSource.out;true
422*1efe7de2SJames Wright	-@echo "----- Using if (PetscUnlikelyDebug(condition)) SETERRQ(...) instead of PetscAssert()" >> checkbadSource.out
423*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E ' if +\(PetscUnlikelyDebug.*\) *SETERRQ' -- ${GITSRC} | grep -v petscerror.h >> checkbadSource.out;true
424*1efe7de2SJames Wright	-@echo "----- Using PetscFunctionReturn(ierr) ------------------------------" >> checkbadSource.out
425*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'PetscFunctionReturn(ierr)' -- ${GITSRC} >> checkbadSource.out;true
426*1efe7de2SJames Wright	-@echo "----- Defining a returning macro without PetscMacroReturns() -------" >> checkbadSource.out
427*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'define .*\w+;\s+do' -- ${GITSRC} | grep -E -v '(PetscMacroReturns|PetscDrawCollectiveBegin|MatPreallocateBegin|PetscOptionsBegin|PetscObjectOptionsBegin|PetscOptionsHeadEnd)' >> checkbadSource.out;true
428*1efe7de2SJames Wright	-@echo "----- Defining an error checking macro using CHKERR style ----------" >> checkbadSource.out
429*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'define\s+CHKERR\w*\(.*\)\s*do\s+{' -- ${GITSRC} >> checkbadSource.out;true
430*1efe7de2SJames Wright	-@echo "----- Using Petsc[Array|Mem]cpy() for ops instead of assignment ----" >> checkbadSource.out
431*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'cpy\(.*(.|->)ops, .*\)' -- ${GITSRC} >> checkbadSource.out;true
432*1efe7de2SJames Wright	-@echo "----- Using PetscInfo() without carriage return --------------------" >> checkbadSource.out
433*1efe7de2SJames Wright	-@git --no-pager grep -n -P 'PetscCall\(PetscInfo\(' -- ${GITSRC} | grep -v '\\n' >> checkbadSource.out;true
434*1efe7de2SJames Wright	-@echo "----- Using Petsc(Assert|Check)() with carriage return -------------" >> checkbadSource.out
435*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E 'Petsc(Assert|Check)\(.*[^\]\\\n' -- ${GITSRC} >> checkbadSource.out;true
436*1efe7de2SJames Wright	-@echo "----- Extra \"\" after format specifier ending a string --------------" >> checkbadSource.out
437*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E '_FMT \"\",' -- ${GITSRC} >> checkbadSource.out;true
438*1efe7de2SJames Wright	-@echo "----- First blank line ---------------------------------------------" >> checkbadSource.out
439*1efe7de2SJames Wright	-@git --no-pager grep -n -P \^\$$ -- ${GITSRC} | grep ':1:' >> checkbadSource.out;true
440*1efe7de2SJames Wright	-@echo "----- Blank line after PetscFunctionBegin and derivatives ----------" >> checkbadSource.out
441*1efe7de2SJames Wright	-@git --no-pager grep -n -E -A 1 '  PetscFunctionBegin(User|Hot){0,1};' -- ${GITSRC} | grep -E '\-[0-9]+-$$' | grep -v '^--$$' >> checkbadSource.out;true
442*1efe7de2SJames Wright	-@echo "----- Blank line before PetscFunctionReturn ------------------------" >> checkbadSource.out
443*1efe7de2SJames Wright	-@git --no-pager grep -n -E -B 1 '  PetscFunctionReturn' -- ${GITSRC} | grep -E '\-[0-9]+-$$' | grep -v '^--$$' >> checkbadSource.out;true
444*1efe7de2SJames Wright	-@echo "----- No blank line before PetscFunctionBegin and derivatives ------" >> checkbadSource.out
445*1efe7de2SJames Wright	-@git --no-pager grep -n -E -B 1 '  PetscFunctionBegin(User|Hot){0,1};' -- ${GITSRC} ':!src/sys/tests/*' ':!src/sys/tutorials/*' | grep -E '\-[0-9]+-.*;' | grep -v '^--$$' | grep -v '\\' >> checkbadSource.out;true
446*1efe7de2SJames Wright	-@echo "----- Unneeded parentheses [!&~*](foo[->|.]bar) --------------------" >> checkbadSource.out
447*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E '([\!\&\~\*\(]|\)\)|\([^,\*\(]+\**\))\(([a-zA-Z0-9_]+((\.|->)[a-zA-Z0-9_]+|\[[a-zA-Z0-9_ \%\+\*\-]+\])+)\)' -- ${GITSRC} >> checkbadSource.out;true
448*1efe7de2SJames Wright	-@echo "----- Use PetscSafePointerPlusOffset(ptr, n) instead of ptr ? ptr + n : NULL" >> checkbadSource.out
449*1efe7de2SJames Wright	-@git --no-pager grep -n -Po ' ([^()\ ]+) \? (?1) \+ (.)* : NULL' -- ${GITSRC} >> checkbadSource.out;true
450*1efe7de2SJames Wright	-@echo "----- Wrong PETSc capitalization -----------------------------------" >> checkbadSource.out
451*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E '[^a-zA-Z_*>{.]petsc [^+=]' -- ${GITSRC} | grep -v 'mat_solver_type petsc' | grep -v ' PETSc ' >> checkbadSource.out;true
452*1efe7de2SJames Wright	-@echo "----- Unnecessary braces around one-liners -------------------------" >> checkbadSource.out
453*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E '[ ]*(if|for|while|do|else) \(.*\) \{[^;]*;[^;]*\}( \\)?$$' -- ${GITSRC} >> checkbadSource.out;true
454*1efe7de2SJames Wright	-@echo "----- MPI_(Allreduce|Irecv|Isend) instead of MPIU_(Allreduce|Irecv|Isend)" >> checkbadSource.out
455*1efe7de2SJames Wright	-@git --no-pager grep -n -P -E '\(MPI_(Allreduce|Irecv|Isend)\([^\)]' -- ${GITSRC} ':!*/tests/*' ':!*/tutorials/*' ':!src/sys/objects/pinit.c' >> checkbadSource.out;true
456*1efe7de2SJames Wright	@a=`cat checkbadSource.out | wc -l`; l=`expr $$a - 36` ;\
457*1efe7de2SJames Wright         if [ $$l -gt 0 ] ; then \
458*1efe7de2SJames Wright           echo $$l " files with errors detected in source code formatting" ;\
459*1efe7de2SJames Wright           cat checkbadSource.out ;\
460*1efe7de2SJames Wright         else \
461*1efe7de2SJames Wright	   ${RM} -f checkbadSource.out;\
462*1efe7de2SJames Wright         fi;\
463*1efe7de2SJames Wright         test ! $$l -gt 0
464*1efe7de2SJames Wright	-@git --no-pager grep -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" -- ${GITSRC} > badSourceChar.out;true
465*1efe7de2SJames Wright	-@w=`cat badSourceChar.out | wc -l`;\
466*1efe7de2SJames Wright         if [ $$w -gt 0 ] ; then \
467*1efe7de2SJames Wright           echo "Source files with non-ASCII characters ----------------" ;\
468*1efe7de2SJames Wright           cat badSourceChar.out ;\
469*1efe7de2SJames Wright         else \
470*1efe7de2SJames Wright	   ${RM} -f badSourceChar.out;\
471*1efe7de2SJames Wright         fi
472*1efe7de2SJames Wright	@test ! -s badSourceChar.out
473*1efe7de2SJames Wright
474a515125bSLeila Ghaffari-include $(src.o:%.o=%.d)
475