www-apache/mod_tls: new package, add 0.14.0
[gentoo/gentoo.git] / sci-mathematics / petsc / petsc-3.21.3.ebuild
blob10be74f1f7e23ef98166330e6bcde3e7bd499125
1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 EAPI=8
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"
14 LICENSE="BSD-2"
15 SLOT="0"
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) \
23 RDEPEND="
24         virtual/blas
25         virtual/lapack
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 )
39 DEPEND="
40         ${RDEPEND}
41         ${PYTHON_DEPS}
43 BDEPEND="
44         dev-build/cmake
45         virtual/pkgconfig
48 # hypre and superlu curretly exclude each other due to missing linking to hypre
49 # if both are enabled
50 REQUIRED_USE="
51         afterimage? ( X )
52         complex-scalars? ( !hypre !superlu )
53         fftw? ( mpi )
54         hdf5? ( mpi )
55         hypre? ( mpi !superlu )
56         mumps? ( mpi scotch )
57         scotch? ( mpi )
58         superlu? ( !hypre )
60 PATCHES=(
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
66 petsc_enable() {
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
72 petsc_with() {
73         local myuse p=${2:-${1}}
74         if use ${1}; then
75                 myuse="--with-${p}=1"
76                 if [[ $# -ge 4 ]]; then
77                         myuse="${myuse} --with-${p}-include=${EPREFIX}${3}"
78                         shift 3
79                         myuse="${myuse} --with-${p}-lib=$@"
80                 else
81                         myuse="${myuse} --with-${p}-dir=${EPREFIX}${3:-/usr}"
82                 fi
83         else
84                 myuse="--with-${p}=0"
85         fi
86         echo ${myuse}
89 # select between configure options depending on use flag
90 petsc_select() {
91         use "$1" && echo "--with-$2=$3" || echo "--with-$2=$4"
94 src_configure() {
95         # bug 548498
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
102         addpredict /dev/knem
104         # configureMPITypes with openmpi-2* insists on accessing the scaling
105         # governor rw.
106         addpredict /sys/devices/system/cpu/
108         # bug 771711
109         # configureMPIEXEC and  configureMPITypes access /dev/nvidiactl
110         addpredict /dev/nvidiactl
112         # bug 810841
113         addpredict /dev/kfd
115         local myopt
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}"
124         if use debug; then
125                 strip-flags
126                 filter-flags -O*
127         fi
129         tc-export AR RANLIB
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)
134         econf \
135                 scrollOutput=1 \
136                 AR="${AR}" \
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}" \
145                 RANLIB="${RANLIB}" \
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 \
153                 --with-python=0 \
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") \
173                 $(use_with boost) \
174                 $(use_with fftw) \
175                 $(use_with hdf5) \
176                 $(use_with X x) \
177                 $(use_with X x11)
180 src_install() {
181         emake DESTDIR="${ED}" install
183         #
184         # Clean up the mess:
185         #
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)"
198         # fix pc files:
199         sed -i \
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)"
210         done
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
226         else
227                 rm -r "${ED}"/usr/share/petsc/examples || die "rm failed (examples)"
228         fi
230         # add PETSC_DIR to environmental variables
231         cat >> 99petsc <<- EOF
232                 PETSC_DIR=${EPREFIX}/usr/$(get_libdir)/petscdir
233         EOF
234         doenvd 99petsc