configure: fix argument passing and --quiet argument
[vlock.git] / configure
blob8a0aaec6301cf3b85af42890c0397987d22bb2ec
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]
47 Some influential environment variables:
48 CC C compiler command
49 CFLAGS C compiler flags
50 LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
51 nonstandard directory <lib dir>
53 Use these variables to override the choices made by \`configure' or to help
54 it to find libraries and programs with nonstandard names/locations.
56 Report bugs to <frank-vlock@benkstein.net>.
57 EOT
60 set_variable() {
61 eval "$1"='"$2"'
64 enable_feature() {
65 case "$1" in
66 plugins)
67 ENABLE_PLUGINS="$2"
69 root-password)
70 ENABLE_ROOT_PASSWORD="$2"
72 pam|shadow)
73 if [ "$2" = "yes" ] ; then
74 if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then
75 fatal_error "pam and shadow authentication are mutually exclusive"
77 AUTH_METHOD="$1"
78 else
79 fatal_error "cannot disable authentication"
83 fatal_error "invalid feature name: $1"
85 esac
88 parse_arguments() {
89 local feature opt optarg
91 while [ $# -gt 0 ] ; do
92 if ! opt=`expr "x$1" : 'x\([^=]*\)=.*'` ; then
93 opt="$1"
96 if ! optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` ; then
97 optarg=""
100 case "$1" in
101 --disable-*)
102 feature=`expr "$1" : '--disable-\(.*\)'`
103 enable_feature "$feature" no
104 shift
106 --enable-*=no)
107 feature=`expr "$1" : '--enable-\(.*\)=no'`
108 enable_feature "$feature" no
109 shift
111 --enable-*=yes)
112 feature=`expr "$1" : '--enable-\(.*\)=yes'`
113 enable_feature "$feature" yes
114 shift
116 --enable-*)
117 feature=`expr "$1" : '--enable-\(.*\)'`
118 enable_feature "$feature" yes
119 shift
121 *=*)
122 shift
123 # unshift
124 set -- "$opt" "$optarg" "$@"
126 --prefix)
127 PREFIX="$2"
128 shift 2 || fatal_error "$1 argument missing"
130 --bindir)
131 BINDIR="$2"
132 shift 2 || fatal_error "$1 argument missing"
134 --sbindir)
135 SBINDIR="$2"
136 shift 2 || fatal_error "$1 argument missing"
138 --libdir)
139 LIBDIR="$2"
140 shift 2 || fatal_error "$1 argument missing"
142 --moduledir)
143 MODULEDIR="$2"
144 shift 2 || fatal_error "$1 argument missing"
146 --scriptdir)
147 SCRIPTDIR="$2"
148 shift 2 || fatal_error "$1 argument missing"
150 --mandir)
151 MANDIR="$2"
152 shift 2 || fatal_error "$1 argument missing"
154 [A-Z]*)
155 set_variable "$1" "$2"
156 shift 2 || fatal_error "$1 value missing"
158 --quiet)
159 verbose=0
160 shift
162 --help)
163 show_usage
164 exit
166 --*)
167 error "unrecognized option: $1"
168 echo >&2 "Try \`$0 --help' for more information."
169 exit 1
172 error "invalid argument: $1"
173 echo >&2 "Try \`$0 --help' for more information."
174 exit 1
176 esac
177 done
180 parse_environment() {
181 OS=`uname`
183 for make in make gmake ; do
184 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
185 MAKE="$make"
186 break
188 done
190 if [ -z "$MAKE" ] ; then
191 error "GNU make not found"
192 echo >&2 "Set MAKE variable to specify alternative."
193 exit 1
196 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
198 case "$OS" in
199 Linux)
200 PAM_LIBS='-ldl -lpam'
201 DL_LIB='-ldl'
202 CRYPT_LIB='-lcrypt'
203 DEFAULT_MODULES="all.so new.so nosysrq.so"
205 GNU/kFreeBSD)
206 PAM_LIBS='-ldl -lpam'
207 DL_LIB='-ldl'
208 CRYPT_LIB='-lcrypt'
209 DEFAULT_MODULES="all.so new.so"
211 FreeBSD)
212 PAM_LIBS='-lpam'
213 DL_LIB=''
214 CRYPT_LIB=''
215 DEFAULT_MODULES="all.so new.so"
217 esac
220 parse_config_mk() {
221 local tmpdir
223 tmpdir=`mktemp -d`
225 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '\
226 /^# makefile .from .config\.mk., line/ { p=1; next }
227 /^#/ { p=0; next }
228 p==1 && $1 != "MAKEFILE_LIST" && /^[[:alpha:]_]+ :?= .*/ { print }
231 while read line
233 variable_name=`expr "${line}" : '\([[:alpha:]_]\+\) :\?='`
234 if variable_value=`expr "${line}" : '[[:alpha:]_]\+ :\?= \(.*\)'` ; then
235 set_variable "$variable_name" "$variable_value"
236 else
237 set_variable "$variable_name" ""
239 done < "$tmpdir/config.mk"
241 rm -rf "$tmpdir"
244 parse_defaults() {
245 is_set PREFIX || PREFIX="/usr/local"
246 is_set BINDIR || BINDIR="\$(PREFIX)/bin"
247 is_set SBINDIR || SBINDIR="\$(PREFIX)/sbin"
248 is_set LIBDIR || LIBDIR="\$(PREFIX)/lib"
249 is_set MANDIR || MANDIR="\$(PREFIX)/share/man"
250 is_set SCRIPTDIR || SCRIPTDIR="\$(LIBDIR)/vlock/scripts"
251 is_set MODULEDIR || MODULEDIR="\$(LIBDIR)/vlock/modules"
253 is_set CC || CC=gcc
254 is_set CFLAGS || CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
255 is_set LD || LD=ld
256 is_set LDFLAGS || LDFLAGS=""
257 is_set AUTH_METHOD || AUTH_METHOD="pam"
258 is_set PLUGINS || PLUGINS="$DEFAULT_MODULES"
259 is_set ENABLE_ROOT_PASSWORD || ENABLE_ROOT_PASSWORD="yes"
260 is_set ENABLE_PLUGINS || ENABLE_PLUGINS="yes"
262 is_set VLOCK_GROUP || VLOCK_GROUP="vlock"
263 is_set VLOCK_MODULE_MODE || VLOCK_MODULE_MODE="0750"
265 is_set BOURNE_SHELL || BOURNE_SHELL="/bin/sh"
268 show_summary() {
269 cat <<EOF
270 vlock configuration
272 directories:
273 prefix: $PREFIX
274 bindir: $BINDIR
275 sbindir: $SBINDIR
276 libdir: $LIBDIR
277 mandir: $MANDIR
278 scriptdir: $SCRIPTDIR
279 moduledir: $MODULEDIR
281 features:
282 enable plugins: $ENABLE_PLUGINS
283 root-password: $ENABLE_ROOT_PASSWORD
284 auth-method: $AUTH_METHOD
285 plugins: $PLUGINS
287 build configuration:
289 operating system: $OS
290 gnu make: $MAKE
291 c compiler: $CC
292 compiler flags: $CFLAGS
293 pam libs: $PAM_LIBS
294 dl libs: $DL_LIB
295 crypt lib: $CRYPT_LIB
297 installation configuration:
298 root group: $ROOT_GROUP
299 vlock group: $VLOCK_GROUP
303 create_config_mk() {
304 cat > config.mk <<EOF
305 # automatically generated by $0 on $(date)
307 ### configuration options ###
309 # authentification method (pam or shadow)
310 AUTH_METHOD = ${AUTH_METHOD}
311 # also prompt for the root password in adition to the user's
312 ENABLE_ROOT_PASSWORD = ${ENABLE_ROOT_PASSWORD}
313 # enable plugins for vlock-main
314 ENABLE_PLUGINS = ${ENABLE_PLUGINS}
315 # which plugins should be build
316 MODULES = \$(filter %.so, ${PLUGINS})
317 # which scripts should be installed
318 SCRIPTS = \$(filter %.sh, ${PLUGINS})
320 # root's group
321 ROOT_GROUP = ${ROOT_GROUP}
323 # group to install vlock-main with
324 VLOCK_GROUP = ${VLOCK_GROUP}
325 # mode to install privileged plugins with
326 VLOCK_MODULE_MODE = ${VLOCK_MODULE_MODE}
328 ### paths ###
330 # installation prefix
331 PREFIX = ${PREFIX}
332 BINDIR = ${BINDIR}
333 SBINDIR = ${SBINDIR}
334 LIBDIR = ${LIBDIR}
335 MANDIR = ${MANDIR}
336 # installation root
337 DESTDIR =
338 # path where modules will be located
339 VLOCK_MODULE_DIR = ${VLOCK_MODULE_DIR}
340 # path where scripts will be located
341 VLOCK_SCRIPT_DIR = ${VLOCK_SCRIPT_DIR}
343 ### programs ###
345 # shell to run vlock.sh with (only bash is known to work)
346 BOURNE_SHELL = ${BOURNE_SHELL}
347 # C compiler
348 CC = gcc
349 # gnu install
350 INSTALL = install
351 # linker
352 LD = ld
353 # mkdir
354 MKDIR_P = mkdir -p
356 ### compiler and linker settings ###
358 # C compiler flags
359 CFLAGS = ${CFLAGS}
360 # linker flags
361 LDFLAGS = ${LDFLAGS}
362 # linker flags needed for dlopen and friends, default is system dependend
363 # DL_LIB = ${DL_LIB}
364 # linker flags needed for crypt
365 CRYPT_LIB = ${CRYPT_LIB}
366 # linker flags needed for pam
367 PAM_LIBS = ${PAM_LIBS}
371 main() {
372 verbose=1
374 parse_environment
375 parse_config_mk
376 parse_arguments "$@"
377 parse_defaults
379 if [ "$verbose" -ge 1 ] ; then
380 show_summary
383 create_config_mk
386 main "$@"