lammps-20170109.ebuild 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. PYTHON_COMPAT=( python{2_7,3_4} )
  5. inherit eutils flag-o-matic fortran-2 multilib python-r1
  6. convert_month() {
  7. local months=( "" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
  8. echo ${months[${1#0}]}
  9. }
  10. MY_P=${PN}-$((10#${PV:6:2}))$(convert_month ${PV:4:2})${PV:2:2}
  11. DESCRIPTION="Large-scale Atomic/Molecular Massively Parallel Simulator"
  12. HOMEPAGE="http://lammps.sandia.gov/"
  13. SRC_URI="http://lammps.sandia.gov/tars/${MY_P}.tar.gz"
  14. LICENSE="GPL-2"
  15. SLOT="0"
  16. KEYWORDS="~amd64 ~x86"
  17. IUSE="doc examples gzip lammps-memalign mpi python static-libs"
  18. # blas/lapack is needed by the ATC package which is only built with MPI.
  19. DEPEND="
  20. gzip? ( app-arch/gzip )
  21. mpi? (
  22. virtual/mpi
  23. )
  24. python? ( ${PYTHON_DEPS} )
  25. sci-libs/voro++
  26. virtual/blas
  27. virtual/lapack
  28. "
  29. RDEPEND="${DEPEND}"
  30. REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
  31. S="${WORKDIR}/${MY_P}"
  32. PATCHES=(
  33. "${FILESDIR}/fm_exp.patch"
  34. )
  35. lmp_emake() {
  36. local LAMMPS_INCLUDEFLAGS
  37. LAMMPS_INCLUDEFLAGS="$(usex gzip '-DLAMMPS_GZIP' '')"
  38. LAMMPS_INCLUDEFLAGS+="$(usex lammps-memalign ' -DLAMMPS_MEMALIGN=64' '')"
  39. # The lammps makefile uses CC to indicate the C++ compiler.
  40. emake \
  41. ARCHIVE="$(tc-getAR)" \
  42. CC="$(usex mpi "mpic++" "$(tc-getCXX)")" \
  43. F90="$(usex mpi "mpif90" "$(tc-getFC)")" \
  44. LINK="$(usex mpi "mpic++" "$(tc-getCXX)")" \
  45. CCFLAGS="${CXXFLAGS}" \
  46. F90FLAGS="${FCFLAGS}" \
  47. LINKFLAGS="${LDFLAGS}" \
  48. LMP_INC="${LAMMPS_INCLUDEFLAGS}" \
  49. MPI_INC="$(usex mpi "" "-I../STUBS")" \
  50. MPI_PATH="$(usex mpi "" "-L../STUBS")" \
  51. MPI_LIB="$(usex mpi "" "-lmpi_stubs")" \
  52. user-atc_SYSLIB="$(usex mpi "$($(tc-getPKG_CONFIG) --libs blas) $($(tc-getPKG_CONFIG) --libs lapack)" '')"\
  53. "$@"
  54. }
  55. lmp_activate_packages() {
  56. # Build packages
  57. local packages=( yes-asphere yes-body yes-class2 yes-colloid \
  58. yes-coreshell yes-dipole yes-fld yes-granular yes-kspace \
  59. yes-manybody yes-mc yes-meam yes-misc \
  60. $(usex mpi "yes-user-atc" "") \
  61. yes-molecule yes-opt yes-peri yes-poems yes-qeq yes-reax \
  62. yes-replica yes-rigid yes-shock yes-snap yes-srd \
  63. yes-user-eff yes-user-fep \
  64. $(usex mpi "yes-user-lb" "") \
  65. yes-user-phonon yes-user-sph yes-voronoi yes-xtc )
  66. for p in ${packages[@]}; do
  67. lmp_emake -C src ${p}
  68. done
  69. }
  70. lmp_build_packages() {
  71. lmp_emake -C lib/meam -j1 -f Makefile.gfortran
  72. lmp_emake -C lib/poems -f Makefile.g++
  73. lmp_emake -C lib/reax -j1 -f Makefile.gfortran
  74. use mpi && lmp_emake -C lib/atc -f Makefile.g++
  75. }
  76. lmp_clean_packages() {
  77. lmp_emake -C lib/meam -f Makefile.gfortran clean
  78. lmp_emake -C lib/poems -f Makefile.g++ clean
  79. lmp_emake -C lib/reax -f Makefile.gfortran clean
  80. use mpi && lmp_emake -C lib/atc -f Makefile.g++ clean
  81. }
  82. src_prepare() {
  83. # Fix inconsistent use of SHFLAGS.
  84. sed -i \
  85. -e 's:voronoi_SYSINC\s\+=.*$:voronoi_SYSINC = -I/usr/include/voro++:' \
  86. -e 's:voronoi_SYSPATH\s\+=.*$:voronoi_SYSPATH =:' \
  87. lib/voronoi/Makefile.lammps || die
  88. # Fix missing .so name.
  89. sed -i \
  90. -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
  91. src/MAKE/Makefile.serial || die
  92. # Fix makefile in tools.
  93. sed -i \
  94. -e 's:g++:$(CXX) $(CXXFLAGS):' \
  95. -e 's:gcc:$(CC) $(CCFLAGS):' \
  96. -e 's:ifort:$(FC) $(FCFLAGS):' \
  97. tools/Makefile || die
  98. eapply "${PATCHES[@]}"
  99. eapply_user
  100. }
  101. src_compile() {
  102. # Fix atc...
  103. append-cxxflags -I../../src
  104. # Acticate packages.
  105. elog "Activating lammps packages..."
  106. lmp_activate_packages
  107. # STUBS/mpi.c is using '#include <mpi.h>' now instead of '#include
  108. # "mpi.h"' which requires an additional '-I.'.
  109. append-cxxflags -I.
  110. # Compile stubs for serial version.
  111. use mpi || lmp_emake -C src mpi-stubs
  112. elog "Building packages..."
  113. lmp_build_packages
  114. if use static-libs; then
  115. # Build static library.
  116. elog "Building static library..."
  117. lmp_emake -C src mode=lib serial
  118. fi
  119. # Clean out packages (that's not done by the build system with the clean
  120. # target), so we can rebuild the packages with -fPIC.
  121. elog "Cleaning packages..."
  122. lmp_clean_packages
  123. # The build system does not rebuild the packages with -fPIC, adding flag
  124. # manually.
  125. append-cxxflags -fPIC
  126. append-fflags -fPIC
  127. # Compile stubs for serial version.
  128. use mpi || lmp_emake -C src mpi-stubs
  129. elog "Building packages..."
  130. lmp_build_packages
  131. # Build shared library.
  132. elog "Building shared library..."
  133. lmp_emake -C src mode=shlib serial
  134. # Compile main executable. The shared library is always built, and
  135. # mode=shexe is simply a way to re-use the object files built in the
  136. # "shlib" step when linking the executable. The executable is not actually
  137. # using the shared library. If we have built the static library, then we
  138. # link that into the executable.
  139. elog "Linking executable..."
  140. if use static-libs; then
  141. lmp_emake -C src mode=exe serial
  142. else
  143. lmp_emake -C src mode=shexe serial
  144. fi
  145. # Compile tools.
  146. elog "Building tools..."
  147. lmp_emake -C tools binary2txt chain data2xmovie micelle2d
  148. }
  149. src_install() {
  150. use static-libs && newlib.a src/liblammps_serial.a liblammps.a
  151. newlib.so src/liblammps_serial.so liblammps.so.0.0.0
  152. dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so
  153. dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so.0
  154. newbin src/lmp_serial lmp
  155. dobin tools/binary2txt
  156. dobin tools/chain
  157. dobin tools/data2xmovie
  158. dobin tools/micelle2d
  159. # Don't forget to add header files of optional packages as they are added
  160. # to this ebuild. There may also be .mod files from Fortran based
  161. # packages.
  162. insinto "/usr/include/${PN}"
  163. doins -r src/*.h lib/meam/*.mod
  164. local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
  165. insinto "/${LAMMPS_POTENTIALS}"
  166. doins potentials/*
  167. echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
  168. doenvd 99lammps
  169. # Install python script.
  170. use python && python_foreach_impl python_domodule python/lammps.py
  171. if use examples; then
  172. local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
  173. insinto "${LAMMPS_EXAMPLES}"
  174. doins -r examples/*
  175. fi
  176. dodoc README
  177. if use doc; then
  178. dodoc doc/Manual.pdf
  179. dohtml -r doc/*
  180. fi
  181. }