document the change in prompt timeout handling
[vlock.git] / configure
blob5c7a185163e9c638dc6e1136bcf5fdbee218d421
1 #!/bin/sh
3 set -e
5 error() {
6 echo >&2 "$0: error: $@"
9 fatal_error() {
10 error "$@"
11 exit 1
14 is_set() {
15 ( eval [ "\"\${$1+set}\"" = "set" ] )
18 show_usage() {
19 cat <<EOT
20 Usage: $0 [OPTION]... [VAR=VALUE]...
22 This script creates necessary configuration files to build/install.
24 To assign environment variables (e.g., CC, CFLAGS...), specify them as
25 VAR=VALUE. See below for descriptions of some of the useful variables.
27 Defaults for the options are specified in brackets.
29 Main options:
30 -h, --help display this help and exit
31 --prefix=[path] base path [/usr/local]
32 --bindir=DIR user executables [PREFIX/bin]
33 --sbindir=DIR system admin executables [PREFIX/sbin]
34 --libdir=DIR object code libraries [PREFIX/lib]
35 --scriptdir=DIR script type plugins [LIBDIR/vlock/scripts]
36 --moduledir=DIR module type plugins [LIBDIR/vlock/modules]
37 --mandir=DIR man documentation [PREFIX/share/man]
39 Optional Features:
40 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
41 --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
42 --enable-plugins enable plugin support [enabled]
43 --enable-pam enable PAM authentication [enabled]
44 --enable-shadow enable shadow authentication [disabled]
45 --enable-root-password enable unlogging with root password [enabled]
46 --enable-debug enable debugging
48 Additional configuration:
49 --with-scripts=SCRIPTS enable the named scripts []
50 --with-modules=MODULES enable the named modules [<architecture depedent>]
52 Some influential environment variables:
53 CC C compiler command
54 CFLAGS C compiler flags
55 EXTRA_CFLAGS additional C compiler flags (extends default)
56 LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
57 nonstandard directory <lib dir>
58 EXTRA_LDFLAGS additional linker flags (extends default)
59 VLOCK_GROUP group for restricted modules (default: vlock)
60 VLOCK_MODE mode for restricted modules (default: 0750)
62 Use these variables to override the choices made by \`configure' or to help
63 it to find libraries and programs with nonstandard names/locations.
65 Report bugs to <frank-vlock@benkstein.net>.
66 EOT
69 set_variable() {
70 eval "$1"='"$2"'
73 enable_feature() {
74 case "$1" in
75 plugins)
76 ENABLE_PLUGINS="$2"
78 root-password)
79 ENABLE_ROOT_PASSWORD="$2"
81 pam|shadow)
82 if [ "$2" = "yes" ] ; then
83 if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then
84 fatal_error "pam and shadow authentication are mutually exclusive"
86 AUTH_METHOD="$1"
87 else
88 fatal_error "cannot disable authentication"
91 debug)
92 if [ "$2" = "yes" ] ; then
93 CFLAGS="${DEBUG_CFLAGS} ${GLIB_CFLAGS}"
94 else
95 CFLAGS="${DEFAULT_CFLAGS} ${GLIB_CFLAGS}"
99 fatal_error "invalid feature name: $1"
101 esac
104 parse_arguments() {
105 local feature opt optarg
107 while [ $# -gt 0 ] ; do
108 if ! opt=`expr "x$1" : 'x\([^=]*\)=.*'` ; then
109 opt="$1"
112 if ! optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` ; then
113 optarg=""
116 case "$1" in
117 --disable-*)
118 feature=`expr "x$1" : 'x--disable-\(.*\)'`
119 enable_feature "$feature" no
120 shift
122 --enable-*=no)
123 feature=`expr "x$1" : 'x--enable-\(.*\)=no'`
124 enable_feature "$feature" no
125 shift
127 --enable-*=yes)
128 feature=`expr "x$1" : 'x--enable-\(.*\)=yes'`
129 enable_feature "$feature" yes
130 shift
132 --enable-*)
133 feature=`expr "x$1" : 'x--enable-\(.*\)'`
134 enable_feature "$feature" yes
135 shift
137 *=*)
138 shift
139 # unshift
140 set -- "$opt" "$optarg" "$@"
142 --prefix)
143 PREFIX="$2"
144 shift 2 || fatal_error "$1 argument missing"
146 --bindir)
147 BINDIR="$2"
148 shift 2 || fatal_error "$1 argument missing"
150 --sbindir)
151 SBINDIR="$2"
152 shift 2 || fatal_error "$1 argument missing"
154 --libdir)
155 LIBDIR="$2"
156 shift 2 || fatal_error "$1 argument missing"
158 --moduledir)
159 MODULEDIR="$2"
160 shift 2 || fatal_error "$1 argument missing"
162 --scriptdir)
163 SCRIPTDIR="$2"
164 shift 2 || fatal_error "$1 argument missing"
166 --mandir)
167 MANDIR="$2"
168 shift 2 || fatal_error "$1 argument missing"
170 --with-modules)
171 MODULES="$2"
172 shift 2 || fatal_error "$1 argument missing"
174 --with-scripts)
175 SCRIPTS="$2"
176 shift 2 || fatal_error "$1 argument missing"
178 EXTRA_CFLAGS)
179 CFLAGS="${CFLAGS} $2"
180 shift 2 || fatal_error "$1 value missing"
182 EXTRA_LDFLAGS)
183 LDFLAGS="${LDFLAGS} $2"
184 shift 2 || fatal_error "$1 value missing"
186 [A-Z]*)
187 set_variable "$1" "$2"
188 shift 2 || fatal_error "$1 value missing"
190 --quiet)
191 verbose=0
192 shift
194 --help|-h)
195 show_usage
196 exit
199 error "unrecognized option: $1"
200 echo >&2 "Try \`$0 --help' for more information."
201 exit 1
204 error "invalid argument: $1"
205 echo >&2 "Try \`$0 --help' for more information."
206 exit 1
208 esac
209 done
212 set_defaults() {
213 # architecture independent defaults
214 PREFIX="/usr/local"
215 BINDIR="\$(PREFIX)/bin"
216 SBINDIR="\$(PREFIX)/sbin"
217 LIBDIR="\$(PREFIX)/lib"
218 MANDIR="\$(PREFIX)/share/man"
219 SCRIPTDIR="\$(LIBDIR)/vlock/scripts"
220 MODULEDIR="\$(LIBDIR)/vlock/modules"
222 # glib
223 GLIB_CFLAGS="$(pkg-config --cflags glib-2.0 gobject-2.0)"
224 GLIB_LIBS="$(pkg-config --libs glib-2.0 gobject-2.0)"
226 CC=gcc
227 DEFAULT_CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
228 DEBUG_CFLAGS="-O0 -g -Wall -W -pedantic -std=gnu99"
229 CFLAGS="${DEFAULT_CFLAGS} ${GLIB_CFLAGS}"
230 LD=ld
231 LDFLAGS=""
232 LDLIBS="${GLIB_LIBS}"
233 AUTH_METHOD="pam"
234 ENABLE_ROOT_PASSWORD="yes"
235 ENABLE_PLUGINS="yes"
236 SCRIPTS=""
238 VLOCK_GROUP="vlock"
239 VLOCK_MODULE_MODE="0750"
241 BOURNE_SHELL="/bin/sh"
243 # architecture dependent defaults
244 OS=`uname`
246 for make in make gmake ; do
247 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
248 MAKE="$make"
249 break
251 done
253 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
255 case "$OS" in
256 Linux)
257 PAM_LIBS='-ldl -lpam'
258 DL_LIB='-ldl'
259 CRYPT_LIB='-lcrypt'
260 MODULES="all.so new.so nosysrq.so"
262 GNU/kFreeBSD)
263 PAM_LIBS='-ldl -lpam'
264 DL_LIB='-ldl'
265 CRYPT_LIB='-lcrypt'
266 MODULES="all.so new.so"
268 FreeBSD)
269 PAM_LIBS='-lpam'
270 DL_LIB=''
271 CRYPT_LIB=''
272 MODULES="all.so new.so"
274 esac
277 parse_config_mk() {
278 local tmpdir
280 if [ -z "$MAKE" ] ; then
281 error "GNU make not found"
282 echo >&2 "Set MAKE environment variable to specify alternative."
283 exit 1
286 tmpdir=`mktemp -d -t vlock-configure.XXXXXX`
288 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '
289 /^# makefile/ { p=1; next }
290 /^#/ { p=0; next }
291 p==1 && $1 != "MAKEFILE_LIST" && /^[A-Za-z_]+ :?= .*/ { print }
294 while read line
296 variable_name=`expr "x${line}" : 'x\([[[:alpha:]_]\{1,\}\) :\{0,1\}='`
297 if variable_value=`expr "x${line}" : 'x[[:alpha:]_]\{1,\} :\{0,1\}= \(.*\)'` ; then
298 set_variable "$variable_name" "$variable_value"
299 else
300 set_variable "$variable_name" ""
302 done < "$tmpdir/config.mk"
304 rm -rf "$tmpdir"
307 show_summary() {
308 cat <<EOF
309 vlock configuration
311 directories:
312 prefix: $PREFIX
313 bindir: $BINDIR
314 sbindir: $SBINDIR
315 libdir: $LIBDIR
316 mandir: $MANDIR
317 scriptdir: $SCRIPTDIR
318 moduledir: $MODULEDIR
320 features:
321 enable plugins: $ENABLE_PLUGINS
322 root-password: $ENABLE_ROOT_PASSWORD
323 auth-method: $AUTH_METHOD
324 modules: $MODULES
325 scripts: $SCRIPTS
327 build configuration:
329 operating system: $OS
330 gnu make: $MAKE
331 c compiler: $CC
332 compiler flags: $CFLAGS
333 libraries: $LDLIBS
334 linker flags: $LDFLAGS
335 pam libs: $PAM_LIBS
336 dl libs: $DL_LIB
337 crypt lib: $CRYPT_LIB
339 installation configuration:
340 root group: $ROOT_GROUP
341 vlock group: $VLOCK_GROUP
345 create_config_mk() {
346 cat > config.mk <<EOF
347 # automatically generated by $0 on $(date)
349 ### configuration options ###
351 # authentification method (pam or shadow)
352 AUTH_METHOD = ${AUTH_METHOD}
353 # also prompt for the root password in adition to the user's
354 ENABLE_ROOT_PASSWORD = ${ENABLE_ROOT_PASSWORD}
355 # enable plugins for vlock-main
356 ENABLE_PLUGINS = ${ENABLE_PLUGINS}
357 # which plugins should be build
358 MODULES = ${MODULES}
359 # which scripts should be installed
360 SCRIPTS = ${SCRIPTS}
362 # root's group
363 ROOT_GROUP = ${ROOT_GROUP}
365 # group for privileged plugins
366 VLOCK_GROUP = ${VLOCK_GROUP}
367 # mode for privileged plugins
368 VLOCK_MODULE_MODE = ${VLOCK_MODULE_MODE}
370 ### paths ###
372 # installation prefix
373 PREFIX = ${PREFIX}
374 BINDIR = ${BINDIR}
375 SBINDIR = ${SBINDIR}
376 LIBDIR = ${LIBDIR}
377 MANDIR = ${MANDIR}
378 # installation root
379 DESTDIR =
380 # path where modules will be located
381 MODULEDIR = ${MODULEDIR}
382 # path where scripts will be located
383 SCRIPTDIR = ${SCRIPTDIR}
385 ### programs ###
387 # shell to run vlock.sh with (only bash is known to work)
388 BOURNE_SHELL = ${BOURNE_SHELL}
389 # C compiler
390 CC = ${CC}
391 # linker
392 LD = ${LD}
393 # mkdir
394 MKDIR_P = mkdir -p
395 # install
396 INSTALL = install
398 ### compiler and linker settings ###
400 # C compiler flags
401 CFLAGS = ${CFLAGS}
402 # libraries
403 LDLIBS = ${LDLIBS}
404 # linker flags
405 LDFLAGS = ${LDFLAGS}
406 # linker flags needed for dlopen and friends
407 DL_LIB = ${DL_LIB}
408 # linker flags needed for crypt
409 CRYPT_LIB = ${CRYPT_LIB}
410 # linker flags needed for pam
411 PAM_LIBS = ${PAM_LIBS}
415 main() {
416 verbose=1
418 set_defaults
419 parse_config_mk
420 parse_arguments "$@"
422 if [ "$verbose" -ge 1 ] ; then
423 show_summary
426 create_config_mk
429 main "$@"