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.30 2003/05/31 13:24:45 mholzer 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 | |
10 | ECLASS=eutils |
12 | ECLASS=eutils |
11 | INHERITED="$INHERITED $ECLASS" |
13 | INHERITED="$INHERITED $ECLASS" |
12 | |
14 | |
13 | newdepend sys-devel/patch |
15 | newdepend "!bootstrap? ( sys-devel/patch )" |
14 | |
16 | |
15 | DESCRIPTION="Based on the ${ECLASS} eclass" |
17 | DESCRIPTION="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 |
… | |
… | |
92 | # 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, |
93 | # and not the full path .. |
95 | # and not the full path .. |
94 | EPATCH_EXCLUDE="" |
96 | EPATCH_EXCLUDE="" |
95 | # Change the printed message for a single patch. |
97 | # Change the printed message for a single patch. |
96 | EPATCH_SINGLE_MSG="" |
98 | EPATCH_SINGLE_MSG="" |
|
|
99 | # Force applying bulk patches even if not following the style: |
|
|
100 | # |
|
|
101 | # ??_${ARCH}_foo.${EPATCH_SUFFIX} |
|
|
102 | # |
|
|
103 | EPATCH_FORCE="no" |
97 | |
104 | |
98 | # 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 |
99 | # or two patches. |
106 | # or two patches. |
100 | # |
107 | # |
101 | # It should work with .bz2, .gz, .zip and plain text patches. |
108 | # It should work with .bz2, .gz, .zip and plain text patches. |
… | |
… | |
149 | local EPATCH_SOURCE="$1" |
156 | local EPATCH_SOURCE="$1" |
150 | local EPATCH_SUFFIX="${1##*\.}" |
157 | local EPATCH_SUFFIX="${1##*\.}" |
151 | |
158 | |
152 | elif [ -n "$1" -a -d "$1" ] |
159 | elif [ -n "$1" -a -d "$1" ] |
153 | 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 |
154 | local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" |
166 | local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" |
|
|
167 | fi |
155 | else |
168 | else |
156 | if [ ! -d ${EPATCH_SOURCE} ] |
169 | if [ ! -d ${EPATCH_SOURCE} ] |
157 | then |
170 | then |
|
|
171 | if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ] |
|
|
172 | then |
|
|
173 | EPATCH_SOURCE="$1" |
|
|
174 | fi |
|
|
175 | |
158 | echo |
176 | echo |
159 | eerror "Cannot find \$EPATCH_SOURCE!" |
177 | eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" |
|
|
178 | eerror |
|
|
179 | eerror " ${EPATCH_SOURCE}" |
160 | echo |
180 | echo |
161 | die "Cannot find \$EPATCH_SOURCE!" |
181 | die "Cannot find \$EPATCH_SOURCE!" |
162 | fi |
182 | fi |
163 | |
183 | |
164 | local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" |
184 | local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" |
… | |
… | |
192 | # New ARCH dependant patch naming scheme... |
212 | # New ARCH dependant patch naming scheme... |
193 | # |
213 | # |
194 | # ???_arch_foo.patch |
214 | # ???_arch_foo.patch |
195 | # |
215 | # |
196 | if [ -f ${x} ] && \ |
216 | if [ -f ${x} ] && \ |
197 | [ "${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" ]) |
198 | then |
219 | then |
199 | local count=0 |
220 | local count=0 |
200 | local popts="${EPATCH_OPTS}" |
221 | local popts="${EPATCH_OPTS}" |
201 | |
222 | |
202 | if [ -n "${EPATCH_EXCLUDE}" ] |
223 | if [ -n "${EPATCH_EXCLUDE}" ] |
… | |
… | |
253 | count=5 |
274 | count=5 |
254 | break |
275 | break |
255 | fi |
276 | fi |
256 | fi |
277 | fi |
257 | |
278 | |
258 | if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${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 |
259 | then |
280 | then |
260 | draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
281 | draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
261 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
282 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
262 | echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
283 | echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
263 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
284 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
264 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
285 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
265 | |
286 | |
266 | patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1 |
287 | cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1 |
267 | |
288 | |
268 | if [ "$?" -ne 0 ] |
289 | if [ "$?" -ne 0 ] |
269 | then |
290 | then |
270 | cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
291 | cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} |
271 | echo |
292 | echo |
… | |
… | |
309 | then |
330 | then |
310 | einfo "Done with patching" |
331 | einfo "Done with patching" |
311 | fi |
332 | fi |
312 | } |
333 | } |
313 | |
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 | |
|
|
341 | have_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 | # |
|
|
387 | get_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}" = "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}' |
|
|
472 | enewuser() { |
|
|
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 |
|
|
583 | enewgroup() { |
|
|
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>...) |
|
|
636 | edos2unix() { |
|
|
637 | for f in $@ ; do |
|
|
638 | cp ${f} ${T}/edos2unix |
|
|
639 | rm -f ${f} |
|
|
640 | sed 's/\r$//' ${T}/edos2unix > ${f} |
|
|
641 | rm -f ${T}/edos2unix |
|
|
642 | done |
|
|
643 | } |