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

Diff of /eclass/eutils.eclass

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

Revision 1.5 Revision 1.35
1# Copyright 1999-2002 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.35 2003/06/22 05:44:04 drobbins Exp $
4#
3# Author: Martin Schlemmer <azarah@gentoo.org> 5# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.5 2002/11/11 22:36:22 azarah Exp $ 6#
5# This eclass is for general purpose functions that most ebuilds 7# This eclass is for general purpose functions that most ebuilds
6# have to implement themselfs. 8# have to implement themselves.
7# 9#
8# NB: If you add anything, please comment it! 10# NB: If you add anything, please comment it!
9 11
10ECLASS=eutils 12ECLASS=eutils
11INHERITED="$INHERITED $ECLASS" 13INHERITED="$INHERITED $ECLASS"
12 14
13newdepend sys-devel/patch 15DEPEND="$DEPEND !bootstrap? ( sys-devel/patch )"
14 16
15DESCRIPTION="Based on the ${ECLASS} eclass" 17DESCRIPTION="Based on the ${ECLASS} eclass"
16 18
17# This function generate linker scripts in /usr/lib for dynamic 19# This function generate linker scripts in /usr/lib for dynamic
18# 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
34# 36#
35gen_usr_ldscript() { 37gen_usr_ldscript() {
36 38
37 # Just make sure it exists 39 # Just make sure it exists
38 dodir /usr/lib 40 dodir /usr/lib
39 41
40 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT" 42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
41/* GNU ld script 43/* GNU ld script
42 Because Gentoo have critical dynamic libraries 44 Because Gentoo have critical dynamic libraries
43 in /lib, and the static versions in /usr/lib, we 45 in /lib, and the static versions in /usr/lib, we
44 need to have a "fake" dynamic lib in /usr/lib, 46 need to have a "fake" dynamic lib in /usr/lib,
68 return 0 70 return 0
69 fi 71 fi
70 72
71 # Get the length of $* 73 # Get the length of $*
72 str_length="$(echo -n "$*" | wc -m)" 74 str_length="$(echo -n "$*" | wc -m)"
73 75
74 while [ "$i" -lt "${str_length}" ] 76 while [ "$i" -lt "${str_length}" ]
75 do 77 do
76 echo -n "=" 78 echo -n "="
77 79
78 i=$((i + 1)) 80 i=$((i + 1))
79 done 81 done
80 82
81 echo 83 echo
82 84
87EPATCH_SOURCE="${WORKDIR}/patch" 89EPATCH_SOURCE="${WORKDIR}/patch"
88# Default extension for patches 90# Default extension for patches
89EPATCH_SUFFIX="patch.bz2" 91EPATCH_SUFFIX="patch.bz2"
90# Default options for patch 92# Default options for patch
91EPATCH_OPTS="" 93EPATCH_OPTS=""
94# List of patches not to apply. Not this is only file names,
95# and not the full path ..
96EPATCH_EXCLUDE=""
97# Change the printed message for a single patch.
98EPATCH_SINGLE_MSG=""
99# Force applying bulk patches even if not following the style:
100#
101# ??_${ARCH}_foo.${EPATCH_SUFFIX}
102#
103EPATCH_FORCE="no"
92 104
93# 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
94# or two patches. 106# or two patches.
95# 107#
96# It should work with .bz2, .gz, .zip and plain text patches. 108# It should work with .bz2, .gz, .zip and plain text patches.
124# <azarah@gentoo.org> (10 Nov 2002) 136# <azarah@gentoo.org> (10 Nov 2002)
125# 137#
126epatch() { 138epatch() {
127 local PIPE_CMD="" 139 local PIPE_CMD=""
128 local STDERR_TARGET="${T}/$$.out" 140 local STDERR_TARGET="${T}/$$.out"
141 local PATCH_TARGET="${T}/$$.patch"
142 local PATCH_SUFFIX=""
129 local SINGLE_PATCH="no" 143 local SINGLE_PATCH="no"
130 local x="" 144 local x=""
131 145
132 if [ "$#" -gt 1 ] 146 if [ "$#" -gt 1 ]
133 then 147 then
136 fi 150 fi
137 151
138 if [ -n "$1" -a -f "$1" ] 152 if [ -n "$1" -a -f "$1" ]
139 then 153 then
140 SINGLE_PATCH="yes" 154 SINGLE_PATCH="yes"
141 155
142 local EPATCH_SOURCE="$1" 156 local EPATCH_SOURCE="$1"
143 local EPATCH_SUFFIX="${1##*\.}" 157 local EPATCH_SUFFIX="${1##*\.}"
144 158
145 elif [ -n "$1" -a -d "$1" ] 159 elif [ -n "$1" -a -d "$1" ]
146 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
147 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 166 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
167 fi
148 else 168 else
169 if [ ! -d ${EPATCH_SOURCE} ]
170 then
171 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
172 then
173 EPATCH_SOURCE="$1"
174 fi
175
176 echo
177 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
178 eerror
179 eerror " ${EPATCH_SOURCE}"
180 echo
181 die "Cannot find \$EPATCH_SOURCE!"
182 fi
183
149 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
150 fi 185 fi
151 186
152 case ${EPATCH_SUFFIX##*\.} in 187 case ${EPATCH_SUFFIX##*\.} in
153 bz2) 188 bz2)
154 PIPE_CMD="bzip2 -dc" 189 PIPE_CMD="bzip2 -dc"
190 PATCH_SUFFIX="bz2"
155 ;; 191 ;;
156 gz) 192 gz|Z|z)
157 PIPE_CMD="gzip -dc" 193 PIPE_CMD="gzip -dc"
194 PATCH_SUFFIX="gz"
158 ;; 195 ;;
159 zip) 196 ZIP|zip)
160 PIPE_CMD="unzip -p" 197 PIPE_CMD="unzip -p"
198 PATCH_SUFFIX="zip"
161 ;; 199 ;;
162 *) 200 *)
163 PIPE_CMD="cat" 201 PIPE_CMD="cat"
202 PATCH_SUFFIX="patch"
164 ;; 203 ;;
165 esac 204 esac
166 205
167 if [ "${SINGLE_PATCH}" = "no" ] 206 if [ "${SINGLE_PATCH}" = "no" ]
168 then 207 then
173 # New ARCH dependant patch naming scheme... 212 # New ARCH dependant patch naming scheme...
174 # 213 #
175 # ???_arch_foo.patch 214 # ???_arch_foo.patch
176 # 215 #
177 if [ -f ${x} ] && \ 216 if [ -f ${x} ] && \
178 [ -n "$1" -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" ])
179 then 219 then
180 local count=0 220 local count=0
181 local popts="${EPATCH_OPTS}" 221 local popts="${EPATCH_OPTS}"
222
223 if [ -n "${EPATCH_EXCLUDE}" ]
224 then
225 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
226 then
227 continue
228 fi
182 229 fi
230
183 if [ "${SINGLE_PATCH}" = "yes" ] 231 if [ "${SINGLE_PATCH}" = "yes" ]
184 then 232 then
233 if [ -n "${EPATCH_SINGLE_MSG}" ]
234 then
235 einfo "${EPATCH_SINGLE_MSG}"
236 else
185 einfo "Applying ${x##*/}..." 237 einfo "Applying ${x##*/}..."
238 fi
186 else 239 else
187 einfo " ${x##*/}..." 240 einfo " ${x##*/}..."
188 fi 241 fi
189 242
190 echo "***** ${x##*/} *****" > ${STDERR_TARGET} 243 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
191 echo >> ${STDERR_TARGET} 244 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
192 245
193 # Allow for prefix to differ ... im lazy, so shoot me :/ 246 # Allow for prefix to differ ... im lazy, so shoot me :/
194 while [ "${count}" -lt 5 ] 247 while [ "${count}" -lt 5 ]
195 do 248 do
196 # Generate some useful debug info ... 249 # Generate some useful debug info ...
197 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET} 250 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
198 echo >> ${STDERR_TARGET} 251 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
199 252
200 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET} 253 if [ "${PATCH_SUFFIX}" != "patch" ]
201 echo "${PIPE_CMD} ${x} | patch ${popts} -p${count}" >> ${STDERR_TARGET}
202
203 echo >> ${STDERR_TARGET}
204 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET}
205
206 if eval ${PIPE_CMD} ${x} | patch ${popts} --dry-run -f -p${count} 2>&1 >> ${STDERR_TARGET}
207 then 254 then
208 eval ${PIPE_CMD} ${x} | patch ${popts} -p${count} 2>&1 >> ${STDERR_TARGET} 255 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
256 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
257 else
258 PATCH_TARGET="${x}"
259 fi
260
261 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
262 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
263
264 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
265 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
266
267 if [ "${PATCH_SUFFIX}" != "patch" ]
268 then
269 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
270 then
271 echo
272 eerror "Could not extract patch!"
273 #die "Could not extract patch!"
274 count=5
275 break
276 fi
277 fi
278
279 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
280 then
281 draw_line "***** ${x##*/} *****" > ${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
284 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
285 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
286
287 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
288
289 if [ "$?" -ne 0 ]
290 then
291 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
292 echo
293 eerror "A dry-run of patch command succeeded, but actually"
294 eerror "applying the patch failed!"
295 #die "Real world sux compared to the dreamworld!"
296 count=5
297 fi
298
299 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
300
209 break 301 break
210 fi 302 fi
211 303
212 count=$((count + 1)) 304 count=$((count + 1))
213 done 305 done
214 306
307 if [ "${PATCH_SUFFIX}" != "patch" ]
308 then
309 rm -f ${PATCH_TARGET}
310 fi
311
215 if [ "${count}" -eq 5 ] 312 if [ "${count}" -eq 5 ]
216 then 313 then
314 echo
217 eerror "Failed Patch: ${x##*/}!" 315 eerror "Failed Patch: ${x##*/}!"
218 eerror 316 eerror
219 eerror "Include in your bugreport the contents of:" 317 eerror "Include in your bugreport the contents of:"
220 eerror 318 eerror
221 eerror " ${STDERR_TARGET}" 319 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
222 eerror 320 echo
223 die "Failed Patch: ${x##*/}!" 321 die "Failed Patch: ${x##*/}!"
224 fi 322 fi
225 323
324 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
325
226 eend 0 326 eend 0
227 fi 327 fi
228 done 328 done
229 if [ "${SINGLE_PATCH}" = "no" ] 329 if [ "${SINGLE_PATCH}" = "no" ]
230 then 330 then
231 einfo "Done with patching" 331 einfo "Done with patching"
232 fi 332 fi
233} 333}
234 334
335# This function return true if we are using the NPTL pthreads
336# implementation.
337#
338# <azarah@gentoo.org> (06 March 2003)
339#
340
341have_NPTL() {
342
343 cat > ${T}/test-nptl.c <<-"END"
344 #define _XOPEN_SOURCE
345 #include <unistd.h>
346 #include <stdio.h>
347
348 int main()
349 {
350 char buf[255];
351 char *str = buf;
352
353 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, 255);
354 if (NULL != str) {
355 printf("%s\n", str);
356 if (NULL != strstr(str, "NPTL"))
357 return 0;
358 }
359
360 return 1;
361 }
362 END
363
364 einfon "Checking for _CS_GNU_LIBPTHREAD_VERSION support in glibc ... "
365 if gcc -o ${T}/nptl ${T}/test-nptl.c &> /dev/null
366 then
367 echo "yes"
368 einfon "Checking what PTHREADS implementation we have ... "
369 if ${T}/nptl
370 then
371 return 0
372 else
373 return 1
374 fi
375 else
376 echo "no"
377 fi
378
379 return 1
380}
381
382# This function check how many cpu's are present, and then set
383# -j in MAKEOPTS accordingly.
384#
385# Thanks to nall <nall@gentoo.org> for this.
386#
387get_number_of_jobs() {
388 local jobs=0
389
390 if [ ! -r /proc/cpuinfo ]
391 then
392 return 1
393 fi
394
395 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
396 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
397 then
398 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
399 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
400 ADMINPARAM="${ADMINPARAM/-j}"
401 fi
402
403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
404
405 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
407 then
408 # these archs will always have "[Pp]rocessor"
409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
410
411 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
412 then
413 # sparc always has "ncpus active"
414 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
415
416 elif [ "${ARCH}" = "alpha" ]
417 then
418 # alpha has "cpus active", but only when compiled with SMP
419 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
420 then
421 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
422 else
423 jobs=2
424 fi
425
426 elif [ "${ARCH}" = "ppc" ]
427 then
428 # ppc has "processor", but only when compiled with SMP
429 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
430 then
431 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
432 else
433 jobs=2
434 fi
435 else
436 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
437 die "Unknown ARCH -- ${ARCH}!"
438 fi
439
440 # Make sure the number is valid ...
441 if [ "${jobs}" -lt 1 ]
442 then
443 jobs=1
444 fi
445
446 if [ -n "${ADMINPARAM}" ]
447 then
448 if [ "${jobs}" -gt "${ADMINPARAM}" ]
449 then
450 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
451 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
452 else
453 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
454 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
455 fi
456 fi
457}
458
459# Simplify/standardize adding users to the system
460# vapier@gentoo.org
461#
462# enewuser(username, uid, shell, homedir, groups, extra options)
463#
464# Default values if you do not specify any:
465# username: REQUIRED !
466# uid: next available (see useradd(8))
467# note: pass -1 to get default behavior
468# shell: /bin/false
469# homedir: /dev/null
470# groups: none
471# extra: comment of 'added by portage for ${PN}'
472enewuser() {
473 # get the username
474 local euser="$1"; shift
475 if [ -z "${euser}" ] ; then
476 eerror "No username specified !"
477 die "Cannot call enewuser without a username"
478 fi
479 einfo "Adding user '${euser}' to your system ..."
480
481 # setup a file for testing usernames/groups
482 local tmpfile="`mktemp -p ${T}`"
483 touch ${tmpfile}
484 chown ${euser} ${tmpfile} >& /dev/null
485 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
486
487 # see if user already exists
488 if [ "${euser}" == "${realuser}" ] ; then
489 einfo "${euser} already exists on your system :)"
490 return 0
491 fi
492
493 # options to pass to useradd
494 local opts=""
495
496 # handle uid
497 local euid="$1"; shift
498 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] ; then
499 if [ ${euid} -gt 0 ] ; then
500 opts="${opts} -u ${euid}"
501 else
502 eerror "Userid given but is not greater than 0 !"
503 die "${euid} is not a valid UID"
504 fi
505 else
506 euid="next available"
507 fi
508 einfo " - Userid: ${euid}"
509
510 # handle shell
511 local eshell="$1"; shift
512 if [ ! -z "${eshell}" ] ; then
513 if [ ! -e ${eshell} ] ; then
514 eerror "A shell was specified but it does not exist !"
515 die "${eshell} does not exist"
516 fi
517 else
518 eshell=/bin/false
519 fi
520 einfo " - Shell: ${eshell}"
521 opts="${opts} -s ${eshell}"
522
523 # handle homedir
524 local ehome="$1"; shift
525 if [ -z "${ehome}" ] ; then
526 ehome=/dev/null
527 fi
528 einfo " - Home: ${ehome}"
529 opts="${opts} -d ${ehome}"
530
531 # handle groups
532 local egroups="$1"; shift
533 if [ ! -z "${egroups}" ] ; then
534 local realgroup
535 local oldifs="${IFS}"
536 export IFS=","
537 for g in ${egroups} ; do
538 chgrp ${g} ${tmpfile} >& /dev/null
539 realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
540 if [ "${g}" != "${realgroup}" ] ; then
541 eerror "You must add ${g} to the system first"
542 die "${g} is not a valid GID"
543 fi
544 done
545 export IFS="${oldifs}"
546 opts="${opts} -g ${egroups}"
547 else
548 egroups="(none)"
549 fi
550 einfo " - Groups: ${egroups}"
551
552 # handle extra and add the user
553 local eextra="$@"
554 local oldsandbox="${oldsandbox}"
555 export SANDBOX_ON="0"
556 if [ -z "${eextra}" ] ; then
557 useradd ${opts} ${euser} \
558 -c "added by portage for ${PN}" \
559 || die "enewuser failed"
560 else
561 einfo " - Extra: ${eextra}"
562 useradd ${opts} ${euser} ${eextra} \
563 || die "enewuser failed"
564 fi
565 export SANDBOX_ON="${oldsandbox}"
566
567 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
568 einfo " - Creating ${ehome} in ${D}"
569 dodir ${ehome}
570 fperms ${euser} ${ehome}
571 fi
572}
573
574# Simplify/standardize adding groups to the system
575# vapier@gentoo.org
576#
577# enewgroup(group, gid)
578#
579# Default values if you do not specify any:
580# groupname: REQUIRED !
581# gid: next available (see groupadd(8))
582# extra: none
583enewgroup() {
584 # get the group
585 local egroup="$1"; shift
586 if [ -z "${egroup}" ] ; then
587 eerror "No group specified !"
588 die "Cannot call enewgroup without a group"
589 fi
590 einfo "Adding group '${egroup}' to your system ..."
591
592 # setup a file for testing groupname
593 local tmpfile="`mktemp -p ${T}`"
594 touch ${tmpfile}
595 chgrp ${egroup} ${tmpfile} >& /dev/null
596 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
597
598 # see if group already exists
599 if [ "${egroup}" == "${realgroup}" ] ; then
600 einfo "${egroup} already exists on your system :)"
601 return 0
602 fi
603
604 # options to pass to useradd
605 local opts=""
606
607 # handle gid
608 local egid="$1"; shift
609 if [ ! -z "${egid}" ] ; then
610 if [ ${egid} -gt 0 ] ; then
611 opts="${opts} -g ${egid}"
612 else
613 eerror "Groupid given but is not greater than 0 !"
614 die "${egid} is not a valid GID"
615 fi
616 else
617 egid="next available"
618 fi
619 einfo " - Groupid: ${egid}"
620
621 # handle extra
622 local eextra="$@"
623 opts="${opts} ${eextra}"
624
625 # add the group
626 local oldsandbox="${oldsandbox}"
627 export SANDBOX_ON="0"
628 groupadd ${opts} ${egroup} || die "enewgroup failed"
629 export SANDBOX_ON="${oldsandbox}"
630}
631
632# Simple script to replace 'dos2unix' binaries
633# vapier@gentoo.org
634#
635# edos2unix(file, <more files>...)
636edos2unix() {
637 for f in $@ ; do
638 cp ${f} ${T}/edos2unix
639 sed 's/\r$//' ${T}/edos2unix > ${f}
640 done
641}
642
643# new convenience patch wrapper function to eventually replace epatch(),
644# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
645# /usr/bin/patch
646# Features:
647# - bulk patch handling similar to epatch()'s
648# - automatic patch level detection like epatch()'s
649# - automatic patch uncompression like epatch()'s
650# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
651# manually instead
652# - once I decide it's production-ready, it'll be called from base_src_unpack
653# to handle $PATCHES to avoid defining src_unpack just to use xpatch
654
655# accepts zero or more parameters specifying patchfiles and/or patchdirs
656
657# known issues:
658# - only supports unified style patches (does anyone _really_ use anything
659# else?)
660# - because it doesn't use --dry-run there is a risk of it failing
661# to find the files to patch, ie detect the patchlevel, properly. It doesn't use
662# any of the backup heuristics that patch employs to discover a filename.
663# however, this isn't dangerous because if it works for the developer who's
664# writing the ebuild, it'll always work for the users, and if it doesn't,
665# then we'll fix it :-)
666# - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
667xpatch() {
668
669 debug-print-function $FUNCNAME $*
670
671 local list=""
672 local list2=""
673 declare -i plevel
674
675 # parse patch sources
676 for x in $*; do
677 debug-print "$FUNCNAME: parsing parameter $x"
678 if [ -f "$x" ]; then
679 list="$list $x"
680 elif [ -d "$x" ]; then
681 # handles patchdirs like epatch() for now: no recursion.
682 # patches are sorted by filename, so with an xy_foo naming scheme you'll get the right order.
683 # only patches with _$ARCH_ or _all_ in their filenames are applied.
684 for file in `ls -A $x`; do
685 debug-print "$FUNCNAME: parsing in subdir: file $file"
686 if [ -f "$x/$file" ] && [ "${file}" != "${file/_all_}" -o "${file}" != "${file/_$ARCH_}" ]; then
687 list2="$list2 $x/$file"
688 fi
689 done
690 list="`echo $list2 | sort` $list"
691 else
692 die "Couldn't find $x"
693 fi
694 done
695
696 debug-print "$FUNCNAME: final list of patches: $list"
697
698 for x in $list; do
699 debug-print "$FUNCNAME: processing $x"
700 # deal with compressed files. /usr/bin/file is in the system profile, or should be.
701 case "`/usr/bin/file -b $x`" in
702 *gzip*) patchfile="${T}/current.patch"; ungzip -c "$x" > "${patchfile}";;
703 *bzip2*) patchfile="${T}/current.patch"; bunzip2 -c "$x" > "${patchfile}";;
704 *text*) patchfile="$x";;
705 *) die "Could not determine filetype of patch $x";;
706 esac
707 debug-print "$FUNCNAME: patchfile=$patchfile"
708
709 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
710 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
711 debug-print "$FUNCNAME: raw target=$target"
712 # strip target down to the path/filename, remove leading +++
713 target="${target/+++ }"; target="${target%% *}"
714 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
715 # to discard them as well to calculate the correct patchlevel.
716 target="${target//\/\//\/}"
717 debug-print "$FUNCNAME: stripped target=$target"
718
719 # look for target
720 for basedir in "$S" "$WORKDIR" "${PWD}"; do
721 debug-print "$FUNCNAME: looking in basedir=$basedir"
722 cd "$basedir"
723
724 # try stripping leading directories
725 target2="$target"
726 plevel=0
727 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
728 while [ ! -f "$target2" ]; do
729 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
730 plevel=plevel+1
731 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
732 [ "$target2" == "${target2/\/}" ] && break
733 done
734 test -f "$target2" && break
735
736 # try stripping filename - needed to support patches creating new files
737 target2="${target%/*}"
738 plevel=0
739 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
740 while [ ! -d "$target2" ]; do
741 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
742 plevel=plevel+1
743 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
744 [ "$target2" == "${target2/\/}" ] && break
745 done
746 test -d "$target2" && break
747
748 done
749
750 test -f "${basedir}/${target2}" || test -d "${basedir}/${target2}" || die "Could not determine patchlevel for $x"
751 debug-print "$FUNCNAME: determined plevel=$plevel"
752 # do the patching
753 ebegin "Applying patch ${x##*/}..."
754 /usr/bin/patch -p$plevel < "$patchfile" > /dev/null || die "Failed to apply patch $x"
755 eend $?
756
757 done
758
759}

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.20