| 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.21 2003/02/18 20:23:20 zwelch 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.12 2002/12/14 21:46:25 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 "!bootstrap? ( sys-devel/patch )" |
15 | newdepend "!bootstrap? ( sys-devel/patch )" |
| 14 | |
16 | |
| 15 | DESCRIPTION="Based on the ${ECLASS} eclass" |
17 | [ -z "$DESCRIPTION" ] && 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 |
| 19 | # the .so in /lib, and the .a in /usr/lib. What happens is that |
21 | # the .so in /lib, and the .a in /usr/lib. What happens is that |
| 20 | # in some cases when linking dynamic, the .a in /usr/lib is used |
22 | # in some cases when linking dynamic, the .a in /usr/lib is used |
| … | |
… | |
| 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! Value for \$EPATCH_SOURCE is:" |
166 | eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" |
| 160 | eerror |
167 | eerror |
| 161 | eerror " ${EPATCH_SOURCE}" |
168 | eerror " ${EPATCH_SOURCE}" |
| 162 | echo |
169 | echo |
| … | |
… | |
| 255 | count=5 |
262 | count=5 |
| 256 | break |
263 | break |
| 257 | fi |
264 | fi |
| 258 | fi |
265 | fi |
| 259 | |
266 | |
| 260 | 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 |
| 261 | then |
268 | then |
| 262 | draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
269 | draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
| 263 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
270 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
| 264 | echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
271 | echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
| 265 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
272 | echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
| 266 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
273 | draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real |
| 267 | |
274 | |
| 268 | 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 |
| 269 | |
276 | |
| 270 | if [ "$?" -ne 0 ] |
277 | if [ "$?" -ne 0 ] |
| 271 | then |
278 | then |
| 272 | 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##*/} |
| 273 | echo |
280 | echo |
| … | |
… | |
| 317 | # -j in MAKEOPTS accordingly. |
324 | # -j in MAKEOPTS accordingly. |
| 318 | # |
325 | # |
| 319 | # Thanks to nall <nall@gentoo.org> for this. |
326 | # Thanks to nall <nall@gentoo.org> for this. |
| 320 | # |
327 | # |
| 321 | get_number_of_jobs() { |
328 | get_number_of_jobs() { |
|
|
329 | local jobs=0 |
|
|
330 | |
| 322 | if [ ! -r /proc/cpuinfo ] |
331 | if [ ! -r /proc/cpuinfo ] |
| 323 | then |
332 | then |
| 324 | return 1 |
333 | return 1 |
| 325 | fi |
334 | fi |
| 326 | |
335 | |
|
|
336 | # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565. |
|
|
337 | if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ] |
|
|
338 | then |
|
|
339 | ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`" |
|
|
340 | ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`" |
|
|
341 | ADMINPARAM="${ADMINPARAM/-j}" |
|
|
342 | fi |
|
|
343 | |
| 327 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`" |
344 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
| 328 | |
345 | |
| 329 | if [ "${ARCH}" = "x86" ] |
346 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
|
|
347 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] |
| 330 | then |
348 | then |
| 331 | # x86 always has "processor" |
349 | # these archs will always have "[Pp]rocessor" |
| 332 | export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" |
350 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
| 333 | |
351 | |
| 334 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
352 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
| 335 | then |
353 | then |
| 336 | # sparc always has "ncpus active" |
354 | # sparc always has "ncpus active" |
| 337 | export MAKEOPTS="${MAKEOPTS} -j$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
355 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
| 338 | |
356 | |
| 339 | elif [ "${ARCH}" = "alpha" ] |
357 | elif [ "${ARCH}" = "alpha" ] |
| 340 | then |
358 | then |
| 341 | # alpha has "cpus active", but only when compiled with SMP |
359 | # alpha has "cpus active", but only when compiled with SMP |
| 342 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" = "1" ] |
360 | if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ] |
| 343 | then |
361 | then |
| 344 | export MAKEOPTS="${MAKEOPTS} -j$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
362 | jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
| 345 | else |
363 | else |
| 346 | export MAKEOPTS="${MAKEOPTS} -j2" |
364 | jobs=2 |
| 347 | fi |
365 | fi |
| 348 | |
366 | |
| 349 | elif [ "${ARCH}" = "ppc" ] |
367 | elif [ "${ARCH}" = "ppc" ] |
| 350 | then |
368 | then |
| 351 | # ppc has "processor", but only when compiled with SMP |
369 | # ppc has "processor", but only when compiled with SMP |
| 352 | if [ "`grep -c "^processor" /proc/cpuinfo`" = "1" ] |
370 | if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ] |
| 353 | then |
371 | then |
| 354 | export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))" |
372 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
| 355 | else |
373 | else |
| 356 | export MAKEOPTS="${MAKEOPTS} -j2" |
374 | jobs=2 |
| 357 | fi |
375 | fi |
| 358 | else |
376 | else |
| 359 | export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
377 | jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
| 360 | die "Unknown ARCH -- ${ARCH}!" |
378 | die "Unknown ARCH -- ${ARCH}!" |
| 361 | fi |
379 | fi |
|
|
380 | |
|
|
381 | # Make sure the number is valid ... |
|
|
382 | if [ "${jobs}" -lt 1 ] |
|
|
383 | then |
|
|
384 | jobs=1 |
|
|
385 | fi |
|
|
386 | |
|
|
387 | if [ -n "${ADMINPARAM}" ] |
|
|
388 | then |
|
|
389 | if [ "${jobs}" -gt "${ADMINPARAM}" ] |
|
|
390 | then |
|
|
391 | einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..." |
|
|
392 | export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}" |
|
|
393 | else |
|
|
394 | einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..." |
|
|
395 | export MAKEOPTS="${MAKEOPTS} -j${jobs}" |
|
|
396 | fi |
|
|
397 | fi |
| 362 | } |
398 | } |
| 363 | |
399 | |