src/process.c: fix typo
[vlock.git] / configure
blobf1fecab612c1df4f683290dd669315b6bbc159a8
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 LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
56 nonstandard directory <lib dir>
57 VLOCK_GROUP group for restricted modules (default: vlock)
58 VLOCK_MODE mode for restricted modules (default: 0750)
60 Use these variables to override the choices made by \`configure' or to help
61 it to find libraries and programs with nonstandard names/locations.
63 Report bugs to <frank-vlock@benkstein.net>.
64 EOT
67 set_variable() {
68 eval "$1"='"$2"'
71 enable_feature() {
72 case "$1" in
73 plugins)
74 ENABLE_PLUGINS="$2"
76 root-password)
77 ENABLE_ROOT_PASSWORD="$2"
79 pam|shadow)
80 if [ "$2" = "yes" ] ; then
81 if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then
82 fatal_error "pam and shadow authentication are mutually exclusive"
84 AUTH_METHOD="$1"
85 else
86 fatal_error "cannot disable authentication"
89 debug)
90 if [ "$2" = "yes" ] ; then
91 CFLAGS="${DEBUG_CFLAGS}"
92 else
93 CFLAGS="${DEFAULT_CFLAGS}"
97 fatal_error "invalid feature name: $1"
99 esac
102 parse_arguments() {
103 local feature opt optarg
105 while [ $# -gt 0 ] ; do
106 if ! opt=`expr "x$1" : 'x\([^=]*\)=.*'` ; then
107 opt="$1"
110 if ! optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` ; then
111 optarg=""
114 case "$1" in
115 --disable-*)
116 feature=`expr "x$1" : 'x--disable-\(.*\)'`
117 enable_feature "$feature" no
118 shift
120 --enable-*=no)
121 feature=`expr "x$1" : 'x--enable-\(.*\)=no'`
122 enable_feature "$feature" no
123 shift
125 --enable-*=yes)
126 feature=`expr "x$1" : 'x--enable-\(.*\)=yes'`
127 enable_feature "$feature" yes
128 shift
130 --enable-*)
131 feature=`expr "x$1" : 'x--enable-\(.*\)'`
132 enable_feature "$feature" yes
133 shift
135 *=*)
136 shift
137 # unshift
138 set -- "$opt" "$optarg" "$@"
140 --prefix)
141 PREFIX="$2"
142 shift 2 || fatal_error "$1 argument missing"
144 --bindir)
145 BINDIR="$2"
146 shift 2 || fatal_error "$1 argument missing"
148 --sbindir)
149 SBINDIR="$2"
150 shift 2 || fatal_error "$1 argument missing"
152 --libdir)
153 LIBDIR="$2"
154 shift 2 || fatal_error "$1 argument missing"
156 --moduledir)
157 MODULEDIR="$2"
158 shift 2 || fatal_error "$1 argument missing"
160 --scriptdir)
161 SCRIPTDIR="$2"
162 shift 2 || fatal_error "$1 argument missing"
164 --mandir)
165 MANDIR="$2"
166 shift 2 || fatal_error "$1 argument missing"
168 --with-modules)
169 MODULES="$2"
170 shift 2 || fatal_error "$1 argument missing"
172 --with-scripts)
173 SCRIPTS="$2"
174 shift 2 || fatal_error "$1 argument missing"
176 [A-Z]*)
177 set_variable "$1" "$2"
178 shift 2 || fatal_error "$1 value missing"
180 --quiet)
181 verbose=0
182 shift
184 --help)
185 show_usage
186 exit
188 --*)
189 error "unrecognized option: $1"
190 echo >&2 "Try \`$0 --help' for more information."
191 exit 1
194 error "invalid argument: $1"
195 echo >&2 "Try \`$0 --help' for more information."
196 exit 1
198 esac
199 done
202 set_defaults() {
203 # architecture independent defaults
204 PREFIX="/usr/local"
205 BINDIR="\$(PREFIX)/bin"
206 SBINDIR="\$(PREFIX)/sbin"
207 LIBDIR="\$(PREFIX)/lib"
208 MANDIR="\$(PREFIX)/share/man"
209 SCRIPTDIR="\$(LIBDIR)/vlock/scripts"
210 MODULEDIR="\$(LIBDIR)/vlock/modules"
212 CC=gcc
213 DEFAULT_CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
214 DEBUG_CFLAGS="-O0 -g -Wall -W -pedantic -std=gnu99"
215 CFLAGS="${DEFAULT_CFLAGS}"
216 LD=ld
217 LDFLAGS=""
218 AUTH_METHOD="pam"
219 ENABLE_ROOT_PASSWORD="yes"
220 ENABLE_PLUGINS="yes"
221 SCRIPTS=""
223 VLOCK_GROUP="vlock"
224 VLOCK_MODULE_MODE="0750"
226 BOURNE_SHELL="/bin/sh"
228 # architecture dependent defaults
229 OS=`uname`
231 for make in make gmake ; do
232 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
233 MAKE="$make"
234 break
236 done
238 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
240 case "$OS" in
241 Linux)
242 PAM_LIBS='-ldl -lpam'
243 DL_LIB='-ldl'
244 CRYPT_LIB='-lcrypt'
245 MODULES="all.so new.so nosysrq.so"
247 GNU/kFreeBSD)
248 PAM_LIBS='-ldl -lpam'
249 DL_LIB='-ldl'
250 CRYPT_LIB='-lcrypt'
251 MODULES="all.so new.so"
253 FreeBSD)
254 PAM_LIBS='-lpam'
255 DL_LIB=''
256 CRYPT_LIB=''
257 MODULES="all.so new.so"
259 esac
262 parse_config_mk() {
263 local tmpdir
265 if [ -z "$MAKE" ] ; then
266 error "GNU make not found"
267 echo >&2 "Set MAKE environment variable to specify alternative."
268 exit 1
271 tmpdir=`mktemp -d -t vlock-configure.XXXXXX`
273 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '
274 /^# makefile .from .config\.mk., line/ { p=1; next }
275 /^#/ { p=0; next }
276 p==1 && $1 != "MAKEFILE_LIST" && /^[[:alpha:]_]+ :?= .*/ { print }
279 while read line
281 variable_name=`expr "x${line}" : 'x\([[[:alpha:]_]\{1,\}\) :\{0,1\}='`
282 if variable_value=`expr "x${line}" : 'x[[:alpha:]_]\{1,\} :\{0,1\}= \(.*\)'` ; then
283 set_variable "$variable_name" "$variable_value"
284 else
285 set_variable "$variable_name" ""
287 done < "$tmpdir/config.mk"
289 rm -rf "$tmpdir"
292 show_summary() {
293 cat <<EOF
294 vlock configuration
296 directories:
297 prefix: $PREFIX
298 bindir: $BINDIR
299 sbindir: $SBINDIR
300 libdir: $LIBDIR
301 mandir: $MANDIR
302 scriptdir: $SCRIPTDIR
303 moduledir: $MODULEDIR
305 features:
306 enable plugins: $ENABLE_PLUGINS
307 root-password: $ENABLE_ROOT_PASSWORD
308 auth-method: $AUTH_METHOD
309 modules: $MODULES
310 scripts: $SCRIPTS
312 build configuration:
314 operating system: $OS
315 gnu make: $MAKE
316 c compiler: $CC
317 compiler flags: $CFLAGS
318 pam libs: $PAM_LIBS
319 dl libs: $DL_LIB
320 crypt lib: $CRYPT_LIB
322 installation configuration:
323 root group: $ROOT_GROUP
324 vlock group: $VLOCK_GROUP
328 create_config_mk() {
329 cat > config.mk <<EOF
330 # automatically generated by $0 on $(date)
332 ### configuration options ###
334 # authentification method (pam or shadow)
335 AUTH_METHOD = ${AUTH_METHOD}
336 # also prompt for the root password in adition to the user's
337 ENABLE_ROOT_PASSWORD = ${ENABLE_ROOT_PASSWORD}
338 # enable plugins for vlock-main
339 ENABLE_PLUGINS = ${ENABLE_PLUGINS}
340 # which plugins should be build
341 MODULES = ${MODULES}
342 # which scripts should be installed
343 SCRIPTS = ${SCRIPTS}
345 # root's group
346 ROOT_GROUP = ${ROOT_GROUP}
348 # group for privileged plugins
349 VLOCK_GROUP = ${VLOCK_GROUP}
350 # mode for privileged plugins
351 VLOCK_MODULE_MODE = ${VLOCK_MODULE_MODE}
353 ### paths ###
355 # installation prefix
356 PREFIX = ${PREFIX}
357 BINDIR = ${BINDIR}
358 SBINDIR = ${SBINDIR}
359 LIBDIR = ${LIBDIR}
360 MANDIR = ${MANDIR}
361 # installation root
362 DESTDIR =
363 # path where modules will be located
364 MODULEDIR = ${MODULEDIR}
365 # path where scripts will be located
366 SCRIPTDIR = ${SCRIPTDIR}
368 ### programs ###
370 # shell to run vlock.sh with (only bash is known to work)
371 BOURNE_SHELL = ${BOURNE_SHELL}
372 # C compiler
373 CC = ${CC}
374 # linker
375 LD = ${LD}
376 # mkdir
377 MKDIR_P = mkdir -p
378 # install
379 INSTALL = install
381 ### compiler and linker settings ###
383 # C compiler flags
384 CFLAGS = ${CFLAGS}
385 # linker flags
386 LDFLAGS = ${LDFLAGS}
387 # linker flags needed for dlopen and friends
388 DL_LIB = ${DL_LIB}
389 # linker flags needed for crypt
390 CRYPT_LIB = ${CRYPT_LIB}
391 # linker flags needed for pam
392 PAM_LIBS = ${PAM_LIBS}
396 main() {
397 verbose=1
399 set_defaults
400 parse_config_mk
401 parse_arguments "$@"
403 if [ "$verbose" -ge 1 ] ; then
404 show_summary
407 create_config_mk
410 main "$@"