aboutsummaryrefslogtreecommitdiff
blob: a227c0be74da61156ad99745684d4fd992d4b364 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=5

inherit eutils multilib toolchain-funcs fortran-2

PATCHDATE="14Feb17"

DESCRIPTION="Material eXplorer"
HOMEPAGE="http://www.openmx-square.org/"
SRC_URI="
	http://www.openmx-square.org/${PN}${PV%.[0-9]}.tar.gz
	http://www.openmx-square.org/bugfixed/${PATCHDATE}/patch${PV}.tar.gz"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="-debug mpi openmp test"

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

S="${WORKDIR}/${PN}${PV%.[0-9]}"

MAKEOPTS+=" -j1"

FORTRAN_STANDARD=90

pkg_setup() {
	# Link in the GNU Fortran library for Fortran code.
	# Other compilers may need other hacks.
	FC_LIB=""
	if [[ $(tc-getCC)$ == *gcc* ]]; then
		FC_LIB="-lgfortran"
	fi
	export FC_LIB

	if use mpi; then
		export CC="mpicc"
		export FC="mpif90"
	else
		tc-export CC
		tc-export FC
	fi

	if use openmp; then FORTRAN_NEED_OPENMP=1; fi

	fortran-2_pkg_setup

	if use openmp; then
		# based on _fortran-has-openmp() of fortran-2.eclass
		local code=ebuild-openmp-flags
		local ret
		local openmp

		pushd "${T}"
		cat <<- EOF > "${code}.c"
		# include <omp.h>
		main () {
			int nthreads;
			nthreads=omp_get_num_threads();
		}
		EOF

		for openmp in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
			${CC} ${openmp} "${code}.c" -o "${code}.o" &>> "${T}"/_c_compile_test.log
			ret=$?
			(( ${ret} )) || break
		done

		rm -f "${code}.*"
		popd

		if (( ${ret} )); then
			die "Please switch to an openmp compatible C compiler"
		else
			export CC="${CC} ${openmp}"
		fi

		pushd "${T}"
		cat <<- EOF > "${code}.f"
		1     call omp_get_num_threads
		2     end
		EOF

		for openmp in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp; do
			${FC} ${openmp} "${code}.f" -o "${code}.o" &>> "${T}"/_f_compile_test.log
			ret=$?
			(( ${ret} )) || break
		done

		rm -f "${code}.*"
		popd

		if (( ${ret} )); then
			die "Please switch to an openmp compatible fortran compiler"
		else
			export FC="${FC} ${openmp}"
		fi
	fi

}

src_prepare() {
	cd "${WORKDIR}"
	mv *.[hc] "${S}"/source
	epatch "${FILESDIR}/3.7-fortran_objects.patch"
}

src_configure() {
	local FFTW_FLAVOUR=fftw3
	if use openmp; then
	   FFTW_FLAVOUR=fftw3_omp
	else
	   export CFLAGS="${CFLAGS} -Dnoomp"
	fi
	if use mpi; then
	   FFTW_FLAVOUR=fftw3_mpi
	else
	   export CFLAGS="${CFLAGS} -Dnompi"
	fi
	CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) --cflags lapack)"
	CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) --cflags ${FFTW_FLAVOUR})"
	export CFLAGS

	FCFLAGS="${FCFLAGS} -I/usr/include"
	FCFLAGS="${FCFLAGS} $($(tc-getPKG_CONFIG) --cflags lapack)"
	FCFLAGS="${FCFLAGS} $($(tc-getPKG_CONFIG) --cflags ${FFTW_FLAVOUR})"
	export FCFLAGS

	local MX_LIB="$($(tc-getPKG_CONFIG) --static --libs lapack)"
	MX_LIB="${MX_LIB} $($(tc-getPKG_CONFIG) --static --libs ${FFTW_FLAVOUR})"
	if use mpi; then
		MX_LIB="${MX_LIB} $(mpif90 -showme:link)"
	fi

	sed \
		-e "s%^CC *=.*$%CC  = ${CC} ${CFLAGS}%" \
		-e "s%^FC *=.*$%FC  = ${FC} ${FCFLAGS}%" \
		-e "s%^LIB *=.*$%LIB = ${MX_LIB} ${FC_LIB}%" \
		-i source/makefile || die
}

src_compile() {
	emake -C source
}

src_test() {
	cd work
	../source/openmx -runtest || die
}

src_install() {
	insinto /usr/share/${P}
	doins -r DFT_DATA13
	cd work
	insinto /usr/share/${P}/examples
	doins -r *
	cd ../source
	dodir /usr/bin
	emake DESTDIR="${D}/usr/bin" install
	dodoc "${S}/${PN}${PV%.?}.pdf"
	use test && dodoc "${S}"/work/runtest.result
}