-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·339 lines (306 loc) · 10.6 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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/sh
#
# CONFIGURE, check requirements then set variables and create Makefiles
# Copyright (C) 2017 CEA/DAM
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
progpath=$0
prog=${progpath##*/}
# argument list
arglist="TCLSH prefix bindir libexecdir initdir datarootdir mandir docdir \
modulefilesdir setmanpath setbinpath setswitchml setdotmodulespath \
usecverdotmodulespath cverinitdir cverbindir cvermandir modulepath \
loadedmodules"
# flags to know if argument has been specified on command-line
defswitchml=1
defdotmodulespath=1
defcverdotmodulespath=1
# set argument default values
prefix=/usr/local/modules-tcl
setmanpath=y
setbinpath=y
setswitchml=y
setdotmodulespath=n
usecverdotmodulespath=n
cverinitdir=
cverbindir=
cvermandir=
loadedmodules=
# these args are initialized here but as they depend on other argument value
# they will get their default value later (after command-line parse)
bindir=
libexecdir=
initdir=
datarootdir=
mandir=
docdir=
modulefilesdir=
modulepath=
# print message on stderr then exit
echo_error() {
echo -e "ERROR: $1" >&2
exit 1
}
# print message on stderr then exit
echo_warning() {
echo -e "WARNING: $1"
}
# print usage message
echo_usage() {
echo "Usage: $progpath [OPTION]...
Check requirements then set variables and create Makefiles.
Defaults for the options are specified in square brackets.
Configuration:
-h, --help display this help and exit
Installation directories:
--prefix=PREFIX install files in PREFIX [$prefix]
By default, \`make install' will install all the files in
\`$prefix/bin', \`$prefix/libexec', etc. You
can specify an installation prefix other than \`$prefix'
using \`--prefix', for instance \`--prefix=\$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [PREFIX/bin]
--libexecdir=DIR program executables [PREFIX/libexec]
--initdir=DIR environment initialization scripts [PREFIX/init]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc]
--modulefilesdir=DIR system modulefiles [PREFIX/modulefiles]
Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-set-manpath add mandir to MANPATH in init scripts [yes]
--enable-set-binpath add bindir to PATH in init scripts [yes]
--enable-set-switchml define switchml in init scripts (requires
cver-initdir to be defined) [yes]
--enable-dotmodulespath configure modules path in .modulespath file rather
than modulerc file [no]
--enable-use-cver-dotmodulespath
bind to the .modulespath configuration file of the
installed Modules C version (requires cver-initdir
to be defined and superseeds dotmodulespath) [no]
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-cver-initdir=DIR directory containing Modules C version init
scripts, which is a required information to enable
the \`switchml' and \`use-cver-dotmodulespath'
features []
--with-cver-bindir=DIR directory containing Modules C version binaries,
which is an optional information when enabling the
\`switchml' feature []
--with-cver-mandir=DIR directory containing Modules C version man pages,
which is an optional information when enabling the
\`switchml' feature []
--with-modulepath=PATHLIST
default modulepaths to set in default configuration
file to be enabled (each path in PATHLIST should
be separated by \`:') [PREFIX/modulefiles]
--with-loadedmodules=MODLIST
default modulefiles to set in default configuration
file to be loaded (each modulefile name in MODLIST
should be separated by \`:') []
Depending on the above configuration options the files are approximately
placed in the following directory structure:
PREFIX/
bin/
init/
libexec/
share/
doc/
man/
man1/
man4/
modulefiles/"
}
# check requirement availability
check_requirement() {
typeset req=$1
typeset optmesg=$2
typeset cmdenv=$3
echo -n "checking for ${req}... "
if [ -n "$cmdenv" ]; then
cmdsearch="$cmdenv command -v $req"
else
cmdsearch="command -v $req"
fi
reqpath=$(eval $cmdsearch)
if [ -n "$reqpath" ]; then
echo $reqpath
else
echo "not found"
if [ -z "$optmesg" ]; then
echo_error "$req could not be found"
else
echo_warning "$optmesg"
fi
fi
}
# parse optional argument to find if feature is enabled or disabled
get_feature_value() {
typeset val="${1#*=}"
if [ "${1//--enable/}" != "$1" ]; then
if [ "$val" = 'no' ]; then
echo 'n'
else
echo 'y'
fi
else
echo 'n'
fi
}
# parse optional argument to find package is set or disabled
get_package_value() {
typeset val="${1#*=}"
if [ "${1//--with/}" != "$1" ]; then
if [ "$val" = 'no' ]; then
echo ''
else
echo "$val"
fi
else
echo ''
fi
}
# parse arguments
for arg in "$@"; do
case "$arg" in
--prefix=*)
prefix="${arg#*=}" ;;
--bindir=*)
bindir="${arg#*=}" ;;
--libexecdir=*)
libexecdir="${arg#*=}" ;;
--initdir=*)
initdir="${arg#*=}" ;;
--datarootdir=*)
datarootdir="${arg#*=}" ;;
--mandir=*)
mandir="${arg#*=}" ;;
--docdir=*)
docdir="${arg#*=}" ;;
--modulefilesdir=*)
modulefilesdir="${arg#*=}" ;;
--enable-set-manpath*|--disable-set-manpath)
setmanpath=$(get_feature_value "$arg") ;;
--enable-set-binpath*|--disable-set-binpath)
setbinpath=$(get_feature_value "$arg") ;;
--enable-set-switchml*|--disable-set-switchml)
setswitchml=$(get_feature_value "$arg")
defswitchml=0 ;;
--enable-dotmodulespath*|--disable-dotmodulespath)
setdotmodulespath=$(get_feature_value "$arg")
defdotmodulespath=0 ;;
--enable-use-cver-dotmodulespath*|--disable-use-cver-dotmodulespath)
usecverdotmodulespath=$(get_feature_value "$arg")
defcverdotmodulespath=0 ;;
--with-cver-initdir=*|--without-cver-initdir)
cverinitdir=$(get_package_value "$arg") ;;
--with-cver-bindir=*|--without-cver-bindir)
cverbindir=$(get_package_value "$arg") ;;
--with-cver-mandir=*|--without-cver-mandir)
cvermandir=$(get_package_value "$arg") ;;
--with-modulepath=*|--without-modulepath)
modulepath=$(get_package_value "$arg") ;;
--with-loadedmodules=*|--without-loadedmodules)
loadedmodules=$(get_package_value "$arg") ;;
-h|--help)
echo_usage
exit 0
;;
*)
echo_error "Unrecognized option \`$arg'\nTry \
\`$progpath --help' for more information." ;;
esac
done
# set argument default values for those depending of other argument
[ -z "$bindir" ] && bindir=$prefix/bin
[ -z "$libexecdir" ] && libexecdir=$prefix/libexec
[ -z "$initdir" ] && initdir=$prefix/init
[ -z "$datarootdir" ] && datarootdir=$prefix/share
[ -z "$mandir" ] && mandir=$datarootdir/man
[ -z "$docdir" ] && docdir=$datarootdir/doc
[ -z "$modulefilesdir" ] && modulefilesdir=$prefix/modulefiles
[ -z "$modulepath" ] && modulepath=$modulefilesdir
# test requirements availability
check_requirement make
check_requirement perl
check_requirement grep
check_requirement cut
check_requirement pod2text
check_requirement pod2man
check_requirement pod2html "Install \`pod2html' if you want to build html \
documentation"
check_requirement runtest "Install \`dejagnu' if you want to run the \
testsuite"
# get tclsh location from standard PATHs or /usr/local/bin
check_requirement tclsh '' 'PATH=/usr/bin:/bin:/usr/local/bin'
TCLSH=$reqpath
# check feature requirements are met
# define switchml if we know where C version is installed
if [ "$setswitchml" = 'y' -a -z "$cverinitdir" ]; then
featmesg="Cannot enable \`switchml' as \`cver-initdir' not defined"
if [ $defswitchml -eq 0 ]; then
echo_error "$featmesg"
else
echo_warning "$featmesg"
setswitchml='n'
fi
fi
# same applies for using C version .modulespath config
if [ "$usecverdotmodulespath" = 'y' -a -z "$cverinitdir" ]; then
featmesg="Cannot enable \`use-cver-dotmodulespath' as \`cver-initdir' \
not defined"
if [ $defcverdotmodulespath -eq 0 ]; then
echo_error "$featmesg"
else
echo_warning "$featmesg"
usecverdotmodulespath='n'
fi
fi
if [ "$setdotmodulespath" = 'n' -a "$usecverdotmodulespath" = 'y' ]; then
featmesg="Need to enable \`dotmodulespath' as \`use-cver-dotmodulespath' \
enabled"
if [ $defdotmodulespath -eq 0 ]; then
echo_error "$featmesg"
else
echo_warning "$featmesg"
setdotmodulespath='y'
fi
fi
if [ "$setdotmodulespath" = 'y' -a -n "$loadedmodules" ]; then
featmesg="As \`setdotmodulespath' is enabled beware that \`loadedmodules' may be ignored by init scripts"
echo_warning "$featmesg"
fi
if [ -n "$loadedmodules" -a -z "$modulepath" ]; then
featmesg="A value is set for \`loadedmodules' whereas \`modulepath' is not defined"
echo_warning "$featmesg"
fi
# display configuration set
# and build Makefile translation expression
translation_regexp=''
for arg in ${arglist}; do
echo "$arg = ${!arg}"
translation_regexp+="s|\@${arg}\@|${!arg}|g; "
done
# generate Makefiles
echo "creating Makefile"
perl -pe "$translation_regexp" Makefile.in >Makefile
echo "creating doc/Makefile"
perl -pe "$translation_regexp" doc/Makefile.in >doc/Makefile
echo "creating init/Makefile"
perl -pe "$translation_regexp" init/Makefile.in >init/Makefile
exit 0