PKGBUILD 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # This package tries to compile PETSc with a working branch
  2. # of the git sources (either main or release) and its
  3. # documentation. It prevents the use of non-free software
  4. # and finds most optional dependencies. The petsc package
  5. # from AUR is still recommended if you don't care about the
  6. # documentation, freedom or extra compatibility. If you find
  7. # any similarities to the petsc-git package it's because I was
  8. # the owner and maintainer of that package until I decided to
  9. # host this one.
  10. # Maintainer: eDgar <edgar |at] openmail cc>
  11. # Contributor: Martin Diehl <aur@martin-diehl.net>
  12. # Contributor: Lucas H. Gabrielli <heitzmann@gmail.com> (creator)
  13. _base=petsc
  14. pkgname=("${_base}"-free+opts "${_base}"-doc-bin)
  15. pkgver=3.20.5.910.gec4bd5ab864
  16. pkgrel=1
  17. _mainver="${pkgver:0:6}"
  18. pkgdesc="Portable, extensible toolkit for scientific computation"
  19. arch=('i686' 'x86_64')
  20. url="https://gitlab.com/petsc/${_base}"
  21. license=('BSD')
  22. # DAMASK requires PETSc's static libraries
  23. options=(staticlibs)
  24. depends=('openmpi' 'lapack' 'fftw' 'zlib' 'cython'
  25. 'python-mpi4py' "python-numpy" "eigen>=3" "blas-openblas")
  26. # Force version to force recompilation of HYPRE
  27. hypre=$(pacman -Qs hypre | head -n 1 | cut -f2 -d' ')
  28. makedepends=('gcc' 'gcc-fortran' 'cmake' 'sowing' "pkgconf"
  29. 'git' 'cython' 'chrpath' "hypre=${hypre}")
  30. source=("git+${url}.git#branch=main"
  31. "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-with-docs-3.19.5.tar.gz"
  32. # "https://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-with-docs-${_mainver}.tar.gz"
  33. test_optdepends.sh
  34. 0001-sowing-minversion1_1_26.patch)
  35. sha512sums=('SKIP'
  36. 'b00026074349f3995312b407044def7a104f62e9ba68e1b571e7f09ddb8aa56aa64bea5e5f9e5546d4d6866c37278d8b40334af2697bd0f837ca3981229d700a'
  37. '49bf2d313582a51d5ce866a9b5a640266a8132e817d2f5266c70f3b77ef3c49eac12a2a3bdcf773c8b030a3f7a47d5f4d7c082ff3f49a05bd8d18847453a1c0a'
  38. '3c156d1c465c10ba0a3c79b829f98ecc05e48b8f002a3a382f86ac834faaa34108d522f04757af38257f4a4e1292d8d8b79c9c039ecb9ea25444d902a384907f')
  39. install=petsc.install
  40. _config=linux-c-opt
  41. _install_dir="/usr"
  42. # From UPC: Building And Using Static And Shared "C"
  43. # Libraries.html
  44. # #+begin_QUOTE
  45. # we need that all jump calls ("goto", in assembly speak)
  46. # and subroutine calls will use relative addresses, and not
  47. # absolute addresses. Thus, we need to use ... ~-fPIC~ or
  48. # ~-fpic~
  49. # #+end_QUOTE
  50. #
  51. # From makepkg.conf
  52. # -march (or -mcpu) builds exclusively for an architecture
  53. # -mtune optimizes for an architecture, but builds for
  54. # whole processor family
  55. #
  56. # -O3 optimises
  57. #
  58. # -D-FORTIFY-SOURCE=2
  59. # | https://stackoverflow.com/a/16604146
  60. # |- man 7 feature_test_macros
  61. # checks to be performed to detect some buffer overflow
  62. # errors when employing various string and memory
  63. # manipulation functions ... some conforming programs
  64. # might fail
  65. #
  66. # -fcf-protection
  67. # | Info pages for gcc (gnu compiler collection)
  68. # intended to protect against such threats as
  69. # Return-oriented Programming (ROP), and similarly
  70. # call/jmp-oriented programming (COP/JOP)
  71. #
  72. # -pipe
  73. # | Info pages for gcc (controlling the kind of output)
  74. # Use pipes rather than temporary files for communication
  75. # between the various stages of compilation
  76. #
  77. # -fno-plt
  78. # | Info pages for gcc (code generation conventions)
  79. # leads to more efficient code by eliminating PLT stubs and
  80. # exposing GOT loads to optimizations
  81. #
  82. # -fopenmp
  83. # | Info pages for gcc (controlling c dialect)
  84. # Enable handling of OpenMP directives
  85. safe_flags="-Wp,-D-FORTIFY-SOURCE=2,-D_GLIBCXX_ASSERTIONS"
  86. safe_flags+=" -fcf-protection -fno-plt"
  87. safe_flags+=" -fstack-clash-protection -Wformat"
  88. safe_flags+=" -Werror=format-security"
  89. generic_flags="-march=native -mtune=native"
  90. generic_flags+=" -pipe -fno-plt -fPIC -fopenmp"
  91. generic_flags+="${safe_flags}"
  92. opt_flags="${generic_flags} -O3"
  93. generic_flags="${generic_flags} -O2"
  94. export LANG=C
  95. # Try to mute warnings from missing CUDA
  96. # https://github.com/open-mpi/ompi/issues/4405
  97. export OMPI_MCA_opal_cuda_support=0
  98. # (muting may not work:
  99. # https://github.com/open-mpi/ompi/issues/10049)
  100. export OMPI_MCA_opal_warn_on_missing_libcuda=0
  101. # export OMPI_MCA_mpi_oversubscribe=0
  102. unset PETSC_DIR
  103. export PETSC_ARCH=${_config}
  104. prepare() {
  105. cd "${srcdir}"/"${_base}"
  106. # patch -Np1 -i "${srcdir}"/hypre_global_error.error_flag-0.patch
  107. patch -Np1 -i "${srcdir}"/0001-sowing-minversion1_1_26.patch
  108. }
  109. pkgver() {
  110. cd "${srcdir}"/"${_base}"
  111. git describe --tags --match '*.*' | tr '-' '.' | sed 's-^v--'
  112. }
  113. build() {
  114. CONFOPTS=(
  115. --silent --enable-silent-rules
  116. --ignoreWarnings=1
  117. --prefix="${_install_dir}"
  118. --COPTFLAGS="${opt_flags}"
  119. --CXXOPTFLAGS="${opt_flags}"
  120. --FOPTFLAGS="${opt_flags}"
  121. --CFLAGS="${generic_flags}"
  122. --CXXFLAGS="$generic_flags"
  123. --CPPFLAGS="$generic_flags"
  124. --FCFLAGS="$generic_flags"
  125. --F90FLAGS="$generic_flags"
  126. --FFLAGS="$generic_flags"
  127. --MAKEFLAGS=${MAKEFLAGS}
  128. --LDFLAGS=${LDFLAGS}
  129. --with-environment-variables=1
  130. --with-cxx-dialect=auto
  131. --with-mpi=1
  132. --with-pic=1
  133. --with-shared-libraries=1
  134. --with-zlib=1
  135. --with-petsc4py=1
  136. --with-mpi-f90module-visibility=0
  137. --with-cuda=0
  138. # Disabled for DAMASK
  139. # --with-scalar-type=complex
  140. " $(sh ${srcdir}/test_optdepends.sh)")
  141. # --with-single-library=1
  142. cd "${srcdir}"/"${_base}"
  143. export PETSC_DIR="${srcdir}"/"${_base}"
  144. python ./configure ${CONFOPTS[@]}
  145. make -s ${MAKEFLAGS} all
  146. make DESTDIR=${srcdir}/tmp install
  147. }
  148. check() {
  149. cd "${srcdir}"/"${_base}"
  150. if [ -z "$(ldconfig -p | grep libcuda.so.1)" ]; then
  151. export OMPI_MCA_opal_warn_on_missing_libcuda=0
  152. fi
  153. export OMPI_MCA_plm_rsh_agent=sh
  154. PYTHONPATH=${srcdir}/tmp/${_install_dir}/lib:${PYTHONPATH} make check ||
  155. printf "Tests failed\n"
  156. }
  157. package_petsc-free+opts() {
  158. optdepends=(
  159. "boost: Free peer-reviewed portable C++ source libraries"
  160. "cgns: Recording and recovering computer data"
  161. "eigen: Lightweight C++ template library for vector and matrix math"
  162. "fftw: Fast-Fourier Transform"
  163. "gdb: Debugging"
  164. "hdf5: large files"
  165. "hwloc: Portable Hardware Locality (abstraction of hierarchical architectures)"
  166. "med>=4.0: Data Modelization and Exchanges (meshes)"
  167. "metis: Partitioning library (for meshes)"
  168. "mumps: Sparse solver library"
  169. "netcdf-openmpi: Management of array-data"
  170. "openblas: Linear algebra libraries"
  171. "opencl: GPU computing"
  172. "opencl-headers: for opencl (GPU computing)"
  173. "opencl-clhpp: for opencl C++ compatibility (GPU computing)"
  174. "openmp: Parallel distributed tasks"
  175. "libpng"
  176. "scalapack: Parallel memory linear algebra"
  177. "scotch: Partitioning with sparse matrices"
  178. "suitesparse: Sparse matrix library"
  179. "superlu: Subroutines for sparsse linear systems"
  180. "tetgen: For meshing (tetrahedral mesh and 3D Delaunay triangulator)"
  181. "libyaml: configuration files")
  182. provides=(${_base}="${_mainver}"
  183. petsc4py="${_mainver}"
  184. ${_base}="${pkgver}-${pkgrel}"
  185. petsc4py="${pkgver}-${pkgrel}")
  186. conflicts=(${_base} ${_base}-git)
  187. # # From OpenCV (hack destination of petsc4py)
  188. # _pythonpath=`python -c "from sysconfig import get_path; print(get_path('platlib'))"`
  189. # sed -i "s%\(installLibPath = \)os.path.join(self.installDir, 'lib')%\1'${_pythonpath}'%"
  190. unset PETSC_DIR
  191. _build_dir="${srcdir}"/"${_base}"
  192. make -C "${_build_dir}" \
  193. ${MAKEFLAGS} DESTDIR="${pkgdir}" install
  194. export PETSC_DIR=${_install_dir}
  195. # install licence (even though there is no such word as licenses)
  196. install -Dm 644 ${_build_dir}/LICENSE \
  197. "${pkgdir}"/"${_install_dir}"/share/licenses/"${pkgname}"/LICENSE
  198. mkdir -p "${pkgdir}"/etc/profile.d
  199. echo "export PETSC_DIR=${_install_dir}" > \
  200. "${pkgdir}"/etc/profile.d/${_base}.sh
  201. echo "export OMPI_MCA_opal_cuda_support=0 OMPI_MCA_opal_warn_on_missing_libcuda=0" >> \
  202. "${pkgdir}"/etc/profile.d/${_base}.sh
  203. # echo "export PYTHONPATH=\$PYTHONPATH:/${_install_dir}/${_base}/${_config}/lib" \
  204. # >> "${pkgdir}"/etc/profile.d/${_base}.sh
  205. chmod +x "${pkgdir}"/etc/profile.d/${_base}.sh
  206. # show where the shared libraries are
  207. install -dm 755 "${pkgdir}"/etc/ld.so.conf.d/
  208. echo "${_install_dir}/lib" > \
  209. "${pkgdir}"/etc/ld.so.conf.d/${_base}.conf
  210. # install pkgconfig settings
  211. install -Dm 644 "${_build_dir}/${_config}"/lib/pkgconfig/PETSc.pc \
  212. "${pkgdir}"/"${_install_dir}"/share/pkgconfig/PETSc.pc
  213. # cd "${srcdir}"/"${_base}"/src/binding/petsc4py
  214. # CFLAGS="$(echo "${CFLAGS}" | sed 's%-D[^[:space:]]*%%g')" python setup.py install --root="${pkgdir}" --optimize=1 --skip-build
  215. # cd -
  216. _pythonpath="${pkgdir}"/`python -c "from sysconfig import get_path; print(get_path('platlib'))"`
  217. install -dm 755 ${_pythonpath}
  218. ln -s "${_install_dir}"/lib/petsc4py ${_pythonpath}
  219. }
  220. package_petsc-doc-bin () {
  221. depends=()
  222. optdepends=()
  223. provides=(${_base}-doc)
  224. conflicts=()
  225. pkgdesc="Documentation for PETSc"
  226. # Two options: compile the documentation or get it from
  227. # the web. Downloading is easier.
  228. [[ -d ${pkgdir}/${_install_dir}/share/doc ]] && \
  229. rm -fr "${pkgdir}"/"${_install_dir}"/share/doc
  230. mkdir -p "${pkgdir}"/"${_install_dir}"/share/doc
  231. cp -r "${srcdir}/${_base}-"*"/docs" \
  232. "${pkgdir}"/"${_install_dir}"/share/doc/${_base}
  233. }