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

Diff of /eclass/eutils.eclass

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

Revision 1.164 Revision 1.178
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 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.164 2005/03/30 14:12:25 wolf31o2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.178 2005/05/26 22:09:26 vapier Exp $
4# 4#
5# Author: Martin Schlemmer <azarah@gentoo.org> 5# Author: Martin Schlemmer <azarah@gentoo.org>
6# 6#
7# This eclass is for general purpose functions that most ebuilds 7# This eclass is for general purpose functions that most ebuilds
8# have to implement themselves. 8# have to implement themselves.
14INHERITED="$INHERITED $ECLASS" 14INHERITED="$INHERITED $ECLASS"
15 15
16DEPEND="!bootstrap? ( sys-devel/patch )" 16DEPEND="!bootstrap? ( sys-devel/patch )"
17 17
18DESCRIPTION="Based on the ${ECLASS} eclass" 18DESCRIPTION="Based on the ${ECLASS} eclass"
19
20# ecpu_check
21# Usage:
22#
23# ecpu_check array_of_cpu_flags
24#
25# array_of_cpu_flags - An array of cpu flags to check against USE flags
26#
27# Checks user USE related cpu flags against /proc/cpuinfo. If user enables a
28# cpu flag that is not supported in their processor flags, it will warn the
29# user if CROSSCOMPILE is not set to 1 ( because cross compile users are
30# obviously using different cpu flags than their own cpu ). Examples:
31#
32# CPU_FLAGS=(mmx mmx2 sse sse2)
33# ecpu_check CPU_FLAGS
34# Chris White <chriswhite@gentoo.org> (03 Feb 2005)
35
36ecpu_check() {
37 # Think about changing below to: if [ "${CROSSCOMPILE}" -ne 1 -a -e "/proc/cpuinfo" ]
38 # and dropping the else if you do not plan on adding anything to that
39 # empty block ....
40 # PS: also try to add some quoting, and consider rather using ${foo} than $foo ...
41 if [ "${CROSSCOMPILE}" != "1" -a -e "/proc/cpuinfo" ]
42 then
43 CPU_FLAGS=${1}
44 USER_CPU=`grep "flags" /proc/cpuinfo`
45
46 for flags in `seq 1 ${#CPU_FLAGS[@]}`
47 do
48 if has ${CPU_FLAGS[${flags} - 1]} ${USER_CPU} && ! has ${CPU_FLAGS[${flags} - 1]} ${USE}
49 then
50 ewarn "Your system is ${CPU_FLAGS[${flags} - 1]} capable but you don't have it enabled!"
51 ewarn "You might be cross compiling (in this case set CROSSCOMPILE to 1 to disable this warning."
52 fi
53
54 if ! has ${CPU_FLAGS[${flags} - 1]} ${USER_CPU} && has ${CPU_FLAGS[${flags} -1]} ${USE}
55 then
56 ewarn "You have ${CPU_FLAGS[${flags} - 1]} support enabled but your processor doesn't"
57 ewarn "Seem to support it! You might be cross compiling or do not have /proc filesystem"
58 ewarn "enabled. If either is the case, set CROSSCOMPILE to 1 to disable this warning."
59 fi
60 done
61 fi
62}
63 19
64# Wait for the supplied number of seconds. If no argument is supplied, defaults 20# Wait for the supplied number of seconds. If no argument is supplied, defaults
65# to five seconds. If the EPAUSE_IGNORE env var is set, don't wait. If we're not 21# to five seconds. If the EPAUSE_IGNORE env var is set, don't wait. If we're not
66# outputting to a terminal, don't wait. For compatability purposes, the argument 22# outputting to a terminal, don't wait. For compatability purposes, the argument
67# must be an integer greater than zero. 23# must be an integer greater than zero.
126 fperms a+x "/usr/${libdir}/${lib}" 82 fperms a+x "/usr/${libdir}/${lib}"
127 done 83 done
128} 84}
129 85
130# Simple function to draw a line consisting of '=' the same length as $* 86# Simple function to draw a line consisting of '=' the same length as $*
87# - only to be used by epatch()
131# 88#
132# <azarah@gentoo.org> (11 Nov 2002) 89# <azarah@gentoo.org> (11 Nov 2002)
133# 90#
134draw_line() { 91draw_line() {
135 local i=0 92 local i=0
161EPATCH_SOURCE="${WORKDIR}/patch" 118EPATCH_SOURCE="${WORKDIR}/patch"
162# Default extension for patches 119# Default extension for patches
163EPATCH_SUFFIX="patch.bz2" 120EPATCH_SUFFIX="patch.bz2"
164# Default options for patch 121# Default options for patch
165# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571 122# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571
166EPATCH_OPTS="-g0" 123# Set --no-backup-if-mismatch so we don't leave '.orig' files behind.
124EPATCH_OPTS="-g0 --no-backup-if-mismatch"
167# List of patches not to apply. Not this is only file names, 125# List of patches not to apply. Not this is only file names,
168# and not the full path .. 126# and not the full path ..
169EPATCH_EXCLUDE="" 127EPATCH_EXCLUDE=""
170# Change the printed message for a single patch. 128# Change the printed message for a single patch.
171EPATCH_SINGLE_MSG="" 129EPATCH_SINGLE_MSG=""
130# Change the printed message for multiple patches.
131EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
172# Force applying bulk patches even if not following the style: 132# Force applying bulk patches even if not following the style:
173# 133#
174# ??_${ARCH}_foo.${EPATCH_SUFFIX} 134# ??_${ARCH}_foo.${EPATCH_SUFFIX}
175# 135#
176EPATCH_FORCE="no" 136EPATCH_FORCE="no"
217 local x="" 177 local x=""
218 178
219 if [ "$#" -gt 1 ] 179 if [ "$#" -gt 1 ]
220 then 180 then
221 local m="" 181 local m=""
222 einfo "${#} patches to apply ..."
223 for m in "$@" ; do 182 for m in "$@" ; do
224 epatch "${m}" 183 epatch "${m}"
225 done 184 done
226 return 0 185 return 0
227 fi 186 fi
281 ;; 240 ;;
282 esac 241 esac
283 242
284 if [ "${SINGLE_PATCH}" = "no" ] 243 if [ "${SINGLE_PATCH}" = "no" ]
285 then 244 then
286 einfo "Applying various patches (bugfixes/updates) ..." 245 einfo "${EPATCH_MULTI_MSG}"
287 fi 246 fi
288 for x in ${EPATCH_SOURCE} 247 for x in ${EPATCH_SOURCE}
289 do 248 do
290 # New ARCH dependant patch naming scheme ... 249 # New ARCH dependant patch naming scheme ...
291 # 250 #
292 # ???_arch_foo.patch 251 # ???_arch_foo.patch
293 # 252 #
294 if [ -f ${x} ] && \ 253 if [ -f ${x} ] && \
295 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] || \ 254 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "${x/_${ARCH}_}" != "${x}" ] || \
296 [ "${EPATCH_FORCE}" = "yes" ]) 255 [ "${EPATCH_FORCE}" = "yes" ])
297 then 256 then
298 local count=0 257 local count=0
299 local popts="${EPATCH_OPTS}" 258 local popts="${EPATCH_OPTS}"
300 local patchname=${x##*/} 259 local patchname=${x##*/}
407 fi 366 fi
408 done 367 done
409 if [ "${SINGLE_PATCH}" = "no" ] 368 if [ "${SINGLE_PATCH}" = "no" ]
410 then 369 then
411 einfo "Done with patching" 370 einfo "Done with patching"
412 fi
413}
414
415# This function return true if we are using the NPTL pthreads
416# implementation.
417#
418# <azarah@gentoo.org> (06 March 2003)
419#
420have_NPTL() {
421 cat > ${T}/test-nptl.c <<-"END"
422 #define _XOPEN_SOURCE
423 #include <unistd.h>
424 #include <stdio.h>
425
426 int main()
427 {
428 char buf[255];
429 char *str = buf;
430
431 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, 255);
432 if (NULL != str) {
433 printf("%s\n", str);
434 if (NULL != strstr(str, "NPTL"))
435 return 0;
436 }
437
438 return 1;
439 }
440 END
441
442 einfon "Checking for _CS_GNU_LIBPTHREAD_VERSION support in glibc ..."
443 if gcc -o ${T}/nptl ${T}/test-nptl.c &> /dev/null
444 then
445 echo "yes"
446 einfon "Checking what PTHREADS implementation we have ..."
447 if ${T}/nptl
448 then
449 return 0
450 else
451 return 1
452 fi
453 else
454 echo "no"
455 fi
456
457 return 1
458}
459
460# This function check how many cpu's are present, and then set
461# -j in MAKEOPTS accordingly.
462#
463# Thanks to nall <nall@gentoo.org> for this.
464#
465get_number_of_jobs() {
466 local jobs=0
467
468 if [ ! -r /proc/cpuinfo ]
469 then
470 return 1
471 fi
472
473 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
474 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
475 then
476 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
477 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
478 ADMINPARAM="${ADMINPARAM/-j}"
479 fi
480
481 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
482
483 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
484 "${ARCH}" = "arm" -o "${ARCH}" = "mips" -o "${ARCH}" = "ia64" ]
485 then
486 # these archs will always have "[Pp]rocessor"
487 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
488
489 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
490 then
491 # sparc always has "ncpus active"
492 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
493
494 elif [ "${ARCH}" = "alpha" ]
495 then
496 # alpha has "cpus active", but only when compiled with SMP
497 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
498 then
499 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
500 else
501 jobs=2
502 fi
503
504 elif [ "${ARCH}" = "ppc" -o "${ARCH}" = "ppc64" ]
505 then
506 # ppc has "processor", but only when compiled with SMP
507 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
508 then
509 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
510 else
511 jobs=2
512 fi
513 elif [ "${ARCH}" = "s390" ]
514 then
515 # s390 has "# processors : "
516 jobs="$((`grep "^\# processors" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
517 else
518 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
519 die "Unknown ARCH -- ${ARCH}!"
520 fi
521
522 # Make sure the number is valid ...
523 if [ "${jobs}" -lt 1 ]
524 then
525 jobs=1
526 fi
527
528 if [ -n "${ADMINPARAM}" ]
529 then
530 if [ "${jobs}" -gt "${ADMINPARAM}" ]
531 then
532 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge ..."
533 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
534 else
535 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge ..."
536 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
537 fi
538 fi 371 fi
539} 372}
540 373
541# Cheap replacement for when debianutils (and thus mktemp) 374# Cheap replacement for when debianutils (and thus mktemp)
542# does not exist on the users system 375# does not exist on the users system
686 einfo " - Shell: ${eshell}" 519 einfo " - Shell: ${eshell}"
687 opts="${opts} -s ${eshell}" 520 opts="${opts} -s ${eshell}"
688 521
689 # handle homedir 522 # handle homedir
690 local ehome="$1"; shift 523 local ehome="$1"; shift
691 if [ -z "${ehome}" ] && [ "${eshell}" != "-1" ] 524 if [ -z "${ehome}" ] || [ "${eshell}" == "-1" ]
692 then 525 then
693 ehome="/dev/null" 526 ehome="/dev/null"
694 fi 527 fi
695 einfo " - Home: ${ehome}" 528 einfo " - Home: ${ehome}"
696 opts="${opts} -d ${ehome}" 529 opts="${opts} -d ${ehome}"
1025 *) 858 *)
1026 type= 859 type=
1027 ;; 860 ;;
1028 esac 861 esac
1029 fi 862 fi
1030 863 if [ "${SLOT}" == "0" ] ; then
864 local desktop_name="${PN}"
865 else
866 local desktop_name="${PN}-${SLOT}"
867 fi
1031 local desktop=${T}/${exec%% *}-${P}.desktop 868 local desktop=${T}/${exec%% *}-${desktop_name}.desktop
1032 869
1033echo "[Desktop Entry] 870echo "[Desktop Entry]
1034Encoding=UTF-8 871Encoding=UTF-8
1035Version=0.9.2 872Version=0.9.2
1036Name=${name} 873Name=${name}
1052# make_desktop_entry(<title>, <command>) 889# make_desktop_entry(<title>, <command>)
1053# title: File to execute to start the Window Manager 890# title: File to execute to start the Window Manager
1054# command: Name of the Window Manager 891# command: Name of the Window Manager
1055 892
1056make_session_desktop() { 893make_session_desktop() {
1057
1058 [ -z "$1" ] && eerror "make_session_desktop: You must specify the title" && return 1 894 [[ -z $1 ]] && eerror "make_session_desktop: You must specify the title" && return 1
1059 [ -z "$2" ] && eerror "make_session_desktop: You must specify the command" && return 1 895 [[ -z $2 ]] && eerror "make_session_desktop: You must specify the command" && return 1
1060 896
1061 local title="${1}" 897 local title=$1
1062 local command="${2}" 898 local command=$2
1063 local desktop="${T}/${wm}.desktop" 899 local desktop=${T}/${wm}.desktop
1064 900
1065echo "[Desktop Entry] 901echo "[Desktop Entry]
1066Encoding=UTF-8 902Encoding=UTF-8
1067Name=${title} 903Name=${title}
1068Comment=This session logs you into ${title} 904Comment=This session logs you into ${title}
1070TryExec=${command} 906TryExec=${command}
1071Type=Application" > "${desktop}" 907Type=Application" > "${desktop}"
1072 908
1073 insinto /usr/share/xsessions 909 insinto /usr/share/xsessions
1074 doins "${desktop}" 910 doins "${desktop}"
1075
1076 return 0
1077} 911}
1078 912
1079domenu() { 913domenu() {
1080 local i 914 local i j
1081 local j
1082 insinto /usr/share/applications 915 insinto /usr/share/applications
1083 for i in ${@} 916 for i in "$@" ; do
1084 do
1085 if [ -f "${i}" ]; 917 if [[ -f ${i} ]] ; then
1086 then
1087 doins ${i} 918 doins "${i}"
1088 elif [ -d "${i}" ]; 919 elif [[ -d ${i} ]] ; then
1089 then
1090 for j in ${i}/*.desktop 920 for j in "${i}"/*.desktop ; do
1091 do
1092 doins ${j} 921 doins "${j}"
1093 done 922 done
1094 fi 923 fi
1095 done 924 done
1096} 925}
926newmenu() {
927 insinto /usr/share/applications
928 newins "$1" "$2"
929}
1097 930
1098doicon() { 931doicon() {
1099 local i 932 local i j
1100 local j
1101 insinto /usr/share/pixmaps 933 insinto /usr/share/pixmaps
1102 for i in ${@} 934 for i in "$@" ; do
1103 do
1104 if [ -f "${i}" ]; 935 if [[ -f ${i} ]] ; then
1105 then
1106 doins ${i} 936 doins "${i}"
1107 elif [ -d "${i}" ]; 937 elif [[ -d ${i} ]] ; then
1108 then
1109 for j in ${i}/*.png 938 for j in "${i}"/*.png ; do
1110 do
1111 doins ${j} 939 doins "${j}"
1112 done 940 done
1113 fi 941 fi
1114 done 942 done
943}
944newicon() {
945 insinto /usr/share/pixmaps
946 newins "$1" "$2"
1115} 947}
1116 948
1117############################################################## 949##############################################################
1118# END: Handle .desktop files and menu entries # 950# END: Handle .desktop files and menu entries #
1119############################################################## 951##############################################################
1520 local mline="" 1352 local mline=""
1521 local showedmsg=0 1353 local showedmsg=0
1522 1354
1523 for mline in $(mount | egrep -e '(iso|cdrom)' | awk '{print $3}') ; do 1355 for mline in $(mount | egrep -e '(iso|cdrom)' | awk '{print $3}') ; do
1524 [[ -d ${mline}/${dir} ]] || continue 1356 [[ -d ${mline}/${dir} ]] || continue
1525 [[ ! -z $(find ${mline}/${dir} -iname ${file} -maxdepth 1) ]] \ 1357 [[ ! -z $(find ${mline}/${dir} -maxdepth 1 -iname ${file}) ]] \
1526 && export CDROM_ROOT=${mline} 1358 && export CDROM_ROOT=${mline}
1527 done 1359 done
1528 1360
1529 if [[ -z ${CDROM_ROOT} ]] ; then 1361 if [[ -z ${CDROM_ROOT} ]] ; then
1530 echo 1362 echo
1598 else 1430 else
1599 ewarn "Sorry, but ${PN} does not support the ${f} LINGUA" 1431 ewarn "Sorry, but ${PN} does not support the ${f} LINGUA"
1600 fi 1432 fi
1601 done 1433 done
1602 if [[ -z ${newls} ]] ; then 1434 if [[ -z ${newls} ]] ; then
1603 unset LINGUAS 1435 export LINGUAS=""
1604 else 1436 else
1605 export LINGUAS=${newls:1} 1437 export LINGUAS=${newls:1}
1606 fi 1438 fi
1607} 1439}
1608 1440
1618 while ((i--)) ; do 1450 while ((i--)) ; do
1619 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass" 1451 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass"
1620 done 1452 done
1621 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}" 1453 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}"
1622 case ${ARCH} in 1454 case ${ARCH} in
1623 x86) export ARCH="i386";; 1455 x86) export ARCH="i386";;
1624 amd64) export ARCH="x86_64";; 1456 amd64) export ARCH="x86_64";;
1625 hppa) export ARCH="parisc";; 1457 hppa) export ARCH="parisc";;
1626 mips) export ARCH="mips";; 1458 mips) export ARCH="mips";;
1627 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one! 1459 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one!
1628 *) export ARCH="${ARCH}";; 1460 *) export ARCH="${ARCH}";;
1629 esac 1461 esac
1630} 1462}
1631 1463
1632# set's ARCH back to what portage expects 1464# set's ARCH back to what portage expects
1633set_arch_to_portage() { 1465set_arch_to_portage() {
1740dopamd() { 1572dopamd() {
1741 [[ -z $1 ]] && die "dopamd requires at least one argument" 1573 [[ -z $1 ]] && die "dopamd requires at least one argument"
1742 1574
1743 use pam || return 0 1575 use pam || return 0
1744 1576
1745 insinto /etc/pam.d 1577 INSDESTTREE=/etc/pam.d \
1746 doins "$@" || die "failed to install $@" 1578 doins "$@" || die "failed to install $@"
1747} 1579}
1748# newpamd <old name> <new name> 1580# newpamd <old name> <new name>
1749# 1581#
1750# Install pam file <old name> as <new name> in /etc/pam.d 1582# Install pam file <old name> as <new name> in /etc/pam.d
1751newpamd() { 1583newpamd() {
1752 [[ $# -ne 2 ]] && die "newpamd requires two arguements" 1584 [[ $# -ne 2 ]] && die "newpamd requires two arguements"
1753 1585
1754 use pam || return 0 1586 use pam || return 0
1755 1587
1756 insinto /etc/pam.d 1588 INSDESTTREE=/etc/pam.d \
1757 newins "$1" "$2" || die "failed to install $1 as $2" 1589 newins "$1" "$2" || die "failed to install $1 as $2"
1758} 1590}
1759 1591
1760# make a wrapper script ... 1592# make a wrapper script ...
1761# NOTE: this was originally games_make_wrapper, but I noticed other places where 1593# NOTE: this was originally games_make_wrapper, but I noticed other places where

Legend:
Removed from v.1.164  
changed lines
  Added in v.1.178

  ViewVC Help
Powered by ViewVC 1.1.20