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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
# $NetBSD: libtool-fix-la,v 1.7 2005/12/09 16:16:41 hira Exp $
#
# Copyright (c) 2004 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Johnny C. Lam.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the NetBSD
# Foundation, Inc. and its contributors.
# 4. Neither the name of The NetBSD Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# 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. We also make sure that we don't
# ever reference other .la files, only referring to other libraries
# via the usual "-L/path -llib" and making sure that /path is always
# somewhere under the default view. This makes wildcard dependencies
# work for "overwrite" packages by letting libtool find libraries in
# the default view.
BUILDLINK_DIR="@BUILDLINK_DIR@"
DEPOTBASE="@DEPOTBASE@"
LOCALBASE="@LOCALBASE@"
WRKSRC="@WRKSRC@"
basename="@BASENAME@"
dirname="@DIRNAME@"
egrep="@EGREP@"
mv="@MV@"
pwd="@PWD@"
rm="@RM@"
wrksrc_physical=`cd ${WRKSRC}; $pwd`
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
####################################################
# Skip all -R* options... rpath info shouldn't go into
# the dependency_libs line.
####################################################
-R*)
;;
####################################################
# Catch -L<dir> and remove redundant ones.
####################################################
-L*)
case $deps in
*"$i "*) ;;
*"$i") ;;
*) deps="$deps $i" ;;
esac
;;
####################################################
# Convert "dirpath/libfoo.la" into "-Ldirpath/.libs
# libfoo.la" if it's an uninstalled libtool archive.
# This allows proper relinking by libtool during the
# install stage by allowing it to find the uninstalled
# shared library in the .libs directory.
####################################################
*.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"
;;
####################################################
# Everything else Just Belongs in the dependency_libs
# line.
####################################################
*)
deps="$deps $i"
;;
esac
done
relink=
for i in ${relink_command}; do
case $i in
####################################################
# -I* and -D* are useless for linking.
####################################################
-I*|-D*)
;;
####################################################
# Catch -L<dir> and remove redundant ones.
####################################################
-L*)
case $relink in
*"$i "*) ;;
*"$i") ;;
*) relink="$relink $i" ;;
esac
;;
# This is the .la file we're relinking... don't touch it!
$lafile)
relink="$relink $i"
;;
####################################################
# Convert "dirpath/libfoo.la" into "-Ldirpath/.libs
# libfoo.la" if it's an uninstalled libtool archive.
# This allows proper relinking by libtool during the
# install stage by allowing it to find the uninstalled
# shared library in the .libs directory.
####################################################
*.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"
;;
####################################################
# Everything else Just Belongs in the relink_command
# line.
####################################################
*)
relink="$relink $i"
;;
esac
done
##############################################################
# Save the orignal .la file produced by libtool as .la.blsav,
# and create the new one with a signature.
##############################################################
$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 "# Directory that this library was built in:" >> $lafile
$echo "buildlibdir='"`cd $ladir; $pwd | $sed -e "s,^${wrksrc_physical},${WRKSRC},"`"'" >> $lafile
$echo >> $lafile
$echo "# This file has been modified by buildlink3." >> $lafile
$rm ${lafile}.tmp
msg_log $wrapperlog "==> Fixed $lafile"
##############################################################
# Fix up any .lai files (libtool archives that will be
# installed).
##############################################################
if $test -z "$laifile" || $test ! -f "$laifile" || \
$egrep "^#.*modified by buildlink3" $laifile >/dev/null 2>&1; then
:
else
$sed @_BLNK_WRAP_LT_UNTRANSFORM_SED@ \
$laifile > ${laifile}.tmp
. ${laifile}.tmp
deps_ok=no
deps="${dependency_libs}"
while $test "$deps_ok" = "no"; do
deps_ok=yes
L=; l=; lexist=; prev=
for i in $deps; do
case $i in
######################################
# Don't allowed repeated arguments, so
# "-lm -lm" becomes just "-lm".
######################################
$prev)
;;
######################################
# Skip all -R* options... rpath info
# shouldn't go into the dependency_libs
# line.
######################################
-R*)
;;
######################################
# Skip directories that should never
# appear in the -L<dir> flags. Also
# modify directories in ${DEPOTBASE} to
# point to somewhere in the default view
# ${LOCALBASE}, since we want "overwrite"
# packages to think the libraries really
# do just exist through the default view.
######################################
-L*)
case $i in
-L${BUILDLINK_DIR}/*)
;;
-L${WRKSRC}|-L${WRKSRC}/*)
;;
-L${DEPOTBASE}/*)
i=`$echo "$i" | $sed -e "s,-L${DEPOTBASE}/[^/]*/,-L${LOCALBASE}/,"`
case $L in
*"$i "*) ;;
*"$i") ;;
*) L="$L $i" ;;
esac
;;
*)
case $L in
*"$i "*) ;;
*"$i") ;;
*) L="$L $i" ;;
esac
;;
esac
;;
######################################
# Libraries really do exist, so we want
# to keep any -L<dir> flags we've seen
# in the generated dependency_libs line.
######################################
-l*)
lexist=1
l="$l $i"
;;
######################################
# Libtool archives should be changed from
# "/path/libfoo.la" to "-L/path -lfoo",
# where /path is appropriately modified
# so that the depot directory is changed
# to the views directory. This allows
# the .la files to be used by either
# "overwrite" or "pkgviews" packages and
# works correctly with wildcard
# dependencies.
######################################
*.la)
dirbase=`$dirname $i`
dir=`$echo "X$dirbase" | $Xsed -e "s,^${DEPOTBASE}/[^/]*/,${LOCALBASE}/,"`
case $L in
*"-L$dir "*) ;;
*"-L$dir") ;;
*) L="$L -L$dir" ;;
esac
libbase=`$basename $i .la`
lib="${libbase#lib}"
lexist=1
l="$l -l$lib"
deps_ok=no
;;
######################################
# Everything else Just Belongs.
######################################
*)
l="$l $i"
;;
esac
prev="$i"
done
if $test -z "$lexist"; then
L=
fi
deps="$L$l"
deps=`$echo "X$deps" | $Xsed -e "s/^[ ]*//"`
done
$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 buildlink3."
) > ${laifile}
$rm -f ${laifile}.tmp
msg_log $wrapperlog "==> Fixed $laifile"
if $egrep "${BUILDLINK_DIR}" $laifile >/dev/null 2>&1; then
msg_log $wrapperlog "==> [buildlink3] Error: buildlink3 leakage into $laifile"
$echo "==> [buildlink3] Error: buildlink3 leakage into $laifile" 1>&2
wrapper_result=1
fi
fi
fi
|