-
Notifications
You must be signed in to change notification settings - Fork 15
/
bootstrap
executable file
·98 lines (84 loc) · 3.73 KB
/
bootstrap
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
#!/usr/bin/env bash
cd $(dirname $(readlink -f $0))
autoreconf -fiv
# Patch ltmain.sh
if [[ -f ltmain.sh ]] ; then
echo -n "Patching ltmain.sh... "
# (A) Apply some of the patches that Debian introduces to ltmain.sh in order to not link against
# all the dependencies of our libraries. Thus, reducing the over-linking produced by libtool.
# Concatenate dependency_libs only if link_all_deplibs != no
case="link) libs=\"\$deplibs %DEPLIBS% \$dependency_libs\" ;;"
newcase="link) libs=\"\$deplibs %DEPLIBS%\"\n"
newcase+="\t\ttest \"X\$link_all_deplibs\" != Xno \&\& libs=\"\$libs \$dependency_libs\" ;;"
script_1="s/$case/$newcase/"
# In the step of checking convenience libraries, iterate dependency_libs only if libdir is empty
# The objective here is to move 3 lines down (elif -> fi) until the end of the debplib loop.
script_2="
# Match only from '# It is a libtool convenience library' until the end of the next loop
/# It is a libtool convenience library/,/done/ {
# If the elif block is found, move it to the hold buffer
/elif/ {
# Append the next two lines to the pattern buffer
N
N
# Exchange pattern and hold buffers to keep the 3 lines
x
# Delele the current pattern buffer which should be blank
d
}
# If the end of the loop is found, append the contents of the hold buffer
/done/ {
# First, we switch buffers to check if the hold buffer contains our code
x
# If the hold buffer contained elif, it means that the elif block was prior to the loop
/elif/ {
# Restore the initial pattern
x
# Append the hold buffer to the pattern space
G
}
# If the hold buffer was empty, the elif block was not prior and the patch is not needed
/^$/ {
# Switch buffers again to restore the initial pattern
x
}
}
}"
# (B) Libtool has a weird 'feature' in which places all the linker options '-Wl,option' at the
# end of the command line. Some options, like '--as-needed', need to be placed before the
# library list to have any effect.
parse_flags=" -Wl,*--as-needed*)\n"
parse_flags+=" deplibs=\"\$deplibs \$wl--as-needed\"\n"
parse_flags+=" ;;\n"
parse_flags+=" -Wl,*--no-as-needed*)\n"
parse_flags+=" deplibs=\"\$deplibs \$wl--no-as-needed\"\n"
parse_flags+=" ;;\n"
iter_flags=" -Wl,--as-needed)\n"
iter_flags+=" if test \"\$linkmode,\$pass\" = \"prog,link\"; then\n"
iter_flags+=" compile_deplibs=\"\$deplib \$compile_deplibs\"\n"
iter_flags+=" finalize_deplibs=\"\$deplib \$finalize_deplibs\"\n"
iter_flags+=" else\n"
iter_flags+=" deplibs=\"\$deplib \$deplibs\"\n"
iter_flags+=" fi\n"
iter_flags+=" continue\n"
iter_flags+=" ;;\n"
script_3="
# Match only from within the func_mode_link() function
/func_mode_link\s*\(\)/,/^}/ {
# Prepend parsing of -Wl,--as-nedded / -Wl,--no-as-needed
/-Wl,\*)/ {
s/.*/$parse_flags&/
}
# Place flags before the library list
# We are looking for the loop where -pthread is parsed from \$deplib
/case \$deplib in/ {
n
/-pthread/ {
s/.*/$iter_flags&/
}
}
}"
# Apply scripts
sed -i -e "$script_1" -e "$script_2" -e "$script_3" ltmain.sh
echo "DONE"
fi