configure: set default values
[vlock.git] / configure
blob719ed969aa02d1b08bb21827c511b7f5cbe4aef2
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 --help)
159 show_usage
160 exit
162 --*)
163 error "unrecognized option: $1"
164 echo >&2 "Try \`$0 --help' for more information."
165 exit 1
168 error "invalid argument: $1"
169 echo >&2 "Try \`$0 --help' for more information."
170 exit 1
172 esac
173 done
176 parse_environment() {
177 OS=`uname`
179 for make in make gmake ; do
180 if $make -f /dev/null -q -v 2>/dev/null | head -n 1 | grep -q "GNU Make" ; then
181 MAKE="$make"
182 break
184 done
186 if [ -z "$MAKE" ] ; then
187 error "GNU make not found"
188 echo >&2 "Set MAKE variable to specify alternative."
189 exit 1
192 ROOT_GROUP=`getent group | awk -F: '$3 == 0 { print $1 ; exit }'`
194 case "$OS" in
195 Linux)
196 PAM_LIBS='-ldl -lpam'
197 DL_LIB='-ldl'
198 CRYPT_LIB='-lcrypt'
199 DEFAULT_MODULES="all.so new.so nosysrq.so"
201 GNU/kFreeBSD)
202 PAM_LIBS='-ldl -lpam'
203 DL_LIB='-ldl'
204 CRYPT_LIB='-lcrypt'
205 DEFAULT_MODULES="all.so new.so"
207 FreeBSD)
208 PAM_LIBS='-lpam'
209 DL_LIB=''
210 CRYPT_LIB=''
211 DEFAULT_MODULES="all.so new.so"
213 esac
216 parse_config_mk() {
217 local tmpdir
219 tmpdir=`mktemp -d`
221 $MAKE -rR -f config.mk -p -q . 2>/dev/null | awk > "$tmpdir/config.mk" '\
222 /^# makefile .from .config\.mk., line/ { p=1; next }
223 /^#/ { p=0; next }
224 p==1 && $1 != "MAKEFILE_LIST" && /^[[:alpha:]_]+ :?= .*/ { print }
227 while read line
229 variable_name=`expr "${line}" : '\([[:alpha:]_]\+\) :\?='`
230 if variable_value=`expr "${line}" : '[[:alpha:]_]\+ :\?= \(.*\)'` ; then
231 set_variable "$variable_name" "$variable_value"
232 else
233 set_variable "$variable_name" ""
235 done < "$tmpdir/config.mk"
237 rm -rf "$tmpdir"
240 parse_defaults() {
241 is_set PREFIX || PREFIX="/usr/local"
242 is_set BINDIR || BINDIR="${PREFIX}/bin"
243 is_set SBINDIR || SBINDIR="${PREFIX}/sbin"
244 is_set LIBDIR || LIBDIR="${PREFIX}/lib"
245 is_set SCRIPTDIR || SCRIPTDIR="${LIBDIR}/vlock/scripts"
246 is_set MODULEDIR || MODULEDIR="${LIBDIR}/vlock/modules"
248 is_set CC || CC=gcc
249 is_set CFLAGS || CFLAGS="-O2 -Wall -W -pedantic -std=gnu99"
250 is_set LD || LD=ld
251 is_set LDFLAGS || LDFLAGS=""
252 is_set AUTH_METHOD || AUTH_METHOD="pam"
253 is_set PLUGINS || PLUGINS="$DEFAULT_MODULES"
254 is_set ENABLE_ROOT_PASSWORD || ENABLE_ROOT_PASSWORD="yes"
255 is_set ENABLE_PLUGINS || ENABLE_PLUGINS="yes"
257 is_set VLOCK_GROUP || VLOCK_GROUP="vlock"
258 is_set VLOCK_MODULE_MODE || VLOCK_MODULE_MODE="0750"
260 is_set BOURNE_SHELL || BOURNE_SHELL="/bin/sh"
263 show_summary() {
264 cat <<EOF
265 vlock configuration
267 directories:
268 prefix: $PREFIX
269 bindir: $BINDIR
270 sbindir: $SBINDIR
271 libdir: $LIBDIR
272 scriptdir: $SCRIPTDIR
273 moduledir: $MODULEDIR
275 features:
276 enable plugins: $ENABLE_PLUGINS
277 root-password: $ENABLE_ROOT_PASSWORD
278 auth-method: $AUTH_METHOD
279 plugins: $PLUGINS
281 build configuration:
283 operating system: $OS
284 gnu make: $MAKE
285 c compiler: $CC
286 compiler flags: $CFLAGS
287 pam libs: $PAM_LIBS
288 dl libs: $DL_LIB
289 crypt lib: $CRYPT_LIB
291 installation configuration:
292 root group: $ROOT_GROUP
293 vlock group: $VLOCK_GROUP
297 create_config_mk() {
301 parse_environment
302 parse_config_mk
303 parse_arguments "$@"
304 parse_defaults
306 show_summary
308 create_config_mk