lammps-20160115.ebuild 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/blas
  23. virtual/lapack
  24. virtual/mpi
  25. )
  26. python? ( ${PYTHON_DEPS} )
  27. sci-libs/voro++
  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-r1.patch"
  97. epatch "${FILESDIR}/python-shebang.patch"
  98. }
  99. src_compile() {
  100. # Fix atc...
  101. append-cxxflags -I../../src
  102. # Acticate packages.
  103. elog "Activating lammps packages..."
  104. lmp_activate_packages
  105. # STUBS/mpi.c is using '#include <mpi.h>' now instead of '#include
  106. # "mpi.h"' which requires an additional '-I.'.
  107. append-cxxflags -I.
  108. # Compile stubs for serial version.
  109. use mpi || lmp_emake -C src mpi-stubs
  110. elog "Building packages..."
  111. lmp_build_packages
  112. if use static-libs; then
  113. # Build static library.
  114. elog "Building static library..."
  115. lmp_emake -C src mode=lib serial
  116. fi
  117. # Clean out packages (that's not done by the build system with the clean
  118. # target), so we can rebuild the packages with -fPIC.
  119. elog "Cleaning packages..."
  120. lmp_clean_packages
  121. # The build system does not rebuild the packages with -fPIC, adding flag
  122. # manually.
  123. append-cxxflags -fPIC
  124. append-fflags -fPIC
  125. # Compile stubs for serial version.
  126. use mpi || lmp_emake -C src mpi-stubs
  127. elog "Building packages..."
  128. lmp_build_packages
  129. # Build shared library.
  130. elog "Building shared library..."
  131. lmp_emake -C src mode=shlib serial
  132. # Compile main executable. The shared library is always built, and
  133. # mode=shexe is simply a way to re-use the object files built in the
  134. # "shlib" step when linking the executable. The executable is not actually
  135. # using the shared library. If we have built the static library, then we
  136. # link that into the executable.
  137. elog "Linking executable..."
  138. if use static-libs; then
  139. lmp_emake -C src mode=exe serial
  140. else
  141. lmp_emake -C src mode=shexe serial
  142. fi
  143. # Compile tools.
  144. elog "Building tools..."
  145. lmp_emake -C tools binary2txt chain data2xmovie micelle2d
  146. }
  147. src_install() {
  148. use static-libs && newlib.a src/liblammps_serial.a liblammps.a
  149. newlib.so src/liblammps_serial.so liblammps.so.0.0.0
  150. dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so
  151. dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so.0
  152. newbin src/lmp_serial lmp
  153. dobin tools/binary2txt
  154. dobin tools/chain
  155. dobin tools/data2xmovie
  156. dobin tools/micelle2d
  157. # Don't forget to add header files of optional packages as they are added
  158. # to this ebuild. There may also be .mod files from Fortran based
  159. # packages.
  160. insinto "/usr/include/${PN}"
  161. doins -r src/*.h lib/meam/*.mod
  162. local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
  163. insinto "/${LAMMPS_POTENTIALS}"
  164. doins potentials/*
  165. echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
  166. doenvd 99lammps
  167. # Install python script.
  168. use python && python_foreach_impl python_domodule python/lammps.py
  169. if use examples; then
  170. local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
  171. insinto "${LAMMPS_EXAMPLES}"
  172. doins -r examples/*
  173. fi
  174. dodoc README
  175. if use doc; then
  176. dodoc doc/Manual.pdf
  177. dohtml -r doc/*
  178. fi
  179. }