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
|
#!@BUILDLINK_SHELL@
#
# $NetBSD: gen-transform.sh,v 1.10 2004/01/11 03:30:20 grant Exp $
transform="@_BLNK_TRANSFORM_SEDFILE@"
untransform="@_BLNK_UNTRANSFORM_SEDFILE@"
# Mini-language for translating wrapper arguments into their buildlink
# equivalents:
#
# mangle:src:dst mangles the directory "src" into "dst"
# rpath:src:dst translates the directory "src" into "dst"
# in rpath options
# no-rpath removes "-R*", "-Wl,-R", and "-Wl,-rpath,*"
# depot:src:dst translates "src/<dir>/" into "dst/"
# I:src:dst translates "-Isrc" into "-Idst"
# L:src:dst translates "-Lsrc" into "-Ldst"
# l:foo:bar[:baz1...] translates "-lfoo" into "-lbar [-lbaz...]"
# P:src:dst translates "src/libfoo.{a,la}" into
# "dst/libfoo.{a,la}"
# p:path translates "path/*/libfoo.so" into
# "-Lpath/* -lfoo"
# r:dir removes "dir" and "dir/*"
# S:foo:bar translates word "foo" into "bar"
# s:foo:bar translates "foo" into "bar"
#
# Some transformations only make sense in one direction, so if a command
# is prefixed with either "transform:" or "untransform:", then the
# resulting sed commands are only appended the the corresponding sedfile.
gen() {
action=$1; shift
case "$action" in
transform) sedfile="$transform" ;;
untransform) sedfile="$untransform" ;;
esac
save_IFS="${IFS}"; IFS=":"
set -- $1
IFS="${save_IFS}"
case "$1" in
mangle)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2\([/ \`"':;]\)|$3\1|g
s|$2$|$3|g
EOF
;;
esac
;;
rpath)
gen $action mangle:-Wl,--rpath-link,$2:-Wl,--rpath-link,$3
gen $action mangle:-Wl,--rpath,$2:-Wl,--rpath,$3
gen $action mangle:-Wl,-rpath-link,$2:-Wl,-rpath-link,$3
gen $action mangle:-Wl,-rpath,$2:-Wl,-rpath,$3
gen $action mangle:-Wl,-R$2:-Wl,-R$3
gen $action mangle:-R$2:-R$3
;;
no-rpath)
gen $action _r:-Wl,--rpath-link,
gen $action _r:-Wl,--rpath,
gen $action _r:-Wl,-rpath-link,
gen $action _r:-Wl,-rpath,
gen $action _r:-Wl,-R
gen $action _r:-R
;;
depot)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2/[^/ \`"':;]*\(/[^ \`"':;]\)|$3\1|g
s|$2/[^/ \`"':;]*$|$3|g
EOF
;;
esac
;;
I|L)
case "$action" in
transform)
@CAT@ >> $sedfile << EOF
s|-$1$2\([ \`"':;]\)|-$1$3\1|g
s|-$1$2$|-$1$3|g
s|-$1$2/|-$1$3/|g
EOF
;;
untransform)
@CAT@ >> $sedfile << EOF
s|-$1$3\([ \`"':;]\)|-$1$2\1|g
s|-$1$3$|-$1$2|g
s|-$1$3/|-$1$2/|g
EOF
;;
esac
;;
l)
case "$action" in
transform|untransform)
shift
tolibs=
fromlib="-l$1"; shift
while [ $# -gt 0 ]; do
case $1 in
"") ;;
*) case $tolibs in
"") tolibs="-l$1" ;;
*) tolibs="$tolibs -l$1"
esac
;;
esac
shift
done
@CAT@ >> $sedfile << EOF
s|$fromlib\([ "':;]\)|$tolibs\1|g
s|$fromlib$|$tolibs|g
EOF
;;
esac
;;
P)
case "$action" in
transform)
@CAT@ >> $sedfile << EOF
s|$2\(/[^ \`"':;]*/lib[^/ \`"':;]*\.la\)\([ \`"':;]\)|$3\1\2|g
s|$2\(/[^ \`"':;]*/lib[^/ \`"':;]*\.la\)$|$3\1|g
s|$2\(/[^ \`"':;]*/lib[^/ \`"':;]*\.a\)\([ \`"':;]\)|$3\1\2|g
s|$2\(/[^ \`"':;]*/lib[^/ \`"':;]*\.a\)$|$3\1|g
EOF
;;
untransform)
@CAT@ >> $sedfile << EOF
s|$3\(/[^ \`"':;]*/lib[^/ \`"':;]*\.a\)\([ \`"':;]\)|$2\1\2|g
s|$3\(/[^ \`"':;]*/lib[^/ \`"':;]*\.a\)$|$2\1|g
s|$3\(/[^ \`"':;]*/lib[^/ \`"':;]*\.la\)\([ \`"':;]\)|$2\1\2|g
s|$3\(/[^ \`"':;]*/lib[^/ \`"':;]*\.la\)$|$2\1|g
EOF
;;
esac
;;
p)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*\.[0-9]*\.[0-9]*|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*\.[0-9]*\.[0-9]*|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*\.[0-9]*|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*\.[0-9]*|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.so\.[0-9]*|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.so|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.so|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.[0-9]*\.[0-9]*\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.[0-9]*\.[0-9]*\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.[0-9]*\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.[0-9]*\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.[0-9]*\.dylib|-L\1 -l\2|g
s|\($2/[^ \`"':;]*\)/lib\([^/ \`"':;]*\)\.dylib|-L\1 -l\2|g
s|\($2\)/lib\([^/ \`"':;]*\)\.dylib|-L\1 -l\2|g
EOF
;;
esac
;;
__r)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2/[^ \`"':;]*||g
EOF
;;
esac
;;
_r)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2\([ \`"':;]\)|\1|g
s|$2$||g
s|$2/[^ \`"':;]*||g
EOF
;;
esac
;;
r)
case "$2" in
"") r=__r ;;
*) r=_r ;;
esac
gen $action $r:-I$2
gen $action $r:-L$2
gen $action $r:-Wl,--rpath-link,$2
gen $action $r:-Wl,--rpath,$2
gen $action $r:-Wl,-rpath-link,$2
gen $action $r:-Wl,-rpath,$2
gen $action $r:-Wl,-R$2
gen $action $r:-R$2
;;
S)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2\([ \`"':;]\)|$3\1|g
s|$2$|$3|g
EOF
;;
esac
;;
s)
case "$action" in
transform|untransform)
@CAT@ >> $sedfile << EOF
s|$2|$3|g
EOF
;;
esac
;;
*)
echo "Unknown arg: $arg" 1>&2
exit 1
;;
esac
}
for arg do
case $arg in
transform:*)
gen transform "${arg#transform:}"
;;
untransform:*)
gen untransform "${arg#untransform:}"
;;
*)
gen transform "$arg"
gen untransform "$arg"
;;
esac
done
|