dev-libs/botan: ppc stable wrt bug #574034
[gentoo.git] / sci-physics / lammps / lammps-20151022.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 PYTHON_COMPAT=( python{2_7,3_3} )
8
9 inherit eutils flag-o-matic fortran-2 multilib python-r1
10
11 convert_month() {
12         local months=( "" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )
13         echo ${months[${1#0}]}
14 }
15
16 MY_P=${PN}-$((10#${PV:6:2}))$(convert_month ${PV:4:2})${PV:2:2}
17
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"
21
22 LICENSE="GPL-2"
23 SLOT="0"
24 KEYWORDS="~amd64 ~x86"
25 IUSE="doc examples gzip lammps-memalign mpi python static-libs"
26
27 DEPEND="
28         mpi? (
29                 virtual/blas
30                 virtual/lapack
31                 virtual/mpi
32         )
33         gzip? ( app-arch/gzip )
34         sci-libs/voro++
35         python? ( ${PYTHON_DEPS} )
36         "
37 RDEPEND="${DEPEND}"
38
39 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
40
41 S="${WORKDIR}/${MY_P}"
42
43 lmp_emake() {
44         local LAMMPS_INCLUDEFLAGS
45         LAMMPS_INCLUDEFLAGS="$(usex gzip '-DLAMMPS_GZIP' '')"
46         LAMMPS_INCLUDEFLAGS+="$(usex lammps-memalign ' -DLAMMPS_MEMALIGN=64' '')"
47
48         # The lammps makefile uses CC to indicate the C++ compiler.
49         emake \
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)" '')"\
62                 "$@"
63 }
64
65 lmp_activate_packages() {
66         # Build packages
67         lmp_emake -C src yes-asphere
68         lmp_emake -C src yes-body
69         lmp_emake -C src yes-class2
70         lmp_emake -C src yes-colloid
71         lmp_emake -C src yes-coreshell
72         lmp_emake -C src yes-dipole
73         lmp_emake -C src yes-fld
74         #lmp_emake -C src yes-gpu
75         lmp_emake -C src yes-granular
76         # Need OpenKIM external dependency.
77         #lmp_emake -C src yes-kim
78         # Need Kokkos external dependency.
79         #lmp_emake -C src yes-kokkos
80         lmp_emake -C src yes-kspace
81         lmp_emake -C src yes-manybody
82         lmp_emake -C src yes-mc
83         lmp_emake -C src yes-meam
84         lmp_emake -C src yes-misc
85         lmp_emake -C src yes-molecule
86         #lmp_emake -C src yes-mpiio
87         lmp_emake -C src yes-opt
88         lmp_emake -C src yes-peri
89         lmp_emake -C src yes-poems
90         lmp_emake -C src yes-qeq
91         lmp_emake -C src yes-reax
92         lmp_emake -C src yes-replica
93         lmp_emake -C src yes-rigid
94         lmp_emake -C src yes-shock
95         lmp_emake -C src yes-snap
96         lmp_emake -C src yes-srd
97         lmp_emake -C src yes-voronoi
98         lmp_emake -C src yes-xtc
99
100         if use mpi; then
101                 lmp_emake -C src yes-user-atc
102         fi
103         lmp_emake -C src yes-user-eff
104         lmp_emake -C src yes-user-fep
105         use mpi && lmp_emake -C src yes-user-lb
106         lmp_emake -C src yes-user-phonon
107         lmp_emake -C src yes-user-sph
108 }
109
110 lmp_build_packages() {
111         lmp_emake -C lib/meam -j1 -f Makefile.gfortran
112         lmp_emake -C lib/poems -f Makefile.g++
113         lmp_emake -C lib/reax -j1 -f Makefile.gfortran
114         use mpi && lmp_emake -C lib/atc -f Makefile.g++
115 }
116
117 lmp_clean_packages() {
118         lmp_emake -C lib/meam -f Makefile.gfortran clean
119         lmp_emake -C lib/poems -f Makefile.g++ clean
120         lmp_emake -C lib/reax -f Makefile.gfortran clean
121         use mpi && lmp_emake -C lib/atc -f Makefile.g++ clean
122 }
123
124 src_prepare() {
125         # Fix inconsistent use of SHFLAGS.
126         sed -i \
127                 -e 's:voronoi_SYSINC\s\+=.*$:voronoi_SYSINC = -I/usr/include/voro++:' \
128                 -e 's:voronoi_SYSPATH\s\+=.*$:voronoi_SYSPATH =:' \
129                 lib/voronoi/Makefile.lammps || die
130
131         # Fix missing .so name.
132         sed -i \
133                 -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
134                 src/MAKE/Makefile.serial || die
135
136         # Fix makefile in tools.
137         sed -i \
138                 -e 's:g++:$(CXX) $(CXXFLAGS):' \
139                 -e 's:gcc:$(CC) $(CCFLAGS):' \
140                 -e 's:ifort:$(FC) $(FCFLAGS):' \
141                 tools/Makefile || die
142
143         # Patch python.
144         epatch "${FILESDIR}/lammps-python3-r1.patch"
145         epatch "${FILESDIR}/python-shebang.patch"
146 }
147
148 src_compile() {
149         # Fix atc...
150         append-cxxflags -I../../src
151
152         # Acticate packages.
153         elog "Activating lammps packages..."
154         lmp_activate_packages
155
156         # Compile stubs for serial version.
157         use mpi || lmp_emake -C src mpi-stubs
158
159         elog "Building packages..."
160         lmp_build_packages
161
162         if use static-libs; then
163                 # Build static library.
164                 elog "Building static library..."
165                 lmp_emake -C src mode=lib serial
166         fi
167
168         # Clean out packages (that's not done by the build system with the clean
169         # target), so we can rebuild the packages with -fPIC.
170         elog "Cleaning packages..."
171         lmp_clean_packages
172
173         # The build system does not rebuild the packages with -fPIC, adding flag
174         # manually.
175         append-cxxflags -fPIC
176         append-fflags -fPIC
177
178         # Compile stubs for serial version.
179         use mpi || lmp_emake -C src mpi-stubs
180
181         elog "Building packages..."
182         lmp_build_packages
183
184         # Build shared library.
185         elog "Building shared library..."
186         lmp_emake -C src mode=shlib serial
187
188         # Compile main executable. The shared library is always built, and
189         # mode=shexe is simply a way to re-use the object files built in the
190         # "shlib" step when linking the executable. The executable is not actually
191         # using the shared library. If we have built the static library, then we
192         # link that into the executable.
193         elog "Linking executable..."
194         if use static-libs; then
195                 lmp_emake -C src mode=exe serial
196         else
197                 lmp_emake -C src mode=shexe serial
198         fi
199
200         # Compile tools.
201         elog "Building tools..."
202         lmp_emake -C tools binary2txt chain data2xmovie micelle2d
203 }
204
205 src_install() {
206         use static-libs && newlib.a src/liblammps_serial.a liblammps.a
207         newlib.so src/liblammps_serial.so liblammps.so.0.0.0
208         dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so
209         dosym liblammps.so.0.0.0 /usr/$(get_libdir)/liblammps.so.0
210         newbin src/lmp_serial lmp
211         dobin tools/binary2txt
212         dobin tools/chain
213         dobin tools/data2xmovie
214         dobin tools/micelle2d
215         # Don't forget to add header files of optional packages as they are added
216         # to this ebuild. There may also be .mod files from Fortran based
217         # packages.
218         insinto "/usr/include/${PN}"
219         doins -r src/*.h lib/meam/*.mod
220
221         local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
222         insinto "/${LAMMPS_POTENTIALS}"
223         doins potentials/*
224         echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
225         doenvd 99lammps
226
227         # Install python script.
228         use python && python_foreach_impl python_domodule python/lammps.py
229
230         if use examples; then
231                 local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
232                 insinto "${LAMMPS_EXAMPLES}"
233                 doins -r examples/*
234         fi
235
236         dodoc README
237         if use doc; then
238                 dodoc doc/Manual.pdf
239                 dohtml -r doc/*
240         fi
241 }