gromacs-9999.ebuild 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. CMAKE_MAKEFILE_GENERATOR="ninja"
  5. inherit bash-completion-r1 cmake-utils cuda eutils multilib readme.gentoo-r1 toolchain-funcs xdg-utils
  6. if [[ $PV = *9999* ]]; then
  7. EGIT_REPO_URI="git://git.gromacs.org/gromacs.git
  8. https://gerrit.gromacs.org/gromacs.git
  9. git://github.com/gromacs/gromacs.git
  10. http://repo.or.cz/r/gromacs.git"
  11. [[ $PV = 9999 ]] && EGIT_BRANCH="master" || EGIT_BRANCH="release-${PV:0:4}"
  12. inherit git-r3
  13. KEYWORDS=""
  14. else
  15. SRC_URI="ftp://ftp.gromacs.org/pub/${PN}/${PN}-${PV/_/-}.tar.gz
  16. test? ( http://gerrit.gromacs.org/download/regressiontests-${PV/_/-}.tar.gz )"
  17. KEYWORDS="~alpha ~amd64 ~arm ~ppc64 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos"
  18. fi
  19. ACCE_IUSE="cpu_flags_x86_sse2 cpu_flags_x86_sse4_1 cpu_flags_x86_fma4 cpu_flags_x86_avx cpu_flags_x86_avx2"
  20. DESCRIPTION="The ultimate molecular dynamics simulation package"
  21. HOMEPAGE="http://www.gromacs.org/"
  22. # see COPYING for details
  23. # http://repo.or.cz/w/gromacs.git/blob/HEAD:/COPYING
  24. # base, vmd plugins, fftpack from numpy, blas/lapck from netlib, memtestG80 library, mpi_thread lib
  25. LICENSE="LGPL-2.1 UoI-NCSA !mkl? ( !fftw? ( BSD ) !blas? ( BSD ) !lapack? ( BSD ) ) cuda? ( LGPL-3 ) threads? ( BSD )"
  26. SLOT="0/${PV}"
  27. IUSE="X blas cuda +doc -double-precision +fftw +hwloc lapack mkl mpi +offensive openmp +single-precision test +threads +tng ${ACCE_IUSE}"
  28. CDEPEND="
  29. X? (
  30. x11-libs/libX11
  31. x11-libs/libSM
  32. x11-libs/libICE
  33. )
  34. blas? ( virtual/blas )
  35. cuda? ( >=dev-util/nvidia-cuda-toolkit-4.2.9-r1 )
  36. fftw? ( sci-libs/fftw:3.0 )
  37. hwloc? ( sys-apps/hwloc )
  38. lapack? ( virtual/lapack )
  39. mkl? ( sci-libs/mkl )
  40. mpi? ( virtual/mpi )
  41. "
  42. DEPEND="${CDEPEND}
  43. virtual/pkgconfig
  44. doc? (
  45. app-doc/doxygen
  46. dev-texlive/texlive-latex
  47. dev-texlive/texlive-latexextra
  48. media-gfx/imagemagick
  49. )"
  50. RDEPEND="${CDEPEND}"
  51. REQUIRED_USE="
  52. || ( single-precision double-precision )
  53. cuda? ( single-precision )
  54. mkl? ( !blas !fftw !lapack )"
  55. DOCS=( AUTHORS README )
  56. if [[ ${PV} != *9999 ]]; then
  57. S="${WORKDIR}/${PN}-${PV/_/-}"
  58. fi
  59. pkg_pretend() {
  60. [[ $(gcc-version) == "4.1" ]] && die "gcc 4.1 is not supported by gromacs"
  61. use openmp && ! tc-has-openmp && \
  62. die "Please switch to an openmp compatible compiler"
  63. }
  64. src_unpack() {
  65. if [[ ${PV} != *9999 ]]; then
  66. default
  67. else
  68. git-r3_src_unpack
  69. if use test; then
  70. EGIT_REPO_URI="git://git.gromacs.org/regressiontests.git" \
  71. EGIT_BRANCH="${EGIT_BRANCH}" \
  72. EGIT_CHECKOUT_DIR="${WORKDIR}/regressiontests"\
  73. git-r3_src_unpack
  74. fi
  75. fi
  76. }
  77. src_prepare() {
  78. #notes/todos
  79. # -on apple: there is framework support
  80. xdg_environment_reset #591952
  81. cmake-utils_src_prepare
  82. use cuda && cuda_src_prepare
  83. GMX_DIRS=""
  84. use single-precision && GMX_DIRS+=" float"
  85. use double-precision && GMX_DIRS+=" double"
  86. if use test; then
  87. for x in ${GMX_DIRS}; do
  88. mkdir -p "${WORKDIR}/${P}_${x}" || die
  89. cp -al "${WORKDIR}/regressiontests"* "${WORKDIR}/${P}_${x}/tests" || die
  90. done
  91. fi
  92. DOC_CONTENTS="Gromacs can use sci-chemistry/vmd to read additional file formats"
  93. }
  94. src_configure() {
  95. local mycmakeargs_pre=( ) extra fft_opts=( )
  96. #go from slowest to fastest acceleration
  97. local acce="None"
  98. use cpu_flags_x86_sse2 && acce="SSE2"
  99. use cpu_flags_x86_sse4_1 && acce="SSE4.1"
  100. use cpu_flags_x86_fma4 && acce="AVX_128_FMA"
  101. use cpu_flags_x86_avx && acce="AVX_256"
  102. use cpu_flags_x86_avx2 && acce="AVX2_256"
  103. #to create man pages, build tree binaries are executed (bug #398437)
  104. [[ ${CHOST} = *-darwin* ]] && \
  105. extra+=" -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF"
  106. if use fftw; then
  107. fft_opts=( -DGMX_FFT_LIBRARY=fftw3 )
  108. elif use mkl && has_version "=sci-libs/mkl-10*"; then
  109. fft_opts=( -DGMX_FFT_LIBRARY=mkl
  110. -DMKL_INCLUDE_DIR="${MKLROOT}/include"
  111. -DMKL_LIBRARIES="$(echo /opt/intel/mkl/10.0.5.025/lib/*/libmkl.so);$(echo /opt/intel/mkl/10.0.5.025/lib/*/libiomp*.so)"
  112. )
  113. elif use mkl; then
  114. local bits=$(get_libdir)
  115. fft_opts=( -DGMX_FFT_LIBRARY=mkl
  116. -DMKL_INCLUDE_DIR="$(echo /opt/intel/*/mkl/include)"
  117. -DMKL_LIBRARIES="$(echo /opt/intel/*/mkl/lib/*${bits/lib}/libmkl_rt.so)"
  118. )
  119. else
  120. fft_opts=( -DGMX_FFT_LIBRARY=fftpack )
  121. fi
  122. mycmakeargs_pre+=(
  123. "${fft_opts[@]}"
  124. -DGMX_X11=$(usex X)
  125. -DGMX_EXTERNAL_BLAS=$(usex blas)
  126. -DGMX_EXTERNAL_LAPACK=$(usex lapack)
  127. -DGMX_OPENMP=$(usex openmp)
  128. -DGMX_COOL_QUOTES=$(usex offensive)
  129. -DGMX_USE_TNG=$(usex tng)
  130. -DGMX_BUILD_MANUAL=$(usex doc)
  131. -DGMX_HWLOC=$(usex hwloc)
  132. -DGMX_DEFAULT_SUFFIX=off
  133. -DGMX_SIMD="$acce"
  134. -DGMX_LIB_INSTALL_DIR="$(get_libdir)"
  135. -DGMX_VMD_PLUGIN_PATH="${EPREFIX}/usr/$(get_libdir)/vmd/plugins/*/molfile/"
  136. -DBUILD_TESTING=$(usex test)
  137. -DGMX_BUILD_UNITTESTS=$(usex test)
  138. ${extra}
  139. )
  140. for x in ${GMX_DIRS}; do
  141. einfo "Configuring for ${x} precision"
  142. local suffix=""
  143. #if we build single and double - double is suffixed
  144. use double-precision && use single-precision && \
  145. [[ ${x} = "double" ]] && suffix="_d"
  146. local p
  147. [[ ${x} = "double" ]] && p="-DGMX_DOUBLE=ON" || p="-DGMX_DOUBLE=OFF"
  148. local cuda=( "-DGMX_GPU=OFF" )
  149. [[ ${x} = "float" ]] && use cuda && \
  150. cuda=( -DGMX_GPU=ON )
  151. mycmakeargs=(
  152. ${mycmakeargs_pre[@]} ${p}
  153. -DGMX_MPI=OFF
  154. -DGMX_THREAD_MPI=$(usex threads)
  155. "${cuda[@]}"
  156. "$(use test && echo -DREGRESSIONTEST_PATH="${WORKDIR}/${P}_${x}/tests")"
  157. -DGMX_BINARY_SUFFIX="${suffix}"
  158. -DGMX_LIBS_SUFFIX="${suffix}"
  159. )
  160. BUILD_DIR="${WORKDIR}/${P}_${x}" cmake-utils_src_configure
  161. [[ ${CHOST} != *-darwin* ]] || \
  162. sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}/gentoo_rules.cmake" || die
  163. use mpi || continue
  164. einfo "Configuring for ${x} precision with mpi"
  165. mycmakeargs=(
  166. ${mycmakeargs_pre[@]} ${p}
  167. -DGMX_THREAD_MPI=OFF
  168. -DGMX_MPI=ON ${cuda}
  169. -DGMX_OPENMM=OFF
  170. -DGMX_BUILD_MDRUN_ONLY=ON
  171. -DBUILD_SHARED_LIBS=OFF
  172. -DGMX_BUILD_MANUAL=OFF
  173. -DGMX_BINARY_SUFFIX="_mpi${suffix}"
  174. -DGMX_LIBS_SUFFIX="_mpi${suffix}"
  175. )
  176. BUILD_DIR="${WORKDIR}/${P}_${x}_mpi" CC="mpicc" cmake-utils_src_configure
  177. [[ ${CHOST} != *-darwin* ]] || \
  178. sed -i '/SET(CMAKE_INSTALL_NAME_DIR/s/^/#/' "${WORKDIR}/${P}_${x}_mpi/gentoo_rules.cmake" || die
  179. done
  180. }
  181. src_compile() {
  182. for x in ${GMX_DIRS}; do
  183. einfo "Compiling for ${x} precision"
  184. BUILD_DIR="${WORKDIR}/${P}_${x}"\
  185. cmake-utils_src_compile
  186. # not 100% necessary for rel ebuilds as available from website
  187. if use doc; then
  188. BUILD_DIR="${WORKDIR}/${P}_${x}"\
  189. cmake-utils_src_compile manual
  190. fi
  191. use mpi || continue
  192. einfo "Compiling for ${x} precision with mpi"
  193. BUILD_DIR="${WORKDIR}/${P}_${x}_mpi"\
  194. cmake-utils_src_compile
  195. done
  196. }
  197. src_test() {
  198. for x in ${GMX_DIRS}; do
  199. BUILD_DIR="${WORKDIR}/${P}_${x}"\
  200. cmake-utils_src_make check
  201. done
  202. }
  203. src_install() {
  204. for x in ${GMX_DIRS}; do
  205. BUILD_DIR="${WORKDIR}/${P}_${x}" \
  206. cmake-utils_src_install
  207. if use doc; then
  208. newdoc "${WORKDIR}/${P}_${x}"/docs/manual/gromacs.pdf "${PN}-manual-${PV}.pdf"
  209. fi
  210. use mpi || continue
  211. BUILD_DIR="${WORKDIR}/${P}_${x}_mpi" \
  212. cmake-utils_src_install
  213. done
  214. if use tng; then
  215. insinto /usr/include/tng
  216. doins src/external/tng_io/include/tng/*h
  217. fi
  218. # drop unneeded stuff
  219. rm "${ED}"usr/bin/GMXRC* || die
  220. for x in "${ED}"usr/bin/gmx-completion-*.bash ; do
  221. local n=${x##*/gmx-completion-}
  222. n="${n%.bash}"
  223. cat "${ED}"usr/bin/gmx-completion.bash "$x" > "${T}/${n}" || die
  224. newbashcomp "${T}"/"${n}" "${n}"
  225. done
  226. rm "${ED}"usr/bin/gmx-completion*.bash || die
  227. readme.gentoo_create_doc
  228. }
  229. pkg_postinst() {
  230. einfo
  231. einfo "Please read and cite:"
  232. einfo "Gromacs 4, J. Chem. Theory Comput. 4, 435 (2008). "
  233. einfo "http://dx.doi.org/10.1021/ct700301q"
  234. einfo
  235. readme.gentoo_print_elog
  236. }