summaryrefslogtreecommitdiff
blob: 715430e6e3e98a527a63896e223eabf410cf99c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Copyright 1999-2004 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/libtool.eclass,v 1.27 2004/06/08 21:11:50 mr_bones_ Exp $
#
# Author: Martin Schlemmer <azarah@gentoo.org>
#
# This eclass patches ltmain.sh distributed with libtoolized packages with the
# relink and portage patch among others

ECLASS="libtool"
INHERITED="${INHERITED} ${ECLASS}"

DEPEND="!bootstrap? ( sys-devel/libtool )"

DESCRIPTION="Based on the ${ECLASS} eclass"

ELIBTOOL_VERSION="2.0.1"


ELT_PATCH_DIR="${PORTDIR}/eclass/ELT-patches"
ELT_APPLIED_PATCHES=

#
# Returns all the directories containing ltmain.sh
#
ELT_find_ltmain_sh() {
	local x=
	local dirlist=

	for x in $(find "${S}" -name 'ltmain.sh')
	do
		dirlist="${dirlist} ${x%/*}"
	done

	echo "${dirlist}"
}

#
# See if we can apply $2 on $1, and if so, do it
#
ELT_try_and_apply_patch() {
	local ret=0
	local patch="$2"

	# We only support patchlevel of 0 - why worry if its static patches?
	if patch -p0 --dry-run $1 < ${patch} &>${T}/elibtool.log
	then
		einfo "  Applying $(basename "$(dirname "${patch}")")-${patch##*/}.patch..."
		patch -p0 $1 < ${patch} &>${T}/elibtool.log
		ret=$?
		export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${patch##*/}"
	else
		ret=1
	fi

	return ${ret}
}

#
# Run through the patches in $2 and see if any
# apply to $1 ...
#
ELT_walk_patches() {
	local x=
	local y=
	local ret=1
	local patch_dir=

	if [ -n "$2" ]
	then
		if [ -d "${ELT_PATCH_DIR}/$2" ]
		then
			patch_dir="${ELT_PATCH_DIR}/$2"
		else
			return ${ret}
		fi

		for x in $(ls -d "${patch_dir}"/* 2>/dev/null)
		do
			if [ -n "${x}" -a -f "${x}" ]
			then
				# For --remove-internal-dep ...
				if [ -n "$3" ]
				then
					# For replace @REM_INT_DEP@ with what was passed
					# to --remove-internal-dep
					sed -e "s|@REM_INT_DEP@|$3|g" ${x} > \
						${T}/$$.rem_int_deps.patch

					x="${T}/$$.rem_int_deps.patch"
				fi

				if ELT_try_and_apply_patch "$1" "${x}"
				then
					ret=0
					break
				fi
			fi
		done
	fi

	return ${ret}
}

elibtoolize() {
	local x=
	local y=
	local do_portage="no"
	local do_reversedeps="no"
	local do_only_patches="no"
	local deptoremove=
	local my_dirlist=
	local elt_patches="portage relink max_cmd_len sed test tmp"

	my_dirlist="$(ELT_find_ltmain_sh)"

	for x in $*
	do
		case "${x}" in
			"--portage")
				# Only apply portage patch, and don't
				# 'libtoolize --copy --force' if all patches fail.
				do_portage="yes"
				;;
			"--reverse-deps")
				# Apply the reverse-deps patch
				# http://bugzilla.gnome.org/show_bug.cgi?id=75635
				do_reversedeps="yes"
				elt_patches="${elt_patches} fix-relink"
				;;
			"--patch-only")
				# Do not run libtoolize if none of the patches apply ..
				do_only_patches="yes"
				;;
			"^--remove-internal-dep="*)
				# We will replace @REM_INT_DEP@ with what is needed
				# in ELT_walk_patches() ...
				deptoremove="$(echo "${x}" | sed -e 's|--remove-internal-dep=||')"

				# Add the patch for this ...
				[ -n "${deptoremove}" ] && elt_patches="${elt_patches} rem-int-dep"
				;;
			"--shallow")
				# Only patch the ltmain.sh in ${S}
				if [ -f "${S}/ltmain.sh" ]
				then
					my_dirlist="${S}"
				else
					my_dirlist=
				fi
				;;
		esac
	done

	for x in ${my_dirlist}
	do
		local tmp="$(echo "${x}" | sed -e "s|${S}||")"
		export ELT_APPLIED_PATCHES=

		cd ${x}
		einfo "Patching \${S}$(echo "/${tmp}/ltmain.sh" | sed -e 's|//|/|g')..."

		for y in ${elt_patches}
		do
			local ret=0

			case "${y}" in
				"rem-int-dep")
					ELT_walk_patches "${x}/ltmain.sh" "${y}" "${deptoremove}"
					ret=$?
					;;
				"fix-relink")
					# Do not apply if we do not have the relink patch applied ...
					if [ -n "$(grep 'inst_prefix_dir' "${x}/ltmain.sh")" ]
					then
						ELT_walk_patches "${x}/ltmain.sh" "${y}"
						ret=$?
					fi
					;;
				"max_cmd_len")
					# Do not apply if $max_cmd_len is not used ...
					if [ -n "$(grep 'max_cmd_len' "${x}/ltmain.sh")" ]
					then
						ELT_walk_patches "${x}/ltmain.sh" "${y}"
						ret=$?
					fi
					;;
				*)
					ELT_walk_patches "${x}/ltmain.sh" "${y}"
					ret=$?
					;;
			esac

			if [ "${ret}" -ne 0 ]
			then
				case ${y} in
					"relink")
						# Critical patch, but could be applied ...
						if [ -z "$(grep 'inst_prefix_dir' "${x}/ltmain.sh")" ]
						then
							ewarn "  Could not apply relink.patch!"
						fi
						;;
					"portage")
						# Critical patch - for this one we abort, as it can really
						# cause breakage without it applied!
						if [ "${do_portage}" = "yes" ]
						then
							# Stupid test to see if its already applied ...
							if [ -z "$(grep 'We do not want portage' "${x}/ltmain.sh")" ]
							then
								echo
								eerror "Portage patch requested, but failed to apply!"
								die "Portage patch requested, but failed to apply!"
							fi
						else
							ewarn "  Could not apply portage.patch!"
							ewarn "  Please verify that it is not needed."
						fi
						;;
				esac
			fi

			if [ -z "${ELT_APPLIED_PATCHES}" ]
			then
				if [ "${do_portage}" = "no" -a \
				     "${do_reversedeps}" = "no" -a \
					 "${do_only_patches}" = "no" -a \
				     "${deptoremove}" = "" ]
				then
					# Sometimes ltmain.sh is in a subdirectory ...
					if [ ! -f ${x}/configure.in -a ! -f ${x}/configure.ac ]
					then
						if [ -f ${x}/../configure.in -o -f ${x}/../configure.ac ]
						then
							cd ${x}/../
						fi
					fi

					if which libtoolize &>/dev/null
					then
						ewarn "Cannot apply any patch, running libtoolize..."
						libtoolize --copy --force
					fi
					cd ${x}
					break
				fi
			fi
		done
	done

	if [ -f libtool ]
	then
		rm -f libtool
	fi

	# We need to change the pwd back to $S, as we may be called in
	# src_compile()
	cd ${S}
}