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

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.6 Revision 1.12
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.6 2002/11/12 18:25:37 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.12 2002/12/14 21:46:25 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 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"
12 12
13newdepend sys-devel/patch 13newdepend "!bootstrap? ( sys-devel/patch )"
14 14
15DESCRIPTION="Based on the ${ECLASS} eclass" 15DESCRIPTION="Based on the ${ECLASS} eclass"
16 16
17# This function generate linker scripts in /usr/lib for dynamic 17# This function generate linker scripts in /usr/lib for dynamic
18# libs in /lib. This is to fix linking problems when you have 18# libs in /lib. This is to fix linking problems when you have
90# Default options for patch 90# Default options for patch
91EPATCH_OPTS="" 91EPATCH_OPTS=""
92# List of patches not to apply. Not this is only file names, 92# List of patches not to apply. Not this is only file names,
93# and not the full path .. 93# and not the full path ..
94EPATCH_EXCLUDE="" 94EPATCH_EXCLUDE=""
95# Change the printed message for a single patch.
96EPATCH_SINGLE_MSG=""
95 97
96# This function is for bulk patching, or in theory for just one 98# This function is for bulk patching, or in theory for just one
97# or two patches. 99# or two patches.
98# 100#
99# It should work with .bz2, .gz, .zip and plain text patches. 101# It should work with .bz2, .gz, .zip and plain text patches.
127# <azarah@gentoo.org> (10 Nov 2002) 129# <azarah@gentoo.org> (10 Nov 2002)
128# 130#
129epatch() { 131epatch() {
130 local PIPE_CMD="" 132 local PIPE_CMD=""
131 local STDERR_TARGET="${T}/$$.out" 133 local STDERR_TARGET="${T}/$$.out"
134 local PATCH_TARGET="${T}/$$.patch"
135 local PATCH_SUFFIX=""
132 local SINGLE_PATCH="no" 136 local SINGLE_PATCH="no"
133 local x="" 137 local x=""
134 138
135 if [ "$#" -gt 1 ] 139 if [ "$#" -gt 1 ]
136 then 140 then
147 151
148 elif [ -n "$1" -a -d "$1" ] 152 elif [ -n "$1" -a -d "$1" ]
149 then 153 then
150 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 154 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
151 else 155 else
156 if [ ! -d ${EPATCH_SOURCE} ]
157 then
158 echo
159 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
160 eerror
161 eerror " ${EPATCH_SOURCE}"
162 echo
163 die "Cannot find \$EPATCH_SOURCE!"
164 fi
165
152 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 166 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
153 fi 167 fi
154 168
155 case ${EPATCH_SUFFIX##*\.} in 169 case ${EPATCH_SUFFIX##*\.} in
156 bz2) 170 bz2)
157 PIPE_CMD="bzip2 -dc" 171 PIPE_CMD="bzip2 -dc"
172 PATCH_SUFFIX="bz2"
158 ;; 173 ;;
159 gz|Z|z) 174 gz|Z|z)
160 PIPE_CMD="gzip -dc" 175 PIPE_CMD="gzip -dc"
176 PATCH_SUFFIX="gz"
161 ;; 177 ;;
162 ZIP|zip) 178 ZIP|zip)
163 PIPE_CMD="unzip -p" 179 PIPE_CMD="unzip -p"
180 PATCH_SUFFIX="zip"
164 ;; 181 ;;
165 *) 182 *)
166 PIPE_CMD="cat" 183 PIPE_CMD="cat"
184 PATCH_SUFFIX="patch"
167 ;; 185 ;;
168 esac 186 esac
169 187
170 if [ "${SINGLE_PATCH}" = "no" ] 188 if [ "${SINGLE_PATCH}" = "no" ]
171 then 189 then
176 # New ARCH dependant patch naming scheme... 194 # New ARCH dependant patch naming scheme...
177 # 195 #
178 # ???_arch_foo.patch 196 # ???_arch_foo.patch
179 # 197 #
180 if [ -f ${x} ] && \ 198 if [ -f ${x} ] && \
181 [ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] 199 [ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
182 then 200 then
183 local count=0 201 local count=0
184 local popts="${EPATCH_OPTS}" 202 local popts="${EPATCH_OPTS}"
185 203
186 if [ -n "${EPATCH_EXCLUDE}" ] 204 if [ -n "${EPATCH_EXCLUDE}" ]
187 then 205 then
188 if [ "${EPATCH_EXCLUDE/${x##*/}}" != "${EPATCH_EXCLUDE}" ] 206 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
189 then 207 then
190 continue 208 continue
191 fi 209 fi
192 fi 210 fi
193 211
194 if [ "${SINGLE_PATCH}" = "yes" ] 212 if [ "${SINGLE_PATCH}" = "yes" ]
195 then 213 then
214 if [ -n "${EPATCH_SINGLE_MSG}" ]
215 then
216 einfo "${EPATCH_SINGLE_MSG}"
217 else
196 einfo "Applying ${x##*/}..." 218 einfo "Applying ${x##*/}..."
219 fi
197 else 220 else
198 einfo " ${x##*/}..." 221 einfo " ${x##*/}..."
199 fi 222 fi
200 223
201 echo "***** ${x##*/} *****" > ${STDERR_TARGET} 224 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
202 echo >> ${STDERR_TARGET} 225 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
203 226
204 # Allow for prefix to differ ... im lazy, so shoot me :/ 227 # Allow for prefix to differ ... im lazy, so shoot me :/
205 while [ "${count}" -lt 5 ] 228 while [ "${count}" -lt 5 ]
206 do 229 do
207 # Generate some useful debug info ... 230 # Generate some useful debug info ...
208 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET} 231 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
209 echo >> ${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
210 241
211 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET} 242 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
212 echo "${PIPE_CMD} ${x} | patch ${popts} -p${count}" >> ${STDERR_TARGET} 243 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
213 244
214 echo >> ${STDERR_TARGET} 245 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
215 draw_line "***** ${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
216 259
217 if eval ${PIPE_CMD} ${x} | patch ${popts} --dry-run -f -p${count} 2>&1 >> ${STDERR_TARGET} 260 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
261 then
262 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 ]
218 then 271 then
219 eval ${PIPE_CMD} ${x} | patch ${popts} -p${count} 2>&1 >> ${STDERR_TARGET} 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
220 break 282 break
221 fi 283 fi
222 284
223 count=$((count + 1)) 285 count=$((count + 1))
224 done 286 done
225 287
288 if [ "${PATCH_SUFFIX}" != "patch" ]
289 then
290 rm -f ${PATCH_TARGET}
291 fi
292
226 if [ "${count}" -eq 5 ] 293 if [ "${count}" -eq 5 ]
227 then 294 then
295 echo
228 eerror "Failed Patch: ${x##*/}!" 296 eerror "Failed Patch: ${x##*/}!"
229 eerror 297 eerror
230 eerror "Include in your bugreport the contents of:" 298 eerror "Include in your bugreport the contents of:"
231 eerror 299 eerror
232 eerror " ${STDERR_TARGET}" 300 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
233 eerror 301 echo
234 die "Failed Patch: ${x##*/}!" 302 die "Failed Patch: ${x##*/}!"
235 fi 303 fi
304
305 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
236 306
237 eend 0 307 eend 0
238 fi 308 fi
239 done 309 done
240 if [ "${SINGLE_PATCH}" = "no" ] 310 if [ "${SINGLE_PATCH}" = "no" ]
241 then 311 then
242 einfo "Done with patching" 312 einfo "Done with patching"
243 fi 313 fi
244} 314}
245 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#
321get_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 fi
362}
363

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.20