xref: /petsc/makefile (revision 088deb40795b4b22dc635ef828f3a6fda94efd55)
1753a1a87SJed Brown#
24c512586SBarry Smith# See https://petsc.org/release/install/ for instructions on installing PETSc
3753a1a87SJed Brown#
44c512586SBarry Smith# This is the top level makefile for compiling PETSc.
54c512586SBarry Smith#   * make help - useful messages on functionality
64c512586SBarry Smith#   * make all  - compile the PETSc libraries and utilities
74c512586SBarry Smith#   * make check - runs a quick test that the libraries are built correctly and PETSc applications can run
84c512586SBarry Smith#
94c512586SBarry Smith#   * make install - for use with ./configure is run with the --prefix=directory option
104c512586SBarry Smith#   * make test - runs a comprehensive test suite (requires gnumake)
114c512586SBarry Smith#   * make docs - build the entire PETSc website of documentation (locally)
124c512586SBarry Smith#   * a variety of rules that print library properties useful for building applications (use make help)
134c512586SBarry Smith#   * a variety of rules for PETSc developers
144c512586SBarry Smith#
154c512586SBarry Smith# gmakefile - manages the compiling PETSc in parallel
164c512586SBarry Smith# gmakefile.test - manages running the comprehensive test suite
174c512586SBarry Smith#
184c512586SBarry Smith# This makefile does not require GNUmake
19753a1a87SJed BrownALL: all
209e423941SBarry SmithDIRS = src include interfaces share/petsc/matlab
21753a1a87SJed Brown
22753a1a87SJed Brown# next line defines PETSC_DIR and PETSC_ARCH if they are not set
23af0996ceSBarry Smithinclude ././${PETSC_ARCH}/lib/petsc/conf/petscvariables
249e423941SBarry Smith#include ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscrules
25af0996ceSBarry Smithinclude ${PETSC_DIR}/lib/petsc/conf/variables
269e423941SBarry Smithinclude ${PETSC_DIR}/lib/petsc/conf/rules.doc
27753a1a87SJed Brown
28fa2665b1SJed Brown# This makefile contains a lot of PHONY targets with improperly specified prerequisites
29fa2665b1SJed Brown# where correct execution instead depends on the targets being processed in the correct
304c512586SBarry Smith# order.
31fa2665b1SJed Brown.NOTPARALLEL:
32fa2665b1SJed Brown
330e03b746SBarry SmithOMAKE_SELF = $(OMAKE) -f makefile
340e03b746SBarry SmithOMAKE_SELF_PRINTDIR = $(OMAKE_PRINTDIR) -f makefile
350e03b746SBarry Smith
364c512586SBarry Smith#********* Rules for make all **********************************************************************************************************************************
374c512586SBarry Smith
38dd8585cdSJed Brownall:
390e03b746SBarry Smith	+@${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} chk_petscdir chk_upgrade | tee ${PETSC_ARCH}/lib/petsc/conf/make.log
40af0996ceSBarry Smith	@ln -sf ${PETSC_ARCH}/lib/petsc/conf/make.log make.log
410093410fSSatish Balay	+@(${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
422b38c152SPierre Jolivet	+@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then \
43f53b81b6SPierre Jolivet           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; \
440093410fSSatish Balay           if test -s ${PETSC_ARCH}/lib/petsc/conf/memoryerror.log; then \
4571488455SBarry Smith             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
4671488455SBarry Smith             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; \
4771488455SBarry Smith             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
480093410fSSatish Balay           else \
49af0996ceSBarry Smith             printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
50af0996ceSBarry Smith             echo "  Error during compile, check ${PETSC_ARCH}/lib/petsc/conf/make.log" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
51af0996ceSBarry Smith             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;\
52af0996ceSBarry Smith             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
530093410fSSatish Balay           fi \
54753a1a87SJed Brown	 else \
550e03b746SBarry Smith	  ${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 ;\
56753a1a87SJed Brown        fi #solaris make likes to print the whole command that gave error. So split this up into the smallest chunk below
574dcdf380SSatish Balay	@echo "Finishing make run at `date +'%a, %d %b %Y %H:%M:%S %z'`" >> ${PETSC_ARCH}/lib/petsc/conf/make.log
582b38c152SPierre Jolivet	@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then exit 1; fi
59753a1a87SJed Brown
60504e95faSBarry Smithall-local: info libs matlabbin petsc4py-build libmesh-build mfem-build slepc-build hpddm-build amrex-build bamg-build
61fa2665b1SJed Brown
629e423941SBarry Smith${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files:
639e423941SBarry Smith	@touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files
649e423941SBarry Smith
659e423941SBarry Smith${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles:
669e423941SBarry Smith	@${MKDIR} -p ${PETSC_DIR}/${PETSC_ARCH}/tests && touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
679e423941SBarry Smith
689e423941SBarry Smithlibs: ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
699e423941SBarry Smith	+@r=`echo "${MAKEFLAGS}" | grep ' -j'`; \
709e423941SBarry Smith        if [ "$$?" = 0 ]; then make_j=""; else make_j="-j${MAKE_NP}"; fi; \
719e423941SBarry Smith	r=`echo "${MAKEFLAGS}" | grep ' -l'`; \
729e423941SBarry Smith        if [ "$$?" = 0 ]; then make_l=""; else make_l="-l${MAKE_LOAD}"; fi; \
739e423941SBarry Smith        cmd="${OMAKE_PRINTDIR} -f gmakefile $${make_j} $${make_l} ${MAKE_PAR_OUT_FLG} V=${V} libs"; \
749e423941SBarry Smith        cd ${PETSC_DIR} && echo $${cmd} && exec $${cmd}
759e423941SBarry Smith
764c512586SBarry Smithchk_upgrade:
774c512586SBarry Smith	-@PETSC_DIR=${PETSC_DIR} ${PYTHON} ${PETSC_DIR}/lib/petsc/bin/petscnagupgrade.py
78753a1a87SJed Brown
794c512586SBarry Smithchklib_dir:
804c512586SBarry Smith	@if [ ! -d "${INSTALL_LIB_DIR}" ]; then \
814c512586SBarry Smith	  echo Making directory ${INSTALL_LIB_DIR} for library; ${MKDIR} ${INSTALL_LIB_DIR} ; fi
824c512586SBarry Smith
83d2b3add8SSatish Balaymatlabbin:
844242cbabSBarry Smith	-@if [ "${MATLAB_MEX}" != "" -a "${MATLAB_SOCKET}" != "" -a "${PETSC_SCALAR}" = "real" -a "${PETSC_PRECISION}" = "double" ]; then \
85d2b3add8SSatish Balay          echo "BEGINNING TO COMPILE MATLAB INTERFACE"; \
86d2b3add8SSatish Balay            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc; fi; \
87d2b3add8SSatish Balay            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab; fi; \
88b75c6efcSBarry Smith            cd src/sys/classes/viewer/impls/socket/mex-scripts && ${OMAKE_SELF} mex-scripts PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR}; \
89d2b3add8SSatish Balay            echo "========================================="; \
90d2b3add8SSatish Balay        fi
914c512586SBarry Smith
924c512586SBarry Smithallfortranstubs:
934c512586SBarry Smith	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
944c512586SBarry Smith	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py ${BFORT}  ${VERBOSE}
954c512586SBarry Smith	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py -merge  ${VERBOSE}
964c512586SBarry Smith	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
974c512586SBarry Smith
984c512586SBarry Smithdeleteshared:
994c512586SBarry Smith	@for LIBNAME in ${SHLIBS}; \
1004c512586SBarry Smith	do \
1014c512586SBarry Smith	   if [ -d ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM ]; then \
1024c512586SBarry Smith             echo ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
1034c512586SBarry Smith	     ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
1044c512586SBarry Smith	   fi; \
1054c512586SBarry Smith           echo ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
1064c512586SBarry Smith           ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
1074c512586SBarry Smith	done
1084c512586SBarry Smith	@if [ -f ${INSTALL_LIB_DIR}/so_locations ]; then \
1094c512586SBarry Smith          echo ${RM} ${INSTALL_LIB_DIR}/so_locations; \
1104c512586SBarry Smith          ${RM} ${INSTALL_LIB_DIR}/so_locations; \
1114c512586SBarry Smith	fi
1124c512586SBarry Smith
1134c512586SBarry Smithdeletefortranstubs:
1144c512586SBarry Smith	-@find . -type d -name ftn-auto | xargs rm -rf
1154c512586SBarry Smith
1164c512586SBarry Smithreconfigure: allclean
1174c512586SBarry Smith	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
1184c512586SBarry Smith
1194c512586SBarry Smithchkopts:
1204c512586SBarry Smith	-@echo "Warning: chkopts target is deprecated and can be removed from user makefiles"
1214c512586SBarry Smith
1224c512586SBarry Smithgnumake:
1234c512586SBarry Smith	+@echo "make gnumake is deprecated, use make libs"
1244c512586SBarry Smith	+@make libs
1254c512586SBarry Smith
1264c512586SBarry Smith# ********  Rules for make check ****************************************************************************************************************************
1274c512586SBarry Smith
12827cb8d94SBarry SmithRUN_TEST = ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff
12927cb8d94SBarry Smith
1300e03b746SBarry Smithcheck_install: check
1310e03b746SBarry Smithcheck:
1320e03b746SBarry Smith	-@echo "Running check examples to verify correct installation"
133753a1a87SJed Brown	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
13427cb8d94SBarry Smith	@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
13527cb8d94SBarry Smith           echo "Running with batch filesystem, cannot run make check"; \
13627cb8d94SBarry Smith        elif [ "${MPIEXEC}" = "/bin/false" ]; then \
13727cb8d94SBarry Smith           echo "*mpiexec not found*. cannot run make check"; \
13827cb8d94SBarry Smith        else \
13927cb8d94SBarry Smith          ${RM} -f check_error;\
14027cb8d94SBarry Smith          ${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; \
14127cb8d94SBarry Smith          if [ -f check_error ]; then \
14227cb8d94SBarry Smith            echo "Error while running make check"; \
14327cb8d94SBarry Smith            ${RM} -f check_error;\
14427cb8d94SBarry Smith            exit 1; \
14527cb8d94SBarry Smith          fi; \
14627cb8d94SBarry Smith          ${RM} -f check_error;\
14727cb8d94SBarry Smith        fi;
14827cb8d94SBarry Smith
14927cb8d94SBarry Smithcheck_build:
15027cb8d94SBarry Smith	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} clean-legacy
15127cb8d94SBarry Smith	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19
15227cb8d94SBarry Smith	+@if [ ! "${MPI_IS_MPIUNI}" ]; then cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19_mpi; fi
15327cb8d94SBarry Smith	+@if [ "${HYPRE_LIB}" != "" ] && [ "${PETSC_SCALAR}" = "real" ]; then \
154de5e753aSSatish Balay          if [ "${CUDA_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_cuda; \
155de5e753aSSatish Balay          elif [ "${HIP_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_hip; \
15627cb8d94SBarry Smith          else HYPRE_TEST=runex19_hypre; fi; \
15727cb8d94SBarry Smith          cd src/snes/tutorials >/dev/null; ${RUN_TEST} $${HYPRE_TEST}; \
15827cb8d94SBarry Smith        fi;
15927cb8d94SBarry Smith	+@if [ "${CUDA_LIB}" != "" ]; then \
16027cb8d94SBarry Smith          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_cuda; \
16127cb8d94SBarry Smith        fi;
16227cb8d94SBarry Smith	+@if [ "${MPI_IS_MPIUNI}" = "" ]; then \
16327cb8d94SBarry Smith          cd src/snes/tutorials >/dev/null; \
16427cb8d94SBarry Smith          if [ "${KOKKOS_KERNELS_LIB}" != "" ]  &&  [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ]; then \
16527cb8d94SBarry Smith            ${RUN_TEST} runex3k_kokkos; \
166de5e753aSSatish Balay          fi;\
16727cb8d94SBarry Smith          if [ "${MUMPS_LIB}" != "" ]; then \
16827cb8d94SBarry Smith             ${RUN_TEST} runex19_fieldsplit_mumps; \
16927cb8d94SBarry Smith          fi;\
17027cb8d94SBarry Smith          if [ "${SUITESPARSE_LIB}" != "" ]; then \
17127cb8d94SBarry Smith             ${RUN_TEST} runex19_suitesparse; \
17227cb8d94SBarry Smith          fi;\
17327cb8d94SBarry Smith          if [ "${SUPERLU_DIST_LIB}" != "" ]; then \
17427cb8d94SBarry Smith            ${RUN_TEST} runex19_superlu_dist; \
17527cb8d94SBarry Smith          fi;\
17627cb8d94SBarry Smith          if ( [ "${ML_LIB}" != "" ] ||  [ "${TRILINOS_LIB}" != "" ] ); then \
17727cb8d94SBarry Smith            ${RUN_TEST} runex19_ml; \
17827cb8d94SBarry Smith          fi; \
17927cb8d94SBarry Smith	  ${RUN_TEST} clean-legacy; \
18027cb8d94SBarry Smith          cd - > /dev/null; \
181e91fee76SPierre Jolivet          if ( [ "${AMREX_LIB}" != "" ] && [ "${CUDA_LIB}" = "" ] ); then \
182bd579fedSSatish Balay            echo "Running amrex test example to verify correct installation";\
183bd579fedSSatish Balay            echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}";\
184bd579fedSSatish Balay            cd src/ksp/ksp/tutorials/amrex >/dev/null;\
18527cb8d94SBarry Smith            ${RUN_TEST} clean-legacy; \
18627cb8d94SBarry Smith            ${RUN_TEST} testamrex; \
18727cb8d94SBarry Smith            ${RUN_TEST} clean-legacy; \
18827cb8d94SBarry Smith            cd - > /dev/null; \
18927cb8d94SBarry Smith          fi;\
19027cb8d94SBarry Smith        fi;
19127cb8d94SBarry Smith	+@if [ "${HDF5_LIB}" != "" ]; then \
19227cb8d94SBarry Smith          cd src/vec/vec/tests >/dev/null;\
19327cb8d94SBarry Smith          ${RUN_TEST} clean-legacy; \
19427cb8d94SBarry Smith          ${RUN_TEST} runex47; \
19527cb8d94SBarry Smith          ${RUN_TEST} clean-legacy; \
196bd579fedSSatish Balay         fi;
197b6efb0a5SBarry Smith	+@if [ "${MPI4PY}" = "yes" ]; then \
198b6efb0a5SBarry Smith           cd src/sys/tests >/dev/null; \
19927cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
20027cb8d94SBarry Smith           ${RUN_TEST} testex55; \
20127cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
202b6efb0a5SBarry Smith         fi;
20345ee4180SJed Brown	+@if [ "${PETSC4PY}" = "yes" ]; then \
204c4762a1bSJed Brown           cd src/ksp/ksp/tutorials >/dev/null; \
20527cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
20627cb8d94SBarry Smith           ${RUN_TEST} testex100; \
20727cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
2085061939cSBarry Smith         fi;
209f53b81b6SPierre Jolivet	+@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
210cb297985SSatish Balay         if test -s .ftn.log; then \
211bd579fedSSatish Balay           cd src/snes/tutorials >/dev/null; \
21227cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
21327cb8d94SBarry Smith           ${RUN_TEST} testex5f; \
21427cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
215cb297985SSatish Balay         fi; ${RM} .ftn.log;
216f53b81b6SPierre Jolivet	+@grep -E "^#define PETSC_HAVE_MATLAB 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
21769cdbcb9SBarry Smith         if test -s .ftn.log; then \
218bd579fedSSatish Balay           cd src/vec/vec/tutorials >/dev/null; \
21927cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
22027cb8d94SBarry Smith           ${RUN_TEST} testex31; \
22127cb8d94SBarry Smith           ${RUN_TEST} clean-legacy; \
22269cdbcb9SBarry Smith          fi; ${RM} .ftn.log;
223753a1a87SJed Brown	-@echo "Completed test examples"
22427cb8d94SBarry Smith
2254c512586SBarry Smith# ********* Rules for make install *******************************************************************************************************************
2264c512586SBarry Smith
2274c512586SBarry Smithinstall:
2284c512586SBarry Smith	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
2294c512586SBarry Smith	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
2304c512586SBarry Smith
2314c512586SBarry Smith# A smaller install with fewer extras
2324c512586SBarry Smithinstall-lib:
2334c512586SBarry Smith	@${PYTHON} ./config/install.py -destDir=${DESTDIR} -no-examples
2344c512586SBarry Smith	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
2354c512586SBarry Smith
2364c512586SBarry Smithinstall-builtafterpetsc:
2374c512586SBarry Smith	+${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
2384c512586SBarry Smith
2394c512586SBarry Smith# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
2404c512586SBarry Smithdist:
2414c512586SBarry Smith	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
2424c512586SBarry Smith
243*088deb40SBarry Smith# ******** Rules for running the full test suite ********************************************************************************************************
244*088deb40SBarry Smith
245*088deb40SBarry SmithTESTMODE = testexamples
246*088deb40SBarry SmithALLTESTS_CHECK_FAILURES = no
247*088deb40SBarry SmithALLTESTS_MAKEFILE = ${PETSC_DIR}/gmakefile.test
248*088deb40SBarry SmithVALGRIND=0
249*088deb40SBarry Smithalltests: chk_in_petscdir ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
250*088deb40SBarry Smith	-@${RM} -rf ${PETSC_ARCH}/lib/petsc/conf/alltests.log alltests.log
251*088deb40SBarry Smith	+@if [ -f ${PETSC_DIR}/share/petsc/examples/gmakefile.test ] ; then \
252*088deb40SBarry Smith            ALLTESTS_MAKEFILE=${PETSC_DIR}/share/petsc/examples/gmakefile.test ; \
253*088deb40SBarry Smith            ALLTESTSLOG=alltests.log ;\
254*088deb40SBarry Smith          else \
255*088deb40SBarry Smith            ALLTESTS_MAKEFILE=${PETSC_DIR}/gmakefile.test; \
256*088deb40SBarry Smith            ALLTESTSLOG=${PETSC_ARCH}/lib/petsc/conf/alltests.log ;\
257*088deb40SBarry Smith            ln -s $${ALLTESTSLOG} alltests.log ;\
258*088deb40SBarry Smith          fi; \
259*088deb40SBarry Smith          ${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*088deb40SBarry Smith          if [ x${ALLTESTS_CHECK_FAILURES} = xyes -a ${PETSC_PRECISION} != single ]; then \
261*088deb40SBarry Smith            cat $${ALLTESTSLOG} | grep -E '(^not ok|not remade because of errors|^# No tests run)' | wc -l | grep '^[ ]*0$$' > /dev/null; \
262*088deb40SBarry Smith          fi;
263*088deb40SBarry Smith
264*088deb40SBarry Smithallgtests-tap: allgtest-tap
265*088deb40SBarry Smith	+@${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check-test-errors
266*088deb40SBarry Smith
267*088deb40SBarry Smithallgtest-tap: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
268*088deb40SBarry Smith	+@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*088deb40SBarry Smith
270*088deb40SBarry Smithallgtest: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
271*088deb40SBarry Smith	+@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*088deb40SBarry Smith
273*088deb40SBarry Smithtest:
274*088deb40SBarry Smith	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test
275*088deb40SBarry Smithcleantest:
276*088deb40SBarry Smith	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} cleantest
277*088deb40SBarry Smith
2784c512586SBarry Smith#********* Rules for cleaning ***************************************************************************************************************************
2794c512586SBarry Smith
2804c512586SBarry Smithdeletelibs:
2814c512586SBarry Smith	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
2824c512586SBarry Smithdeletemods:
2834c512586SBarry Smith	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
2844c512586SBarry Smith
2854c512586SBarry Smithallclean:
2864c512586SBarry Smith	-@${OMAKE} -f gmakefile clean
2874c512586SBarry Smith
2884c512586SBarry Smithclean:: allclean
2894c512586SBarry Smith
2904c512586SBarry Smithdistclean: chk_petscdir
2914c512586SBarry Smith	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
2924c512586SBarry Smith	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
2934c512586SBarry Smith          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; fi
2944c512586SBarry Smith	@echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"
2954c512586SBarry Smith	-${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/
2964c512586SBarry Smith
2974c512586SBarry Smith#********* Rules for printing library properties useful for building applications  ***********************************************************
2984c512586SBarry Smith
2994c512586SBarry Smithgetmpilinklibs:
3004c512586SBarry Smith	-@echo  ${MPI_LIB}
3014c512586SBarry Smith
3024c512586SBarry Smithgetmpiincludedirs:
3034c512586SBarry Smith	-@echo  ${MPI_INCLUDE}
3044c512586SBarry Smith
3054c512586SBarry Smithgetmpiexec:
3064c512586SBarry Smith	-@echo  ${MPIEXEC}
3074c512586SBarry Smith
3084c512586SBarry Smithgetccompiler:
3094c512586SBarry Smith	-@echo ${CC}
3104c512586SBarry Smith
3114c512586SBarry Smithgetfortrancompiler:
3124c512586SBarry Smith	-@echo ${FC}
3134c512586SBarry Smith
3144c512586SBarry Smithgetcxxcompiler:
3154c512586SBarry Smith	-@echo ${CXX}
3164c512586SBarry Smith
3174c512586SBarry Smithgetlinklibs:
3184c512586SBarry Smith	-@echo  ${C_SH_LIB_PATH} ${PETSC_TS_LIB}
3194c512586SBarry Smith
3204c512586SBarry Smithgetincludedirs:
3214c512586SBarry Smith	-@echo  ${PETSC_CC_INCLUDES}
3224c512586SBarry Smith
3234c512586SBarry Smithgetcflags:
3244c512586SBarry Smith	-@echo ${CC_FLAGS}
3254c512586SBarry Smith
3264c512586SBarry Smithgetcxxflags:
3274c512586SBarry Smith	-@echo ${CXX_FLAGS}
3284c512586SBarry Smith
3294c512586SBarry Smithgetfortranflags:
3304c512586SBarry Smith	-@echo ${FC_FLAGS}
3314c512586SBarry Smith
3324c512586SBarry Smithgetblaslapacklibs:
3334c512586SBarry Smith	-@echo ${BLASLAPACK_LIB}
3344c512586SBarry Smith
3354c512586SBarry Smithgetautoconfargs:
3364c512586SBarry Smith	-@echo CC='"${CC}"' CXX='"${CXX}"'  FC='"${FC}"' CFLAGS='"${CC_FLAGS}"' CXXFLAGS='"${CXX_FLAGS}"' FCFLAGS='"${FC_FLAGS}"' LIBS='"${C_SH_LIB_PATH} ${PETSC_TS_LIB}"'
3374c512586SBarry Smith
3384c512586SBarry Smithinfo:
3394c512586SBarry Smith	-@echo "=========================================="
3404c512586SBarry Smith	-@echo " "
3414c512586SBarry Smith	-@echo "See documentation/faq.html and documentation/bugreporting.html"
3424c512586SBarry Smith	-@echo "for help with installation problems.  Please send EVERYTHING"
3434c512586SBarry Smith	-@echo "printed out below when reporting problems.  Please check the"
3444c512586SBarry Smith	-@echo "mailing list archives and consider subscribing."
3454c512586SBarry Smith	-@echo " "
3464c512586SBarry Smith	-@echo "  https://petsc.org/release/community/mailing/"
3474c512586SBarry Smith	-@echo " "
3484c512586SBarry Smith	-@echo "=========================================="
3494c512586SBarry Smith	-@echo Starting make run on `hostname` at `date +'%a, %d %b %Y %H:%M:%S %z'`
3504c512586SBarry Smith	-@echo Machine characteristics: `uname -a`
3514c512586SBarry Smith	-@echo "-----------------------------------------"
3524c512586SBarry Smith	-@echo "Using PETSc directory: ${PETSC_DIR}"
3534c512586SBarry Smith	-@echo "Using PETSc arch: ${PETSC_ARCH}"
3544c512586SBarry Smith	-@echo "-----------------------------------------"
3554c512586SBarry Smith	-@grep "define PETSC_VERSION" ${PETSC_DIR}/include/petscversion.h | ${SED} "s/........//" | head -n 7
3564c512586SBarry Smith	-@echo "-----------------------------------------"
3574c512586SBarry Smith	-@echo "Using configure Options: ${CONFIGURE_OPTIONS}"
3584c512586SBarry Smith	-@echo "Using configuration flags:"
3594c512586SBarry Smith	-@grep "\#define " ${PETSCCONF_H} | tail -n +2
3604c512586SBarry Smith	-@echo "-----------------------------------------"
3614c512586SBarry Smith	-@echo "Using C compile: ${PETSC_CCOMPILE_SINGLE}"
3624c512586SBarry Smith	-@if [  "${MPICC_SHOW}" != "" ]; then \
3634c512586SBarry Smith             printf  "mpicc -show: %b\n" "${MPICC_SHOW}";\
3644c512586SBarry Smith          fi; \
3654c512586SBarry Smith        printf  "C compiler version: %b\n" "${C_VERSION}"; \
3664c512586SBarry Smith        if [ "${CXX}" != "" ]; then \
3674c512586SBarry Smith        echo "Using C++ compile: ${PETSC_CXXCOMPILE_SINGLE}";\
3684c512586SBarry Smith        if [ "${MPICXX_SHOW}" != "" ]; then \
3694c512586SBarry Smith               printf "mpicxx -show: %b\n" "${MPICXX_SHOW}"; \
3704c512586SBarry Smith            fi;\
3714c512586SBarry Smith            printf  "C++ compiler version: %b\n" "${Cxx_VERSION}"; \
3724c512586SBarry Smith          fi
3734c512586SBarry Smith	-@if [ "${FC}" != "" ]; then \
3744c512586SBarry Smith	   echo "Using Fortran compile: ${PETSC_FCOMPILE_SINGLE}";\
3754c512586SBarry Smith           if [ "${MPIFC_SHOW}" != "" ]; then \
3764c512586SBarry Smith             printf "mpif90 -show: %b\n" "${MPIFC_SHOW}"; \
3774c512586SBarry Smith           fi; \
3784c512586SBarry Smith             printf  "Fortran compiler version: %b\n" "${FC_VERSION}"; \
3794c512586SBarry Smith         fi
3804c512586SBarry Smith	-@if [ "${CUDAC}" != "" ]; then \
3814c512586SBarry Smith	   echo "Using CUDA compile: ${PETSC_CUCOMPILE_SINGLE}";\
3824c512586SBarry Smith         fi
3834c512586SBarry Smith	-@if [ "${CLANGUAGE}" = "CXX" ]; then \
3844c512586SBarry Smith           echo "Using C++ compiler to compile PETSc";\
3854c512586SBarry Smith        fi
3864c512586SBarry Smith	-@echo "-----------------------------------------"
3874c512586SBarry Smith	-@echo "Using C/C++ linker: ${PCC_LINKER}"
3884c512586SBarry Smith	-@echo "Using C/C++ flags: ${PCC_LINKER_FLAGS}"
3894c512586SBarry Smith	-@if [ "${FC}" != "" ]; then \
3904c512586SBarry Smith	   echo "Using Fortran linker: ${FC_LINKER}";\
3914c512586SBarry Smith	   echo "Using Fortran flags: ${FC_LINKER_FLAGS}";\
3924c512586SBarry Smith         fi
3934c512586SBarry Smith	-@echo "-----------------------------------------"
3944c512586SBarry Smith	-@echo "Using system modules: ${LOADEDMODULES}"
3954c512586SBarry Smith	-@if [ "${MPI_IS_MPIUNI}" = "1" ]; then \
3964c512586SBarry Smith           echo Using mpi.h: mpiuni; \
3974c512586SBarry Smith        else \
3984c512586SBarry Smith           TESTDIR=`mktemp -q -d -t petscmpi-XXXXXXXX` && \
3994c512586SBarry Smith           echo '#include <mpi.h>' > $${TESTDIR}/mpitest.c && \
4004c512586SBarry Smith           BUF=`${CPP} ${PETSC_CPPFLAGS} ${PETSC_CC_INCLUDES} $${TESTDIR}/mpitest.c |grep 'mpi\.h' | ( head -1 ; cat > /dev/null )` && \
4014c512586SBarry Smith           echo Using mpi.h: $${BUF}; ${RM} -rf $${TESTDIR}; \
4024c512586SBarry Smith        fi
4034c512586SBarry Smith	-@echo "-----------------------------------------"
4044c512586SBarry Smith	-@echo "Using libraries: ${PETSC_LIB}"
4054c512586SBarry Smith	-@echo "------------------------------------------"
4064c512586SBarry Smith	-@echo "Using mpiexec: ${MPIEXEC}"
4074c512586SBarry Smith	-@echo "------------------------------------------"
4084c512586SBarry Smith	-@echo "Using MAKE: ${MAKE}"
4094c512586SBarry Smith	-@echo "Default MAKEFLAGS: MAKE_NP:${MAKE_NP} MAKE_LOAD:${MAKE_LOAD} MAKEFLAGS:${MAKEFLAGS}"
4104c512586SBarry Smith	-@echo "=========================================="
4114c512586SBarry Smith
4124c512586SBarry Smith
4130e03b746SBarry Smithcheck_usermakefile:
414b752486dSSatish Balay	-@echo "Testing compile with user makefile"
415b752486dSSatish Balay	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
41627cb8d94SBarry Smith	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
417c4762a1bSJed Brown	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
418f53b81b6SPierre Jolivet	@grep -E "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
419b752486dSSatish Balay         if test -s .ftn.log; then \
420c4762a1bSJed Brown          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
421b752486dSSatish Balay         fi; ${RM} .ftn.log;
42227cb8d94SBarry Smith	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
423b752486dSSatish Balay	-@echo "Completed compile with user makefile"
424753a1a87SJed Brown
4254c512586SBarry Smith#********* Rules for running clangformat ************************************************************************************************************
4264c512586SBarry Smith
427c45dcc3fSBarry Smithcheckgitclean:
4289a632cc8SPierre Jolivet	@if ! git diff --quiet; then \
429d5b43468SJose E. Roman           echo "The repository has uncommitted files, cannot run checkclangformat" ;\
430c45dcc3fSBarry Smith           git status -s --untracked-files=no ;\
431c45dcc3fSBarry Smith           false;\
432c45dcc3fSBarry Smith        fi;
433c45dcc3fSBarry Smith
434c45dcc3fSBarry Smithcheckclangformatversion:
435c45dcc3fSBarry Smith	@version=`clang-format --version | cut -d" " -f3 | cut -d"." -f 1` ;\
436c45dcc3fSBarry Smith         if [ "$$version" == "version" ]; then version=`clang-format --version | cut -d" " -f4 | cut -d"." -f 1`; fi;\
4376c5826a2SPierre Jolivet         if [ $$version != 16 ]; then echo "Require clang-format version 16! Currently used clang-format version is $$version" ;false ; fi
438c45dcc3fSBarry Smith
439c45dcc3fSBarry Smith# Check that all the source code in the repository satisfies the .clang_format
440c45dcc3fSBarry Smithcheckclangformat: checkclangformatversion checkgitclean clangformat
4419a632cc8SPierre Jolivet	@if ! git diff --quiet; then \
4429a632cc8SPierre Jolivet          printf "The current commit has source code formatting problems\n" ;\
4439a632cc8SPierre Jolivet          if [ -z "${CI_PIPELINE_ID}"  ]; then \
4449a632cc8SPierre Jolivet            printf "Please run 'git diff' to check\n"; \
4459a632cc8SPierre Jolivet            git diff --stat; \
4469a632cc8SPierre Jolivet          else \
4479a632cc8SPierre Jolivet            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch; \
4489a632cc8SPierre Jolivet            git diff --patch-with-stat --color=always | head -1000; \
4499a632cc8SPierre Jolivet            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch` -gt 1000 ]; then \
4509a632cc8SPierre Jolivet              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch (in CI artifacts) for all changes\n"; \
4519a632cc8SPierre Jolivet            fi;\
4529a632cc8SPierre Jolivet          fi;\
453c45dcc3fSBarry Smith          false;\
454c45dcc3fSBarry Smith        fi;
455c45dcc3fSBarry Smith
4563d33ad60SJunchao Zhang# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
4573d33ad60SJunchao Zhangabitest:
458cab5ea25SPierre Jolivet	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
4593d33ad60SJunchao Zhang		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
4603d33ad60SJunchao Zhang		exit 1; \
4613d33ad60SJunchao Zhang	fi;
4623d33ad60SJunchao Zhang	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
4633d33ad60SJunchao Zhang	-@echo "========================================================================================="
4643d33ad60SJunchao Zhang	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
4653d33ad60SJunchao Zhang	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
4667b444a09SBarry Smith	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
4673d33ad60SJunchao Zhang	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
4683d33ad60SJunchao Zhang	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
4697b444a09SBarry Smith	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
4703d33ad60SJunchao Zhang	-@echo "========================================================================================="
471454c5dfcSJunchao Zhang	-@$(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
4723d33ad60SJunchao Zhang
4737b444a09SBarry Smith# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
4747b444a09SBarry Smithabitestcomplete:
4757b444a09SBarry Smith	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
4767b444a09SBarry Smith          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"` ;\
4777b444a09SBarry Smithecho $${OPTIONS} ;\
4787b444a09SBarry Smith        fi ; \
4797b444a09SBarry Smith        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
4807b444a09SBarry Smith          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
4817b444a09SBarry Smith        else \
4827b444a09SBarry Smith          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
4837b444a09SBarry Smith        fi ; \
4847b444a09SBarry Smith        echo "=================================================================================================" ;\
4857b444a09SBarry Smith        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
4867b444a09SBarry Smith        echo "=================================================================================================" ;\
4877b444a09SBarry Smith        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
4887b444a09SBarry Smith          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
4897b444a09SBarry Smith        else \
4907b444a09SBarry Smith          cd $${PETSC_DIR_OLD} ; \
4917b444a09SBarry Smith          git pull ; \
4927b444a09SBarry Smith        fi ; \
4937b444a09SBarry Smith        cd $${PETSC_DIR_OLD} ; \
4947b444a09SBarry Smith        git checkout ${branch} ; \
4957b444a09SBarry Smith        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
4967b444a09SBarry Smith        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
4977b444a09SBarry Smith        cd ${PETSC_DIR} ; \
4987b444a09SBarry Smith        ./configure $${OPTIONS}; \
4997b444a09SBarry Smith        make all test ; \
5007b444a09SBarry Smith        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
5017b444a09SBarry Smith
5024c512586SBarry Smith# ******** Rules for running Streams benchmark ****************************************************************************************************
503753a1a87SJed Brown
5044198fb66SBarry Smithmpistreams:
5050e03b746SBarry Smith	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
5065fabf859SBarry Smith
5074198fb66SBarry Smithmpistream:
5080e03b746SBarry Smith	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
5094198fb66SBarry Smith
5104198fb66SBarry Smithopenmpstreams:
5110e03b746SBarry Smith	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
5124198fb66SBarry Smith
5134198fb66SBarry Smithopenmpstream:
5140e03b746SBarry Smith	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
5154198fb66SBarry Smith
5164198fb66SBarry Smithstream: mpistream
5174198fb66SBarry Smith
5184198fb66SBarry Smithstreams: mpistreams
519fc5166cbSSatish Balay
5204c512586SBarry Smith# ********  Rules for generating tag files for Emacs/VIM *******************************************************************************************
5214c512586SBarry Smith
522753a1a87SJed Brownalletags:
523c3a89c15SBarry Smith	-@${PYTHON} lib/petsc/bin/maint/generateetags.py
524753a1a87SJed Brown	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
525753a1a87SJed Brown
52637763f56SJed Brown# obtain gtags from https://www.gnu.org/software/global/
527762ef373SBarry Smithallgtags:
52837763f56SJed Brown	-@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 -
529762ef373SBarry Smith
5304c512586SBarry Smith# ********* Rules for building "classic" documentation; uses rules also in lib/petsc/conf/petscrules.doc **************************************************
531753a1a87SJed Brown
5324c512586SBarry Smithdocs:
5334c512586SBarry Smith	cd doc; ${OMAKE_SELF} sphinxhtml
5349e423941SBarry Smith
5359e423941SBarry Smithchk_petscdir:
5369e423941SBarry Smith	@mypwd=`pwd`; cd ${PETSC_DIR} 2>&1 > /dev/null; true_PETSC_DIR=`pwd`; cd $${mypwd} 2>&1 >/dev/null; \
5379e423941SBarry Smith        newpwd=`echo $${mypwd} | sed "s+$${true_PETSC_DIR}+DUMMY+g"`;\
5389e423941SBarry Smith        haspetsc=`echo $${mypwd} | sed "s+petsc-+DUMMY+g"`;\
5399e423941SBarry Smith        if [ $${mypwd} = $${newpwd} -a $${haspetsc} != $${mypwd} ]; then \
5409e423941SBarry Smith          printf ${PETSC_TEXT_HILIGHT}"*********************W-a-r-n-i-n-g*************************\n" ; \
5419e423941SBarry Smith          echo "Your PETSC_DIR may not match the directory you are in";\
5429e423941SBarry Smith          echo "PETSC_DIR " $${true_PETSC_DIR} "Current directory" $${mypwd};\
5439e423941SBarry Smith          echo "Ignore this if you are running make check             ";\
5449e423941SBarry Smith          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ; \
5459e423941SBarry Smith        fi
5469e423941SBarry Smith
5479e423941SBarry Smithchk_in_petscdir:
5489e423941SBarry Smith	@if [ ! -f include/petscversion.h ]; then \
5499e423941SBarry Smith	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
5509e423941SBarry Smith	  echo " This target should be invoked in top level PETSc source dir!"; \
5519e423941SBarry Smith	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
5529e423941SBarry Smith
5539e423941SBarry Smithchk_loc:
5549e423941SBarry Smith	@if [ ${LOC}foo = foo ] ; then \
5559e423941SBarry Smith	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
5569e423941SBarry Smith	  echo " Please specify LOC variable for eg: make allmanpages LOC=/sandbox/petsc "; \
5579e423941SBarry Smith	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
5589e423941SBarry Smith	@${MKDIR} ${LOC}/manualpages
5599e423941SBarry Smith
5609e423941SBarry Smithchk_c2html:
5619e423941SBarry Smith	@if [ ${C2HTML}foo = foo ] ; then \
5629e423941SBarry Smith          printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR ************************\n" ; \
5639e423941SBarry Smith          echo "Require c2html for html docs. Please reconfigure with --download-c2html=1"; \
5649e423941SBarry Smith          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ;false; fi
5659e423941SBarry Smith
5669e423941SBarry Smith
5679e423941SBarry Smith# the ACTION=manualpages cannot run in parallel because they all write to the same manualpages.cit file
5686121d795SBarry Smithhloc=include/petsc/private
569589e537fSPatrick Sananallmanpages: chk_loc deletemanualpages
5702ba9d5beSBarry Smith	-echo " /* SUBMANSEC = PetscH */ " > ${hloc}/generated_khash.h
5712ba9d5beSBarry Smith	-sed -e 's?<T>?I?g' -e 's?<t>?i?g' -e 's?<KeyType>?PetscInt?g' ${hloc}/hashset.txt >> ${hloc}/generated_khash.h
5722ba9d5beSBarry Smith	-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
5732ba9d5beSBarry Smith	-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
5742ba9d5beSBarry Smith	-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
575faa16638SBarry Smith	-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
5762ba9d5beSBarry Smith	-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
5772ba9d5beSBarry Smith	-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
57871c41f4fSBarry Smith	-${RM} ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
579ac09b921SBarry Smith	-${OMAKE_SELF} ACTION=manualpages tree_src LOC=${LOC}
58073fdd05bSBarry Smith	-@sed -e s%man+../%man+manualpages/% ${LOC}/manualpages/manualpages.cit > ${LOC}/manualpages/htmlmap
58173fdd05bSBarry Smith	-@cat ${PETSC_DIR}/doc/classic/mpi.www.index >> ${LOC}/manualpages/htmlmap
58249762cbcSSatish Balay	cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
583d7b6776fSBarry Smith	a=`cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err | wc -l`; test ! $$a -gt 0
584f4da3331SVáclav Hapla
585f4da3331SVáclav Haplaallmanexamples: chk_loc allmanpages
5869e423941SBarry Smith	-${OMAKE_SELF} ACTION=manexamples tree LOC=${LOC}
5879e423941SBarry Smith
5889e423941SBarry Smith#
5899e423941SBarry Smith#    Goes through all manual pages adding links to implementations of the method
5909e423941SBarry Smith# or class, at the end of the file.
5919e423941SBarry Smith#
5929e423941SBarry Smith# To find functions implementing methods, we use git grep to look for
5939e423941SBarry Smith# well-formed PETSc functions
5949e423941SBarry Smith# - with names containing a single underscore
5959e423941SBarry Smith# - in files of appropriate types (.cu .c .cxx .h),
5969e423941SBarry Smith# - in paths including "/impls/",
5979e423941SBarry Smith# - excluding any line with a semicolon (to avoid matching prototypes), and
5989e423941SBarry Smith# - excluding any line including "_Private",
5999e423941SBarry Smith# storing potential matches in implsFuncAll.txt.
6009e423941SBarry Smith#
6019e423941SBarry Smith# For each man page we then grep in this file for the item's name followed by
6029e423941SBarry Smith# a single underscore and process the resulting implsFunc.txt to generate HTML.
6039e423941SBarry Smith#
6049e423941SBarry Smith# To find class implementations, we populate implsClassAll.txt with candidates
6059e423941SBarry Smith# - of the form "struct _p_itemName {",  and
6069e423941SBarry Smith# - not containing a semicolon
6079e423941SBarry Smith# and then grep for particular values of itemName, generating implsClass.txt,
6089e423941SBarry Smith# which is processed to generate HTML.
6099e423941SBarry Smith#
6109e423941SBarry Smith# Note: PETSC_DOC_OUT_ROOT_PLACEHOLDER must match the term used elsewhere in doc/
6119e423941SBarry Smithmanimplementations:
6129e423941SBarry Smith	-@git grep "struct\s\+_[pn]_[^\s]\+.*{" -- *.cpp *.cu *.c *.h *.cxx | grep -v -e ";" -e "/tests/" -e "/tutorials/" > implsClassAll.txt ; \
6139e423941SBarry Smith  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 ; \
6149e423941SBarry Smith  for i in ${LOC}/manualpages/*/*.md foo; do \
6159e423941SBarry Smith       if [ "$$i" != "foo" ] ; then \
6169e423941SBarry Smith          itemName=`basename $$i .md`;\
6179e423941SBarry Smith          grep "\s$${itemName}_" implsFuncAll.txt > implsFunc.txt ; \
6189e423941SBarry Smith          grep "_p_$${itemName}\b" implsClassAll.txt > implsClass.txt ; \
6199e423941SBarry Smith          if [ -s implsFunc.txt ] || [ -s implsClass.txt ] ; then \
6209e423941SBarry Smith            printf "\n## Implementations\n\n" >> $$i; \
6219e423941SBarry Smith          fi ; \
6229e423941SBarry Smith          if [ -s implsFunc.txt ] ; then \
6239e423941SBarry Smith            sed "s?\(.*\.[ch]x*u*\).*\($${itemName}.*\)(.*)?<A HREF=\"PETSC_DOC_OUT_ROOT_PLACEHOLDER/\1.html#\2\">\2 in \1</A><BR>?" implsFunc.txt >> $$i ; \
6249e423941SBarry Smith          fi ; \
6259e423941SBarry Smith          if [ -s implsClass.txt ] ; then \
6269e423941SBarry Smith            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 ; \
6279e423941SBarry Smith          fi ; \
6289e423941SBarry Smith          ${RM} implsFunc.txt implsClass.txt; \
6299e423941SBarry Smith       fi ; \
6309e423941SBarry Smith  done ; \
6319e423941SBarry Smith  ${RM} implsClassAll.txt implsFuncAll.txt
632f4da3331SVáclav Hapla
6337b770568SPatrick Sanan# Build all classic docs except html sources
6349e423941SBarry Smithalldoc_pre: chk_loc allmanpages allmanexamples
6359e423941SBarry Smith	-${OMAKE_SELF} LOC=${LOC} manimplementations
636c3a89c15SBarry Smith	-${PYTHON} lib/petsc/bin/maint/wwwindex.py ${PETSC_DIR} ${LOC}
637753a1a87SJed Brown
63803953011SBarry Smith# Run after alldoc_pre to build html sources
63903953011SBarry Smithalldoc_post: chk_loc  chk_c2html
64003953011SBarry Smith	-@if command -v parallel &> /dev/null; then \
64103953011SBarry Smith           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' ; \
64203953011SBarry Smith         else \
64303953011SBarry Smith           ${OMAKE_SELF} ACTION=html PETSC_DIR=${PETSC_DIR} tree LOC=${LOC}; \
64403953011SBarry Smith        fi
645753a1a87SJed Brown
64672ece014SPatrick Sananalldocclean: deletemanualpages allcleanhtml
647753a1a87SJed Brown
648589e537fSPatrick Sanan# Deletes man pages (.md version)
649753a1a87SJed Browndeletemanualpages: chk_loc
65073fdd05bSBarry Smith	-@if [ -d ${LOC} -a -d ${LOC}/manualpages ]; then \
65173fdd05bSBarry Smith          find ${LOC}/manualpages -type f -name "*.md" -exec ${RM} {} \; ;\
65273fdd05bSBarry Smith          ${RM} ${LOC}/manualpages/manualpages.cit ;\
653753a1a87SJed Brown        fi
654753a1a87SJed Brown
655753a1a87SJed Brownallcleanhtml:
6569e423941SBarry Smith	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} tree
657753a1a87SJed Brown
6584c512586SBarry Smith# ********* Rules for checking code coverage *********************************************************************************************
659753a1a87SJed Brown
660753a1a87SJed Browngcov:
66141baa1e4SJacob Faibussowitsch	output_file_base_name=${PETSC_ARCH}-gcovr-report.json; \
66220c90202SJacob Faibussowitsch	petsc_arch_dir=${PETSC_DIR}/${PETSC_ARCH}; \
663ccfcae5eSJacob Faibussowitsch        tar_file=$${petsc_arch_dir}/$${output_file_base_name}.tar.bz2; \
664ccfcae5eSJacob Faibussowitsch	cd $${petsc_arch_dir}/obj && \
665ccfcae5eSJacob Faibussowitsch	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} && \
666ccfcae5eSJacob Faibussowitsch	${RM} -f $${tar_file} && \
667ccfcae5eSJacob Faibussowitsch	tar --bzip2 -cf $${tar_file} -C $${petsc_arch_dir} ./$${output_file_base_name} && \
668ccfcae5eSJacob Faibussowitsch	${RM} $${petsc_arch_dir}/$${output_file_base_name}
669753a1a87SJed Brown
670753a1a87SJed Brownmergegcov:
6717ce81a4bSJacob Faibussowitsch	$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge-branch `lib/petsc/bin/maint/check-merge-branch.sh` --html --xml ${PETSC_GCOV_OPTIONS}
672b0e5478fSScott Kruger
6734c512586SBarry Smith#********* Rules for make clangformat and checking violation of coding standards **************************************************************
6744c512586SBarry Smith
6754c512586SBarry Smith# Format all the source code in the given directory and down according to the file .clang_format
6764c512586SBarry Smithclangformat:
6774c512586SBarry Smith	-@git --no-pager ls-files -z ${GITCFSRC} | xargs -0 -P $(MAKE_NP) -L 10 clang-format -i
6784c512586SBarry Smith
6794c512586SBarry SmithGITSRC = '*.[chF]' '*.F90' '*.hpp' '*.cpp' '*.cxx' '*.cu' ${GITSRCEXCL}
6804c512586SBarry SmithGITSRCEXCL = \
6814c512586SBarry Smith':!*khash/*' \
6824c512586SBarry Smith':!*valgrind/*' \
6834c512586SBarry Smith':!*yaml/*' \
6844c512586SBarry Smith':!*perfstubs/*'
6854c512586SBarry SmithGITCFSRC = '*.[ch]' '*.hpp' '*.cpp' '*.cxx' '*.cu' ${GITSRCEXCL} ${GITCFSRCEXCL}
6864c512586SBarry SmithGITCFSRCEXCL = \
6874c512586SBarry Smith':!*petscversion.h' \
6884c512586SBarry Smith':!*mpif.h' \
6894c512586SBarry Smith':!*mpiunifdef.h' \
6904c512586SBarry Smith':!*finclude/*' \
6914c512586SBarry Smith':!systems/*' \
6924c512586SBarry Smith':!*benchmarks/*' \
6934c512586SBarry Smith':!*binding/*' \
6944c512586SBarry Smith':!*-custom/*' \
6954c512586SBarry Smith':!*f90-mod/*'
6964c512586SBarry Smith
6974c512586SBarry SmithcheckbadSource:
6984c512586SBarry Smith	@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
6994c512586SBarry Smith	-@${RM} -f checkbadSource.out
7004c512586SBarry Smith	-@echo "------Double blank lines in file -----------------------------------" > checkbadSource.out
7014c512586SBarry Smith	-@git --no-pager grep -n -P '^$$' -- ${GITSRC} > doublelinecheck.out
7024c512586SBarry Smith	-@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/doublelinecheck.py doublelinecheck.out >> checkbadSource.out
7034c512586SBarry Smith	-@${RM} -f doublelinecheck.out
7044c512586SBarry Smith	-@echo "------Tabs in file -------------------------------------------------" >> checkbadSource.out
7054c512586SBarry Smith	-@git --no-pager grep -n -P '\t' -- ${GITSRC} >> checkbadSource.out;true
7064c512586SBarry Smith	-@echo "------White space at end of line -----------------------------------" >> checkbadSource.out
7074c512586SBarry Smith	-@git --no-pager grep -n -P ' $$' -- ${GITSRC} >> checkbadSource.out;true
7084c512586SBarry Smith	-@echo "------Two ;; -------------------------------------------------------" >> checkbadSource.out
7094c512586SBarry Smith	-@git --no-pager grep -n -P -e ';;' -- ${GITSRC} | grep -v ' for (' >> checkbadSource.out;true
7104c512586SBarry Smith	-@echo "------PetscCall for an MPI error code ------------------------------" >> checkbadSource.out
7114c512586SBarry Smith	-@git --no-pager grep -n -P -e '= MPI[U]*_\w*\(.*PetscCall' -- ${GITSRC} | grep -v MPIU_File >> checkbadSource.out;true
7124c512586SBarry Smith	-@echo "------Missing if (ierr) return ierr; -------------------------------" >> checkbadSource.out
7134c512586SBarry Smith	-@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
7144c512586SBarry Smith	-@echo "------DOS file (with DOS newlines) ---------------------------------" >> checkbadSource.out
7154c512586SBarry Smith	-@git --no-pager grep -n -P '\r' -- ${GITSRC} >> checkbadSource.out;true
7164c512586SBarry Smith	-@echo "------{ before SETERRQ ---------------------------------------------" >> checkbadSource.out
7174c512586SBarry Smith	-@git --no-pager grep -n -P '{SETERRQ' -- ${GITSRC} >> checkbadSource.out;true
7184c512586SBarry Smith	-@echo "------PetscCall following SETERRQ ----------------------------------" >> checkbadSource.out
7194c512586SBarry Smith	-@git --no-pager grep -n -P 'SETERRQ' -- ${GITSRC} | grep ";PetscCall" >> checkbadSource.out;true
7204c512586SBarry Smith	-@echo "------SETERRQ() without defined error code -------------------------" >> checkbadSource.out
7214c512586SBarry Smith	-@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
7224c512586SBarry Smith	-@echo "------SETERRQ() with trailing newline ------------------------------" >> checkbadSource.out
7234c512586SBarry Smith	-@git --no-pager grep -n -P "SETERRQ[1-9]?.*\\\n\"" -- ${GITSRC} >> checkbadSource.out;true
7244c512586SBarry Smith	-@echo "------Define keyword used in test definition -----------------------" >> checkbadSource.out
7254c512586SBarry Smith	-@git --no-pager grep -n -P -e 'requires:.*define\(' -- ${GITSRC} >> checkbadSource.out;true
7264c512586SBarry Smith	-@echo "------No new line at end of file -----------------------------------" >> checkbadSource.out
7274c512586SBarry Smith	-@git --no-pager grep -n -P '[^\n]\z' -- ${GITSRC} >> checkbadSource.out;true
7284c512586SBarry Smith	-@echo "------Using if (condition) SETERRQ(...) instead of PetscCheck() ----" >> checkbadSource.out
7294c512586SBarry Smith	-@git --no-pager grep -n -P ' if +(.*) *SETERRQ' -- ${GITSRC} | grep -v 'PetscUnlikelyDebug' | grep -v 'petscerror.h' >> checkbadSource.out;true
7304c512586SBarry Smith	-@echo "------Using if (PetscUnlikelyDebug(condition)) SETERRQ(...) instead of PetscAssert()" >> checkbadSource.out
7314c512586SBarry Smith	-@git --no-pager grep -n -P -E ' if +\(PetscUnlikelyDebug.*\) *SETERRQ' -- ${GITSRC} | grep -v petscerror.h >> checkbadSource.out;true
7324c512586SBarry Smith	-@echo "------Using PetscFunctionReturn(ierr) ------------------------------" >> checkbadSource.out
7334c512586SBarry Smith	-@git --no-pager grep -n -P 'PetscFunctionReturn(ierr)' -- ${GITSRC} >> checkbadSource.out;true
7344c512586SBarry Smith	-@echo "------Defining a returning macro without PetscMacroReturns() -------" >> checkbadSource.out
7354c512586SBarry Smith	-@git --no-pager grep -n -P 'define .*\w+;\s+do' -- ${GITSRC} | grep -E -v '(PetscMacroReturns|PetscDrawCollectiveBegin|MatPreallocateBegin|PetscOptionsBegin|PetscObjectOptionsBegin|PetscOptionsHeadEnd)' >> checkbadSource.out;true
7364c512586SBarry Smith	-@echo "------Defining an error checking macro using CHKERR style ----------" >> checkbadSource.out
7374c512586SBarry Smith	-@git --no-pager grep -n -P 'define\s+CHKERR\w*\(.*\)\s*do\s+{' -- ${GITSRC} >> checkbadSource.out;true
7384c512586SBarry Smith	@a=`cat checkbadSource.out | wc -l`; l=`expr $$a - 18` ;\
7394c512586SBarry Smith         if [ $$l -gt 0 ] ; then \
7404c512586SBarry Smith           echo $$l " files with errors detected in source code formatting" ;\
7414c512586SBarry Smith           cat checkbadSource.out ;\
7424c512586SBarry Smith         else \
7434c512586SBarry Smith	   ${RM} -f checkbadSource.out;\
7444c512586SBarry Smith         fi;\
7454c512586SBarry Smith         test ! $$l -gt 0
7464c512586SBarry Smith	-@git --no-pager grep -P -n "[\x00-\x08\x0E-\x1F\x80-\xFF]" -- ${GITSRC} > badSourceChar.out;true
7474c512586SBarry Smith	-@w=`cat badSourceChar.out | wc -l`;\
7484c512586SBarry Smith         if [ $$w -gt 0 ] ; then \
7494c512586SBarry Smith           echo "Source files with non-ASCII characters ----------------" ;\
7504c512586SBarry Smith           cat badSourceChar.out ;\
7514c512586SBarry Smith         else \
7524c512586SBarry Smith	   ${RM} -f badSourceChar.out;\
7534c512586SBarry Smith         fi
7544c512586SBarry Smith	@test ! -s badSourceChar.out
7554c512586SBarry Smith
7564c512586SBarry SmithcheckbadFileChange:
7574c512586SBarry Smith	@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
7584c512586SBarry Smith
7594c512586SBarry Smithvermin:
7604c512586SBarry Smith	@vermin -vvv -t=3.4- ${VERMIN_OPTIONS} ${PETSC_DIR}/config
7614c512586SBarry Smith
7624c512586SBarry Smithlint:
7634c512586SBarry Smith	${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter --verbose=${V} --apply-patches=${REPLACE} $(LINTER_OPTIONS)
7644c512586SBarry Smith
7654c512586SBarry Smithhelp-lint:
7664c512586SBarry Smith	@${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter --help
7674c512586SBarry Smith	-@echo "Basic usage:"
7684c512586SBarry Smith	-@echo "   make lint      <options>"
7694c512586SBarry Smith	-@echo "   make test-lint <options> <test only options>"
7704c512586SBarry Smith	-@echo
7714c512586SBarry Smith	-@echo "Options:"
7724c512586SBarry Smith	-@echo "  V=[1,0]                                Enable or disable verbose output"
7734c512586SBarry Smith	-@echo "  LINTER_OPTIONS=\"--opt1 --opt2 ...\"     See above for available options"
7744c512586SBarry Smith	-@echo
7754c512586SBarry Smith	-@echo "Test Only Options:"
7764c512586SBarry Smith	-@echo "  REPLACE=[1,0]                          Enable or disable replacing test output"
7774c512586SBarry Smith	-@echo
7784c512586SBarry Smith
7794c512586SBarry Smithtest-lint:
7804c512586SBarry Smith	${PYTHON} ${PETSC_DIR}/lib/petsc/bin/maint/petsclinter ${PETSC_DIR}/src/sys/tests/linter --test -j0 --werror --replace=${REPLACE} --verbose=${V} $(LINTER_OPTIONS)
7814c512586SBarry Smith
782753a1a87SJed Browncountfortranfunctions:
783f53b81b6SPierre Jolivet	-@cd ${PETSC_DIR}/src/fortran; grep -E '^void' custom/*.c auto/*.c | \
784f53b81b6SPierre Jolivet	cut -d'(' -f1 | tr -s  ' ' | cut -d' ' -f2 | uniq | grep -E -v "(^$$|Petsc)" | \
785753a1a87SJed Brown	sed "s/_$$//" | sort > /tmp/countfortranfunctions
786753a1a87SJed Brown
787753a1a87SJed Browncountcfunctions:
788068711b4SBarry Smith	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
789753a1a87SJed Brown	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
790068711b4SBarry Smith	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
791753a1a87SJed Brown
792753a1a87SJed Browndifffortranfunctions: countfortranfunctions countcfunctions
793753a1a87SJed Brown	-@echo -------------- Functions missing in the fortran interface ---------------------
794753a1a87SJed Brown	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^<" | cut -d' ' -f2
795753a1a87SJed Brown	-@echo ----------------- Functions missing in the C interface ------------------------
796753a1a87SJed Brown	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^>" | cut -d' ' -f2
797753a1a87SJed Brown	-@${RM}  /tmp/countcfunctions /tmp/countfortranfunctions
798753a1a87SJed Brown
799753a1a87SJed Browncheckbadfortranstubs:
800753a1a87SJed Brown	-@echo "========================================="
801753a1a87SJed Brown	-@echo "Functions with MPI_Comm as an Argument"
802753a1a87SJed Brown	-@echo "========================================="
803753a1a87SJed Brown	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'MPI_Comm' | \
804753a1a87SJed Brown	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
805753a1a87SJed Brown	-@echo "========================================="
806753a1a87SJed Brown	-@echo "Functions with a String as an Argument"
807753a1a87SJed Brown	-@echo "========================================="
808753a1a87SJed Brown	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'char \*' | \
809753a1a87SJed Brown	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
810753a1a87SJed Brown	-@echo "========================================="
811753a1a87SJed Brown	-@echo "Functions with Pointers to PETSc Objects as Argument"
812753a1a87SJed Brown	-@echo "========================================="
813753a1a87SJed Brown	-@cd ${PETSC_DIR}/src/fortran/auto; \
814753a1a87SJed Brown	_p_OBJ=`grep _p_ ${PETSC_DIR}/include/*.h | tr -s ' ' | \
815753a1a87SJed Brown	cut -d' ' -f 3 | tr -s '\012' | grep -v '{' | cut -d'*' -f1 | \
816753a1a87SJed Brown	sed "s/_p_//g" | tr -s '\012 ' ' *|' ` ; \
817753a1a87SJed Brown	for OBJ in $$_p_OBJ; do \
818753a1a87SJed Brown	grep "$$OBJ \*" *.c | tr -s ' ' | tr -s ':' ' ' | \
819753a1a87SJed Brown	cut -d'(' -f1 | cut -d' ' -f1,3; \
820753a1a87SJed Brown	done
821a3269974SBarry Smith
822a3269974SBarry Smithcheckpackagetests:
823a3269974SBarry Smith	-@echo "Missing package tests"
824f53b81b6SPierre Jolivet	-@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
825a3269974SBarry Smith	-@echo "Missing download package tests"
826f53b81b6SPierre Jolivet	-@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
827a3269974SBarry Smith
8284c512586SBarry Smithcheck_petsc4py_rst:
8294c512586SBarry Smith	@${RM} -f petsc4py_rst.log
8304c512586SBarry Smith	@echo "Checking src/binding/petsc4py/DESCRIPTION.rst"
8314c512586SBarry Smith	@rst2html src/binding/petsc4py/DESCRIPTION.rst > /dev/null 2> petsc4py_rst.log
8324c512586SBarry Smith	@if test -s petsc4py_rst.log; then cat petsc4py_rst.log; exit 1; fi
8334c512586SBarry Smith
8344c512586SBarry Smith# TODO: checkTestCoverage: that makes sure every tutorial test has at least one test listed in the file, perhaps handled by gmakegentest.py
8354c512586SBarry Smith# TODO: check for PetscBeginFunctionUser in non-example source
8364c512586SBarry Smith# TODO: check for __ at start of #define or symbol
8374c512586SBarry Smith# TODO: checking for missing manual pages
8384c512586SBarry Smith# TODO: check for incorrect %d
8394c512586SBarry Smith# TODO: check for double blank lines
8404c512586SBarry Smith# TODO: check for ill-formed manual pages
8414c512586SBarry Smith# TODO: check for { on line after for
8424c512586SBarry Smith# TODO: check for } then else on following line
8434c512586SBarry Smith# TODO: check for } else { with SETERRQ on following line or if () { with SETERRQ on following line
8444c512586SBarry Smith
8454c512586SBarry Smith#  Lists all the URLs in the PETSc repository that are unaccessible, nonexistent, or permanently moved (301)
8464c512586SBarry Smith#  REPLACE=1 locations marked as permanently moved (301) are replaced in the repository
8474c512586SBarry Smith#  This code is fragile; always check the changes after a use of REPLACE=1 before committing the changes
8484c512586SBarry Smith#
8494c512586SBarry Smith#  Notes:
8504c512586SBarry Smith#    The first tr in the line is split lines for the cases where multiple URLs are in the same line
8514c512586SBarry Smith#    The first sed handles the case (http[s]*://xxx)
8524c512586SBarry Smith#    The list is sorted by length so that if REPLACE is used the longer apply before the shorter
8534c512586SBarry Smith#    The code recursively follows the permanently moved (301) redirections until it reaches the final URL
8544c512586SBarry Smith#    For DropBox we need to check the validity of the new URL but do not want to return to user the internal "raw" URL
8554c512586SBarry SmithcheckbadURLS:
8564c512586SBarry Smith	-@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` ; \
8574c512586SBarry Smith        for i in $$x; do \
8584c512586SBarry Smith          url=$$i; \
8594c512586SBarry Smith          msg=''; \
8604c512586SBarry Smith          while [[ "$${msg}D" == "D" ]] ; do \
8614c512586SBarry Smith            y1=`curl --connect-timeout 5 --head --silent $${url} | head -n 1`; \
8624c512586SBarry Smith            y2=`echo $${y1} | grep ' 4[0-9]* '`; \
8634c512586SBarry Smith            y3=`echo $${y1} | grep ' 301 '`; \
8644c512586SBarry Smith            if [[ "$${y1}D" == "D" ]] ; then \
8654c512586SBarry Smith              msg="Unable to reach site" ; \
8664c512586SBarry Smith            elif [[ "$${y2}D" != "D" ]] ; then \
8674c512586SBarry Smith              msg=$${y1} ; \
8684c512586SBarry Smith            elif [[ "$${y3}D" != "D" ]] ; then \
8694c512586SBarry Smith              l=`curl --connect-timeout 5 --head --silent $${url} | grep ocation | sed 's/.*ocation:[[:blank:]]\(.*\)/\1/g' | tr -d '\r'` ; \
8704c512586SBarry Smith              w=`echo $$l | grep 'http'` ; \
8714c512586SBarry Smith              if [[ "$${w}D" != "D" ]] ; then \
8724c512586SBarry Smith                url=$$l ; \
8734c512586SBarry Smith              else \
8744c512586SBarry Smith                ws=`echo $${url} | sed 's!\(http[s]*://[-a-zA-Z0-9_.]*\)/.*!\1!g'` ; \
8754c512586SBarry Smith                dp=`echo $${ws}$${l} | grep "dropbox.com/s/raw"` ; \
8764c512586SBarry Smith                if [[ "$${dp}D" != "D" ]] ; then \
8774c512586SBarry Smith                  b=`curl --connect-timeout 5 --head --silent $${ws}$$l | head -n 1` ; \
8784c512586SBarry Smith                  c=`echo $${b} | grep -E "( 2[0-9]* | 302 )"` ; \
8794c512586SBarry Smith                  if [[ "$${c}D" == "D" ]] ; then \
8804c512586SBarry Smith                    msg=`echo "dropbox file doesn't exist" $${c}` ; \
8814c512586SBarry Smith                  else \
8824c512586SBarry Smith                    break ; \
8834c512586SBarry Smith                  fi; \
8844c512586SBarry Smith                else \
8854c512586SBarry Smith                  url="$${ws}$$l" ; \
8864c512586SBarry Smith                fi; \
8874c512586SBarry Smith              fi; \
8884c512586SBarry Smith            else \
8894c512586SBarry Smith              break; \
8904c512586SBarry Smith            fi; \
8914c512586SBarry Smith          done;\
8924c512586SBarry Smith          if [[ "$${msg}D" == "D" && "$${url}" != "$$i" ]] ; then \
8934c512586SBarry Smith            echo "URL" $$i "has moved to valid final location:" $${url} ; \
8944c512586SBarry Smith            if [[ "$${REPLACE}D" != "D" ]] ; then \
8954c512586SBarry Smith              git psed $$i $$l ;\
8964c512586SBarry Smith            fi; \
8974c512586SBarry Smith          elif [[ "$${msg}D" != "D" && "$${url}" != "$$i" ]] ; then \
8984c512586SBarry Smith            echo "ERROR: URL" $$i "has moved to invalid final location:" $${url} $${msg} ; \
8994c512586SBarry Smith          elif [[ "$${msg}D" != "D" ]] ; then \
9004c512586SBarry Smith            echo "ERROR: URL" $$i "invalid:" $${msg} ; \
9014c512586SBarry Smith          fi; \
9024c512586SBarry Smith        done
9034c512586SBarry Smith
9044c512586SBarry SmithcheckbadSpelling:
9054c512586SBarry Smith	-@x=`python3 ../bin/extract.py | aspell list | sort -u` ;
9064c512586SBarry Smith
9074c512586SBarry Smithupdatedatafiles:
9084c512586SBarry Smith	-@if [ -d "${HOME}/datafiles" ]; then \
9094c512586SBarry Smith            echo " ** Updating datafiles at ${HOME}/datafiles **"; \
9104c512586SBarry Smith            cd "${HOME}/datafiles" && git pull -q; fi
9114c512586SBarry Smith
912dc0529c6SBarry Smith.PHONY: info info_h all deletelibs allclean update \
913425fd74bSBarry Smith        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanpages \
914425fd74bSBarry Smith        allcleanhtml  countfortranfunctions \
915416ff897SSatish Balay        start_configure configure_petsc configure_clean matlabbin install
916