move ensure_atexit back to vlock-main.c and simplify
[vlock.git] / configure
blob2a2ba27482fc0d3f486f4f97be903a0c93efd506
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 Additional configuration:
48 --with-scripts=SCRIPTS enable the named scripts []
49 --with-modules=MODULES enable the named modules [<architecture depedent>]
51 Some influential environment variables:
52 CC C compiler command
53 CFLAGS C compiler flags
54 LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
55 nonstandard directory <lib dir>
57 Use these variables to override the choices made by \`configure' or to help
58 it to find libraries and programs with nonstandard names/locations.
60 Report bugs to <frank-vlock@benkstein.net>.
61 EOT
64 set_variable() {
65 eval "$1"='"$2"'
68 enable_feature() {
69 case "$1" in
70 plugins)
71 ENABLE_PLUGINS="$2"
73 root-password)
74 ENABLE_ROOT_PASSWORD="$2"
76 pam|shadow)
77 if [ "$2" = "yes" ] ; then
78 if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then
79 fatal_error "pam and shadow authentication are mutually exclusive"
81 AUTH_METHOD="$1"
82 else
83 fatal_error "cannot disable authentication"
87 fatal_error "invalid feature name: $1"
89 esac
92 parse_arguments() {
93 local feature opt optarg
95 while [ $# -gt 0 ] ; do
96 if ! opt=`expr "x$1" : 'x\([^=]*\)=.*'` ; then
97 opt="$1"
100 if ! optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` ; then
101 optarg=""
104 case "$1" in
105 --disable-*)
106 feature=`expr "$1" : '--disable-\(.*\)'`
107 enable_feature "$feature" no
108 shift
110 --enable-*=no)
111 feature=`expr "$1" : '--enable-\(.*\)=no'`
112 enable_feature "$feature" no
113 shift
115 --enable-*=yes)
116 feature=`expr "$1" : '--enable-\(.*\)=yes'`
117 enable_feature "$feature" yes
118 shift
120 --enable-*)
121 feature=`expr "$1" : '--enable-\(.*\)'`
122 enable_feature "$feature" yes
123 shift
125 *=*)
126 shift
127 # unshift
128 set -- "$opt" "$optarg" "$@"
130 --prefix)
131 PREFIX="$2"
132 shift 2 || fatal_error "$1 argument missing"
134 --bindir)
135 BINDIR="$2"
136 shift 2 || fatal_error "$1 argument missing"
138 --sbindir)
139 SBINDIR="$2"
140 shift 2 || fatal_error "$1 argument missing"
142 --libdir)
143 LIBDIR="$2"
144 shift 2 || fatal_error "$1 argument missing"
146 --moduledir)
147 MODULEDIR="$2"
148 shift 2 || fatal_error "$1 argument missing"
150 --scriptdir)
151 SCRIPTDIR="$2"
152 shift 2 || fatal_error "$1 argument missing"
154 --mandir)
155 MANDIR="$2"
156 shift 2 || fatal_error "$1 argument missing"
158 --with-modules)
159 MODULES="$2"
160 shift 2 || fatal_error "$1 argument missing"
162 --with-scripts)
163 SCRIPTS="$2"
164 shift 2 || fatal_error "$1 argument missing"
166 [A-Z]*)
167 set_variable "$1" "$2"
168 shift 2 || fatal_error "$1 value missing"
170 --quiet)
171 verbose=0
172 shift
174 --help)
175 show_usage
176 exit
178 --*)
179 error "unrecognized option: $1"
180 echo >&2 "Try \`$0 --help' for more information."
181 exit 1
184 error "invalid argument: $1"
185 echo >&2 "Try \`$0 --help' for more information."
186 exit 1
188 esac
189 done
192 set_defaults() {
193 # architecture independent defaults
194 PREFIX="/usr/local"
195 BINDIR="\$(PREFIX)/bin"
196 SBINDIR="\$(PREFIX)/sbin"
197 LIBDIR="\$(PREFIX)/lib"
198 MANDIR="\$(PREFIX)/share/man"
199 SCRIPTDIR="\$(LIBDIR)/vlock/scripts"
200 MODULEDIR="\$(LIBDIR)/vlock/modules"
202 CC=gcc
203 CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
204 LD=ld
205 LDFLAGS=""
206 AUTH_METHOD="pam"
207 ENABLE_ROOT_PASSWORD="yes"
208 ENABLE_PLUGINS="yes"
209 SCRIPTS=""
211 VLOCK_GROUP="vlock"
212 VLOCK_MODULE_MODE="0750"
214 BOURNE_SHELL="/bin/sh"
216 # architecture dependent defaults
217 OS=`uname`
219 for make in make gmake ; do
220 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
221 MAKE="$make"
222 break
224 done
226 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
228 case "$OS" in
229 Linux)
230 PAM_LIBS='-ldl -lpam'
231 DL_LIB='-ldl'
232 CRYPT_LIB='-lcrypt'
233 MODULES="all.so new.so nosysrq.so"
235 GNU/kFreeBSD)
236 PAM_LIBS='-ldl -lpam'
237 DL_LIB='-ldl'
238 CRYPT_LIB='-lcrypt'
239 MODULES="all.so new.so"
241 FreeBSD)
242 PAM_LIBS='-lpam'
243 DL_LIB=''
244 CRYPT_LIB=''
245 DEFAULT_MODULES="all.so new.so"
247 esac
250 parse_config_mk() {
251 local tmpdir
253 if [ -z "$MAKE" ] ; then
254 error "GNU make not found"
255 echo >&2 "Set MAKE environment variable to specify alternative."
256 exit 1
259 tmpdir=`mktemp -d -t vlock-configure.XXXXXX`
261 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '
262 /^# makefile .from .config\.mk., line/ { p=1; next }
263 /^#/ { p=0; next }
264 p==1 && $1 != "MAKEFILE_LIST" && /^[[:alpha:]_]+ :?= .*/ { print }
267 while read line
269 variable_name=`expr "${line}" : '\([[[:alpha:]_]\{1,\}\) :\{0,1\}='`
270 if variable_value=`expr "${line}" : '[[:alpha:]_]\{1,\} :\{0,1\}= \(.*\)'` ; then
271 set_variable "$variable_name" "$variable_value"
272 else
273 set_variable "$variable_name" ""
275 done < "$tmpdir/config.mk"
277 rm -rf "$tmpdir"
280 show_summary() {
281 cat <<EOF
282 vlock configuration
284 directories:
285 prefix: $PREFIX
286 bindir: $BINDIR
287 sbindir: $SBINDIR
288 libdir: $LIBDIR
289 mandir: $MANDIR
290 scriptdir: $SCRIPTDIR
291 moduledir: $MODULEDIR
293 features:
294 enable plugins: $ENABLE_PLUGINS
295 root-password: $ENABLE_ROOT_PASSWORD
296 auth-method: $AUTH_METHOD
297 modules: $MODULES
298 scripts: $SCRIPTS
300 build configuration:
302 operating system: $OS
303 gnu make: $MAKE
304 c compiler: $CC
305 compiler flags: $CFLAGS
306 pam libs: $PAM_LIBS
307 dl libs: $DL_LIB
308 crypt lib: $CRYPT_LIB
310 installation configuration:
311 root group: $ROOT_GROUP
312 vlock group: $VLOCK_GROUP
316 create_config_mk() {
317 cat > config.mk <<EOF
318 # automatically generated by $0 on $(date)
320 ### configuration options ###
322 # authentification method (pam or shadow)
323 AUTH_METHOD = ${AUTH_METHOD}
324 # also prompt for the root password in adition to the user's
325 ENABLE_ROOT_PASSWORD = ${ENABLE_ROOT_PASSWORD}
326 # enable plugins for vlock-main
327 ENABLE_PLUGINS = ${ENABLE_PLUGINS}
328 # which plugins should be build
329 MODULES = ${MODULES}
330 # which scripts should be installed
331 SCRIPTS = ${SCRIPTS}
333 # root's group
334 ROOT_GROUP = ${ROOT_GROUP}
336 # group to install vlock-main with
337 VLOCK_GROUP = ${VLOCK_GROUP}
338 # mode to install privileged plugins with
339 VLOCK_MODULE_MODE = ${VLOCK_MODULE_MODE}
341 ### paths ###
343 # installation prefix
344 PREFIX = ${PREFIX}
345 BINDIR = ${BINDIR}
346 SBINDIR = ${SBINDIR}
347 LIBDIR = ${LIBDIR}
348 MANDIR = ${MANDIR}
349 # installation root
350 DESTDIR =
351 # path where modules will be located
352 VLOCK_MODULE_DIR = ${VLOCK_MODULE_DIR}
353 # path where scripts will be located
354 VLOCK_SCRIPT_DIR = ${VLOCK_SCRIPT_DIR}
356 ### programs ###
358 # shell to run vlock.sh with (only bash is known to work)
359 BOURNE_SHELL = ${BOURNE_SHELL}
360 # C compiler
361 CC = ${CC}
362 # linker
363 LD = ${LD}
364 # mkdir
365 MKDIR_P = mkdir -p
367 ### compiler and linker settings ###
369 # C compiler flags
370 CFLAGS = ${CFLAGS}
371 # linker flags
372 LDFLAGS = ${LDFLAGS}
373 # linker flags needed for dlopen and friends
374 DL_LIB = ${DL_LIB}
375 # linker flags needed for crypt
376 CRYPT_LIB = ${CRYPT_LIB}
377 # linker flags needed for pam
378 PAM_LIBS = ${PAM_LIBS}
382 main() {
383 verbose=1
385 set_defaults
386 parse_config_mk
387 parse_arguments "$@"
389 if [ "$verbose" -ge 1 ] ; then
390 show_summary
393 create_config_mk
396 main "$@"