xref: /petsc/makefile (revision ed5129f1107a1f646d097a6cc1a3fa1878fa2eb0)
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
27
28# This makefile contains a lot of PHONY targets with improperly specified prerequisites
29# where correct execution instead depends on the targets being processed in the correct
30# order.
31.NOTPARALLEL:
32
33OMAKE_SELF = $(OMAKE) -f makefile
34OMAKE_SELF_PRINTDIR = $(OMAKE_PRINTDIR) -f makefile
35
36#********* Rules for make all **********************************************************************************************************************************
37
38all:
39	+@${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} chk_petscdir chk_upgrade | tee ${PETSC_ARCH}/lib/petsc/conf/make.log
40	@ln -sf ${PETSC_ARCH}/lib/petsc/conf/make.log make.log
41	+@(${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
42	+@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then \
43           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; \
44           if test -s ${PETSC_ARCH}/lib/petsc/conf/memoryerror.log; then \
45             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
46             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; \
47             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
48           else \
49             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
50             echo "  Error during compile, check ${PETSC_ARCH}/lib/petsc/conf/make.log" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
51             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;\
52             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
53           fi \
54	 else \
55	  ${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 ;\
56        fi #solaris make likes to print the whole command that gave error. So split this up into the smallest chunk below
57	@echo "Finishing make run at `date +'%a, %d %b %Y %H:%M:%S %z'`" >> ${PETSC_ARCH}/lib/petsc/conf/make.log
58	@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then exit 1; fi
59
60all-local: info libs matlabbin petsc4py-build libmesh-build mfem-build slepc-build hpddm-build amrex-build bamg-build
61
62${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files:
63	@touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files
64
65${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles:
66	@${MKDIR} -p ${PETSC_DIR}/${PETSC_ARCH}/tests && touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
67
68libs: ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
69	+@r=`echo "${MAKEFLAGS}" | grep ' -j'`; \
70        if [ "$$?" = 0 ]; then make_j=""; else make_j="-j${MAKE_NP}"; fi; \
71	r=`echo "${MAKEFLAGS}" | grep ' -l'`; \
72        if [ "$$?" = 0 ]; then make_l=""; else make_l="-l${MAKE_LOAD}"; fi; \
73        cmd="${OMAKE_PRINTDIR} -f gmakefile $${make_j} $${make_l} ${MAKE_PAR_OUT_FLG} V=${V} libs"; \
74        cd ${PETSC_DIR} && echo $${cmd} && exec $${cmd}
75
76chk_upgrade:
77	-@PETSC_DIR=${PETSC_DIR} ${PYTHON} ${PETSC_DIR}/lib/petsc/bin/petscnagupgrade.py
78
79chklib_dir:
80	@if [ ! -d "${INSTALL_LIB_DIR}" ]; then \
81	  echo Making directory ${INSTALL_LIB_DIR} for library; ${MKDIR} ${INSTALL_LIB_DIR} ; fi
82
83matlabbin:
84	-@if [ "${MATLAB_MEX}" != "" -a "${MATLAB_SOCKET}" != "" -a "${PETSC_SCALAR}" = "real" -a "${PETSC_PRECISION}" = "double" ]; then \
85          echo "BEGINNING TO COMPILE MATLAB INTERFACE"; \
86            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc; fi; \
87            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab; fi; \
88            cd src/sys/classes/viewer/impls/socket/mex-scripts && ${OMAKE_SELF} mex-scripts PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR}; \
89            echo "========================================="; \
90        fi
91
92allfortranstubs:
93	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
94	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py ${BFORT}  ${VERBOSE}
95	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py -merge  ${VERBOSE}
96	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
97
98deleteshared:
99	@for LIBNAME in ${SHLIBS}; \
100	do \
101	   if [ -d ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM ]; then \
102             echo ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
103	     ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
104	   fi; \
105           echo ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
106           ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
107	done
108	@if [ -f ${INSTALL_LIB_DIR}/so_locations ]; then \
109          echo ${RM} ${INSTALL_LIB_DIR}/so_locations; \
110          ${RM} ${INSTALL_LIB_DIR}/so_locations; \
111	fi
112
113deletefortranstubs:
114	-@find . -type d -name ftn-auto | xargs rm -rf
115
116reconfigure: allclean
117	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
118
119chkopts:
120	-@echo "Warning: chkopts target is deprecated and can be removed from user makefiles"
121
122gnumake:
123	+@echo "make gnumake is deprecated, use make libs"
124	+@make libs
125
126# ********  Rules for make check ****************************************************************************************************************************
127
128RUN_TEST = ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff
129
130check_install: check
131check:
132	-@echo "Running check examples to verify correct installation"
133	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
134	@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
135           echo "Running with batch filesystem, cannot run make check"; \
136        elif [ "${MPIEXEC}" = "/bin/false" ]; then \
137           echo "*mpiexec not found*. cannot run make check"; \
138        else \
139          ${RM} -f check_error;\
140          ${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; \
141          if [ -f check_error ]; then \
142            echo "Error while running make check"; \
143            ${RM} -f check_error;\
144            exit 1; \
145          fi; \
146          ${RM} -f check_error;\
147        fi;
148
149check_build:
150	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} clean-legacy
151	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19
152	+@if [ ! "${MPI_IS_MPIUNI}" ]; then cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19_mpi; fi
153	+@if [ "${HYPRE_LIB}" != "" ] && [ "${PETSC_SCALAR}" = "real" ]; then \
154          if [ "${CUDA_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_cuda; \
155          elif [ "${HIP_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_hip; \
156          else HYPRE_TEST=runex19_hypre; fi; \
157          cd src/snes/tutorials >/dev/null; ${RUN_TEST} $${HYPRE_TEST}; \
158        fi;
159	+@if [ "${CUDA_LIB}" != "" ]; then \
160          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_cuda; \
161        fi;
162	+@if [ "${MPI_IS_MPIUNI}" = "" ]; then \
163          cd src/snes/tutorials >/dev/null; \
164          if [ "${KOKKOS_KERNELS_LIB}" != "" ]  &&  [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ]; then \
165            ${RUN_TEST} runex3k_kokkos; \
166          fi;\
167          if [ "${MUMPS_LIB}" != "" ]; then \
168             ${RUN_TEST} runex19_fieldsplit_mumps; \
169          fi;\
170          if [ "${SUITESPARSE_LIB}" != "" ]; then \
171             ${RUN_TEST} runex19_suitesparse; \
172          fi;\
173          if [ "${SUPERLU_DIST_LIB}" != "" ]; then \
174            ${RUN_TEST} runex19_superlu_dist; \
175          fi;\
176          if ( [ "${ML_LIB}" != "" ] ||  [ "${TRILINOS_LIB}" != "" ] ); then \
177            ${RUN_TEST} runex19_ml; \
178          fi; \
179	  ${RUN_TEST} clean-legacy; \
180          cd - > /dev/null; \
181          if ( [ "${AMREX_LIB}" != "" ] && [ "${CUDA_LIB}" = "" ] ); then \
182            echo "Running amrex test example to verify correct installation";\
183            echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}";\
184            cd src/ksp/ksp/tutorials/amrex >/dev/null;\
185            ${RUN_TEST} clean-legacy; \
186            ${RUN_TEST} testamrex; \
187            ${RUN_TEST} clean-legacy; \
188            cd - > /dev/null; \
189          fi;\
190        fi;
191	+@if [ "${HDF5_LIB}" != "" ]; then \
192          cd src/vec/vec/tests >/dev/null;\
193          ${RUN_TEST} clean-legacy; \
194          ${RUN_TEST} runex47; \
195          ${RUN_TEST} clean-legacy; \
196         fi;
197	+@if [ "${MPI4PY}" = "yes" ]; then \
198           cd src/sys/tests >/dev/null; \
199           ${RUN_TEST} clean-legacy; \
200           ${RUN_TEST} testex55; \
201           ${RUN_TEST} clean-legacy; \
202         fi;
203	+@if [ "${PETSC4PY}" = "yes" ]; then \
204           cd src/ksp/ksp/tutorials >/dev/null; \
205           ${RUN_TEST} clean-legacy; \
206           ${RUN_TEST} testex100; \
207           ${RUN_TEST} clean-legacy; \
208         fi;
209	+@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
210         if test -s .ftn.log; then \
211           cd src/snes/tutorials >/dev/null; \
212           ${RUN_TEST} clean-legacy; \
213           ${RUN_TEST} testex5f; \
214           ${RUN_TEST} clean-legacy; \
215         fi; ${RM} .ftn.log;
216	+@grep -E "^#define PETSC_HAVE_MATLAB 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
217         if test -s .ftn.log; then \
218           cd src/vec/vec/tutorials >/dev/null; \
219           ${RUN_TEST} clean-legacy; \
220           ${RUN_TEST} testex31; \
221           ${RUN_TEST} clean-legacy; \
222          fi; ${RM} .ftn.log;
223	-@echo "Completed test examples"
224
225# ********* Rules for make install *******************************************************************************************************************
226
227install:
228	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
229	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
230
231# A smaller install with fewer extras
232install-lib:
233	@${PYTHON} ./config/install.py -destDir=${DESTDIR} -no-examples
234	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
235
236install-builtafterpetsc:
237	+${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
238
239# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
240dist:
241	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
242
243# ******** Rules for running the full test suite ********************************************************************************************************
244
245TESTMODE = testexamples
246ALLTESTS_CHECK_FAILURES = no
247ALLTESTS_MAKEFILE = ${PETSC_DIR}/gmakefile.test
248VALGRIND=0
249alltests: chk_in_petscdir ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
250	-@${RM} -rf ${PETSC_ARCH}/lib/petsc/conf/alltests.log alltests.log
251	+@if [ -f ${PETSC_DIR}/share/petsc/examples/gmakefile.test ] ; then \
252            ALLTESTS_MAKEFILE=${PETSC_DIR}/share/petsc/examples/gmakefile.test ; \
253            ALLTESTSLOG=alltests.log ;\
254          else \
255            ALLTESTS_MAKEFILE=${PETSC_DIR}/gmakefile.test; \
256            ALLTESTSLOG=${PETSC_ARCH}/lib/petsc/conf/alltests.log ;\
257            ln -s $${ALLTESTSLOG} alltests.log ;\
258          fi; \
259          ${OMAKE} allgtest ALLTESTS_MAKEFILE=$${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} MPIEXEC="${MPIEXEC}" DATAFILESPATH=${DATAFILESPATH} VALGRIND=${VALGRIND} 2>&1 | tee $${ALLTESTSLOG};\
260          if [ x${ALLTESTS_CHECK_FAILURES} = xyes -a ${PETSC_PRECISION} != single ]; then \
261            cat $${ALLTESTSLOG} | grep -E '(^not ok|not remade because of errors|^# No tests run)' | wc -l | grep '^[ ]*0$$' > /dev/null; \
262          fi;
263
264allgtests-tap: allgtest-tap
265	+@${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check-test-errors
266
267allgtest-tap: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
268	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test OUTPUT=1
269
270allgtest: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
271	+@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).$$)'
272
273test:
274	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test
275cleantest:
276	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} cleantest
277
278#********* Rules for cleaning ***************************************************************************************************************************
279
280deletelibs:
281	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
282deletemods:
283	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
284
285allclean:
286	-@${OMAKE} -f gmakefile clean
287
288clean:: allclean
289
290distclean: chk_petscdir
291	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
292	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
293          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; fi
294	@echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"
295	-${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/
296
297#********* Rules for printing library properties useful for building applications  ***********************************************************
298
299getmpilinklibs:
300	-@echo  ${MPI_LIB}
301
302getmpiincludedirs:
303	-@echo  ${MPI_INCLUDE}
304
305getmpiexec:
306	-@echo  ${MPIEXEC}
307
308getccompiler:
309	-@echo ${CC}
310
311getfortrancompiler:
312	-@echo ${FC}
313
314getcxxcompiler:
315	-@echo ${CXX}
316
317getlinklibs:
318	-@echo  ${C_SH_LIB_PATH} ${PETSC_TS_LIB}
319
320getincludedirs:
321	-@echo  ${PETSC_CC_INCLUDES}
322
323getcflags:
324	-@echo ${CC_FLAGS}
325
326getcxxflags:
327	-@echo ${CXX_FLAGS}
328
329getfortranflags:
330	-@echo ${FC_FLAGS}
331
332getblaslapacklibs:
333	-@echo ${BLASLAPACK_LIB}
334
335getautoconfargs:
336	-@echo CC='"${CC}"' CXX='"${CXX}"'  FC='"${FC}"' CFLAGS='"${CC_FLAGS}"' CXXFLAGS='"${CXX_FLAGS}"' FCFLAGS='"${FC_FLAGS}"' LIBS='"${C_SH_LIB_PATH} ${PETSC_TS_LIB}"'
337
338info:
339	-@echo "=========================================="
340	-@echo " "
341	-@echo "See documentation/faq.html and documentation/bugreporting.html"
342	-@echo "for help with installation problems.  Please send EVERYTHING"
343	-@echo "printed out below when reporting problems.  Please check the"
344	-@echo "mailing list archives and consider subscribing."
345	-@echo " "
346	-@echo "  https://petsc.org/release/community/mailing/"
347	-@echo " "
348	-@echo "=========================================="
349	-@echo Starting make run on `hostname` at `date +'%a, %d %b %Y %H:%M:%S %z'`
350	-@echo Machine characteristics: `uname -a`
351	-@echo "-----------------------------------------"
352	-@echo "Using PETSc directory: ${PETSC_DIR}"
353	-@echo "Using PETSc arch: ${PETSC_ARCH}"
354	-@echo "-----------------------------------------"
355	-@grep "define PETSC_VERSION" ${PETSC_DIR}/include/petscversion.h | ${SED} "s/........//" | head -n 7
356	-@echo "-----------------------------------------"
357	-@echo "Using configure Options: ${CONFIGURE_OPTIONS}"
358	-@echo "Using configuration flags:"
359	-@grep "\#define " ${PETSCCONF_H} | tail -n +2
360	-@echo "-----------------------------------------"
361	-@echo "Using C compile: ${PETSC_CCOMPILE_SINGLE}"
362	-@if [  "${MPICC_SHOW}" != "" ]; then \
363             printf  "mpicc -show: %b\n" "${MPICC_SHOW}";\
364          fi; \
365        printf  "C compiler version: %b\n" "${C_VERSION}"; \
366        if [ "${CXX}" != "" ]; then \
367        echo "Using C++ compile: ${PETSC_CXXCOMPILE_SINGLE}";\
368        if [ "${MPICXX_SHOW}" != "" ]; then \
369               printf "mpicxx -show: %b\n" "${MPICXX_SHOW}"; \
370            fi;\
371            printf  "C++ compiler version: %b\n" "${Cxx_VERSION}"; \
372          fi
373	-@if [ "${FC}" != "" ]; then \
374	   echo "Using Fortran compile: ${PETSC_FCOMPILE_SINGLE}";\
375           if [ "${MPIFC_SHOW}" != "" ]; then \
376             printf "mpif90 -show: %b\n" "${MPIFC_SHOW}"; \
377           fi; \
378             printf  "Fortran compiler version: %b\n" "${FC_VERSION}"; \
379         fi
380	-@if [ "${CUDAC}" != "" ]; then \
381	   echo "Using CUDA compile: ${PETSC_CUCOMPILE_SINGLE}";\
382         fi
383	-@if [ "${CLANGUAGE}" = "CXX" ]; then \
384           echo "Using C++ compiler to compile PETSc";\
385        fi
386	-@echo "-----------------------------------------"
387	-@echo "Using C/C++ linker: ${PCC_LINKER}"
388	-@echo "Using C/C++ flags: ${PCC_LINKER_FLAGS}"
389	-@if [ "${FC}" != "" ]; then \
390	   echo "Using Fortran linker: ${FC_LINKER}";\
391	   echo "Using Fortran flags: ${FC_LINKER_FLAGS}";\
392         fi
393	-@echo "-----------------------------------------"
394	-@echo "Using system modules: ${LOADEDMODULES}"
395	-@if [ "${MPI_IS_MPIUNI}" = "1" ]; then \
396           echo Using mpi.h: mpiuni; \
397        else \
398           TESTDIR=`mktemp -q -d -t petscmpi-XXXXXXXX` && \
399           echo '#include <mpi.h>' > $${TESTDIR}/mpitest.c && \
400           BUF=`${CPP} ${PETSC_CPPFLAGS} ${PETSC_CC_INCLUDES} $${TESTDIR}/mpitest.c |grep 'mpi\.h' | ( head -1 ; cat > /dev/null )` && \
401           echo Using mpi.h: $${BUF}; ${RM} -rf $${TESTDIR}; \
402        fi
403	-@echo "-----------------------------------------"
404	-@echo "Using libraries: ${PETSC_LIB}"
405	-@echo "------------------------------------------"
406	-@echo "Using mpiexec: ${MPIEXEC}"
407	-@echo "------------------------------------------"
408	-@echo "Using MAKE: ${MAKE}"
409	-@echo "Default MAKEFLAGS: MAKE_NP:${MAKE_NP} MAKE_LOAD:${MAKE_LOAD} MAKEFLAGS:${MAKEFLAGS}"
410	-@echo "=========================================="
411
412
413check_usermakefile:
414	-@echo "Testing compile with user makefile"
415	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
416	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
417	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
418	@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
419         if test -s .ftn.log; then \
420          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
421         fi; ${RM} .ftn.log;
422	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
423	-@echo "Completed compile with user makefile"
424
425#********* Rules for running clangformat ************************************************************************************************************
426
427checkgitclean:
428	@if ! git diff --quiet; then \
429           echo "The repository has uncommitted files, cannot run checkclangformat" ;\
430           git status -s --untracked-files=no ;\
431           false;\
432        fi;
433
434checkclangformatversion:
435	@version=`clang-format --version | cut -d" " -f3 | cut -d"." -f 1` ;\
436         if [ "$$version" == "version" ]; then version=`clang-format --version | cut -d" " -f4 | cut -d"." -f 1`; fi;\
437         if [ $$version != 16 ]; then echo "Require clang-format version 16! Currently used clang-format version is $$version" ;false ; fi
438
439# Check that all the source code in the repository satisfies the .clang_format
440checkclangformat: checkclangformatversion checkgitclean clangformat
441	@if ! git diff --quiet; then \
442          printf "The current commit has source code formatting problems\n" ;\
443          if [ -z "${CI_PIPELINE_ID}"  ]; then \
444            printf "Please run 'git diff' to check\n"; \
445            git diff --stat; \
446          else \
447            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch; \
448            git diff --patch-with-stat --color=always | head -1000; \
449            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch` -gt 1000 ]; then \
450              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch (in CI artifacts) for all changes\n"; \
451            fi;\
452          fi;\
453          false;\
454        fi;
455
456# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
457abitest:
458	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
459		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
460		exit 1; \
461	fi;
462	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
463	-@echo "========================================================================================="
464	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
465	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
466	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
467	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
468	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
469	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
470	-@echo "========================================================================================="
471	-@$(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
472
473# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
474abitestcomplete:
475	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
476          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"` ;\
477echo $${OPTIONS} ;\
478        fi ; \
479        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
480          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
481        else \
482          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
483        fi ; \
484        echo "=================================================================================================" ;\
485        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
486        echo "=================================================================================================" ;\
487        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
488          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
489        else \
490          cd $${PETSC_DIR_OLD} ; \
491          git pull ; \
492        fi ; \
493        cd $${PETSC_DIR_OLD} ; \
494        git checkout ${branch} ; \
495        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
496        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
497        cd ${PETSC_DIR} ; \
498        ./configure $${OPTIONS}; \
499        make all test ; \
500        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
501
502# ******** Rules for running Streams benchmark ****************************************************************************************************
503
504mpistreams:
505	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
506
507mpistream:
508	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
509
510openmpstreams:
511	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
512
513openmpstream:
514	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
515
516stream: mpistream
517
518streams: mpistreams
519
520# ********  Rules for generating tag files for Emacs/VIM *******************************************************************************************
521
522alletags:
523	-@${PYTHON} lib/petsc/bin/maint/generateetags.py
524	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
525
526# obtain gtags from https://www.gnu.org/software/global/
527allgtags:
528	-@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 -
529
530# ********* Rules for building "classic" documentation; uses rules also in lib/petsc/conf/rules.doc **************************************************
531
532docs:
533	cd doc; ${OMAKE_SELF} sphinxhtml
534
535chk_petscdir:
536	@mypwd=`pwd`; cd ${PETSC_DIR} 2>&1 > /dev/null; true_PETSC_DIR=`pwd`; cd $${mypwd} 2>&1 >/dev/null; \
537        newpwd=`echo $${mypwd} | sed "s+$${true_PETSC_DIR}+DUMMY+g"`;\
538        haspetsc=`echo $${mypwd} | sed "s+petsc-+DUMMY+g"`;\
539        if [ $${mypwd} = $${newpwd} -a $${haspetsc} != $${mypwd} ]; then \
540          printf ${PETSC_TEXT_HILIGHT}"*********************W-a-r-n-i-n-g*************************\n" ; \
541          echo "Your PETSC_DIR may not match the directory you are in";\
542          echo "PETSC_DIR " $${true_PETSC_DIR} "Current directory" $${mypwd};\
543          echo "Ignore this if you are running make check             ";\
544          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ; \
545        fi
546
547chk_in_petscdir:
548	@if [ ! -f include/petscversion.h ]; then \
549	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
550	  echo " This target should be invoked in top level PETSc source dir!"; \
551	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
552
553chk_loc:
554	@if [ ${LOC}foo = foo ] ; then \
555	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
556	  echo " Please specify LOC variable for eg: make allmanpages LOC=/sandbox/petsc "; \
557	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
558	@${MKDIR} ${LOC}/manualpages
559
560chk_c2html:
561	@if [ ${C2HTML}foo = foo ] ; then \
562          printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR ************************\n" ; \
563          echo "Require c2html for html docs. Please reconfigure with --download-c2html=1"; \
564          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ;false; fi
565
566
567# the ACTION=manualpages cannot run in parallel because they all write to the same manualpages.cit file
568hloc=include/petsc/private
569allmanpages: chk_loc deletemanualpages
570	-echo " /* SUBMANSEC = PetscH */ " > ${hloc}/generated_khash.h
571	-sed -e 's?<T>?I?g' -e 's?<t>?i?g' -e 's?<KeyType>?PetscInt?g' ${hloc}/hashset.txt >> ${hloc}/generated_khash.h
572	-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
573	-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
574	-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
575	-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
576	-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
577	-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
578	-${RM} ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
579	-${OMAKE_SELF} ACTION=manualpages tree_src LOC=${LOC}
580	-@sed -e s%man+../%man+manualpages/% ${LOC}/manualpages/manualpages.cit > ${LOC}/manualpages/htmlmap
581	-@cat ${PETSC_DIR}/doc/classic/mpi.www.index >> ${LOC}/manualpages/htmlmap
582	cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
583	a=`cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err | wc -l`; test ! $$a -gt 0
584
585allmanexamples: chk_loc allmanpages
586	-${OMAKE_SELF} ACTION=manexamples tree LOC=${LOC}
587
588#
589#    Goes through all manual pages adding links to implementations of the method
590# or class, at the end of the file.
591#
592# To find functions implementing methods, we use git grep to look for
593# well-formed PETSc functions
594# - with names containing a single underscore
595# - in files of appropriate types (.cu .c .cxx .h),
596# - in paths including "/impls/",
597# - excluding any line with a semicolon (to avoid matching prototypes), and
598# - excluding any line including "_Private",
599# storing potential matches in implsFuncAll.txt.
600#
601# For each man page we then grep in this file for the item's name followed by
602# a single underscore and process the resulting implsFunc.txt to generate HTML.
603#
604# To find class implementations, we populate implsClassAll.txt with candidates
605# - of the form "struct _p_itemName {",  and
606# - not containing a semicolon
607# and then grep for particular values of itemName, generating implsClass.txt,
608# which is processed to generate HTML.
609#
610# Note: PETSC_DOC_OUT_ROOT_PLACEHOLDER must match the term used elsewhere in doc/
611manimplementations:
612	-@git grep "struct\s\+_[pn]_[^\s]\+.*{" -- *.cpp *.cu *.c *.h *.cxx | grep -v -e ";" -e "/tests/" -e "/tutorials/" > implsClassAll.txt ; \
613  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 ; \
614  for i in ${LOC}/manualpages/*/*.md foo; do \
615       if [ "$$i" != "foo" ] ; then \
616          itemName=`basename $$i .md`;\
617          grep "\s$${itemName}_" implsFuncAll.txt > implsFunc.txt ; \
618          grep "_p_$${itemName}\b" implsClassAll.txt > implsClass.txt ; \
619          if [ -s implsFunc.txt ] || [ -s implsClass.txt ] ; then \
620            printf "\n## Implementations\n\n" >> $$i; \
621          fi ; \
622          if [ -s implsFunc.txt ] ; then \
623            sed "s?\(.*\.[ch]x*u*\).*\($${itemName}.*\)(.*)?<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\1.html#\2\">\2 in \1</A><BR>?" implsFunc.txt >> $$i ; \
624          fi ; \
625          if [ -s implsClass.txt ] ; then \
626            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 ; \
627          fi ; \
628          ${RM} implsFunc.txt implsClass.txt; \
629       fi ; \
630  done ; \
631  ${RM} implsClassAll.txt implsFuncAll.txt
632
633# Build all classic docs except html sources
634alldoc_pre: chk_loc allmanpages allmanexamples
635	-${OMAKE_SELF} LOC=${LOC} manimplementations
636	-${PYTHON} lib/petsc/bin/maint/wwwindex.py ${PETSC_DIR} ${LOC}
637
638# Run after alldoc_pre to build html sources
639alldoc_post: chk_loc  chk_c2html
640	-@if command -v parallel &> /dev/null; then \
641           ls include/makefile src/*/makefile | xargs dirname | parallel -j ${MAKE_TEST_NP} --load ${MAKE_LOAD} 'cd {}; ${OMAKE_SELF} LOC=${LOC} PETSC_DIR=${PETSC_DIR} ACTION=html tree' ; \
642         else \
643           ${OMAKE_SELF} ACTION=html PETSC_DIR=${PETSC_DIR} tree LOC=${LOC}; \
644        fi
645
646alldocclean: deletemanualpages allcleanhtml
647
648# Deletes man pages (.md version)
649deletemanualpages: chk_loc
650	-@if [ -d ${LOC} -a -d ${LOC}/manualpages ]; then \
651          find ${LOC}/manualpages -type f -name "*.md" -exec ${RM} {} \; ;\
652          ${RM} ${LOC}/manualpages/manualpages.cit ;\
653        fi
654
655allcleanhtml:
656	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} tree
657
658# ********* Rules for checking code coverage *********************************************************************************************
659
660gcov:
661	output_file_base_name=${PETSC_ARCH}-gcovr-report.json; \
662	petsc_arch_dir=${PETSC_DIR}/${PETSC_ARCH}; \
663        tar_file=$${petsc_arch_dir}/$${output_file_base_name}.tar.bz2; \
664	cd $${petsc_arch_dir}/obj && \
665	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} && \
666	${RM} -f $${tar_file} && \
667	tar --bzip2 -cf $${tar_file} -C $${petsc_arch_dir} ./$${output_file_base_name} && \
668	${RM} $${petsc_arch_dir}/$${output_file_base_name}
669
670mergegcov:
671	$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge-branch `lib/petsc/bin/maint/check-merge-branch.sh` --html --xml ${PETSC_GCOV_OPTIONS}
672
673#********* Rules for make clangformat and checking violation of coding standards **************************************************************
674
675# Format all the source code in the given directory and down according to the file .clang_format
676clangformat:
677	-@git --no-pager ls-files -z ${GITCFSRC} | xargs -0 -P $(MAKE_NP) -L 10 clang-format -i
678
679GITSRC = '*.[chF]' '*.F90' '*.hpp' '*.cpp' '*.cxx' '*.cu' ${GITSRCEXCL}
680GITSRCEXCL = \
681':!*khash/*' \
682':!*valgrind/*' \
683':!*yaml/*' \
684':!*perfstubs/*'
685GITCFSRC = '*.[ch]' '*.hpp' '*.cpp' '*.cxx' '*.cu' ${GITSRCEXCL} ${GITCFSRCEXCL}
686GITCFSRCEXCL = \
687':!*petscversion.h' \
688':!*mpif.h' \
689':!*mpiunifdef.h' \
690':!*finclude/*' \
691':!systems/*' \
692':!*benchmarks/*' \
693':!*binding/*' \
694':!*-custom/*' \
695':!*f90-mod/*'
696
697checkbadSource:
698	@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
699	-@${RM} -f checkbadSource.out
700	-@echo "------Double blank lines in file -----------------------------------" > checkbadSource.out
701	-@git --no-pager grep -n -P '^$$' -- ${GITSRC} > doublelinecheck.out
702	-@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/doublelinecheck.py doublelinecheck.out >> checkbadSource.out
703	-@${RM} -f doublelinecheck.out
704	-@echo "------Tabs in file -------------------------------------------------" >> checkbadSource.out
705	-@git --no-pager grep -n -P '\t' -- ${GITSRC} >> checkbadSource.out;true
706	-@echo "------White space at end of line -----------------------------------" >> checkbadSource.out
707	-@git --no-pager grep -n -P ' $$' -- ${GITSRC} >> checkbadSource.out;true
708	-@echo "------Two ;; -------------------------------------------------------" >> checkbadSource.out
709	-@git --no-pager grep -n -P -e ';;' -- ${GITSRC} | grep -v ' for (' >> checkbadSource.out;true
710	-@echo "------PetscCall for an MPI error code ------------------------------" >> checkbadSource.out
711	-@git --no-pager grep -n -P -e '= MPI[U]*_\w*\(.*PetscCall' -- ${GITSRC} | grep -v MPIU_File >> checkbadSource.out;true
712	-@echo "------Missing if (ierr) return ierr; -------------------------------" >> checkbadSource.out
713	-@git --no-pager grep -n -P -e 'ierr = PetscInitialize\(' -- '*.[ch]' '*.cpp' '*.cxx' '*.cu' | grep -v 'if (ierr) return ierr;' | grep -E "(test|tutorial)" >> checkbadSource.out;true
714	-@echo "------DOS file (with DOS newlines) ---------------------------------" >> checkbadSource.out
715	-@git --no-pager grep -n -P '\r' -- ${GITSRC} >> checkbadSource.out;true
716	-@echo "------{ before SETERRQ ---------------------------------------------" >> checkbadSource.out
717	-@git --no-pager grep -n -P '{SETERRQ' -- ${GITSRC} >> checkbadSource.out;true
718	-@echo "------PetscCall following SETERRQ ----------------------------------" >> checkbadSource.out
719	-@git --no-pager grep -n -P 'SETERRQ' -- ${GITSRC} | grep ";PetscCall" >> checkbadSource.out;true
720	-@echo "------SETERRQ() without defined error code -------------------------" >> checkbadSource.out
721	-@git --no-pager grep -n -P 'SETERRQ\((?!\))' -- ${GITSRC} | grep -v PETSC_ERR  | grep " if " | grep -v "__VA_ARGS__" | grep -v flow.c >> checkbadSource.out;true
722	-@echo "------SETERRQ() with trailing newline ------------------------------" >> checkbadSource.out
723	-@git --no-pager grep -n -P "SETERRQ[1-9]?.*\\\n\"" -- ${GITSRC} >> checkbadSource.out;true
724	-@echo "------Define keyword used in test definition -----------------------" >> checkbadSource.out
725	-@git --no-pager grep -n -P -e 'requires:.*define\(' -- ${GITSRC} >> checkbadSource.out;true
726	-@echo "------No new line at end of file -----------------------------------" >> checkbadSource.out
727	-@git --no-pager grep -n -P '[^\n]\z' -- ${GITSRC} >> checkbadSource.out;true
728	-@echo "------Using if (condition) SETERRQ(...) instead of PetscCheck() ----" >> checkbadSource.out
729	-@git --no-pager grep -n -P ' if +(.*) *SETERRQ' -- ${GITSRC} | grep -v 'PetscUnlikelyDebug' | grep -v 'petscerror.h' >> checkbadSource.out;true
730	-@echo "------Using if (PetscUnlikelyDebug(condition)) SETERRQ(...) instead of PetscAssert()" >> checkbadSource.out
731	-@git --no-pager grep -n -P -E ' if +\(PetscUnlikelyDebug.*\) *SETERRQ' -- ${GITSRC} | grep -v petscerror.h >> checkbadSource.out;true
732	-@echo "------Using PetscFunctionReturn(ierr) ------------------------------" >> checkbadSource.out
733	-@git --no-pager grep -n -P 'PetscFunctionReturn(ierr)' -- ${GITSRC} >> checkbadSource.out;true
734	-@echo "------Defining a returning macro without PetscMacroReturns() -------" >> checkbadSource.out
735	-@git --no-pager grep -n -P 'define .*\w+;\s+do' -- ${GITSRC} | grep -E -v '(PetscMacroReturns|PetscDrawCollectiveBegin|MatPreallocateBegin|PetscOptionsBegin|PetscObjectOptionsBegin|PetscOptionsHeadEnd)' >> checkbadSource.out;true
736	-@echo "------Defining an error checking macro using CHKERR style ----------" >> checkbadSource.out
737	-@git --no-pager grep -n -P 'define\s+CHKERR\w*\(.*\)\s*do\s+{' -- ${GITSRC} >> checkbadSource.out;true
738	@a=`cat checkbadSource.out | wc -l`; l=`expr $$a - 18` ;\
739         if [ $$l -gt 0 ] ; then \
740           echo $$l " files with errors detected in source code formatting" ;\
741           cat checkbadSource.out ;\
742         else \
743	   ${RM} -f checkbadSource.out;\
744         fi;\
745         test ! $$l -gt 0
746	-@git --no-pager grep -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" -- ${GITSRC} > badSourceChar.out;true
747	-@w=`cat badSourceChar.out | wc -l`;\
748         if [ $$w -gt 0 ] ; then \
749           echo "Source files with non-ASCII characters ----------------" ;\
750           cat badSourceChar.out ;\
751         else \
752	   ${RM} -f badSourceChar.out;\
753         fi
754	@test ! -s badSourceChar.out
755
756checkbadFileChange:
757	@git diff --stat --exit-code `lib/petsc/bin/maint/check-merge-branch.sh`..HEAD -- src/sys/yaml/src src/sys/yaml/include src/sys/yaml/License include/petsc/private/valgrind include/petsc/private/kash
758
759vermin:
760	@vermin -vvv -t=3.4- ${VERMIN_OPTIONS} ${PETSC_DIR}/config
761
762lint:
763	${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter --verbose=${V} --apply-patches=${REPLACE} $(LINTER_OPTIONS)
764
765help-lint:
766	@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter --help
767	-@echo "Basic usage:"
768	-@echo "   make lint      <options>"
769	-@echo "   make test-lint <options> <test only options>"
770	-@echo
771	-@echo "Options:"
772	-@echo "  V=[1,0]                                Enable or disable verbose output"
773	-@echo "  LINTER_OPTIONS=\"--opt1 --opt2 ...\"     See above for available options"
774	-@echo
775	-@echo "Test Only Options:"
776	-@echo "  REPLACE=[1,0]                          Enable or disable replacing test output"
777	-@echo
778
779test-lint:
780	${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter ${PETSC_DIR}/src/sys/tests/linter --test -j0 --werror --replace=${REPLACE} --verbose=${V} $(LINTER_OPTIONS)
781
782countfortranfunctions:
783	-@cd ${PETSC_DIR}/src/fortran; grep -E '^void' custom/*.c auto/*.c | \
784	cut -d'(' -f1 | tr -s  ' ' | cut -d' ' -f2 | uniq | grep -E -v "(^$$|Petsc)" | \
785	sed "s/_$$//" | sort > /tmp/countfortranfunctions
786
787countcfunctions:
788	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
789	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
790	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
791
792difffortranfunctions: countfortranfunctions countcfunctions
793	-@echo -------------- Functions missing in the fortran interface ---------------------
794	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^<" | cut -d' ' -f2
795	-@echo ----------------- Functions missing in the C interface ------------------------
796	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^>" | cut -d' ' -f2
797	-@${RM}  /tmp/countcfunctions /tmp/countfortranfunctions
798
799checkbadfortranstubs:
800	-@echo "========================================="
801	-@echo "Functions with MPI_Comm as an Argument"
802	-@echo "========================================="
803	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'MPI_Comm' | \
804	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
805	-@echo "========================================="
806	-@echo "Functions with a String as an Argument"
807	-@echo "========================================="
808	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'char \*' | \
809	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
810	-@echo "========================================="
811	-@echo "Functions with Pointers to PETSc Objects as Argument"
812	-@echo "========================================="
813	-@cd ${PETSC_DIR}/src/fortran/auto; \
814	_p_OBJ=`grep _p_ ${PETSC_DIR}/include/*.h | tr -s ' ' | \
815	cut -d' ' -f 3 | tr -s '\012' | grep -v '{' | cut -d'*' -f1 | \
816	sed "s/_p_//g" | tr -s '\012 ' ' *|' ` ; \
817	for OBJ in $$_p_OBJ; do \
818	grep "$$OBJ \*" *.c | tr -s ' ' | tr -s ':' ' ' | \
819	cut -d'(' -f1 | cut -d' ' -f1,3; \
820	done
821
822checkpackagetests:
823	-@echo "Missing package tests"
824	-@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
825	-@echo "Missing download package tests"
826	-@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
827
828check_petsc4py_rst:
829	@${RM} -f petsc4py_rst.log
830	@echo "Checking src/binding/petsc4py/DESCRIPTION.rst"
831	@rst2html src/binding/petsc4py/DESCRIPTION.rst > /dev/null 2> petsc4py_rst.log
832	@if test -s petsc4py_rst.log; then cat petsc4py_rst.log; exit 1; fi
833
834# TODO: checkTestCoverage: that makes sure every tutorial test has at least one test listed in the file, perhaps handled by gmakegentest.py
835# TODO: check for PetscBeginFunctionUser in non-example source
836# TODO: check for __ at start of #define or symbol
837# TODO: checking for missing manual pages
838# TODO: check for incorrect %d
839# TODO: check for double blank lines
840# TODO: check for ill-formed manual pages
841# TODO: check for { on line after for
842# TODO: check for } then else on following line
843# TODO: check for } else { with SETERRQ on following line or if () { with SETERRQ on following line
844
845#  Lists all the URLs in the PETSc repository that are unaccessible, nonexistent, or permanently moved (301)
846#  REPLACE=1 locations marked as permanently moved (301) are replaced in the repository
847#  This code is fragile; always check the changes after a use of REPLACE=1 before committing the changes
848#
849#  Notes:
850#    The first tr in the line is split lines for the cases where multiple URLs are in the same line
851#    The first sed handles the case (http[s]*://xxx)
852#    The list is sorted by length so that if REPLACE is used the longer apply before the shorter
853#    The code recursively follows the permanently moved (301) redirections until it reaches the final URL
854#    For DropBox we need to check the validity of the new URL but do not want to return to user the internal "raw" URL
855checkbadURLS:
856	-@x=`git grep "http[s]*://" -- '*.[chF]' '*.html' '*.cpp' '*.cxx' '*.cu' '*.F90' '*.py' '*.tex' | grep -E -v "(config/packages|HandsOnExercises)" | tr '[[:blank:]]' '\n' | grep 'http[s]*://' | sed 's!.*(\(http[s]*://[-a-zA-Z0-9_./()?=&+%~]*\))!\1!g' | sed 's!.*\(http[s]*://[-a-zA-Z0-9_./()?=&+%~]*\).*!\1!g' | sed 's/\.$$//g' | sort | uniq| awk '{ print length, $$0 }' | sort -r -n -s | cut -d" " -f2` ; \
857        for i in $$x; do \
858          url=$$i; \
859          msg=''; \
860          while [[ "$${msg}D" == "D" ]] ; do \
861            y1=`curl --connect-timeout 5 --head --silent $${url} | head -n 1`; \
862            y2=`echo $${y1} | grep ' 4[0-9]* '`; \
863            y3=`echo $${y1} | grep ' 301 '`; \
864            if [[ "$${y1}D" == "D" ]] ; then \
865              msg="Unable to reach site" ; \
866            elif [[ "$${y2}D" != "D" ]] ; then \
867              msg=$${y1} ; \
868            elif [[ "$${y3}D" != "D" ]] ; then \
869              l=`curl --connect-timeout 5 --head --silent $${url} | grep ocation | sed 's/.*ocation:[[:blank:]]\(.*\)/\1/g' | tr -d '\r'` ; \
870              w=`echo $$l | grep 'http'` ; \
871              if [[ "$${w}D" != "D" ]] ; then \
872                url=$$l ; \
873              else \
874                ws=`echo $${url} | sed 's!\(http[s]*://[-a-zA-Z0-9_.]*\)/.*!\1!g'` ; \
875                dp=`echo $${ws}$${l} | grep "dropbox.com/s/raw"` ; \
876                if [[ "$${dp}D" != "D" ]] ; then \
877                  b=`curl --connect-timeout 5 --head --silent $${ws}$$l | head -n 1` ; \
878                  c=`echo $${b} | grep -E "( 2[0-9]* | 302 )"` ; \
879                  if [[ "$${c}D" == "D" ]] ; then \
880                    msg=`echo "dropbox file doesn't exist" $${c}` ; \
881                  else \
882                    break ; \
883                  fi; \
884                else \
885                  url="$${ws}$$l" ; \
886                fi; \
887              fi; \
888            else \
889              break; \
890            fi; \
891          done;\
892          if [[ "$${msg}D" == "D" && "$${url}" != "$$i" ]] ; then \
893            echo "URL" $$i "has moved to valid final location:" $${url} ; \
894            if [[ "$${REPLACE}D" != "D" ]] ; then \
895              git psed $$i $$l ;\
896            fi; \
897          elif [[ "$${msg}D" != "D" && "$${url}" != "$$i" ]] ; then \
898            echo "ERROR: URL" $$i "has moved to invalid final location:" $${url} $${msg} ; \
899          elif [[ "$${msg}D" != "D" ]] ; then \
900            echo "ERROR: URL" $$i "invalid:" $${msg} ; \
901          fi; \
902        done
903
904checkbadSpelling:
905	-@x=`python3 ../bin/extract.py | aspell list | sort -u` ;
906
907updatedatafiles:
908	-@if [ -d "${HOME}/datafiles" ]; then \
909            echo " ** Updating datafiles at ${HOME}/datafiles **"; \
910            cd "${HOME}/datafiles" && git pull -q; fi
911
912.PHONY: info info_h all deletelibs allclean update \
913        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanpages \
914        allcleanhtml  countfortranfunctions \
915        start_configure configure_petsc configure_clean matlabbin install
916