1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 )
8 inherit eutils flag-o-matic fortran-2 multilib python-r1
11 local months=( "" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
12 echo ${months[${1#0}]}
15 MY_P=${PN}-$((10#${PV:6:2}))$(convert_month ${PV:4:2})${PV:2:2}
17 DESCRIPTION="Large-scale Atomic/Molecular Massively Parallel Simulator"
18 HOMEPAGE="https://lammps.sandia.gov/"
19 SRC_URI="https://lammps.sandia.gov/tars/${MY_P}.tar.gz"
23 KEYWORDS="~amd64 ~x86"
24 IUSE="doc examples gzip lammps-memalign mpi python static-libs"
26 # blas/lapack is needed by the ATC package which is only built with MPI.
28 gzip? ( app-arch/gzip )
32 python? ( ${PYTHON_DEPS} )
39 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
41 S="${WORKDIR}/${MY_P}"
44 "${FILESDIR}/fm_exp.patch"
48 local LAMMPS_INCLUDEFLAGS
49 LAMMPS_INCLUDEFLAGS="$(usex gzip '-DLAMMPS_GZIP' '')"
50 LAMMPS_INCLUDEFLAGS+="$(usex lammps-memalign ' -DLAMMPS_MEMALIGN=64' '')"
52 # The lammps makefile uses CC to indicate the C++ compiler.
54 ARCHIVE="$(tc-getAR)" \
55 CC="$(usex mpi "mpic++" "$(tc-getCXX)")" \
56 F90="$(usex mpi "mpif90" "$(tc-getFC)")" \
57 LINK="$(usex mpi "mpic++" "$(tc-getCXX)")" \
58 CCFLAGS="${CXXFLAGS}" \
59 F90FLAGS="${FCFLAGS}" \
60 LINKFLAGS="${LDFLAGS}" \
61 LMP_INC="${LAMMPS_INCLUDEFLAGS}" \
62 MPI_INC="$(usex mpi "" "-I../STUBS")" \
63 MPI_PATH="$(usex mpi "" "-L../STUBS")" \
64 MPI_LIB="$(usex mpi "" "-lmpi_stubs")" \
65 user-atc_SYSLIB="$(usex mpi "$($(tc-getPKG_CONFIG) --libs blas) $($(tc-getPKG_CONFIG) --libs lapack)" '')"\
69 lmp_activate_packages() {
71 local packages=( yes-asphere yes-body yes-class2 yes-colloid \
72 yes-coreshell yes-dipole yes-fld yes-granular yes-kspace \
73 yes-manybody yes-mc yes-meam yes-misc \
74 $(usex mpi "yes-user-atc" "") \
75 yes-molecule yes-opt yes-peri yes-poems yes-qeq yes-reax \
76 yes-replica yes-rigid yes-shock yes-snap yes-srd \
77 yes-user-eff yes-user-fep \
78 $(usex mpi "yes-user-lb" "") \
79 yes-user-phonon yes-user-sph yes-voronoi yes-xtc )
81 for p in ${packages[@]}; do
86 lmp_build_packages() {
87 lmp_emake -C lib/meam -j1 -f Makefile.gfortran
88 lmp_emake -C lib/poems -f Makefile.g++
89 lmp_emake -C lib/reax -j1 -f Makefile.gfortran
90 use mpi && lmp_emake -C lib/atc -f Makefile.g++
93 lmp_clean_packages() {
94 lmp_emake -C lib/meam -f Makefile.gfortran clean
95 lmp_emake -C lib/poems -f Makefile.g++ clean
96 lmp_emake -C lib/reax -f Makefile.gfortran clean
97 use mpi && lmp_emake -C lib/atc -f Makefile.g++ clean
101 # Fix inconsistent use of SHFLAGS.
103 -e 's:voronoi_SYSINC\s\+=.*$:voronoi_SYSINC = -I/usr/include/voro++:' \
104 -e 's:voronoi_SYSPATH\s\+=.*$:voronoi_SYSPATH =:' \
105 lib/voronoi/Makefile.lammps || die
107 # Fix missing .so name.
109 -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
110 src/MAKE/Makefile.serial || die
112 # Fix makefile in tools.
114 -e 's:g++:$(CXX) $(CXXFLAGS):' \
115 -e 's:gcc:$(CC) $(CCFLAGS):' \
116 -e 's:ifort:$(FC) $(FCFLAGS):' \
117 tools/Makefile || die
119 eapply "${PATCHES[@]}"
125 append-cxxflags -I../../src
128 elog "Activating lammps packages..."
129 lmp_activate_packages
131 # STUBS/mpi.c is using '#include <mpi.h>' now instead of '#include
132 # "mpi.h"' which requires an additional '-I.'.
135 # Compile stubs for serial version.
136 use mpi || lmp_emake -C src mpi-stubs
138 elog "Building packages..."
141 if use static-libs; then
142 # Build static library.
143 elog "Building static library..."
144 lmp_emake -C src mode=lib serial
147 # Clean out packages (that's not done by the build system with the clean
148 # target), so we can rebuild the packages with -fPIC.
149 elog "Cleaning packages..."
152 # The build system does not rebuild the packages with -fPIC, adding flag
154 append-cxxflags -fPIC
157 # Compile stubs for serial version.
158 use mpi || lmp_emake -C src mpi-stubs
160 elog "Building packages..."
163 # Build shared library.
164 elog "Building shared library..."
165 lmp_emake -C src mode=shlib serial
167 # Compile main executable. The shared library is always built, and
168 # mode=shexe is simply a way to re-use the object files built in the
169 # "shlib" step when linking the executable. The executable is not actually
170 # using the shared library. If we have built the static library, then we
171 # link that into the executable.
172 elog "Linking executable..."
173 if use static-libs; then
174 lmp_emake -C src mode=exe serial
176 lmp_emake -C src mode=shexe serial
180 elog "Building tools..."
181 lmp_emake -C tools binary2txt chain data2xmovie micelle2d
185 use static-libs && newlib.a src/liblammps_serial.a liblammps.a
186 newlib.so src/liblammps_serial.so liblammps.so.0.0.0
187 dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so
188 dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so.0
189 newbin src/lmp_serial lmp
190 dobin tools/binary2txt
192 dobin tools/data2xmovie
193 dobin tools/micelle2d
194 # Don't forget to add header files of optional packages as they are added
195 # to this ebuild. There may also be .mod files from Fortran based
197 insinto "/usr/include/${PN}"
198 doins -r src/*.h lib/meam/*.mod
200 local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
201 insinto "/${LAMMPS_POTENTIALS}"
203 echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
206 # Install python script.
207 use python && python_foreach_impl python_domodule python/lammps.py
209 if use examples; then
210 local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
211 insinto "${LAMMPS_EXAMPLES}"