summaryrefslogtreecommitdiff
blob: 1d2218c8311d1a3cd95a23d61ab73208c260ecb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=6
PYTHON_COMPAT=( python{2_6,2_7} )

inherit flag-o-matic fortran-2 toolchain-funcs python-any-r1

FORTRAN_STANDARD=2003
FORTRAN_NEED_OPENMP=1
# OpenMP support would be optional

DESCRIPTION="Quantum chemistry and solid state physics software package"
HOMEPAGE="https://www.cp2k.org/"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE="+fftw openmp"

RDEPEND="virtual/blas
	fftw? ( sci-libs/fftw:3.0=[fortran,openmp?,threads] )"
DEPEND="${RDEPEND}
	virtual/pkgconfig
	${PYTHON_DEPS}"

pkg_setup() {
	python-any-r1_pkg_setup
	fortran-2_pkg_setup
}

src_configure() {
	if use openmp ; then
		append-fflags -fopenmp
		append-ldflags -fopenmp
	fi

	declare -a libs defines

	if use fftw ; then
		if use openmp ; then
			libs+=($(pkg-config --libs fftw3))
		else
			libs+=($(pkg-config --libs fftw3_omp))
		fi
		defines+=(-D__FFTW3)
		echo ${defines[*]}
	fi

	cat > arch/custom.gentoo << EOF
CC         = $(tc-getCC)
# empty CPP var makes it use the compiler directly instead of two-step
CPP        =
FC         = $(tc-getFC)
LD         = $(tc-getFC)
AR         = $(tc-getAR) -r
CPPFLAGS   = ${defines[*]} ${CPPFLAGS}
FCFLAGS    = -ffree-form -ffree-line-length-none ${defines[*]} ${CPPFLAGS} ${FCFLAGS}
LDFLAGS    = ${LDFLAGS}
LIBS       = $(pkg-config --libs lapack) ${libs[*]}
DATA_DIR   = ${EPREFIX}/usr/share/cp2k
EOF
}

src_compile() {
	cd makefiles # using `-C makefiles` does not work, because "reasons"
	emake ARCH=custom VERSION=gentoo
}

src_install() {
	for e in cp2k cp2k_shell ; do
		newbin exe/custom/$e.gentoo $e
	done

	insinto /usr/share/cp2k
	doins -r data/*

	dodoc README
}