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

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

  ViewVC Help
Powered by ViewVC 1.1.20