-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·269 lines (248 loc) · 7.76 KB
/
configure
File metadata and controls
executable file
·269 lines (248 loc) · 7.76 KB
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
#!/usr/bin/env bash
PACKAGE_VERSION=0.3.0-alpha
function string#quote-arguments {
ret=()
local q=\' Q="'\''" special=$' \t\n\\`$!^'\"\'"#&|;()<>[*?]~{,}"
while (($#)); do
if [[ $1 != *["$special"]* ]]; then
ret+=("$1")
elif [[ $1 =~ ^([a-zA-Z0-9_]+=|--[a-zA-Z0-9][a-zA-Z0-9_-]*=)(.*)$ ]]; then
ret+=("${BASH_REMATCH[1]}'${BASH_REMATCH[2]//$q/$Q}'")
else
ret+=("'${1//$q/$Q}'")
fi
shift
done
}
function util/replace-if-dirty {
local src=$1.part dst=$1
if diff -q "$src" "$dst" >/dev/null; then
rm -f "$src"
else
mv "$src" "$dst"
fi
}
function check-lib {
local prefix=$1 name=$2
[[ -s $prefix/lib/lib$name.a || -s $prefix/lib/lib$name.so ]]
}
function readargs/option:with-jam1 {
if check-lib "$1" jam; then
libjam1_PREFIX=$1
else
echo "configure: jam1 not found at '$1'" >&2
[[ :$2: == *:opt:* ]] || flags=E$flags
return 1
fi
}
function readargs/option:with-jam2 {
if check-lib "$1" jam2; then
libjam2_PREFIX=$1
else
echo "configure: jam2 not found at '$1'" >&2
[[ :$2: == *:opt:* ]] || flags=E$flags
return 1
fi
}
function readargs/option:with-pythia8 {
if check-lib "$1" pythia8; then
pythia8_PREFIX=$1
else
echo "configure: pythia8 not found at '$1'" >&2
[[ :$2: == *:opt:* ]] || flags=E$flags
return 1
fi
}
function readargs/option:help {
printf '%s\n' \
'usage: configure [OPTION|VAR=VAL]...' \
'' \
'OPTION' \
' --help print this help' \
' --config print the previous configure flags' \
'' \
' --with-jam1=JAM1_PREFIX_DIR' \
' specify the path of jam1 installation' \
' --with-jam2=JAM2_PREFIX_DIR' \
' specify the path of jam2 installation' \
' --with-pythia8=Pythia8_PREFIX_DIR' \
' specify the path of pythia8 installation' \
' --static-libjam1 statically link libjam1.a' \
' --static-libjam2 statically link libjam2.a' \
' --static-pythia8 statically link libpythia8.a' \
' --static statically link all the above libaries' \
''
}
function readargs/option:config {
if [[ -s config.mk ]]; then
sed -n 's/^configure := //p' config.mk
return 0
else
echo "./configure --config: configure has never been called." >&2
return 1
fi
}
## @fn readargs
## @var[out] flags
## @var[out] PREFIX
## @var[out] libjam1_PREFIX
function readargs {
opts=
flags=
libjam1_PREFIX=
libjam2_PREFIX=
pythia8_PREFIX=
PREFIX=~/.opt/idt
while (($#)); do
local arg=$1; shift
if [[ $flags != *R* ]]; then
if local rex='^[[:alnum:]_]+='; [[ $arg =~ $rex ]]; then
printf -v "${arg%%=*}" %s "${arg#*=}"
elif [[ $arg == -* ]]; then
case $arg in
(--help)
readargs/option:help
flags=H$flags ;;
(--config)
readargs/option:config
flags=H$flags ;;
(--prefix=*) PREFIX=${arg#*=} ;;
(--prefix) PREFIX=$1; shift ;;
(--with-jam1=*) readargs/option:with-jam1 "${arg#*=}" ;;
(--with-jam1) readargs/option:with-jam1 "$1"; shift ;;
(--with-jam2=*) readargs/option:with-jam2 "${arg#*=}" ;;
(--with-jam2) readargs/option:with-jam2 "$1"; shift ;;
(--with-pythia8=*) readargs/option:with-pythia8 "${arg#*=}" ;;
(--with-pythia8) readargs/option:with-pythia8 "$1"; shift ;;
(--static | --static-pythia8 | --static-jam[12]) opts=$opts:${arg#--} ;;
# old names of the option
(--with-jam=*) readargs/option:with-jam1 "${arg#*=}" ;;
(--with-jam) readargs/option:with-jam1 "$1"; shift ;;
(*)
echo "configure: unknown option '$arg'" >&2
flags=E$flags ;;
esac
else
echo "configure: unrecognized argument '$arg'" >&2
flags=E$flags
fi
fi
done
: "${PREFIX:-/usr}"
[[ $flags != *E* ]]
}
function main {
: "${CXX:=g++}"
local flags opts libjam1_PREFIX libjam2_PREFIX pythia8_PREFIX
readargs "$@" || return 1
[[ $flags == *H* ]] && return 0
# fall back to default locations
[[ $libjam1_PREFIX ]] ||
readargs/option:with-jam1 "$PREFIX" opt ||
readargs/option:with-jam1 ~/opt/jam/1.820 opt ||
readargs/option:with-jam1 ~/opt/jam-1.820 opt
[[ $libjam2_PREFIX ]] ||
readargs/option:with-jam2 "$PREFIX" opt ||
readargs/option:with-jam2 ~/.opt/jam/dev jam2 opt
[[ $pythia8_PREFIX ]] ||
readargs/option:with-pythia8 "$PREFIX" opt ||
readargs/option:with-pythia8 ~/.opt/pythia/8.315 opt
# determine caps
use_libjam1=
use_libjam2=
if [[ $libjam1_PREFIX ]]; then
use_libjam1=yes
libjam1_MXV=200000
fi
if [[ $libjam2_PREFIX && $pythia8_PREFIX ]]; then
use_libjam2=yes
elif [[ $libjam2_PREFIX ]]; then
printf 'note: libpythia-8.315 is required for the JAM2 support but not found.\n' >&2
fi
local ret; string#quote-arguments "$@"
local configure_command="./configure ${ret[*]}"
echo ---------------------------------------
{
echo '# -*- mode: makefile-gmake -*-'
echo
{
echo "configure := $configure_command"
echo "PREFIX := $PREFIX"
echo "CXX := $CXX"
echo "CPPFLAGS := $CPPFLAGS"
echo "CXXFLAGS := $CXXFLAGS"
echo "LDFLAGS := $LDFLAGS"
echo "LIBS := $LIBS"
echo "use_libjam1 := $use_libjam1"
echo "ifneq (\$(use_libjam1),)"
echo " libjam1_PREFIX := $libjam1_PREFIX"
if [[ ( :$opts: == *:static:* || :$opts: == *:static-jam1:* ) && -s $libjam1_PREFIX/lib/libjam.a ]]; then
echo " libjam1_LIBS := $libjam1_PREFIX/lib/libjam.a"
else
echo " libjam1_LIBS := -ljam"
fi
echo " libjam1_MXV := $libjam1_MXV"
echo "endif"
echo "use_libjam2 := $use_libjam2"
echo "ifneq (\$(use_libjam2),)"
echo " libjam2_PREFIX := $libjam2_PREFIX"
if [[ ( :$opts: == *:static:* || :$opts: == *:static-jam2:* ) && -s $libjam2_PREFIX/lib/libjam2.a ]]; then
echo " libjam2_LIBS := $libjam2_PREFIX/lib/libjam2.a"
else
echo " libjam2_LIBS := -ljam2"
fi
echo " pythia8_PREFIX := $pythia8_PREFIX"
if [[ ( :$opts: == *:static:* || :$opts: == *:static-pythia8:* ) && -s $pythia8_PREFIX/lib/libpythia8.a ]]; then
echo " pythia8_LIBS := $pythia8_PREFIX/lib/libpythia8.a"
else
echo " pythia8_LIBS := -lpythia8"
fi
echo "endif"
} | tee /dev/tty
} > config.mk #.part && util/replace-if-dirty config.mk
{
echo "#ifndef CONFIG_HPP"
echo "#define CONFIG_HPP"
echo "#define PACKAGE_VERSION \"$PACKAGE_VERSION\""
echo "#define PACKAGE_PREFIX \"$PREFIX\""
echo "#define PACKAGE_BUILD \"$PWD\""
if [[ $use_libjam1 ]]; then
echo "#define USE_LIBJAM1 1"
echo "#define CONFIG_JAM_MXV $libjam1_MXV"
else
echo "#undef USE_LIBJAM1"
fi
if [[ $use_libjam2 ]]; then
echo "#define USE_LIBJAM2 1"
echo "#define Pythia8_PREFIX \"$pythia8_PREFIX\""
else
echo "#undef USE_LIBJAM2"
fi
if [[ $use_libjam2 ]]; then
echo "#define DEFAULT_JAM_VERSION 2"
elif [[ $use_libjam1 ]]; then
echo "#define DEFAULT_JAM_VERSION 1"
else
echo "#define DEFAULT_JAM_VERSION 0"
fi
echo 'namespace idt {'
echo 'namespace runjam {'
echo ' extern const char* package_hash;'
echo '}'
echo '}'
echo "#endif"
} > config.hpp.part
util/replace-if-dirty config.hpp
{
echo '#include "config.hpp"'
echo 'namespace idt {'
echo 'namespace runjam {'
echo " const char* package_hash = \"$hash\";"
echo '}'
echo '}'
} > config.cpp.part
./mktool.sh update-commit-hash config.cpp.part
util/replace-if-dirty config.cpp
echo ---------------------------------------
}
main "$@"