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

Diff of /eclass/eutils.eclass

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

Revision 1.9 Revision 1.28
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.28 2003/03/10 09:32:34 vapier 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.9 2002/12/01 15:48:27 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 themselves. 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 15newdepend "!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
153 then 155 then
154 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 156 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
155 else 157 else
156 if [ ! -d ${EPATCH_SOURCE} ] 158 if [ ! -d ${EPATCH_SOURCE} ]
157 then 159 then
160 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
161 then
162 EPATCH_SOURCE="$1"
163 fi
164
158 echo 165 echo
159 eerror "Cannot find \$EPATCH_SOURCE!" 166 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
167 eerror
168 eerror " ${EPATCH_SOURCE}"
160 echo 169 echo
161 die "Cannot find \$EPATCH_SOURCE!" 170 die "Cannot find \$EPATCH_SOURCE!"
162 fi 171 fi
163 172
164 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 173 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
253 count=5 262 count=5
254 break 263 break
255 fi 264 fi
256 fi 265 fi
257 266
258 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1 267 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
259 then 268 then
260 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 269 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
261 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 270 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
262 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 271 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
263 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 272 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
264 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 273 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
265 274
266 patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1 275 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
267 276
268 if [ "$?" -ne 0 ] 277 if [ "$?" -ne 0 ]
269 then 278 then
270 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 279 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
271 echo 280 echo
309 then 318 then
310 einfo "Done with patching" 319 einfo "Done with patching"
311 fi 320 fi
312} 321}
313 322
323# This function return true if we are using the NPTL pthreads
324# implementation.
325#
326# <azarah@gentoo.org> (06 March 2003)
327#
328
329have_NPTL() {
330
331 cat > ${T}/test-nptl.c <<-"END"
332 #define _XOPEN_SOURCE
333 #include <unistd.h>
334 #include <stdio.h>
335
336 int main()
337 {
338 char buf[255];
339 char *str = buf;
340
341 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, 255);
342 if (NULL != str) {
343 printf("%s\n", str);
344 if (NULL != strstr(str, "NPTL"))
345 return 0;
346 }
347
348 return 1;
349 }
350 END
351
352 einfon "Checking for _CS_GNU_LIBPTHREAD_VERSION support in glibc ... "
353 if gcc -o ${T}/nptl ${T}/test-nptl.c &> /dev/null
354 then
355 echo "yes"
356 einfon "Checking what PTHREADS implementation we have ... "
357 if ${T}/nptl
358 then
359 return 0
360 else
361 return 1
362 fi
363 else
364 echo "no"
365 fi
366
367 return 1
368}
369
370# This function check how many cpu's are present, and then set
371# -j in MAKEOPTS accordingly.
372#
373# Thanks to nall <nall@gentoo.org> for this.
374#
375get_number_of_jobs() {
376 local jobs=0
377
378 if [ ! -r /proc/cpuinfo ]
379 then
380 return 1
381 fi
382
383 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
384 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
385 then
386 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
387 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
388 ADMINPARAM="${ADMINPARAM/-j}"
389 fi
390
391 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
392
393 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
394 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
395 then
396 # these archs will always have "[Pp]rocessor"
397 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
398
399 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
400 then
401 # sparc always has "ncpus active"
402 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
403
404 elif [ "${ARCH}" = "alpha" ]
405 then
406 # alpha has "cpus active", but only when compiled with SMP
407 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
408 then
409 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
410 else
411 jobs=2
412 fi
413
414 elif [ "${ARCH}" = "ppc" ]
415 then
416 # ppc has "processor", but only when compiled with SMP
417 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
418 then
419 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
420 else
421 jobs=2
422 fi
423 else
424 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
425 die "Unknown ARCH -- ${ARCH}!"
426 fi
427
428 # Make sure the number is valid ...
429 if [ "${jobs}" -lt 1 ]
430 then
431 jobs=1
432 fi
433
434 if [ -n "${ADMINPARAM}" ]
435 then
436 if [ "${jobs}" -gt "${ADMINPARAM}" ]
437 then
438 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
439 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
440 else
441 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
442 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
443 fi
444 fi
445}
446
447# Simplify/standardize adding users to the system
448# vapier@gentoo.org
449#
450# enewuser(username, uid, shell, homedir, groups, extra options)
451#
452# Default values if you do not specify any:
453# username: REQUIRED !
454# uid: next available (see useradd(8))
455# note: pass -1 to get default behavior
456# shell: /bin/false
457# homedir: /dev/null
458# groups: none
459# extra: comment of 'added by portage for ${PN}'
460enewuser() {
461 # get the username
462 local euser="$1"; shift
463 if [ -z "${euser}" ] ; then
464 eerror "No username specified !"
465 die "Cannot call enewuser without a username"
466 fi
467 einfo "Adding user '${euser}' to your system ..."
468
469 # setup a file for testing usernames/groups
470 local tmpfile="`mktemp -p ${T}`"
471 touch ${tmpfile}
472 chown ${euser} ${tmpfile} >& /dev/null
473 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
474
475 # see if user already exists
476 if [ "${euser}" == "${realuser}" ] ; then
477 einfo "${euser} already exists on your system :)"
478 return 0
479 fi
480
481 # options to pass to useradd
482 local opts=""
483
484 # handle uid
485 local euid="$1"; shift
486 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] ; then
487 if [ ${euid} -gt 0 ] ; then
488 opts="${opts} -u ${euid}"
489 else
490 eerror "Userid given but is not greater than 0 !"
491 die "${euid} is not a valid UID"
492 fi
493 else
494 euid="next available"
495 fi
496 einfo " - Userid: ${euid}"
497
498 # handle shell
499 local eshell="$1"; shift
500 if [ ! -z "${eshell}" ] ; then
501 if [ ! -e ${eshell} ] ; then
502 eerror "A shell was specified but it does not exist !"
503 die "${eshell} does not exist"
504 fi
505 else
506 eshell=/bin/false
507 fi
508 einfo " - Shell: ${eshell}"
509 opts="${opts} -s ${eshell}"
510
511 # handle homedir
512 local ehome="$1"; shift
513 if [ -z "${ehome}" ] ; then
514 ehome=/dev/null
515 fi
516 einfo " - Home: ${ehome}"
517 opts="${opts} -d ${ehome}"
518
519 # handle groups
520 local egroups="$1"; shift
521 if [ ! -z "${egroups}" ] ; then
522 local realgroup
523 local oldifs="${IFS}"
524 export IFS=","
525 for g in ${egroups} ; do
526 chgrp ${g} ${tmpfile} >& /dev/null
527 realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
528 if [ "${g}" != "${realgroup}" ] ; then
529 eerror "You must add ${g} to the system first"
530 die "${g} is not a valid GID"
531 fi
532 done
533 export IFS="${oldifs}"
534 opts="${opts} -g ${egroups}"
535 else
536 egroups="(none)"
537 fi
538 einfo " - Groups: ${egroups}"
539
540 # handle extra and add the user
541 local eextra="$@"
542 local oldsandbox="${oldsandbox}"
543 export SANDBOX_ON="0"
544 if [ -z "${eextra}" ] ; then
545 useradd ${opts} ${euser} \
546 -c "added by portage for ${PN}" \
547 || die "enewuser failed"
548 else
549 einfo " - Extra: ${eextra}"
550 useradd ${opts} ${euser} ${eextra} \
551 || die "enewuser failed"
552 fi
553 export SANDBOX_ON="${oldsandbox}"
554
555 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
556 einfo " - Creating ${ehome} in ${D}"
557 dodir ${ehome}
558 fperms ${euser} ${ehome}
559 fi
560}
561
562# Simplify/standardize adding groups to the system
563# vapier@gentoo.org
564#
565# enewgroup(group, gid)
566#
567# Default values if you do not specify any:
568# groupname: REQUIRED !
569# gid: next available (see groupadd(8))
570# extra: none
571enewgroup() {
572 # get the group
573 local egroup="$1"; shift
574 if [ -z "${egroup}" ] ; then
575 eerror "No group specified !"
576 die "Cannot call enewgroup without a group"
577 fi
578 einfo "Adding group '${egroup}' to your system ..."
579
580 # setup a file for testing groupname
581 local tmpfile="`mktemp -p ${T}`"
582 touch ${tmpfile}
583 chgrp ${egroup} ${tmpfile} >& /dev/null
584 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
585
586 # see if group already exists
587 if [ "${egroup}" == "${realgroup}" ] ; then
588 einfo "${egroup} already exists on your system :)"
589 return 0
590 fi
591
592 # options to pass to useradd
593 local opts=""
594
595 # handle gid
596 local egid="$1"; shift
597 if [ ! -z "${egid}" ] ; then
598 if [ ${egid} -gt 0 ] ; then
599 opts="${opts} -g ${egid}"
600 else
601 eerror "Groupid given but is not greater than 0 !"
602 die "${egid} is not a valid GID"
603 fi
604 else
605 egid="next available"
606 fi
607 einfo " - Groupid: ${egid}"
608
609 # handle extra
610 local eextra="$@"
611 opts="${opts} ${eextra}"
612
613 # add the group
614 local oldsandbox="${oldsandbox}"
615 export SANDBOX_ON="0"
616 groupadd ${opts} ${egroup} || die "enewgroup failed"
617 export SANDBOX_ON="${oldsandbox}"
618}
619
620# Simple script to replace 'dos2unix' binaries
621# vapier@gentoo.org
622#
623# edos2unix(file, <more files>...)
624edos2unix() {
625 for f in $@ ; do
626 cp ${f} ${T}/edos2unix
627 sed 's/\r$//' ${T}/edos2unix > ${f}
628 done
629}

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.20