Revision 2 (by (no author), 2006/12/19 10:12:51) Fixed up directories
dnl Process this file with autoconf to produce a configure script.

AC_INIT(include/allegro.h)
AC_CONFIG_AUX_DIR(misc)
AC_CONFIG_HEADER(include/allegro/platform/alunixac.h:include/allegro/platform/alunixac.hin)
AC_PREREQ(2.53)
AC_ARG_PROGRAM

dnl Build CFLAGS from scratch
CFLAGS=

dnl Enable asm code in the library (default)
AC_ARG_ENABLE(asm,
[  --enable-asm[=x]        enable the use of asm code [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_asm=yes,
allegro_enable_asm=yes)

dnl Enable 8-bpp color depth (default).
AH_TEMPLATE([ALLEGRO_COLOR8], [Define if you want support for 8 bpp modes.])
AC_ARG_ENABLE(color8,
[  --enable-color8[=x]     enable support for 8-bpp modes [default=yes]],
test "X$enableval" != "Xno" && AC_DEFINE(ALLEGRO_COLOR8),
AC_DEFINE(ALLEGRO_COLOR8))

dnl Enable 16-bpp color depth (default).
AH_TEMPLATE([ALLEGRO_COLOR16], [Define if you want support for 16 bpp modes.])
AC_ARG_ENABLE(color16,
[  --enable-color16[=x]    enable support for 16-bpp modes [default=yes]],
test "X$enableval" != "Xno" && AC_DEFINE(ALLEGRO_COLOR16),
AC_DEFINE(ALLEGRO_COLOR16))

dnl Enable 24-bpp color depth (default).
AH_TEMPLATE([ALLEGRO_COLOR24], [Define if you want support for 24 bpp modes.])
AC_ARG_ENABLE(color24,
[  --enable-color24[=x]    enable support for 24-bpp modes [default=yes]],
test "X$enableval" != "Xno" && AC_DEFINE(ALLEGRO_COLOR24),
AC_DEFINE(ALLEGRO_COLOR24))

dnl Enable 32-bpp color depth (default).
AH_TEMPLATE([ALLEGRO_COLOR32], [Define if you want support for 32 bpp modes.])
AC_ARG_ENABLE(color32,
[  --enable-color32[=x]    enable support for 32-bpp modes [default=yes]],
test "X$enableval" != "Xno" && AC_DEFINE(ALLEGRO_COLOR32),
AC_DEFINE(ALLEGRO_COLOR32))

dnl Enable static library.
AC_ARG_ENABLE(static,
[  --enable-static[=x]     build static libraries [default=no]],
test "X$enableval" != "Xno" && allegro_static_libraries=yes)

dnl Enable shared library.
AC_ARG_ENABLE(shared,
[  --enable-shared[=x]     build shared libraries [default=yes]],
test "X$enableval" != "Xno" && allegro_shared_libraries=yes,
allegro_shared_libraries=yes)

dnl Enable building normal library (default).
AC_ARG_ENABLE(stdlib,
[  --enable-stdlib[=x]     enable building normal library [default=yes]],
test "X$enableval" != "Xno" && allegro_build_normal_library=yes,
allegro_build_normal_library=yes)

dnl Enable building debugging library.
AC_ARG_ENABLE(dbglib,
[  --enable-dbglib[=x]     enable building debugging library [default=no]],
test "X$enableval" != "Xno" && allegro_build_debugging_library=yes)

dnl Enable building profiling library.
AC_ARG_ENABLE(proflib,
[  --enable-proflib[=x]    enable building profiling library [default=no]],
test "X$enableval" != "Xno" && allegro_build_profiling_library=yes)

dnl Enable building debugging programs.
AC_ARG_ENABLE(dbgprog,
[  --enable-dbgprog[=x]    enable building debugging programs [default=no]],
test "X$enableval" != "Xno" && allegro_build_debugging_programs=yes)

dnl Enable building profiling programs.
AC_ARG_ENABLE(profprog,
[  --enable-profprog[=x]   enable building profiling programs [default=no]],
test "X$enableval" != "Xno" && allegro_build_profiling_programs=yes)

dnl Link programs with static library rather than shared (if available)
AC_ARG_ENABLE(staticprog,
[  --enable-staticprog[=x] link programs with static library [default=no]],
test "X$enableval" != "Xno" && allegro_build_static_programs=yes)

dnl Enable x86 processor-specific optimizations.
AC_ARG_ENABLE(opts,
[  --enable-opts=CPU       enable x86 processor optimizations [pentium]],
test "X$enableval" != "Xyes" && allegro_optimizations=$enableval,
allegro_optimizations=pentium)

dnl Enable x86 processor-specific exclusive optimizations.
AC_ARG_ENABLE(exclopts,
[  --enable-exclopts=CPU   enable x86 processor exclusive optimizations [none]],
test "X$enableval" != "Xyes" && allegro_exclusive_optimizations=$enableval,
allegro_exclusive_optimizations=none)

dnl Sanity check on shared/static options
if test "X$allegro_static_libraries" != "Xyes"; then
  if test "X$allegro_shared_libraries" != "Xyes"; then
    AC_MSG_WARN([static and shared libraries all disabled, assuming shared])
    allegro_shared_libraries=yes
  fi
elif test "X$allegro_shared_libraries" != "Xyes"; then
  allegro_build_static_programs=yes
fi

dnl How strict should we be about compiler warnings
AC_ARG_ENABLE(strictwarn,
[  --enable-strictwarn[=x] produce strict compiler warnings [default=no]],
test "X$enableval" != "Xno" && allegro_strict_warnings=yes)

if test "X$allegro_strict_warnings" = "Xyes"; then
   _warnmode="Building Allegro with strict warnings."
else
   _warnmode="Ignoring compiler warnings."
fi

dnl Enable magic main (default: no).
AC_ARG_ENABLE(magicmain,
[  --enable-magicmain[=x]  enable magic main [default=no]],
test "X$enableval" == "Xyes" && AC_DEFINE(ALLEGRO_WITH_MAGIC_MAIN,1,[Define if you need to use a magic main.]))

dnl Check that $prefix is set (needed for ALLEGRO_ACTEST_GCC_INCLUDE_PREFIX)
test "$prefix" = NONE && prefix=/usr/local

dnl Check for tools.
AC_PROG_CC
ALLEGRO_ACTEST_GCC_VERSION
ALLEGRO_ACTEST_GCC_INCLUDE_PREFIX
AC_PROG_CPP
ALLEGRO_ACTEST_GCC_CXX
ALLEGRO_ACTEST_PROG_LD_S
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LN_S

dnl LDCONFIG is used for installing shared libraries, in Linux/ELF at least
AC_PATH_PROG(LDCONFIG, ldconfig, [echo ought to run ldconfig], $PATH:/sbin:/usr/sbin)

dnl MAKEINFO is needed for producing the info pages
AC_PATH_PROG(MAKEINFO, makeinfo, [echo ought to run makeinfo], $PATH:/sbin:/usr/sbin)

dnl INSTALL_INFO is needed for installing the info pages
AC_PATH_PROG(INSTALL_INFO, install-info, [echo ought to run install-info], $PATH:/sbin:/usr/sbin)

dnl Test for processor type.
ALLEGRO_ACTEST_PROCESSOR_TYPE

dnl Test for -mtune i386 option
if test "X$allegro_cv_processor_type" = "Xi386"; then
  ALLEGRO_ACTEST_GCC_I386_MTUNE
fi

dnl Test for -mtune AMD64 option
if test "X$allegro_cv_processor_type" = "Xamd64"; then
  ALLEGRO_ACTEST_GCC_AMD64_MTUNE
fi

dnl Test for asm support.
if test "X$allegro_enable_asm" = "Xyes"; then
  if test "X$allegro_cv_processor_type" = "Xi386"; then
    ALLEGRO_MAYBE_ASM_FILES=ALLEGRO_SRC_I386_FILES
    _code_features="i386 asm"

    dnl Test for MMX support.
    ALLEGRO_ACTEST_SUPPORT_MMX
    if test "X$allegro_cv_support_mmx" = "Xyes"; then
      AC_DEFINE(ALLEGRO_MMX,1,[Define if assembler supports MMX.])
      _code_features="$_code_features, MMX"
    fi
  
    dnl Test for SSE support.
    ALLEGRO_ACTEST_SUPPORT_SSE
    if test "X$allegro_cv_support_sse" = "Xyes"; then
      AC_DEFINE(ALLEGRO_SSE,1,[Define if assembler supports SSE.])
      _code_features="$_code_features, SSE"
    fi
  elif test "X$allegro_cv_processor_type" = "Xamd64"; then
    ALLEGRO_MAYBE_ASM_FILES=ALLEGRO_SRC_AMD64_FILES
    _code_features="amd64 asm"

    dnl MMX support available if AMD64 is available, but we can't use it yet.
    dnl AC_DEFINE(ALLEGRO_MMX,1,[Define if assembler supports MMX.])
    dnl _code_features="$_code_features, MMX"
  
    dnl SSE support available if AMD64 is available, but we can't use it yet.
    dnl AC_DEFINE(ALLEGRO_SSE,1,[Define if assembler supports SSE.])
    dnl _code_features="$_code_features, SSE"
  fi
fi

if test -z "$ALLEGRO_MAYBE_ASM_FILES"; then
  ALLEGRO_MAYBE_ASM_FILES=ALLEGRO_SRC_C_FILES
  CFLAGS="$CFLAGS -DALLEGRO_NO_ASM"
  AC_DEFINE(ALLEGRO_NO_ASM,1,
	    [Define for Unix platforms, to use C convention for bank switching.])
  _code_features="C only"
fi

AC_SUBST(ALLEGRO_MAYBE_ASM_FILES)

dnl Test for underscore prepended by compiler.
ALLEGRO_ACTEST_ASM_PREFIX
if test "$allegro_cv_asm_prefix" != ""; then
  AC_DEFINE_UNQUOTED(ALLEGRO_ASM_PREFIX, "$allegro_cv_asm_prefix",
		     [Define if compiler prepends underscore to symbols.])
fi

dnl Test target machine endianess.
AC_C_BIGENDIAN
if test "$ac_cv_c_bigendian" = yes; then
  AC_DEFINE(ALLEGRO_BIG_ENDIAN,1,[Define if target machine is big endian.])
  _code_features="big endian, $_code_features"
else
  AC_DEFINE(ALLEGRO_LITTLE_ENDIAN,1,[Define if target machine is little endian.])
  _code_features="little endian, $_code_features"
fi

dnl Test for MAP_FAILED presence.
ALLEGRO_ACTEST_MAP_FAILED
if test "$Xallegro_cv_have_map_failed" = "Xno"; then
  AC_DEFINE(MAP_FAILED, [(void *)-1],
	    [Define to (void *)-1, if MAP_FAILED is not defined.])
fi

dnl Test for sched_yield (SunOS).
ALLEGRO_ACTEST_SCHED_YIELD
if test "X$allegro_cv_support_sched_yield" = "Xyes"; then
   AC_DEFINE(ALLEGRO_USE_SCHED_YIELD,1,[Define if sched_yield is provided by some library.])
fi

dnl Test for constructor attribute support.
ALLEGRO_ACTEST_CONSTRUCTOR
if test "X$allegro_support_constructor" = "Xyes"; then
  AC_DEFINE(ALLEGRO_USE_CONSTRUCTOR,1,
	    [Define if constructor attribute is supported.])
fi

dnl Test for modules support.
ALLEGRO_ACTEST_MODULES
if test -n "$allegro_support_modules"; then
  AC_DEFINE(ALLEGRO_WITH_MODULES,1,
	    [Define if dynamically loaded modules are supported.])
  _modules="Some drivers will be built as dynamic modules."
else
  _modules="All drivers will be statically linked."
fi

dnl Do we need to pass the include prefix to the compiler?
if test "$allegro_cv_support_include_prefix" = "yes"; then
  INCLUDE_PREFIX="$prefix"
else
  INCLUDE_PREFIX=
fi
AC_SUBST(INCLUDE_PREFIX)

dnl Which version of library to link with (static, shared, normal, debugging, profiling)?
if test "X$allegro_build_debugging_programs" = "Xyes"; then
  COMPILE_PROGRAM=COMPILE_DEBUG
  COMPILE_CXX_PROGRAM=COMPILE_CXX_DEBUG
  COMPILE_S_PROGRAM=COMPILE_S_DEBUG
  PROG_LDFLAGS="-g \$(LDFLAGS)"
  LIB_TO_LINK=alld
  PLUGIN_LIB=lib/unix/libaddat.a
  allegro_build_debugging_library=yes
  _programs="debug"
elif test "X$allegro_build_profiling_programs" = "Xyes"; then
  COMPILE_PROGRAM=COMPILE_PROFILE
  COMPILE_CXX_PROGRAM=COMPILE_CXX_PROFILE
  COMPILE_S_PROGRAM=COMPILE_S_PROFILE
  PROG_LDFLAGS="-pg \$(LDFLAGS)"
  LIB_TO_LINK=allp
  PLUGIN_LIB=lib/unix/libapdat.a
  allegro_build_profiling_library=yes
  _programs="profile"
else
  COMPILE_PROGRAM=COMPILE_NORMAL
  COMPILE_CXX_PROGRAM=COMPILE_CXX_NORMAL
  COMPILE_S_PROGRAM=COMPILE_S_NORMAL
  if test "X$allegro_cv_prog_ld_s" = "Xyes"; then
    PROG_LDFLAGS="-s \$(LDFLAGS)"
  else
    PROG_LDFLAGS="\$(LDFLAGS)"
  fi
  LIB_TO_LINK=alleg
  PLUGIN_LIB=lib/unix/libaldat.a
  allegro_build_normal_library=yes
  _programs="release"
fi
if test "X$allegro_build_static_programs" = "Xyes"; then
  LIBALLEG=lib/unix/lib$LIB_TO_LINK.a
  LINK_LIBALLEG="$LIBALLEG \$(LIBS)"
  LINK_WITH_STATIC_LIBS=yes
  allegro_static_libraries=yes
  _programs="statically linked $_programs"
else
  LIBALLEG="lib/unix/lib${LIB_TO_LINK}-\$(shared_version).so lib/unix/lib${LIB_TO_LINK}_unsharable.a"
  LINK_LIBALLEG="-Llib/unix -l${LIB_TO_LINK}-\$(shared_version) -l${LIB_TO_LINK}_unsharable -lm"
  LINK_WITH_STATIC_LIBS=no
  allegro_shared_libraries=yes
  _programs="dynamically linked $_programs"
fi
AC_SUBST(LIBALLEG)
AC_SUBST(LINK_LIBALLEG)
AC_SUBST(PLUGIN_LIB)
AC_SUBST(COMPILE_PROGRAM)
AC_SUBST(COMPILE_CXX_PROGRAM)
AC_SUBST(COMPILE_S_PROGRAM)
AC_SUBST(PROG_LDFLAGS)
AC_SUBST(LIB_TO_LINK)
AC_SUBST(LINK_WITH_STATIC_LIBS)

dnl Which libraries to build (static, shared, normal, debugging, profiling)?
ALLEGRO_LIB_TARGETS=
if test "X$allegro_static_libraries" = "Xyes"; then
  _libraries=" static"
  if test "X$allegro_build_normal_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballeg.a"
    _libraries="$_libraries release"
  fi
  if test "X$allegro_build_debugging_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballd.a"
    _libraries="$_libraries debug"
  fi
  if test "X$allegro_build_profiling_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballp.a"
    _libraries="$_libraries profile"
  fi
fi
if test "X$allegro_shared_libraries" = "Xyes"; then
  if test -n "$_libraries"; then
    _libraries="$_libraries,"
  fi

  _libraries="$_libraries shared"
  if test "X$allegro_build_normal_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballeg-\$(shared_version).so lib/unix/liballeg_unsharable.a"
    _libraries="$_libraries release"
  fi
  if test "X$allegro_build_debugging_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballd-\$(shared_version).so lib/unix/liballd_unsharable.a"
    _libraries="$_libraries debug"
  fi
  if test "X$allegro_build_profiling_library" = "Xyes"; then
    ALLEGRO_LIB_TARGETS="$ALLEGRO_LIB_TARGETS lib/unix/liballp-\$(shared_version).so lib/unix/liballp_unsharable.a"
    _libraries="$_libraries profile"
  fi
fi
AC_SUBST(ALLEGRO_LIB_TARGETS)

dnl Test for debugging with Fortify.
ALLEGRO_ACTEST_DEBUG_WITH_FORTIFY
if test -n "$allegro_debug_with_fortify"; then
  LIBS="$LIBS -lfortify"
fi

dnl Test for debugging with DMalloc.
ALLEGRO_ACTEST_DEBUG_WITH_DMALLOC
if test -n "$allegro_debug_with_dmalloc"; then
  LIBS="$LIBS -ldmalloc"
fi

dnl Test for OSS drivers.
ALLEGRO_ACTEST_OSSDIGI
if test -n "$allegro_support_ossdigi"; then
  AC_DEFINE(ALLEGRO_WITH_OSSDIGI,1,[Define if OSS DIGI driver is supported.])
  _enabled_modules="ossdigi $_enabled_modules"
else
  _disabled_modules="ossdigi $_disabled_modules"
fi

dnl Test for ALSA drivers.
ALLEGRO_ACTEST_ALSADIGI
if test "$allegro_cv_support_alsadigi" = yes; then
  AC_DEFINE(ALLEGRO_WITH_ALSADIGI,1,[Define if ALSA DIGI driver is supported.])
  if test "$allegro_cv_alsa_version" = 9; then
    AC_DEFINE(ALLEGRO_ALSA_VERSION,9,[Define to the installed ALSA version.])
  else
    AC_DEFINE(ALLEGRO_ALSA_VERSION,5,[Define to the installed ALSA version.])
  fi
  _enabled_modules="alsadigi $_enabled_modules"
else
  _disabled_modules="alsadigi $_disabled_modules"
fi

ALLEGRO_ACTEST_ALSAMIDI
if test "$allegro_cv_support_alsamidi" = yes; then
  AC_DEFINE(ALLEGRO_WITH_ALSAMIDI,1,[Define if ALSA MIDI driver is supported.])
  if test "$allegro_cv_alsa_version" = 9; then
    AC_DEFINE(ALLEGRO_ALSA_VERSION,9,[Define to the installed ALSA version.])
  else
    AC_DEFINE(ALLEGRO_ALSA_VERSION,5,[Define to the installed ALSA version.])
  fi
  _enabled_modules="alsamidi $_enabled_modules"
else
  _disabled_modules="alsamidi $_disabled_modules"
fi

dnl Test for ESD drivers.
ALLEGRO_ACTEST_ESDDIGI
if test -n "$allegro_support_esddigi"; then
  AC_DEFINE(ALLEGRO_WITH_ESDDIGI,1,[Define if ESD DIGI driver is supported.])
  _enabled_modules="esddigi $_enabled_modules"
else
  _disabled_modules="esddigi $_disabled_modules"
fi

dnl Test for aRts drivers.
ALLEGRO_ACTEST_ARTSDIGI
if test -n "$allegro_support_artsdigi"; then
  AC_DEFINE(ALLEGRO_WITH_ARTSDIGI,1,[Define if aRts DIGI driver is supported.])
  _enabled_modules="artsdigi $_enabled_modules"
else
  _disabled_modules="artsdigi $_disabled_modules"
fi

dnl Test for SGI AL drivers.
ALLEGRO_ACTEST_SGIALDIGI
if test "$allegro_cv_support_sgialdigi" = yes; then
   AC_DEFINE(ALLEGRO_WITH_SGIALDIGI,1,[Define if SGI AL DIGI driver is supported.])
  _enabled_modules="sgialdigi $_enabled_modules"
else
  _disabled_modules="sgialdigi $_disabled_modules"
fi

dnl Test for OSS MIDI drivers.
ALLEGRO_ACTEST_OSSMIDI
if test -n "$allegro_support_ossmidi"; then
  AC_DEFINE(ALLEGRO_WITH_OSSMIDI,1,[Define if OSS MIDI driver is supported.])
  _enabled_modules="ossmidi $_enabled_modules"
else
  _disabled_modules="ossmidi $_disabled_modules"
fi

dnl Test for System V procfs
ALLEGRO_SV_PROCFS
if test "$allegro_sv_procfs" = yes; then
   AC_DEFINE(ALLEGRO_HAVE_SV_PROCFS,1,
      [Define to 1 if you have a System V sys/procfs.h])
      
   ALLEGRO_PROCFS_ARGCV
   if test "$allegro_procfs_argcv" = yes; then
      AC_DEFINE(ALLEGRO_HAVE_PROCFS_ARGCV,1,
         [Define to 1 if procfs reveals argc and argv])
   fi
fi

dnl Test for Solaris like getexecname().
ALLEGRO_SYS_GETEXECNAME
if test "$allegro_sys_getexecname" = yes; then
   AC_DEFINE(ALLEGRO_HAVE_GETEXECNAME,1,
      [Define to 1 if you have getexecname])
fi


dnl Test for X-Windows support.
ALLEGRO_ACTEST_SUPPORT_XWINDOWS
if test "$allegro_support_xwindows" = yes; then
  ALLEGRO_MAYBE_XWINDOWS_FILES=ALLEGRO_SRC_X_FILES
  ALLEGRO_MAYBE_LIB_X_EXE_SOURCES=ALLEGRO_LIB_X_EXE_SOURCES
  ALLEGRO_MAYBE_LIB_X_EXES=ALLEGRO_LIB_X_EXES
else
  ALLEGRO_MAYBE_XWINDOWS_FILES=ALLEGRO_EMPTY_LIST
  ALLEGRO_MAYBE_LIB_X_EXE_SOURCES=ALLEGRO_EMPTY_LIST
  ALLEGRO_MAYBE_LIB_X_EXES=ALLEGRO_EMPTY_LIST
fi
AC_SUBST(ALLEGRO_MAYBE_XWINDOWS_FILES)
AC_SUBST(ALLEGRO_MAYBE_LIB_X_EXE_SOURCES)
AC_SUBST(ALLEGRO_MAYBE_LIB_X_EXES)
AC_SUBST(ALLEGRO_XWINDOWS_LIBDIR)

dnl Enable pthreads
AC_ARG_ENABLE(pthreads,
[  --enable-pthreads[=x]   enable use of pthreads [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_pthreads=yes,
allegro_enable_pthreads=yes)

dnl Enable Linux console support
AC_ARG_ENABLE(linux,
[  --enable-linux[=x]      enable Linux console support [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_linux=yes,
allegro_enable_linux=yes)

_linux_console="Linux console support:"
if test "X$allegro_enable_linux" != "Xyes"; then
  _linux_console="$_linux_console disabled"
else
  _linux_console="$_linux_console enabled"
fi

dnl Enable Linux console VGA driver
AC_ARG_ENABLE(vga,
[  --enable-vga[=x]        enable VGA graphics driver [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_vga=yes,
allegro_enable_vga=yes)

dnl Enable Linux console fbcon driver
AC_ARG_ENABLE(fbcon,
[  --enable-fbcon[=x]      enable fbcon graphics driver [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_fbcon=yes,
allegro_enable_fbcon=yes)

dnl Enable Linux console VBE/AF driver
AC_ARG_ENABLE(vbeaf,
[  --enable-vbeaf[=x]      enable VBE/AF graphics driver [default=no]],
test "X$enableval" != "Xno" && allegro_enable_vbeaf=yes,
allegro_enable_vbeaf=no)

dnl Enable Linux console SVGAlib driver
AC_ARG_ENABLE(svgalib,
[  --enable-svgalib[=x]    enable SVGAlib graphics driver [default=yes]],
test "X$enableval" != "Xno" && allegro_enable_svgalib=yes,
allegro_enable_svgalib=yes)

dnl Some miscellaneous defines.
ALLEGRO_MAYBE_LINUX_FILES=ALLEGRO_EMPTY_LIST

allegro_system=`uname -s | tr A-Z a-z`
case "$allegro_system" in

*linux*)
  if test "X$allegro_enable_linux" = "Xyes"; then
    AC_DEFINE(ALLEGRO_LINUX,1,[Define if target platform is linux.])
    ALLEGRO_MAYBE_LINUX_FILES=ALLEGRO_SRC_LINUX_FILES

    AC_CHECK_HEADERS(sys/io.h linux/joystick.h linux/input.h)

    if test "X$allegro_cv_processor_type" = "Xi386" -a "X$allegro_enable_vga" = "Xyes"; then
      allegro_support_vga=yes
      AC_DEFINE(ALLEGRO_LINUX_VGA,1,
		[Define to enable Linux console VGA driver.])
      _enabled_modules="vga $_enabled_modules"
    else
      _disabled_modules="vga $_disabled_modules"
    fi

    if test "X$allegro_cv_processor_type" = "Xi386" -a "X$allegro_enable_vbeaf" = "Xyes"; then
      AC_DEFINE(ALLEGRO_LINUX_VBEAF,1,
		[Define to enable Linux console VBE/AF driver.])
      _enabled_modules="vbeaf $_enabled_modules"
    else
      _disabled_modules="vbeaf $_disabled_modules"
    fi

    _do_fbcon="no"
    if test "X$allegro_enable_fbcon" = "Xyes"; then
      ALLEGRO_ACTEST_FBCON
      if test "X$allegro_cv_support_fbcon" = "Xyes"; then
	AC_DEFINE(ALLEGRO_LINUX_FBCON,1,
		    [Define to enable Linux console fbcon driver.])
	_do_fbcon="yes"
      fi
    fi

    if test "$_do_fbcon" = yes; then
      _enabled_modules="fbcon $_enabled_modules"
    else
      _disabled_modules="fbcon $_disabled_modules"
    fi

    _do_svgalib="no"
    if test "X$allegro_enable_svgalib" = "Xyes"; then
      ALLEGRO_ACTEST_SVGALIB
      if test "X$allegro_cv_support_svgalib" = "Xyes"; then
        AC_DEFINE(ALLEGRO_LINUX_SVGALIB,1,
		    [Define to enable Linux console SVGAlib driver.])
	_do_svgalib="yes"
	if test -z "$allegro_support_modules"; then
	  LIBS="-lvga $LIBS"
	fi
	if test "X$allegro_cv_have_vga_version" = "Xyes"; then
	  AC_DEFINE(ALLEGRO_LINUX_SVGALIB_HAVE_VGA_VERSION,1,
		      [Define if SVGAlib driver can check vga_version.])
        fi
      fi
    fi

    if test "$_do_svgalib" = yes; then
      _enabled_modules="svgalib $_enabled_modules"
    else
      _disabled_modules="svgalib $_disabled_modules"
    fi
  fi
  ;;

esac

AC_SUBST(ALLEGRO_MAYBE_LINUX_FILES)

_do_pthread="no"
dnl Test for pthreads.
if test "X$allegro_enable_pthreads" = "Xyes"; then
  ALLEGRO_ACTEST_PTHREADS
  if test "X$allegro_cv_support_pthreads" = "Xyes"; then
    AC_DEFINE(HAVE_LIBPTHREAD,1, [Define if you have the pthread library.])
    _do_pthread="yes"
  fi
fi

if test "$_do_pthread" = yes; then
  _code_features="multithreaded, $_code_features"
else
  _code_features="signals instead of threads, $_code_features"
fi

dnl Test for JACK driver
ALLEGRO_ACTEST_JACK
if test "X$allegro_cv_support_jackdigi" = "Xyes"; then
  if test "X$_do_pthread" = "Xyes"; then
    AC_DEFINE(ALLEGRO_WITH_JACKDIGI,1,[Define if JACK DIGI driver is supported.])
    _enabled_modules="jackdigi $_enabled_modules"
  else
	echo Warning: Jack will be disabled, since pthreads support is missing/disabled.
	_disabled_modules="jackdigi $_disabled_modules"
  fi
else
  _disabled_modules="jackdigi $_disabled_modules"
fi

if test "X$allegro_support_xf86dga2" = "Xyes"; then
  _enabled_modules="dga2 $_enabled_modules"
else
  _disabled_modules="dga2 $_disabled_modules"
fi

dnl Modules.
if test -n "$allegro_support_modules"; then

  dnl VGA/ModeX.
  if test "X$allegro_support_vga" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-vga.so"
  fi

  dnl SVGAlib.
  if test "X$allegro_cv_support_svgalib" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-svgalib.so"
  fi

  dnl fbcon.
  if test "X$allegro_cv_support_fbcon" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-fbcon.so"
  fi

  dnl DGA2.
  if test "X$allegro_support_xf86dga2" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-dga2.so"
  fi

  dnl ALSA DIGI.
  if test "X$allegro_cv_support_alsadigi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsadigi.so"
  fi

  dnl ALSA MIDI.
  if test "X$allegro_cv_support_alsamidi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-alsamidi.so"
  fi

  dnl ESD DIGI.
  if test "X$allegro_support_esddigi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-esddigi.so"
  fi

  dnl aRts DIGI.
  if test "X$allegro_support_artsdigi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-artsdigi.so"
  fi

  dnl SGI AL DIGI.
  if test "X$allegro_cv_support_sgialdigi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-sgialdigi.so"
  fi

  dnl JACK DIGI.
  if test "X$allegro_cv_support_jackdigi" = "Xyes"; then
    ALLEGRO_MODULE_TARGETS="$ALLEGRO_MODULE_TARGETS lib/unix/alleg-jackdigi.so"
  fi
fi
AC_SUBST(ALLEGRO_MODULE_TARGETS)

dnl Additional libraries.
LIBS="-lm $LIBS"

case "$allegro_system" in

*darwin*)
  AC_DEFINE(ALLEGRO_DARWIN,1,[Define if target platform is Darwin.])
  LIBS="-lcc_dynamic $LIBS"
  AR="\$(LD) -r -keep_private_externs -o"
  ;;

*)
  AR="ar rvs"
  ;;

esac

AC_SUBST(LIBS)
AC_SUBST(AR)

dnl Headers, features, functions and macros.
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h sys/utsname.h)

AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_TYPE_SIGNAL

AC_CHECK_FUNCS(mmap mprotect memcmp mkstemp stricmp strlwr strupr vprintf stat64)
AC_CHECK_FUNCS(sysconf)

dnl Tweak header files for library build
CFLAGS="$CFLAGS -DALLEGRO_LIB_BUILD"

dnl How to compile C and asm files.
if test -n "$GCC"; then
  if test "X$allegro_strict_warnings" = "Xyes"; then
    WFLAGS="-Wall -W -Wstrict-prototypes -Wno-unused-parameter -Werror"
  else
    WFLAGS="-Wall -Wno-unused"
  fi
  if test "X$allegro_cv_processor_type" = "Xi386"; then
    if test "$allegro_exclusive_optimizations" != none; then
      TARGET_ARCH="-march=$allegro_exclusive_optimizations"
    elif test "X$allegro_cv_support_i386_mtune" = "Xyes"; then
      TARGET_ARCH="-mtune=$allegro_optimizations"
    else
      TARGET_ARCH="-mcpu=$allegro_optimizations"
    fi
  elif test "X$allegro_cv_processor_type" = "Xamd64"; then
    dnl Change default pentium->athlon64
    if test "X$allegro_optimizations" = "Xpentium"; then
      allegro_optimizations="k8"
    fi
    if test "$allegro_exclusive_optimizations" != none; then
      TARGET_ARCH="-march=$allegro_exclusive_optimizations"
    elif test "X$allegro_cv_support_amd64_mtune" = "Xyes"; then
      TARGET_ARCH="-mtune=$allegro_optimizations"
    else
      TARGET_ARCH="-mcpu=$allegro_optimizations"
    fi
  else
    TARGET_ARCH=
  fi
  dnl Allow to specify additional flags.
  CFLAGS="$CFLAGS $XCFLAGS"
  WFLAGS="$WFLAGS $WCFLAGS"
  dnl In this order...
  ALLEGRO_DEBUG_CFLAGS="$CFLAGS -g $WFLAGS -DDEBUGMODE"
  if test "X$allegro_debug_with_fortify" = "Xyes"; then
     ALLEGRO_DEBUG_CFLAGS="$ALLEGRO_DEBUG_CFLAGS -DFORTIFY"
  fi
  if test "X$allegro_debug_with_dmalloc" = "Xyes"; then
     ALLEGRO_DEBUG_CFLAGS="$ALLEGRO_DEBUG_CFLAGS -DDMALLOC"
  fi
  ALLEGRO_PROFILE_CFLAGS="$CFLAGS -pg $TARGET_ARCH -O2 -funroll-loops -ffast-math $WFLAGS"
  if test "X$allegro_cv_support_fomit_frame_pointer" = "Xyes"; then
    CFLAGS="$CFLAGS $TARGET_ARCH -O2 -funroll-loops -ffast-math -fomit-frame-pointer $WFLAGS"
  else
    CFLAGS="$CFLAGS $TARGET_ARCH -O2 -funroll-loops -ffast-math $WFLAGS"
  fi
  ALLEGRO_SFLAGS="-x assembler-with-cpp"
  ALLEGRO_SHAREDLIB_CFLAGS="-fPIC -DALLEGRO_SHARED"
else
  ALLEGRO_DEBUG_CFLAGS="$CFLAGS"
  ALLEGRO_PROFILE_CFLAGS="$CFLAGS"
  ALLEGRO_SFLAGS=
  ALLEGRO_SHAREDLIB_CFLAGS=
fi

AC_SUBST(CFLAGS)
AC_SUBST(ALLEGRO_DEBUG_CFLAGS)
AC_SUBST(ALLEGRO_PROFILE_CFLAGS)
AC_SUBST(ALLEGRO_SFLAGS)
AC_SUBST(ALLEGRO_SHAREDLIB_CFLAGS)

dnl How to compile C++ files.
if test "X$allegro_cv_support_cplusplus" = "Xyes"; then
  CXX="$CC"
  CXXFLAGS="-fno-exceptions $CFLAGS"
  ALLEGRO_DEBUG_CXXFLAGS="-fno-exceptions $ALLEGRO_DEBUG_CFLAGS"
  ALLEGRO_PROFILE_CXXFLAGS="-fno-exceptions $ALLEGRO_PROFILE_CFLAGS"
else
  CXX=
  CXXFLAGS=
  ALLEGRO_DEBUG_CXXFLAGS=
  ALLEGRO_PROFILE_CXXFLAGS=
fi

AC_SUBST(CXX)
AC_SUBST(CXXFLAGS)
AC_SUBST(ALLEGRO_DEBUG_CXXFLAGS)
AC_SUBST(ALLEGRO_PROFILE_CXXFLAGS)

cat > makefile.info << EOF
 $_modules
 Enabled modules: $_enabled_modules
 Disabled modules: $_disabled_modules
 Generated code: $_code_features
 Generated libraries:$_libraries
 Compiled programs: $_programs
 $_warnmode
 $_x11
 $_linux_console

EOF

dnl Warn if neither X11 nor Linux console support is going to be built,
dnl or just if X11 support is not going to be built.
if test "X$allegro_support_xwindows" != "Xyes"; then
  if test "X$allegro_enable_linux" != "Xyes"; then
    cat >> makefile.info << EOF
 Warning: the library will not be built with either X11 or Linux console
          support.  This configuration is useless for most purposes.

EOF
  else
    cat >> makefile.info << EOF
 Warning: the library will not be built with X11 support.
          If you were expecting X11 support then you may need to install
          the appropriate development packages from your distribution.
          Otherwise, ignore this warning (it's just that a lot of new
          users trip up on this).

EOF
  fi
fi

dnl Warn if passed --enable-dbg-with-fortify
if test -n "$allegro_debug_with_fortify"; then
  if test -z "$allegro_build_debugging_library"; then
    cat >> makefile.info << EOF
 Warning: the library will not be built with Fortify support.
          The support is only enabled with the debug version.

EOF
  fi 
  if test -z "$allegro_build_debugging_programs"; then
    cat >> makefile.info << EOF
 Warning: the programs will not be built with Fortify support.
          The support is only enabled with the debug version.

EOF
  fi 
fi

dnl Warn if passed --enable-dbg-with-dmalloc
if test -n "$allegro_debug_with_dmalloc"; then
  if test -z "$allegro_build_debugging_library"; then
    cat >> makefile.info << EOF
 Warning: the library will not be built with DMalloc support.
          The support is only enabled with the debug version.

EOF
  fi 
  if test -z "$allegro_build_debugging_programs"; then
    cat >> makefile.info << EOF
 Warning: the programs will not be built with DMalloc support.
          The support is only enabled with the debug version.

EOF
  fi 
fi

dnl Prepare initial dependencies file (if missing).
if test -f "$srcdir/makefile.dep"; then
  if test `cd "$srcdir" ; pwd` != `cd . ; pwd`; then
    cp "$srcdir/makefile.dep" makefile.dep
    dnl Wait for a moment, to ensure the makefile gets a nice late
    dnl timestamp, otherwise `makefile.dep' looks too new.
    echo 'Having a snooze...'
    sleep 1
  fi
elif test ! -f makefile.dep; then
  allegro_make_depend="yes"
fi

dnl Cosmetics for allegro-config
FRAMEWORKS=
AC_SUBST(FRAMEWORKS)

dnl Prepare makefile and allegro-config.
AC_OUTPUT(makefile:makefile.in allegro-config:misc/allegro-config.in,
  [test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h])

dnl The makefile doesn't work with non-GNU make so test for its presence.
if ${MAKE-make} -v -f /dev/null 2>/dev/null | grep -i "gnu" >/dev/null; then
  gnu_make="yes"
fi

dnl Run "make depend" if necessary.
if test "X$allegro_make_depend" = "Xyes"; then
  if test "X$gnu_make" = "Xyes"; then
    ${MAKE-make} depend
  else
    AC_MSG_WARN([Non-GNU make detected, trying gmake to build dependencies.])
    gmake depend
  fi
fi

dnl Display configuration informations
if test "X$gnu_make" = "Xyes"; then
  ${MAKE-make} info
else
  gmake info
fi

if test "X$gnu_make" != "Xyes"; then
  AC_MSG_WARN([You need to use GNU make to build Allegro.])
  AC_MSG_WARN([This might be called gmake on your system.])
fi