1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{10..12} pypy3 )
8 inherit flag-o-matic fortran-2 python-any-r1 toolchain-funcs
10 DESCRIPTION="Portable, Extensible Toolkit for Scientific Computation"
11 HOMEPAGE="https://petsc.org/release/"
12 SRC_URI="https://web.cels.anl.gov/projects/petsc/download/release-snapshots/${P}.tar.gz"
16 KEYWORDS="~amd64 ~x86"
17 IUSE="afterimage boost complex-scalars debug +examples fftw
18 fortran hdf5 hypre int64 mpi metis mumps scotch superlu threads X"
20 # readd sparse when suitesparse-5.6.0 is in tree
21 # sparse? ( >=sci-libs/suitesparse-5.6.0 >=sci-libs/cholmod-1.7.0 )
22 # $(use_with sparse suitesparse) \
27 afterimage? ( media-libs/libafterimage )
28 boost? ( dev-libs/boost )
29 fftw? ( sci-libs/fftw:3.0[mpi?] )
30 hdf5? ( sci-libs/hdf5:=[mpi?] )
31 hypre? ( >=sci-libs/hypre-2.18.0[int64?,mpi?] )
32 metis? ( >=sci-libs/parmetis-4 )
33 mpi? ( virtual/mpi[fortran?] )
34 mumps? ( sci-libs/mumps[mpi?] sci-libs/scalapack )
35 scotch? ( sci-libs/scotch[int64?,mpi?] )
36 superlu? ( >=sci-libs/superlu-5 )
37 X? ( x11-libs/libX11 )
48 # hypre and superlu curretly exclude each other due to missing linking to hypre
52 complex-scalars? ( !hypre !superlu )
55 hypre? ( mpi !superlu )
61 "${FILESDIR}/${P}-disable-rpath.patch"
62 "${FILESDIR}"/${P}-fix_sandbox_violation.patch
65 # petsc uses --with-blah=1 and --with-blah=0 to en/disable options
67 use "$1" && echo "--with-${2:-$1}=1" || echo "--with-${2:-$1}=0"
69 # add external library:
70 # petsc_with use_flag libname libdir
71 # petsc_with use_flag libname include linking_libs
73 local myuse p=${2:-${1}}
76 if [[ $# -ge 4 ]]; then
77 myuse="${myuse} --with-${p}-include=${EPREFIX}${3}"
79 myuse="${myuse} --with-${p}-lib=$@"
81 myuse="${myuse} --with-${p}-dir=${EPREFIX}${3:-/usr}"
89 # select between configure options depending on use flag
91 use "$1" && echo "--with-$2=$3" || echo "--with-$2=$4"
96 # PETSc runs mpi processes during configure that result in a sandbox
97 # violation by trying to open /proc/mtrr rw. This is not easy to
98 # mitigate because it happens in libpciaccess.so called by libhwloc.so,
99 # which is used by libmpi.so.
100 addpredict /proc/mtrr
101 # if mpi is built with knem support it needs /dev/knem too
104 # configureMPITypes with openmpi-2* insists on accessing the scaling
106 addpredict /sys/devices/system/cpu/
109 # configureMPIEXEC and configureMPITypes access /dev/nvidiactl
110 addpredict /dev/nvidiactl
117 use debug && myopt="debug" || myopt="opt"
119 # environmental variables expected by petsc during build
121 export PETSC_DIR="${S}"
122 export PETSC_ARCH="linux-gnu-c-${myopt}"
131 # C Support on CXX builds is enabled if possible i.e. when not using
132 # complex scalars (no complex type for both available at the same time)
137 CFLAGS="${CFLAGS} -fPIC" \
138 CPPFLAGS="${CPPFLAGS}" \
139 CXXFLAGS="${CXXFLAGS} -fPIC" \
140 CXXOPTFLAGS="${CXXFLAGS} -fPIC" \
141 FCFLAGS="${FCFLAGS} -fPIC" \
142 FFLAGS="${FFLAGS} -fPIC" \
143 LDFLAGS="${LDFLAGS}" \
144 MAKEFLAGS="${MAKEFLAGS}" \
146 --prefix="${EPREFIX}/usr/$(get_libdir)/petscdir/" \
147 --with-blas-lapack-lib="$($(tc-getPKG_CONFIG) --libs blas lapack)" \
148 --with-cmake:BOOL=1 \
149 --with-gnu-compilers \
150 --with-imagemagick=0 \
151 --with-petsc-arch="${PETSC_ARCH}" \
152 --with-precision=double \
154 --with-shared-libraries \
155 --with-single-library \
156 --with-windows-graphics=0 \
157 $(petsc_enable debug debugging) \
158 $(petsc_enable fortran) \
159 $(petsc_enable mpi) \
160 $(petsc_enable mpi mpi-compilers) \
161 $(petsc_enable threads pthread) \
162 $(petsc_select complex-scalars scalar-type complex real) \
163 $(petsc_select mpi cc mpicc $(tc-getCC)) \
164 $(petsc_select mpi cxx mpicxx $(tc-getCXX)) \
165 $(petsc_with afterimage afterimage /usr/include/libAfterImage -lAfterImage) \
166 $(petsc_with hypre hypre /usr/include/hypre -lHYPRE) \
167 $(petsc_with superlu superlu /usr/include/superlu -lsuperlu) \
168 $(petsc_with scotch ptscotch /usr/include/scotch [-lptesmumps,-lptscotch,-lptscotcherr,-lscotch,-lscotcherr]) \
169 $(petsc_with mumps scalapack /usr/include/scalapack -lscalapack) \
170 $(petsc_with mumps mumps /usr/include [-lcmumps,-ldmumps,-lsmumps,-lzmumps,-lmumps_common,-lpord]) \
171 $(use fortran && echo "$(petsc_select mpi fc mpif77 $(tc-getF77))") \
172 $(use int64 && echo "--with-index-size=64") \
181 emake DESTDIR="${ED}" install
187 # put all include directories under a proper subdirectory
188 mkdir "${ED}"/usr/include || die "mkdir failed (include)"
189 mv "${ED}"/usr/{$(get_libdir)/petscdir/include,include/petsc} || die "mv failed (include)"
191 # put libraries and pkconfig file into proper place
192 mv "${ED}"/usr/$(get_libdir)/petscdir/lib/{libpetsc*,pkgconfig} \
193 "${ED}/usr/$(get_libdir)" || die "mv failed (lib)"
195 # move share to proper location
196 mv "${ED}"/usr/{$(get_libdir)/petscdir/share,share} || die "mv failed (share)"
200 -e 's#include$#include/petsc#' \
201 -e "s#lib\$#$(get_libdir)#" \
202 -e "s#^prefix=.*petscdir\$#prefix=${EPREFIX}/usr#" \
203 "${ED}"/usr/$(get_libdir)/pkgconfig/*.pc || die "sed failed (pkgconfig)"
205 # recreate a "valid" petscdir:
206 for i in "${ED}"/usr/$(get_libdir)/*; do
207 [ $(basename $i) = petscdir ] && continue
208 ln -s "${EPREFIX}/usr/$(get_libdir)/$(basename $i)" \
209 "${ED}/usr/$(get_libdir)/petscdir/lib/$(basename $i)" || die "ln failed (petscdir)"
211 ln -s "${EPREFIX}"/usr/include/petsc/ \
212 "${ED}/usr/$(get_libdir)/petscdir/include" || die "ln failed (petscdir)"
213 mkdir "${ED}/usr/$(get_libdir)/petscdir/share" || die "mkdir fialed (petscdir)"
214 ln -s "${EPREFIX}"/usr/share/petsc/ \
215 "${ED}/usr/$(get_libdir)/petscdir/share/petsc" || die "ln failed (petscdir)"
217 # automatically symlink petsc matlab modules:
218 mkdir -p "${ED}"/usr/share/octave/site/m/
219 ln -s "${EPREFIX}"/usr/share/petsc/matlab "${ED}"/usr/share/octave/site/m/petsc || die "ln failed (matlab)"
221 if use examples; then
222 mkdir -p "${ED}"/usr/share/doc/${PF} || die "mkdir failed (examples)"
223 mv "${ED}"/usr/share/petsc/examples "${ED}"/usr/share/doc/${PF} || die "mv failed (examples)"
224 ln -s "${EPREFIX}"/usr/share/doc/${PF}/examples "${ED}"/usr/share/petsc/examples || die "ln failed (examples)"
225 docompress -x /usr/share/doc/${PF}/examples
227 rm -r "${ED}"/usr/share/petsc/examples || die "rm failed (examples)"
230 # add PETSC_DIR to environmental variables
231 cat >> 99petsc <<- EOF
232 PETSC_DIR=${EPREFIX}/usr/$(get_libdir)/petscdir