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