# Contributor: Oleg A. Khlybov # The supplementary `petsc-build` package contains the distilled PETSc build tree # required at compile time by some packages (such as SLEPc). # Regular users should use the `petsc` package. # This package provides multiple library build flavors differentiated by # the 3-character suffix XYZ as follows: # # * X is the scalar type based on the Netlib's SDCZ notation: # - A for multiprecision or precision-neutral build # - S for single precision real # - D for double precision real # - C for single precision complex # - Z for double precision complex # # * Y is the execution model: # - S for sequential code # - M for MPI parallel code # - T for multithreaded code, either bare threading or OpenMP, OpenACC etc. # - H for heterogeneous code with CUDA, OpenCL etc. # # * Z is the build type: # - O for optimized build # - G for debugging build # # The suffix is used in the static and dynamic libraires as well as in PkgConfig .pc files. # That is the ZMO suffix designates the optimized MPI parallel double precision complex library flavor. # Consider the `pkg-config petsc-zmo --cflags` command to obtain the build-specific compilation flags. # There is a Tcl integration test suite for both package maintainers and package end users # to ensure the installed package is intact. The test suite performs a series of compile/run # tests for multiple configurations from the build matrix. # Basic usage: tclsh $MINGW_PREFIX/share/test/petsc/petsc.tcl _realname=petsc pkgbase=mingw-w64-${_realname} pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}" "${MINGW_PACKAGE_PREFIX}-${_realname}-build") pkgver=3.23.3 pkgrel=1 pkgdesc='Sparse iterative (non)linear solver package (mingw-w64)' arch=('any') mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64') url="https://www.mcs.anl.gov/petsc/" msys2_repository_url="https://gitlab.com/petsc/petsc" msys2_references=( 'aur: petsc' ) license=('spdx:BSD-2-Clause') depends=("${MINGW_PACKAGE_PREFIX}-cc-libs" $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-gcc-libgfortran") "${MINGW_PACKAGE_PREFIX}-hwloc" "${MINGW_PACKAGE_PREFIX}-metis" $([[ ${CARCH} == aarch64 ]] || echo "${MINGW_PACKAGE_PREFIX}-parmetis") "${MINGW_PACKAGE_PREFIX}-omp" "${MINGW_PACKAGE_PREFIX}-openblas") makedepends=('python' "${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-pkgconf" $([[ ${CARCH} == aarch64 ]] || echo "${MINGW_PACKAGE_PREFIX}-msmpi") $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-fc")) optdepends=("${MINGW_PACKAGE_PREFIX}-tcl: build & run test suite") source=("https://web.cels.anl.gov/projects/petsc/download/release-snapshots/${_realname}-${pkgver}.tar.gz" 'petsc.tcl' 'testme-0.tm' 'buildme-0.tm' 'xyz-0.tm' '0001-mpi-detection-override.patch' '0002-openblas-clang.patch' '0003-pid.patch' '0004-set_output_format.patch' '0005-with-pthread.patch') noextract=("${_realname}-${pkgver}.tar.gz") sha256sums=('bb51e8cbaa3782afce38c6f0bdd64d20ed090695992b7d49817518aa7e909139' '5df892855b26560a2ccd1a258b70ac63a772dbde5ecc4a40a95e48c1f52b94ab' '47aa9a8a03627ffeb299191ede391f5aa96071c1b09fb294ec6712e3beb0b799' 'e9585cccd9269c9ff3d68a6f9bb313d4cd64b86e5cc8d7b1f2db585e53c7a04d' '285520fc2e38db814914e6a45a1417508cf9e819a27ac64185fe4bcc57c419ad' 'bef5353d6d10de492c9832f24b41993c38d1b36a78eb55e7d49089ba72acc05a' 'c954cc4240a6f3cebdc40cf4fca07561e58eb50717b9741c296b73657bac1c51' '08d37a205d7a2ae27ccef41ee931f92c96aa428b94ed633def2f56fdfa6fb11e' '254405c6c0eb5aa57b1cb74bbaf8876bcdb67d63136102e48a8036824bb9f129' 'bd7d1fa888d24f5183de992fb9377a4532cd9f38c5608018f5cd82f61e3096e9') # Helper macros to help make tasks easier # apply_patch_with_msg() { for _fname in "$@" do msg2 "Applying ${_fname}" patch -Nbp1 -i "${srcdir}"/${_fname} done } prepare() { mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM} tar xzf $srcdir/${_realname}-${pkgver}.tar.gz cd ${_realname}-${pkgver} apply_patch_with_msg \ 0001-mpi-detection-override.patch \ 0002-openblas-clang.patch \ 0003-pid.patch \ 0004-set_output_format.patch \ 0005-with-pthread.patch } # Optimized build flavors builds='dso dto zso zto sso sto cso cto' if [[ ${CARCH} != aarch64 ]]; then builds+=' dmo zmo smo cmo' fi # Additional debugging build flavors, disabled by default due to huge library sizes # builds="$builds dsg dtg dmg zsg ztg zmg ssg stg smg csg ctg cmg" _petsc() { desc= opts="--with-single-library=1 --with-shared=0 --with-cxx=0 --with-windows-graphics=0 --with-x=0 --with-hwloc=1 --with-openblas=1 --with-openblas-dir=$MINGW_PREFIX" pc="hwloc openblas" cflags="$CFLAGS" cxxflags="$CXXFLAGS" fflags="$CFLAGS -I$MINGW_PREFIX/include" cppflags="$CPPFLAGS" ldflags="$LDFLAGS" pc_libs="$LIBS" libs="$LIBS" ld="$CC" if [[ ${MINGW_PACKAGE_PREFIX} != *-clang-* ]]; then fflags+=" -fallow-invalid-boz -fallow-argument-mismatch" opts+=" --with-fc=gfortran" libs+=" -lgfortran -lquadmath" pc_libs="$libs" else opts+=" --with-fc=0" # opts+=" --with-fc=${MINGW_PREFIX}/bin/flang" cflags+=" -Wno-incompatible-function-pointer-types" # libs+=" -lFortranRuntime -lFortranDecimal" fi case $1 in ?m?) opts+=" --with-mpi=1 --with-mpi-compilers=0 --with-pthread=0 --with-openmp=0 --with-metis=1 --with-parmetis=1" pc+=" parmetis msmpi" libs+=" -lmsmpi" # pc_libs is not augmented because MPI is provided by the PkgConfig desc="MPI parallel" ;; ?t?) opts+=" --with-mpi=0 --with-pthread=0 --with-openmp=1" ldflags+=" -fopenmp" desc="OpenMP multithreaded" ;; ?s?) opts+=" --with-mpi=0 --with-pthread=0 --with-openmp=0" desc="Sequential" ;; esac case $1 in z*|d*) opts+=" --with-precision=double" desc+=" double precision" ;; c*|s*) opts+=" --with-precision=single" desc+=" single precision" ;; esac case $1 in d*|s*) opts+=" --with-scalar-type=real" ;; z*|c*) opts+=" --with-scalar-type=complex" desc+=" complex" ;; esac case $1 in *o) opts+=" --with-debugging=0" ;; *g) opts+=" --with-debugging=1" debug="-g -Og" cflags+=" $debug" cxxflags+=" $debug" fflags+=" $debug" ;; esac } build() { cd "${srcdir}/build-${MSYSTEM}/${_realname}-${pkgver}" if [[ ${MINGW_PACKAGE_PREFIX} != *-clang-* ]]; then export FC=gfortran # else # export FC=${MINGW_PREFIX}/bin/flang.exe fi for build in ${builds}; do _petsc ${build} export PETSC_DIR=`pwd` /usr/bin/python configure --PETSC_ARCH=${build} ${opts} CC="$CC" CXX="$CXX" FC="$FC" CFLAGS="$cflags" FFLAGS="$fflags" CXXFLAGS="$cxxflags" CPPFLAGS="$cppflags" LDFLAGS="$ldflags" LIBS="$libs" MAKEFLAGS="$MAKEFLAGS" make PETSC_ARCH=${build} all ( cd ${build}/lib case ${build} in *o) strip -S *.a ;; esac ${ld} -shared -Wl,--enable-auto-import -Wl,--export-all-symbols -o lib${_realname}-${build}.dll -Wl,--out-implib,lib${_realname}.dll.a -Wl,--whole-archive lib${_realname}.a -Wl,--no-whole-archive ${ldflags} ${libs} $(pkg-config ${pc} --libs) ) done } eval "package_${MINGW_PACKAGE_PREFIX}-${_realname}() { _package; }" eval "package_${MINGW_PACKAGE_PREFIX}-${_realname}-build() { _package_build; }" _package() { builddir="${srcdir}"/build-${MSYSTEM}/${_realname}-${pkgver} cd "${builddir}" mkdir -p "${pkgdir}"${MINGW_PREFIX}/{bin,lib/pkgconfig,lib/${_realname},include/${_realname},share/test/${_realname}/{ksp,mat}} cd "${builddir}/include" cp -R * "${pkgdir}"${MINGW_PREFIX}/include/${_realname} for build in $builds; do cd "${builddir}/${build}/include" mkdir -p "${pkgdir}"${MINGW_PREFIX}/include/${_realname}/${build} cp -R * "${pkgdir}"${MINGW_PREFIX}/include/${_realname}/${build} done cd "${pkgdir}"${MINGW_PREFIX}/include/${_realname} find . \( ! \( -name '*.h' -o -name '*.hpp' -o -name '*.mod' \) -a -type f \) -delete cd "${srcdir}" cp petsc.tcl {testme-0,buildme-0,xyz-0}.tm "${pkgdir}"${MINGW_PREFIX}/share/test/${_realname} cd "${builddir}/src/ksp/ksp/tutorials" cp ex1.c ex2.c ex1f.F90 ex2f.F90 "${pkgdir}"${MINGW_PREFIX}/share/test/${_realname}/ksp cd "${builddir}/src/mat/tutorials" cp ex15.c ex15f.F90 "${pkgdir}"${MINGW_PREFIX}/share/test/${_realname}/mat for build in ${builds}; do _petsc ${build} cd "${builddir}/${build}/lib" mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib/${_realname}/${build} cp *.a "${pkgdir}"${MINGW_PREFIX}/lib/${_realname}/${build} cp *.dll "${pkgdir}"${MINGW_PREFIX}/bin echo " prefix=${MINGW_PREFIX} libdir=\${prefix}/lib/${_realname} includedir=\${prefix}/include/${_realname} Name: ${_realname} URL: ${url} Version: ${pkgver} Description: ${desc} PETSc build Requires.private: ${pc} Cflags: -I\${includedir}/${build} -I\${includedir} Libs.private: -L\${libdir}/${build} -l${_realname} ${ldflags} ${pc_libs} Libs: -L\${libdir}/${build} -l${_realname} " | sed '/^\s*$/d;s/^\s*//' > "${pkgdir}"${MINGW_PREFIX}/lib/pkgconfig/${_realname}-${build}.pc done } _package_build() { mkdir -p "${pkgdir}"${MINGW_PREFIX}/src cd "${srcdir}"/build-${MSYSTEM} cp -R ${_realname}-${pkgver} "${pkgdir}"${MINGW_PREFIX}/src cd "${pkgdir}"${MINGW_PREFIX}/src mv ${_realname}-${pkgver} ${_realname} find . -regextype posix-extended \( -regex '.*\.(o|dll|log|DIR)$' -or -regex '.*/__pycache__' \) -exec rm -rf {} + for build in ${builds}; do find . -regextype posix-extended -regex ".*$build/(bin|obj|tests)" -exec rm -rf {} + si=${MINGW_PREFIX}/src/${_realname}/include sb=${MINGW_PREFIX}/src/${_realname}/${build}/include pi=${MINGW_PREFIX}/include/petsc pb=${MINGW_PREFIX}/include/petsc/${build} sed -r -i \ -e "s%(PETSC_(C|F)C_INCLUDES)[[:space:]]+.*$%\\1 = -I${sb} -I${si}%" \ -e "s%(PETSC_(C|F)C_INCLUDES_INSTALL)[[:space:]]+.*$%\\1 = -I${pb} -I${pi}%" \ -e "s%(wPETSC_DIR)[[:space:]]+.*$%\\1 = ${MINGW_PREFIX}/src/${_realname}%" \ -e "s%(PREFIXDIR)[[:space:]]+.*$%\\1 = ${MINGW_PREFIX}/src/${_realname}/${build}%" \ -e "/^PETSC_WITH_EXTERNAL_LIB/s%${srcdir}/build-${MSYSTEM}/${_realname}-${pkgver}%${MINGW_PREFIX}/src/${_realname}%g" \ ${_realname}/${build}/lib/petsc/conf/petscvariables done echo " petsc_pkgver=${pkgver} petsc_builds=\"${builds}\" " | sed '/^\s*$/d;s/^\s*//' > ${_realname}/petsc }