dev-perl/Test-MockModule: Add ~sh keyword wrt bug #690140
[gentoo.git] / sci-physics / lammps / lammps-20160730.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python2_7 )
7
8 inherit eutils flag-o-matic fortran-2 multilib python-r1
9
10 convert_month() {
11         local months=( "" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
12         echo ${months[${1#0}]}
13 }
14
15 MY_P=${PN}-$((10#${PV:6:2}))$(convert_month ${PV:4:2})${PV:2:2}
16
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"
20
21 LICENSE="GPL-2"
22 SLOT="0"
23 KEYWORDS="~amd64 ~x86"
24 IUSE="doc examples gzip lammps-memalign mpi python static-libs"
25
26 # blas/lapack is needed by the ATC package which is only built with MPI.
27 DEPEND="
28         gzip? ( app-arch/gzip )
29         mpi? (
30                 virtual/mpi
31         )
32         python? ( ${PYTHON_DEPS} )
33         sci-libs/voro++
34         virtual/blas
35         virtual/lapack
36         "
37 RDEPEND="${DEPEND}"
38
39 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
40
41 S="${WORKDIR}/${MY_P}"
42
43 PATCHES=(
44         "${FILESDIR}/fm_exp.patch"
45 )
46
47 lmp_emake() {
48         local LAMMPS_INCLUDEFLAGS
49         LAMMPS_INCLUDEFLAGS="$(usex gzip '-DLAMMPS_GZIP' '')"
50         LAMMPS_INCLUDEFLAGS+="$(usex lammps-memalign ' -DLAMMPS_MEMALIGN=64' '')"
51
52         # The lammps makefile uses CC to indicate the C++ compiler.
53         emake \
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)" '')"\
66                 "$@"
67 }
68
69 lmp_activate_packages() {
70         # Build 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 )
80
81         for p in ${packages[@]}; do
82                 lmp_emake -C src ${p}
83         done
84 }
85
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++
91 }
92
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
98 }
99
100 src_prepare() {
101         # Fix inconsistent use of SHFLAGS.
102         sed -i \
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
106
107         # Fix missing .so name.
108         sed -i \
109                 -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
110                 src/MAKE/Makefile.serial || die
111
112         # Fix makefile in tools.
113         sed -i \
114                 -e 's:g++:$(CXX) $(CXXFLAGS):' \
115                 -e 's:gcc:$(CC) $(CCFLAGS):' \
116                 -e 's:ifort:$(FC) $(FCFLAGS):' \
117                 tools/Makefile || die
118
119         eapply "${PATCHES[@]}"
120         eapply_user
121 }
122
123 src_compile() {
124         # Fix atc...
125         append-cxxflags -I../../src
126
127         # Acticate packages.
128         elog "Activating lammps packages..."
129         lmp_activate_packages
130
131         # STUBS/mpi.c is using '#include <mpi.h>' now instead of '#include
132         # "mpi.h"' which requires an additional '-I.'.
133         append-cxxflags -I.
134
135         # Compile stubs for serial version.
136         use mpi || lmp_emake -C src mpi-stubs
137
138         elog "Building packages..."
139         lmp_build_packages
140
141         if use static-libs; then
142                 # Build static library.
143                 elog "Building static library..."
144                 lmp_emake -C src mode=lib serial
145         fi
146
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..."
150         lmp_clean_packages
151
152         # The build system does not rebuild the packages with -fPIC, adding flag
153         # manually.
154         append-cxxflags -fPIC
155         append-fflags -fPIC
156
157         # Compile stubs for serial version.
158         use mpi || lmp_emake -C src mpi-stubs
159
160         elog "Building packages..."
161         lmp_build_packages
162
163         # Build shared library.
164         elog "Building shared library..."
165         lmp_emake -C src mode=shlib serial
166
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
175         else
176                 lmp_emake -C src mode=shexe serial
177         fi
178
179         # Compile tools.
180         elog "Building tools..."
181         lmp_emake -C tools binary2txt chain data2xmovie micelle2d
182 }
183
184 src_install() {
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
191         dobin tools/chain
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
196         # packages.
197         insinto "/usr/include/${PN}"
198         doins -r src/*.h lib/meam/*.mod
199
200         local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
201         insinto "/${LAMMPS_POTENTIALS}"
202         doins potentials/*
203         echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
204         doenvd 99lammps
205
206         # Install python script.
207         use python && python_foreach_impl python_domodule python/lammps.py
208
209         if use examples; then
210                 local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
211                 insinto "${LAMMPS_EXAMPLES}"
212                 doins -r examples/*
213         fi
214
215         dodoc README
216         if use doc; then
217                 dodoc doc/Manual.pdf
218                 dohtml -r doc/*
219         fi
220 }