/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.391 Revision 1.407
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.391 2012/04/20 19:35:37 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.407 2012/10/11 16:50:53 mgorny Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
16# different from the overall eclass! 16# different from the overall eclass!
17 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then 18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" 19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
20 20
21inherit multilib user 21inherit multilib toolchain-funcs user
22
23DESCRIPTION="Based on the ${ECLASS} eclass"
24 22
25if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
26 24
27# @FUNCTION: epause 25# @FUNCTION: epause
28# @USAGE: [seconds] 26# @USAGE: [seconds]
551 549
552# @FUNCTION: epatch_user 550# @FUNCTION: epatch_user
553# @USAGE: 551# @USAGE:
554# @DESCRIPTION: 552# @DESCRIPTION:
555# Applies user-provided patches to the source tree. The patches are 553# Applies user-provided patches to the source tree. The patches are
556# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first 554# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>[:SLOT]/, where the first
557# of these three directories to exist will be the one to use, ignoring 555# of these three directories to exist will be the one to use, ignoring
558# any more general directories which might exist as well. They must end 556# any more general directories which might exist as well. They must end
559# in ".patch" to be applied. 557# in ".patch" to be applied.
560# 558#
561# User patches are intended for quick testing of patches without ebuild 559# User patches are intended for quick testing of patches without ebuild
583 local applied="${T}/epatch_user.log" 581 local applied="${T}/epatch_user.log"
584 [[ -e ${applied} ]] && return 2 582 [[ -e ${applied} ]] && return 2
585 583
586 # don't clobber any EPATCH vars that the parent might want 584 # don't clobber any EPATCH vars that the parent might want
587 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 585 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
588 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}; do 586 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}}; do
589 EPATCH_SOURCE=${base}/${CTARGET}/${check} 587 EPATCH_SOURCE=${base}/${CTARGET}/${check}
590 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check} 588 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
591 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check} 589 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
592 if [[ -d ${EPATCH_SOURCE} ]] ; then 590 if [[ -d ${EPATCH_SOURCE} ]] ; then
593 EPATCH_SOURCE=${EPATCH_SOURCE} \ 591 EPATCH_SOURCE=${EPATCH_SOURCE} \
656# Make a .desktop file. 654# Make a .desktop file.
657# 655#
658# @CODE 656# @CODE
659# binary: what command does the app run with ? 657# binary: what command does the app run with ?
660# name: the name that will show up in the menu 658# name: the name that will show up in the menu
661# icon: give your little like a pretty little icon ... 659# icon: the icon to use in the menu entry
662# this can be relative (to /usr/share/pixmaps) or 660# this can be relative (to /usr/share/pixmaps) or
663# a full path to an icon 661# a full path to an icon
664# type: what kind of application is this? 662# type: what kind of application is this?
665# for categories: 663# for categories:
666# http://standards.freedesktop.org/menu-spec/latest/apa.html 664# http://standards.freedesktop.org/menu-spec/latest/apa.html
942 insinto /usr/share/applications 940 insinto /usr/share/applications
943 newins "$@" 941 newins "$@"
944 ) 942 )
945} 943}
946 944
947# @FUNCTION: doicon 945# @FUNCTION: _iconins
948# @USAGE: <list of icons> 946# @INTERNAL
949# @DESCRIPTION: 947# @DESCRIPTION:
950# Install the list of icons into the icon directory (/usr/share/pixmaps). 948# function for use in doicon and newicon
951# This is useful in conjunction with creating desktop/menu files. 949_iconins() {
952doicon() {
953 ( 950 (
954 # wrap the env here so that the 'insinto' call 951 # wrap the env here so that the 'insinto' call
955 # doesn't corrupt the env of the caller 952 # doesn't corrupt the env of the caller
956 local i j ret 953 local funcname=$1; shift
954 local size dir
955 local context=apps
956 local theme=hicolor
957
958 while [[ $# -gt 0 ]] ; do
959 case $1 in
960 -s|--size)
961 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
962 size=${2%%x*}
963 else
964 size=${2}
965 fi
966 case ${size} in
967 16|22|24|32|36|48|64|72|96|128|192|256)
968 size=${size}x${size};;
969 scalable)
970 ;;
971 *)
972 eerror "${size} is an unsupported icon size!"
973 exit 1;;
974 esac
975 shift 2;;
976 -t|--theme)
977 theme=${2}
978 shift 2;;
979 -c|--context)
980 context=${2}
981 shift 2;;
982 *)
983 if [[ -z ${size} ]] ; then
957 insinto /usr/share/pixmaps 984 insinto /usr/share/pixmaps
958 for i in "$@" ; do
959 if [[ -f ${i} ]] ; then
960 doins "${i}"
961 ((ret+=$?))
962 elif [[ -d ${i} ]] ; then
963 for j in "${i}"/*.png ; do
964 doins "${j}"
965 ((ret+=$?))
966 done
967 else 985 else
968 ((++ret)) 986 insinto /usr/share/icons/${theme}/${size}/${context}
969 fi 987 fi
988
989 if [[ ${funcname} == doicon ]] ; then
990 if [[ -f $1 ]] ; then
991 doins "${1}"
992 elif [[ -d $1 ]] ; then
993 shopt -s nullglob
994 doins "${1}"/*.{png,svg}
995 shopt -u nullglob
996 else
997 eerror "${1} is not a valid file/directory!"
998 exit 1
999 fi
1000 else
1001 break
1002 fi
1003 shift 1;;
1004 esac
970 done 1005 done
971 exit ${ret} 1006 if [[ ${funcname} == newicon ]] ; then
972 ) 1007 newins "$@"
1008 fi
1009 ) || die
1010}
1011
1012# @FUNCTION: doicon
1013# @USAGE: [options] <icons>
1014# @DESCRIPTION:
1015# Install icon into the icon directory /usr/share/icons or into
1016# /usr/share/pixmaps if "--size" is not set.
1017# This is useful in conjunction with creating desktop/menu files.
1018#
1019# @CODE
1020# options:
1021# -s, --size
1022# !!! must specify to install into /usr/share/icons/... !!!
1023# size of the icon, like 48 or 48x48
1024# supported icon sizes are:
1025# 16 22 24 32 36 48 64 72 96 128 192 256 scalable
1026# -c, --context
1027# defaults to "apps"
1028# -t, --theme
1029# defaults to "hicolor"
1030#
1031# icons: list of icons
1032#
1033# example 1: doicon foobar.png fuqbar.svg suckbar.png
1034# results in: insinto /usr/share/pixmaps
1035# doins foobar.png fuqbar.svg suckbar.png
1036#
1037# example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1038# results in: insinto /usr/share/icons/hicolor/48x48/apps
1039# doins foobar.png fuqbar.png blobbar.png
1040# @CODE
1041doicon() {
1042 _iconins ${FUNCNAME} "$@"
973} 1043}
974 1044
975# @FUNCTION: newicon 1045# @FUNCTION: newicon
976# @USAGE: <icon> <newname> 1046# @USAGE: [options] <icon> <newname>
977# @DESCRIPTION: 1047# @DESCRIPTION:
978# Like all other new* functions, install the specified icon as newname. 1048# Like doicon, install the specified icon as newname.
1049#
1050# @CODE
1051# example 1: newicon foobar.png NEWNAME.png
1052# results in: insinto /usr/share/pixmaps
1053# newins foobar.png NEWNAME.png
1054#
1055# example 2: newicon -s 48 foobar.png NEWNAME.png
1056# results in: insinto /usr/share/icons/hicolor/48x48/apps
1057# newins foobar.png NEWNAME.png
1058# @CODE
979newicon() { 1059newicon() {
980 ( 1060 _iconins ${FUNCNAME} "$@"
981 # wrap the env here so that the 'insinto' call
982 # doesn't corrupt the env of the caller
983 insinto /usr/share/pixmaps
984 newins "$@"
985 )
986} 1061}
987 1062
988# @FUNCTION: strip-linguas 1063# @FUNCTION: strip-linguas
989# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>] 1064# @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
990# @DESCRIPTION: 1065# @DESCRIPTION:
1086 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1161 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1087 ewarn "in order to remove these old dependencies. If you do not have this" 1162 ewarn "in order to remove these old dependencies. If you do not have this"
1088 ewarn "helper program, simply emerge the 'gentoolkit' package." 1163 ewarn "helper program, simply emerge the 'gentoolkit' package."
1089 ewarn 1164 ewarn
1090 fi 1165 fi
1091 # temp hack for #348634 #357225
1092 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1093 ewarn " # revdep-rebuild --library '${lib}'" 1166 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1094 done 1167 done
1095 if [[ ${notice} -eq 1 ]] ; then
1096 ewarn
1097 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1098 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1099 for lib in "$@" ; do
1100 ewarn " # rm '${lib}'"
1101 done
1102 fi
1103} 1168}
1104 1169
1105# @FUNCTION: built_with_use 1170# @FUNCTION: built_with_use
1106# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1171# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1107# @DESCRIPTION: 1172# @DESCRIPTION:
1304} 1369}
1305 1370
1306# @FUNCTION: usex 1371# @FUNCTION: usex
1307# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix] 1372# @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1308# @DESCRIPTION: 1373# @DESCRIPTION:
1374# Proxy to declare usex for package managers or EAPIs that do not provide it
1375# and use the package manager implementation when available (i.e. EAPI >= 5).
1309# If USE flag is set, echo [true output][true suffix] (defaults to "yes"), 1376# If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1310# otherwise echo [false output][false suffix] (defaults to "no"). 1377# otherwise echo [false output][false suffix] (defaults to "no").
1378if has "${EAPI:-0}" 0 1 2 3 4; then
1311usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963 1379 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1380fi
1312 1381
1313# @FUNCTION: makeopts_jobs 1382# @FUNCTION: prune_libtool_files
1314# @USAGE: [${MAKEOPTS}] 1383# @USAGE: [--all]
1315# @DESCRIPTION: 1384# @DESCRIPTION:
1316# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number 1385# Locate unnecessary libtool files (.la) and libtool static archives
1317# specified therein. i.e. if the user has MAKEOPTS=-j9, this will show "9". 1386# (.a) and remove them from installation image.
1318# We can't return the number as bash normalizes it to [0, 255]. If the flags 1387#
1319# haven't specified a -j flag, then "1" is shown as that is the default `make` 1388# By default, .la files are removed whenever the static linkage can
1320# uses. Useful for running non-make tools in parallel too. 1389# either be performed using pkg-config or doesn't introduce additional
1321makeopts_jobs() { 1390# flags.
1322 [[ $# -eq 0 ]] && set -- ${MAKEOPTS} 1391#
1323 local x jobs 1392# If '--all' argument is passed, all .la files are removed. This is
1324 for x ; do [[ ${x} == -j* ]] && jobs=${x#-j} ; done 1393# usually useful when the package installs plugins and does not use .la
1325 echo ${jobs:-1} 1394# files for loading them.
1395#
1396# The .a files are only removed whenever corresponding .la files state
1397# that they should not be linked to, i.e. whenever these files
1398# correspond to plugins.
1399#
1400# Note: if your package installs both static libraries and .pc files,
1401# you need to add pkg-config to your DEPEND.
1402prune_libtool_files() {
1403 debug-print-function ${FUNCNAME} "$@"
1404
1405 local removing_all opt
1406 for opt; do
1407 case "${opt}" in
1408 --all)
1409 removing_all=1
1410 ;;
1411 *)
1412 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1413 esac
1414 done
1415
1416 local f
1417 local queue=()
1418 while IFS= read -r -d '' f; do # for all .la files
1419 local archivefile=${f/%.la/.a}
1420
1421 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1422
1423 # Remove static libs we're not supposed to link against.
1424 if grep -q '^shouldnotlink=yes$' "${f}"; then
1425 if [[ -f ${archivefile} ]]; then
1426 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1427 queue+=( "${archivefile}" )
1428 fi
1429
1430 # The .la file may be used by a module loader, so avoid removing it
1431 # unless explicitly requested.
1432 [[ ${removing_all} ]] || continue
1433 fi
1434
1435 # Remove .la files when:
1436 # - user explicitly wants us to remove all .la files,
1437 # - respective static archive doesn't exist,
1438 # - they are covered by a .pc file already,
1439 # - they don't provide any new information (no libs & no flags).
1440 local reason pkgconfig_scanned
1441 if [[ ${removing_all} ]]; then
1442 reason='requested'
1443 elif [[ ! -f ${archivefile} ]]; then
1444 reason='no static archive'
1445 elif [[ ! $(sed -nre \
1446 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1447 "${f}") ]]; then
1448 reason='no libs & flags'
1449 else
1450 if [[ ! ${pkgconfig_scanned} ]]; then
1451 # Create a list of all .pc-covered libs.
1452 local pc_libs=()
1453 if [[ ! ${removing_all} ]]; then
1454 local f
1455 local tf=${T}/prune-lt-files.pc
1456 local pkgconf=$(tc-getPKG_CONFIG)
1457
1458 while IFS= read -r -d '' f; do # for all .pc files
1459 local arg
1460
1461 sed -e '/^Requires:/d' "${f}" > "${tf}"
1462 for arg in $("${pkgconf}" --libs "${tf}"); do
1463 [[ ${arg} == -l* ]] && pc_libs+=( lib${arg#-l}.la )
1464 done
1465 done < <(find "${D}" -type f -name '*.pc' -print0)
1466
1467 rm -f "${tf}"
1468 fi
1469
1470 pkgconfig_scanned=1
1471 fi
1472
1473 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1474 fi
1475
1476 if [[ ${reason} ]]; then
1477 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1478 queue+=( "${f}" )
1479 fi
1480 done < <(find "${D}" -xtype f -name '*.la' -print0)
1481
1482 if [[ ${queue[@]} ]]; then
1483 rm -f "${queue[@]}"
1484 fi
1326} 1485}
1327 1486
1328check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; } 1487check_license() { die "you no longer need this as portage supports ACCEPT_LICENSE itself"; }
1329 1488
1330fi 1489fi

Legend:
Removed from v.1.391  
changed lines
  Added in v.1.407

  ViewVC Help
Powered by ViewVC 1.1.20