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