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

Diff of /eclass/eutils.eclass

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

Revision 1.27 Revision 1.45
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.27 2003/03/10 08:49:05 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.45 2003/07/18 20:43:00 wolf31o2 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.
10# NB: If you add anything, please comment it! 10# NB: If you add anything, please comment it!
11 11
12ECLASS=eutils 12ECLASS=eutils
13INHERITED="$INHERITED $ECLASS" 13INHERITED="$INHERITED $ECLASS"
14 14
15newdepend "!bootstrap? ( sys-devel/patch )" 15DEPEND="$DEPEND !bootstrap? ( sys-devel/patch )"
16 16
17DESCRIPTION="Based on the ${ECLASS} eclass" 17DESCRIPTION="Based on the ${ECLASS} eclass"
18 18
19# This function generate linker scripts in /usr/lib for dynamic 19# This function generate linker scripts in /usr/lib for dynamic
20# libs in /lib. This is to fix linking problems when you have 20# libs in /lib. This is to fix linking problems when you have
36# 36#
37gen_usr_ldscript() { 37gen_usr_ldscript() {
38 38
39 # Just make sure it exists 39 # Just make sure it exists
40 dodir /usr/lib 40 dodir /usr/lib
41 41
42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT" 42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
43/* GNU ld script 43/* GNU ld script
44 Because Gentoo have critical dynamic libraries 44 Because Gentoo have critical dynamic libraries
45 in /lib, and the static versions in /usr/lib, we 45 in /lib, and the static versions in /usr/lib, we
46 need to have a "fake" dynamic lib in /usr/lib, 46 need to have a "fake" dynamic lib in /usr/lib,
70 return 0 70 return 0
71 fi 71 fi
72 72
73 # Get the length of $* 73 # Get the length of $*
74 str_length="$(echo -n "$*" | wc -m)" 74 str_length="$(echo -n "$*" | wc -m)"
75 75
76 while [ "$i" -lt "${str_length}" ] 76 while [ "$i" -lt "${str_length}" ]
77 do 77 do
78 echo -n "=" 78 echo -n "="
79 79
80 i=$((i + 1)) 80 i=$((i + 1))
81 done 81 done
82 82
83 echo 83 echo
84 84
94# List of patches not to apply. Not this is only file names, 94# List of patches not to apply. Not this is only file names,
95# and not the full path .. 95# and not the full path ..
96EPATCH_EXCLUDE="" 96EPATCH_EXCLUDE=""
97# Change the printed message for a single patch. 97# Change the printed message for a single patch.
98EPATCH_SINGLE_MSG="" 98EPATCH_SINGLE_MSG=""
99# Force applying bulk patches even if not following the style:
100#
101# ??_${ARCH}_foo.${EPATCH_SUFFIX}
102#
103EPATCH_FORCE="no"
99 104
100# This function is for bulk patching, or in theory for just one 105# This function is for bulk patching, or in theory for just one
101# or two patches. 106# or two patches.
102# 107#
103# It should work with .bz2, .gz, .zip and plain text patches. 108# It should work with .bz2, .gz, .zip and plain text patches.
145 fi 150 fi
146 151
147 if [ -n "$1" -a -f "$1" ] 152 if [ -n "$1" -a -f "$1" ]
148 then 153 then
149 SINGLE_PATCH="yes" 154 SINGLE_PATCH="yes"
150 155
151 local EPATCH_SOURCE="$1" 156 local EPATCH_SOURCE="$1"
152 local EPATCH_SUFFIX="${1##*\.}" 157 local EPATCH_SUFFIX="${1##*\.}"
153 158
154 elif [ -n "$1" -a -d "$1" ] 159 elif [ -n "$1" -a -d "$1" ]
155 then 160 then
161 # Allow no extension if EPATCH_FORCE=yes ... used by vim for example ...
162 if [ "${EPATCH_FORCE}" = "yes" ] && [ -z "${EPATCH_SUFFIX}" ]
163 then
164 local EPATCH_SOURCE="$1/*"
165 else
156 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 166 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
167 fi
157 else 168 else
158 if [ ! -d ${EPATCH_SOURCE} ] 169 if [ ! -d ${EPATCH_SOURCE} ]
159 then 170 then
160 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ] 171 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
161 then 172 then
167 eerror 178 eerror
168 eerror " ${EPATCH_SOURCE}" 179 eerror " ${EPATCH_SOURCE}"
169 echo 180 echo
170 die "Cannot find \$EPATCH_SOURCE!" 181 die "Cannot find \$EPATCH_SOURCE!"
171 fi 182 fi
172 183
173 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
174 fi 185 fi
175 186
176 case ${EPATCH_SUFFIX##*\.} in 187 case ${EPATCH_SUFFIX##*\.} in
177 bz2) 188 bz2)
201 # New ARCH dependant patch naming scheme... 212 # New ARCH dependant patch naming scheme...
202 # 213 #
203 # ???_arch_foo.patch 214 # ???_arch_foo.patch
204 # 215 #
205 if [ -f ${x} ] && \ 216 if [ -f ${x} ] && \
206 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] 217 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] || \
218 [ "${EPATCH_FORCE}" = "yes" ])
207 then 219 then
208 local count=0 220 local count=0
209 local popts="${EPATCH_OPTS}" 221 local popts="${EPATCH_OPTS}"
210 222
211 if [ -n "${EPATCH_EXCLUDE}" ] 223 if [ -n "${EPATCH_EXCLUDE}" ]
213 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ] 225 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
214 then 226 then
215 continue 227 continue
216 fi 228 fi
217 fi 229 fi
218 230
219 if [ "${SINGLE_PATCH}" = "yes" ] 231 if [ "${SINGLE_PATCH}" = "yes" ]
220 then 232 then
221 if [ -n "${EPATCH_SINGLE_MSG}" ] 233 if [ -n "${EPATCH_SINGLE_MSG}" ]
222 then 234 then
223 einfo "${EPATCH_SINGLE_MSG}" 235 einfo "${EPATCH_SINGLE_MSG}"
243 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 255 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 256 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
245 else 257 else
246 PATCH_TARGET="${x}" 258 PATCH_TARGET="${x}"
247 fi 259 fi
248 260
249 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 261 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
250 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 262 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
251 263
252 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 264 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
253 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 265 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
254 266
255 if [ "${PATCH_SUFFIX}" != "patch" ] 267 if [ "${PATCH_SUFFIX}" != "patch" ]
256 then 268 then
261 #die "Could not extract patch!" 273 #die "Could not extract patch!"
262 count=5 274 count=5
263 break 275 break
264 fi 276 fi
265 fi 277 fi
266 278
267 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1 279 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
268 then 280 then
269 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 281 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
270 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 282 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
271 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 283 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
283 #die "Real world sux compared to the dreamworld!" 295 #die "Real world sux compared to the dreamworld!"
284 count=5 296 count=5
285 fi 297 fi
286 298
287 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 299 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
288 300
289 break 301 break
290 fi 302 fi
291 303
292 count=$((count + 1)) 304 count=$((count + 1))
293 done 305 done
387 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`" 399 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
388 ADMINPARAM="${ADMINPARAM/-j}" 400 ADMINPARAM="${ADMINPARAM/-j}"
389 fi 401 fi
390 402
391 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" 403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
392 404
393 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ 405 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
394 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] 406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
395 then 407 then
396 # these archs will always have "[Pp]rocessor" 408 # these archs will always have "[Pp]rocessor"
397 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" 409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
398 410
399 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] 411 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
400 then 412 then
401 # sparc always has "ncpus active" 413 # sparc always has "ncpus active"
402 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 414 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
403 415
404 elif [ "${ARCH}" = "alpha" ] 416 elif [ "${ARCH}" = "alpha" ]
405 then 417 then
406 # alpha has "cpus active", but only when compiled with SMP 418 # alpha has "cpus active", but only when compiled with SMP
407 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] 419 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
408 then 420 then
409 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 421 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
410 else 422 else
411 jobs=2 423 jobs=2
412 fi 424 fi
413 425
414 elif [ "${ARCH}" = "ppc" ] 426 elif [ "${ARCH}" = "ppc" ]
415 then 427 then
416 # ppc has "processor", but only when compiled with SMP 428 # ppc has "processor", but only when compiled with SMP
417 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] 429 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
418 then 430 then
428 # Make sure the number is valid ... 440 # Make sure the number is valid ...
429 if [ "${jobs}" -lt 1 ] 441 if [ "${jobs}" -lt 1 ]
430 then 442 then
431 jobs=1 443 jobs=1
432 fi 444 fi
433 445
434 if [ -n "${ADMINPARAM}" ] 446 if [ -n "${ADMINPARAM}" ]
435 then 447 then
436 if [ "${jobs}" -gt "${ADMINPARAM}" ] 448 if [ "${jobs}" -gt "${ADMINPARAM}" ]
437 then 449 then
438 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." 450 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
462 local euser="$1"; shift 474 local euser="$1"; shift
463 if [ -z "${euser}" ] ; then 475 if [ -z "${euser}" ] ; then
464 eerror "No username specified !" 476 eerror "No username specified !"
465 die "Cannot call enewuser without a username" 477 die "Cannot call enewuser without a username"
466 fi 478 fi
467 einfo "Adding user '${euser}' to your system ..."
468 479
469 # setup a file for testing usernames/groups 480 # setup a file for testing usernames/groups
470 local tmpfile="`mktemp -p ${T}`" 481 local tmpfile="`mktemp -p ${T}`"
471 touch ${tmpfile} 482 touch ${tmpfile}
472 chown ${euser} ${tmpfile} >& /dev/null 483 chown ${euser} ${tmpfile} >& /dev/null
473 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`" 484 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
474 485
475 # see if user already exists 486 # see if user already exists
476 if [ "${euser}" == "${realuser}" ] ; then 487 if [ "${euser}" == "${realuser}" ] ; then
477 einfo "${euser} already exists on your system :)"
478 return 0 488 return 0
479 fi 489 fi
490 einfo "Adding user '${euser}' to your system ..."
480 491
481 # options to pass to useradd 492 # options to pass to useradd
482 local opts="" 493 local opts=""
483 494
484 # handle uid 495 # handle uid
537 fi 548 fi
538 einfo " - Groups: ${egroups}" 549 einfo " - Groups: ${egroups}"
539 550
540 # handle extra and add the user 551 # handle extra and add the user
541 local eextra="$@" 552 local eextra="$@"
542 local oldsandbox="${oldsandbox}" 553 local oldsandbox=${SANDBOX_ON}
543 export SANDBOX_ON="0" 554 export SANDBOX_ON="0"
544 if [ -z "${eextra}" ] ; then 555 if [ -z "${eextra}" ] ; then
545 useradd ${opts} ${euser} \ 556 useradd ${opts} ${euser} \
546 -c "added by portage for ${PN}" \ 557 -c "added by portage for ${PN}" \
547 || die "enewuser failed" 558 || die "enewuser failed"
548 else 559 else
549 einfo " - Extra: ${eextra}" 560 einfo " - Extra: ${eextra}"
550 useradd ${opts} ${euser} ${eextra} \ 561 useradd ${opts} ${euser} ${eextra} \
551 || die "enewuser failed" 562 || die "enewuser failed"
552 fi 563 fi
553 export SANDBOX_ON="${oldsandbox}" 564 export SANDBOX_ON="${oldsandbox}"
554 565
555 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then 566 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
556 einfo " - Creating ${ehome} in ${D}" 567 einfo " - Creating ${ehome} in ${D}"
557 dodir ${ehome} 568 dodir ${ehome}
558 fperms ${euser} ${ehome} 569 fowners ${euser} ${ehome}
570 fperms 755 ${ehome}
559 fi 571 fi
560} 572}
561 573
562# Simplify/standardize adding groups to the system 574# Simplify/standardize adding groups to the system
563# vapier@gentoo.org 575# vapier@gentoo.org
573 local egroup="$1"; shift 585 local egroup="$1"; shift
574 if [ -z "${egroup}" ] ; then 586 if [ -z "${egroup}" ] ; then
575 eerror "No group specified !" 587 eerror "No group specified !"
576 die "Cannot call enewgroup without a group" 588 die "Cannot call enewgroup without a group"
577 fi 589 fi
578 einfo "Adding group '${egroup}' to your system ..."
579 590
580 # setup a file for testing groupname 591 # setup a file for testing groupname
581 local tmpfile="`mktemp -p ${T}`" 592 local tmpfile="`mktemp -p ${T}`"
582 touch ${tmpfile} 593 touch ${tmpfile}
583 chgrp ${egroup} ${tmpfile} >& /dev/null 594 chgrp ${egroup} ${tmpfile} >& /dev/null
584 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" 595 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
585 596
586 # see if group already exists 597 # see if group already exists
587 if [ "${egroup}" == "${realgroup}" ] ; then 598 if [ "${egroup}" == "${realgroup}" ] ; then
588 einfo "${egroup} already exists on your system :)"
589 return 0 599 return 0
590 fi 600 fi
601 einfo "Adding group '${egroup}' to your system ..."
591 602
592 # options to pass to useradd 603 # options to pass to useradd
593 local opts="" 604 local opts=""
594 605
595 # handle gid 606 # handle gid
609 # handle extra 620 # handle extra
610 local eextra="$@" 621 local eextra="$@"
611 opts="${opts} ${eextra}" 622 opts="${opts} ${eextra}"
612 623
613 # add the group 624 # add the group
614 local oldsandbox="${oldsandbox}" 625 local oldsandbox=${SANDBOX_ON}
615 export SANDBOX_ON="0" 626 export SANDBOX_ON="0"
616 groupadd ${opts} ${egroup} || die "enewgroup failed" 627 groupadd ${opts} ${egroup} || die "enewgroup failed"
617 export SANDBOX_ON="${oldsandbox}" 628 export SANDBOX_ON="${oldsandbox}"
618} 629}
619 630
621# vapier@gentoo.org 632# vapier@gentoo.org
622# 633#
623# edos2unix(file, <more files>...) 634# edos2unix(file, <more files>...)
624edos2unix() { 635edos2unix() {
625 for f in $@ ; do 636 for f in $@ ; do
626 cp ${f} ${T}/ 637 cp ${f} ${T}/edos2unix
627 sed 's/\r$//' ${T}/${f} > ${f} 638 sed 's/\r$//' ${T}/edos2unix > ${f}
628 done 639 done
629} 640}
641
642# Make a desktop file !
643# Great for making those icons in kde/gnome startmenu !
644# Amaze your friends ! Get the women ! Join today !
645# gnome2 /usr/share/applications
646# gnome1 /usr/share/gnome/apps/
647# KDE ${KDEDIR}/share/applnk /usr/share/applnk
648#
649# make_desktop_entry(<binary>, [name], [icon], [type], [path])
650#
651# binary: what binary does the app run with ?
652# name: the name that will show up in the menu
653# icon: give your little like a pretty little icon ...
654# this can be relative (to /usr/share/pixmaps) or
655# a full path to an icon
656# type: what kind of application is this ? for categories:
657# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
658# path: if your app needs to startup in a specific dir
659make_desktop_entry() {
660 [ -z "$1" ] && eerror "You must specify the executable" && return 1
661
662 local exec=${1}
663 local name=${2:-${PN}}
664 local icon=${3:-${PN}.png}
665 local type=${4}
666 local path=${5:-${GAMES_PREFIX}}
667 if [ -z "${type}" ] ; then
668 case ${CATEGORY} in
669 app-emulation) type=Emulator ;;
670 app-games) type=Game ;;
671 *) type="" ;;
672 esac
673 fi
674 local desktop=${T}/${exec}.desktop
675
676echo "[Desktop Entry]
677Encoding=UTF-8
678Version=0.9.2
679Name=${name}
680Type=Application
681Comment=${DESCRIPTION}
682Exec=${exec}
683Path=${path}
684Icon=${icon}
685Categories=Application;${type};" > ${desktop}
686
687 if [ -d /usr/share/applications ] ; then
688 insinto /usr/share/applications
689 doins ${desktop}
690 fi
691
692 #if [ -d /usr/share/gnome/apps ] ; then
693 # insinto /usr/share/gnome/apps/Games
694 # doins ${desktop}
695 #fi
696
697 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
698 # for ver in /usr/kde/* ; do
699 # insinto ${ver}/share/applnk/Games
700 # doins ${desktop}
701 # done
702 #fi
703
704 if [ -d /usr/share/applnk ] ; then
705 insinto /usr/share/applnk/${type}
706 doins ${desktop}
707 fi
708
709 return 0
710}
711
712# new convenience patch wrapper function to eventually replace epatch(),
713# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
714# /usr/bin/patch
715# Features:
716# - bulk patch handling similar to epatch()'s
717# - automatic patch level detection like epatch()'s
718# - automatic patch uncompression like epatch()'s
719# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
720# manually instead
721# - once I decide it's production-ready, it'll be called from base_src_unpack
722# to handle $PATCHES to avoid defining src_unpack just to use xpatch
723
724# accepts zero or more parameters specifying patchfiles and/or patchdirs
725
726# known issues:
727# - only supports unified style patches (does anyone _really_ use anything
728# else?)
729# - because it doesn't use --dry-run there is a risk of it failing
730# to find the files to patch, ie detect the patchlevel, properly. It doesn't use
731# any of the backup heuristics that patch employs to discover a filename.
732# however, this isn't dangerous because if it works for the developer who's
733# writing the ebuild, it'll always work for the users, and if it doesn't,
734# then we'll fix it :-)
735# - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
736xpatch() {
737
738 debug-print-function $FUNCNAME $*
739
740 local list=""
741 local list2=""
742 declare -i plevel
743
744 # parse patch sources
745 for x in $*; do
746 debug-print "$FUNCNAME: parsing parameter $x"
747 if [ -f "$x" ]; then
748 list="$list $x"
749 elif [ -d "$x" ]; then
750 # handles patchdirs like epatch() for now: no recursion.
751 # patches are sorted by filename, so with an xy_foo naming scheme you'll get the right order.
752 # only patches with _$ARCH_ or _all_ in their filenames are applied.
753 for file in `ls -A $x`; do
754 debug-print "$FUNCNAME: parsing in subdir: file $file"
755 if [ -f "$x/$file" ] && [ "${file}" != "${file/_all_}" -o "${file}" != "${file/_$ARCH_}" ]; then
756 list2="$list2 $x/$file"
757 fi
758 done
759 list="`echo $list2 | sort` $list"
760 else
761 die "Couldn't find $x"
762 fi
763 done
764
765 debug-print "$FUNCNAME: final list of patches: $list"
766
767 for x in $list; do
768 debug-print "$FUNCNAME: processing $x"
769 # deal with compressed files. /usr/bin/file is in the system profile, or should be.
770 case "`/usr/bin/file -b $x`" in
771 *gzip*) patchfile="${T}/current.patch"; ungzip -c "$x" > "${patchfile}";;
772 *bzip2*) patchfile="${T}/current.patch"; bunzip2 -c "$x" > "${patchfile}";;
773 *text*) patchfile="$x";;
774 *) die "Could not determine filetype of patch $x";;
775 esac
776 debug-print "$FUNCNAME: patchfile=$patchfile"
777
778 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
779 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
780 debug-print "$FUNCNAME: raw target=$target"
781 # strip target down to the path/filename, remove leading +++
782 target="${target/+++ }"; target="${target%% *}"
783 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
784 # to discard them as well to calculate the correct patchlevel.
785 target="${target//\/\//\/}"
786 debug-print "$FUNCNAME: stripped target=$target"
787
788 # look for target
789 for basedir in "$S" "$WORKDIR" "${PWD}"; do
790 debug-print "$FUNCNAME: looking in basedir=$basedir"
791 cd "$basedir"
792
793 # try stripping leading directories
794 target2="$target"
795 plevel=0
796 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
797 while [ ! -f "$target2" ]; do
798 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
799 plevel=plevel+1
800 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
801 [ "$target2" == "${target2/\/}" ] && break
802 done
803 test -f "$target2" && break
804
805 # try stripping filename - needed to support patches creating new files
806 target2="${target%/*}"
807 plevel=0
808 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
809 while [ ! -d "$target2" ]; do
810 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
811 plevel=plevel+1
812 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
813 [ "$target2" == "${target2/\/}" ] && break
814 done
815 test -d "$target2" && break
816
817 done
818
819 test -f "${basedir}/${target2}" || test -d "${basedir}/${target2}" || die "Could not determine patchlevel for $x"
820 debug-print "$FUNCNAME: determined plevel=$plevel"
821 # do the patching
822 ebegin "Applying patch ${x##*/}..."
823 /usr/bin/patch -p$plevel < "$patchfile" > /dev/null || die "Failed to apply patch $x"
824 eend $?
825
826 done
827
828}
829
830# Unpack those pesky makeself generated files ...
831# They're shell scripts with the binary package tagged onto
832# the end of the archive. Loki utilized the format as does
833# many other game companies.
834#
835# Usage: unpack_makeself [file to unpack] [offset]
836# - If the file is not specified then unpack will utilize ${A}.
837# - If the offset is not specified then we will attempt to extract
838# the proper offset from the script itself.
839unpack_makeself() {
840 local src=$1
841 local skip=$2
842
843 [ -z "${src}" ] && src=${A}
844 [ -e ./${src} ] \
845 && src=${PWD}/${src} \
846 || src=${DISTDIR}/${src}
847 local shrtsrc=`basename ${src}`
848 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
849 if [ -z "${skip}" ] ; then
850 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
851 local skip=0
852 case ${ver} in
853 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
854 skip=`grep -a ^skip= ${src} | cut -d= -f2`
855 ;;
856 2.0|2.0.1)
857 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
858 ;;
859 2.1.1)
860 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
861 let skip="skip + 1"
862 ;;
863 *)
864 eerror "I'm sorry, but I was unable to support the Makeself file."
865 eerror "The version I detected was '${ver}'."
866 eerror "Please file a bug about the file ${shrtsrc} at"
867 eerror "http://bugs.gentoo.org/ so that support can be added."
868 die "makeself version '${ver}' not supported"
869 ;;
870 esac
871 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
872 fi
873
874 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
875 # to tar which will make tar not extract anything and exit with 0
876 local out="`tail +${skip} ${src} | gzip -cd | tar -x --no-same-owner -v -f -`"
877 [ -z "${out}" ] && die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
878}

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20