forked from andrewprock/ustl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·197 lines (170 loc) · 5.34 KB
/
configure
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
#! /bin/sh
######################################################################
# Project Configuration #
######################################################################
pkg_name="ustl"
pkg_verstr="v3.0"
pkg_bugreport="Mike Sharov <[email protected]>"
# Files that get created by this script
files="Config.mk config.h $pkg_name.pc"
# Package options
components='
{
name=[with-debug]
desc=[ Compile for debugging]
seds=[s/^#\(debug\)/\1/]
}{
name=[with-native]
desc=[ Use -march=native]
seds=[s/ -std=c/ -march=native -std=c/]
}{
name=[with-bstrxept]
desc=[enable runtime bounds checking on binary streams]
seds=[s/#undef \(WANT_BSTREAM_EXCEPTIONS\)/#define \1 1/]
}{
name=[with-forced-inline]
desc=[make inline keyword mean always inline, not just a hint]
seds=[s/#undef \(WANT_ALWAYS_INLINE\)/#define \1 1/]
}';
# First pair is used if nothing matches
progs="CC=gcc CC=clang CXX=g++ CXX=clang++ AR=ar RANLIB=ranlib RANLIB=touch INSTALL=install"
# Automatic vars
if [ -d .git ]; then
pkg_vverstr=$(git describe --always)
[ -z "$pkg_vverstr" ] || pkg_verstr=$pkg_vverstr
fi
pkg_major=$(expr "$pkg_verstr" : 'v\([0-9]*\)')
pkg_minor=$(expr "$pkg_verstr" : 'v[0-9]*\.\([0-9]*\)')
pkg_string="$pkg_name $pkg_verstr"
# Miscellaneous substitutions
custsubs="s/@pkg_name@/$pkg_name/g
s/@pkg_version@/0x$pkg_major${pkg_minor}0/g
s/@pkg_verstr@/$pkg_verstr/g
s/@pkg_string@/$pkg_string/g
s/@pkg_uname@/$(echo $pkg_name|tr a-z A-Z)/g
s/@pkg_bugreport@/$pkg_bugreport/g
s/@pkg_major@/$pkg_major/g
s/@pkg_minor@/$pkg_minor/g"
######################################################################
#### The rest of the file is configuration code. Leave it alone. #####
######################################################################
die() { rm -f config.sed; exit; }
sub() { printf "%s\n" "$1">>config.sed; }
escpath() { echo "$@" | sed 's/\//\\\//g'; }
#### Printing helper functions #######################################
print_components() {
local cc name desc
cc=$components
echo "Options:"
while [ ! -z "$cc" ]; do
name=$(expr "$cc" : '[^}]*name=\[\([^]]*\)\]')
desc=$(expr "$cc" : '[^}]*desc=\[\([^]]*\)\]')
echo " --$name $desc"
cc=$(expr "$cc" : '[^}]*}\(.*\)')
done
echo
}
print_help() {
echo "This program configures $pkg_string build system.
Usage: configure [option]...
Configuration:
-h, --help display this help and exit
-V, --version display version information and exit
Installation directories:
--prefix=dir architecture-independent root [/usr/local]
--libdir=dir object code libraries [prefix/lib]
--includedir=dir C header files [prefix/include]
--pkgconfigdir=dir pkg-config configuration [libdir/pkgconfig]
--builddir=dir location for compiled objects [\$TMPDIR/make]
"
print_components
echo "Report bugs to $pkg_bugreport"
}
print_version() {
echo "$pkg_name $pkg_verstr configure"
}
sub_var() {
local esc2
esc2=$(escpath $2)
eval ac_var_$1='$esc2';
sub "s/@$1@/$esc2/g"
}
sub_comp() {
local cc name seds
cc=$components
while [ -n "$cc" ]; do
name=$(expr "$cc" : '[^}]*name=\[\([^]]*\)\]')
seds=$(expr "$cc" : '[^}]*seds=\[\([^]]*\)\]')
[ "$name" = "$1" ] && sub "$seds"
cc=$(expr "$cc" : '[^}]*}\(.*\)')
done
}
for i in "$@"; do
case $i in
--) break;;
--version |-V) print_version && die;;
--help |-h |-?) print_help && die;;
--*=*) sub_var $(expr $i : '--\([^=]*\)=') "$(expr $i : '[^=]*=\(.*\)')";;
--*) sub_comp "$(expr $i : '--\(.*\)')";;
*) echo "Error: unrecognized option \"$i\"" && die;;
esac
done
#### Set directory prefixes ##########################################
sub "s/@prefix@/${ac_var_prefix:=\/usr\/local}/g
s/@includedir@/${ac_var_includedir:=\$\{prefix\}\/include}/g
s/@libdir@/${ac_var_libdir:=\$\{prefix\}\/lib}/g
s/@pkgconfigdir@/${ac_var_pkgconfigdir:=\$\{libdir\}\/pkgconfig}/g
s/@TMPDIR@/$(escpath ${TMPDIR:-/tmp})/g
s/@builddir@/\$\{TMPDIR\}\/make/g"
#### Find headers, libs, programs, and subs ##########################
# Determine host OS
SYSNAME=$(uname|tr A-Z a-z)
case "$SYSNAME" in
*solaris*| *sun*) SYSNAME="sun";;
*darwin*| *osx*) SYSNAME="mac";;
*bsd*) SYSNAME="bsd";;
*) SYSNAME="linux";;
esac
# Programs found using which
CC=
for i in $progs; do
pname=$(expr "$i" : '\([^=]*\)')
pcall=$(expr "$i" : '[^=]*=\([^=]*\)')
ppath=$(escpath $(eval echo \$\{$pname\}))
# First check if an environment variable is set
[ -n "$ppath" ] && sub "s/@$pname@/$ppath/g"
# Check if the program exists
ppath=$(which $pcall 2>/dev/null)
if [ -n "$ppath" ] && [ -x "$ppath" ]; then
sub "s/@$pname@/$pcall/g";
if [ -z "$CC" ] && [ "$pname" = "CC" ]; then
CC=$pcall;
fi
fi
done
if [ "$CC" = "clang" ]; then
if [ "$SYSNAME" = "mac" ]; then
sub "s/ -lsupc++/ -lc++abi/g"
elif [ "$SYSNAME" != "linux" ]; then
sub "s/ -lsupc++/ -lcxxrt/g"
fi
fi
# If nothing found in first loop, set the first pair anyway
for i in $progs; do
pname=$(expr $i : '\([^=]*\)')
pcall=$(expr $i : '[^=]*=\([^=]*\)')
sub "s/@$pname@/$pcall/g"
done
# Miscellaneous custom substitutions
sub "$custsubs"
#### Apply substitutions to all files ################################
for i in $files; do
sed -f config.sed $i.in > $i
done
touch config.status
echo "#!/bin/sh
$0 $@
$(tail -n+3 config.status)" > config.status.new
chmod u+x config.status.new
mv config.status.new config.status
die