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

Diff of /eclass/eutils.eclass

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

Revision 1.3 Revision 1.19
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.19 2003/02/16 20:12:26 azarah 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.3 2002/11/11 19:51:20 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 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
47 more info. */ 49 more info. */
48GROUP ( /lib/libxxx ) 50GROUP ( /lib/libxxx )
49END_LDSCRIPT 51END_LDSCRIPT
50 52
51 dosed "s:libxxx:$1:" /usr/lib/$1 53 dosed "s:libxxx:$1:" /usr/lib/$1
54
55 return 0
52} 56}
53 57
58# Simple function to draw a line consisting of '=' the same length as $*
59#
60# <azarah@gentoo.org> (11 Nov 2002)
61#
62draw_line() {
63 local i=0
64 local str_length=""
65
66 # Handle calls that do not have args, or wc not being installed ...
67 if [ -z "$1" -o ! -x "$(which wc 2>/dev/null)" ]
68 then
69 echo "==============================================================="
70 return 0
71 fi
72
73 # Get the length of $*
74 str_length="$(echo -n "$*" | wc -m)"
75
76 while [ "$i" -lt "${str_length}" ]
77 do
78 echo -n "="
79
80 i=$((i + 1))
81 done
82
83 echo
84
85 return 0
86}
54 87
55# Default directory where patches are located 88# Default directory where patches are located
56EPATCH_SOURCE="${WORKDIR}/patch" 89EPATCH_SOURCE="${WORKDIR}/patch"
57# Default extension for patches 90# Default extension for patches
58EPATCH_SUFFIX="patch.bz2" 91EPATCH_SUFFIX="patch.bz2"
59# Default options for patch 92# Default options for patch
60EPATCH_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=""
61 99
62# This function is for bulk patching, or in theory for just one 100# This function is for bulk patching, or in theory for just one
63# or two patches. 101# or two patches.
64# 102#
65# It should work with .bz2, .gz, .zip and plain text patches. 103# It should work with .bz2, .gz, .zip and plain text patches.
93# <azarah@gentoo.org> (10 Nov 2002) 131# <azarah@gentoo.org> (10 Nov 2002)
94# 132#
95epatch() { 133epatch() {
96 local PIPE_CMD="" 134 local PIPE_CMD=""
97 local STDERR_TARGET="${T}/$$.out" 135 local STDERR_TARGET="${T}/$$.out"
136 local PATCH_TARGET="${T}/$$.patch"
137 local PATCH_SUFFIX=""
98 local SINGLE_PATCH="no" 138 local SINGLE_PATCH="no"
139 local x=""
99 140
100 if [ "$#" -gt 1 ] 141 if [ "$#" -gt 1 ]
101 then 142 then
102 eerror "Invalid arguments to epatch()" 143 eerror "Invalid arguments to epatch()"
103 die "Invalid arguments to epatch()" 144 die "Invalid arguments to epatch()"
105 146
106 if [ -n "$1" -a -f "$1" ] 147 if [ -n "$1" -a -f "$1" ]
107 then 148 then
108 SINGLE_PATCH="yes" 149 SINGLE_PATCH="yes"
109 150
110 EPATCH_SOURCE="$1" 151 local EPATCH_SOURCE="$1"
111 EPATCH_SUFFIX="${1##*\.}" 152 local EPATCH_SUFFIX="${1##*\.}"
112 153
113 elif [ -n "$1" -a -d "$1" ] 154 elif [ -n "$1" -a -d "$1" ]
114 then 155 then
115 EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 156 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
116 else 157 else
158 if [ ! -d ${EPATCH_SOURCE} ]
159 then
160 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
161 then
162 EPATCH_SOURCE="$1"
163 fi
164
165 echo
166 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
167 eerror
168 eerror " ${EPATCH_SOURCE}"
169 echo
170 die "Cannot find \$EPATCH_SOURCE!"
171 fi
172
117 EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 173 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
118 fi 174 fi
119 175
120 case ${EPATCH_SUFFIX##*\.} in 176 case ${EPATCH_SUFFIX##*\.} in
121 bz2) 177 bz2)
122 PIPE_CMD="bzip2 -dc" 178 PIPE_CMD="bzip2 -dc"
179 PATCH_SUFFIX="bz2"
123 ;; 180 ;;
124 gz) 181 gz|Z|z)
125 PIPE_CMD="gzip -dc" 182 PIPE_CMD="gzip -dc"
183 PATCH_SUFFIX="gz"
126 ;; 184 ;;
127 zip) 185 ZIP|zip)
128 PIPE_CMD="unzip -p" 186 PIPE_CMD="unzip -p"
187 PATCH_SUFFIX="zip"
129 ;; 188 ;;
130 *) 189 *)
131 PIPE_CMD="cat" 190 PIPE_CMD="cat"
191 PATCH_SUFFIX="patch"
132 ;; 192 ;;
133 esac 193 esac
134 194
135 if [ "${SINGLE_PATCH}" = "no" ] 195 if [ "${SINGLE_PATCH}" = "no" ]
136 then 196 then
141 # New ARCH dependant patch naming scheme... 201 # New ARCH dependant patch naming scheme...
142 # 202 #
143 # ???_arch_foo.patch 203 # ???_arch_foo.patch
144 # 204 #
145 if [ -f ${x} ] && \ 205 if [ -f ${x} ] && \
146 [ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] 206 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
147 then 207 then
148 local count=0 208 local count=0
149 local popts="${EPATCH_OPTS}" 209 local popts="${EPATCH_OPTS}"
210
211 if [ -n "${EPATCH_EXCLUDE}" ]
212 then
213 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
214 then
215 continue
216 fi
217 fi
150 218
151 if [ "${SINGLE_PATCH}" = "yes" ] 219 if [ "${SINGLE_PATCH}" = "yes" ]
152 then 220 then
221 if [ -n "${EPATCH_SINGLE_MSG}" ]
222 then
223 einfo "${EPATCH_SINGLE_MSG}"
224 else
153 einfo "Applying ${x##*/}..." 225 einfo "Applying ${x##*/}..."
226 fi
154 else 227 else
155 einfo " ${x##*/}..." 228 einfo " ${x##*/}..."
156 fi 229 fi
157 230
158 echo "*** Patch ${x##*/} ***" > ${STDERR_TARGET} 231 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
232 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
159 233
160 # Allow for prefix to differ ... im lazy, so shoot me :/ 234 # Allow for prefix to differ ... im lazy, so shoot me :/
161 while [ "${count}" -lt 5 ] 235 while [ "${count}" -lt 5 ]
162 do 236 do
163 if eval ${PIPE_CMD} ${x} | patch ${popts} --dry-run -f -p${count} 2>&1 >> ${STDERR_TARGET} 237 # Generate some useful debug info ...
238 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
239 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
240
241 if [ "${PATCH_SUFFIX}" != "patch" ]
164 then 242 then
165 eval ${PIPE_CMD} ${x} | patch ${popts} -p${count} 2>&1 >> ${STDERR_TARGET} 243 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
245 else
246 PATCH_TARGET="${x}"
247 fi
248
249 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
250 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
251
252 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
253 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
254
255 if [ "${PATCH_SUFFIX}" != "patch" ]
256 then
257 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
258 then
259 echo
260 eerror "Could not extract patch!"
261 #die "Could not extract patch!"
262 count=5
263 break
264 fi
265 fi
266
267 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
268 then
269 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
270 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
271 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
272 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
273 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
274
275 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
276
277 if [ "$?" -ne 0 ]
278 then
279 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
280 echo
281 eerror "A dry-run of patch command succeeded, but actually"
282 eerror "applying the patch failed!"
283 #die "Real world sux compared to the dreamworld!"
284 count=5
285 fi
286
287 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
288
166 break 289 break
167 fi 290 fi
168 291
169 count=$((count + 1)) 292 count=$((count + 1))
170 done 293 done
171 294
295 if [ "${PATCH_SUFFIX}" != "patch" ]
296 then
297 rm -f ${PATCH_TARGET}
298 fi
299
172 if [ "${count}" -eq 5 ] 300 if [ "${count}" -eq 5 ]
173 then 301 then
302 echo
174 eerror "Failed Patch: ${x##*/}!" 303 eerror "Failed Patch: ${x##*/}!"
175 eerror 304 eerror
176 eerror "Include in your bugreport the contents of:" 305 eerror "Include in your bugreport the contents of:"
177 eerror 306 eerror
178 eerror " ${STDERR_TARGET}" 307 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
179 eerror 308 echo
180 die "Failed Patch: ${x##*/}!" 309 die "Failed Patch: ${x##*/}!"
181 fi 310 fi
311
312 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
182 313
183 eend 0 314 eend 0
184 fi 315 fi
185 done 316 done
186 if [ "${SINGLE_PATCH}" = "no" ] 317 if [ "${SINGLE_PATCH}" = "no" ]
187 then 318 then
188 einfo "Done with patching" 319 einfo "Done with patching"
189 fi 320 fi
190} 321}
191 322
323# This function check how many cpu's are present, and then set
324# -j in MAKEOPTS accordingly.
325#
326# Thanks to nall <nall@gentoo.org> for this.
327#
328get_number_of_jobs() {
329 local jobs=0
330
331 if [ ! -r /proc/cpuinfo ]
332 then
333 return 1
334 fi
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
344 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
345
346 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" ]
347 then
348 # x86 and hppa always has "processor"
349 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
350
351 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
352 then
353 # sparc always has "ncpus active"
354 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
355
356 elif [ "${ARCH}" = "alpha" ]
357 then
358 # alpha has "cpus active", but only when compiled with SMP
359 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
360 then
361 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
362 else
363 jobs=2
364 fi
365
366 elif [ "${ARCH}" = "ppc" ]
367 then
368 # ppc has "processor", but only when compiled with SMP
369 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
370 then
371 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
372 else
373 jobs=2
374 fi
375 elif [ "${ARCH}" = "mips" ]
376 then
377 # mips always has "processor"
378 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
379
380 else
381 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
382 die "Unknown ARCH -- ${ARCH}!"
383 fi
384
385 # Make sure the number is valid ...
386 if [ "${jobs}" -lt 1 ]
387 then
388 jobs=1
389 fi
390
391 if [ -n "${ADMINPARAM}" ]
392 then
393 if [ "${jobs}" -gt "${ADMINPARAM}" ]
394 then
395 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
396 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
397 else
398 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
399 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
400 fi
401 fi
402}
403

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.20