xref: /petsc/makefile (revision f1a0fde416081eec0802fc3fe2b62de3a9ab880c)
1#
2# See https://petsc.org/release/install/ for instructions on installing PETSc
3#
4# This is the top level makefile for compiling PETSc.
5#   * make help - useful messages on functionality
6#   * make all  - compile the PETSc libraries and utilities
7#   * make check - runs a quick test that the libraries are built correctly and PETSc applications can run
8#
9#   * make install - for use with ./configure is run with the --prefix=directory option
10#   * make test - runs a comprehensive test suite (requires gnumake)
11#   * make docs - build the entire PETSc website of documentation (locally)
12#   * a variety of rules that print library properties useful for building applications (use make help)
13#   * a variety of rules for PETSc developers
14#
15# gmakefile - manages the compiling PETSc in parallel
16# gmakefile.test - manages running the comprehensive test suite
17#
18# This makefile does not require GNUmake
19ALL: all
20DIRS = src include interfaces share/petsc/matlab
21
22# next line defines PETSC_DIR and PETSC_ARCH if they are not set
23include ././${PETSC_ARCH}/lib/petsc/conf/petscvariables
24include ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscrules
25include ${PETSC_DIR}/lib/petsc/conf/variables
26include ${PETSC_DIR}/lib/petsc/conf/rules.doc
27include ${PETSC_DIR}/lib/petsc/conf/rules.utils
28
29# This makefile contains a lot of PHONY targets with improperly specified prerequisites
30# where correct execution instead depends on the targets being processed in the correct
31# order.
32.NOTPARALLEL:
33
34OMAKE_SELF = $(OMAKE) -f makefile
35OMAKE_SELF_PRINTDIR = $(OMAKE_PRINTDIR) -f makefile
36
37#********* Rules for make all **********************************************************************************************************************************
38
39all:
40	+@${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} chk_upgrade | tee ${PETSC_ARCH}/lib/petsc/conf/make.log
41	@ln -sf ${PETSC_ARCH}/lib/petsc/conf/make.log make.log
42	+@(${OMAKE_SELF_PRINTDIR} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} all-local; echo "$$?" > ${PETSC_ARCH}/lib/petsc/conf/error.log) 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log
43	+@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then \
44           grep -E '(out of memory allocating.*after a total of|gfortran: fatal error: Killed signal terminated program f951|f95: fatal error: Killed signal terminated program f951)' ${PETSC_ARCH}/lib/petsc/conf/make.log | tee ${PETSC_ARCH}/lib/petsc/conf/memoryerror.log > /dev/null; \
45           if test -s ${PETSC_ARCH}/lib/petsc/conf/memoryerror.log; then \
46             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
47             echo "  Error during compile, you need to increase the memory allocated to the VM and rerun " 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
48             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
49           else \
50             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
51             echo "  Error during compile, check ${PETSC_ARCH}/lib/petsc/conf/make.log" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
52             echo "  Send it and ${PETSC_ARCH}/lib/petsc/conf/configure.log to petsc-maint@mcs.anl.gov" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
53             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
54           fi \
55	 else \
56	  ${OMAKE_SELF} print_mesg_after_build PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log ;\
57        fi #solaris make likes to print the whole command that gave error. So split this up into the smallest chunk below
58	@echo "Finishing make run at `date +'%a, %d %b %Y %H:%M:%S %z'`" >> ${PETSC_ARCH}/lib/petsc/conf/make.log
59	@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then exit 1; fi
60
61all-local: info libs matlabbin petsc4py-build libmesh-build mfem-build slepc-build hpddm-build amrex-build bamg-build
62
63${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files:
64	@touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files
65
66${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles:
67	@${MKDIR} -p ${PETSC_DIR}/${PETSC_ARCH}/tests && touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
68
69libs: ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
70	+@r=`echo "${MAKEFLAGS}" | grep ' -j'`; \
71        if [ "$$?" = 0 ]; then make_j=""; else make_j="-j${MAKE_NP}"; fi; \
72	r=`echo "${MAKEFLAGS}" | grep ' -l'`; \
73        if [ "$$?" = 0 ]; then make_l=""; else make_l="-l${MAKE_LOAD}"; fi; \
74        cmd="${OMAKE_PRINTDIR} -f gmakefile $${make_j} $${make_l} ${MAKE_PAR_OUT_FLG} V=${V} libs"; \
75        cd ${PETSC_DIR} && echo $${cmd} && exec $${cmd}
76
77chk_upgrade:
78	-@PETSC_DIR=${PETSC_DIR} ${PYTHON} ${PETSC_DIR}/lib/petsc/bin/petscnagupgrade.py
79
80matlabbin:
81	-@if [ "${MATLAB_MEX}" != "" -a "${MATLAB_SOCKET}" != "" -a "${PETSC_SCALAR}" = "real" -a "${PETSC_PRECISION}" = "double" ]; then \
82          echo "BEGINNING TO COMPILE MATLAB INTERFACE"; \
83            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc; fi; \
84            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab; fi; \
85            cd src/sys/classes/viewer/impls/socket/mex-scripts && ${OMAKE_SELF} mex-scripts PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR}; \
86            echo "========================================="; \
87        fi
88
89allfortranstubs:
90	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
91	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py ${BFORT}  ${VERBOSE}
92	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py -merge  ${VERBOSE}
93	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
94
95deleteshared:
96	@for LIBNAME in ${SHLIBS}; \
97	do \
98	   if [ -d ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM ]; then \
99             echo ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
100	     ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
101	   fi; \
102           echo ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
103           ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
104	done
105	@if [ -f ${INSTALL_LIB_DIR}/so_locations ]; then \
106          echo ${RM} ${INSTALL_LIB_DIR}/so_locations; \
107          ${RM} ${INSTALL_LIB_DIR}/so_locations; \
108	fi
109
110deletefortranstubs:
111	-@find . -type d -name ftn-auto | xargs rm -rf
112
113reconfigure: allclean
114	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
115
116chkopts:
117	-@echo "Warning: chkopts target is deprecated and can be removed from user makefiles"
118
119gnumake:
120	+@echo "make gnumake is deprecated, use make libs"
121	+@make libs
122
123# ********  Rules for make check ****************************************************************************************************************************
124
125RUN_TEST = ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff
126
127check_install: check
128check:
129	-@echo "Running check examples to verify correct installation"
130	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
131	@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
132           echo "Running with batch filesystem, cannot run make check"; \
133        elif [ "${MPIEXEC}" = "/bin/false" ]; then \
134           echo "*mpiexec not found*. cannot run make check"; \
135        else \
136          ${RM} -f check_error;\
137          ${RUN_TEST} PETSC_OPTIONS="${PETSC_OPTIONS} ${PETSC_TEST_OPTIONS}" PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" check_build 2>&1 | tee ./${PETSC_ARCH}/lib/petsc/conf/check.log; \
138          if [ -f check_error ]; then \
139            echo "Error while running make check"; \
140            ${RM} -f check_error;\
141            exit 1; \
142          fi; \
143          ${RM} -f check_error;\
144        fi;
145
146check_build:
147	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} clean-legacy
148	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19
149	+@if [ ! "${MPI_IS_MPIUNI}" ]; then cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19_mpi; fi
150	+@if [ "${HYPRE_LIB}" != "" ] && [ "${PETSC_SCALAR}" = "real" ]; then \
151          if [ "${CUDA_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_cuda; \
152          elif [ "${HIP_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_hip; \
153          else HYPRE_TEST=runex19_hypre; fi; \
154          cd src/snes/tutorials >/dev/null; ${RUN_TEST} $${HYPRE_TEST}; \
155        fi;
156	+@if [ "${CUDA_LIB}" != "" ]; then \
157          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_cuda; \
158        fi;
159	+@if [ "${MPI_IS_MPIUNI}" = "" ]; then \
160          cd src/snes/tutorials >/dev/null; \
161          if [ "${KOKKOS_KERNELS_LIB}" != "" ]  &&  [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ]; then \
162            ${RUN_TEST} runex3k_kokkos; \
163          fi;\
164          if [ "${MUMPS_LIB}" != "" ]; then \
165             ${RUN_TEST} runex19_fieldsplit_mumps; \
166          fi;\
167          if [ "${SUITESPARSE_LIB}" != "" ]; then \
168             ${RUN_TEST} runex19_suitesparse; \
169          fi;\
170          if [ "${SUPERLU_DIST_LIB}" != "" ]; then \
171            ${RUN_TEST} runex19_superlu_dist; \
172          fi;\
173          if ( [ "${ML_LIB}" != "" ] ||  [ "${TRILINOS_LIB}" != "" ] ); then \
174            ${RUN_TEST} runex19_ml; \
175          fi; \
176	  ${RUN_TEST} clean-legacy; \
177          cd - > /dev/null; \
178          if ( [ "${AMREX_LIB}" != "" ] && [ "${CUDA_LIB}" = "" ] ); then \
179            echo "Running amrex test example to verify correct installation";\
180            echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}";\
181            cd src/ksp/ksp/tutorials/amrex >/dev/null;\
182            ${RUN_TEST} clean-legacy; \
183            ${RUN_TEST} testamrex; \
184            ${RUN_TEST} clean-legacy; \
185            cd - > /dev/null; \
186          fi;\
187        fi;
188	+@if [ "${HDF5_LIB}" != "" ]; then \
189          cd src/vec/vec/tests >/dev/null;\
190          ${RUN_TEST} clean-legacy; \
191          ${RUN_TEST} runex47; \
192          ${RUN_TEST} clean-legacy; \
193         fi;
194	+@if [ "${MPI4PY}" = "yes" ]; then \
195           cd src/sys/tests >/dev/null; \
196           ${RUN_TEST} clean-legacy; \
197           ${RUN_TEST} testex55; \
198           ${RUN_TEST} clean-legacy; \
199         fi;
200	+@if [ "${PETSC4PY}" = "yes" ]; then \
201           cd src/ksp/ksp/tutorials >/dev/null; \
202           ${RUN_TEST} clean-legacy; \
203           ${RUN_TEST} testex100; \
204           ${RUN_TEST} clean-legacy; \
205         fi;
206	+@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
207         if test -s .ftn.log; then \
208           cd src/snes/tutorials >/dev/null; \
209           ${RUN_TEST} clean-legacy; \
210           ${RUN_TEST} testex5f; \
211           ${RUN_TEST} clean-legacy; \
212         fi; ${RM} .ftn.log;
213	+@grep -E "^#define PETSC_HAVE_MATLAB 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
214         if test -s .ftn.log; then \
215           cd src/vec/vec/tutorials >/dev/null; \
216           ${RUN_TEST} clean-legacy; \
217           ${RUN_TEST} testex31; \
218           ${RUN_TEST} clean-legacy; \
219          fi; ${RM} .ftn.log;
220	-@echo "Completed test examples"
221
222# ********* Rules for make install *******************************************************************************************************************
223
224install:
225	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
226	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
227
228# A smaller install with fewer extras
229install-lib:
230	@${PYTHON} ./config/install.py -destDir=${DESTDIR} -no-examples
231	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
232
233install-builtafterpetsc:
234	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=${PETSC_INSTALL} petsc4py-install libmesh-install mfem-install slepc-install hpddm-install amrex-install bamg-install
235
236# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
237dist:
238	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
239
240# ******** Rules for running the full test suite ********************************************************************************************************
241
242TESTMODE = testexamples
243ALLTESTS_CHECK_FAILURES = no
244ALLTESTS_MAKEFILE = ${PETSC_DIR}/gmakefile.test
245VALGRIND=0
246alltests: chk_in_petscdir ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
247	-@${RM} -rf ${PETSC_ARCH}/lib/petsc/conf/alltests.log alltests.log
248	+@if [ -f ${PETSC_DIR}/share/petsc/examples/gmakefile.test ] ; then \
249            ALLTESTS_MAKEFILE=${PETSC_DIR}/share/petsc/examples/gmakefile.test ; \
250            ALLTESTSLOG=alltests.log ;\
251          else \
252            ALLTESTS_MAKEFILE=${PETSC_DIR}/gmakefile.test; \
253            ALLTESTSLOG=${PETSC_ARCH}/lib/petsc/conf/alltests.log ;\
254            ln -s $${ALLTESTSLOG} alltests.log ;\
255          fi; \
256          ${OMAKE} allgtest ALLTESTS_MAKEFILE=$${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} MPIEXEC="${MPIEXEC}" DATAFILESPATH=${DATAFILESPATH} VALGRIND=${VALGRIND} 2>&1 | tee $${ALLTESTSLOG};\
257          if [ x${ALLTESTS_CHECK_FAILURES} = xyes -a ${PETSC_PRECISION} != single ]; then \
258            cat $${ALLTESTSLOG} | grep -E '(^not ok|not remade because of errors|^# No tests run)' | wc -l | grep '^[ ]*0$$' > /dev/null; \
259          fi;
260
261allgtests-tap: allgtest-tap
262	+@${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check-test-errors
263
264allgtest-tap: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
265	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test OUTPUT=1
266
267allgtest: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
268	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} -k -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test V=0 2>&1 | grep -E -v '^(ok [^#]*(# SKIP|# TODO|$$)|[A-Za-z][A-Za-z0-9_]*\.(c|F|cxx|F90).$$)'
269
270test:
271	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test
272cleantest:
273	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} cleantest
274
275#********* Rules for cleaning ***************************************************************************************************************************
276
277deletelibs:
278	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
279deletemods:
280	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
281
282allclean:
283	-@${OMAKE} -f gmakefile clean
284
285clean:: allclean
286
287distclean:
288	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
289	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
290          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; fi
291	@echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"
292	-${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/
293
294info:
295	-@echo "=========================================="
296	-@echo " "
297	-@echo "See documentation/faq.html and documentation/bugreporting.html"
298	-@echo "for help with installation problems.  Please send EVERYTHING"
299	-@echo "printed out below when reporting problems.  Please check the"
300	-@echo "mailing list archives and consider subscribing."
301	-@echo " "
302	-@echo "  https://petsc.org/release/community/mailing/"
303	-@echo " "
304	-@echo "=========================================="
305	-@echo Starting make run on `hostname` at `date +'%a, %d %b %Y %H:%M:%S %z'`
306	-@echo Machine characteristics: `uname -a`
307	-@echo "-----------------------------------------"
308	-@echo "Using PETSc directory: ${PETSC_DIR}"
309	-@echo "Using PETSc arch: ${PETSC_ARCH}"
310	-@echo "-----------------------------------------"
311	-@grep "define PETSC_VERSION" ${PETSC_DIR}/include/petscversion.h | ${SED} "s/........//" | head -n 7
312	-@echo "-----------------------------------------"
313	-@echo "Using configure Options: ${CONFIGURE_OPTIONS}"
314	-@echo "Using configuration flags:"
315	-@grep "\#define " ${PETSCCONF_H} | tail -n +2
316	-@echo "-----------------------------------------"
317	-@echo "Using C compile: ${PETSC_CCOMPILE_SINGLE}"
318	-@if [  "${MPICC_SHOW}" != "" ]; then \
319             printf  "mpicc -show: %b\n" "${MPICC_SHOW}";\
320          fi; \
321        printf  "C compiler version: %b\n" "${C_VERSION}"; \
322        if [ "${CXX}" != "" ]; then \
323        echo "Using C++ compile: ${PETSC_CXXCOMPILE_SINGLE}";\
324        if [ "${MPICXX_SHOW}" != "" ]; then \
325               printf "mpicxx -show: %b\n" "${MPICXX_SHOW}"; \
326            fi;\
327            printf  "C++ compiler version: %b\n" "${Cxx_VERSION}"; \
328          fi
329	-@if [ "${FC}" != "" ]; then \
330	   echo "Using Fortran compile: ${PETSC_FCOMPILE_SINGLE}";\
331           if [ "${MPIFC_SHOW}" != "" ]; then \
332             printf "mpif90 -show: %b\n" "${MPIFC_SHOW}"; \
333           fi; \
334             printf  "Fortran compiler version: %b\n" "${FC_VERSION}"; \
335         fi
336	-@if [ "${CUDAC}" != "" ]; then \
337	   echo "Using CUDA compile: ${PETSC_CUCOMPILE_SINGLE}";\
338         fi
339	-@if [ "${CLANGUAGE}" = "CXX" ]; then \
340           echo "Using C++ compiler to compile PETSc";\
341        fi
342	-@echo "-----------------------------------------"
343	-@echo "Using C/C++ linker: ${PCC_LINKER}"
344	-@echo "Using C/C++ flags: ${PCC_LINKER_FLAGS}"
345	-@if [ "${FC}" != "" ]; then \
346	   echo "Using Fortran linker: ${FC_LINKER}";\
347	   echo "Using Fortran flags: ${FC_LINKER_FLAGS}";\
348         fi
349	-@echo "-----------------------------------------"
350	-@echo "Using system modules: ${LOADEDMODULES}"
351	-@if [ "${MPI_IS_MPIUNI}" = "1" ]; then \
352           echo Using mpi.h: mpiuni; \
353        else \
354           TESTDIR=`mktemp -q -d -t petscmpi-XXXXXXXX` && \
355           echo '#include <mpi.h>' > $${TESTDIR}/mpitest.c && \
356           BUF=`${CPP} ${PETSC_CPPFLAGS} ${PETSC_CC_INCLUDES} $${TESTDIR}/mpitest.c |grep 'mpi\.h' | ( head -1 ; cat > /dev/null )` && \
357           echo Using mpi.h: $${BUF}; ${RM} -rf $${TESTDIR}; \
358        fi
359	-@echo "-----------------------------------------"
360	-@echo "Using libraries: ${PETSC_LIB}"
361	-@echo "------------------------------------------"
362	-@echo "Using mpiexec: ${MPIEXEC}"
363	-@echo "------------------------------------------"
364	-@echo "Using MAKE: ${MAKE}"
365	-@echo "Default MAKEFLAGS: MAKE_NP:${MAKE_NP} MAKE_LOAD:${MAKE_LOAD} MAKEFLAGS:${MAKEFLAGS}"
366	-@echo "=========================================="
367
368
369check_usermakefile:
370	-@echo "Testing compile with user makefile"
371	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
372	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
373	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
374	@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
375         if test -s .ftn.log; then \
376          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
377         fi; ${RM} .ftn.log;
378	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
379	-@echo "Completed compile with user makefile"
380
381#********* Rules for running clangformat ************************************************************************************************************
382
383checkgitclean:
384	@if ! git diff --quiet; then \
385           echo "The repository has uncommitted files, cannot run checkclangformat" ;\
386           git status -s --untracked-files=no ;\
387           false;\
388        fi;
389
390checkclangformatversion:
391	@version=`clang-format --version | cut -d" " -f3 | cut -d"." -f 1` ;\
392         if [ "$$version" == "version" ]; then version=`clang-format --version | cut -d" " -f4 | cut -d"." -f 1`; fi;\
393         if [ $$version != 16 ]; then echo "Require clang-format version 16! Currently used clang-format version is $$version" ;false ; fi
394
395# Check that all the source code in the repository satisfies the .clang_format
396checkclangformat: checkclangformatversion checkgitclean clangformat
397	@if ! git diff --quiet; then \
398          printf "The current commit has source code formatting problems\n" ;\
399          if [ -z "${CI_PIPELINE_ID}"  ]; then \
400            printf "Please run 'git diff' to check\n"; \
401            git diff --stat; \
402          else \
403            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch; \
404            git diff --patch-with-stat --color=always | head -1000; \
405            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch` -gt 1000 ]; then \
406              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch (in CI artifacts) for all changes\n"; \
407            fi;\
408          fi;\
409          false;\
410        fi;
411
412# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
413abitest:
414	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
415		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
416		exit 1; \
417	fi;
418	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
419	-@echo "========================================================================================="
420	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
421	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
422	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
423	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
424	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
425	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
426	-@echo "========================================================================================="
427	-@$(PYTHON)	${PETSC_DIR}/lib/petsc/bin/maint/abicheck.py -old_dir ${PETSC_DIR_ABI_OLD} -old_arch ${PETSC_ARCH_ABI_OLD} -new_dir ${PETSC_DIR} -new_arch ${PETSC_ARCH} -report_format html
428
429# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
430abitestcomplete:
431	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
432          OPTIONS=`grep -h -m 1 "Configure Options: " ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log  | sed "s!Configure Options: --configModules=PETSc.Configure --optionsModule=config.compilerOptions!!g"` ;\
433echo $${OPTIONS} ;\
434        fi ; \
435        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
436          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
437        else \
438          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
439        fi ; \
440        echo "=================================================================================================" ;\
441        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
442        echo "=================================================================================================" ;\
443        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
444          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
445        else \
446          cd $${PETSC_DIR_OLD} ; \
447          git pull ; \
448        fi ; \
449        cd $${PETSC_DIR_OLD} ; \
450        git checkout ${branch} ; \
451        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
452        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
453        cd ${PETSC_DIR} ; \
454        ./configure $${OPTIONS}; \
455        make all test ; \
456        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
457
458# ******** Rules for running Streams benchmark ****************************************************************************************************
459
460mpistreams:
461	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
462
463mpistream:
464	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
465
466openmpstreams:
467	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
468
469openmpstream:
470	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
471
472stream: mpistream
473
474streams: mpistreams
475
476# ********  Rules for generating tag files for Emacs/VIM *******************************************************************************************
477
478alletags:
479	-@${PYTHON} lib/petsc/bin/maint/generateetags.py
480	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
481
482# obtain gtags from https://www.gnu.org/software/global/
483allgtags:
484	-@find ${PETSC_DIR}/include ${PETSC_DIR}/src -regex '\(.*makefile\|.*\.\(cc\|hh\|cpp\|cxx\|C\|hpp\|c\|h\|cu\|m\)$$\)' | grep -v ftn-auto  | gtags -f -
485
486# ********* Rules for building "classic" documentation; uses rules also in lib/petsc/conf/rules.doc **************************************************
487
488docs:
489	cd doc; ${OMAKE_SELF} sphinxhtml
490
491chk_in_petscdir:
492	@if [ ! -f include/petscversion.h ]; then \
493	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
494	  echo " This target should be invoked in top level PETSc source dir!"; \
495	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
496
497chk_loc:
498	@if [ ${LOC}foo = foo ] ; then \
499	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
500	  echo " Please specify LOC variable for eg: make allmanpages LOC=/sandbox/petsc "; \
501	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
502	@${MKDIR} ${LOC}/manualpages
503
504chk_c2html:
505	@if [ ${C2HTML}foo = foo ] ; then \
506          printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR ************************\n" ; \
507          echo "Require c2html for html docs. Please reconfigure with --download-c2html=1"; \
508          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ;false; fi
509
510
511# the ACTION=manualpages cannot run in parallel because they all write to the same manualpages.cit file
512hloc=include/petsc/private
513allmanpages: chk_loc deletemanualpages
514	-echo " /* SUBMANSEC = PetscH */ " > ${hloc}/generated_khash.h
515	-sed -e 's?<T>?I?g' -e 's?<t>?i?g' -e 's?<KeyType>?PetscInt?g' ${hloc}/hashset.txt >> ${hloc}/generated_khash.h
516	-sed -e 's?<T>?IJ?g' -e 's?<t>?ij?g' -e 's?<KeyType>?struct {PetscInt i, j;}?g' ${hloc}/hashset.txt >> ${hloc}/generated_khash.h
517	-sed -e 's?<T>?I?g' -e 's?<t>?i?g' -e 's?<KeyType>?PetscInt?g'  -e 's?<ValType>?PetscInt?g' ${hloc}/hashmap.txt >> ${hloc}/generated_khash.h
518	-sed -e 's?<T>?IJ?g' -e 's?<t>?ij?g' -e 's?<KeyType>?struct {PetscInt i, j;}?g' -e 's?<ValType>?PetscInt?g' ${hloc}/hashmap.txt >> ${hloc}/generated_khash.h
519	-sed -e 's?<T>?IJ?g' -e 's?<t>?ij?g' -e 's?<KeyType>?struct {PetscInt i, j;}?g' -e 's?<ValType>?PetscScalar?g' ${hloc}/hashmap.txt >> ${hloc}/generated_khash.h
520	-sed -e 's?<T>?IV?g' -e 's?<t>?iv?g' -e 's?<KeyType>?PetscInt?g'  -e 's?<ValType>?PetscScalar?g' ${hloc}/hashmap.txt >> ${hloc}/generated_khash.h
521	-sed -e 's?<T>?Obj?g' -e 's?<t>?obj?g' -e 's?<KeyType>?PetscInt64?g'  -e 's?<ValType>?PetscObject?g' ${hloc}/hashmap.txt >> ${hloc}/generated_khash.h
522	-${RM} ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
523	-${OMAKE_SELF} ACTION=manualpages tree_src LOC=${LOC}
524	-@sed -e s%man+../%man+manualpages/% ${LOC}/manualpages/manualpages.cit > ${LOC}/manualpages/htmlmap
525	-@cat ${PETSC_DIR}/doc/classic/mpi.www.index >> ${LOC}/manualpages/htmlmap
526	cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
527	a=`cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err | wc -l`; test ! $$a -gt 0
528
529allmanexamples: chk_loc allmanpages
530	-${OMAKE_SELF} ACTION=manexamples tree LOC=${LOC}
531
532#
533#    Goes through all manual pages adding links to implementations of the method
534# or class, at the end of the file.
535#
536# To find functions implementing methods, we use git grep to look for
537# well-formed PETSc functions
538# - with names containing a single underscore
539# - in files of appropriate types (.cu .c .cxx .h),
540# - in paths including "/impls/",
541# - excluding any line with a semicolon (to avoid matching prototypes), and
542# - excluding any line including "_Private",
543# storing potential matches in implsFuncAll.txt.
544#
545# For each man page we then grep in this file for the item's name followed by
546# a single underscore and process the resulting implsFunc.txt to generate HTML.
547#
548# To find class implementations, we populate implsClassAll.txt with candidates
549# - of the form "struct _p_itemName {",  and
550# - not containing a semicolon
551# and then grep for particular values of itemName, generating implsClass.txt,
552# which is processed to generate HTML.
553#
554# Note: PETSC_DOC_OUT_ROOT_PLACEHOLDER must match the term used elsewhere in doc/
555manimplementations:
556	-@git grep "struct\s\+_[pn]_[^\s]\+.*{" -- *.cpp *.cu *.c *.h *.cxx | grep -v -e ";" -e "/tests/" -e "/tutorials/" > implsClassAll.txt ; \
557  git grep -n "^\(static \)\?\(PETSC_EXTERN \)\?\(PETSC_INTERN \)\?\(extern \)\?PetscErrorCode \+[^_ ]\+_[^_ ]\+(" -- '*/impls/*.c' '*/impls/*.cpp' '*/impls/*.cu' '*/impls/*.cxx' '*/impls/*.h' | grep -v -e ";" -e "_[Pp]rivate" > implsFuncAll.txt ; \
558  for i in ${LOC}/manualpages/*/*.md foo; do \
559       if [ "$$i" != "foo" ] ; then \
560          itemName=`basename $$i .md`;\
561          grep "\s$${itemName}_" implsFuncAll.txt > implsFunc.txt ; \
562          grep "_p_$${itemName}\b" implsClassAll.txt > implsClass.txt ; \
563          if [ -s implsFunc.txt ] || [ -s implsClass.txt ] ; then \
564            printf "\n## Implementations\n\n" >> $$i; \
565          fi ; \
566          if [ -s implsFunc.txt ] ; then \
567            sed "s?\(.*\.[ch]x*u*\).*\($${itemName}.*\)(.*)?<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\1.html#\2\">\2 in \1</A><BR>?" implsFunc.txt >> $$i ; \
568          fi ; \
569          if [ -s implsClass.txt ] ; then \
570            sed "s?\(.*\.[ch]x*u*\):.*\(_p_$${itemName}\)\b.*{?<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\1.html#\2\">\2 in \1</A><BR>?" implsClass.txt >> $$i ; \
571          fi ; \
572          ${RM} implsFunc.txt implsClass.txt; \
573       fi ; \
574  done ; \
575  ${RM} implsClassAll.txt implsFuncAll.txt
576
577# Build all classic docs except html sources
578alldoc_pre: chk_loc allmanpages allmanexamples
579	-${OMAKE_SELF} LOC=${LOC} manimplementations
580	-${PYTHON} lib/petsc/bin/maint/wwwindex.py ${PETSC_DIR} ${LOC}
581
582# Run after alldoc_pre to build html sources
583alldoc_post: chk_loc  chk_c2html
584	-@if command -v parallel &> /dev/null; then \
585           ls include/makefile src/*/makefile | xargs dirname | parallel -j ${MAKE_TEST_NP} --load ${MAKE_LOAD} 'cd {}; ${OMAKE_SELF} HTMLMAP=${HTMLMAP} LOC=${LOC} PETSC_DIR=${PETSC_DIR} ACTION=html tree' ; \
586         else \
587           ${OMAKE_SELF} HTMLMAP=${HTMLMAP} LOC=${LOC} PETSC_DIR=${PETSC_DIR} ACTION=html tree; \
588        fi
589
590alldocclean: deletemanualpages allcleanhtml
591
592# Deletes man pages (.md version)
593deletemanualpages: chk_loc
594	-@if [ -d ${LOC} -a -d ${LOC}/manualpages ]; then \
595          find ${LOC}/manualpages -type f -name "*.md" -exec ${RM} {} \; ;\
596          ${RM} ${LOC}/manualpages/manualpages.cit ;\
597        fi
598
599allcleanhtml:
600	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} tree
601
602# ********* Rules for checking code coverage *********************************************************************************************
603
604gcov:
605	output_file_base_name=${PETSC_ARCH}-gcovr-report.json; \
606	petsc_arch_dir=${PETSC_DIR}/${PETSC_ARCH}; \
607        tar_file=$${petsc_arch_dir}/$${output_file_base_name}.tar.bz2; \
608	cd $${petsc_arch_dir}/obj && \
609	gcovr --json --output $${petsc_arch_dir}/$${output_file_base_name} --exclude '.*/ftn-auto/.*' --exclude-lines-by-pattern '^\s*SETERR.*' --exclude-throw-branches --exclude-unreachable-branches -j 4 --gcov-executable "${PETSC_COVERAGE_EXEC}" --root ${PETSC_DIR} . ${PETSC_GCOV_OPTIONS} && \
610	${RM} -f $${tar_file} && \
611	tar --bzip2 -cf $${tar_file} -C $${petsc_arch_dir} ./$${output_file_base_name} && \
612	${RM} $${petsc_arch_dir}/$${output_file_base_name}
613
614mergegcov:
615	$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge-branch `lib/petsc/bin/maint/check-merge-branch.sh` --html --xml ${PETSC_GCOV_OPTIONS}
616
617countfortranfunctions:
618	-@cd ${PETSC_DIR}/src/fortran; grep -E '^void' custom/*.c auto/*.c | \
619	cut -d'(' -f1 | tr -s  ' ' | cut -d' ' -f2 | uniq | grep -E -v "(^$$|Petsc)" | \
620	sed "s/_$$//" | sort > /tmp/countfortranfunctions
621
622countcfunctions:
623	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
624	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
625	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
626
627difffortranfunctions: countfortranfunctions countcfunctions
628	-@echo -------------- Functions missing in the fortran interface ---------------------
629	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^<" | cut -d' ' -f2
630	-@echo ----------------- Functions missing in the C interface ------------------------
631	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^>" | cut -d' ' -f2
632	-@${RM}  /tmp/countcfunctions /tmp/countfortranfunctions
633
634checkbadfortranstubs:
635	-@echo "========================================="
636	-@echo "Functions with MPI_Comm as an Argument"
637	-@echo "========================================="
638	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'MPI_Comm' | \
639	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
640	-@echo "========================================="
641	-@echo "Functions with a String as an Argument"
642	-@echo "========================================="
643	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'char \*' | \
644	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
645	-@echo "========================================="
646	-@echo "Functions with Pointers to PETSc Objects as Argument"
647	-@echo "========================================="
648	-@cd ${PETSC_DIR}/src/fortran/auto; \
649	_p_OBJ=`grep _p_ ${PETSC_DIR}/include/*.h | tr -s ' ' | \
650	cut -d' ' -f 3 | tr -s '\012' | grep -v '{' | cut -d'*' -f1 | \
651	sed "s/_p_//g" | tr -s '\012 ' ' *|' ` ; \
652	for OBJ in $$_p_OBJ; do \
653	grep "$$OBJ \*" *.c | tr -s ' ' | tr -s ':' ' ' | \
654	cut -d'(' -f1 | cut -d' ' -f1,3; \
655	done
656
657checkpackagetests:
658	-@echo "Missing package tests"
659	-@cat config/examples/*.py > configexamples; pushd config/BuildSystem/config/packages/; packages=`ls *.py | sed "s/\\.py//g"`;popd; for i in $${packages}; do j=`echo $${i} | tr '[:upper:]' '[:lower:]'`; printf $${j} ; grep -E "(with-$${j}|download-$${j})" configexamples | grep -v "=0" | wc -l ; done
660	-@echo "Missing download package tests"
661	-@cat config/examples/*.py > configexamples; pushd config/BuildSystem/config/packages/; packages=`grep -l "download " *.py  | sed "s/\\.py//g"`;popd; for i in $${packages}; do j=`echo $${i} | tr '[:upper:]' '[:lower:]'`; printf $${j} ; grep -E "(download-$${j})" configexamples | grep -v "=0" | wc -l ; done
662
663check_petsc4py_rst:
664	@${RM} -f petsc4py_rst.log
665	@echo "Checking src/binding/petsc4py/DESCRIPTION.rst"
666	@rst2html src/binding/petsc4py/DESCRIPTION.rst > /dev/null 2> petsc4py_rst.log
667	@if test -s petsc4py_rst.log; then cat petsc4py_rst.log; exit 1; fi
668
669# TODO: checkTestCoverage: that makes sure every tutorial test has at least one test listed in the file, perhaps handled by gmakegentest.py
670# TODO: check for PetscBeginFunctionUser in non-example source
671# TODO: check for __ at start of #define or symbol
672# TODO: checking for missing manual pages
673# TODO: check for incorrect %d
674# TODO: check for double blank lines
675# TODO: check for ill-formed manual pages
676# TODO: check for { on line after for
677# TODO: check for } then else on following line
678# TODO: check for } else { with SETERRQ on following line or if () { with SETERRQ on following line
679
680checkbadSpelling:
681	-@x=`python3 ../bin/extract.py | aspell list | sort -u` ;
682
683updatedatafiles:
684	-@if [ -d "${HOME}/datafiles" ]; then \
685            echo " ** Updating datafiles at ${HOME}/datafiles **"; \
686            cd "${HOME}/datafiles" && git pull -q; fi
687
688.PHONY: info info_h all deletelibs allclean update \
689        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanpages \
690        allcleanhtml  countfortranfunctions \
691        start_configure configure_petsc configure_clean matlabbin install
692