aboutsummaryrefslogtreecommitdiff
blob: b2feb7fc7cedbc56683dd6faf3a300152a3a8107 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=4
inherit eutils toolchain-funcs versionator alternatives-2 multilib

LAPACKP=lapack-3.3.1

DESCRIPTION="Automatically Tuned Linear Algebra Software"
HOMEPAGE="http://math-atlas.sourceforge.net/"
SRC_URI="mirror://sourceforge/math-atlas/${PN}${PV}.tar.bz2
	fortran? ( lapack? ( http://www.netlib.org/lapack/${LAPACKP}.tgz ) )"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~x86 ~amd64-linux"
IUSE="fortran doc lapack static-libs threads"

RDEPEND="fortran? ( virtual/fortran )"
DEPEND="${RDEPEND}
	!prefix? ( sys-power/cpufrequtils )"

S="${WORKDIR}/ATLAS"

lapack_compile() {
	cd "${WORKDIR}/${LAPACKP}"
	local timer=INT_CPU_TIME
	case $(tc-getFC) in
		*gfortran|*g77) timer=INT_ETIME ;;
		*ifort) timer=EXT_ETIME ;;
	esac
	cat > make.inc <<-EOF
		FORTRAN = $(tc-getFC)
		OPTS = ${FFLAGS}
		NOOPT = -O0
		LOADER = $(tc-getFC)
		LOADEROPTS = ${LDFLAGS}
		ARCH = $(tc-getAR)
		ARCHFLAGS = cr
		RANLIB = $(tc-getRANLIB)
		TIMER = ${timer}
	EOF
	if use static-libs; then
		emake \
			LAPACKLIB=liblapack_nonpic.a \
			lapacklib || die "lapack static compilation failed"
		emake clean
	fi
	emake \
		LAPACKLIB=liblapack_pic.a \
		OPTS="${FFLAGS} -fPIC" \
		NOOPT="-O0 -fPIC" \
		lapacklib || die "lapack pic compilation failed"
}

atlas_configure() {
	local mycc="$(tc-getCC)"
	# http://sourceforge.net/tracker/?func=detail&aid=3301697&group_id=23725&atid=379483
	[[ ${mycc} == *gcc* ]] && mycc=gcc
	local myconf=(
		"--prefix=${ED}/usr"
		"--libdir=${ED}/usr/$(get_libdir)"
		"--incdir=${ED}/usr/include"
		"--cc=${mycc}"
		"-C ac ${mycc}"
		"-D c -DWALL"
		"-F ac '${CFLAGS}'"
		"-Ss pmake '\$(MAKE) ${MAKEOPTS}'"
	)

	if use threads; then
		myconf+=( "-t -1" )
	else
		myconf+=( "-t  0" )
	fi

	if use amd64 || use ppc64 || use sparc; then
		if [ ${ABI} = amd64 ] || [ ${ABI} = ppc64 ] || [ ${ABI} = sparc64 ] ; then
			myconf+=( "-b 64" )
		elif [ ${ABI} = x86 ] || [ ${ABI} = ppc ] || [ ${ABI} = sparc32 ] ; then
			myconf+=( "-b 32" )
		else
			myconf+=( "-b 64" )
		fi
	elif use ppc || use x86; then
		myconf+=( "-b 32" )
	elif use ia64; then
		myconf+=( "-b 64" )
	else #hppa alpha ...
		myconf+=( "" )
	fi
	if use fortran; then
		myconf+=(
			"-Si nof77 0"
			"-C if $(tc-getFC)"
			"-F if '${FFLAGS}'"
		)
		use lapack && myconf+=( "--with-netlib-lapack=${LAPACKLIB}" )
	else
		myconf+=( "-Si nof77 1" )
	fi
	local confdir="${S}_${1}"; shift
	myconf+=( $@ )
	mkdir "${confdir}" && cd "${confdir}"
	"${S}"/configure ${myconf[@]} || die "configure in ${confdir} failed"
}

atlas_compile() {
	pushd "${S}_${1}" > /dev/null
	# atlas does its own parallel builds
	emake -j1 build
	cd lib
	emake libclapack.a
	popd > /dev/null
}

# transform a static archive into a shared library and install them
# atlas_install_libs <mylib.a> [extra link flags]
atlas_install_libs() {
	local libname=$(basename ${1%.*})
	einfo "Installing ${libname}"
	local soname=${libname}.so.$(get_major_version)
	shift
	pushd "${S}_shared"/lib > /dev/null
	${LINK:-$(tc-getCC)} ${LDFLAGS} -shared -Wl,-soname=${soname} \
		-Wl,--whole-archive ${libname}.a -Wl,--no-whole-archive \
		"$@" -o ${soname} || die "Creating ${soname} failed"
	dolib.so ${soname}
	ln -s ${soname} ${soname%.*}
	dosym ${soname} /usr/$(get_libdir)/${soname%.*}
	popd > /dev/null
	use static-libs && dolib.a "${S}_static"/lib/${libname}.a
}

# create and install a pkgconfig file
# atlas_install_pc <libname> <pkg name> [extra link flags]
atlas_install_pc() {
	local libname=${1} ; shift
	local pcname=${1} ; shift
	cat <<-EOF > ${pcname}.pc
		prefix=${EPREFIX}/usr
		libdir=\${prefix}/$(get_libdir)
		includedir=\${prefix}/include
		Name: ${pcname}
		Description: ${PN} ${pcname}
		Version: ${PV}
		URL: ${HOMEPAGE}
		Libs: -L\${libdir} -l${libname} $@
		Cflags: -I\${includedir}/${PN}
		${PCREQ}
	EOF
	insinto /usr/$(get_libdir)/pkgconfig
	doins ${pcname}.pc
}

pkg_setup() {
	if [[ -n $(type -P cpufreq-info) ]]; then
		[[ -z $(cpufreq-info -d) ]] && return
		local ncpu=$(LANG=C cpufreq-info | grep -c "analyzing CPU")
		local cpu=0
		while [[ ${cpu} -lt ${ncpu} ]]; do
			if ! $(LANG=C cpufreq-info -p -c ${cpu} | grep -q performance); then
				ewarn "CPU $cpu is not set to performance"
				ewarn "Run cpufreq-set -r -g performance as root"
			fi
			cpu=$(( cpu + 1 ))
		done
	else
		ewarn "Please make sure to disable CPU throttling completely"
		ewarn "during the compile of ${PN}. Otherwise, all ${PN}"
		ewarn "generated timings will be completely random and the"
		ewarn "performance of the resulting libraries will be degraded"
		ewarn "considerably."
	fi
}

src_prepare() {
	epatch "${FILESDIR}"/3.9.39-bfr-overflow.patch
}

src_configure() {
	if use fortran && use lapack; then
		lapack_compile
		LAPACKLIB="${WORKDIR}/${LAPACKP}/liblapack_pic.a"
	fi
	atlas_configure shared "-Fa alg -fPIC"
	if use static-libs; then
		use fortran && use lapack && \
			LAPACKLIB="${WORKDIR}/${LAPACKP}/liblapack_nonpic.a"
		atlas_configure static
	fi
}

src_compile() {
	atlas_compile shared
	use static-libs && atlas_compile static
}

src_test() {
	cd "${S}_shared"
	emake -j1 check
	emake -j1 time
}

src_install() {
	cd "${S}_shared/lib"
	# rename to avoid collision with other packages
	local l
	for l in {,c}{blas,lapack}; do
		if [[ -e lib${l}.a ]]; then
			mv lib{,atl}${l}.a
			use static-libs && mv "${S}"_static/lib/lib{,atl}${l}.a
		fi
	done

	[[ -e libptcblas.a ]] && PTLIBS="-lpthread"

	# atlas
	atlas_install_libs libatlas.a -lm ${PTLIBS}

	# cblas
	atlas_install_libs libatlcblas.a -lm -L. -latlas
	atlas_install_pc atlcblas atlas-cblas -lm -latlas
	alternatives_for cblas atlas 0 \
		/usr/$(get_libdir)/pkgconfig/cblas.pc atlas-cblas.pc \
		/usr/include/cblas.h atlas/cblas.h

	# cblas threaded
	if [[ -e libptcblas.a ]]; then
		atlas_install_libs libptcblas.a -lm -L. -latlas ${PTLIBS}
		atlas_install_pc ptcblas atlas-cblas-threads -lm -latlas ${PTLIBS}
		alternatives_for cblas atlas-threads 0 \
			/usr/$(get_libdir)/pkgconfig/cblas.pc atlas-cblas-threads.pc \
			/usr/include/cblas.h atlas/cblas.h
	fi

	if use lapack; then
		PCREQ="Requires: cblas"
		# clapack
		atlas_install_libs libatlclapack.a -lm -L. -latlas -latlcblas
		atlas_install_pc atlclapack atlas-clapack -lm -latlas
	fi

	if use fortran; then
		LINK=$(tc-getF77) PCREQ=
		# blas
		atlas_install_libs libf77blas.a -lm -L. -latlas
		atlas_install_pc f77blas atlas-blas -lm -latlas
		alternatives_for blas atlas 0 \
			/usr/$(get_libdir)/pkgconfig/blas.pc atlas-blas.pc

		# blas threaded
		if [[ -e libptf77blas.a ]]; then
			atlas_install_libs libptf77blas.a -lm -L. -latlas ${PTLIBS}
			atlas_install_pc ptf77blas atlas-blas-threads -lm -latlas ${PTLIBS}
			alternatives_for blas atlas-threads 0 \
				/usr/$(get_libdir)/pkgconfig/blas.pc atlas-blas-threads.pc
		fi

		if use lapack; then
			PCREQ="Requires: blas cblas"
			# lapack
			atlas_install_libs libatllapack.a \
				-lm -L. -latlas -latlcblas -lf77blas
			atlas_install_pc atllapack atlas-lapack -lm -latlas
			alternatives_for lapack atlas 0 \
				/usr/$(get_libdir)/pkgconfig/lapack.pc atlas-lapack.pc
		fi
	fi

	cd "${S}"
	insinto /usr/include/${PN}
	doins include/*.h

	cd "${S}/doc"
	dodoc INDEX.txt AtlasCredits.txt ChangeLog
	use doc && dodoc atlas*pdf cblas.pdf cblasqref.pdf
	use doc && use fortran && dodoc f77blas*pdf
	use doc && use fortran && use lapack && dodoc lapack*pdf
}