AC_INIT(nawm.c)

# For now at least, I don't want the extra hair associated with
# libtool, so figure out our OS and compiler and set various flags by
# hand. Set CFLAGS to -g because -O makes it too hard to debug on some
# OSes.

AC_CANONICAL_HOST
CFLAGS=-g
AC_PROG_CC
export=-export-dynamic

case $host_os in
solaris*)
	MODULE_LDFLAGS=-G
	;;
irix*)
	MODULE_LDFLAGS="-shared -n32"
	export=
	;;
netbsd*)
	MODULE_CFLAGS=-fpic
	MODULE_LDFLAGS=-Bshareable
	export=--export-dynamic
	;;
*)
	MODULE_LDFLAGS=-shared
	;;
esac
AC_SUBST(MODULE_CFLAGS)
AC_SUBST(MODULE_LDFLAGS)

if test `basename $CC` = "gcc"; then
	LDFLAGS="$LDFLAGS $export"
	AC_SUBST(LDFLAGS)
fi

# Other programs we need
AC_PROG_INSTALL
AC_PROG_LEX
AC_DECL_YYTEXT
AC_PROG_YACC
AC_PROG_MAKE_SET


# For NetBSD a.out architectures
AC_MSG_CHECKING(if symbols have underscores prepended)
for libm in /usr/lib/libm.so*; do
	underscore=`nm $libm | sed -n -e 's/.* _sin$/_/p'`;
	break;
done
if test "$underscore" = "_"; then
	AC_MSG_RESULT(yes)
	AC_DEFINE(NEED_UNDERSCORES)
else
	AC_MSG_RESULT(no)
fi

# X11
AC_PATH_XTRA
if test -n "${x_includes}"; then
	X_INCLUDES="${x_includes}"
fi
if test -n "${x_librariess}"; then
	X_LIBRARIES="${x_libraries}"
fi
AC_SUBST(X_INCLUDES)
AC_SUBST(X_LIBRARIES)

# See if we need libdl
AC_CHECK_LIB(dl,dlopen)

# Some default prefixes
if test "$srcdir" = /afs/sipb.mit.edu/project/nawm/src/nawm -o \
	"$srcdir" = /mit/nawm/src/nawm; then
	prefix=/afs/sipb.mit.edu/project/nawm;
	exec_prefix=$prefix/arch/$ATHENA_SYS;
fi

if test "$srcdir" = /afs/athena.mit.edu/project/windowmgr/src/nawm -o \
	"$srcdir" = /mit/windowmanagers/src/nawm -o \
	"$srcdir" = /mit/windowmgr/src/nawm; then
	prefix=/afs/athena.mit.edu/project/windowmgr;
	exec_prefix=$prefix/arch/$ATHENA_SYS;
fi

if test "$prefix" != NONE; then
	echo prefix is $prefix, exec_prefix is $exec_prefix
fi

AC_OUTPUT(Makefile modules/Makefile)
