vis: implement complement of selections
[vis.git] / configure
blob67f7dfd79706686b87f86827484814c1b2b3214e
1 #!/bin/sh
2 # Based on the configure script from musl libc, MIT licensed
4 usage () {
5 cat <<EOF
6 Usage: $0 [OPTION]... [VAR=VALUE]...
8 To assign environment variables (e.g., CC, CFLAGS...), specify them as
9 VAR=VALUE. See below for descriptions of some of the useful variables.
11 Defaults for the options are specified in brackets.
13 Configuration:
14 --srcdir=DIR source directory [detected]
16 Installation directories:
17 --prefix=PREFIX main installation prefix [/usr/local]
18 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
20 Fine tuning of the installation directories:
21 --bindir=DIR user executables [EPREFIX/bin]
22 --sharedir=DIR share directories [PREFIX/share]
23 --docdir=DIR misc. documentation [PREFIX/share/doc]
24 --mandir=DIR man pages [PREFIX/share/man]
26 Optional features:
27 --enable-curses build with Curses terminal output [yes]
28 --enable-lua build with Lua support [auto]
29 --enable-lpeg-static build with support for statically linked LPeg [auto]
30 --enable-tre build with TRE regex support [auto]
31 --enable-selinux build with SELinux support [auto]
32 --enable-acl build with POSIX ACL support [auto]
33 --enable-help build with built-in help texts [yes]
35 Some influential environment variables:
36 CC C compiler command [detected]
37 CFLAGS C compiler flags [-Os -pipe ...]
38 LDFLAGS Linker flags
40 Use these variables to override the choices made by configure.
42 EOF
43 exit 0
46 # Helper functions
48 quote () {
49 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
51 EOF
52 printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
54 echo () { printf "%s\n" "$*" ; }
55 fail () { echo "$*" ; exit 1 ; }
56 fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
57 cmdexists () { type "$1" >/dev/null 2>&1 ; }
58 trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
60 stripdir () {
61 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
64 trycppif () {
65 printf "checking preprocessor condition %s... " "$1"
66 echo "typedef int x;" > "$tmpc"
67 echo "#if $1" >> "$tmpc"
68 echo "#error yes" >> "$tmpc"
69 echo "#endif" >> "$tmpc"
70 if $CC $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
71 printf "false\n"
72 return 1
73 else
74 printf "true\n"
75 return 0
79 tryflag () {
80 printf "checking whether compiler accepts %s... " "$2"
81 echo "typedef int x;" > "$tmpc"
82 if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
83 printf "yes\n"
84 eval "$1=\"\${$1} \$2\""
85 eval "$1=\${$1# }"
86 return 0
87 else
88 printf "no\n"
89 return 1
93 tryldflag () {
94 printf "checking whether linker accepts %s... " "$2"
95 echo "typedef int x;" > "$tmpc"
96 if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
97 printf "yes\n"
98 eval "$1=\"\${$1} \$2\""
99 eval "$1=\${$1# }"
100 return 0
101 else
102 printf "no\n"
103 return 1
107 # Beginning of actual script
109 CFLAGS_AUTO=
110 CFLAGS_TRY=
111 LDFLAGS_AUTO=
112 LDFLAGS_TRY=
113 SRCDIR=
114 PREFIX=/usr/local
115 EXEC_PREFIX='$(PREFIX)'
116 BINDIR='$(EXEC_PREFIX)/bin'
117 SHAREDIR='$(PREFIX)/share'
118 DOCDIR='$(PREFIX)/share/doc'
119 MANDIR='$(PREFIX)/share/man'
121 help=yes
122 curses=yes
123 lua=auto
124 lpeg=auto
125 tre=auto
126 selinux=auto
127 acl=auto
129 for arg ; do
130 case "$arg" in
131 --help|-h) usage ;;
132 --srcdir=*) SRCDIR=${arg#*=} ;;
133 --prefix=*) PREFIX=${arg#*=} ;;
134 --exec-prefix=*) EXEC_PREFIX=${arg#*=} ;;
135 --bindir=*) BINDIR=${arg#*=} ;;
136 --sharedir=*) SHAREDIR=${arg#*=} ;;
137 --docdir=*) DOCDIR=${arg#*=} ;;
138 --mandir=*) MANDIR=${arg#*=} ;;
139 --environment-only) environmentonly=yes ;;
140 --enable-help|--enable-help=yes) help=yes ;;
141 --disable-help|--enable-help=no) help=no ;;
142 --enable-curses|--enable-curses=yes) curses=yes ;;
143 --disable-curses|--enable-curses=no) curses=no ;;
144 --enable-lua|--enable-lua=yes) lua=yes ;;
145 --disable-lua|--enable-lua=no) lua=no ;;
146 --enable-lpeg-static|--enable-lpeg-static=yes) lpeg=yes ;;
147 --disable-lpeg-static|--enable-lpeg-static=no) lpeg=no ;;
148 --enable-tre|--enable-tre=yes) tre=yes ;;
149 --disable-tre|--enable-tre=no) tre=no ;;
150 --enable-selinux|--enable-selinux=yes) selinux=yes ;;
151 --disable-selinux|--enable-selinux=no) selinux=no ;;
152 --enable-acl|--enable-acl=yes) acl=yes ;;
153 --disable-acl|--enable-acl=no) acl=no ;;
154 --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
155 -* ) echo "$0: unknown option $arg" ;;
156 CC=*) CC=${arg#*=} ;;
157 CFLAGS=*) CFLAGS=${arg#*=} ;;
158 CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
159 LDFLAGS=*) LDFLAGS=${arg#*=} ;;
160 *=*) ;;
161 *) ;;
162 esac
163 done
165 for i in SRCDIR PREFIX EXEC_PREFIX BINDIR SHAREDIR DOCDIR MANDIR ; do
166 stripdir $i
167 done
170 # Get the source dir for out-of-tree builds
172 if test -z "$SRCDIR" ; then
173 SRCDIR="${0%/configure}"
174 stripdir SRCDIR
176 abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
177 abs_srcdir="$(cd $SRCDIR && pwd)" || fail "$0: invalid source directory $SRCDIR"
178 test "$abs_srcdir" = "$abs_builddir" && SRCDIR=.
179 test "$SRCDIR" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
182 # Get a temp filename we can use
185 set -C
186 while : ; do i=$(($i+1))
187 tmpc="./conf$$-$PPID-$i.c"
188 tmpo="./conf$$-$PPID-$i.o"
189 2>|/dev/null > "$tmpc" && break
190 test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
191 done
192 set +C
193 trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
196 # Find a C compiler to use
198 printf "checking for C compiler... "
199 trycc cc
200 trycc gcc
201 trycc clang
202 printf "%s\n" "$CC"
203 test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
205 printf "checking whether C compiler works... "
206 echo "typedef int x;" > "$tmpc"
207 if output=$($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
208 printf "yes\n"
209 else
210 printf "no; compiler output follows:\n%s\n" "$output"
211 exit 1
215 # Figure out options to force errors on unknown flags.
217 tryflag CFLAGS_TRY -Werror=unknown-warning-option
218 tryflag CFLAGS_TRY -Werror=unused-command-line-argument
219 tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
220 tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
222 CFLAGS_STD="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
223 LDFLAGS_STD="-lc"
225 OS=$(uname)
227 case "$OS" in
228 FreeBSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
229 *BSD) CFLAGS_STD="$CFLAGS_STD -D_BSD_SOURCE" ;;
230 Darwin) CFLAGS_STD="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
231 AIX) CFLAGS_STD="$CFLAGS_STD -D_ALL_SOURCE" ;;
232 esac
234 tryflag CFLAGS -pipe
236 # Try flags to optimize binary size
237 tryflag CFLAGS -Os
238 tryflag CFLAGS -ffunction-sections
239 tryflag CFLAGS -fdata-sections
240 tryldflag LDFLAGS_AUTO -Wl,--gc-sections
242 # Try hardening flags
243 tryflag CFLAGS -fPIE
244 tryflag CFLAGS_AUTO -fstack-protector-all
245 tryldflag LDFLAGS -Wl,-z,now
246 tryldflag LDFLAGS -Wl,-z,relro
247 tryldflag LDFLAGS_AUTO -pie
249 printf "creating config.mk... "
251 cmdline=$(quote "$0")
252 for i ; do cmdline="$cmdline $(quote "$i")" ; done
254 exec 3>&1 1>config.mk
256 cat << EOF
257 # This version of config.mk was generated by:
258 # $cmdline
259 # Any changes made here will be lost if configure is re-run
260 SRCDIR = $SRCDIR
261 PREFIX = $PREFIX
262 EXEC_PREFIX = $EXEC_PREFIX
263 BINDIR = $BINDIR
264 DOCPREFIX = $DOCDIR
265 MANPREFIX = $MANDIR
266 SHAREPREFIX = $SHAREDIR
267 CC = $CC
268 CFLAGS = $CFLAGS
269 LDFLAGS = $LDFLAGS
270 CFLAGS_STD = $CFLAGS_STD
271 LDFLAGS_STD = $LDFLAGS_STD
272 CFLAGS_AUTO = $CFLAGS_AUTO
273 LDFLAGS_AUTO = $LDFLAGS_AUTO
274 CFLAGS_DEBUG = -U_FORTIFY_SOURCE -UNDEBUG -O0 -g -ggdb -Wall -Wextra -pedantic -Wno-missing-field-initializers -Wno-unused-parameter
276 exec 1>&3 3>&-
278 printf "done\n"
280 if test "$environmentonly" = "yes"; then
281 exit 0
284 have_pkgconfig=no
285 printf "checking for pkg-config... "
286 cmdexists pkg-config && have_pkgconfig=yes
287 printf "%s\n" "$have_pkgconfig"
289 if test "$help" = "yes" ; then
290 CONFIG_HELP=1
291 else
292 CONFIG_HELP=0
295 CONFIG_CURSES=0
297 if test "$curses" != "no" ; then
299 printf "checking for libcurses...\n"
301 cat > "$tmpc" <<EOF
302 #include <curses.h>
304 int main(int argc, char *argv[]) {
305 initscr();
306 endwin();
307 return 0;
311 for libcurses in ncursesw ncurses libcurses; do
312 printf " checking for %s... " "$libcurses"
314 if test "$have_pkgconfig" = "yes" ; then
315 CFLAGS_CURSES=$(pkg-config --cflags $libcurses 2>/dev/null)
316 LDFLAGS_CURSES=$(pkg-config --libs $libcurses 2>/dev/null)
317 if test $? -eq 0 && $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
318 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev/null 2>&1 ; then
319 CONFIG_CURSES=1
320 printf "yes\n"
321 break
325 CFLAGS_CURSES=""
326 LDFLAGS_CURSES="-l$libcurses"
328 if $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
329 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev/null 2>&1 ; then
330 CONFIG_CURSES=1
331 printf "yes\n"
332 break
333 else
334 CFLAGS_CURSES=""
335 LDFLAGS_CURSES=""
336 printf "no\n"
338 done
340 test "$curses" = "yes" -a $CONFIG_CURSES -ne 1 && fail "$0: cannot find libcurses"
343 # libtermkey is a mandatory dependency
345 printf "checking for libtermkey... "
346 cat > "$tmpc" <<EOF
347 #include <termkey.h>
349 int main(int argc, char *argv[]) {
350 TERMKEY_CHECK_VERSION;
351 return 0;
355 if test "$have_pkgconfig" = "yes" ; then
356 CFLAGS_TERMKEY=$(pkg-config --cflags termkey 2>/dev/null)
357 LDFLAGS_TERMKEY=$(pkg-config --libs termkey 2>/dev/null)
360 if test -z "$LDFLAGS_TERMKEY"; then
361 CFLAGS_TERMKEY=""
362 LDFLAGS_TERMKEY="-ltermkey -lncursesw"
365 if $CC $CFLAGS $CFLAGS_TERMKEY "$tmpc" $LDFLAGS $LDFLAGS_TERMKEY $LDFLAGS_CURSES \
366 -o "$tmpo" >/dev/null 2>&1; then
367 printf "%s\n" "yes"
368 else
369 printf "%s\n" "no"
370 fail "$0: cannot find libtermkey"
373 CONFIG_TRE=0
374 REGEX_SRC=text-regex.c
376 if test "$tre" != "no" ; then
378 printf "checking for libtre... "
380 cat > "$tmpc" <<EOF
381 #include <tre/tre.h>
383 int main() {
384 regex_t preg;
385 tre_str_source *source = NULL;
386 regmatch_t pmatch[1];
387 tre_regcomp(&preg, "\0", REG_EXTENDED);
388 tre_reguexec(&preg, source, 1, pmatch, 0);
389 tre_regfree(&preg);
390 return 0;
394 if test "$have_pkgconfig" = "yes" ; then
395 CFLAGS_TRE=$(pkg-config --cflags tre 2>/dev/null)
396 LDFLAGS_TRE=$(pkg-config --libs tre 2>/dev/null)
399 if test -z "$LDFLAGS_TRE"; then
400 CFLAGS_TRE=""
401 LDFLAGS_TRE="-ltre"
404 if $CC $CFLAGS $CFLAGS_TRE "$tmpc" \
405 $LDFLAGS $LDFLAGS_TRE -o "$tmpo" >/dev/null 2>&1; then
406 CONFIG_TRE=1
407 REGEX_SRC=text-regex-tre.c
408 printf "%s\n" "yes"
409 else
410 printf "%s\n" "no"
411 CFLAGS_TRE=""
412 LDFLAGS_TRE=""
413 test "$tre" = "yes" && fail "$0: cannot find libtre"
417 CONFIG_LUA=0
419 # enabling builtin lpeg requires lua support
420 test "$lpeg" = "yes" -a "$lua" = "no" && fail "$0: need lua support for built-in lpeg"
421 test "$lpeg" = "yes" && lua=yes
423 if test "$lua" != "no" ; then
425 printf "checking for liblua >= 5.2 ...\n"
427 cat > "$tmpc" <<EOF
428 #include <lua.h>
429 #include <lualib.h>
430 #include <lauxlib.h>
432 #if LUA_VERSION_NUM < 502
433 #error "Need at least Lua 5.2"
434 #endif
436 int main(int argc, char *argv[]) {
437 lua_State *L = luaL_newstate();
438 luaL_openlibs(L);
439 lua_close(L);
440 return 0;
444 for liblua in lua lua5.3 lua5.2 lua-5.3 lua-5.2 lua53 lua52; do
445 printf " checking for %s... " "$liblua"
447 if test "$have_pkgconfig" = "yes" ; then
448 CFLAGS_LUA=$(pkg-config --cflags $liblua 2>/dev/null)
449 LDFLAGS_LUA=$(pkg-config --libs $liblua 2>/dev/null)
450 if test $? -eq 0 && $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
451 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev/null 2>&1 ; then
452 CONFIG_LUA=1
453 printf "yes\n"
454 break
458 CFLAGS_LUA=""
459 LDFLAGS_LUA="-l$liblua -lm -ldl"
461 if $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
462 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev/null 2>&1 ; then
463 CONFIG_LUA=1
464 printf "yes\n"
465 break
466 else
467 printf "no\n"
468 CFLAGS_LUA=""
469 LDFLAGS_LUA=""
471 done
473 test "$lua" = "yes" -a $CONFIG_LUA -ne 1 && fail "$0: cannot find liblua"
475 if test $CONFIG_LUA -eq 1; then
476 CFLAGS_LUA="$CFLAGS_LUA -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL"
480 CONFIG_LPEG=0
482 if test $CONFIG_LUA -eq 1 -a "$lpeg" != "no" ; then
484 printf "checking for statically linked liblpeg ... "
486 cat > "$tmpc" <<EOF
487 #include <lua.h>
488 #include <lualib.h>
489 #include <lauxlib.h>
491 int main(int argc, char *argv[]) {
492 lua_State *L = luaL_newstate();
493 luaL_openlibs(L);
494 extern int luaopen_lpeg(lua_State *L);
495 lua_getglobal(L, "package");
496 lua_getfield(L, -1, "preload");
497 lua_pushcfunction(L, luaopen_lpeg);
498 lua_setfield(L, -2, "lpeg");
499 lua_pop(L, 2);
500 lua_close(L);
501 return 0;
505 CFLAGS_LPEG=""
506 LDFLAGS_LPEG="-llpeg"
508 if $CC $CFLAGS $CFLAGS_LUA $CFLAGS_LPEG "$tmpc" \
509 $LDFLAGS $LDFLAGS_LUA $LDFLAGS_LPEG -o "$tmpo" >/dev/null 2>&1 ; then
510 CONFIG_LPEG=1
511 printf "yes\n"
512 break
513 else
514 printf "no\n"
515 CFLAGS_LPEG=""
516 LDFLAGS_LPEG=""
519 test "$lpeg" = "yes" -a $CONFIG_LPEG -ne 1 && fail "$0: cannot find liblpeg"
522 CONFIG_ACL=0
524 if test "$OS" = "Linux" -a "$acl" != "no"; then
525 printf "checking for libacl... "
527 cat > "$tmpc" <<EOF
528 #include <sys/types.h>
529 #include <sys/acl.h>
531 int main(int argc, char *argv[]) {
532 acl_t acl = acl_get_fd(0);
533 return 0;
537 if test "$have_pkgconfig" = "yes" ; then
538 CFLAGS_ACL=$(pkg-config --cflags acl 2>/dev/null)
539 LDFLAGS_ACL=$(pkg-config --libs acl 2>/dev/null)
542 if test -z "$LDFLAGS_ACL"; then
543 CFLAGS_ACL=""
544 LDFLAGS_ACL="-lacl"
547 if $CC $CFLAGS $CFLAGS_ACL "$tmpc" \
548 $LDFLAGS $LDFLAGS_ACL -o "$tmpo" >/dev/null 2>&1; then
549 CONFIG_ACL=1
550 printf "%s\n" "yes"
551 else
552 printf "%s\n" "no"
553 CFLAGS_ACL=""
554 LDFLAGS_ACL=""
555 test "$acl" = "yes" && fail "$0: cannot find libacl"
559 CONFIG_SELINUX=0
561 if test "$OS" = "Linux" -a "$selinux" != "no"; then
562 printf "checking for libselinux... "
564 cat > "$tmpc" <<EOF
565 #include <selinux/selinux.h>
567 int main(int argc, char *argv[]) {
568 return is_selinux_enabled();
572 if test "$have_pkgconfig" = "yes" ; then
573 CFLAGS_SELINUX=$(pkg-config --cflags selinux 2>/dev/null)
574 LDFLAGS_SELINUX=$(pkg-config --libs selinux 2>/dev/null)
577 if test -z "$LDFLAGS_SELINUX"; then
578 CFLAGS_SELINUX=""
579 LDFLAGS_SELINUX="-lselinux"
582 if $CC $CFLAGS $CFLAGS_SELINUX "$tmpc" \
583 $LDFLAGS $LDFLAGS_SELINUX -o "$tmpo" >/dev/null 2>&1; then
584 CONFIG_SELINUX=1
585 printf "%s\n" "yes"
586 else
587 printf "%s\n" "no"
588 CFLAGS_SELINUX=""
589 LDFLAGS_SELINUX=""
590 test "$selinux" = "yes" && fail "$0: cannot find libselinux"
594 printf "checking for memrchr... "
596 cat > "$tmpc" <<EOF
597 #define _GNU_SOURCE
598 #include <string.h>
600 int main(int argc, char *argv[]) {
601 return !memrchr("\n", '\n', 1);
605 if $CC $CFLAGS "$tmpc" $LDFLAGS -o "$tmpo" >/dev/null 2>&1; then
606 HAVE_MEMRCHR=1
607 printf "%s\n" "yes"
608 else
609 HAVE_MEMRCHR=0
610 printf "%s\n" "no"
613 printf "completing config.mk... "
615 exec 3>&1 1>>config.mk
617 cat << EOF
618 CONFIG_HELP = $CONFIG_HELP
619 CFLAGS_TERMKEY = $CFLAGS_TERMKEY
620 LDFLAGS_TERMKEY = $LDFLAGS_TERMKEY
621 CONFIG_CURSES = $CONFIG_CURSES
622 CFLAGS_CURSES = $CFLAGS_CURSES
623 LDFLAGS_CURSES = $LDFLAGS_CURSES
624 REGEX_SRC = $REGEX_SRC
625 CONFIG_TRE = $CONFIG_TRE
626 CFLAGS_TRE = $CFLAGS_TRE
627 LDFLAGS_TRE = $LDFLAGS_TRE
628 CONFIG_LUA = $CONFIG_LUA
629 CFLAGS_LUA = $CFLAGS_LUA
630 LDFLAGS_LUA = $LDFLAGS_LUA
631 CONFIG_LPEG = $CONFIG_LPEG
632 CFLAGS_LPEG = $CFLAGS_LPEG
633 LDFLAGS_LPEG = $LDFLAGS_LPEG
634 CONFIG_ACL = $CONFIG_ACL
635 CFLAGS_ACL = $CFLAGS_ACL
636 LDFLAGS_ACL = $LDFLAGS_ACL
637 CONFIG_SELINUX = $CONFIG_SELINUX
638 CFLAGS_SELINUX = $CFLAGS_SELINUX
639 LDFLAGS_SELINUX = $LDFLAGS_SELINUX
640 CFLAGS_LIBC = -DHAVE_MEMRCHR=$HAVE_MEMRCHR
642 exec 1>&3 3>&-
644 test "$SRCDIR" = "." || ln -sf $SRCDIR/Makefile .
646 printf "done\n"