xref: /petsc/makefile (revision edb0e59d3c097acd4a4005a4e51d4daa5c739255)
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, run after ./configure
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 ${PETSC_POST_BUILDS}
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
83fortranbindings: deletefortranbindings
84	@${PYTHON} config/utils/generatefortranbindings.py --petsc-dir=${PETSC_DIR} --petsc-arch=${PETSC_ARCH}
85
86deleteshared:
87	@for LIBNAME in ${SHLIBS}; \
88	do \
89	   if [ -d ${INSTALL_LIB_DIR}/$${LIBNAME}$${LIB_NAME_SUFFIX}.dylib.dSYM ]; then \
90             echo ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}$${LIB_NAME_SUFFIX}.dylib.dSYM; \
91	     ${RM} -rf ${INSTALL_LIB_DIR}/$${LIBNAME}$${LIB_NAME_SUFFIX}.dylib.dSYM; \
92	   fi; \
93           echo ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}$${LIB_NAME_SUFFIX}.${SL_LINKER_SUFFIX}; \
94           ${RM} ${INSTALL_LIB_DIR}/$${LIBNAME}$${LIB_NAME_SUFFIX}.${SL_LINKER_SUFFIX}; \
95	done
96	@if [ -f ${INSTALL_LIB_DIR}/so_locations ]; then \
97          echo ${RM} ${INSTALL_LIB_DIR}/so_locations; \
98          ${RM} ${INSTALL_LIB_DIR}/so_locations; \
99	fi
100
101deletefortranbindings:
102	-@find src -type d -name ftn-auto* | xargs rm -rf
103	-@if [ -n "${PETSC_ARCH}" ] && [ -d ${PETSC_ARCH} ] && [ -d ${PETSC_ARCH}/src ]; then \
104          find ${PETSC_ARCH}/src -type d -name ftn-auto* | xargs rm -rf ;\
105        fi
106
107reconfigure: allclean
108	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
109
110chkopts:
111	-@echo "Warning: chkopts target is deprecated and can be removed from user makefiles"
112
113gnumake:
114	+@echo "make gnumake is deprecated, use make libs"
115	+@make libs
116
117# ********  Rules for make check ****************************************************************************************************************************
118
119RUN_TEST = ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff
120
121check: check_body ${PETSC_POST_CHECKS}
122
123check_install: check
124
125check_body:
126	-@echo "Running PETSc check examples to verify correct installation"
127	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
128	@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
129           echo "Running with batch filesystem, cannot run make check"; \
130        elif [ "${MPIEXEC}" = "/bin/false" ]; then \
131           echo "*mpiexec not found*. cannot run make check"; \
132        else \
133          ${RM} -f check_error;\
134          ${RUN_TEST} OMP_NUM_THREADS=1 PETSC_OPTIONS="${EXTRA_OPTIONS} ${PETSC_TEST_OPTIONS}" PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" check_build 2>&1 | tee ./${PETSC_ARCH}/lib/petsc/conf/check.log; \
135          if [ -f check_error ]; then \
136            echo "Error while running make check"; \
137            ${RM} -f check_error;\
138            exit 1; \
139          fi; \
140          ${RM} -f check_error;\
141        fi;
142
143check_build:
144	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} clean-legacy
145	+@cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19
146	+@if [ ! "${MPI_IS_MPIUNI}" ]; then cd src/snes/tutorials >/dev/null; ${RUN_TEST} testex19_mpi; fi
147	+@if [ "`grep -E '^#define PETSC_HAVE_HYPRE 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_HYPRE 1" ] && [ "${PETSC_SCALAR}" = "real" ]; then \
148          if [ "`grep -E '^#define PETSC_HAVE_CUDA 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_CUDA 1" ]; then HYPRE_TEST=runex19_hypre_cuda; \
149          elif [ "`grep -E '^#define PETSC_HAVE_HIP 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_HIP 1" ]; then HYPRE_TEST=runex19_hypre_hip; \
150          else HYPRE_TEST=runex19_hypre; fi; \
151          cd src/snes/tutorials >/dev/null; ${RUN_TEST} $${HYPRE_TEST}; \
152        fi;
153	+@if [ "`grep -E '^#define PETSC_HAVE_CUDA 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_CUDA 1" ]; then \
154          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_cuda; \
155        fi;
156	+@if [ "`grep -E '^#define PETSC_HAVE_HIP 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_HIP 1" ]; then \
157          cd src/snes/tutorials >/dev/null; ${RUN_TEST} runex19_hip; \
158        fi;
159	+@if [ "${MPI_IS_MPIUNI}" = "" ]; then \
160          cd src/snes/tutorials >/dev/null; \
161          if [ "`grep -E '^#define PETSC_HAVE_KOKKOS_KERNELS 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_KOKKOS_KERNELS 1" ] && [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ]; then \
162            ${RUN_TEST} runex3k_kokkos; \
163          fi;\
164          if [ "`grep -E '^#define PETSC_HAVE_MUMPS 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_MUMPS 1" ]; then \
165             ${RUN_TEST} runex19_fieldsplit_mumps; \
166          fi;\
167          if [ "`grep -E '^#define PETSC_HAVE_SUITESPARSE 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_SUITESPARSE 1" ]; then \
168             ${RUN_TEST} runex19_suitesparse; \
169          fi;\
170          if [ "`grep -E '^#define PETSC_HAVE_SUPERLU_DIST 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_SUPERLU_DIST 1" ]; then \
171            ${RUN_TEST} runex19_superlu_dist; \
172          fi;\
173          if [ "`grep -E '^#define PETSC_HAVE_ML 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_ML 1" ] || [ "`grep -E '^#define PETSC_HAVE_TRILINOS 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_TRILINOS 1" ]; then \
174            ${RUN_TEST} runex19_ml; \
175          fi; \
176	  ${RUN_TEST} clean-legacy; \
177          cd - > /dev/null; \
178          if [ "`grep -E '^#define PETSC_HAVE_AMREX 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_AMREX 1" ] && [ "`grep -E '^#define PETSC_HAVE_CUDA 1' ${PETSCCONF_H}`" != "#define PETSC_HAVE_CUDA 1" ]; 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 [ "`grep -E '^#define PETSC_HAVE_HDF5 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_HDF5 1" ]; 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	+@if [ "`grep -E '^#define PETSC_USE_FORTRAN_BINDINGS 1' ${PETSCCONF_H}`" = "#define PETSC_USE_FORTRAN_BINDINGS 1" ]; then \
207           cd src/snes/tutorials >/dev/null; \
208           ${RUN_TEST} clean-legacy; \
209           ${RUN_TEST} testex5f; \
210           ${RUN_TEST} clean-legacy; \
211         fi;
212	+@if [ "`grep -E '^#define PETSC_HAVE_MATLAB 1' ${PETSCCONF_H}`" = "#define PETSC_HAVE_MATLAB 1" ]; then \
213           ${RUN_TEST} clean-legacy; \
214           ${RUN_TEST} testex31; \
215           ${RUN_TEST} clean-legacy; \
216          fi;
217	-@echo "Completed PETSc check examples"
218
219# ********* Rules for make install *******************************************************************************************************************
220
221install:
222	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
223	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
224
225# A smaller install with fewer extras
226install-lib:
227	@${PYTHON} ./config/install.py -destDir=${DESTDIR} -no-examples
228	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=$@ install-builtafterpetsc
229
230install-builtafterpetsc:
231	@if [ "${PETSC_POST_INSTALLS}" != "" ]; then ${OMAKE_SELF} PETSC_DIR=${PETSC_DIR} PETSC_INSTALL=${PETSC_INSTALL} ${PETSC_POST_INSTALLS}; fi
232	@echo "*** Install of PETSc (and any other packages) complete ***"
233
234# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
235dist:
236	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
237
238# ******** Rules for running the full test suite ********************************************************************************************************
239
240TESTMODE = testexamples
241ALLTESTS_CHECK_FAILURES = no
242ALLTESTS_MAKEFILE = ${PETSC_DIR}/gmakefile.test
243VALGRIND=0
244alltests: chk_in_petscdir ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
245	-@${RM} -rf ${PETSC_ARCH}/lib/petsc/conf/alltests.log alltests.log
246	+@if [ -f ${PETSC_DIR}/share/petsc/examples/gmakefile.test ] ; then \
247            ALLTESTS_MAKEFILE=${PETSC_DIR}/share/petsc/examples/gmakefile.test ; \
248            ALLTESTSLOG=alltests.log ;\
249          else \
250            ALLTESTS_MAKEFILE=${PETSC_DIR}/gmakefile.test; \
251            ALLTESTSLOG=${PETSC_ARCH}/lib/petsc/conf/alltests.log ;\
252            ln -s $${ALLTESTSLOG} alltests.log ;\
253          fi; \
254          ${OMAKE} allgtest ALLTESTS_MAKEFILE=$${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} MPIEXEC="${MPIEXEC}" DATAFILESPATH=${DATAFILESPATH} VALGRIND=${VALGRIND} 2>&1 | tee $${ALLTESTSLOG};\
255          if [ x${ALLTESTS_CHECK_FAILURES} = xyes -a ${PETSC_PRECISION} != single ]; then \
256            cat $${ALLTESTSLOG} | grep -E '(^not ok|not remade because of errors|^# No tests run)' | wc -l | grep '^[ ]*0$$' > /dev/null; \
257          fi;
258
259allgtests-tap: allgtest-tap
260	+@${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check-test-errors
261
262allgtest-tap: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
263	+@MAKEFLAGS="-j$(MAKE_TEST_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)" ${OMAKE} ${MAKE_SHUFFLE_FLG} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test OUTPUT=1
264
265allgtest: ${PETSC_DIR}/${PETSC_ARCH}/tests/testfiles
266	+@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).$$)'
267
268test:
269	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} test
270cleantest:
271	+${OMAKE} -f ${ALLTESTS_MAKEFILE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} cleantest
272
273#********* Rules for cleaning ***************************************************************************************************************************
274
275deletelibs:
276	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
277deletemods:
278	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
279
280allclean:
281	-@${OMAKE} -f gmakefile clean
282
283clean:: allclean
284
285distclean:
286	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
287	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
288          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; \
289	  echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"; \
290	  ${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/ ; \
291        else  \
292	  echo "*** Build files in PETSC_ARCH=${PETSC_ARCH} not found. Skipping delete! ***"; \
293        fi
294
295info:
296	+@${OMAKE} -f gmakefile gmakeinfo
297
298check_usermakefile:
299	-@echo "Testing compile with user makefile"
300	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
301	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
302	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
303	@grep -E "^#define PETSC_USE_FORTRAN_BINDINGS 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
304         if test -s .ftn.log; then \
305          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
306         fi; ${RM} .ftn.log;
307	@cd src/snes/tutorials; ${RUN_TEST} clean-legacy
308	-@echo "Completed compile with user makefile"
309
310#********* Rules for formating Fortran source **********************************************************************************************
311
312# pip install fprettify
313fprettify:
314	@git ls-files "*.[hF]90" | xargs fprettify --indent 2 --line-length 1000 --whitespace 2 --whitespace-type F --enable-replacements --c-relations
315
316# git clone https://github.com/louoberto/fortify.git && cd fortify && export PATH=$PATH:$(pwd)/source
317fortify:
318	@files=`git ls-files "*.[hF]90"`; for i in $${files}; do fortify --tab_length 2 --lowercasing F $${i}; done
319
320#********* Rules for running clangformat ************************************************************************************************************
321
322checkgitclean:
323	@if ! git diff --quiet; then \
324           echo "The repository has uncommitted files, cannot run checkclangformat" ;\
325           git status -s --untracked-files=no ;\
326           false;\
327        fi;
328
329# Check that all the C/C++ source code in the repository satisfies the .clang_format
330checkclangformat: checkclangformatversion checkgitclean clangformat
331	@if ! git diff --quiet; then \
332          printf "The current commit has C/C++ source code formatting problems\n" ;\
333          if [ -z "${CI_PIPELINE_ID}"  ]; then \
334            printf "Please run 'git diff' to check\n"; \
335            git diff --stat; \
336          else \
337            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch; \
338            git diff --patch-with-stat --color=always | head -1000; \
339            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch` -gt 1000 ]; then \
340              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkclangformat.patch (in CI artifacts) for all changes\n"; \
341            fi;\
342          fi;\
343          false;\
344        fi;
345
346# Check that all the Fortran source code in the repository satisfies the fprettify format
347checkfprettifyformat: checkgitclean fprettify
348	@if ! git diff --quiet; then \
349          printf "The current commit has Fortra source code formatting problems\n" ;\
350          if [ -z "${CI_PIPELINE_ID}"  ]; then \
351            printf "Please run 'git diff' to check\n"; \
352            git diff --stat; \
353          else \
354            git diff --patch-with-stat >  ${PETSC_ARCH}/lib/petsc/conf/checkfprettifyformat.patch; \
355            git diff --patch-with-stat --color=always | head -1000; \
356            if [ `wc -l < ${PETSC_ARCH}/lib/petsc/conf/checkfprettifyformat.patch` -gt 1000 ]; then \
357              printf "The diff has been trimmed, check ${PETSC_ARCH}/lib/petsc/conf/checkfprettifyformat.patch (in CI artifacts) for all changes\n"; \
358            fi;\
359          fi;\
360          false;\
361        fi;
362
363# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
364abitest:
365	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
366		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
367		exit 1; \
368	fi;
369	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
370	-@echo "========================================================================================="
371	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
372	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
373	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
374	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
375	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
376	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
377	-@echo "========================================================================================="
378	-@$(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
379
380# Run fortitude Fortran linter; pip install fortitude-lint; fortitude does not support using the preprocessor so it is of only limited utility
381fortitude:
382	-@fortitude check --line-length 1000 --ignore C003,C121,S241 --verbose --fix --preview
383
384# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
385abitestcomplete:
386	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
387          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"` ;\
388echo $${OPTIONS} ;\
389        fi ; \
390        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
391          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
392        else \
393          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
394        fi ; \
395        echo "=================================================================================================" ;\
396        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
397        echo "=================================================================================================" ;\
398        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
399          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
400        else \
401          cd $${PETSC_DIR_OLD} ; \
402          git pull ; \
403        fi ; \
404        cd $${PETSC_DIR_OLD} ; \
405        git checkout ${branch} ; \
406        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
407        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
408        cd ${PETSC_DIR} ; \
409        ./configure $${OPTIONS}; \
410        make all test ; \
411        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
412
413# ******** Rules for running Streams benchmark ****************************************************************************************************
414
415mpistreams:
416	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
417
418mpistream:
419	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
420
421openmpstreams:
422	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
423
424openmpstream:
425	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
426
427stream: mpistream
428
429streams: mpistreams
430
431# ********  Rules for generating tag files for Emacs/VIM *******************************************************************************************
432
433alletags: etags
434
435etags:
436	-@${PYTHON} lib/petsc/bin/maint/generateetags.py && ${CP} TAGS ${PETSC_ARCH}/
437	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
438
439# obtain gtags from https://www.gnu.org/software/global/
440allgtags:
441	-@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 -
442
443# ********* Rules for building "classic" documentation; uses rules also in lib/petsc/conf/rules_doc.mk **************************************************
444
445docs:
446	cd doc; ${OMAKE_SELF} docs
447
448chk_in_petscdir:
449	@if [ ! -f include/petscversion.h ]; then \
450	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
451	  echo " This target should be invoked in top level PETSc source dir!"; \
452	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
453
454chk_loc:
455	@if [ ${LOC}foo = foo ] ; then \
456	  printf ${PETSC_TEXT_HILIGHT}"*********************** ERROR **********************************************\n" ; \
457	  echo " Please specify LOC variable for eg: make allmanpages LOC=/sandbox/petsc "; \
458	  printf "****************************************************************************"${PETSC_TEXT_NORMAL}"\n" ;  false; fi
459	@${MKDIR} ${LOC}/manualpages
460
461alldocclean: deletemanualpages allcleanhtml
462
463# Deletes man pages (.md version)
464deletemanualpages: chk_loc
465	-@if [ -d ${LOC} -a -d ${LOC}/manualpages ]; then \
466          find ${LOC}/manualpages -type f -name "*.md" -exec ${RM} {} \; ;\
467          ${RM} ${LOC}/manualpages/manualpages.cit ;\
468        fi
469
470allcleanhtml:
471	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} tree
472
473# ********* Rules for checking code coverage *********************************************************************************************
474
475gcov:
476	output_file_base_name=${PETSC_ARCH}-gcovr-report.json; \
477	petsc_arch_dir=${PETSC_DIR}/${PETSC_ARCH}; \
478        tar_file=$${petsc_arch_dir}/$${output_file_base_name}.tar.bz2; \
479	cd $${petsc_arch_dir} && \
480	gcovr --json --output $${petsc_arch_dir}/$${output_file_base_name} --exclude '.*/ftn-auto/.*' --exclude '.*/petscsys.h' --exclude-lines-by-pattern '^\s*SETERR.*' --exclude-throw-branches --exclude-unreachable-branches --gcov-ignore-parse-errors -j 8 --gcov-executable "${PETSC_COVERAGE_EXEC}" --root ${PETSC_DIR} ./obj ./tests ${PETSC_GCOV_OPTIONS} && \
481	${RM} -f $${tar_file} && \
482	tar --bzip2 -cf $${tar_file} -C $${petsc_arch_dir} ./$${output_file_base_name} && \
483	${RM} $${petsc_arch_dir}/$${output_file_base_name}
484
485mergegcov:
486	$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge-branch `lib/petsc/bin/maint/check-merge-branch.sh` --html --xml ${PETSC_GCOV_OPTIONS}
487
488countcfunctions:
489	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
490	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
491	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
492
493checkpackagetests:
494	-@echo "Missing package tests"
495	-@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
496	-@echo "Missing download package tests"
497	-@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
498
499check_petsc4py_rst:
500	@${RM} -f petsc4py_rst.log
501	@echo "Checking src/binding/petsc4py/DESCRIPTION.rst"
502	@rst2html src/binding/petsc4py/DESCRIPTION.rst > /dev/null 2> petsc4py_rst.log
503	@if test -s petsc4py_rst.log; then cat petsc4py_rst.log; exit 1; fi
504
505# TODO: checkTestCoverage: that makes sure every tutorial test has at least one test listed in the file, perhaps handled by gmakegentest.py
506# TODO: check for PetscBeginFunctionUser in non-example source
507# TODO: check for __ at start of #define or symbol
508# TODO: checking for missing manual pages
509# TODO: check for incorrect %d
510# TODO: check for double blank lines
511# TODO: check for ill-formed manual pages
512# TODO: check for { on line after for
513# TODO: check for } then else on following line
514# TODO: check for } else { with SETERRQ on following line or if () { with SETERRQ on following line
515
516checkbadSpelling:
517	-@x=`python3 ../bin/extract.py | aspell list | sort -u` ;
518
519updatedatafiles:
520	-@if [ -d "${HOME}/datafiles" ]; then \
521            echo " ** Updating datafiles at ${HOME}/datafiles **"; \
522            cd "${HOME}/datafiles" && git pull -q; fi
523
524.PHONY: info info_h all deletelibs allclean update \
525        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanpages \
526        allcleanhtml \
527        start_configure configure_petsc configure_clean matlabbin install
528