/[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.14
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.14 2003/01/19 20:23:28 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"
12 12
13newdepend sys-devel/patch 13newdepend "!bootstrap? ( sys-devel/patch )"
14 14
15DESCRIPTION="Based on the ${ECLASS} eclass" 15DESCRIPTION="Based on the ${ECLASS} eclass"
16 16
17# This function generate linker scripts in /usr/lib for dynamic 17# This function generate linker scripts in /usr/lib for dynamic
18# libs in /lib. This is to fix linking problems when you have 18# libs in /lib. This is to fix linking problems when you have
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! Value for \$EPATCH_SOURCE is:"
160 eerror
161 eerror " ${EPATCH_SOURCE}"
162 echo
163 die "Cannot find \$EPATCH_SOURCE!"
164 fi
165
166 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
167 fi
168
169 case ${EPATCH_SUFFIX##*\.} in
170 bz2)
171 PIPE_CMD="bzip2 -dc"
172 PATCH_SUFFIX="bz2"
173 ;;
174 gz|Z|z)
175 PIPE_CMD="gzip -dc"
176 PATCH_SUFFIX="gz"
177 ;;
178 ZIP|zip)
179 PIPE_CMD="unzip -p"
180 PATCH_SUFFIX="zip"
181 ;;
182 *)
183 PIPE_CMD="cat"
184 PATCH_SUFFIX="patch"
185 ;;
186 esac
187
188 if [ "${SINGLE_PATCH}" = "no" ]
189 then
190 einfo "Applying various patches (bugfixes/updates)..."
191 fi
192 for x in ${EPATCH_SOURCE}
193 do
194 # New ARCH dependant patch naming scheme...
195 #
196 # ???_arch_foo.patch
197 #
198 if [ -f ${x} ] && \
199 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
200 then
201 local count=0
202 local popts="${EPATCH_OPTS}"
203
204 if [ -n "${EPATCH_EXCLUDE}" ]
205 then
206 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
207 then
208 continue
209 fi
210 fi
211
212 if [ "${SINGLE_PATCH}" = "yes" ]
213 then
214 if [ -n "${EPATCH_SINGLE_MSG}" ]
215 then
216 einfo "${EPATCH_SINGLE_MSG}"
217 else
218 einfo "Applying ${x##*/}..."
219 fi
220 else
221 einfo " ${x##*/}..."
222 fi
223
224 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
225 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
226
227 # Allow for prefix to differ ... im lazy, so shoot me :/
228 while [ "${count}" -lt 5 ]
229 do
230 # Generate some useful debug info ...
231 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
232 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
233
234 if [ "${PATCH_SUFFIX}" != "patch" ]
235 then
236 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
237 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
238 else
239 PATCH_TARGET="${x}"
240 fi
241
242 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
243 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244
245 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
246 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
247
248 if [ "${PATCH_SUFFIX}" != "patch" ]
249 then
250 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
251 then
252 echo
253 eerror "Could not extract patch!"
254 #die "Could not extract patch!"
255 count=5
256 break
257 fi
258 fi
259
260 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
261 then
262 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
263 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
264 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
265 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
266 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
267
268 patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
269
270 if [ "$?" -ne 0 ]
271 then
272 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
273 echo
274 eerror "A dry-run of patch command succeeded, but actually"
275 eerror "applying the patch failed!"
276 #die "Real world sux compared to the dreamworld!"
277 count=5
278 fi
279
280 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
281
282 break
283 fi
284
285 count=$((count + 1))
286 done
287
288 if [ "${PATCH_SUFFIX}" != "patch" ]
289 then
290 rm -f ${PATCH_TARGET}
291 fi
292
293 if [ "${count}" -eq 5 ]
294 then
295 echo
296 eerror "Failed Patch: ${x##*/}!"
297 eerror
298 eerror "Include in your bugreport the contents of:"
299 eerror
300 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
301 echo
302 die "Failed Patch: ${x##*/}!"
303 fi
304
305 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
306
307 eend 0
308 fi
309 done
310 if [ "${SINGLE_PATCH}" = "no" ]
311 then
312 einfo "Done with patching"
313 fi
314}
315
316# This function check how many cpu's are present, and then set
317# -j in MAKEOPTS accordingly.
318#
319# Thanks to nall <nall@gentoo.org> for this.
320#
321get_number_of_jobs() {
322 local jobs=0
323
324 if [ ! -r /proc/cpuinfo ]
325 then
326 return 1
327 fi
328
329 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
330 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
331 then
332 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
333 ADMINPARAM="${ADMINOPTS##*-j}"
334 ADMINPARAM="${ADMINPARAM%% -*}"
335 fi
336
337 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`"
338
339 if [ "${ARCH}" = "x86" ]
340 then
341 # x86 always has "processor"
342 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
343
344 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
345 then
346 # sparc always has "ncpus active"
347 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
348
349 elif [ "${ARCH}" = "alpha" ]
350 then
351 # alpha has "cpus active", but only when compiled with SMP
352 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
353 then
354 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
355 else
356 jobs=2
357 fi
358
359 elif [ "${ARCH}" = "ppc" ]
360 then
361 # ppc has "processor", but only when compiled with SMP
362 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
363 then
364 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
365 else
366 jobs=2
367 fi
368 elif [ "${ARCH}" = "mips" ]
369 then
370 # mips always has "processor"
371 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
372
373 else
374 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
375 die "Unknown ARCH -- ${ARCH}!"
376 fi
377
378 # Make sure the number is valid ...
379 if [ "${jobs}" -lt 1 ]
380 then
381 jobs=1
382 fi
383
384 if [ -n "${ADMINPARAM}" -a "${jobs}" -gt "${ADMINPARAM}" ]
385 then
386 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
387 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
388 else
389 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
390 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
391 fi
392}
393

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

  ViewVC Help
Powered by ViewVC 1.1.20