2 # Based on the configure script from musl libc, MIT licensed
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.
14 --srcdir=DIR source directory [detected]
15 --environment-only check environment only, no system libraries
16 --static prepare for static build
18 Installation directories:
19 --prefix=PREFIX main installation prefix [/usr/local]
20 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
22 Fine tuning of the installation directories:
23 --bindir=DIR user executables [EPREFIX/bin]
24 --sharedir=DIR share directories [PREFIX/share]
25 --mandir=DIR man pages [PREFIX/share/man]
28 --enable-lua build with Lua support [auto]
29 --enable-selinux build with SELinux support [auto]
30 --enable-acl build with POSIX ACL support [auto]
32 Some influential environment variables:
33 CC C compiler command [detected]
34 CFLAGS C compiler flags [-Os -pipe ...]
37 Use these variables to override the choices made by configure.
46 tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
49 printf %s
\\n
"$1" |
sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
51 echo () { printf "%s\n" "$*" ; }
52 fail
() { echo "$*" ; exit 1 ; }
53 fnmatch
() { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
54 cmdexists
() { type "$1" >/dev
/null
2>&1 ; }
55 trycc
() { test -z "$CC" && cmdexists
"$1" && CC
=$1 ; }
58 while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
62 printf "checking preprocessor condition %s... " "$1"
63 echo "typedef int x;" > "$tmpc"
64 echo "#if $1" >> "$tmpc"
65 echo "#error yes" >> "$tmpc"
66 echo "#endif" >> "$tmpc"
67 if $CC $2 -c -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
77 printf "checking whether compiler accepts %s... " "$2"
78 echo "typedef int x;" > "$tmpc"
79 if $CC $CFLAGS_TRY $2 -c -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
81 eval "$1=\"\${$1} \$2\""
91 printf "checking whether linker accepts %s... " "$2"
92 echo "typedef int x;" > "$tmpc"
93 if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o "$tmpo" "$tmpc" >/dev
/null
2>&1 ; then
95 eval "$1=\"\${$1} \$2\""
104 # Beginning of actual script
112 EXEC_PREFIX
='$(PREFIX)'
113 BINDIR
='$(EXEC_PREFIX)/bin'
114 SHAREDIR
='$(PREFIX)/share'
115 MANDIR
='$(PREFIX)/share/man'
124 --srcdir=*) SRCDIR
=${arg#*=} ;;
125 --prefix=*) PREFIX
=${arg#*=} ;;
126 --exec-prefix=*) EXEC_PREFIX
=${arg#*=} ;;
127 --bindir=*) BINDIR
=${arg#*=} ;;
128 --sharedir=*) SHAREDIR
=${arg#*=} ;;
129 --mandir=*) MANDIR
=${arg#*=} ;;
130 --environment-only) environmentonly
=yes ;;
131 --static) static
=yes ;;
132 --enable-lua|
--enable-lua=yes) lua
=yes ;;
133 --disable-lua|
--enable-lua=no
) lua
=no
;;
134 --enable-selinux|
--enable-selinux=yes) selinux
=yes ;;
135 --disable-selinux|
--enable-selinux=no
) selinux
=no
;;
136 --enable-acl|
--enable-acl=yes) acl
=yes ;;
137 --disable-acl|
--enable-acl=no
) acl
=no
;;
138 --enable-*|
--disable-*|
--with-*|
--without-*|
--*dir
=*|
--build=*) ;;
139 -* ) echo "$0: unknown option $arg" ;;
140 CC
=*) CC
=${arg#*=} ;;
141 CFLAGS
=*) CFLAGS
=${arg#*=} ;;
142 CPPFLAGS
=*) CPPFLAGS
=${arg#*=} ;;
143 LDFLAGS
=*) LDFLAGS
=${arg#*=} ;;
149 for i
in SRCDIR PREFIX EXEC_PREFIX BINDIR SHAREDIR MANDIR
; do
154 # Get the source dir for out-of-tree builds
156 if test -z "$SRCDIR" ; then
157 SRCDIR
="${0%/configure}"
160 abs_builddir
="$(pwd)" || fail
"$0: cannot determine working directory"
161 abs_srcdir
="$(cd $SRCDIR && pwd)" || fail
"$0: invalid source directory $SRCDIR"
162 test "$abs_srcdir" = "$abs_builddir" && SRCDIR
=.
163 test "$SRCDIR" != "." -a -f Makefile
-a ! -h Makefile
&& fail
"$0: Makefile already exists in the working directory"
166 # Get a temp filename we can use
170 while : ; do i
=$
(($i+1))
171 tmpc
="./conf$$-$PPID-$i.c"
172 tmpo
="./conf$$-$PPID-$i.o"
173 2>|
/dev
/null
> "$tmpc" && break
174 test "$i" -gt 50 && fail
"$0: cannot create temporary file $tmpc"
177 trap 'rm -f "$tmpc" "$tmpo"' EXIT INT QUIT TERM HUP
180 # Find a C compiler to use
182 printf "checking for C compiler... "
187 test -n "$CC" ||
{ echo "$0: cannot find a C compiler" ; exit 1 ; }
189 printf "checking whether C compiler works... "
190 echo "typedef int x;" > "$tmpc"
191 if output
=$
($CC $CPPFLAGS $CFLAGS -c -o "$tmpo" "$tmpc" 2>&1) ; then
194 printf "no; compiler output follows:\n%s\n" "$output"
199 # Figure out options to force errors on unknown flags.
201 tryflag CFLAGS_TRY
-Werror=unknown-warning-option
202 tryflag CFLAGS_TRY
-Werror=unused-command-line-argument
203 tryldflag LDFLAGS_TRY
-Werror=unknown-warning-option
204 tryldflag LDFLAGS_TRY
-Werror=unused-command-line-argument
206 CFLAGS_STD
="-std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DNDEBUG -D_FORTIFY_SOURCE=2"
212 FreeBSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE -D__BSD_VISIBLE=1" ;;
213 *BSD
) CFLAGS_STD
="$CFLAGS_STD -D_BSD_SOURCE" ;;
214 Darwin
) CFLAGS_STD
="$CFLAGS_STD -D_DARWIN_C_SOURCE" ;;
215 AIX
) CFLAGS_STD
="$CFLAGS_STD -D_ALL_SOURCE" ;;
220 # Try flags to optimize binary size
222 #tryflag CFLAGS -ffunction-sections
223 #tryflag CFLAGS -fdata-sections
224 #tryldflag LDFLAGS_AUTO -Wl,--gc-sections
226 # Try hardening flags
228 tryflag CFLAGS_AUTO
-fstack-protector-all
229 tryldflag LDFLAGS
-Wl,-z,now
230 tryldflag LDFLAGS
-Wl,-z,relro
231 # in theory it should be perfectly fine to produce a staticically linked PIE
232 # however in practice it is not yet properly supported by gcc:
234 # cc -fPIE -pie --static
236 # will always add a PT_INTERP referencing the dynamic loader/linker
237 if test "$static" != "yes" || tryldflag LDFLAGS_AUTO
-Wl,--no-dynamic-linker ; then
238 tryldflag LDFLAGS_AUTO
-pie
241 printf "creating config.mk... "
243 cmdline
=$
(quote
"$0")
244 for i
; do cmdline
="$cmdline $(quote "$i")" ; done
246 exec 3>&1 1>config.mk
249 # This version of config.mk was generated by:
251 # Any changes made here will be lost if configure is re-run
254 EXEC_PREFIX = $EXEC_PREFIX
257 SHAREPREFIX = $SHAREDIR
261 CFLAGS_STD = $CFLAGS_STD
262 LDFLAGS_STD = $LDFLAGS_STD
263 CFLAGS_AUTO = $CFLAGS_AUTO
264 LDFLAGS_AUTO = $LDFLAGS_AUTO
270 if test "$environmentonly" = "yes"; then
275 printf "checking for pkg-config... "
276 cmdexists pkg-config
&& have_pkgconfig
=yes
277 printf "%s\n" "$have_pkgconfig"
279 # libcurses is a mandatory dependency
281 printf "checking for libcurses...\n"
285 int main(int argc, char *argv[]) {
294 for curses
in ncursesw ncurses curses
; do
295 printf " checking for %s... " "$curses"
297 if test "$have_pkgconfig" = "yes" ; then
298 CFLAGS_CURSES
=$
(pkg-config
--cflags $curses 2>/dev
/null
)
299 LDFLAGS_CURSES
=$
(pkg-config
--libs $curses 2>/dev
/null
)
300 if test $?
-eq 0 && $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
301 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev
/null
2>&1 ; then
309 LDFLAGS_CURSES
="-l$curses"
311 if $CC $CFLAGS $CFLAGS_CURSES "$tmpc" \
312 $LDFLAGS $LDFLAGS_CURSES -o "$tmpo" >/dev
/null
2>&1 ; then
321 test $CONFIG_CURSES -ne 1 && fail
"$0: cannot find libcurses"
323 # libtermkey is a mandatory dependency
325 printf "checking for libtermkey... "
329 int main(int argc, char *argv[]) {
330 TERMKEY_CHECK_VERSION;
335 if test "$have_pkgconfig" = "yes" ; then
336 CFLAGS_TERMKEY
=$
(pkg-config
--cflags termkey
2>/dev
/null
)
337 LDFLAGS_TERMKEY
=$
(pkg-config
--libs termkey
2>/dev
/null
)
340 if test -z "$LDFLAGS_TERMKEY"; then
342 LDFLAGS_TERMKEY
="-ltermkey"
345 if $CC $CFLAGS $CFLAGS_TERMKEY "$tmpc" $LDFLAGS $LDFLAGS_TERMKEY $LDFLAGS_CURSES \
346 -o "$tmpo" >/dev
/null
2>&1; then
350 fail
"$0: cannot find libtermkey"
355 if test "$lua" != "no" ; then
357 printf "checking for liblua >= 5.2 ...\n"
363 #if LUA_VERSION_NUM < 502
364 #error "Need at least Lua 5.2"
367 int main(int argc, char *argv[]) {
368 lua_State *L = luaL_newstate();
375 for liblua
in lua lua5.2 lua5.3 lua-5.2 lua-5.3 lua52 lua53
; do
376 printf " checking for %s... " "$liblua"
378 if test "$have_pkgconfig" = "yes" ; then
379 CFLAGS_LUA
=$
(pkg-config
--cflags $liblua 2>/dev
/null
)
380 LDFLAGS_LUA
=$
(pkg-config
--libs $liblua 2>/dev
/null
)
381 if test $?
-eq 0 && $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
382 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev
/null
2>&1 ; then
390 LDFLAGS_LUA
="-l$liblua -lm -ldl"
392 if $CC $CFLAGS $CFLAGS_LUA "$tmpc" \
393 $LDFLAGS $LDFLAGS_LUA -o "$tmpo" >/dev
/null
2>&1 ; then
404 test "$lua" = "yes" -a $CONFIG_LUA -ne 1 && fail
"$0: cannot find liblua"
406 if test $CONFIG_LUA -eq 1; then
407 CFLAGS_LUA
="$CFLAGS_LUA -DLUA_COMPAT_5_1 -DLUA_COMPAT_5_2 -DLUA_COMPAT_ALL"
413 if test "$OS" = "Linux" -a "$acl" != "no"; then
414 printf "checking for libacl... "
417 #include <sys/types.h>
420 int main(int argc, char *argv[]) {
421 acl_t acl = acl_get_fd(0);
426 if test "$have_pkgconfig" = "yes" ; then
427 CFLAGS_ACL
=$
(pkg-config
--cflags acl
2>/dev
/null
)
428 LDFLAGS_ACL
=$
(pkg-config
--libs acl
2>/dev
/null
)
431 if test -z "$LDFLAGS_ACL"; then
436 if $CC $CFLAGS $CFLAGS_ACL "$tmpc" \
437 $LDFLAGS $LDFLAGS_ACL -o "$tmpo" >/dev
/null
2>&1; then
444 test "$acl" = "yes" && fail
"$0: cannot find libacl"
450 if test "$OS" = "Linux" -a "$selinux" != "no"; then
451 printf "checking for libselinux... "
454 #include <selinux/selinux.h>
456 int main(int argc, char *argv[]) {
457 return is_selinux_enabled();
461 if test "$have_pkgconfig" = "yes" ; then
462 CFLAGS_SELINUX
=$
(pkg-config
--cflags selinux
2>/dev
/null
)
463 LDFLAGS_SELINUX
=$
(pkg-config
--libs selinux
2>/dev
/null
)
466 if test -z "$LDFLAGS_SELINUX"; then
468 LDFLAGS_SELINUX
="-lselinux"
471 if $CC $CFLAGS $CFLAGS_SELINUX "$tmpc" \
472 $LDFLAGS $LDFLAGS_SELINUX -o "$tmpo" >/dev
/null
2>&1; then
479 test "$selinux" = "yes" && fail
"$0: cannot find libselinux"
483 printf "completing config.mk... "
485 exec 3>&1 1>>config.mk
488 CFLAGS_CURSES = $CFLAGS_CURSES
489 LDFLAGS_CURSES = $LDFLAGS_CURSES
490 CFLAGS_TERMKEY = $CFLAGS_TERMKEY
491 LDFLAGS_TERMKEY = $LDFLAGS_TERMKEY
492 CONFIG_LUA = $CONFIG_LUA
493 CFLAGS_LUA = $CFLAGS_LUA
494 LDFLAGS_LUA = $LDFLAGS_LUA
495 CONFIG_ACL = $CONFIG_ACL
496 CFLAGS_ACL = $CFLAGS_ACL
497 LDFLAGS_ACL = $LDFLAGS_ACL
498 CONFIG_SELINUX = $CONFIG_SELINUX
499 CFLAGS_SELINUX = $CFLAGS_SELINUX
500 LDFLAGS_SELINUX = $LDFLAGS_SELINUX
504 test "$SRCDIR" = "." ||
ln -sf $SRCDIR/Makefile .