xref: /petsc/makefile (revision a2d3a777ecd762f0bf20196f73eeaa0a40a403ea)
1#
2# This is the makefile for compiling PETSc. See
3# http://www.mcs.anl.gov/petsc/documentation/installation.html for directions on installing PETSc.
4# See also conf for additional commands.
5#
6ALL: all
7LOCDIR	 = ./
8DIRS	 = src include tutorials interfaces share/petsc/matlab
9CFLAGS	 =
10FFLAGS	 =
11CPPFLAGS =
12FPPFLAGS =
13
14# next line defines PETSC_DIR and PETSC_ARCH if they are not set
15include ././${PETSC_ARCH}/lib/petsc/conf/petscvariables
16include ${PETSC_DIR}/lib/petsc/conf/variables
17include ${PETSC_DIR}/lib/petsc/conf/rules
18include ${PETSC_DIR}/lib/petsc/conf/test.common
19
20# This makefile contains a lot of PHONY targets with improperly specified prerequisites
21# where correct execution instead depends on the targets being processed in the correct
22# order.  This is gross, but this makefile doesn't really do any work.  Sub-makes still
23# benefit from parallelism.
24.NOTPARALLEL:
25
26OMAKE_SELF = $(OMAKE) -f makefile
27OMAKE_SELF_PRINTDIR = $(OMAKE_PRINTDIR) -f makefile
28
29#
30# Basic targets to build PETSc libraries.
31#
32all:
33	+@${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} chk_petscdir chk_upgrade | tee ${PETSC_ARCH}/lib/petsc/conf/make.log
34	@ln -sf ${PETSC_ARCH}/lib/petsc/conf/make.log make.log
35	+@${OMAKE_SELF_PRINTDIR} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} all-local 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;
36	@egrep '(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
37	@egrep -i "( error | error: |no such file or directory)" ${PETSC_ARCH}/lib/petsc/conf/make.log | tee ${PETSC_ARCH}/lib/petsc/conf/error.log > /dev/null
38	+@if test -s ${PETSC_ARCH}/lib/petsc/conf/memoryerror.log; then \
39           printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
40           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; \
41           printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
42         elif test -s ${PETSC_ARCH}/lib/petsc/conf/error.log; then \
43           printf ${PETSC_TEXT_HILIGHT}"**************************ERROR*************************************\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
44           echo "  Error during compile, check ${PETSC_ARCH}/lib/petsc/conf/make.log" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log; \
45           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;\
46           printf "********************************************************************"${PETSC_TEXT_NORMAL}"\n" 2>&1 | tee -a ${PETSC_ARCH}/lib/petsc/conf/make.log;\
47	 else \
48	  ${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 ;\
49        fi #solaris make likes to print the whole command that gave error. So split this up into the smallest chunk below
50	@echo "Finishing make run at `date +'%a, %d %b %Y %H:%M:%S %z'`" >> ${PETSC_ARCH}/lib/petsc/conf/make.log
51	@if test -s ${PETSC_ARCH}/lib/petsc/conf/error.log; then exit 1; fi
52
53all-local: info libs matlabbin petsc4py-build libmesh-build mfem-build slepc-build hpddm-build amrex-build bamg-build
54
55#
56# Prints information about the system and version of PETSc being compiled
57#
58info:
59	-@echo "=========================================="
60	-@echo " "
61	-@echo "See documentation/faq.html and documentation/bugreporting.html"
62	-@echo "for help with installation problems.  Please send EVERYTHING"
63	-@echo "printed out below when reporting problems.  Please check the"
64	-@echo "mailing list archives and consider subscribing."
65	-@echo " "
66	-@echo "  https://petsc.org/release/community/mailing/"
67	-@echo " "
68	-@echo "=========================================="
69	-@echo Starting make run on `hostname` at `date +'%a, %d %b %Y %H:%M:%S %z'`
70	-@echo Machine characteristics: `uname -a`
71	-@echo "-----------------------------------------"
72	-@echo "Using PETSc directory: ${PETSC_DIR}"
73	-@echo "Using PETSc arch: ${PETSC_ARCH}"
74	-@echo "-----------------------------------------"
75	-@grep "define PETSC_VERSION" ${PETSC_DIR}/include/petscversion.h | ${SED} "s/........//"
76	-@echo "-----------------------------------------"
77	-@echo "Using configure Options: ${CONFIGURE_OPTIONS}"
78	-@echo "Using configuration flags:"
79	-@grep "\#define " ${PETSCCONF_H}
80	-@echo "-----------------------------------------"
81	-@echo "Using C compile: ${PETSC_CCOMPILE_SINGLE}"
82	-@if [  "${MPICC_SHOW}" != "" ]; then \
83             printf  "mpicc -show: %b\n" "${MPICC_SHOW}";\
84          fi; \
85        printf  "C compiler version: %b\n" "${C_VERSION}"; \
86        if [ "${CXX}" != "" ]; then \
87        echo "Using C++ compile: ${PETSC_CXXCOMPILE_SINGLE}";\
88        if [ "${MPICXX_SHOW}" != "" ]; then \
89               printf "mpicxx -show: %b\n" "${MPICXX_SHOW}"; \
90            fi;\
91            printf  "C++ compiler version: %b\n" "${Cxx_VERSION}"; \
92          fi
93	-@if [ "${FC}" != "" ]; then \
94	   echo "Using Fortran compile: ${PETSC_FCOMPILE_SINGLE}";\
95           if [ "${MPIFC_SHOW}" != "" ]; then \
96             printf "mpif90 -show: %b\n" "${MPIFC_SHOW}"; \
97           fi; \
98             printf  "Fortran compiler version: %b\n" "${FC_VERSION}"; \
99         fi
100	-@if [ "${CUDAC}" != "" ]; then \
101	   echo "Using CUDA compile: ${PETSC_CUCOMPILE_SINGLE}";\
102         fi
103	-@if [ "${CLANGUAGE}" = "CXX" ]; then \
104           echo "Using C++ compiler to compile PETSc";\
105        fi
106	-@echo "-----------------------------------------"
107	-@echo "Using C/C++ linker: ${PCC_LINKER}"
108	-@echo "Using C/C++ flags: ${PCC_LINKER_FLAGS}"
109	-@if [ "${FC}" != "" ]; then \
110	   echo "Using Fortran linker: ${FC_LINKER}";\
111	   echo "Using Fortran flags: ${FC_LINKER_FLAGS}";\
112         fi
113	-@echo "-----------------------------------------"
114	-@echo "Using system modules: ${LOADEDMODULES}"
115	-@if [ "${MPI_IS_MPIUNI}" = "1" ]; then \
116           echo Using mpi.h: mpiuni; \
117        else \
118           TESTDIR=`mktemp -q -d -t petscmpi-XXXXXXXX` && \
119           echo '#include <mpi.h>' > $${TESTDIR}/mpitest.c && \
120           BUF=`${CPP} ${PETSC_CPPFLAGS} ${PETSC_CC_INCLUDES} $${TESTDIR}/mpitest.c |grep 'mpi\.h' | ( head -1 ; cat > /dev/null )` && \
121           echo Using mpi.h: $${BUF}; ${RM} -rf $${TESTDIR}; \
122        fi
123	-@echo "-----------------------------------------"
124	-@echo "Using libraries: ${PETSC_LIB}"
125	-@echo "------------------------------------------"
126	-@echo "Using mpiexec: ${MPIEXEC}"
127	-@echo "------------------------------------------"
128	-@echo "Using MAKE: $(MAKE)"
129	-@echo "Using MAKEFLAGS: -j$(MAKE_NP) -l$(MAKE_LOAD) $(MAKEFLAGS)"
130	-@echo "=========================================="
131
132#
133# Build MatLab binaries
134#
135matlabbin:
136	-@if [ "${MATLAB_MEX}" != "" -a "${MATLAB_SOCKET}" != "" -a "${PETSC_SCALAR}" = "real" -a "${PETSC_PRECISION}" = "double" ]; then \
137          echo "BEGINNING TO COMPILE MATLAB INTERFACE"; \
138            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc; fi; \
139            if [ ! -d "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab" ] ; then ${MKDIR}  ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/matlab; fi; \
140            cd src/sys/classes/viewer/impls/socket/matlab && ${OMAKE_SELF} matlabcodes PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR}; \
141            echo "========================================="; \
142        fi
143#
144# Builds PETSc check examples for a given architecture
145#
146check_install: check
147check:
148	-+@${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} check_build 2>&1 | tee ./${PETSC_ARCH}/lib/petsc/conf/check.log
149checkx:
150	-@${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} checkx_build 2>&1 | tee ./${PETSC_ARCH}/lib/petsc/conf/checkx.log
151check_build:
152	-@echo "Running check examples to verify correct installation"
153	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
154	+@cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy
155	+@cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testex19
156	+@if [ "${HYPRE_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ] &&  [ "${PETSC_SCALAR}" = "real" ]; then \
157          if [ "${CUDA_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_cuda; \
158          elif [ "${HIP_LIB}" != "" ]; then HYPRE_TEST=runex19_hypre_hip; \
159          else HYPRE_TEST=runex19_hypre; \
160          fi; \
161          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff $${HYPRE_TEST}; \
162	 fi;
163	+@if [ "${CUDA_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
164          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex19_cuda; \
165         fi;
166	+@if [ "${KOKKOS_KERNELS_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ] &&  [ "${PETSC_SCALAR}" = "real" ] && [ "${PETSC_PRECISION}" = "double" ] && [ "${MPI_IS_MPIUNI}" = "" ]; then \
167          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex3k_kokkos; \
168         fi;
169	+@if [ "${MUMPS_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
170          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex19_fieldsplit_mumps; \
171         fi;
172	+@if [ "${SUPERLU_DIST_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
173          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex19_superlu_dist; \
174         fi;
175	+@if [ "${HDF5_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
176          cd src/vec/vec/tests >/dev/null; ${OMAKE_SELF}  PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex47; \
177         fi;
178	+@if [ "${AMREX_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
179           echo "Running testamres examples 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; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy;\
182           ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testamrex;\
183         fi;
184	+@if ( [ "${ML_LIB}" != "" ] ||  [ "${TRILINOS_LIB}" != "" ] ) && [ "${PETSC_WITH_BATCH}" = "" ]; then \
185          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex19_ml; \
186         fi;
187	+@if [ "${SUITESPARSE_LIB}" != "" ] && [ "${PETSC_WITH_BATCH}" = "" ]; then \
188          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} DIFF=${PETSC_DIR}/lib/petsc/bin/petscdiff runex19_suitesparse; \
189         fi;
190	+@cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} ex19.rm
191	+@if [ "${MPI4PY}" = "yes" ]; then \
192          cd src/sys/tests >/dev/null; \
193          ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testex55; \
194         fi;
195	+@if [ "${PETSC4PY}" = "yes" ]; then \
196          cd src/ksp/ksp/tutorials >/dev/null; \
197          ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy; \
198          ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testex100; \
199          ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy; \
200         fi;
201	+@egrep "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
202         if test -s .ftn.log; then \
203          cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testex5f; \
204         fi; ${RM} .ftn.log;
205	+@egrep "^#define PETSC_HAVE_MATLAB_ENGINE 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
206         if test -s .ftn.log; then \
207          cd src/vec/vec/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testex31; \
208         fi; ${RM} .ftn.log;
209	+@cd src/snes/tutorials >/dev/null; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy
210	-@echo "Completed test examples"
211checkx_build:
212	-@echo "Running graphics check example to verify correct X11 installation"
213	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
214	@cd src/snes/tutorials; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy
215	@cd src/snes/tutorials; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} testxex19
216	@cd src/snes/tutorials; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy
217	-@echo "Completed graphics check example"
218check_usermakefile:
219	-@echo "Testing compile with user makefile"
220	-@echo "Using PETSC_DIR=${PETSC_DIR} and PETSC_ARCH=${PETSC_ARCH}"
221	@cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex19
222	@egrep "^#define PETSC_HAVE_FORTRAN 1" ${PETSCCONF_H} | tee .ftn.log > /dev/null; \
223         if test -s .ftn.log; then \
224          cd src/snes/tutorials; ${OMAKE} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} -f ${PETSC_DIR}/share/petsc/Makefile.user ex5f; \
225         fi; ${RM} .ftn.log;
226	@cd src/snes/tutorials; ${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH}  PETSC_DIR=${PETSC_DIR} clean-legacy
227	-@echo "Completed compile with user makefile"
228
229# Compare ABI/API of two versions of PETSc library with the old one defined by PETSC_{DIR,ARCH}_ABI_OLD
230abitest:
231	@if [ "${PETSC_DIR_ABI_OLD}" = "" ] || [ "${PETSC_ARCH_ABI_OLD}" = "" ]; \
232		then printf "You must set environment variables PETSC_DIR_ABI_OLD and PETSC_ARCH_ABI_OLD to run abitest\n"; \
233		exit 1; \
234	fi;
235	-@echo "Comparing ABI/API of the following two PETSc versions (you must have already configured and built them using GCC and with -g):"
236	-@echo "========================================================================================="
237	-@echo "    Old: PETSC_DIR_ABI_OLD  = ${PETSC_DIR_ABI_OLD}"
238	-@echo "         PETSC_ARCH_ABI_OLD = ${PETSC_ARCH_ABI_OLD}"
239	-@pushd ${PETSC_DIR_ABI_OLD} >> /dev/null ; echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
240	-@echo "    New: PETSC_DIR          = ${PETSC_DIR}"
241	-@echo "         PETSC_ARCH         = ${PETSC_ARCH}"
242	-@echo "         Branch             = "`git rev-parse --abbrev-ref HEAD`
243	-@echo "========================================================================================="
244	-@$(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
245
246# Compare ABI/API of current PETSC_ARCH/PETSC_DIR with a previous branch
247abitestcomplete:
248	-@if [[ -f "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/configure.log" ]]; then \
249          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"` ;\
250echo $${OPTIONS} ;\
251        fi ; \
252        if [[ "${PETSC_DIR_ABI_OLD}" != "" ]]; then \
253          PETSC_DIR_OLD=${PETSC_DIR_ABI_OLD}; \
254        else \
255          PETSC_DIR_OLD=${PETSC_DIR}/../petsc-abi; \
256        fi ; \
257        echo "=================================================================================================" ;\
258        echo "Doing ABI/API comparison between" ${branch} " and " `git rev-parse --abbrev-ref HEAD` "using " $${OPTIONS} ;\
259        echo "=================================================================================================" ;\
260        if [[ ! -d $${PETSC_DIR_OLD} ]]; then \
261          git clone ${PETSC_DIR} $${PETSC_DIR_OLD} ; \
262        else \
263          cd $${PETSC_DIR_OLD} ; \
264          git pull ; \
265        fi ; \
266        cd $${PETSC_DIR_OLD} ; \
267        git checkout ${branch} ; \
268        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` ./configure $${OPTIONS} ; \
269        PETSC_DIR=`pwd` PETSC_ARCH=arch-branch-`git rev-parse ${branch}` make all test ; \
270        cd ${PETSC_DIR} ; \
271        ./configure $${OPTIONS}; \
272        make all test ; \
273        PETSC_DIR_ABI_OLD=$${PETSC_DIR_OLD} PETSC_ARCH_ABI_OLD=arch-branch-`git rev-parse ${branch}` make abitest
274
275# Deletes PETSc libraries
276deletelibs:
277	-${RM} -rf ${PETSC_LIB_DIR}/libpetsc*.*
278deletemods:
279	-${RM} -f ${PETSC_DIR}/${PETSC_ARCH}/include/petsc*.mod
280
281allclean:
282	-@${OMAKE} -f gmakefile clean
283
284clean:: allclean
285
286distclean: chk_petscdir
287	@if [ -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ]; then \
288	  echo "*** Preserving ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py in ${PETSC_DIR} ***"; \
289          mv -f ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py ${PETSC_DIR}/; fi
290	@echo "*** Deleting all build files in ${PETSC_DIR}/${PETSC_ARCH} ***"
291	-${RM} -rf ${PETSC_DIR}/${PETSC_ARCH}/
292
293
294#
295reconfigure: allclean
296	@unset MAKEFLAGS && ${PYTHON} ${PETSC_ARCH}/lib/petsc/conf/reconfigure-${PETSC_ARCH}.py
297#
298install:
299	@${PYTHON} ./config/install.py -destDir=${DESTDIR}
300	+${OMAKE_SELF} PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} petsc4py-install libmesh-install mfem-install slepc-install hpddm-install amrex-install bamg-install
301
302mpistreams:
303	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistreams
304
305mpistream:
306	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} mpistream
307
308openmpstreams:
309	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstreams
310
311openmpstream:
312	+@cd src/benchmarks/streams; ${OMAKE_SELF} PATH="${PETSC_DIR}/${PETSC_ARCH}/lib:${PATH}" PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} openmpstream
313
314# for legacy reasons
315stream: mpistream
316
317streams: mpistreams
318
319# ------------------------------------------------------------------
320#
321# All remaining actions are intended for PETSc developers only.
322# PETSc users should not generally need to use these commands.
323#
324#  See the users manual for how the tags files may be used from Emacs and Vi/Vim
325#
326alletags:
327	-@${PYTHON} lib/petsc/bin/maint/generateetags.py
328	-@find config -type f -name "*.py" |grep -v SCCS | xargs etags -o TAGS_PYTHON
329
330# obtain gtags from https://www.gnu.org/software/global/
331allgtags:
332	-@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 -
333
334allfortranstubs:
335	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
336	@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py ${BFORT}  ${VERBOSE}
337	-@${PYTHON} lib/petsc/bin/maint/generatefortranstubs.py -merge  ${VERBOSE}
338	-@${RM} -rf ${PETSC_ARCH}/include/petsc/finclude/ftn-auto/*-tmpdir
339deletefortranstubs:
340	-@find . -type d -name ftn-auto | xargs rm -rf
341
342# Builds all the documentation - should be done every night
343alldoc: allcite sphinx-docs-all alldoc1 alldoc2 docsetdate
344
345# Build just citations
346allcite: chk_loc deletemanualpages
347	-${OMAKE_SELF} ACTION=manualpages_buildcite tree_basic LOC=${LOC}
348	-@sed -e s%man+../%man+manualpages/% ${LOC}/docs/manualpages/manualpages.cit > ${LOC}/docs/manualpages/htmlmap
349	-@cat ${PETSC_DIR}/src/docs/mpi.www.index >> ${LOC}/docs/manualpages/htmlmap
350
351# Build just manual pages + prerequisites
352allmanpages: chk_loc allcite
353	-${RM} ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err
354	-${OMAKE_SELF} ACTION=manualpages tree_basic LOC=${LOC}
355	-a=`cat ${PETSC_DIR}/${PETSC_ARCH}/manualpages.err | wc -l`; test ! $$a -gt 0
356
357# Build just manual examples + prerequisites
358allmanexamples: chk_loc allmanpages
359	-${OMAKE_SELF} ACTION=manexamples tree_basic LOC=${LOC}
360
361# Build everything that goes into 'doc' dir except html sources
362alldoc1: chk_loc chk_concepts_dir allcite allmanpages allmanexamples
363	-${OMAKE_SELF} manimplementations LOC=${LOC}
364	-${PYTHON} lib/petsc/bin/maint/wwwindex.py ${PETSC_DIR} ${LOC}
365	-${OMAKE_SELF} ACTION=getexlist tree_basic LOC=${LOC}
366	-${OMAKE_SELF} ACTION=exampleconcepts tree_basic LOC=${LOC}
367	-${PYTHON} lib/petsc/bin/maint/helpindex.py ${PETSC_DIR} ${LOC}
368
369# Builds .html versions of the source
370# html overwrites some stuff created by update-docs - hence this is done later.
371alldoc2: chk_loc allcite
372	-${OMAKE_SELF} ACTION=html PETSC_DIR=${PETSC_DIR} alltree LOC=${LOC}
373	-${PYTHON} lib/petsc/bin/maint/update-docs.py ${PETSC_DIR} ${LOC}
374
375alldoc12: alldoc1 alldoc2
376#
377# Makes links for all manual pages in $LOC/docs/manualpages/all
378allman:
379	@cd ${LOC}/docs/manualpages; rm -rf all ; mkdir all ; find *  -type d -wholename all -prune -o -name index.html -prune  -o -type f -name \*.html -exec ln -s  -f ../{} all \;
380
381DOCSETDATE_PRUNE_LIST=-o -type f -wholename share/petsc/saws/linearsolveroptions.html -prune -o -type f -wholename tutorials/HandsOnExercise.html -prune -o -type f -wholename tutorials/TAOHandsOnExercise.html -prune
382
383# modify all generated html files and add in version number, date, canonical URL info.
384docsetdate: chk_petscdir
385	@echo "Updating generated html files with petsc version, date, canonical URL info";\
386        version_release=`grep '^#define PETSC_VERSION_RELEASE ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`; \
387        version_major=`grep '^#define PETSC_VERSION_MAJOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`; \
388        version_minor=`grep '^#define PETSC_VERSION_MINOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`; \
389        version_subminor=`grep '^#define PETSC_VERSION_SUBMINOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`; \
390        if  [ $${version_release} = 0 ]; then \
391          petscversion=petsc-main; \
392          export petscversion; \
393        elif [ $${version_release} = 1 ]; then \
394          petscversion=petsc-$${version_major}.$${version_minor}.$${version_subminor}; \
395          export petscversion; \
396        else \
397          echo "Unknown PETSC_VERSION_RELEASE: $${version_release}"; \
398          exit; \
399        fi; \
400        datestr=`git log -1 --pretty=format:%ci | cut -d ' ' -f 1`; \
401        export datestr; \
402        gitver=`git describe --match "v*"`; \
403        export gitver; \
404        find * -type d -wholename src/docs/website \
405          -prune -o -type d -wholename src/benchmarks/results \
406          -prune -o -type d -wholename config/BuildSystem/docs/website \
407          -prune -o -type d -wholename include/web \
408          -prune -o -type d -wholename 'arch-*' \
409          -prune -o -type d -wholename lib/petsc/bin/maint \
410          -prune -o -type d -wholename externalpackages \
411          -prune ${DOCSETDATE_PRUNE_LIST} -o -type f -name \*.html \
412          -exec perl -pi -e 's^(<body.*>)^$$1\n   <div id=\"version\" align=right><b>$$ENV{petscversion} $$ENV{datestr}</b></div>\n   <div id="bugreport" align=right><a href="mailto:petsc-maint\@mcs.anl.gov?subject=Typo or Error in Documentation &body=Please describe the typo or error in the documentation: $$ENV{petscversion} $$ENV{gitver} {} "><small>Report Typos and Errors</small></a></div>^i' {} \; \
413          -exec perl -pi -e 's^(<head>)^$$1 <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/{}" />^i' {} \; ; \
414        echo "Done fixing version number, date, canonical URL info"
415
416# Use Sphinx to build some documentation.  This uses Python's venv, which should
417# behave similarly to what happens on e.g. ReadTheDocs. You may prefer to use
418# your own Python environment and directly build the Sphinx docs by using
419# the makefile in ${PETSC_SPHINX_ROOT}, paying attention to the requirements.txt
420# there.
421PETSC_SPHINX_ROOT=doc
422PETSC_SPHINX_ENV=${PETSC_ARCH}/sphinx_docs_env
423PETSC_SPHINX_DEST=docs/sphinx_docs
424
425sphinx-docs-all: sphinx-docs-manual sphinx-docs-html
426
427sphinx-docs-fast: chk_loc sphinx-docs-env
428	@. ${PETSC_SPHINX_ENV}/bin/activate && ${OMAKE} -C ${PETSC_SPHINX_ROOT} \
429		BUILDDIR=${LOC}/${PETSC_SPHINX_DEST} html
430
431sphinx-docs-html: chk_loc allcite sphinx-docs-env
432	@. ${PETSC_SPHINX_ENV}/bin/activate && ${OMAKE} -C ${PETSC_SPHINX_ROOT} \
433		BUILDDIR=${LOC}/${PETSC_SPHINX_DEST} html
434
435sphinx-docs-manual: chk_loc sphinx-docs-env
436	@. ${PETSC_SPHINX_ENV}/bin/activate && ${OMAKE} -C ${PETSC_SPHINX_ROOT}  BUILDDIR=${LOC}/${PETSC_SPHINX_DEST} latexpdf
437	@mv ${LOC}/${PETSC_SPHINX_DEST}/latex/manual.pdf ${LOC}/docs/manual.pdf
438	@${RM} -rf ${LOC}/${PETSC_SPHINX_DEST}/latex
439
440sphinx-docs-env: sphinx-docs-check-python sphinx-docs-check-rsvg-convert
441	@if [ ! -d  "${PETSC_SPHINX_ENV}" ]; then \
442        ${PYTHON} -m venv ${PETSC_SPHINX_ENV}; \
443        . ${PETSC_SPHINX_ENV}/bin/activate; \
444        pip install -r ${PETSC_SPHINX_ROOT}/requirements.txt; \
445      fi
446
447sphinx-docs-check-rsvg-convert:
448	@if ! command -v rsvg-convert 2>&1 > /dev/null; then \
449		    printf "rsvg-convert is required for the sphinxcontrib-svg2pdfconverter extension for the Sphinx docs\n"; \
450			  false; \
451	    fi
452
453sphinx-docs-check-python:
454	@${PYTHON} -c 'import sys; sys.exit(sys.version_info[:2] < (3,3))' || \
455    (printf 'Working Python 3.3 or later is required to build the Sphinx docs in a virtual environment\nTry e.g.\n  make ... PYTHON=python3\n' && false)
456
457sphinx-docs-clean: chk_loc
458	${RM} -rf ${PETSC_SPHINX_ENV}
459	${RM} -rf ${LOC}/${PETSC_SPHINX_DEST}
460
461alldocclean: deletemanualpages allcleanhtml sphinx-docs-clean
462
463# Deletes man pages (HTML version)
464deletemanualpages: chk_loc
465	-@if [ -d ${LOC} -a -d ${LOC}/docs/manualpages ]; then \
466          find ${LOC}/docs/manualpages -type f -name "*.html" -exec ${RM} {} \; ;\
467          ${RM} ${LOC}/docs/exampleconcepts ;\
468          ${RM} ${LOC}/docs/manualpages/manualpages.cit ;\
469          ${PYTHON} lib/petsc/bin/maint/update-docs.py ${PETSC_DIR} ${LOC} clean;\
470        fi
471
472allcleanhtml:
473	-${OMAKE_SELF} ACTION=cleanhtml PETSC_DIR=${PETSC_DIR} alltree
474
475chk_concepts_dir: chk_loc
476	@if [ ! -d "${LOC}/docs/manualpages/concepts" ]; then \
477	  echo Making directory ${LOC}/docs/manualpages/concepts for library; ${MKDIR} ${LOC}/docs/manualpages/concepts; fi
478
479# Builds simple html versions of the source without links into the $PETSC_ARCH/obj directory, used by make mergecov
480srchtml:
481	-${OMAKE_SELF} ACTION=simplehtml PETSC_DIR=${PETSC_DIR} alltree_src
482
483###########################################################
484# targets to build distribution and update docs
485###########################################################
486
487# Creates ${HOME}/petsc.tar.gz [and petsc-with-docs.tar.gz]
488dist:
489	${PETSC_DIR}/lib/petsc/bin/maint/builddist ${PETSC_DIR} main
490
491# This target works only if you can do 'ssh petsc@login.mcs.anl.gov'
492# also copy the file over to ftp site.
493web-snapshot:
494	@if [ ! -f "${HOME}/petsc-with-docs-main.tar.gz" ]; then \
495	    echo "~/petsc-with-docs-main.tar.gz missing! cannot update petsc-main snapshot on mcs-web-site"; \
496	  else \
497            echo "updating petsc-main snapshot on mcs-web-site"; \
498	    tmpdir=`mktemp -d -t petsc-doc.XXXXXXXX`; \
499	    cd $${tmpdir}; tar -xzf ${HOME}/petsc-with-docs-main.tar.gz; \
500	    /usr/bin/rsync  -e ssh -az --delete $${tmpdir}/petsc-main/ \
501              petsc@login.mcs.anl.gov:/mcs/web/research/projects/petsc/petsc-main ;\
502	    /bin/cp -f /home/petsc/petsc-main.tar.gz /mcs/ftp/pub/petsc/petsc-main.tar.gz;\
503	    ${RM} -rf $${tmpdir} ;\
504	  fi
505
506# build the tarfile - and then update petsc-main snapshot on mcs-web-site
507update-web-snapshot: dist web-snapshot
508
509# This target updates website main pages
510update-web:
511	@cd ${PETSC_DIR}/src/docs; make PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} bib2html; \
512	/usr/bin/rsync -az -C --exclude=documentation/index.html \
513          --exclude=documentation/installation.html --exclude=download/index.html \
514	  ${PETSC_DIR}/src/docs/website/ petsc@login.mcs.anl.gov:/mcs/web/research/projects/petsc
515	@cd ${PETSC_DIR}/src/docs/tex; /usr/bin/rsync -az petscapp.bib petsc.bib petsc@login.mcs.anl.gov:/mcs/web/research/projects/petsc/publications
516
517###########################################################
518#
519#  See script for details
520#
521gcov:
522	@$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --run_gcov --petsc_arch ${PETSC_ARCH}
523
524mergegcov:
525	@$(PYTHON) ${PETSC_DIR}/lib/petsc/bin/maint/gcov.py --merge_gcov  --petsc_arch ${PETSC_ARCH} --merge_branch `lib/petsc/bin/maint/check-merge-branch.sh`
526
527
528########################
529#
530# Create the include dependency graph (requires graphviz to be available)
531#
532includegraph:
533	-@${PETSC_DIR}/src/contrib/style/include-graph.sh includegraph.pdf
534	-@echo Include dependency graph written to includegraph.pdf
535
536#
537# -------------------------------------------------------------------------------
538#
539# Some macros to check if the fortran interface is up-to-date.
540#
541countfortranfunctions:
542	-@cd ${PETSC_DIR}/src/fortran; egrep '^void' custom/*.c auto/*.c | \
543	cut -d'(' -f1 | tr -s  ' ' | cut -d' ' -f2 | uniq | egrep -v "(^$$|Petsc)" | \
544	sed "s/_$$//" | sort > /tmp/countfortranfunctions
545
546countcfunctions:
547	-@grep PETSC_EXTERN ${PETSC_DIR}/include/*.h  | grep "(" | tr -s ' ' | \
548	cut -d'(' -f1 | cut -d' ' -f3 | grep -v "\*" | tr -s '\012' |  \
549	tr 'A-Z' 'a-z' |  sort | uniq > /tmp/countcfunctions
550
551difffortranfunctions: countfortranfunctions countcfunctions
552	-@echo -------------- Functions missing in the fortran interface ---------------------
553	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^<" | cut -d' ' -f2
554	-@echo ----------------- Functions missing in the C interface ------------------------
555	-@${DIFF} /tmp/countcfunctions /tmp/countfortranfunctions | grep "^>" | cut -d' ' -f2
556	-@${RM}  /tmp/countcfunctions /tmp/countfortranfunctions
557
558checkbadfortranstubs:
559	-@echo "========================================="
560	-@echo "Functions with MPI_Comm as an Argument"
561	-@echo "========================================="
562	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'MPI_Comm' | \
563	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
564	-@echo "========================================="
565	-@echo "Functions with a String as an Argument"
566	-@echo "========================================="
567	-@cd ${PETSC_DIR}/src/fortran/auto; grep '^void' *.c | grep 'char \*' | \
568	tr -s ' ' | tr -s ':' ' ' |cut -d'(' -f1 | cut -d' ' -f1,3
569	-@echo "========================================="
570	-@echo "Functions with Pointers to PETSc Objects as Argument"
571	-@echo "========================================="
572	-@cd ${PETSC_DIR}/src/fortran/auto; \
573	_p_OBJ=`grep _p_ ${PETSC_DIR}/include/*.h | tr -s ' ' | \
574	cut -d' ' -f 3 | tr -s '\012' | grep -v '{' | cut -d'*' -f1 | \
575	sed "s/_p_//g" | tr -s '\012 ' ' *|' ` ; \
576	for OBJ in $$_p_OBJ; do \
577	grep "$$OBJ \*" *.c | tr -s ' ' | tr -s ':' ' ' | \
578	cut -d'(' -f1 | cut -d' ' -f1,3; \
579	done
580
581checkpackagetests:
582	-@echo "Missing package tests"
583	-@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} ; egrep "(with-$${j}|download-$${j})" configexamples | grep -v "=0" | wc -l ; done
584	-@echo "Missing download package tests"
585	-@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} ; egrep "(download-$${j})" configexamples | grep -v "=0" | wc -l ; done
586
587.PHONY: info info_h all deletelibs allclean update \
588        alletags etags etags_complete etags_noexamples etags_makefiles etags_examples etags_fexamples alldoc allmanualpages \
589        allhtml allcleanhtml  countfortranfunctions \
590        start_configure configure_petsc configure_clean matlabbin install
591