1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 PYTHON_COMPAT=( python{2_7,3_3,3_4} )
9 inherit eutils flag-o-matic fortran-2 multilib python-r1
12 local months=( "" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
13 echo ${months[${1#0}]}
16 MY_P=${PN}-$((10#${PV:6:2}))$(convert_month ${PV:4:2})${PV:2:2}
18 DESCRIPTION="Large-scale Atomic/Molecular Massively Parallel Simulator"
19 HOMEPAGE="http://lammps.sandia.gov/"
20 SRC_URI="http://lammps.sandia.gov/tars/${MY_P}.tar.gz"
24 KEYWORDS="~amd64 ~x86"
25 IUSE="doc examples gzip lammps-memalign mpi python static-libs"
33 gzip? ( app-arch/gzip )
35 python? ( ${PYTHON_DEPS} )
39 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
41 S="${WORKDIR}/${MY_P}"
44 local LAMMPS_INCLUDEFLAGS
45 LAMMPS_INCLUDEFLAGS="$(usex gzip '-DLAMMPS_GZIP' '')"
46 LAMMPS_INCLUDEFLAGS+="$(usex lammps-memalign ' -DLAMMPS_MEMALIGN=64' '')"
48 # The lammps makefile uses CC to indicate the C++ compiler.
50 ARCHIVE="$(tc-getAR)" \
51 CC="$(usex mpi "mpic++" "$(tc-getCXX)")" \
52 F90="$(usex mpi "mpif90" "$(tc-getFC)")" \
53 LINK="$(usex mpi "mpic++" "$(tc-getCXX)")" \
54 CCFLAGS="${CXXFLAGS}" \
55 F90FLAGS="${FCFLAGS}" \
56 LINKFLAGS="${LDFLAGS}" \
57 LMP_INC="${LAMMPS_INCLUDEFLAGS}" \
58 MPI_INC="$(usex mpi "" "-I../STUBS")" \
59 MPI_PATH="$(usex mpi "" "-L../STUBS")" \
60 MPI_LIB="$(usex mpi "" "-lmpi_stubs")" \
61 user-atc_SYSLIB="$(usex mpi "$($(tc-getPKG_CONFIG) --libs blas) $($(tc-getPKG_CONFIG) --libs lapack)" '')"\
65 lmp_activate_packages() {
67 local packages=( yes-asphere yes-body yes-class2 yes-colloid \
68 yes-coreshell yes-dipole yes-fld yes-granular yes-kspace \
69 yes-manybody yes-mc yes-meam yes-misc \
70 $(usex mpi "yes-user-atc" "") \
71 yes-molecule yes-opt yes-peri yes-poems yes-qeq yes-reax \
72 yes-replica yes-rigid yes-shock yes-snap yes-srd \
73 yes-user-eff yes-user-fep \
74 $(usex mpi "yes-user-lb" "") \
75 yes-user-phonon yes-user-sph yes-voronoi yes-xtc )
77 for p in ${packages[@]}; do
82 lmp_build_packages() {
83 lmp_emake -C lib/meam -j1 -f Makefile.gfortran
84 lmp_emake -C lib/poems -f Makefile.g++
85 lmp_emake -C lib/reax -j1 -f Makefile.gfortran
86 use mpi && lmp_emake -C lib/atc -f Makefile.g++
89 lmp_clean_packages() {
90 lmp_emake -C lib/meam -f Makefile.gfortran clean
91 lmp_emake -C lib/poems -f Makefile.g++ clean
92 lmp_emake -C lib/reax -f Makefile.gfortran clean
93 use mpi && lmp_emake -C lib/atc -f Makefile.g++ clean
97 # Fix inconsistent use of SHFLAGS.
99 -e 's:voronoi_SYSINC\s\+=.*$:voronoi_SYSINC = -I/usr/include/voro++:' \
100 -e 's:voronoi_SYSPATH\s\+=.*$:voronoi_SYSPATH =:' \
101 lib/voronoi/Makefile.lammps || die
103 # Fix missing .so name.
105 -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
106 src/MAKE/Makefile.serial || die
108 # Fix makefile in tools.
110 -e 's:g++:$(CXX) $(CXXFLAGS):' \
111 -e 's:gcc:$(CC) $(CCFLAGS):' \
112 -e 's:ifort:$(FC) $(FCFLAGS):' \
113 tools/Makefile || die
116 epatch "${FILESDIR}/lammps-python3-r1.patch"
117 epatch "${FILESDIR}/python-shebang.patch"
122 append-cxxflags -I../../src
125 elog "Activating lammps packages..."
126 lmp_activate_packages
128 # Compile stubs for serial version.
129 use mpi || lmp_emake -C src mpi-stubs
131 elog "Building packages..."
134 if use static-libs; then
135 # Build static library.
136 elog "Building static library..."
137 lmp_emake -C src mode=lib serial
140 # Clean out packages (that's not done by the build system with the clean
141 # target), so we can rebuild the packages with -fPIC.
142 elog "Cleaning packages..."
145 # The build system does not rebuild the packages with -fPIC, adding flag
147 append-cxxflags -fPIC
150 # Compile stubs for serial version.
151 use mpi || lmp_emake -C src mpi-stubs
153 elog "Building packages..."
156 # Build shared library.
157 elog "Building shared library..."
158 lmp_emake -C src mode=shlib serial
160 # Compile main executable. The shared library is always built, and
161 # mode=shexe is simply a way to re-use the object files built in the
162 # "shlib" step when linking the executable. The executable is not actually
163 # using the shared library. If we have built the static library, then we
164 # link that into the executable.
165 elog "Linking executable..."
166 if use static-libs; then
167 lmp_emake -C src mode=exe serial
169 lmp_emake -C src mode=shexe serial
173 elog "Building tools..."
174 lmp_emake -C tools binary2txt chain data2xmovie micelle2d
178 use static-libs && newlib.a src/liblammps_serial.a liblammps.a
179 newlib.so src/liblammps_serial.so liblammps.so.0.0.0
180 dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so
181 dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so.0
182 newbin src/lmp_serial lmp
183 dobin tools/binary2txt
185 dobin tools/data2xmovie
186 dobin tools/micelle2d
187 # Don't forget to add header files of optional packages as they are added
188 # to this ebuild. There may also be .mod files from Fortran based
190 insinto "/usr/include/${PN}"
191 doins -r src/*.h lib/meam/*.mod
193 local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
194 insinto "/${LAMMPS_POTENTIALS}"
196 echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
199 # Install python script.
200 use python && python_foreach_impl python_domodule python/lammps.py
202 if use examples; then
203 local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
204 insinto "${LAMMPS_EXAMPLES}"