PLUGINS: document scripts
[vlock.git] / configure
blobc3c37071407a012017675e8403c7a78dbdf742ad
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>
58 Use these variables to override the choices made by \`configure' or to help
59 it to find libraries and programs with nonstandard names/locations.
61 Report bugs to <frank-vlock@benkstein.net>.
62 EOT
65 set_variable() {
66 eval "$1"='"$2"'
69 enable_feature() {
70 case "$1" in
71 plugins)
72 ENABLE_PLUGINS="$2"
74 root-password)
75 ENABLE_ROOT_PASSWORD="$2"
77 pam|shadow)
78 if [ "$2" = "yes" ] ; then
79 if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then
80 fatal_error "pam and shadow authentication are mutually exclusive"
82 AUTH_METHOD="$1"
83 else
84 fatal_error "cannot disable authentication"
87 debug)
88 if [ "$2" = "yes" ] ; then
89 CFLAGS="${DEBUG_CFLAGS}"
90 else
91 CFLAGS="${DEFAULT_CFLAGS}"
95 fatal_error "invalid feature name: $1"
97 esac
100 parse_arguments() {
101 local feature opt optarg
103 while [ $# -gt 0 ] ; do
104 if ! opt=`expr "x$1" : 'x\([^=]*\)=.*'` ; then
105 opt="$1"
108 if ! optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` ; then
109 optarg=""
112 case "$1" in
113 --disable-*)
114 feature=`expr "x$1" : 'x--disable-\(.*\)'`
115 enable_feature "$feature" no
116 shift
118 --enable-*=no)
119 feature=`expr "x$1" : 'x--enable-\(.*\)=no'`
120 enable_feature "$feature" no
121 shift
123 --enable-*=yes)
124 feature=`expr "x$1" : 'x--enable-\(.*\)=yes'`
125 enable_feature "$feature" yes
126 shift
128 --enable-*)
129 feature=`expr "x$1" : 'x--enable-\(.*\)'`
130 enable_feature "$feature" yes
131 shift
133 *=*)
134 shift
135 # unshift
136 set -- "$opt" "$optarg" "$@"
138 --prefix)
139 PREFIX="$2"
140 shift 2 || fatal_error "$1 argument missing"
142 --bindir)
143 BINDIR="$2"
144 shift 2 || fatal_error "$1 argument missing"
146 --sbindir)
147 SBINDIR="$2"
148 shift 2 || fatal_error "$1 argument missing"
150 --libdir)
151 LIBDIR="$2"
152 shift 2 || fatal_error "$1 argument missing"
154 --moduledir)
155 MODULEDIR="$2"
156 shift 2 || fatal_error "$1 argument missing"
158 --scriptdir)
159 SCRIPTDIR="$2"
160 shift 2 || fatal_error "$1 argument missing"
162 --mandir)
163 MANDIR="$2"
164 shift 2 || fatal_error "$1 argument missing"
166 --with-modules)
167 MODULES="$2"
168 shift 2 || fatal_error "$1 argument missing"
170 --with-scripts)
171 SCRIPTS="$2"
172 shift 2 || fatal_error "$1 argument missing"
174 [A-Z]*)
175 set_variable "$1" "$2"
176 shift 2 || fatal_error "$1 value missing"
178 --quiet)
179 verbose=0
180 shift
182 --help)
183 show_usage
184 exit
186 --*)
187 error "unrecognized option: $1"
188 echo >&2 "Try \`$0 --help' for more information."
189 exit 1
192 error "invalid argument: $1"
193 echo >&2 "Try \`$0 --help' for more information."
194 exit 1
196 esac
197 done
200 set_defaults() {
201 # architecture independent defaults
202 PREFIX="/usr/local"
203 BINDIR="\$(PREFIX)/bin"
204 SBINDIR="\$(PREFIX)/sbin"
205 LIBDIR="\$(PREFIX)/lib"
206 MANDIR="\$(PREFIX)/share/man"
207 SCRIPTDIR="\$(LIBDIR)/vlock/scripts"
208 MODULEDIR="\$(LIBDIR)/vlock/modules"
210 CC=gcc
211 DEFAULT_CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
212 DEBUG_CFLAGS="-O0 -g -Wall -W -pedantic -std=gnu99"
213 CFLAGS="${DEFAULT_CFLAGS}"
214 LD=ld
215 LDFLAGS=""
216 AUTH_METHOD="pam"
217 ENABLE_ROOT_PASSWORD="yes"
218 ENABLE_PLUGINS="yes"
219 SCRIPTS=""
221 VLOCK_GROUP="vlock"
222 VLOCK_MODULE_MODE="0750"
224 BOURNE_SHELL="/bin/sh"
226 # architecture dependent defaults
227 OS=`uname`
229 for make in make gmake ; do
230 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
231 MAKE="$make"
232 break
234 done
236 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
238 case "$OS" in
239 Linux)
240 PAM_LIBS='-ldl -lpam'
241 DL_LIB='-ldl'
242 CRYPT_LIB='-lcrypt'
243 MODULES="all.so new.so nosysrq.so"
245 GNU/kFreeBSD)
246 PAM_LIBS='-ldl -lpam'
247 DL_LIB='-ldl'
248 CRYPT_LIB='-lcrypt'
249 MODULES="all.so new.so"
251 FreeBSD)
252 PAM_LIBS='-lpam'
253 DL_LIB=''
254 CRYPT_LIB=''
255 MODULES="all.so new.so"
257 esac
260 parse_config_mk() {
261 local tmpdir
263 if [ -z "$MAKE" ] ; then
264 error "GNU make not found"
265 echo >&2 "Set MAKE environment variable to specify alternative."
266 exit 1
269 tmpdir=`mktemp -d -t vlock-configure.XXXXXX`
271 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '
272 /^# makefile .from .config\.mk., line/ { p=1; next }
273 /^#/ { p=0; next }
274 p==1 && $1 != "MAKEFILE_LIST" && /^[[:alpha:]_]+ :?= .*/ { print }
277 while read line
279 variable_name=`expr "x${line}" : 'x\([[[:alpha:]_]\{1,\}\) :\{0,1\}='`
280 if variable_value=`expr "x${line}" : 'x[[:alpha:]_]\{1,\} :\{0,1\}= \(.*\)'` ; then
281 set_variable "$variable_name" "$variable_value"
282 else
283 set_variable "$variable_name" ""
285 done < "$tmpdir/config.mk"
287 rm -rf "$tmpdir"
290 show_summary() {
291 cat <<EOF
292 vlock configuration
294 directories:
295 prefix: $PREFIX
296 bindir: $BINDIR
297 sbindir: $SBINDIR
298 libdir: $LIBDIR
299 mandir: $MANDIR
300 scriptdir: $SCRIPTDIR
301 moduledir: $MODULEDIR
303 features:
304 enable plugins: $ENABLE_PLUGINS
305 root-password: $ENABLE_ROOT_PASSWORD
306 auth-method: $AUTH_METHOD
307 modules: $MODULES
308 scripts: $SCRIPTS
310 build configuration:
312 operating system: $OS
313 gnu make: $MAKE
314 c compiler: $CC
315 compiler flags: $CFLAGS
316 pam libs: $PAM_LIBS
317 dl libs: $DL_LIB
318 crypt lib: $CRYPT_LIB
320 installation configuration:
321 root group: $ROOT_GROUP
322 vlock group: $VLOCK_GROUP
326 create_config_mk() {
327 cat > config.mk <<EOF
328 # automatically generated by $0 on $(date)
330 ### configuration options ###
332 # authentification method (pam or shadow)
333 AUTH_METHOD = ${AUTH_METHOD}
334 # also prompt for the root password in adition to the user's
335 ENABLE_ROOT_PASSWORD = ${ENABLE_ROOT_PASSWORD}
336 # enable plugins for vlock-main
337 ENABLE_PLUGINS = ${ENABLE_PLUGINS}
338 # which plugins should be build
339 MODULES = ${MODULES}
340 # which scripts should be installed
341 SCRIPTS = ${SCRIPTS}
343 # root's group
344 ROOT_GROUP = ${ROOT_GROUP}
346 # group for privileged plugins
347 VLOCK_GROUP = ${VLOCK_GROUP}
348 # mode for privileged plugins
349 VLOCK_MODULE_MODE = ${VLOCK_MODULE_MODE}
351 ### paths ###
353 # installation prefix
354 PREFIX = ${PREFIX}
355 BINDIR = ${BINDIR}
356 SBINDIR = ${SBINDIR}
357 LIBDIR = ${LIBDIR}
358 MANDIR = ${MANDIR}
359 # installation root
360 DESTDIR =
361 # path where modules will be located
362 MODULEDIR = ${MODULEDIR}
363 # path where scripts will be located
364 SCRIPTDIR = ${SCRIPTDIR}
366 ### programs ###
368 # shell to run vlock.sh with (only bash is known to work)
369 BOURNE_SHELL = ${BOURNE_SHELL}
370 # C compiler
371 CC = ${CC}
372 # linker
373 LD = ${LD}
374 # mkdir
375 MKDIR_P = mkdir -p
376 # install
377 INSTALL = install
379 ### compiler and linker settings ###
381 # C compiler flags
382 CFLAGS = ${CFLAGS}
383 # linker flags
384 LDFLAGS = ${LDFLAGS}
385 # linker flags needed for dlopen and friends
386 DL_LIB = ${DL_LIB}
387 # linker flags needed for crypt
388 CRYPT_LIB = ${CRYPT_LIB}
389 # linker flags needed for pam
390 PAM_LIBS = ${PAM_LIBS}
394 main() {
395 verbose=1
397 set_defaults
398 parse_config_mk
399 parse_arguments "$@"
401 if [ "$verbose" -ge 1 ] ; then
402 show_summary
405 create_config_mk
408 main "$@"