#!/bin/sh
# This configure script has been written by Han Boetes
# <han@mijncomputer.nl> and is released in public domain.
add_inc()
{
echo "#define $1" >> config.h
}
note()
{
echo -n "Looking for $@... "
echo "Looking for $@... " >&3
}
case $1 in
-*)
echo "No help and options available. Just run ./configure"
exit 0;
;;
esac
# initial config.h. I think this can be more customizable.
# (Common) compile-time options:
#
# STARTUP -- look for and handle initialization file
# FKEYS -- add support for function key sequences.
# XKEYS -- use termcap function key definitions.
# Warning: XKEYS and bsmap mode do _not_ get along.
# PREFIXREGION -- enable function "prefix-region"
# REGEX -- create regular expression functions
cat << EOF > config.h
#define FKEYS
#define PREFIXREGION
#define REGEX
#define XKEYS
EOF
exec 3> config.log
note 'internal arc4random'
cat << EOF > testfile.c
#include <stdlib.h>
int main(void)
{arc4random();return 0;}
EOF
if gcc testfile.c -o testfile 2>&3; then
echo Found.
add_inc HAVE_ARC4RANDOM
else
echo Not Found.
note 'external arc4random'
cat << EOF > testfile.c
#include <stdlib.h>
#include <arc4random.h>
int main(void)
{arc4random();return 0;}
EOF
if gcc -larc4random testfile.c -o testfile 2>&3; then
echo Found.
add_inc HAVE_ARC4RANDOM_EXT
extralibs="$extralibs -larc4random"
else
echo Not Found.
fi
fi
note 'strtonum'
cat << EOF > testfile.c
#include <stdlib.h>
#include <limits.h>
int main(void)
{strtonum(NULL, 1, 1, NULL);return 0;}
EOF
if gcc testfile.c -o testfile 2>&3; then
echo 'Found.'
else
echo 'Not Found, adding.'
add_inc HAVE_NOSTRTONUM
extraobjs="$extraobjs strtonum.o"
fi
note 'strlcpy'
cat << EOF > testfile.c
#include <string.h>
int main(void)
{strlcpy(NULL, NULL, 1);return 0;}
EOF
if gcc testfile.c -o testfile 2>&3; then
echo 'Found.'
else
echo 'Not Found, adding.'
add_inc HAVE_NOSTRLCPY
extraobjs="$extraobjs strlcpy.o"
fi
note 'strlcat'
cat << EOF > testfile.c
#include <string.h>
int main(void)
{strlcat(NULL, NULL, 1);return 0;}
EOF
if gcc -Wall testfile.c -o testfile 2>&3; then
echo 'Found.'
else
echo 'Not Found, adding.'
add_inc HAVE_NOSTRLCAT
extraobjs="$extraobjs strlcat.o"
fi
note 'fgetln'
cat << EOF > testfile.c
#include <stdio.h>
int main(void)
{fgetln(NULL, NULL);return 0;}
EOF
if gcc -Wall testfile.c -o testfile 2>&3; then
echo 'Found.'
else
echo 'Not Found, adding.'
add_inc HAVE_NOFGETLN
extraobjs="$extraobjs fgetln.o"
fi
# With -O2 or higher you get a warning for strict-aliasing on
# some versions of gcc.
echo -n 'Testing for strict aliasing... '
echo 'Testing for strict aliasing... ' >&3
cat << EOF > testfile.c
int main(void)
{return 0;}
EOF
if gcc -Wno-strict-aliasing testfile.c -o testfile 2>&3; then
echo 'Works OK.'
extraflags="$extraflags -Wno-strict-aliasing"
else
echo 'Fails.'
fi
if [ ! -r /usr/include/term.h ]; then
note 'term.h'
for i in pkg local; do
if [ -e /usr/$i/include/term.h ]; then
echo "Found in /usr/$i/include"
extralibs="$extralibs -L/usr/$i/lib"
extraflags="$extraflags -I/usr/$i/include"
break
fi
echo 'Not found!'
echo 'If you know where term.h is, please email the author!'
exit 1
done
fi
note 'glibc'
cat << EOF > testfile.c
#include <stdio.h>
int main(void)
{
#ifdef __GLIBC__
garbage that will make gcc fail
#endif
return 0;}
EOF
if gcc -Wall testfile.c -o testfile 2>&3; then
echo 'Not on this system'
else
echo 'found, adding base and dirname.'
extraobjs="$extraobjs dirname.o basename.o"
fi
note 'version'
if ls --version > testfile.o 2>&3; then
echo 'GNU ls'
add_inc GNU_LS
else
echo 'Other ls'
fi
rm testfile*
sed -e "s|@extraflags@|$extraflags|" \
-e "s|@extralibs@|$extralibs|" \
-e "s|@extraobjs@|$extraobjs|" \
Makefile.in > Makefile
echo "OK, now run \`make'."