lammps-20160407.ebuild 6.0 KB

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