xref: /petsc/makefile (revision cb5db2414029547a5ccf00a1710ee072432a08af)
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
20
21# next line defines PETSC_DIR and PETSC_ARCH if they are not set
22include ././${PETSC_ARCH}/lib/petsc/conf/petscvariables
23include ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscrules
24include ${PETSC_DIR}/lib/petsc/conf/rules_doc.mk
25include ${PETSC_DIR}/lib/petsc/conf/rules_util.mk
26
27# This makefile contains a lot of PHONY targets with improperly specified prerequisites
28# where correct execution instead depends on the targets being processed in the correct
29# order.
30.NOTPARALLEL:
31
32OMAKE_SELF = $(OMAKE) -f makefile
33OMAKE_SELF_PRINTDIR = $(OMAKE_PRINTDIR) -f makefile
34PETSCCONF_H = ${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h
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             if [ "X${CONDA_ACTIVE}" != "X" ]; then \
53               echo "  Having Conda in your shell may have caused this problem, consider turning off Conda." 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
54             fi ; \
55             printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
56           fi \
57	 else \
58	  ${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 ;\
59        fi #solaris make likes to print the whole command that gave error. So split this up into the smallest chunk below
60	@echo "Finishing make run at `date +'%a, %d %b %Y %H:%M:%S %z'`" >> ${PETSC_ARCH}/lib/petsc/conf/make.log
61	@if [ "`cat ${PETSC_ARCH}/lib/petsc/conf/error.log 2> /dev/null`" != "0" ]; then exit 1; fi
62
63all-local: info libs matlabbin petsc4py-build libmesh-build mfem-build slepc-build hpddm-build amrex-build bamg-build
64
65${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files:
66	@touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/files
67
68${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles:
69	@${MKDIR} -p ${PETSC_DIR}/${PETSC_ARCH}/tests && touch -t 197102020000 ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
70
71chk_upgrade:
72	-@PETSC_DIR=${PETSC_DIR} ${PYTHON} ${PETSC_DIR}/lib/petsc/bin/petscnagupgrade.py
73
74matlabbin:
75	-@if [ "${MATLAB_MEX}" != "" -a "${MATLAB_SOCKET}" != "" -a "${PETSC_SCALAR}" = "real" -a "${PETSC_PRECISION}" = "double" ]; then \
76          echo "BEGINNING TO COMPILE MATLAB INTERFACE"; \
77            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc; fi; \
78            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab; fi; \
79            cd src/sys/classes/viewer/impls/socket/mex-scripts && ${OMAKE_SELF} mex-scripts PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR}; \
80            echo "========================================="; \
81        fi
82
83allfortranstubs: deletefortranstubs
84	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py --petsc-dir=${PETSC_DIR} --petsc-arch=${PETSC_ARCH} --bfort=${BFORT} --mode=generate --verbose=${V}
85	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py --petsc-dir=${PETSC_DIR} --petsc-arch=${PETSC_ARCH} --mode=merge --verbose=${V}
86
87#copy of allfortranstubs with PETSC_ARCH=''
88allfortranstubsinplace: deletefortranstubs
89	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py --petsc-dir=${PETSC_DIR} --petsc-arch='' --bfort=${BFORT} --mode=generate --verbose=${V}
90	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py --petsc-dir=${PETSC_DIR} --petsc-arch='' --mode=merge --verbose=${V}
91
92deleteshared:
93	@for LIBNAME in ${SHLIBS}; \
94	do \
95	   if [ -d ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM ]; then \
96             echo ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
97	     ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}.dylib.dSYM; \
98	   fi; \
99           echo ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
100           ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}.${SL_LINKER_SUFFIX}; \
101	done
102	@if [ -f ${INSTALL_LIB_DIR}/so_locations ]; then \
103          echo ${RM} ${INSTALL_LIB_DIR}/so_locations; \
104          ${RM} ${INSTALL_LIB_DIR}/so_locations; \
105	fi
106
107deletefortranstubs:
108	-@find src -type d -name ftn-auto* | xargs rm -rf
109	-@if [ -n "${PETSC_ARCH}" ] && [ -d ${PETSC_ARCH} ] && [ -d ${PETSC_ARCH}/src ]; then \
110          find ${PETSC_ARCH}/src -type d -name ftn-auto* | xargs rm -rf ;\
111        fi
112
113reconfigure: allclean
114	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
115
116chkopts:
117	-@echo "Warning: chkopts target is deprecated and can be removed from user makefiles"
118
119gnumake:
120	+@echo "make gnumake is deprecated, use make libs"
121	+@make libs
122
123# ********  Rules for make check ****************************************************************************************************************************
124
125RUN_TEST = ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff
126
127check_install: check
128check:
129	-@echo "Running PETSc check examples to verify correct installation"
130	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
131	@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
132           echo "Running with batch filesystem, cannot run make check"; \
133        elif [ "${MPIEXEC}" = "/bin/false" ]; then \
134           echo "*mpiexec not found*. cannot run make check"; \
135        else \
136          ${RM} -f check_error;\
137          ${RUN_TEST} PETSC_OPTIONS="${PETSC_OPTIONS} ${PETSC_TEST_OPTIONS}" PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" check_build 2>&1 | tee ./${PETSC_ARCH}/lib/petsc/conf/check.log; \
138          if [ -f check_error ]; then \
139            echo "Error while running make check"; \
140            ${RM} -f check_error;\
141            exit 1; \
142          fi; \
143          ${RM} -f check_error;\
144        fi;
145
146check_build:
147	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} clean-legacy
148	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19
149	+@if [ ! "${MPI_IS_MPIUNI}" ]; then cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19_mpi; fi
150	+@if [ "${HYPRE_LIB}" != "" ] && [ "${PETSC_SCALAR}" = "real" ]; then \
151          if [ "${CUDA_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_cuda; \
152          elif [ "${HIP_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_hip; \
153          else HYPRE_TEST=runex19_hypre; fi; \
154          cd src/snes/tutorials >/dev/null; ${RUN_TEST} $${HYPRE_TEST}; \
155        fi;
156	+@if [ "${CUDA_LIB}" != "" ]; then \
157          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_cuda; \
158        fi;
159	+@if [ "${MPI_IS_MPIUNI}" = "" ]; then \
160          cd src/snes/tutorials >/dev/null; \
161          if [ "${KOKKOS_KERNELS_LIB}" != "" ]  &&  [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ]; then \
162            ${RUN_TEST} runex3k_kokkos; \
163          fi;\
164          if [ "${MUMPS_LIB}" != "" ]; then \
165             ${RUN_TEST} runex19_fieldsplit_mumps; \
166          fi;\
167          if [ "${SUITESPARSE_LIB}" != "" ]; then \
168             ${RUN_TEST} runex19_suitesparse; \
169          fi;\
170          if [ "${SUPERLU_DIST_LIB}" != "" ]; then \
171            ${RUN_TEST} runex19_superlu_dist; \
172          fi;\
173          if ( [ "${ML_LIB}" != "" ] ||  [ "${TRILINOS_LIB}" != "" ] ); then \
174            ${RUN_TEST} runex19_ml; \
175          fi; \
176	  ${RUN_TEST} clean-legacy; \
177          cd - > /dev/null; \
178          if ( [ "${AMREX_LIB}" != "" ] && [ "${CUDA_LIB}" = "" ] ); then \
179            echo "Running amrex test example to verify correct installation";\
180            echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}";\
181            cd src/ksp/ksp/tutorials/amrex >/dev/null;\
182            ${RUN_TEST} clean-legacy; \
183            ${RUN_TEST} testamrex; \
184            ${RUN_TEST} clean-legacy; \
185            cd - > /dev/null; \
186          fi;\
187        fi;
188	+@if [ "${HDF5_LIB}" != "" ]; then \
189          cd src/vec/vec/tests >/dev/null;\
190          ${RUN_TEST} clean-legacy; \
191          ${RUN_TEST} runex47; \
192          ${RUN_TEST} clean-legacy; \
193         fi;
194	+@if [ "${MPI4PY}" = "yes" ]; then \
195           cd src/sys/tests >/dev/null; \
196           ${RUN_TEST} clean-legacy; \
197           ${RUN_TEST} testex55; \
198           ${RUN_TEST} clean-legacy; \
199         fi;
200	+@if [ "${PETSC4PY}" = "yes" ]; then \
201           cd src/ksp/ksp/tutorials >/dev/null; \
202           ${RUN_TEST} clean-legacy; \
203           ${RUN_TEST} testex100; \
204           ${RUN_TEST} clean-legacy; \
205         fi;
206	+@grep -E "^#define PETSC_USE_FORTRAN_BINDINGS 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
207         if test -s .ftn.log; then \
208           cd src/snes/tutorials >/dev/null; \
209           ${RUN_TEST} clean-legacy; \
210           ${RUN_TEST} testex5f; \
211           ${RUN_TEST} clean-legacy; \
212         fi; ${RM} .ftn.log;
213	+@grep -E "^#define PETSC_HAVE_MATLAB 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
214         if test -s .ftn.log; then \
215           cd src/vec/vec/tutorials >/dev/null; \
216           ${RUN_TEST} clean-legacy; \
217           ${RUN_TEST} testex31; \
218           ${RUN_TEST} clean-legacy; \
219          fi; ${RM} .ftn.log;
220	+@if [ "${SLEPC}" = "yes" ]; then \
221           ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} slepc-check; \
222         fi;
223	-@echo "Completed PETSc check examples"
224
225# ********* Rules for make install *******************************************************************************************************************
226
227install:
228	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
229	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
230
231# A smaller install with fewer extras
232install-lib:
233	@${PYTHON} ./config/install.py -destDir=${DESTDIR} -no-examples
234	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
235
236install-builtafterpetsc:
237	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=${PETSC_INSTALL} petsc4py-install libmesh-install mfem-install slepc-install hpddm-install amrex-install bamg-install
238
239# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
240dist:
241	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
242
243# ******** Rules for running the full test suite ********************************************************************************************************
244
245TESTMODE = testexamples
246ALLTESTS_CHECK_FAILURES = no
247ALLTESTS_MAKEFILE = ${PETSC_DIR}/gmakefile.test
248VALGRIND=0
249alltests: chk_in_petscdir ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
250	-@${RM} -rf ${PETSC_ARCH}/lib/petsc/conf/alltests.log alltests.log
251	+@if [ -f ${PETSC_DIR}/share/petsc/examples/gmakefile.test ] ; then \
252            ALLTESTS_MAKEFILE=${PETSC_DIR}/share/petsc/examples/gmakefile.test ; \
253            ALLTESTSLOG=alltests.log ;\
254          else \
255            ALLTESTS_MAKEFILE=${PETSC_DIR}/gmakefile.test; \
256            ALLTESTSLOG=${PETSC_ARCH}/lib/petsc/conf/alltests.log ;\
257            ln -s $${ALLTESTSLOG} alltests.log ;\
258          fi; \
259          ${OMAKE} allgtest ALLTESTS_MAKEFILE=$${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} MPIEXEC="${MPIEXEC}" DATAFILESPATH=${DATAFILESPATH} VALGRIND=${VALGRIND} 2>&1 | tee $${ALLTESTSLOG};\
260          if [ x${ALLTESTS_CHECK_FAILURES} = xyes -a ${PETSC_PRECISION} != single ]; then \
261            cat $${ALLTESTSLOG} | grep -E '(^not ok|not remade because of errors|^# No tests run)' | wc -l | grep '^[ ]*0$$' > /dev/null; \
262          fi;
263
264allgtests-tap: allgtest-tap
265	+@${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check-test-errors
266
267allgtest-tap: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
268	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test OUTPUT=1
269
270allgtest: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
271	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} -k -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test V=0 2>&1 | grep -E -v '^(ok [^#]*(# SKIP|# TODO|$$)|[A-Za-z][A-Za-z0-9_]*\.(c|F|cxx|F90).$$)'
272
273test:
274	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test
275cleantest:
276	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} cleantest
277
278#********* Rules for cleaning ***************************************************************************************************************************
279
280deletelibs:
281	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
282deletemods:
283	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
284
285allclean:
286	-@${OMAKE} -f gmakefile clean
287
288clean:: allclean
289
290distclean:
291	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
292	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
293          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; \
294	  echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"; \
295	  ${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/ ; \
296        else  \
297	  echo "*** Build files in PETSC_ARCH=${PETSC_ARCH} not found. Skipping delete! ***"; \
298        fi
299
300info:
301	+@${OMAKE} -f gmakefile gmakeinfo
302
303check_usermakefile:
304	-@echo "Testing compile with user makefile"
305	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
306	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
307	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
308	@grep -E "^#define PETSC_USE_FORTRAN_BINDINGS 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
309         if test -s .ftn.log; then \
310          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
311         fi; ${RM} .ftn.log;
312	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
313	-@echo "Completed compile with user makefile"
314
315#********* Rules for running clangformat ************************************************************************************************************
316
317checkgitclean:
318	@if ! git diff --quiet; then \
319           echo "The repository has uncommitted files, cannot run checkclangformat" ;\
320           git status -s --untracked-files=no ;\
321           false;\
322        fi;
323
324# Check that all the source code in the repository satisfies the .clang_format
325checkclangformat: checkclangformatversion checkgitclean clangformat
326	@if ! git diff --quiet; then \
327          printf "The current commit has source code formatting problems\n" ;\
328          if [ -z "${CI_PIPELINE_ID}"  ]; then \
329            printf "Please run 'git diff' to check\n"; \
330            git diff --stat; \
331          else \
332            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch; \
333            git diff --patch-with-stat --color=always | head -1000; \
334            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch` -gt 1000 ]; then \
335              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch (in CI artifacts) for all changes\n"; \
336            fi;\
337          fi;\
338          false;\
339        fi;
340
341# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
342abitest:
343	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
344		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
345		exit 1; \
346	fi;
347	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
348	-@echo "========================================================================================="
349	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
350	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
351	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
352	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
353	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
354	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
355	-@echo "========================================================================================="
356	-@$(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
357
358# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
359abitestcomplete:
360	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
361          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"` ;\
362echo $${OPTIONS} ;\
363        fi ; \
364        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
365          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
366        else \
367          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
368        fi ; \
369        echo "=================================================================================================" ;\
370        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
371        echo "=================================================================================================" ;\
372        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
373          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
374        else \
375          cd $${PETSC_DIR_OLD} ; \
376          git pull ; \
377        fi ; \
378        cd $${PETSC_DIR_OLD} ; \
379        git checkout ${branch} ; \
380        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
381        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
382        cd ${PETSC_DIR} ; \
383        ./configure $${OPTIONS}; \
384        make all test ; \
385        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
386
387# ******** Rules for running Streams benchmark ****************************************************************************************************
388
389mpistreams:
390	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
391
392mpistream:
393	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
394
395openmpstreams:
396	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
397
398openmpstream:
399	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
400
401stream: mpistream
402
403streams: mpistreams
404
405# ********  Rules for generating tag files for Emacs/VIM *******************************************************************************************
406
407alletags:
408	-@${PYTHON} lib/petsc/bin/maint/generateetags.py
409	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
410
411# obtain gtags from https://www.gnu.org/software/global/
412allgtags:
413	-@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 -
414
415# ********* Rules for building "classic" documentation; uses rules also in lib/petsc/conf/rules_doc.mk **************************************************
416
417docs:
418	cd doc; time ${OMAKE_SELF} sphinxhtml
419
420chk_in_petscdir:
421	@if [ ! -f include/petscversion.h ]; then \
422	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
423	  echo " This target should be invoked in top level PETSc source dir!"; \
424	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
425
426chk_loc:
427	@if [ ${LOC}foo = foo ] ; then \
428	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
429	  echo " Please specify LOC variable for eg: make allmanpages LOC=/sandbox/petsc "; \
430	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
431	@${MKDIR} ${LOC}/manualpages
432
433chk_c2html:
434	@if [ ${C2HTML}foo = foo ] ; then \
435          printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR ************************\n" ; \
436          echo "Require c2html for html docs. Please reconfigure with --download-c2html=1"; \
437          printf "******************************************************"${PETSC_TEXT_NORMAL}"\n" ;false; fi
438
439
440# the ACTION=manualpages cannot run in parallel because they all write to the same manualpages.cit file
441hloc=include/petsc/private
442allmanpages: chk_loc deletemanualpages
443	-@echo " /* SUBMANSEC = PetscH */ " > ${hloc}/generated_khash.h
444	-@sed -e 's?<T>?I?g' -e 's?<t>?i?g' -e 's?<KeyType>?PetscInt?g' ${hloc}/hashset.txt >> ${hloc}/generated_khash.h
445	-@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
446	-@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
447	-@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
448	-@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
449	-@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
450	-@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
451	-@${RM} ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
452	-${OMAKE_SELF} ACTION=manualpages tree_src LOC=${LOC}
453	-@sed -e s%man+../%man+manualpages/% ${LOC}/manualpages/manualpages.cit > ${LOC}/manualpages/htmlmap
454	-@cat ${PETSC_DIR}/doc/classic/mpi.www.index >> ${LOC}/manualpages/htmlmap
455	@cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
456	@a=`cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err | wc -l`; test ! $$a -gt 0
457
458#
459#  This code needs to be rewritten in Python to reduce by a factor of 100 the time it takes to run
460#
461c2html: chk_loc  chk_c2html
462	-@if command -v parallel &> /dev/null; then \
463           ls include/makefile src/*/makefile | xargs dirname | parallel -j ${MAKE_TEST_NP} --load ${MAKE_LOAD} 'cd {}; ${OMAKE_SELF} HTMLMAP=${HTMLMAP} LOC=${LOC} PETSC_DIR=${PETSC_DIR} ACTION=html tree' ; \
464         else \
465           ${OMAKE_SELF} HTMLMAP=${HTMLMAP} LOC=${LOC} PETSC_DIR=${PETSC_DIR} ACTION=html tree; \
466        fi
467
468alldocclean: deletemanualpages allcleanhtml
469
470# Deletes man pages (.md version)
471deletemanualpages: chk_loc
472	-@if [ -d ${LOC} -a -d ${LOC}/manualpages ]; then \
473          find ${LOC}/manualpages -type f -name "*.md" -exec ${RM} {} \; ;\
474          ${RM} ${LOC}/manualpages/manualpages.cit ;\
475        fi
476
477allcleanhtml:
478	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} tree
479
480# ********* Rules for checking code coverage *********************************************************************************************
481
482gcov:
483	output_file_base_name=${PETSC_ARCH}-gcovr-report.json; \
484	petsc_arch_dir=${PETSC_DIR}/${PETSC_ARCH}; \
485        tar_file=$${petsc_arch_dir}/$${output_file_base_name}.tar.bz2; \
486	cd $${petsc_arch_dir} && \
487	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} ./obj ./tests ${PETSC_GCOV_OPTIONS} && \
488	${RM} -f $${tar_file} && \
489	tar --bzip2 -cf $${tar_file} -C $${petsc_arch_dir} ./$${output_file_base_name} && \
490	${RM} $${petsc_arch_dir}/$${output_file_base_name}
491
492mergegcov:
493	$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge-branch `lib/petsc/bin/maint/check-merge-branch.sh` --html --xml ${PETSC_GCOV_OPTIONS}
494
495countfortranfunctions:
496	-@cd ${PETSC_DIR}/src/fortran; grep -E '^void' custom/*.c auto/*.c | \
497	cut -d'(' -f1 | tr -s  ' ' | cut -d' ' -f2 | uniq | grep -E -v "(^$$|Petsc)" | \
498	sed "s/_$$//" | sort > /tmp/countfortranfunctions
499
500countcfunctions:
501	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
502	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
503	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
504
505difffortranfunctions: countfortranfunctions countcfunctions
506	-@echo -------------- Functions missing in the fortran interface ---------------------
507	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^<" | cut -d' ' -f2
508	-@echo ----------------- Functions missing in the C interface ------------------------
509	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^>" | cut -d' ' -f2
510	-@${RM}  /tmp/countcfunctions /tmp/countfortranfunctions
511
512checkbadfortranstubs:
513	-@echo "========================================="
514	-@echo "Functions with MPI_Comm as an Argument"
515	-@echo "========================================="
516	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'MPI_Comm' | \
517	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
518	-@echo "========================================="
519	-@echo "Functions with a String as an Argument"
520	-@echo "========================================="
521	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'char \*' | \
522	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
523	-@echo "========================================="
524	-@echo "Functions with Pointers to PETSc Objects as Argument"
525	-@echo "========================================="
526	-@cd ${PETSC_DIR}/src/fortran/auto; \
527	_p_OBJ=`grep _p_ ${PETSC_DIR}/include/*.h | tr -s ' ' | \
528	cut -d' ' -f 3 | tr -s '\012' | grep -v '{' | cut -d'*' -f1 | \
529	sed "s/_p_//g" | tr -s '\012 ' ' *|' ` ; \
530	for OBJ in $$_p_OBJ; do \
531	grep "$$OBJ \*" *.c | tr -s ' ' | tr -s ':' ' ' | \
532	cut -d'(' -f1 | cut -d' ' -f1,3; \
533	done
534
535checkpackagetests:
536	-@echo "Missing package tests"
537	-@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
538	-@echo "Missing download package tests"
539	-@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
540
541check_petsc4py_rst:
542	@${RM} -f petsc4py_rst.log
543	@echo "Checking src/binding/petsc4py/DESCRIPTION.rst"
544	@rst2html src/binding/petsc4py/DESCRIPTION.rst > /dev/null 2> petsc4py_rst.log
545	@if test -s petsc4py_rst.log; then cat petsc4py_rst.log; exit 1; fi
546
547# TODO: checkTestCoverage: that makes sure every tutorial test has at least one test listed in the file, perhaps handled by gmakegentest.py
548# TODO: check for PetscBeginFunctionUser in non-example source
549# TODO: check for __ at start of #define or symbol
550# TODO: checking for missing manual pages
551# TODO: check for incorrect %d
552# TODO: check for double blank lines
553# TODO: check for ill-formed manual pages
554# TODO: check for { on line after for
555# TODO: check for } then else on following line
556# TODO: check for } else { with SETERRQ on following line or if () { with SETERRQ on following line
557
558checkbadSpelling:
559	-@x=`python3 ../bin/extract.py | aspell list | sort -u` ;
560
561updatedatafiles:
562	-@if [ -d "${HOME}/datafiles" ]; then \
563            echo " ** Updating datafiles at ${HOME}/datafiles **"; \
564            cd "${HOME}/datafiles" && git pull -q; fi
565
566.PHONY: info info_h all deletelibs allclean update \
567        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanpages \
568        allcleanhtml  countfortranfunctions \
569        start_configure configure_petsc configure_clean matlabbin install
570