dnl Configure script for GRUB.
dnl Copyright 1999 Free Software Foundation, Inc.

dnl Permission to use, copy, modify and distribute this software and its
dnl documentation is hereby granted, provided that both the copyright
dnl notice and this permission notice appear in all copies of the
dnl software, derivative works or modified versions, and any portions
dnl thereof, and that both notices appear in supporting documentation.
dnl
dnl THE FREE SOFTWARE FOUNDATION ALLOWS FREE USE OF THIS SOFTWARE IN ITS
dnl "AS IS" CONDITION.  THE FREE SOFTWARE FOUNDATION DISCLAIMS ANY
dnl LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
dnl USE OF THIS SOFTWARE.

AC_INIT(stage2/stage2.c)
dnl Grab the package and version from the top debian/changelog entry.
AM_INIT_AUTOMAKE(
   esyscmd([sed 's/ .*$//; q' debian/changelog]),
   esyscmd([sed 's/^.*(\(.*\)).*$/\1/; q' debian/changelog]))dnl
AC_PREREQ(2.12)

AC_CANONICAL_HOST

case "$host_cpu" in
i[[3456]]86) host_cpu=i386 ;;
*) AC_MSG_ERROR([unsupported CPU type]) ;;
esac

AC_SUBST(host_cpu)
AC_SUBST(host_vendor)

#
# Options
#

AC_ARG_ENABLE(maintainer-mode,
[  --enable-maintainer-mode
                          enable the maintainer mode],
[case "x${enableval}" in
   xyes) maintainermode=yes ;;
   xno) maintainermode=no ;;
   *) AC_MSG_ERROR(invalid value ${enableval} for --enable-maintainer-mode) ;;
esac],[maintainermode=no])
AM_CONDITIONAL(GRUB_MAINT, test "x${maintainermode}" = xyes)

# This should be checked before AC_PROG_CC
if test "x$CFLAGS" = x; then
  default_CFLAGS=yes
fi

#
# Programs
#

AC_CHECK_TOOL(CC, gcc)
AC_PROG_CC
AC_PROG_RANLIB

# optimization flags
if test "x$ac_cv_prog_gcc" = xyes; then
  if test "x$default_CFLAGS" = xyes; then
    CFLAGS="-g"
    STAGE1_CFLAGS="-O2"
    GRUB_CFLAGS="-O2"
    AC_CACHE_CHECK([whether optimization for size works], size_flag, [
      saved_CFLAGS=$CFLAGS
      CFLAGS="-Os -g"
      AC_TRY_COMPILE(, , size_flag=yes, size_flag=no)
      CFLAGS=$saved_CFLAGS
    ])
    if test "x$size_flag" = xyes; then
      STAGE2_CFLAGS="-Os"
    else
      STAGE2_CFLAGS="-O2 -fno-strength-reduce -fno-unroll-loops"
    fi
  fi
fi

AC_SUBST(STAGE1_CFLAGS)
AC_SUBST(STAGE2_CFLAGS)
AC_SUBST(GRUB_CFLAGS)

# Enforce coding standards.
CPPFLAGS="$CPPFLAGS -Wall -Wmissing-prototypes -Wunused"

AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(OBJCOPY, objcopy)

# Defined in acinclude.m4.
grub_ASM_EXT_C
grub_PROG_OBJCOPY_ABSOLUTE
if test "x$grub_cv_prog_objcopy_absolute" != xyes; then
  AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
fi

grub_ASM_ADDR32
if test "x$grub_cv_asm_addr32" != xyes; then
  AC_MSG_ERROR([GRUB requires GAS .code16 addr32 support; upgrade your binutils])
fi

# Check for curses libraries.
AC_CHECK_LIB(ncurses, getch, [GRUB_LIBS="$GRUB_LIBS -lncurses"
AC_DEFINE(HAVE_LIBCURSES)],
		[AC_CHECK_LIB(curses, getch, [GRUB_LIBS="$GRUB_LIBS -lcurses"
AC_DEFINE(HAVE_LIBCURSES)])])
AC_SUBST(GRUB_LIBS)

AC_OUTPUT([Makefile stage1/Makefile stage2/Makefile docs/Makefile \
	debian/Makefile grub/Makefile])
