summaryrefslogtreecommitdiff
path: root/mk/buildlink2/libtool-fix-la
blob: 1fd4cb909a0b11a1e71cd23389539848283d9247 (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
# $NetBSD: libtool-fix-la,v 1.22 2003/09/02 06:59:51 jlam Exp $
#
# For *.la files, in the "relink_command" line, we make the following
# replacements:
#
#       "libfoo.la" -> "-L./.libs libfoo.la"
#	"dirpath/libfoo.la" -> "-Ldirpath/.libs libfoo.la"
#
# This allows the libraries to be found within ${WRKSRC} during relinking.
# We rely on the proper rpath settings to be set by libtool.
#
# For the *.lai files, in the "dependency_libs" line, we remove redundant
# -Ldir and -llib options.

labase=`@BASENAME@ $lafile .la`
ladir=`@DIRNAME@ $lafile`
latimestamp=${ladir}/.${labase}.la.timestamp
laifile=${ladir}/.libs/${labase}.lai
if $test -f $lafile; then
	. ${ladir}/${labase}.la

	deps=
	for i in ${dependency_libs}; do
		case "$i" in
		-L*)
			case "$deps" in
			*"$i "*) ;;
			*"$i") ;;
			*) deps="${deps} $i" ;;
			esac
			;;
		*.la)
			fixla=0
			ltlibsdir=`@DIRNAME@ $i`/.libs
			case "$ltlibsdir" in
			/*)
				# fix if an absolute path in ${WRKSRC}
				case "$ltlibsdir" in
				@WRKSRC@/*)	fixla=1 ;;
				esac
				;;
			*)
				# fix all relative paths
				fixla=1
				;;
			esac
			if $test $fixla -gt 0; then
				case "$deps" in
				*"-L$ltlibsdir "*) ;;
				*"-L$ltlibsdir") ;;
				*) deps="$deps -L$ltlibsdir" ;;
				esac
			fi
			deps="${deps} $i"
			;;
		*)
			deps="${deps} $i"
			;;
		esac
	done

	relink=
	for i in ${relink_command}; do
		case "$i" in
		-I*|-D*)
			;;
		-L*)
			case "$relink" in
			*"$i "*) ;;
			*"$i") ;;
			*) relink="${relink} $i" ;;
			esac
			;;
		$lafile)
			relink="${relink} $i"
			;;
		*.la)
			fixla=0
			ltlibsdir=`@DIRNAME@ $i`/.libs
			case "$ltlibsdir" in
			/*)
				# fix if an absolute path in ${WRKSRC}
				case "$ltlibsdir" in
				@WRKSRC@/*)	fixla=1 ;;
				esac
				;;
			*)
				# fix all relative paths
				fixla=1
				;;
			esac
			if $test $fixla -gt 0; then
				case "$relink" in
				*"-L$ltlibsdir "*) ;;
				*"-L$ltlibsdir") ;;
				*) relink="$relink -L$ltlibsdir" ;;
				esac
			fi
			relink="${relink} $i"
			;;
		*)
			relink="${relink} $i"
			;;
		esac
	done
	if $test -z "$deps" && $test -z "$relink" || \
	   @EGREP@ "^#.*modified by buildlink2" $lafile >/dev/null 2>&1; then
		:
	else
		@MV@ -f $lafile ${lafile}.blsav
		if $test -n "$deps"; then
			(
			$cat ${lafile}.blsav | @SED@ -e '/^dependency_libs=/,$d'
			$echo "dependency_libs='$deps'"
			$cat ${lafile}.blsav | @SED@ -e '1,/^dependency_libs=/d'
			) > ${lafile}.tmp
		else
			$cat ${lafile}.blsav > ${lafile}.tmp
		fi
		if $test -n "$relink"; then
			(
			$cat ${lafile}.tmp | @SED@ -e '/^relink_command=/,$d'
			$echo "relink_command='$relink'"
			$cat ${lafile}.tmp | @SED@ -e '1,/^relink_command=/d'
			) > $lafile
		else
			$cat ${lafile}.tmp > $lafile
		fi
		$echo >> $lafile
		$echo "# This file has been modified by buildlink2." >> $lafile
		@RM@ ${lafile}.tmp
		$echo "==> Fixed $lafile" >> $wrapperlog
	fi
	if $test -z "$laifile" || $test ! -f "$laifile" || \
	   @EGREP@ "^#.*modified by buildlink2" $laifile >/dev/null 2>&1; then
		:
	else
		@SED@	@_BLNK_WRAP_LT_UNTRANSFORM_SED@ \
			@_BLNK_UNTRANSFORM_SED@ \
			$laifile > ${laifile}.tmp
		. ${laifile}.tmp
		L=; l=; lexist=; prev=
		for i in ${dependency_libs}; do
			case "$i" in
			$prev)
				;;
			-R*)
				# skip all -R* options... rpath info shouldn't
				# go into the dependency_libs line.
				;;
			-L*)
				case "$i" in
				-L${BUILDLINK_DIR}|-L${BUILDLINK_DIR}/*)
					;;
				-L${BUILDLINK_X11_DIR}|-L${BUILDLINK_X11_DIR}/*)
					;;
				-L@WRKSRC@|-L@WRKSRC@/*)
					;;
				*)
					case "$L" in
					*"$i "*) ;;
					*"$i") ;;
					*) L="$L $i" ;;
					esac
					;;
				esac
				;;
			-l*)
				lexist=1
				l="$l $i"
				;;
			*)
				l="$l $i"
				;;
			esac
			prev="$i"
		done
		if $test -z "$lexist"; then
			L=
		fi
		deps="$L$l"
		@MV@ -f $laifile ${laifile}.blsav
		(
			$cat ${laifile}.tmp | @SED@ -e '/^dependency_libs=/,$d'
			$echo "dependency_libs='$deps'"
			$cat ${laifile}.tmp | @SED@ -e '1,/^dependency_libs=/d'
			$echo
			$echo "# This file has been modified by buildlink2."
		) > ${laifile}
		@RM@ -f ${laifile}.tmp
		$echo "==> Fixed $laifile" >> $wrapperlog
		if $test "$libdir" != "${BUILDLINK_DIR}/.tmp/inst" && \
		   @EGREP@ "${BUILDLINK_X11_DIR}|${BUILDLINK_DIR}" $laifile >/dev/null 2>&1; then
			$echo "==> [buildlink2] Error: buildlink2 leakage into $laifile" >> $wrapperlog
			$echo "==> [buildlink2] Error: buildlink2 leakage into $laifile" 1>&2
			wrapper_result=1
		fi
	fi
fi