/[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.5
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.5 2002/11/11 22:36:22 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 themselfs.
7# 7#
8# NB: If you add anything, please comment it! 8# NB: If you add anything, please comment it!
9 9
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
93# This function is for bulk patching, or in theory for just one
94# or two patches.
95#
96# It should work with .bz2, .gz, .zip and plain text patches.
97# Currently all patches should be the same format.
98#
99# You do not have to specify '-p' option to patch, as it will
100# try with -p0 to -p5 until it succeed, or fail at -p5.
101#
102# Above EPATCH_* variables can be used to control various defaults,
103# bug they should be left as is to ensure an ebuild can rely on
104# them for.
105#
106# Patches are applied in current directory.
107#
108# Bulk Patches should preferibly have the form of:
109#
110# ??_${ARCH}_foo.${EPATCH_SUFFIX}
111#
112# For example:
113#
114# 01_all_misc-fix.patch.bz2
115# 02_sparc_another-fix.patch.bz2
116#
117# This ensures that there are a set order, and you can have ARCH
118# specific patches.
119#
120# If you however give an argument to epatch(), it will treat it as a
121# single patch that need to be applied if its a file. If on the other
122# hand its a directory, it will set EPATCH_SOURCE to this.
123#
124# <azarah@gentoo.org> (10 Nov 2002)
125#
126epatch() {
127 local PIPE_CMD=""
128 local STDERR_TARGET="${T}/$$.out"
129 local SINGLE_PATCH="no"
130 local x=""
131
132 if [ "$#" -gt 1 ]
133 then
134 eerror "Invalid arguments to epatch()"
135 die "Invalid arguments to epatch()"
136 fi
137
138 if [ -n "$1" -a -f "$1" ]
139 then
140 SINGLE_PATCH="yes"
141
142 local EPATCH_SOURCE="$1"
143 local EPATCH_SUFFIX="${1##*\.}"
144
145 elif [ -n "$1" -a -d "$1" ]
146 then
147 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
148 else
149 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
150 fi
151
152 case ${EPATCH_SUFFIX##*\.} in
153 bz2)
154 PIPE_CMD="bzip2 -dc"
155 ;;
156 gz)
157 PIPE_CMD="gzip -dc"
158 ;;
159 zip)
160 PIPE_CMD="unzip -p"
161 ;;
162 *)
163 PIPE_CMD="cat"
164 ;;
165 esac
166
167 if [ "${SINGLE_PATCH}" = "no" ]
168 then
169 einfo "Applying various patches (bugfixes/updates)..."
170 fi
171 for x in ${EPATCH_SOURCE}
172 do
173 # New ARCH dependant patch naming scheme...
174 #
175 # ???_arch_foo.patch
176 #
177 if [ -f ${x} ] && \
178 [ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
179 then
180 local count=0
181 local popts="${EPATCH_OPTS}"
182
183 if [ "${SINGLE_PATCH}" = "yes" ]
184 then
185 einfo "Applying ${x##*/}..."
186 else
187 einfo " ${x##*/}..."
188 fi
189
190 echo "***** ${x##*/} *****" > ${STDERR_TARGET}
191 echo >> ${STDERR_TARGET}
192
193 # Allow for prefix to differ ... im lazy, so shoot me :/
194 while [ "${count}" -lt 5 ]
195 do
196 # Generate some useful debug info ...
197 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET}
198 echo >> ${STDERR_TARGET}
199
200 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET}
201 echo "${PIPE_CMD} ${x} | patch ${popts} -p${count}" >> ${STDERR_TARGET}
202
203 echo >> ${STDERR_TARGET}
204 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET}
205
206 if eval ${PIPE_CMD} ${x} | patch ${popts} --dry-run -f -p${count} 2>&1 >> ${STDERR_TARGET}
207 then
208 eval ${PIPE_CMD} ${x} | patch ${popts} -p${count} 2>&1 >> ${STDERR_TARGET}
209 break
210 fi
211
212 count=$((count + 1))
213 done
214
215 if [ "${count}" -eq 5 ]
216 then
217 eerror "Failed Patch: ${x##*/}!"
218 eerror
219 eerror "Include in your bugreport the contents of:"
220 eerror
221 eerror " ${STDERR_TARGET}"
222 eerror
223 die "Failed Patch: ${x##*/}!"
224 fi
225
226 eend 0
227 fi
228 done
229 if [ "${SINGLE_PATCH}" = "no" ]
230 then
231 einfo "Done with patching"
232 fi
233}
234

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

  ViewVC Help
Powered by ViewVC 1.1.20