net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / intel-sdp.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: intel-sdp.eclass
6 # @MAINTAINER:
7 # Justin Lecher <jlec@gentoo.org>
8 # Sci Team <sci@gentoo.org>
9 # @BLURB: Handling of Intel's Software Development Products package management
10
11 # @ECLASS-VARIABLE: INTEL_DID
12 # @DEFAULT_UNSET
13 # @DESCRIPTION:
14 # The package download ID from Intel.
15 # To find out its value, see the links to download in
16 # https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
17 #
18 # e.g. 2504
19 #
20 # Must be defined before inheriting the eclass
21
22 # @ECLASS-VARIABLE: INTEL_DPN
23 # @DEFAULT_UNSET
24 # @DESCRIPTION:
25 # The package name to download from Intel.
26 # To find out its value, see the links to download in
27 # https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
28 #
29 # e.g. parallel_studio_xe
30 #
31 # Must be defined before inheriting the eclass
32
33 # @ECLASS-VARIABLE: INTEL_DPV
34 # @DEFAULT_UNSET
35 # @DESCRIPTION:
36 # The package download version from Intel.
37 # To find out its value, see the links to download in
38 # https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
39 #
40 # e.g. 2011_sp1_update2
41 #
42 # Must be defined before inheriting the eclass
43
44 # @ECLASS-VARIABLE: INTEL_TARX
45 # @DEFAULT_UNSET
46 # @DESCRIPTION:
47 # The package extention.
48 # To find out its value, see the links to download in
49 # https://registrationcenter.intel.com/RegCenter/MyProducts.aspx
50 #
51 # e.g. tar.gz
52 #
53 # Must be defined before inheriting the eclass
54 : ${INTEL_TARX:=tgz}
55
56 # @ECLASS-VARIABLE: INTEL_SUBDIR
57 # @DEFAULT_UNSET
58 # @DESCRIPTION:
59 # The package sub-directory where it will end-up in /opt/intel
60 # To find out its value, you have to do a raw install from the Intel tar ball
61
62 # @ECLASS-VARIABLE: INTEL_SKIP_LICENSE
63 # @DEFAULT_UNSET
64 # @DESCRIPTION:
65 # Possibility to skip the mandatory check for licenses. Only set this if there
66 # is really no fix.
67
68 # @ECLASS-VARIABLE: INTEL_RPMS_DIR
69 # @DESCRIPTION:
70 # Main subdirectory which contains the rpms to extract.
71 : ${INTEL_RPMS_DIR:=rpm}
72
73 # @ECLASS-VARIABLE: INTEL_X86
74 # @DESCRIPTION:
75 # 32bit arch in rpm names
76 #
77 # e.g. i484
78 : ${INTEL_X86:=i486}
79
80 # @ECLASS-VARIABLE: INTEL_BIN_RPMS
81 # @DEFAULT_UNSET
82 # @DESCRIPTION:
83 # Functional name of rpm without any version/arch tag
84 #
85 # e.g. compilerprof
86 #
87 # if the rpm is located in a directory different to INTEL_RPMS_DIR you can
88 # specify the full path
89 #
90 # e.g. CLI_install/rpm/intel-vtune-amplifier-xe-cli
91
92 # @ECLASS-VARIABLE: INTEL_DAT_RPMS
93 # @DEFAULT_UNSET
94 # @DESCRIPTION:
95 # Functional name of rpm of common data which are arch free
96 # without any version tag
97 #
98 # e.g. openmp
99 #
100 # if the rpm is located in a directory different to INTEL_RPMS_DIR you can
101 # specify the full path
102 #
103 # e.g. CLI_install/rpm/intel-vtune-amplifier-xe-cli-common
104
105 # @ECLASS-VARIABLE: INTEL_SINGLE_ARCH
106 # @DESCRIPTION:
107 # Unset, if only the multilib package will be provided by intel
108 : ${INTEL_SINGLE_ARCH:=true}
109
110 # @ECLASS-VARIABLE: INTEL_SDP_DB
111 # @DESCRIPTION:
112 # Full path to intel registry db
113 INTEL_SDP_DB="${EROOT%/}"/opt/intel/intel-sdp-products.db
114
115 inherit check-reqs eutils multilib versionator
116
117 _INTEL_PV1=$(get_version_component_range 1)
118 _INTEL_PV2=$(get_version_component_range 2)
119 _INTEL_PV3=$(get_version_component_range 3)
120 _INTEL_PV4=$(get_version_component_range 4)
121 _INTEL_URI="http://registrationcenter-download.intel.com/irc_nas/${INTEL_DID}/${INTEL_DPN}"
122
123 if [ ${INTEL_SINGLE_ARCH} == true ]; then
124         SRC_URI="
125                 amd64? ( multilib? ( ${_INTEL_URI}_${INTEL_DPV}.${INTEL_TARX} ) )
126                 amd64? ( !multilib? ( ${_INTEL_URI}_${INTEL_DPV}_intel64.${INTEL_TARX} ) )
127                 x86?    ( ${_INTEL_URI}_${INTEL_DPV}_ia32.${INTEL_TARX} )"
128 else
129         SRC_URI="${_INTEL_URI}_${INTEL_DPV}.${INTEL_TARX}"
130 fi
131
132 LICENSE="Intel-SDP"
133 # Future work, #394411
134 #SLOT="${_INTEL_PV1}.${_INTEL_PV2}"
135 SLOT="0"
136 IUSE="examples multilib"
137
138 RESTRICT="mirror"
139
140 RDEPEND=""
141 DEPEND="app-arch/rpm2targz"
142
143 _INTEL_SDP_YEAR=${INTEL_DPV%_update*}
144 _INTEL_SDP_YEAR=${INTEL_DPV%_sp*}
145
146 # @ECLASS-VARIABLE: INTEL_SDP_DIR
147 # @DEFAULT_UNSET
148 # @DESCRIPTION:
149 # Full rootless path to installation dir
150 INTEL_SDP_DIR="opt/intel/${INTEL_SUBDIR}-${_INTEL_SDP_YEAR:-${_INTEL_PV1}}.${_INTEL_PV3}.${_INTEL_PV4}"
151
152 # @ECLASS-VARIABLE: INTEL_SDP_EDIR
153 # @DEFAULT_UNSET
154 # @DESCRIPTION:
155 # Full rooted path to installation dir
156 INTEL_SDP_EDIR="${EROOT%/}/${INTEL_SDP_DIR}"
157
158 S="${WORKDIR}"
159
160 QA_PREBUILT="${INTEL_SDP_DIR}/*"
161
162 # @ECLASS-VARIABLE: INTEL_ARCH
163 # @DEFAULT_UNSET
164 # @DESCRIPTION:
165 # Intels internal names of the arches; will be set at runtime accordingly
166 #
167 # e.g. amd64-multilib -> INTEL_ARCH="intel64 ia32"
168
169 # @FUNCTION: _isdp_link_eclipse_plugins
170 # @INTERNAL
171 # @DESCRIPTION:
172 # Creating necessary links to use intel compiler with eclipse
173 _isdp_link_eclipse_plugins() {
174         local c f
175         pushd ${INTEL_SDP_DIR}/eclipse_support > /dev/null || die
176                 for c in cdt*; do
177                         local cv=${c#cdt} ev=3.$(( ${cv:0:1} - 1))
178                         if has_version "dev-util/eclipse-sdk:${ev}"; then
179                                 einfo "Linking eclipse (v${ev}) plugin cdt (v${cv})"
180                                 for f in cdt${cv}/eclipse/features/*; do
181                                         dodir /usr/$(get_libdir)/eclipse-${ev}/features
182                                         dosym "${INTEL_SDP_EDIR}"/eclipse_support/${f} \
183                                                 /usr/$(get_libdir)/eclipse-${ev}/features/ || die
184                                 done
185                                 for f in cdt${cv}/eclipse/plugins/*; do
186                                         dodir /usr/$(get_libdir)/eclipse-${ev}/plugins
187                                         dosym "${INTEL_SDP_EDIR}"/eclipse_support/${f} \
188                                                 /usr/$(get_libdir)/eclipse-${ev}/plugins/ || die
189                                 done
190                         fi
191                 done
192         popd > /dev/null || die
193 }
194
195 # @FUNCTION: _isdp_big-warning
196 # @USAGE: [pre-check | test-failed]
197 # @INTERNAL
198 # @DESCRIPTION:
199 # warn user that we really require a license
200 _isdp_big-warning() {
201         case ${1} in
202                 pre-check )
203                         echo ""
204                         ewarn "License file not found!"
205                         ;;
206
207                 test-failed )
208                         echo
209                         ewarn "Function test failed. Most probably due to an invalid license."
210                         ewarn "This means you already tried to bypass the license check once."
211                         ;;
212         esac
213
214         echo ""
215         ewarn "Make sure you have received an Intel license."
216         ewarn "To receive a non-commercial license, you need to register at:"
217         ewarn "https://software.intel.com/en-us/qualify-for-free-software"
218         ewarn "Install the license file into ${INTEL_SDP_EDIR}/licenses/"
219
220         case ${1} in
221                 pre-check )
222                         ewarn "before proceeding with installation of ${P}"
223                         echo ""
224                         ;;
225                 * )
226                         echo ""
227                         ;;
228                         esac
229 }
230
231 # @FUNCTION: _isdp_version_test
232 # @INTERNAL
233 # @DESCRIPTION:
234 # Testing for valid license by asking for version information of the compiler
235 _isdp_version_test() {
236         local comp comp_full arch warn
237         case ${PN} in
238                 ifc )
239                         debug-print "Testing ifort"
240                         comp=ifort
241                         ;;
242                 icc )
243                         debug-print "Testing icc"
244                         comp=icc
245                         ;;
246                 *)
247                         die "${PN} is not supported for testing"
248                         ;;
249         esac
250
251         for arch in ${INTEL_ARCH}; do
252                 case ${EBUILD_PHASE} in
253                         install )
254                                 comp_full="${ED}/${INTEL_SDP_DIR}/bin/${arch}/${comp}"
255                                 ;;
256                         postinst )
257                                 comp_full="${INTEL_SDP_EDIR}/bin/${arch}/${comp}"
258                                 ;;
259                         * )
260                                 ewarn "Compile test not supported in ${EBUILD_PHASE}"
261                                 continue
262                                 ;;
263                 esac
264
265                 debug-print "LD_LIBRARY_PATH=\"${INTEL_SDP_EDIR}/bin/${arch}/\" \"${comp_full}\" -V"
266
267                 LD_LIBRARY_PATH="${INTEL_SDP_EDIR}/bin/${arch}/" "${comp_full}" -V &>/dev/null
268                 [[ $? -ne 0 ]] && warn=yes
269         done
270         [[ "${warn}" == "yes" ]] && _isdp_big-warning test-failed
271 }
272
273 # @FUNCTION: _isdp_run-test
274 # @INTERNAL
275 # Test if installed compiler is working
276 _isdp_run-test() {
277         if [[ -z ${INTEL_SKIP_LICENSE} ]]; then
278                 case ${PN} in
279                         ifc | icc )
280                                 _isdp_version_test ;;
281                         * )
282                                 debug-print "No test available for ${PN}"
283                                 ;;
284                 esac
285         fi
286 }
287
288 # @FUNCTION: intel-sdp_pkg_pretend
289 # @DESCRIPTION:
290 # @CODE
291 # * Check that the user has a (valid) license file before going on.
292 # * Check for space requirements being fullfilled
293 # @CODE
294 intel-sdp_pkg_pretend() {
295         local warn=1 dir dirs ret arch a p
296
297         : ${CHECKREQS_DISK_BUILD:=256M}
298         check-reqs_pkg_pretend
299
300         if [[ -z ${INTEL_SKIP_LICENSE} ]]; then
301                 if echo ${INTEL_LICENSE_FILE} | grep -q @; then
302                         einfo "Looks like you are using following license server:"
303                         einfo "   ${INTEL_LICENSE_FILE}"
304                         return 0
305                 fi
306
307                 dirs=(
308                         "${INTEL_SDP_EDIR}/licenses"
309                         "${INTEL_SDP_EDIR}/Licenses"
310                         "${EPREFIX}/opt/intel/licenses"
311                         )
312                 for dir in "${dirs[@]}" ; do
313                         ebegin "Checking for a license in: ${dir}"
314                         #maybe use nullglob or [[ $(echo ${dir/*lic) != "${dir}/*lic" ]]
315                         [[ $( ls "${dir}"/*lic 2>/dev/null ) ]]; ret=$?
316                         eend ${ret}
317                         if [[ ${ret} == "0" ]]; then
318                                 warn=${ret}
319                                 break
320                         fi
321                 done
322                 if [[ ${warn} == "1" ]]; then
323                         _isdp_big-warning pre-check
324                         die "Could not find license file"
325                 fi
326         else
327                 eqawarn "The ebuild doesn't check for presents of a proper intel license!"
328                 eqawarn "This shouldn't be done unless there is a serious reason."
329         fi
330 }
331
332 # @FUNCTION: intel-sdp_pkg_setup
333 # @DESCRIPTION:
334 # Setting up and sorting some internal variables
335 intel-sdp_pkg_setup() {
336         local arch a p
337
338         if use x86; then
339                 arch=${INTEL_X86}
340                 INTEL_ARCH="ia32"
341         elif use amd64; then
342                 arch=x86_64
343                 INTEL_ARCH="intel64"
344                 if has_multilib_profile; then
345                         arch="x86_64 ${INTEL_X86}"
346                         INTEL_ARCH="intel64 ia32"
347                 fi
348         fi
349         INTEL_RPMS=()
350         INTEL_RPMS_FULL=()
351         if [[ $(declare -p INTEL_BIN_RPMS) = "declare -a "* ]] ; then
352                 _INTEL_BIN_RPMS=( ${INTEL_BIN_RPMS[@]} )
353         else
354                 read -r -d '' -a _INTEL_BIN_RPMS <<<"${INTEL_BIN_RPMS}"
355         fi
356         for p in "${_INTEL_BIN_RPMS[@]}"; do
357                 for a in ${arch}; do
358                         if [ ${p} == $(basename ${p}) ]; then
359                                 INTEL_RPMS+=( intel-${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.${a}.rpm )
360                         else
361                                 INTEL_RPMS_FULL+=( ${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.${a}.rpm )
362                         fi
363                 done
364         done
365         if [[ $(declare -p INTEL_DAT_RPMS) = "declare -a "* ]] ; then
366                 _INTEL_DAT_RPMS=( ${INTEL_DAT_RPMS[@]} )
367         else
368                 read -r -d '' -a _INTEL_DAT_RPMS <<<"${INTEL_DAT_RPMS}"
369         fi
370         for p in "${_INTEL_DAT_RPMS[@]}"; do
371                 if [ ${p} == $(basename ${p}) ]; then
372                         INTEL_RPMS+=( intel-${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.noarch.rpm )
373                 else
374                         INTEL_RPMS_FULL+=( ${p}-${_INTEL_PV4}-${_INTEL_PV1}.${_INTEL_PV2}-${_INTEL_PV3}.noarch.rpm )
375                 fi
376         done
377 }
378
379 # @FUNCTION: intel-sdp_src_unpack
380 # @DESCRIPTION:
381 # Unpacking necessary rpms from tarball, extract them and rearrange the output.
382 intel-sdp_src_unpack() {
383         local l r subdir rb t list=() debug_list
384
385         for t in ${A}; do
386                 for r in "${INTEL_RPMS[@]}"; do
387                         rpmdir=${t%%.*}/${INTEL_RPMS_DIR}
388                         list+=( ${rpmdir}/${r} )
389                 done
390
391                 for r in "${INTEL_RPMS_FULL[@]}"; do
392                         list+=( ${t%%.*}/${r} )
393                 done
394
395                 debug_list="$(IFS=$'\n'; echo ${list[@]} )"
396
397                 debug-print "Adding to decompression list:"
398                 debug-print ${debug_list}
399
400                 tar xvf "${DISTDIR}"/${t} ${list[@]} &> "${T}"/rpm-extraction.log
401
402                 for r in ${list[@]}; do
403                         rb=$(basename ${r})
404                         l=.${rb}_$(date +'%d%m%y_%H%M%S').log
405                         einfo "Unpacking ${rb}"
406                         rpm2tar -O ${r} | tar xvf - | sed -e \
407                                 "s:^\.:${EROOT#/}:g" > ${l}; assert "unpacking ${r} failed"
408                         mv ${l} opt/intel/ || die "failed moving extract log file"
409                 done
410         done
411
412         mv opt/intel/* ${INTEL_SDP_DIR} || die "mv to INTEL_SDP_DIR failed"
413 }
414
415 # @FUNCTION: intel-sdp_src_install
416 # @DESCRIPTION:
417 # Install everything
418 intel-sdp_src_install() {
419         if path_exists "${INTEL_SDP_DIR}"/uninstall*; then
420                 ebegin "Cleaning out uninstall information"
421                 find "${INTEL_SDP_DIR}"/uninstall* -delete || die
422                 eend
423         fi
424
425         if path_exists "${INTEL_SDP_DIR}"/Documentation; then
426                 dodoc -r "${INTEL_SDP_DIR}"/Documentation/*
427
428                 ebegin "Cleaning out documentation"
429                 find "${INTEL_SDP_DIR}"/Documentation -delete || die
430                 eend
431         fi
432
433         if path_exists "${INTEL_SDP_DIR}"/Samples; then
434                 if use examples ; then
435                         insinto /usr/share/${P}/examples/
436                         doins -r "${INTEL_SDP_DIR}"/Samples/*
437                 fi
438                 ebegin "Cleaning out examples"
439                 find "${INTEL_SDP_DIR}"/Samples -delete || die
440                 eend
441         fi
442
443         if path_exists "${INTEL_SDP_DIR}"/eclipse_support; then
444                 if has eclipse ${IUSE} && use eclipse; then
445                         _isdp_link_eclipse_plugins
446                 else
447                         ebegin "Cleaning out eclipse plugin"
448                         find "${INTEL_SDP_DIR}"/eclipse_support -delete || die
449                         eend
450                 fi
451         fi
452
453         if path_exists "${INTEL_SDP_DIR}"/man; then
454                 path_exists "${INTEL_SDP_DIR}"/man/en_US/man1/* && \
455                         doman "${INTEL_SDP_DIR}"/man/en_US/man1/*
456                 path_exists "${INTEL_SDP_DIR}"/man/man1/* && \
457                         doman "${INTEL_SDP_DIR}"/man/man1/*
458                 has linguas_ja ${IUSE} && use linguas_ja && \
459                         doman -i18n=ja_JP "${INTEL_SDP_DIR}"/man/ja_JP/man1/*
460
461                 find "${INTEL_SDP_DIR}"/man -delete || die
462         fi
463
464         ebegin "Tagging ${PN}"
465         find opt -name \*sh -type f -exec sed -i \
466                 -e "s:<.*DIR>:${INTEL_SDP_EDIR}:g" \
467                 '{}' + || die
468         eend
469
470         [[ -d "${ED}" ]] || dodir /
471         mv opt "${ED}"/ || die "moving files failed"
472
473         dodir "${INTEL_SDP_DIR}"/licenses /opt/intel/ism/rm
474         keepdir "${INTEL_SDP_DIR}"/licenses /opt/intel/ism/rm
475 }
476
477 # @FUNCTION: intel-sdp_pkg_postinst
478 # @DESCRIPTION:
479 # Add things to intel database
480 intel-sdp_pkg_postinst() {
481         # add product registry to intel "database"
482         local l r
483         for r in ${INTEL_RPMS}; do
484                 l="$(ls -1 ${EROOT%/}/opt/intel/.${r}_*.log | head -n 1)"
485                 echo >> ${INTEL_SDP_DB} \
486                         "<:${r%-${_INTEL_PV4}*}-${_INTEL_PV4}:${r}:${INTEL_SDP_EDIR}:${l}:>"
487         done
488         _isdp_run-test
489
490         if [[ ${PN} = icc ]] && has_version ">=dev-util/ccache-3.1.9-r2" ; then
491                 #add ccache links as icc might get installed after ccache
492                 "${EROOT}"/usr/bin/ccache-config --install-links
493         fi
494 }
495
496 # @FUNCTION: intel-sdp_pkg_postrm
497 # @DESCRIPTION:
498 # Sanitize intel database
499 intel-sdp_pkg_postrm() {
500         # remove from intel "database"
501         if [[ -e ${INTEL_SDP_DB} ]]; then
502                 local r
503                 for r in ${INTEL_RPMS}; do
504                         sed -i \
505                                 -e "/${r}/d" \
506                                 ${INTEL_SDP_DB}
507                 done
508         fi
509
510         if [[ ${PN} = icc ]] && has_version ">=dev-util/ccache-3.1.9-r2" && [[ -z ${REPLACED_BY_VERSION} ]]; then
511                 # --remove-links would remove all links, --install-links updates them
512                 "${EROOT}"/usr/bin/ccache-config --install-links
513         fi
514 }
515
516 EXPORT_FUNCTIONS pkg_setup src_unpack src_install pkg_postinst pkg_postrm pkg_pretend
517 case "${EAPI:-0}" in
518         0|1|2|3)die "EAPI=${EAPI} is not supported anymore" ;;
519         4|5) ;;
520         *) die "EAPI=${EAPI} is not supported" ;;
521 esac