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

Diff of /eclass/eutils.eclass

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

Revision 1.31 Revision 1.32
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.31 2003/06/05 06:42:32 drobbins Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.32 2003/06/10 17:30:21 danarmak 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.
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
150 fi 150 fi
151 151
152 if [ -n "$1" -a -f "$1" ] 152 if [ -n "$1" -a -f "$1" ]
153 then 153 then
154 SINGLE_PATCH="yes" 154 SINGLE_PATCH="yes"
155 155
156 local EPATCH_SOURCE="$1" 156 local EPATCH_SOURCE="$1"
157 local EPATCH_SUFFIX="${1##*\.}" 157 local EPATCH_SUFFIX="${1##*\.}"
158 158
159 elif [ -n "$1" -a -d "$1" ] 159 elif [ -n "$1" -a -d "$1" ]
160 then 160 then
161 # Allow no extension if EPATCH_FORCE=yes ... used by vim for example ... 161 # Allow no extension if EPATCH_FORCE=yes ... used by vim for example ...
162 if [ "${EPATCH_FORCE}" = "yes" ] && [ -z "${EPATCH_SUFFIX}" ] 162 if [ "${EPATCH_FORCE}" = "yes" ] && [ -z "${EPATCH_SUFFIX}" ]
163 then 163 then
178 eerror 178 eerror
179 eerror " ${EPATCH_SOURCE}" 179 eerror " ${EPATCH_SOURCE}"
180 echo 180 echo
181 die "Cannot find \$EPATCH_SOURCE!" 181 die "Cannot find \$EPATCH_SOURCE!"
182 fi 182 fi
183 183
184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
185 fi 185 fi
186 186
187 case ${EPATCH_SUFFIX##*\.} in 187 case ${EPATCH_SUFFIX##*\.} in
188 bz2) 188 bz2)
225 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ] 225 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
226 then 226 then
227 continue 227 continue
228 fi 228 fi
229 fi 229 fi
230 230
231 if [ "${SINGLE_PATCH}" = "yes" ] 231 if [ "${SINGLE_PATCH}" = "yes" ]
232 then 232 then
233 if [ -n "${EPATCH_SINGLE_MSG}" ] 233 if [ -n "${EPATCH_SINGLE_MSG}" ]
234 then 234 then
235 einfo "${EPATCH_SINGLE_MSG}" 235 einfo "${EPATCH_SINGLE_MSG}"
255 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 255 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
256 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 256 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
257 else 257 else
258 PATCH_TARGET="${x}" 258 PATCH_TARGET="${x}"
259 fi 259 fi
260 260
261 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 261 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
262 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##*/}
263 263
264 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 264 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
265 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 265 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
266 266
267 if [ "${PATCH_SUFFIX}" != "patch" ] 267 if [ "${PATCH_SUFFIX}" != "patch" ]
268 then 268 then
273 #die "Could not extract patch!" 273 #die "Could not extract patch!"
274 count=5 274 count=5
275 break 275 break
276 fi 276 fi
277 fi 277 fi
278 278
279 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
280 then 280 then
281 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 281 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
282 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 282 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
283 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 283 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
295 #die "Real world sux compared to the dreamworld!" 295 #die "Real world sux compared to the dreamworld!"
296 count=5 296 count=5
297 fi 297 fi
298 298
299 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 299 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
300 300
301 break 301 break
302 fi 302 fi
303 303
304 count=$((count + 1)) 304 count=$((count + 1))
305 done 305 done
399 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]}'`"
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}" = "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
411 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] 411 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
412 then 412 then
413 # sparc always has "ncpus active" 413 # sparc always has "ncpus active"
414 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 414 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
415 415
416 elif [ "${ARCH}" = "alpha" ] 416 elif [ "${ARCH}" = "alpha" ]
417 then 417 then
418 # alpha has "cpus active", but only when compiled with SMP 418 # alpha has "cpus active", but only when compiled with SMP
419 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] 419 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
420 then 420 then
421 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" 421 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
422 else 422 else
423 jobs=2 423 jobs=2
424 fi 424 fi
425 425
426 elif [ "${ARCH}" = "ppc" ] 426 elif [ "${ARCH}" = "ppc" ]
427 then 427 then
428 # ppc has "processor", but only when compiled with SMP 428 # ppc has "processor", but only when compiled with SMP
429 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] 429 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
430 then 430 then
440 # Make sure the number is valid ... 440 # Make sure the number is valid ...
441 if [ "${jobs}" -lt 1 ] 441 if [ "${jobs}" -lt 1 ]
442 then 442 then
443 jobs=1 443 jobs=1
444 fi 444 fi
445 445
446 if [ -n "${ADMINPARAM}" ] 446 if [ -n "${ADMINPARAM}" ]
447 then 447 then
448 if [ "${jobs}" -gt "${ADMINPARAM}" ] 448 if [ "${jobs}" -gt "${ADMINPARAM}" ]
449 then 449 then
450 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." 450 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
558 -c "added by portage for ${PN}" \ 558 -c "added by portage for ${PN}" \
559 || die "enewuser failed" 559 || die "enewuser failed"
560 else 560 else
561 einfo " - Extra: ${eextra}" 561 einfo " - Extra: ${eextra}"
562 useradd ${opts} ${euser} ${eextra} \ 562 useradd ${opts} ${euser} ${eextra} \
563 || die "enewuser failed" 563 || die "enewuser failed"
564 fi 564 fi
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}"
639 rm -f ${f} 639 rm -f ${f}
640 sed 's/\r$//' ${T}/edos2unix > ${f} 640 sed 's/\r$//' ${T}/edos2unix > ${f}
641 rm -f ${T}/edos2unix 641 rm -f ${T}/edos2unix
642 done 642 done
643} 643}
644
645# new convinience patch wapper function to eventually replace epatch(), $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and /usr/bin/patch
646# Features:
647# - bulk patch handling similar to epatch()'s
648# - 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)
650# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles manually instead
651# - is called from base_src_unpack to handle $PATCHES to avoid defining src_unpack(-) just to use xpatch
652
653# accepts zero or more parameters specifying patchfiles and/or patchdirs
654
655# known issues:
656# - only supports unified style patches (does anyone _really_ use anything else?)
657# - first file addressed in a patch can't have spaces in its name or in the path mentioned in the patchfile
658# (can be easily fixed to be: at least one file addressed in the patch must have no spaces...)
659xpatch() {
660
661 debug-print-function $FUNCNAME $*
662
663 local list=""
664 local list2=""
665 declare -i plevel
666
667 # parse patch sources
668 for x in $*; do
669 debug-print "$FUNCNAME: parsing parameter $x"
670 if [ -f "$x" ]; then
671 list="$list $x"
672 elif [ -d "$x" ]; then
673 # handles patchdirs like epatch() for now: no recursion.
674 # patches are sorted by filename, so with an xy_foo naming scheme you'll get the right order.
675 # only patches with _$ARCH_ or _all_ in their filenames are applied.
676 for file in `ls -A $x`; do
677 debug-print "$FUNCNAME: parsing in subdir: file $file"
678 if [ -f "$x/$file" ] && [ "${file}" != "${file/_all_}" -o "${file}" != "${file/_$ARCH_}" ]; then
679 list2="$list2 $x/$file"
680 fi
681 done
682 list="`echo $list2 | sort` $list"
683 else
684 die "Couldn't find $x"
685 fi
686 done
687
688 debug-print "$FUNCNAME: final list of patches: $list"
689
690 for x in $list; do
691 debug-print "$FUNCNAME: processing $x"
692 # deal with compressed files. /usr/bin/file is in the system profile, or should be.
693 case "`/usr/bin/file -b $x`" in
694 *gzip*) patchfile="${T}/current.patch"; ungzip -c "$x" > "${patchfile}";;
695 *bzip2*) patchfile="${T}/current.patch"; bunzip2 -c "$x" > "${patchfile}";;
696 *text*) patchfile="$x";;
697 *) die "Could not determine filetype of patch $x";;
698 esac
699 debug-print "$FUNCNAME: patchfile=$patchfile"
700
701 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
702 target="`/bin/grep '+++' $patchfile | /usr/bin/tail -1`"
703 debug-print "$FUNCNAME: raw target=$target"
704 # strip target down to the path/filename. NOTE doesn't support filenames/paths with spaces in them :-(
705 # remove leading +++
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
710 # to calculate the correct patchlevel.
711 while [ "$target" != "${target/\/\/}" ]; do
712 target="${target/\/\//\/}"
713 done
714 debug-print "$FUNCNAME: stripped target=$target"
715
716 # look for target
717 for basedir in "$S" "$WORKDIR" "`pwd`"; do
718 debug-print "$FUNCNAME: looking in basedir=$basedir"
719 cd "$basedir"
720
721 # try stripping leading directories
722 target2="$target"
723 plevel=0
724 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
725 while [ ! -f "$target2" ]; do
726 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
727 plevel=plevel+1
728 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
729 [ "$target2" == "${target2/\/}" ] && break
730 done
731 test -f "$target2" && break
732
733 # try stripping filename - needed to support patches creating new files
734 target2="${target%/*}"
735 plevel=0
736 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
737 while [ ! -d "$target2" ]; do
738 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
739 plevel=plevel+1
740 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
741 [ "$target2" == "${target2/\/}" ] && break
742 done
743 test -d "$target2" && break
744
745 done
746
747 test -f "${basedir}/${target2}" || test -d "${basedir}/${target2}" || die "Could not determine patchlevel for $x"
748 debug-print "$FUNCNAME: determined plevel=$plevel"
749 # do the patching
750 ebegin "Applying patch ${x##*/}..."
751 /usr/bin/patch -p$plevel < "$patchfile" > /dev/null || die "Failed to apply patch $x"
752 eend $?
753
754 done
755
756}

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

  ViewVC Help
Powered by ViewVC 1.1.20