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

Contents of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations) (download)
Sun Feb 16 04:26:21 2003 UTC (11 years, 7 months ago) by vapier
Branch: MAIN
Changes since 1.17: +4 -2 lines
header fixes

1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4 #
5 # Author: Martin Schlemmer <azarah@gentoo.org>
6 #
7 # This eclass is for general purpose functions that most ebuilds
8 # have to implement themselves.
9 #
10 # NB: If you add anything, please comment it!
11
12 ECLASS=eutils
13 INHERITED="$INHERITED $ECLASS"
14
15 newdepend "!bootstrap? ( sys-devel/patch )"
16
17 DESCRIPTION="Based on the ${ECLASS} eclass"
18
19 # This function generate linker scripts in /usr/lib for dynamic
20 # libs in /lib. This is to fix linking problems when you have
21 # the .so in /lib, and the .a in /usr/lib. What happens is that
22 # in some cases when linking dynamic, the .a in /usr/lib is used
23 # instead of the .so in /lib due to gcc/libtool tweaking ld's
24 # library search path. This cause many builds to fail.
25 # See bug #4411 for more info.
26 #
27 # To use, simply call:
28 #
29 # gen_usr_ldscript libfoo.so
30 #
31 # Note that you should in general use the unversioned name of
32 # the library, as ldconfig should usually update it correctly
33 # to point to the latest version of the library present.
34 #
35 # <azarah@gentoo.org> (26 Oct 2002)
36 #
37 gen_usr_ldscript() {
38
39 # Just make sure it exists
40 dodir /usr/lib
41
42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
43 /* GNU ld script
44 Because Gentoo have critical dynamic libraries
45 in /lib, and the static versions in /usr/lib, we
46 need to have a "fake" dynamic lib in /usr/lib,
47 otherwise we run into linking problems.
48 See bug #4411 on http://bugs.gentoo.org/ for
49 more info. */
50 GROUP ( /lib/libxxx )
51 END_LDSCRIPT
52
53 dosed "s:libxxx:$1:" /usr/lib/$1
54
55 return 0
56 }
57
58 # Simple function to draw a line consisting of '=' the same length as $*
59 #
60 # <azarah@gentoo.org> (11 Nov 2002)
61 #
62 draw_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 }
87
88 # Default directory where patches are located
89 EPATCH_SOURCE="${WORKDIR}/patch"
90 # Default extension for patches
91 EPATCH_SUFFIX="patch.bz2"
92 # Default options for patch
93 EPATCH_OPTS=""
94 # List of patches not to apply. Not this is only file names,
95 # and not the full path ..
96 EPATCH_EXCLUDE=""
97 # Change the printed message for a single patch.
98 EPATCH_SINGLE_MSG=""
99
100 # This function is for bulk patching, or in theory for just one
101 # or two patches.
102 #
103 # It should work with .bz2, .gz, .zip and plain text patches.
104 # Currently all patches should be the same format.
105 #
106 # You do not have to specify '-p' option to patch, as it will
107 # try with -p0 to -p5 until it succeed, or fail at -p5.
108 #
109 # Above EPATCH_* variables can be used to control various defaults,
110 # bug they should be left as is to ensure an ebuild can rely on
111 # them for.
112 #
113 # Patches are applied in current directory.
114 #
115 # Bulk Patches should preferibly have the form of:
116 #
117 # ??_${ARCH}_foo.${EPATCH_SUFFIX}
118 #
119 # For example:
120 #
121 # 01_all_misc-fix.patch.bz2
122 # 02_sparc_another-fix.patch.bz2
123 #
124 # This ensures that there are a set order, and you can have ARCH
125 # specific patches.
126 #
127 # If you however give an argument to epatch(), it will treat it as a
128 # single patch that need to be applied if its a file. If on the other
129 # hand its a directory, it will set EPATCH_SOURCE to this.
130 #
131 # <azarah@gentoo.org> (10 Nov 2002)
132 #
133 epatch() {
134 local PIPE_CMD=""
135 local STDERR_TARGET="${T}/$$.out"
136 local PATCH_TARGET="${T}/$$.patch"
137 local PATCH_SUFFIX=""
138 local SINGLE_PATCH="no"
139 local x=""
140
141 if [ "$#" -gt 1 ]
142 then
143 eerror "Invalid arguments to epatch()"
144 die "Invalid arguments to epatch()"
145 fi
146
147 if [ -n "$1" -a -f "$1" ]
148 then
149 SINGLE_PATCH="yes"
150
151 local EPATCH_SOURCE="$1"
152 local EPATCH_SUFFIX="${1##*\.}"
153
154 elif [ -n "$1" -a -d "$1" ]
155 then
156 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
157 else
158 if [ ! -d ${EPATCH_SOURCE} ]
159 then
160 echo
161 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
162 eerror
163 eerror " ${EPATCH_SOURCE}"
164 echo
165 die "Cannot find \$EPATCH_SOURCE!"
166 fi
167
168 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
169 fi
170
171 case ${EPATCH_SUFFIX##*\.} in
172 bz2)
173 PIPE_CMD="bzip2 -dc"
174 PATCH_SUFFIX="bz2"
175 ;;
176 gz|Z|z)
177 PIPE_CMD="gzip -dc"
178 PATCH_SUFFIX="gz"
179 ;;
180 ZIP|zip)
181 PIPE_CMD="unzip -p"
182 PATCH_SUFFIX="zip"
183 ;;
184 *)
185 PIPE_CMD="cat"
186 PATCH_SUFFIX="patch"
187 ;;
188 esac
189
190 if [ "${SINGLE_PATCH}" = "no" ]
191 then
192 einfo "Applying various patches (bugfixes/updates)..."
193 fi
194 for x in ${EPATCH_SOURCE}
195 do
196 # New ARCH dependant patch naming scheme...
197 #
198 # ???_arch_foo.patch
199 #
200 if [ -f ${x} ] && \
201 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
202 then
203 local count=0
204 local popts="${EPATCH_OPTS}"
205
206 if [ -n "${EPATCH_EXCLUDE}" ]
207 then
208 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
209 then
210 continue
211 fi
212 fi
213
214 if [ "${SINGLE_PATCH}" = "yes" ]
215 then
216 if [ -n "${EPATCH_SINGLE_MSG}" ]
217 then
218 einfo "${EPATCH_SINGLE_MSG}"
219 else
220 einfo "Applying ${x##*/}..."
221 fi
222 else
223 einfo " ${x##*/}..."
224 fi
225
226 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
227 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
228
229 # Allow for prefix to differ ... im lazy, so shoot me :/
230 while [ "${count}" -lt 5 ]
231 do
232 # Generate some useful debug info ...
233 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
234 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
235
236 if [ "${PATCH_SUFFIX}" != "patch" ]
237 then
238 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
239 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
240 else
241 PATCH_TARGET="${x}"
242 fi
243
244 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
245 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
246
247 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
248 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
249
250 if [ "${PATCH_SUFFIX}" != "patch" ]
251 then
252 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
253 then
254 echo
255 eerror "Could not extract patch!"
256 #die "Could not extract patch!"
257 count=5
258 break
259 fi
260 fi
261
262 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
263 then
264 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
265 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
266 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
267 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
268 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
269
270 patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
271
272 if [ "$?" -ne 0 ]
273 then
274 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
275 echo
276 eerror "A dry-run of patch command succeeded, but actually"
277 eerror "applying the patch failed!"
278 #die "Real world sux compared to the dreamworld!"
279 count=5
280 fi
281
282 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
283
284 break
285 fi
286
287 count=$((count + 1))
288 done
289
290 if [ "${PATCH_SUFFIX}" != "patch" ]
291 then
292 rm -f ${PATCH_TARGET}
293 fi
294
295 if [ "${count}" -eq 5 ]
296 then
297 echo
298 eerror "Failed Patch: ${x##*/}!"
299 eerror
300 eerror "Include in your bugreport the contents of:"
301 eerror
302 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
303 echo
304 die "Failed Patch: ${x##*/}!"
305 fi
306
307 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
308
309 eend 0
310 fi
311 done
312 if [ "${SINGLE_PATCH}" = "no" ]
313 then
314 einfo "Done with patching"
315 fi
316 }
317
318 # This function check how many cpu's are present, and then set
319 # -j in MAKEOPTS accordingly.
320 #
321 # Thanks to nall <nall@gentoo.org> for this.
322 #
323 get_number_of_jobs() {
324 local jobs=0
325
326 if [ ! -r /proc/cpuinfo ]
327 then
328 return 1
329 fi
330
331 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
332 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
333 then
334 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
335 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
336 ADMINPARAM="${ADMINPARAM/-j}"
337 fi
338
339 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
340
341 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" ]
342 then
343 # x86 and hppa always has "processor"
344 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
345
346 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
347 then
348 # sparc always has "ncpus active"
349 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
350
351 elif [ "${ARCH}" = "alpha" ]
352 then
353 # alpha has "cpus active", but only when compiled with SMP
354 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
355 then
356 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
357 else
358 jobs=2
359 fi
360
361 elif [ "${ARCH}" = "ppc" ]
362 then
363 # ppc has "processor", but only when compiled with SMP
364 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
365 then
366 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
367 else
368 jobs=2
369 fi
370 elif [ "${ARCH}" = "mips" ]
371 then
372 # mips always has "processor"
373 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
374
375 else
376 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
377 die "Unknown ARCH -- ${ARCH}!"
378 fi
379
380 # Make sure the number is valid ...
381 if [ "${jobs}" -lt 1 ]
382 then
383 jobs=1
384 fi
385
386 if [ -n "${ADMINPARAM}" ]
387 then
388 if [ "${jobs}" -gt "${ADMINPARAM}" ]
389 then
390 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
391 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
392 else
393 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
394 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
395 fi
396 fi
397 }

  ViewVC Help
Powered by ViewVC 1.1.20