aboutsummaryrefslogtreecommitdiff
blob: b9826016e8fa94555a8048aedf7bb71828a785fd (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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/intel-sdp.eclass,v 1.4 2012/09/20 13:54:56 jlec Exp $

# @ECLASS: intel-sdp.eclass
# @MAINTAINER:
# Justin Lecher <jlec@gentoo.org>
# Sci Team <sci@gentoo.org>
# @BLURB: Handling of Intel's Software Development Products package management

# @ECLASS-VARIABLE: INTEL_DID
# @DEFAULT_UNSET
# @DESCRIPTION:
# The package download ID from Intel.
# To find out its value, see the links to download in
# https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
#
# e.g. 2504
#
# Must be defined before inheriting the eclass

# @ECLASS-VARIABLE: INTEL_DPN
# @DEFAULT_UNSET
# @DESCRIPTION:
# The package name to download from Intel.
# To find out its value, see the links to download in
# https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
#
# e.g. parallel_studio_xe
#
# Must be defined before inheriting the eclass

# @ECLASS-VARIABLE: INTEL_DPV
# @DEFAULT_UNSET
# @DESCRIPTION:
# The package download version from Intel.
# To find out its value, see the links to download in
# https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
#
# e.g. 2011_sp1_update2
#
# Must be defined before inheriting the eclass

# @ECLASS-VARIABLE: INTEL_SUBDIR
# @DEFAULT_UNSET
# @DESCRIPTION:
# The package sub-directory where it will end-up in /opt/intel
# To find out its value, you have to do a raw install from the Intel tar ball

# @ECLASS-VARIABLE: INTEL_RPMS_DIRS
# @DESCRIPTION:
# List of subdirectories in the main archive which contains the
# rpms to extract.
: ${INTEL_RPMS_DIRS:=rpm}

# @ECLASS-VARIABLE: INTEL_X86
# @DESCRIPTION:
# 32bit arch in rpm names
#
# e.g. i484
: ${INTEL_X86:=i486}

# @ECLASS-VARIABLE: INTEL_BIN_RPMS
# @DEFAULT_UNSET
# @DESCRIPTION:
# Functional name of rpm without any version/arch tag
#
# e.g. compilerprof

# @ECLASS-VARIABLE: INTEL_DAT_RPMS
# @DEFAULT_UNSET
# @DESCRIPTION:
# Functional name of rpm of common data which are arch free
# without any version tag
#
# e.g. openmp

inherit check-reqs multilib versionator

_INTEL_PV1=$(get_version_component_range 1)
_INTEL_PV2=$(get_version_component_range 2)
_INTEL_PV3=$(get_version_component_range 3)
_INTEL_PV4=$(get_version_component_range 4)
_INTEL_URI="http://registrationcenter-download.intel.com/irc_nas/${INTEL_DID}/${INTEL_DPN}"

SRC_URI="
	amd64? ( multilib? ( ${_INTEL_URI}_${INTEL_DPV}.tgz ) )
	amd64? ( !multilib? ( ${_INTEL_URI}_${INTEL_DPV}_intel64.tgz ) )
	x86?  ( ${_INTEL_URI}_${INTEL_DPV}_ia32.tgz )"

LICENSE="Intel-SDP"
# Future work, #394411
#SLOT="${_INTEL_PV1}.${_INTEL_PV2}"
SLOT="0"
IUSE="doc examples multilib"
KEYWORDS="-* ~amd64 ~x86 ~amd64-linux ~x86-linux"

RESTRICT="mirror"

RDEPEND=""
DEPEND="app-arch/rpm2targz"

_INTEL_SDP_YEAR=${INTEL_DPV%_update*}
_INTEL_SDP_YEAR=${INTEL_DPV%_sp*}

# @ECLASS-VARIABLE: INTEL_SDP_DIR
# @DEFAULT_UNSET
# @DESCRIPTION:
# Full rootless path to installation dir

INTEL_SDP_DIR="opt/intel/${INTEL_SUBDIR}-${_INTEL_SDP_YEAR:-${_INTEL_PV1}}.${_INTEL_PV3}.${_INTEL_PV4}"

# @ECLASS-VARIABLE: INTEL_SDP_EDIR
# @DEFAULT_UNSET
# @DESCRIPTION:
# Full rooted path to installation dir

INTEL_SDP_EDIR="${EROOT%/}/${INTEL_SDP_DIR}"

S="${WORKDIR}"

QA_PREBUILT="${INTEL_SDP_DIR}/*"

intel-sdp_pkg_pretend() {
	: ${CHECKREQS_DISK_BUILD:=256M}
	check-reqs_pkg_pretend
}

# @ECLASS-VARIABLE: INTEL_ARCH
# @DEFAULT_UNSET
# @DESCRIPTION:
# Intels internal names of the arches; will be set at runtime accordingly
#
# e.g. amd64-multilib -> INTEL_ARCH="intel64 ia32"

intel-sdp_pkg_setup() {
	local _warn=1 _dirs i _ret arch a p
	_dirs=(
		"${INTEL_SDP_EDIR}/licenses"
		"${INTEL_SDP_EDIR}/Licenses"
		"${EPREFIX}/opt/intel/licenses"
		)
	for ((i = 0; i < ${#_dirs[@]}; i++)); do
		ebegin "Checking for a license in: ${_dirs[$i]}"
		[[ $( ls "${_dirs[$i]}"/*lic 2>/dev/null ) ]]; _ret=$?
		eend ${_ret}
		if [[ ${_ret} == "0" ]]; then
			_warn=${_ret}
			break
		fi
	done
	[[ ${_warn} == "0" ]] || big-warning pre-check

	if use x86; then
		arch=${INTEL_X86}
		INTEL_ARCH="ia32"
	elif use amd64; then
		arch=x86_64
		INTEL_ARCH="intel64"
		if has_multilib_profile; then
			arch="x86_64 ${INTEL_X86}"
			INTEL_ARCH="intel64 ia32"
		fi
	fi
	INTEL_RPMS=""
	for p in ${INTEL_BIN_RPMS}; do
		for a in ${arch}; do
			INTEL_RPMS+=" intel-${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.${a}.rpm"
		done
	done
	for p in ${INTEL_DAT_RPMS}; do
		INTEL_RPMS+=" intel-${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.noarch.rpm"
	done

	case "${EAPI:-0}" in
		0|1|2|3) intel-sdp_pkg_pretend ;;
	esac
}

intel-sdp_src_unpack() {
	local l r t rpmdir
	debug-print "INTEL_RPMS_DIRS are \"${INTEL_RPMS_DIRS}\""
	for t in ${A}; do
		for r in ${INTEL_RPMS}; do
			# Find which subdirectory of the archive the rpm is in
			rpm_found="false"
			for subdir in ${INTEL_RPMS_DIRS}; do
				[[ "${rpm_found}" == "true" ]] && continue
				rpmdir=${t%%.*}/${subdir}
				l=.${r}_$(date +'%d%m%y_%H%M%S').log
				tar xf "${DISTDIR}"/${t} ${rpmdir}/${r} 2> /dev/null || continue
				einfo "Unpacking ${r}"
				rpm_found="true"
				rpm2tar -O "./${rpmdir}/${r}" | tar xvf - | sed -e \
					"s:^\.:${EROOT#/}:g" > ${l} || die "unpacking ${r} failed"
				mv ${l} opt/intel/ || die "failed moving extract log file"
			done
			[[ "${rpm_found}" == "false" ]] && \
				debug-print "RPM \"${r}\" not found in ${t}"
		done
	done
	mv -v opt/intel/* ${INTEL_SDP_DIR} || die "mv to INTEL_SDP_DIR failed"
}

intel_link_eclipse_plugins() {
	pushd ${INTEL_SDP_DIR}/eclipse_support > /dev/null
	local c f
	for c in cdt*; do
		local cv=${c#cdt} ev=3.$(( ${cv:0:1} - 1))
		if has_version "dev-util/eclipse-sdk:${ev}"; then
			einfo "Linking eclipse (v${ev}) plugin cdt (v${cv})"
			for f in cdt${cv}/eclipse/features/*; do
				dodir /usr/$(get_libdir)/eclipse-${ev}/features
				dosym "${INTEL_SDP_EDIR}"/eclipse_support/${f} \
					/usr/$(get_libdir)/eclipse-${ev}/features/ || die
			done
			for f in cdt${cv}/eclipse/plugins/*; do
				dodir /usr/$(get_libdir)/eclipse-${ev}/plugins
				dosym "${INTEL_SDP_EDIR}"/eclipse_support/${f} \
					/usr/$(get_libdir)/eclipse-${ev}/plugins/ || die
			done
		fi
	done
	popd > /dev/null
}

intel-sdp_src_install() {
	if ! use doc && [[ -d "${INTEL_SDP_DIR}"/Documentation ]]; then
		ebegin "Cleaning out documentation"
		find "${INTEL_SDP_DIR}"/Documentation -delete || die
		eend
	fi
	if ! use examples && [[ -d "${INTEL_SDP_DIR}"/Samples ]]; then
		ebegin "Cleaning out examples"
		find "${INTEL_SDP_DIR}"/Samples -delete || die
		eend
	fi
	if [[ -d "${INTEL_SDP_DIR}"/eclipse_support ]]; then
		if has eclipse ${IUSE} && use eclipse; then
			intel_link_eclipse_plugins
		else
			ebegin "Cleaning out eclipse plugin"
			find "${INTEL_SDP_DIR}"/eclipse_support -delete || die
			eend
		fi
	fi

	if [[ -d "${INTEL_SDP_DIR}"/man ]]; then
		doman "${INTEL_SDP_DIR}"/man/en_US/man1/*
		[[ ${LINGUAS} == "*ja_JP*" ]] && \
			doman -i18n=ja_JP "${INTEL_SDP_DIR}"/man/ja_JP/man1/*

		find "${INTEL_SDP_DIR}"/man -delete || die
	fi

	einfo "Tagging ${PN}"
	find opt -name \*sh -type f -exec sed -i \
		-e "s:<.*DIR>:${INTEL_SDP_EDIR}:g" \
		'{}' + || die

	[[ -d "${ED}" ]] || dodir /
	mv opt "${ED}"/ || die "moving files failed"

	dodir "${INTEL_SDP_EDIR}"/licenses
	keepdir "${INTEL_SDP_EDIR}"/licenses
}

# @ECLASS-FUNCTION: big-warning
# @INTERNAL
# warn user that we really require a license

big-warning() {
	case ${1} in
		test-failed )
			echo
			ewarn "Function test failed. Most probably due to an invalid license."
			ewarn "This means you already tried to bypass the license check once."
			;;
	esac

	echo ""
	ewarn "Make sure you have recieved the an Intel license."
	ewarn "To receive a non-commercial license, you need to register at:"
	ewarn "http://software.intel.com/en-us/articles/non-commercial-software-development/"
	ewarn "Install the license file into ${INTEL_SDP_EDIR}/licenses/"

	case ${1} in
		pre-check )
			ewarn "before proceeding with installation of ${P}"
			echo ""
			;;
		* )
			echo ""
			;;
	esac
}

# @ECLASS-FUNCTION: _version_test
# @INTERNAL
# Testing for valid license by asking for version information of the compiler
_version-test() {
	local _comp _comp_full _arch _file _warn
	case ${PN} in
		ifc )
			_comp=ifort
			;;
		icc )
			_comp=icc
			;;
		*)
			die "${PN} is not supported for testing"
			;;
	esac

	for _arch in ${INTEL_ARCH}; do
		case ${EBUILD_PHASE} in
			install )
				_comp_full="${ED}/${INTEL_SDP_DIR}/bin/${_arch}/${_comp}"
				;;
			postinst )
				_comp_full="${INTEL_SDP_EDIR}/bin/${_arch}/${_comp}"
				;;
			* )
				ewarn "Compile test not supported in ${EBUILD_PHASE}"
				continue
				;;
		esac

		debug-print "LD_LIBRARY_PATH=\"${INTEL_SDP_EDIR}/bin/${_arch}/\" \"${_comp_full}\" -V"

		LD_LIBRARY_PATH="${INTEL_SDP_EDIR}/bin/${_arch}/" "${_comp_full}" -V &>/dev/null
			[[ $? -ne 0 ]] && _warn=yes
	done
	[[ "${_warn}" == "yes" ]] && big-warning test-failed
}

# @ECLASS-FUNCTION: _compile-test
# @INTERNAL
# Testing for valid license with small compile test
_compile-test() {
	local _comp _comp_full _arch _file _warn
	case ${1} in
		fortran )
			_file="${T}/${1}.f"
			cat > "${_file}" <<- EOF
			       end
			EOF
			_comp=ifort
			;;
		c )
			_file="${T}/${1}.c"
			cat > "${_file}" <<- EOF
			main() {
				;
			}
			EOF
			_comp=icc
			;;
		*)
			die "This ${1} is not supported for testing"
			;;
	esac

	for _arch in ${INTEL_ARCH}; do
		case ${EBUILD_PHASE} in
			install )
				_comp_full="${ED}/${INTEL_SDP_DIR}/bin/${_arch}/${_comp}"
				;;
			postinst )
				_comp_full="${INTEL_SDP_EDIR}/bin/${_arch}/${_comp}"
				;;
			* )
				ewarn "Compile test not supported in ${EBUILD_PHASE}"
				continue
				;;
		esac

#		debug-print "LD_LIBRARY_PATH=\"${INTEL_SDP_EDIR}/bin/${_arch}/\" \"${_comp_full}\" -c \"${_file}"

#		LD_LIBRARY_PATH="${INTEL_SDP_EDIR}/bin/${_arch}/" "${_comp_full}" -c "${_file}" &>/dev/null

		debug-print "LD_LIBRARY_PATH=\"${INTEL_SDP_EDIR}/bin/${_arch}/\" \"${_comp_full}\" -V"

		LD_LIBRARY_PATH="${INTEL_SDP_EDIR}/bin/${_arch}/" "${_comp_full}" -V &>/dev/null
			[[ $? -ne 0 ]] && _warn=yes
	done
	[[ "${_warn}" == "yes" ]] && big-warning test-failed
}

# @ECLASS-FUNCTION: _compile-fortran
# @INTERNAL
# Run fortran compile test
_compile-fortran() { _compile-test fortran; }

# @ECLASS-FUNCTION: _compile-c
# @INTERNAL
# Run c compile test
_compile-c() { _compile-test c; }

# @ECLASS-FUNCTION: run-test
# @INTERNAL
# Test if installed compiler is working
run-test() {
	case ${PN} in
		ifc )
			debug-print "Testing ifort"
			_compile-fortran ;;
		icc )
			debug-print "Testing icc"
			_compile-c ;;
		* )
			debug-print "No test available for ${PN}"
			;;
	esac
}

# @ECLASS-VARIABLE: INTEL_SDP_DB
# @DESCRIPTION:
# Full path to intel registry db
INTEL_SDP_DB="${EROOT%/}"/opt/intel/intel-sdp-products.db

intel-sdp_pkg_postinst() {
	# add product registry to intel "database"
	local l r
	for r in ${INTEL_RPMS}; do
		l="$(ls -1 ${EROOT%/}/opt/intel/.${r}_*.log | head -n 1)"
		echo >> ${INTEL_SDP_DB} \
			"<:${r%-${_INTEL_PV4}*}-${_INTEL_PV4}:${r}:${INTEL_SDP_EDIR}:${l}:>"
	done
	run-test
}

intel-sdp_pkg_postrm() {
	# remove from intel "database"
	if [[ -e ${INTEL_SDP_DB} ]]; then
		local r
		for r in ${INTEL_RPMS}; do
			sed -i \
				-e "/${r}/d" \
				${INTEL_SDP_DB}
		done
	fi
}

EXPORT_FUNCTIONS pkg_setup src_unpack src_install pkg_postinst pkg_postrm
case "${EAPI:-0}" in
	0|1|2|3) ;;
	4|5) EXPORT_FUNCTIONS pkg_pretend ;;
	*) die "EAPI=${EAPI} is not supported" ;;
esac