summaryrefslogtreecommitdiff
path: root/mk/buildlink2/gen-transform.sh
blob: caf248f864cc71c789632f60e9ad1c287d0a4741 (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
#!@BUILDLINK_SHELL@

transform="@_BLNK_TRANSFORM_SEDFILE@"
untransform="@_BLNK_UNTRANSFORM_SEDFILE@"

# Mini-language for translating wrapper arguments into their buildlink
# equivalents:
#
#       I:src:dst		translates "-Isrc" into "-Idst"
#       II:src:dst1:dst2	translates "-Isrc" into "-Idst1 -Idst2"
#       L:src:dst		translates "-Lsrc" into "-Ldst"
#       LL:src:dst1:dst2	translates "-Lsrc" into "-Ldst1 -Ldst2"
#       l:foo:bar		translates "-lfoo" into "-lbar"
#	p:path			translates "/usr/pkg/lib/libfoo.{a,so}" into
#					"-L/usr/pkg/lib -lfoo"
#       r:dir			removes "dir" and "dir/*"
#       S:foo:bar		translates word "foo" into "bar"
#       s:foo:bar		translates "foo" into "bar"

gen() {
	action=$1; shift
	case "$action" in
	transform)	sedfile="$transform"   ;;
	untransform)	sedfile="$untransform" ;;
	esac
	save_IFS="${IFS}"; IFS=":"
	set -- $1
	case "$1" in
	I|L)
		case "$action" in
		transform)
			@CAT@ >> $sedfile << EOF
s|-$1$2[ 	]$|-$1$3 |g
s|-$1$2$|-$1$3|g
s|-$1$2\([^ 	]*\)|-$1$3\1|g
EOF
			;;
		untransform)
			@CAT@ >> $sedfile << EOF
s|-$1$3[ 	]$|-$1$2 |g
s|-$1$3$|-$1$2|g
s|-$1$3\([^ 	].*\)|-$1$2\1|g
EOF
			;;
		esac
		;;
	II|LL)
		case "$1" in II) opt=I ;; LL) opt=L ;; esac
		case "$action" in
		transform)
			@CAT@ >> $sedfile << EOF
s|-$opt$2[ 	]$|-$opt$3 -$opt$4 |g
s|-$opt$2$|-$opt$3 -$opt$4|g
s|-$opt$2\([^ 	]*\)|-$opt$3\1 -$opt$4\1|g
EOF
			;;
		untransform)
			@CAT@ >> $sedfile << EOF
s|-$opt$3[ 	]$|-$opt$2 |g
s|-$opt$4$|-$opt$2|g
s|-$opt$4\([^ 	]*\)|-$opt$2\1|g
EOF
			;;
		esac
		;;
	l)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|-$1$2[ 	]|-$1$3 |g
s|-$1$2$|-$1$3|g
EOF
			;;
		esac
		;;
	p)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|\($2/[^ 	]*\)/lib\([^ 	/]*\)\.a|-L\1 -l\2|g
s|\($2/[^ 	]*\)/lib\([^ 	/]*\)\.so|-L\1 -l\2|g
EOF
			;;
		esac
		;;
	_r)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|$2[ 	]| |g
s|$2$||g
s|$2[^ 	]*||g
EOF
			;;
		esac
		;;
	r)
		gen $action _r:-I$2
		gen $action _r:-L$2
		gen $action _r:-Wl,-R$2
		gen $action _r:-Wl,-rpath,$2
		gen $action _r:-R$2
		;;
	S)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|$2[ 	]|$3 |g
s|$2$|$3|g
EOF
			;;
		esac
		;;
	s)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|$2|$3|g
EOF
			;;
		esac
		;;
	no-rpath)
		case "$action" in
		transform|untransform)
			@CAT@ >> $sedfile << EOF
s|-Wl,-R[^ 	]*||g
s|-Wl,-rpath,[^ 	]*||g
s|-R[^ 	]*||g
EOF
			;;
		esac
		;;
	esac
	IFS="${save_IFS}"
}

for arg; do
	gen transform "$arg"
	gen untransform "$arg"
done