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

Diff of /eclass/eutils.eclass

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

Revision 1.1 Revision 1.10
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2002 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# Author: Martin Schlemmer <azarah@gentoo.org> 3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.1 2002/10/26 09:16:03 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.10 2002/12/01 23:22:50 azarah Exp $
5# This eclass is for general purpose functions that most ebuilds 5# This eclass is for general purpose functions that most ebuilds
6# have to implement themselfs. 6# have to implement themselves.
7# 7#
8# NB: If you add anything, please comment it! 8# NB: If you add anything, please comment it!
9 9
10ECLASS=eutils 10ECLASS=eutils
11INHERITED="$INHERITED $ECLASS" 11INHERITED="$INHERITED $ECLASS"
47 more info. */ 47 more info. */
48GROUP ( /lib/libxxx ) 48GROUP ( /lib/libxxx )
49END_LDSCRIPT 49END_LDSCRIPT
50 50
51 dosed "s:libxxx:$1:" /usr/lib/$1 51 dosed "s:libxxx:$1:" /usr/lib/$1
52
53 return 0
52} 54}
53 55
56# Simple function to draw a line consisting of '=' the same length as $*
57#
58# <azarah@gentoo.org> (11 Nov 2002)
59#
60draw_line() {
61 local i=0
62 local str_length=""
63
64 # Handle calls that do not have args, or wc not being installed ...
65 if [ -z "$1" -o ! -x "$(which wc 2>/dev/null)" ]
66 then
67 echo "==============================================================="
68 return 0
69 fi
70
71 # Get the length of $*
72 str_length="$(echo -n "$*" | wc -m)"
73
74 while [ "$i" -lt "${str_length}" ]
75 do
76 echo -n "="
77
78 i=$((i + 1))
79 done
80
81 echo
82
83 return 0
84}
85
86# Default directory where patches are located
87EPATCH_SOURCE="${WORKDIR}/patch"
88# Default extension for patches
89EPATCH_SUFFIX="patch.bz2"
90# Default options for patch
91EPATCH_OPTS=""
92# List of patches not to apply. Not this is only file names,
93# and not the full path ..
94EPATCH_EXCLUDE=""
95# Change the printed message for a single patch.
96EPATCH_SINGLE_MSG=""
97
98# This function is for bulk patching, or in theory for just one
99# or two patches.
100#
101# It should work with .bz2, .gz, .zip and plain text patches.
102# Currently all patches should be the same format.
103#
104# You do not have to specify '-p' option to patch, as it will
105# try with -p0 to -p5 until it succeed, or fail at -p5.
106#
107# Above EPATCH_* variables can be used to control various defaults,
108# bug they should be left as is to ensure an ebuild can rely on
109# them for.
110#
111# Patches are applied in current directory.
112#
113# Bulk Patches should preferibly have the form of:
114#
115# ??_${ARCH}_foo.${EPATCH_SUFFIX}
116#
117# For example:
118#
119# 01_all_misc-fix.patch.bz2
120# 02_sparc_another-fix.patch.bz2
121#
122# This ensures that there are a set order, and you can have ARCH
123# specific patches.
124#
125# If you however give an argument to epatch(), it will treat it as a
126# single patch that need to be applied if its a file. If on the other
127# hand its a directory, it will set EPATCH_SOURCE to this.
128#
129# <azarah@gentoo.org> (10 Nov 2002)
130#
131epatch() {
132 local PIPE_CMD=""
133 local STDERR_TARGET="${T}/$$.out"
134 local PATCH_TARGET="${T}/$$.patch"
135 local PATCH_SUFFIX=""
136 local SINGLE_PATCH="no"
137 local x=""
138
139 if [ "$#" -gt 1 ]
140 then
141 eerror "Invalid arguments to epatch()"
142 die "Invalid arguments to epatch()"
143 fi
144
145 if [ -n "$1" -a -f "$1" ]
146 then
147 SINGLE_PATCH="yes"
148
149 local EPATCH_SOURCE="$1"
150 local EPATCH_SUFFIX="${1##*\.}"
151
152 elif [ -n "$1" -a -d "$1" ]
153 then
154 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
155 else
156 if [ ! -d ${EPATCH_SOURCE} ]
157 then
158 echo
159 eerror "Cannot find \$EPATCH_SOURCE!"
160 echo
161 die "Cannot find \$EPATCH_SOURCE!"
162 fi
163
164 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
165 fi
166
167 case ${EPATCH_SUFFIX##*\.} in
168 bz2)
169 PIPE_CMD="bzip2 -dc"
170 PATCH_SUFFIX="bz2"
171 ;;
172 gz|Z|z)
173 PIPE_CMD="gzip -dc"
174 PATCH_SUFFIX="gz"
175 ;;
176 ZIP|zip)
177 PIPE_CMD="unzip -p"
178 PATCH_SUFFIX="zip"
179 ;;
180 *)
181 PIPE_CMD="cat"
182 PATCH_SUFFIX="patch"
183 ;;
184 esac
185
186 if [ "${SINGLE_PATCH}" = "no" ]
187 then
188 einfo "Applying various patches (bugfixes/updates)..."
189 fi
190 for x in ${EPATCH_SOURCE}
191 do
192 # New ARCH dependant patch naming scheme...
193 #
194 # ???_arch_foo.patch
195 #
196 if [ -f ${x} ] && \
197 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
198 then
199 local count=0
200 local popts="${EPATCH_OPTS}"
201
202 if [ -n "${EPATCH_EXCLUDE}" ]
203 then
204 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
205 then
206 continue
207 fi
208 fi
209
210 if [ "${SINGLE_PATCH}" = "yes" ]
211 then
212 if [ -n "${EPATCH_SINGLE_MSG}" ]
213 then
214 einfo "${EPATCH_SINGLE_MSG}"
215 else
216 einfo "Applying ${x##*/}..."
217 fi
218 else
219 einfo " ${x##*/}..."
220 fi
221
222 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
223 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
224
225 # Allow for prefix to differ ... im lazy, so shoot me :/
226 while [ "${count}" -lt 5 ]
227 do
228 # Generate some useful debug info ...
229 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
230 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
231
232 if [ "${PATCH_SUFFIX}" != "patch" ]
233 then
234 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
235 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
236 else
237 PATCH_TARGET="${x}"
238 fi
239
240 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
241 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
242
243 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
245
246 if [ "${PATCH_SUFFIX}" != "patch" ]
247 then
248 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
249 then
250 echo
251 eerror "Could not extract patch!"
252 #die "Could not extract patch!"
253 count=5
254 break
255 fi
256 fi
257
258 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
259 then
260 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
261 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
262 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
263 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
264 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
265
266 patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
267
268 if [ "$?" -ne 0 ]
269 then
270 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
271 echo
272 eerror "A dry-run of patch command succeeded, but actually"
273 eerror "applying the patch failed!"
274 #die "Real world sux compared to the dreamworld!"
275 count=5
276 fi
277
278 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
279
280 break
281 fi
282
283 count=$((count + 1))
284 done
285
286 if [ "${PATCH_SUFFIX}" != "patch" ]
287 then
288 rm -f ${PATCH_TARGET}
289 fi
290
291 if [ "${count}" -eq 5 ]
292 then
293 echo
294 eerror "Failed Patch: ${x##*/}!"
295 eerror
296 eerror "Include in your bugreport the contents of:"
297 eerror
298 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
299 echo
300 die "Failed Patch: ${x##*/}!"
301 fi
302
303 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
304
305 eend 0
306 fi
307 done
308 if [ "${SINGLE_PATCH}" = "no" ]
309 then
310 einfo "Done with patching"
311 fi
312}
313
314# This function check how many cpu's are present, and then set
315# -j in MAKEOPTS accordingly.
316#
317# Thanks to nall <nall@gentoo.org> for this.
318#
319get_number_of_jobs() {
320 if [ ! -r /proc/cpuinfo ]
321 then
322 return 1
323 fi
324
325 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`"
326
327 if [ "${ARCH}" = "x86" ]
328 then
329 # x86 always has "processor"
330 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))"
331
332 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
333 then
334 # sparc always has "ncpus active"
335 export MAKEOPTS="${MAKEOPTS} -j$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
336
337 elif [ "${ARCH}" = "alpha" ]
338 then
339 # alpha has "cpus active", but only when compiled with SMP
340 if [ "`grep -c "^cpus active" /proc/cpuinfo`" = "1" ]
341 then
342 export MAKEOPTS="${MAKEOPTS} -j$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
343 else
344 export MAKEOPTS="${MAKEOPTS} -j2"
345 fi
346
347 elif [ "${ARCH}" = "ppc" ]
348 then
349 # ppc has "processor", but only when compiled with SMP
350 if [ "`grep -c "^processor" /proc/cpuinfo`" = "1" ]
351 then
352 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))"
353 else
354 export MAKEOPTS="${MAKEOPTS} -j2"
355 fi
356 else
357 export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^cpu /proc/cpuinfo` * 2))"
358 die "Unknown ARCH -- ${ARCH}!"
359 fi
360}
361

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.20