dev-libs/botan: ppc stable wrt bug #574034
[gentoo.git] / sci-physics / lammps / lammps-20151026.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,3_4} )
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         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 )
76
77         for p in ${packages[@]}; do
78                 lmp_emake -C src ${p}
79         done
80 }
81
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++
87 }
88
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
94 }
95
96 src_prepare() {
97         # Fix inconsistent use of SHFLAGS.
98         sed -i \
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
102
103         # Fix missing .so name.
104         sed -i \
105                 -e 's:SHLIBFLAGS\s\+=\s\+:SHLIBFLAGS = -Wl,-soname,liblammps.so.0 :' \
106                 src/MAKE/Makefile.serial || die
107
108         # Fix makefile in tools.
109         sed -i \
110                 -e 's:g++:$(CXX) $(CXXFLAGS):' \
111                 -e 's:gcc:$(CC) $(CCFLAGS):' \
112                 -e 's:ifort:$(FC) $(FCFLAGS):' \
113                 tools/Makefile || die
114
115         # Patch python.
116         epatch "${FILESDIR}/lammps-python3-r1.patch"
117         epatch "${FILESDIR}/python-shebang.patch"
118 }
119
120 src_compile() {
121         # Fix atc...
122         append-cxxflags -I../../src
123
124         # Acticate packages.
125         elog "Activating lammps packages..."
126         lmp_activate_packages
127
128         # Compile stubs for serial version.
129         use mpi || lmp_emake -C src mpi-stubs
130
131         elog "Building packages..."
132         lmp_build_packages
133
134         if use static-libs; then
135                 # Build static library.
136                 elog "Building static library..."
137                 lmp_emake -C src mode=lib serial
138         fi
139
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..."
143         lmp_clean_packages
144
145         # The build system does not rebuild the packages with -fPIC, adding flag
146         # manually.
147         append-cxxflags -fPIC
148         append-fflags -fPIC
149
150         # Compile stubs for serial version.
151         use mpi || lmp_emake -C src mpi-stubs
152
153         elog "Building packages..."
154         lmp_build_packages
155
156         # Build shared library.
157         elog "Building shared library..."
158         lmp_emake -C src mode=shlib serial
159
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
168         else
169                 lmp_emake -C src mode=shexe serial
170         fi
171
172         # Compile tools.
173         elog "Building tools..."
174         lmp_emake -C tools binary2txt chain data2xmovie micelle2d
175 }
176
177 src_install() {
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
184         dobin tools/chain
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
189         # packages.
190         insinto "/usr/include/${PN}"
191         doins -r src/*.h lib/meam/*.mod
192
193         local LAMMPS_POTENTIALS="usr/share/${PN}/potentials"
194         insinto "/${LAMMPS_POTENTIALS}"
195         doins potentials/*
196         echo "LAMMPS_POTENTIALS=${EROOT}${LAMMPS_POTENTIALS}" > 99lammps
197         doenvd 99lammps
198
199         # Install python script.
200         use python && python_foreach_impl python_domodule python/lammps.py
201
202         if use examples; then
203                 local LAMMPS_EXAMPLES="/usr/share/${PN}/examples"
204                 insinto "${LAMMPS_EXAMPLES}"
205                 doins -r examples/*
206         fi
207
208         dodoc README
209         if use doc; then
210                 dodoc doc/Manual.pdf
211                 dohtml -r doc/*
212         fi
213 }