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

Contents of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Tue Feb 18 09:00:45 2003 UTC (11 years, 5 months ago) by carpaski
Branch: MAIN
Changes since 1.19: +2 -2 lines
If description is set... don't overwrite it...
Fixes to everything but ASPELL and KDE-SOURCE

1 vapier 1.18 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 azarah 1.1 # Distributed under the terms of the GNU General Public License v2
3 carpaski 1.20 # $Header: /home/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.19 2003/02/16 20:12:26 azarah Exp $
4 vapier 1.18 #
5 azarah 1.1 # Author: Martin Schlemmer <azarah@gentoo.org>
6 vapier 1.18 #
7 azarah 1.1 # This eclass is for general purpose functions that most ebuilds
8 vapier 1.7 # have to implement themselves.
9 azarah 1.1 #
10     # NB: If you add anything, please comment it!
11    
12     ECLASS=eutils
13     INHERITED="$INHERITED $ECLASS"
14    
15 azarah 1.12 newdepend "!bootstrap? ( sys-devel/patch )"
16 azarah 1.1
17 carpaski 1.20 [ -z "$DESCRIPTION" ] && DESCRIPTION="Based on the ${ECLASS} eclass"
18 azarah 1.1
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 azarah 1.5
55     return 0
56 azarah 1.2 }
57    
58 azarah 1.5 # 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 azarah 1.2
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 azarah 1.6 # List of patches not to apply. Not this is only file names,
95     # and not the full path ..
96     EPATCH_EXCLUDE=""
97 azarah 1.9 # Change the printed message for a single patch.
98     EPATCH_SINGLE_MSG=""
99 azarah 1.2
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 azarah 1.3 # Patches are applied in current directory.
114     #
115     # Bulk Patches should preferibly have the form of:
116 azarah 1.2 #
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 azarah 1.3 # 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 1.2 # <azarah@gentoo.org> (10 Nov 2002)
132     #
133     epatch() {
134     local PIPE_CMD=""
135     local STDERR_TARGET="${T}/$$.out"
136 azarah 1.8 local PATCH_TARGET="${T}/$$.patch"
137     local PATCH_SUFFIX=""
138 azarah 1.3 local SINGLE_PATCH="no"
139 azarah 1.4 local x=""
140 azarah 1.3
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 azarah 1.4 local EPATCH_SOURCE="$1"
152     local EPATCH_SUFFIX="${1##*\.}"
153 azarah 1.3
154     elif [ -n "$1" -a -d "$1" ]
155     then
156 azarah 1.4 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
157 azarah 1.3 else
158 azarah 1.8 if [ ! -d ${EPATCH_SOURCE} ]
159     then
160 azarah 1.19 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
161     then
162     EPATCH_SOURCE="$1"
163     fi
164    
165 azarah 1.8 echo
166 azarah 1.11 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
167     eerror
168     eerror " ${EPATCH_SOURCE}"
169 azarah 1.8 echo
170     die "Cannot find \$EPATCH_SOURCE!"
171     fi
172    
173 azarah 1.4 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
174 azarah 1.3 fi
175 azarah 1.2
176     case ${EPATCH_SUFFIX##*\.} in
177     bz2)
178     PIPE_CMD="bzip2 -dc"
179 azarah 1.8 PATCH_SUFFIX="bz2"
180 azarah 1.2 ;;
181 azarah 1.6 gz|Z|z)
182 azarah 1.2 PIPE_CMD="gzip -dc"
183 azarah 1.8 PATCH_SUFFIX="gz"
184 azarah 1.2 ;;
185 azarah 1.6 ZIP|zip)
186 azarah 1.2 PIPE_CMD="unzip -p"
187 azarah 1.8 PATCH_SUFFIX="zip"
188 azarah 1.2 ;;
189     *)
190     PIPE_CMD="cat"
191 azarah 1.8 PATCH_SUFFIX="patch"
192 azarah 1.2 ;;
193     esac
194    
195 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
196     then
197     einfo "Applying various patches (bugfixes/updates)..."
198     fi
199     for x in ${EPATCH_SOURCE}
200 azarah 1.2 do
201     # New ARCH dependant patch naming scheme...
202     #
203     # ???_arch_foo.patch
204     #
205     if [ -f ${x} ] && \
206 azarah 1.9 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
207 azarah 1.2 then
208     local count=0
209     local popts="${EPATCH_OPTS}"
210 azarah 1.6
211     if [ -n "${EPATCH_EXCLUDE}" ]
212     then
213 azarah 1.9 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
214 azarah 1.6 then
215     continue
216     fi
217     fi
218 azarah 1.3
219     if [ "${SINGLE_PATCH}" = "yes" ]
220     then
221 azarah 1.9 if [ -n "${EPATCH_SINGLE_MSG}" ]
222     then
223     einfo "${EPATCH_SINGLE_MSG}"
224     else
225     einfo "Applying ${x##*/}..."
226     fi
227 azarah 1.3 else
228     einfo " ${x##*/}..."
229     fi
230 azarah 1.2
231 azarah 1.8 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
232     echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
233 azarah 1.2
234     # Allow for prefix to differ ... im lazy, so shoot me :/
235     while [ "${count}" -lt 5 ]
236     do
237 azarah 1.5 # Generate some useful debug info ...
238 azarah 1.8 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
239     echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
240    
241     if [ "${PATCH_SUFFIX}" != "patch" ]
242     then
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 azarah 1.5
249 azarah 1.8 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
250     echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
251 azarah 1.5
252 azarah 1.8 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 azarah 1.5
267 azarah 1.19 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
268 azarah 1.2 then
269 azarah 1.8 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 azarah 1.19 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
276 azarah 1.8
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    
289 azarah 1.2 break
290     fi
291    
292     count=$((count + 1))
293     done
294    
295 azarah 1.8 if [ "${PATCH_SUFFIX}" != "patch" ]
296     then
297     rm -f ${PATCH_TARGET}
298     fi
299    
300 azarah 1.2 if [ "${count}" -eq 5 ]
301     then
302 azarah 1.8 echo
303 azarah 1.2 eerror "Failed Patch: ${x##*/}!"
304     eerror
305     eerror "Include in your bugreport the contents of:"
306     eerror
307 azarah 1.8 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
308     echo
309 azarah 1.2 die "Failed Patch: ${x##*/}!"
310     fi
311 azarah 1.8
312     rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
313 azarah 1.3
314     eend 0
315 azarah 1.2 fi
316     done
317 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
318     then
319     einfo "Done with patching"
320 azarah 1.10 fi
321     }
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     #
328     get_number_of_jobs() {
329 azarah 1.13 local jobs=0
330    
331 azarah 1.10 if [ ! -r /proc/cpuinfo ]
332     then
333     return 1
334     fi
335    
336 azarah 1.14 # 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 azarah 1.17 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
341     ADMINPARAM="${ADMINPARAM/-j}"
342 azarah 1.14 fi
343    
344 azarah 1.17 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
345 azarah 1.10
346 carpaski 1.16 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" ]
347 azarah 1.10 then
348 carpaski 1.16 # x86 and hppa always has "processor"
349 azarah 1.13 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
350 azarah 1.10
351     elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
352     then
353     # sparc always has "ncpus active"
354 azarah 1.13 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
355 azarah 1.10
356     elif [ "${ARCH}" = "alpha" ]
357     then
358     # alpha has "cpus active", but only when compiled with SMP
359 azarah 1.13 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
360 azarah 1.10 then
361 azarah 1.13 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
362 azarah 1.10 else
363 azarah 1.13 jobs=2
364 azarah 1.10 fi
365    
366     elif [ "${ARCH}" = "ppc" ]
367     then
368     # ppc has "processor", but only when compiled with SMP
369 azarah 1.13 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
370 azarah 1.10 then
371 azarah 1.13 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
372 azarah 1.10 else
373 azarah 1.13 jobs=2
374 azarah 1.10 fi
375 azarah 1.13 elif [ "${ARCH}" = "mips" ]
376     then
377     # mips always has "processor"
378     jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
379    
380 azarah 1.10 else
381 azarah 1.13 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
382 azarah 1.10 die "Unknown ARCH -- ${ARCH}!"
383 azarah 1.3 fi
384 azarah 1.13
385     # Make sure the number is valid ...
386     if [ "${jobs}" -lt 1 ]
387     then
388     jobs=1
389     fi
390 azarah 1.14
391 azarah 1.15 if [ -n "${ADMINPARAM}" ]
392 azarah 1.14 then
393 azarah 1.15 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 azarah 1.14 fi
402 azarah 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20