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

Diff of /eclass/eutils.eclass

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

Revision 1.32 Revision 1.41
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
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.32 2003/06/10 17:30:21 danarmak Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.41 2003/07/14 04:47:17 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.
400 ADMINPARAM="${ADMINPARAM/-j}" 400 ADMINPARAM="${ADMINPARAM/-j}"
401 fi 401 fi
402 402
403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" 403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
404 404
405 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ 405 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] 406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
407 then 407 then
408 # these archs will always have "[Pp]rocessor" 408 # these archs will always have "[Pp]rocessor"
409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" 409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
410 410
549 fi 549 fi
550 einfo " - Groups: ${egroups}" 550 einfo " - Groups: ${egroups}"
551 551
552 # handle extra and add the user 552 # handle extra and add the user
553 local eextra="$@" 553 local eextra="$@"
554 local oldsandbox="${oldsandbox}" 554 local oldsandbox=${SANDBOX_ON}
555 export SANDBOX_ON="0" 555 export SANDBOX_ON="0"
556 if [ -z "${eextra}" ] ; then 556 if [ -z "${eextra}" ] ; then
557 useradd ${opts} ${euser} \ 557 useradd ${opts} ${euser} \
558 -c "added by portage for ${PN}" \ 558 -c "added by portage for ${PN}" \
559 || die "enewuser failed" 559 || die "enewuser failed"
565 export SANDBOX_ON="${oldsandbox}" 565 export SANDBOX_ON="${oldsandbox}"
566 566
567 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then 567 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
568 einfo " - Creating ${ehome} in ${D}" 568 einfo " - Creating ${ehome} in ${D}"
569 dodir ${ehome} 569 dodir ${ehome}
570 fperms ${euser} ${ehome} 570 fowners ${euser} ${ehome}
571 fperms 755 ${ehome}
571 fi 572 fi
572} 573}
573 574
574# Simplify/standardize adding groups to the system 575# Simplify/standardize adding groups to the system
575# vapier@gentoo.org 576# vapier@gentoo.org
621 # handle extra 622 # handle extra
622 local eextra="$@" 623 local eextra="$@"
623 opts="${opts} ${eextra}" 624 opts="${opts} ${eextra}"
624 625
625 # add the group 626 # add the group
626 local oldsandbox="${oldsandbox}" 627 local oldsandbox=${SANDBOX_ON}
627 export SANDBOX_ON="0" 628 export SANDBOX_ON="0"
628 groupadd ${opts} ${egroup} || die "enewgroup failed" 629 groupadd ${opts} ${egroup} || die "enewgroup failed"
629 export SANDBOX_ON="${oldsandbox}" 630 export SANDBOX_ON="${oldsandbox}"
630} 631}
631 632
634# 635#
635# edos2unix(file, <more files>...) 636# edos2unix(file, <more files>...)
636edos2unix() { 637edos2unix() {
637 for f in $@ ; do 638 for f in $@ ; do
638 cp ${f} ${T}/edos2unix 639 cp ${f} ${T}/edos2unix
639 rm -f ${f}
640 sed 's/\r$//' ${T}/edos2unix > ${f} 640 sed 's/\r$//' ${T}/edos2unix > ${f}
641 rm -f ${T}/edos2unix
642 done 641 done
643} 642}
644 643
645# new convinience patch wapper function to eventually replace epatch(), $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and /usr/bin/patch 644# Make a desktop file !
645# Great for making those icons in kde/gnome startmenu !
646# Amaze your friends ! Get the women ! Join today !
647# gnome2 /usr/share/applications
648# gnome1 /usr/share/gnome/apps/
649# KDE ${KDEDIR}/share/applnk /usr/share/applnk
650#
651# make_desktop_entry(<binary>, [name], [icon], [type], [path])
652#
653# binary: what binary does the app run with ?
654# name: the name that will show up in the menu
655# icon: give your little like a pretty little icon ...
656# this can be relative (to /usr/share/pixmaps) or
657# a full path to an icon
658# type: what kind of application is this ? for categories:
659# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
660# path: if your app needs to startup in a specific dir
661make_desktop_entry() {
662 [ -z "$1" ] && eerror "You must specify the executable" && return 1
663
664 local exec=${1}
665 local name=${2:-${PN}}
666 local icon=${3:-${PN}.png}
667 local type=${4}
668 local path=${5:-${GAMES_PREFIX}}
669 if [ -z "${type}" ] ; then
670 case ${CATEGORY} in
671 app-emulation) type=Emulator ;;
672 app-games) type=Game ;;
673 *) type="" ;;
674 esac
675 fi
676 local desktop=${T}/${exec}.desktop
677
678echo "[Desktop Entry]
679Encoding=UTF-8
680Version=0.9.2
681Name=${name}
682Type=Application
683Comment=${DESCRIPTION}
684Exec=${exec}
685Path=${path}
686Icon=${icon}
687Categories=Application;${type};" > ${desktop}
688
689 if [ -d /usr/share/applications ] ; then
690 insinto /usr/share/applications
691 doins ${desktop}
692 fi
693
694 #if [ -d /usr/share/gnome/apps ] ; then
695 # insinto /usr/share/gnome/apps/Games
696 # doins ${desktop}
697 #fi
698
699 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
700 # for ver in /usr/kde/* ; do
701 # insinto ${ver}/share/applnk/Games
702 # doins ${desktop}
703 # done
704 #fi
705
706 if [ -d /usr/share/applnk ] ; then
707 insinto /usr/share/applnk/${type}
708 doins ${desktop}
709 fi
710
711 return 0
712}
713
714# new convenience patch wrapper function to eventually replace epatch(),
715# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
716# /usr/bin/patch
646# Features: 717# Features:
647# - bulk patch handling similar to epatch()'s 718# - bulk patch handling similar to epatch()'s
648# - automatic patch level detection like epatch()'s 719# - automatic patch level detection like epatch()'s
649# - semiautomatic patch uncompression like epatch()'s (may switch to using /usr/bin/file for extra power, instead of just looking at the filename) 720# - automatic patch uncompression like epatch()'s
650# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles manually instead 721# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
651# - is called from base_src_unpack to handle $PATCHES to avoid defining src_unpack(-) just to use xpatch 722# manually instead
723# - once I decide it's production-ready, it'll be called from base_src_unpack
724# to handle $PATCHES to avoid defining src_unpack just to use xpatch
652 725
653# accepts zero or more parameters specifying patchfiles and/or patchdirs 726# accepts zero or more parameters specifying patchfiles and/or patchdirs
654 727
655# known issues: 728# known issues:
656# - only supports unified style patches (does anyone _really_ use anything else?) 729# - only supports unified style patches (does anyone _really_ use anything
657# - first file addressed in a patch can't have spaces in its name or in the path mentioned in the patchfile 730# else?)
658# (can be easily fixed to be: at least one file addressed in the patch must have no spaces...) 731# - because it doesn't use --dry-run there is a risk of it failing
732# to find the files to patch, ie detect the patchlevel, properly. It doesn't use
733# any of the backup heuristics that patch employs to discover a filename.
734# however, this isn't dangerous because if it works for the developer who's
735# writing the ebuild, it'll always work for the users, and if it doesn't,
736# then we'll fix it :-)
737# - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
659xpatch() { 738xpatch() {
660 739
661 debug-print-function $FUNCNAME $* 740 debug-print-function $FUNCNAME $*
662 741
663 local list="" 742 local list=""
697 *) die "Could not determine filetype of patch $x";; 776 *) die "Could not determine filetype of patch $x";;
698 esac 777 esac
699 debug-print "$FUNCNAME: patchfile=$patchfile" 778 debug-print "$FUNCNAME: patchfile=$patchfile"
700 779
701 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base. 780 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
702 target="`/bin/grep '+++' $patchfile | /usr/bin/tail -1`" 781 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
703 debug-print "$FUNCNAME: raw target=$target" 782 debug-print "$FUNCNAME: raw target=$target"
704 # strip target down to the path/filename. NOTE doesn't support filenames/paths with spaces in them :-( 783 # strip target down to the path/filename, remove leading +++
705 # remove leading +++ 784 target="${target/+++ }"; target="${target%% *}"
706 target="${target/+++ }"
707 # ugly, yes. i dunno why doesn't this work instead: target=${target%% *}
708 for foo in $target; do target="$foo"; break; done
709 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need to discard them as well 785 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
710 # to calculate the correct patchlevel. 786 # to discard them as well to calculate the correct patchlevel.
711 while [ "$target" != "${target/\/\/}" ]; do
712 target="${target/\/\//\/}" 787 target="${target//\/\//\/}"
713 done
714 debug-print "$FUNCNAME: stripped target=$target" 788 debug-print "$FUNCNAME: stripped target=$target"
715 789
716 # look for target 790 # look for target
717 for basedir in "$S" "$WORKDIR" "`pwd`"; do 791 for basedir in "$S" "$WORKDIR" "${PWD}"; do
718 debug-print "$FUNCNAME: looking in basedir=$basedir" 792 debug-print "$FUNCNAME: looking in basedir=$basedir"
719 cd "$basedir" 793 cd "$basedir"
720 794
721 # try stripping leading directories 795 # try stripping leading directories
722 target2="$target" 796 target2="$target"
752 eend $? 826 eend $?
753 827
754 done 828 done
755 829
756} 830}
831
832# Unpack those pesky makeself generated files ...
833# They're shell scripts with the binary package tagged onto
834# the end of the archive. Loki utilized the format as does
835# many other game companies.
836#
837# Usage: unpack_makeself [file to unpack] [offset]
838# - If the file is not specified then unpack will utilize ${A}.
839# - If the offset is not specified then we will attempt to extract
840# the proper offset from the script itself.
841unpack_makeself() {
842 local src=$1
843 local skip=$2
844
845 [ -z "${src}" ] && src=${A}
846 [ -e ./${src} ] \
847 && src=${PWD}/${src} \
848 || src=${DISTDIR}/${src}
849 local shrtsrc=`basename ${src}`
850 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
851 if [ -z "${skip}" ] ; then
852 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
853 local skip=0
854 case ${ver} in
855 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
856 skip=`grep -a ^skip= ${src} | cut -d= -f2`
857 ;;
858 2.0|2.0.1)
859 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
860 ;;
861 2.1.1)
862 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
863 let skip="skip + 1"
864 ;;
865 *)
866 eerror "I'm sorry, but I was unable to support the Makeself file."
867 eerror "The version I detected was '${ver}'."
868 eerror "Please file a bug about the file ${shrtsrc} at"
869 eerror "http://bugs.gentoo.org/ so that support can be added."
870 die "makeself version '${ver}' not supported"
871 ;;
872 esac
873 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
874 fi
875
876 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
877 # to tar which will make tar not extract anything and exit with 0
878 local out="`tail +${skip} ${src} | gzip -cd | tar -x --no-same-owner -v -f -`"
879 [ -z "${out}" ] && die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
880}

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.20