AC_INIT(./src/libqsys/generic.c)
AC_CONFIG_HEADER(./src/include/config.h)
AC_CANONICAL_SYSTEM()
AC_PROG_CC()
AC_PROG_INSTALL()
AC_PROG_RANLIB()
AC_PROG_MAKE_SET()
AC_PATH_PROG(LD, ld, @CC@)
AC_PATH_PROG(AS, as, @CC@)
AC_PATH_PROG(AR, ar, echo)
AC_PATH_PROG(TAR, tar, echo)
AC_PATH_PROG(GZIP, gzip, echo)
AC_PATH_PROG(GPROTO, genproto, echo)
AC_PATH_PROG(MKD, makedepend, echo)

AC_HEADER_STDC()
AC_HEADER_DIRENT()
AC_CHECK_HEADERS(unistd.h ctype.h fnmatch.h math.h setjmp.h stdio.h sys/fcntl.h sys/stat.h)
AC_CHECK_HEADERS(jpeglib.h png.h gif_lib.h)
AC_FUNC_VPRINTF()

#
# look for scalb (byte sized float shifting) or scalw (word sized float shifting
# in math.h (maybe only available for motorolas FPU)
#
dnl if test "$target_cpu" = "m68k" ; then
dnl   CFLAGS="$CFLAGS -m68030 -m68881"
dnl   ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
dnl fi
dnl 
dnl if test "$ac_cv_header_math_h" = "yes"; then
dnl   cat > confdefs.c <\EOF
dnl #include <math.h>
dnl EOF
dnl fi
dnl 
dnl scalb scalw

AC_CHECK_FUNCS(mkdir strtol snprintf fnmatch)

#
# look for available debugging-capabilities
#
DEBUGLIBS=""
AC_CHECK_LIB(png, png_create_write_struct)
AC_CHECK_LIB(m, rint)
AC_CHECK_LIB(gif, DGifOpenFileName)
AC_CHECK_LIB(dbmalloc, malloc, DEBUGLIBS=-ldbmalloc)
AC_CHECK_LIB(jpeg, jpeg_set_quality)
if test "-ldbmalloc" = "$DEBUGLIBS"; then
#define	HAVE_LIBDBMALLOC
  echo "using dbmalloc-library for debugging"
fi
AC_SUBST(DEBUGLIBS)

AC_C_BIGENDIAN()
AC_C_INLINE()
AC_SYS_LONG_FILE_NAMES()

#
# look for graphics and input-subsystems and create the appropriate
# directories and/or links
#
try_X11="no"
X_INCLUDES=""
X_LIBRARIES=""
output="./Makefile 
./src/Makefile
./src/Makefile-rules 
./src/libqbuild/Makefile 
./src/libqdisplay/Makefile 
./src/libqsys/Makefile 
./src/libqsys/generic.h 
./src/libqtools/Makefile 
./src/util/Makefile 
./testfarm/Makefile"

if test -d "./src/libqsys/$target_cpu" ; then
  echo "use special $target_cpu-driver ..."
  if test -d "./src/libqsys/$target_cpu/$target_os" ; then
    echo "use special $target_os-driver ..."
  else
    target_os="X11"
    if test -d "./src/libqsys/$target_cpu/$target_os" ; then
      echo "use generic X11-driver ..."
    else
      ln -s "./src/libqsys/unsupported/X11" "./src/libqsys/$target_cpu/$target_os"
    fi
    try_X11="yes"
  fi
else
  echo "no special system-dependend source-code available, use generic driver ..."
  target_os="X11"
  target_cpu="unsupported"
  try_X11="yes"
fi

if test "$try_X11" = "yes" ; then
  AC_PATH_X()
  if test "$have_x" = "yes" ; then
    AC_DEFINE(HAVE_X)
  else
    target_os="unsupported"
  fi
  if test "${x_libraries}" != NONE && test -n "${x_libraries}"; then
    X_LIBRARIES=-L`echo ${x_libraries} | sed -e "s/:/ -L/g"`
    X_LIBRARIES="$X_LIBRARIES -lX11"
  fi
  if test "${x_includes}" != NONE && test -n "${x_includes}"; then
    X_INCLUDES=-I`echo ${x_includes} | sed -e "s/:/ -I/g"`
  fi
fi

output="$output
./src/libqsys/$target_cpu/Makefile
./src/libqsys/$target_cpu/$target_os/Makefile"

AC_SUBST(X_INCLUDES)
AC_SUBST(X_LIBRARIES)

#
# looking for special gcc-capabilities
#
dnl echo $ac_n "checking whether we are using GNU EGCS""... $ac_c" 1>&6
dnl if eval "test \"`echo '$''{'ac_cv_prog_egcs'+set}'`\" = set"; then
dnl   echo $ac_n "(cached) $ac_c" 1>&6
dnl else
dnl   cat > conftest.c <<EOF
dnl #if (__GNUC_MINOR__ > 90)
dnl   yes;
dnl #endif
dnl EOF
dnl   if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:839: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
dnl     ac_cv_prog_egcs=yes
dnl   else
dnl     ac_cv_prog_egcs=no
dnl   fi
dnl fi

AC_OUTPUT($output)
