| 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.5 |
# $Header: /home/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.4 2002/11/11 21:36:45 azarah Exp $ |
| 5 |
azarah |
1.1 |
# This eclass is for general purpose functions that most ebuilds |
| 6 |
|
|
# have to implement themselfs. |
| 7 |
|
|
# |
| 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 |
|
|
|
| 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 |
azarah |
1.3 |
# Patches are applied in current directory. |
| 107 |
|
|
# |
| 108 |
|
|
# Bulk Patches should preferibly have the form of: |
| 109 |
azarah |
1.2 |
# |
| 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 |
azarah |
1.3 |
# 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 |
1.2 |
# <azarah@gentoo.org> (10 Nov 2002) |
| 125 |
|
|
# |
| 126 |
|
|
epatch() { |
| 127 |
|
|
local PIPE_CMD="" |
| 128 |
|
|
local STDERR_TARGET="${T}/$$.out" |
| 129 |
azarah |
1.3 |
local SINGLE_PATCH="no" |
| 130 |
azarah |
1.4 |
local x="" |
| 131 |
azarah |
1.3 |
|
| 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 |
azarah |
1.4 |
local EPATCH_SOURCE="$1" |
| 143 |
|
|
local EPATCH_SUFFIX="${1##*\.}" |
| 144 |
azarah |
1.3 |
|
| 145 |
|
|
elif [ -n "$1" -a -d "$1" ] |
| 146 |
|
|
then |
| 147 |
azarah |
1.4 |
local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" |
| 148 |
azarah |
1.3 |
else |
| 149 |
azarah |
1.4 |
local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" |
| 150 |
azarah |
1.3 |
fi |
| 151 |
azarah |
1.2 |
|
| 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 |
azarah |
1.3 |
if [ "${SINGLE_PATCH}" = "no" ] |
| 168 |
|
|
then |
| 169 |
|
|
einfo "Applying various patches (bugfixes/updates)..." |
| 170 |
|
|
fi |
| 171 |
|
|
for x in ${EPATCH_SOURCE} |
| 172 |
azarah |
1.2 |
do |
| 173 |
|
|
# New ARCH dependant patch naming scheme... |
| 174 |
|
|
# |
| 175 |
|
|
# ???_arch_foo.patch |
| 176 |
|
|
# |
| 177 |
|
|
if [ -f ${x} ] && \ |
| 178 |
azarah |
1.3 |
[ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] |
| 179 |
azarah |
1.2 |
then |
| 180 |
|
|
local count=0 |
| 181 |
|
|
local popts="${EPATCH_OPTS}" |
| 182 |
azarah |
1.3 |
|
| 183 |
|
|
if [ "${SINGLE_PATCH}" = "yes" ] |
| 184 |
|
|
then |
| 185 |
|
|
einfo "Applying ${x##*/}..." |
| 186 |
|
|
else |
| 187 |
|
|
einfo " ${x##*/}..." |
| 188 |
|
|
fi |
| 189 |
azarah |
1.2 |
|
| 190 |
azarah |
1.5 |
echo "***** ${x##*/} *****" > ${STDERR_TARGET} |
| 191 |
|
|
echo >> ${STDERR_TARGET} |
| 192 |
azarah |
1.2 |
|
| 193 |
|
|
# Allow for prefix to differ ... im lazy, so shoot me :/ |
| 194 |
|
|
while [ "${count}" -lt 5 ] |
| 195 |
|
|
do |
| 196 |
azarah |
1.5 |
# 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 |
azarah |
1.2 |
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 |
azarah |
1.3 |
|
| 226 |
|
|
eend 0 |
| 227 |
azarah |
1.2 |
fi |
| 228 |
|
|
done |
| 229 |
azarah |
1.3 |
if [ "${SINGLE_PATCH}" = "no" ] |
| 230 |
|
|
then |
| 231 |
|
|
einfo "Done with patching" |
| 232 |
|
|
fi |
| 233 |
azarah |
1.1 |
} |