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

Contents of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sun Dec 1 15:48:27 2002 UTC (11 years, 9 months ago) by azarah
Branch: MAIN
Changes since 1.8: +11 -4 lines
small fixes

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.9 # $Header: /home/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.8 2002/12/01 12:34:23 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     eerror "Cannot find \$EPATCH_SOURCE!"
160     echo
161     die "Cannot find \$EPATCH_SOURCE!"
162     fi
163    
164 azarah 1.4 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
165 azarah 1.3 fi
166 azarah 1.2
167     case ${EPATCH_SUFFIX##*\.} in
168     bz2)
169     PIPE_CMD="bzip2 -dc"
170 azarah 1.8 PATCH_SUFFIX="bz2"
171 azarah 1.2 ;;
172 azarah 1.6 gz|Z|z)
173 azarah 1.2 PIPE_CMD="gzip -dc"
174 azarah 1.8 PATCH_SUFFIX="gz"
175 azarah 1.2 ;;
176 azarah 1.6 ZIP|zip)
177 azarah 1.2 PIPE_CMD="unzip -p"
178 azarah 1.8 PATCH_SUFFIX="zip"
179 azarah 1.2 ;;
180     *)
181     PIPE_CMD="cat"
182 azarah 1.8 PATCH_SUFFIX="patch"
183 azarah 1.2 ;;
184     esac
185    
186 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
187     then
188     einfo "Applying various patches (bugfixes/updates)..."
189     fi
190     for x in ${EPATCH_SOURCE}
191 azarah 1.2 do
192     # New ARCH dependant patch naming scheme...
193     #
194     # ???_arch_foo.patch
195     #
196     if [ -f ${x} ] && \
197 azarah 1.9 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
198 azarah 1.2 then
199     local count=0
200     local popts="${EPATCH_OPTS}"
201 azarah 1.6
202     if [ -n "${EPATCH_EXCLUDE}" ]
203     then
204 azarah 1.9 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
205 azarah 1.6 then
206     continue
207     fi
208     fi
209 azarah 1.3
210     if [ "${SINGLE_PATCH}" = "yes" ]
211     then
212 azarah 1.9 if [ -n "${EPATCH_SINGLE_MSG}" ]
213     then
214     einfo "${EPATCH_SINGLE_MSG}"
215     else
216     einfo "Applying ${x##*/}..."
217     fi
218 azarah 1.3 else
219     einfo " ${x##*/}..."
220     fi
221 azarah 1.2
222 azarah 1.8 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
223     echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
224 azarah 1.2
225     # Allow for prefix to differ ... im lazy, so shoot me :/
226     while [ "${count}" -lt 5 ]
227     do
228 azarah 1.5 # Generate some useful debug info ...
229 azarah 1.8 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 azarah 1.5
240 azarah 1.8 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
241     echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
242 azarah 1.5
243 azarah 1.8 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 azarah 1.5
258 azarah 1.8 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
259 azarah 1.2 then
260 azarah 1.8 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 azarah 1.2 break
281     fi
282    
283     count=$((count + 1))
284     done
285    
286 azarah 1.8 if [ "${PATCH_SUFFIX}" != "patch" ]
287     then
288     rm -f ${PATCH_TARGET}
289     fi
290    
291 azarah 1.2 if [ "${count}" -eq 5 ]
292     then
293 azarah 1.8 echo
294 azarah 1.2 eerror "Failed Patch: ${x##*/}!"
295     eerror
296     eerror "Include in your bugreport the contents of:"
297     eerror
298 azarah 1.8 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
299     echo
300 azarah 1.2 die "Failed Patch: ${x##*/}!"
301     fi
302 azarah 1.8
303     rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
304 azarah 1.3
305     eend 0
306 azarah 1.2 fi
307     done
308 azarah 1.3 if [ "${SINGLE_PATCH}" = "no" ]
309     then
310     einfo "Done with patching"
311     fi
312 azarah 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20