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

Contents of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations) (download)
Wed Dec 4 21:46:33 2002 UTC (11 years, 4 months ago) by azarah
Branch: MAIN
Changes since 1.10: +4 -2 lines
better error

1 azarah 1.1 # Copyright 1999-2002 Gentoo Technologies, Inc.
2     # Distributed under the terms of the GNU General Public License v2
3     # Author: Martin Schlemmer <azarah@gentoo.org>
4 azarah 1.11 # $Header: /home/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.10 2002/12/01 23:22:50 azarah Exp $
5 azarah 1.1 # This eclass is for general purpose functions that most ebuilds
6 vapier 1.7 # have to implement themselves.
7 azarah 1.1 #
8     # NB: If you add anything, please comment it!
9    
10     ECLASS=eutils
11     INHERITED="$INHERITED $ECLASS"
12    
13     newdepend sys-devel/patch
14    
15     DESCRIPTION="Based on the ${ECLASS} eclass"
16    
17     # This function generate linker scripts in /usr/lib for dynamic
18     # libs in /lib. This is to fix linking problems when you have
19     # the .so in /lib, and the .a in /usr/lib. What happens is that
20     # in some cases when linking dynamic, the .a in /usr/lib is used
21     # instead of the .so in /lib due to gcc/libtool tweaking ld's
22     # library search path. This cause many builds to fail.
23     # See bug #4411 for more info.
24     #
25     # To use, simply call:
26     #
27     # gen_usr_ldscript libfoo.so
28     #
29     # Note that you should in general use the unversioned name of
30     # the library, as ldconfig should usually update it correctly
31     # to point to the latest version of the library present.
32     #
33     # <azarah@gentoo.org> (26 Oct 2002)
34     #
35     gen_usr_ldscript() {
36    
37     # Just make sure it exists
38     dodir /usr/lib
39    
40     cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
41     /* GNU ld script
42     Because Gentoo have critical dynamic libraries
43     in /lib, and the static versions in /usr/lib, we
44     need to have a "fake" dynamic lib in /usr/lib,
45     otherwise we run into linking problems.
46     See bug #4411 on http://bugs.gentoo.org/ for
47     more info. */
48     GROUP ( /lib/libxxx )
49     END_LDSCRIPT
50    
51     dosed "s:libxxx:$1:" /usr/lib/$1
52 azarah 1.5
53     return 0
54 azarah 1.2 }
55    
56 azarah 1.5 # Simple function to draw a line consisting of '=' the same length as $*
57     #
58     # <azarah@gentoo.org> (11 Nov 2002)
59     #
60     draw_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 azarah 1.2
86     # Default directory where patches are located
87     EPATCH_SOURCE="${WORKDIR}/patch"
88     # Default extension for patches
89     EPATCH_SUFFIX="patch.bz2"
90     # Default options for patch
91     EPATCH_OPTS=""
92 azarah 1.6 # List of patches not to apply. Not this is only file names,
93     # and not the full path ..
94     EPATCH_EXCLUDE=""
95 azarah 1.9 # Change the printed message for a single patch.
96     EPATCH_SINGLE_MSG=""
97 azarah 1.2
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 azarah 1.3 # Patches are applied in current directory.
112     #
113     # Bulk Patches should preferibly have the form of:
114 azarah 1.2 #
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 azarah 1.3 # 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 1.2 # <azarah@gentoo.org> (10 Nov 2002)
130     #
131     epatch() {
132     local PIPE_CMD=""
133     local STDERR_TARGET="${T}/$$.out"
134 azarah 1.8 local PATCH_TARGET="${T}/$$.patch"
135     local PATCH_SUFFIX=""
136 azarah 1.3 local SINGLE_PATCH="no"
137 azarah 1.4 local x=""
138 azarah 1.3
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 azarah 1.4 local EPATCH_SOURCE="$1"
150     local EPATCH_SUFFIX="${1##*\.}"
151 azarah 1.3
152     elif [ -n "$1" -a -d "$1" ]
153     then
154 azarah 1.4 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
155 azarah 1.3 else
156 azarah 1.8 if [ ! -d ${EPATCH_SOURCE} ]
157     then
158     echo
159 azarah 1.11 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
160     eerror
161     eerror " ${EPATCH_SOURCE}"
162 azarah 1.8 echo
163     die "Cannot find \$EPATCH_SOURCE!"
164     fi
165    
166 azarah 1.4 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
167 azarah 1.3 fi
168 azarah 1.2
169     case ${EPATCH_SUFFIX##*\.} in
170     bz2)
171     PIPE_CMD="bzip2 -dc"
172 azarah 1.8 PATCH_SUFFIX="bz2"
173 azarah 1.2 ;;
174 azarah 1.6 gz|Z|z)
175 azarah 1.2 PIPE_CMD="gzip -dc"
176 azarah 1.8 PATCH_SUFFIX="gz"
177 azarah 1.2 ;;
178 azarah 1.6 ZIP|zip)
179 azarah 1.2 PIPE_CMD="unzip -p"
180 azarah 1.8 PATCH_SUFFIX="zip"
181 azarah 1.2 ;;
182     *)
183     PIPE_CMD="cat"
184 azarah 1.8 PATCH_SUFFIX="patch"
185 azarah 1.2 ;;
186     esac
187    
188 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
189     then
190     einfo "Applying various patches (bugfixes/updates)..."
191     fi
192     for x in ${EPATCH_SOURCE}
193 azarah 1.2 do
194     # New ARCH dependant patch naming scheme...
195     #
196     # ???_arch_foo.patch
197     #
198     if [ -f ${x} ] && \
199 azarah 1.9 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
200 azarah 1.2 then
201     local count=0
202     local popts="${EPATCH_OPTS}"
203 azarah 1.6
204     if [ -n "${EPATCH_EXCLUDE}" ]
205     then
206 azarah 1.9 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
207 azarah 1.6 then
208     continue
209     fi
210     fi
211 azarah 1.3
212     if [ "${SINGLE_PATCH}" = "yes" ]
213     then
214 azarah 1.9 if [ -n "${EPATCH_SINGLE_MSG}" ]
215     then
216     einfo "${EPATCH_SINGLE_MSG}"
217     else
218     einfo "Applying ${x##*/}..."
219     fi
220 azarah 1.3 else
221     einfo " ${x##*/}..."
222     fi
223 azarah 1.2
224 azarah 1.8 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
225     echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
226 azarah 1.2
227     # Allow for prefix to differ ... im lazy, so shoot me :/
228     while [ "${count}" -lt 5 ]
229     do
230 azarah 1.5 # Generate some useful debug info ...
231 azarah 1.8 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 azarah 1.5
242 azarah 1.8 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
243     echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244 azarah 1.5
245 azarah 1.8 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 azarah 1.5
260 azarah 1.8 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
261 azarah 1.2 then
262 azarah 1.8 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 azarah 1.2 break
283     fi
284    
285     count=$((count + 1))
286     done
287    
288 azarah 1.8 if [ "${PATCH_SUFFIX}" != "patch" ]
289     then
290     rm -f ${PATCH_TARGET}
291     fi
292    
293 azarah 1.2 if [ "${count}" -eq 5 ]
294     then
295 azarah 1.8 echo
296 azarah 1.2 eerror "Failed Patch: ${x##*/}!"
297     eerror
298     eerror "Include in your bugreport the contents of:"
299     eerror
300 azarah 1.8 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
301     echo
302 azarah 1.2 die "Failed Patch: ${x##*/}!"
303     fi
304 azarah 1.8
305     rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
306 azarah 1.3
307     eend 0
308 azarah 1.2 fi
309     done
310 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
311     then
312     einfo "Done with patching"
313 azarah 1.10 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     #
321     get_number_of_jobs() {
322     if [ ! -r /proc/cpuinfo ]
323     then
324     return 1
325     fi
326    
327     export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j[0-9]*::g'`"
328    
329     if [ "${ARCH}" = "x86" ]
330     then
331     # x86 always has "processor"
332     export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))"
333    
334     elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
335     then
336     # sparc always has "ncpus active"
337     export MAKEOPTS="${MAKEOPTS} -j$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
338    
339     elif [ "${ARCH}" = "alpha" ]
340     then
341     # alpha has "cpus active", but only when compiled with SMP
342     if [ "`grep -c "^cpus active" /proc/cpuinfo`" = "1" ]
343     then
344     export MAKEOPTS="${MAKEOPTS} -j$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
345     else
346     export MAKEOPTS="${MAKEOPTS} -j2"
347     fi
348    
349     elif [ "${ARCH}" = "ppc" ]
350     then
351     # ppc has "processor", but only when compiled with SMP
352     if [ "`grep -c "^processor" /proc/cpuinfo`" = "1" ]
353     then
354     export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^processor /proc/cpuinfo` * 2))"
355     else
356     export MAKEOPTS="${MAKEOPTS} -j2"
357     fi
358     else
359     export MAKEOPTS="${MAKEOPTS} -j$((`grep -c ^cpu /proc/cpuinfo` * 2))"
360     die "Unknown ARCH -- ${ARCH}!"
361 azarah 1.3 fi
362 azarah 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20