| 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.24 2003/03/03 21:27:15 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.36 2003/06/25 03:53:29 vapier 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 | |
| 12 | ECLASS=eutils |
12 | ECLASS=eutils |
| 13 | INHERITED="$INHERITED $ECLASS" |
13 | INHERITED="$INHERITED $ECLASS" |
| 14 | |
14 | |
| 15 | newdepend "!bootstrap? ( sys-devel/patch )" |
15 | DEPEND="$DEPEND !bootstrap? ( sys-devel/patch )" |
| 16 | |
16 | |
| 17 | DESCRIPTION="Based on the ${ECLASS} eclass" |
17 | DESCRIPTION="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 | # |
| 37 | gen_usr_ldscript() { |
37 | gen_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 .. |
| 96 | EPATCH_EXCLUDE="" |
96 | EPATCH_EXCLUDE="" |
| 97 | # Change the printed message for a single patch. |
97 | # Change the printed message for a single patch. |
| 98 | 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" |
| 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 |
| … | |
… | |
| 318 | then |
330 | then |
| 319 | einfo "Done with patching" |
331 | einfo "Done with patching" |
| 320 | fi |
332 | fi |
| 321 | } |
333 | } |
| 322 | |
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 | |
| 323 | # This function check how many cpu's are present, and then set |
382 | # This function check how many cpu's are present, and then set |
| 324 | # -j in MAKEOPTS accordingly. |
383 | # -j in MAKEOPTS accordingly. |
| 325 | # |
384 | # |
| 326 | # Thanks to nall <nall@gentoo.org> for this. |
385 | # Thanks to nall <nall@gentoo.org> for this. |
| 327 | # |
386 | # |
| … | |
… | |
| 340 | 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]}'`" |
| 341 | ADMINPARAM="${ADMINPARAM/-j}" |
400 | ADMINPARAM="${ADMINPARAM/-j}" |
| 342 | fi |
401 | fi |
| 343 | |
402 | |
| 344 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
403 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
| 345 | |
404 | |
| 346 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
405 | if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
| 347 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] |
406 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] |
| 348 | then |
407 | then |
| 349 | # these archs will always have "[Pp]rocessor" |
408 | # these archs will always have "[Pp]rocessor" |
| 350 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
409 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
| 351 | |
410 | |
| 352 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
411 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
| 353 | then |
412 | then |
| 354 | # sparc always has "ncpus active" |
413 | # sparc always has "ncpus active" |
| 355 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
414 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
| 356 | |
415 | |
| 357 | elif [ "${ARCH}" = "alpha" ] |
416 | elif [ "${ARCH}" = "alpha" ] |
| 358 | then |
417 | then |
| 359 | # alpha has "cpus active", but only when compiled with SMP |
418 | # alpha has "cpus active", but only when compiled with SMP |
| 360 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] |
419 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] |
| 361 | then |
420 | then |
| 362 | jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
421 | jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
| 363 | else |
422 | else |
| 364 | jobs=2 |
423 | jobs=2 |
| 365 | fi |
424 | fi |
| 366 | |
425 | |
| 367 | elif [ "${ARCH}" = "ppc" ] |
426 | elif [ "${ARCH}" = "ppc" ] |
| 368 | then |
427 | then |
| 369 | # ppc has "processor", but only when compiled with SMP |
428 | # ppc has "processor", but only when compiled with SMP |
| 370 | if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] |
429 | if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] |
| 371 | then |
430 | then |
| … | |
… | |
| 381 | # Make sure the number is valid ... |
440 | # Make sure the number is valid ... |
| 382 | if [ "${jobs}" -lt 1 ] |
441 | if [ "${jobs}" -lt 1 ] |
| 383 | then |
442 | then |
| 384 | jobs=1 |
443 | jobs=1 |
| 385 | fi |
444 | fi |
| 386 | |
445 | |
| 387 | if [ -n "${ADMINPARAM}" ] |
446 | if [ -n "${ADMINPARAM}" ] |
| 388 | then |
447 | then |
| 389 | if [ "${jobs}" -gt "${ADMINPARAM}" ] |
448 | if [ "${jobs}" -gt "${ADMINPARAM}" ] |
| 390 | then |
449 | then |
| 391 | einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." |
450 | einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." |
| … | |
… | |
| 403 | # enewuser(username, uid, shell, homedir, groups, extra options) |
462 | # enewuser(username, uid, shell, homedir, groups, extra options) |
| 404 | # |
463 | # |
| 405 | # Default values if you do not specify any: |
464 | # Default values if you do not specify any: |
| 406 | # username: REQUIRED ! |
465 | # username: REQUIRED ! |
| 407 | # uid: next available (see useradd(8)) |
466 | # uid: next available (see useradd(8)) |
|
|
467 | # note: pass -1 to get default behavior |
| 408 | # shell: /bin/false |
468 | # shell: /bin/false |
| 409 | # homedir: /dev/null |
469 | # homedir: /dev/null |
| 410 | # groups: none |
470 | # groups: none |
| 411 | # extra: comment of 'added by portage for ${PN}' |
471 | # extra: comment of 'added by portage for ${PN}' |
| 412 | enewuser() { |
472 | enewuser() { |
| … | |
… | |
| 433 | # options to pass to useradd |
493 | # options to pass to useradd |
| 434 | local opts="" |
494 | local opts="" |
| 435 | |
495 | |
| 436 | # handle uid |
496 | # handle uid |
| 437 | local euid="$1"; shift |
497 | local euid="$1"; shift |
| 438 | if [ ! -z "${euid}" ] ; then |
498 | if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] ; then |
| 439 | if [ ${euid} -gt 0 ] ; then |
499 | if [ ${euid} -gt 0 ] ; then |
| 440 | opts="${opts} -u ${euid}" |
500 | opts="${opts} -u ${euid}" |
| 441 | else |
501 | else |
| 442 | eerror "Userid given but is not greater than 0 !" |
502 | eerror "Userid given but is not greater than 0 !" |
| 443 | die "${euid} is not a valid UID" |
503 | die "${euid} is not a valid UID" |
| … | |
… | |
| 489 | fi |
549 | fi |
| 490 | einfo " - Groups: ${egroups}" |
550 | einfo " - Groups: ${egroups}" |
| 491 | |
551 | |
| 492 | # handle extra and add the user |
552 | # handle extra and add the user |
| 493 | local eextra="$@" |
553 | local eextra="$@" |
| 494 | local oldsandbox="${oldsandbox}" |
554 | local oldsandbox=${SANDBOX_ON} |
| 495 | export SANDBOX_ON="0" |
555 | export SANDBOX_ON="0" |
| 496 | if [ -z "${eextra}" ] ; then |
556 | if [ -z "${eextra}" ] ; then |
| 497 | useradd ${opts} ${euser} \ |
557 | useradd ${opts} ${euser} \ |
| 498 | -c "added by portage for ${PN}" \ |
558 | -c "added by portage for ${PN}" \ |
| 499 | || die "enewuser failed" |
559 | || die "enewuser failed" |
| 500 | else |
560 | else |
| 501 | einfo " - Extra: ${eextra}" |
561 | einfo " - Extra: ${eextra}" |
| 502 | useradd ${opts} ${euser} ${eextra} \ |
562 | useradd ${opts} ${euser} ${eextra} \ |
| 503 | || die "enewuser failed" |
563 | || die "enewuser failed" |
| 504 | fi |
564 | fi |
| 505 | export SANDBOX_ON="${oldsandbox}" |
565 | export SANDBOX_ON="${oldsandbox}" |
| 506 | |
566 | |
| 507 | if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then |
567 | if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then |
| 508 | einfo " - Creating ${ehome} in ${D}" |
568 | einfo " - Creating ${ehome} in ${D}" |
| … | |
… | |
| 561 | # handle extra |
621 | # handle extra |
| 562 | local eextra="$@" |
622 | local eextra="$@" |
| 563 | opts="${opts} ${eextra}" |
623 | opts="${opts} ${eextra}" |
| 564 | |
624 | |
| 565 | # add the group |
625 | # add the group |
| 566 | local oldsandbox="${oldsandbox}" |
626 | local oldsandbox=${SANDBOX_ON} |
| 567 | export SANDBOX_ON="0" |
627 | export SANDBOX_ON="0" |
| 568 | groupadd ${opts} ${egroup} || die "enewgroup failed" |
628 | groupadd ${opts} ${egroup} || die "enewgroup failed" |
| 569 | export SANDBOX_ON="${oldsandbox}" |
629 | export SANDBOX_ON="${oldsandbox}" |
| 570 | } |
630 | } |
| 571 | |
631 | |
| … | |
… | |
| 573 | # vapier@gentoo.org |
633 | # vapier@gentoo.org |
| 574 | # |
634 | # |
| 575 | # edos2unix(file, <more files>...) |
635 | # edos2unix(file, <more files>...) |
| 576 | edos2unix() { |
636 | edos2unix() { |
| 577 | for f in $@ ; do |
637 | for f in $@ ; do |
| 578 | cp ${f} ${T}/ |
638 | cp ${f} ${T}/edos2unix |
| 579 | sed 's/\r$//' ${T}/${f}.old > ${f} |
639 | sed 's/\r$//' ${T}/edos2unix > ${f} |
| 580 | done |
640 | done |
| 581 | } |
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). |
|
|
667 | xpatch() { |
|
|
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 | } |