]> git.proxmox.com Git - grub2.git/blobdiff - configure.ac
* grub-core/commands/legacycfg.c (grub_cmd_legacy_kernel): Fix
[grub2.git] / configure.ac
index 7d3aeac9c3709bf7e5d471982769acabb6ebda6b..1094b9249b5e7347ba3bd377e9c70dfe3d3f7a97 100644 (file)
@@ -41,7 +41,9 @@ AC_CONFIG_AUX_DIR([build-aux])
 
 # Checks for host and target systems.
 AC_CANONICAL_HOST
+save_program_prefix="${program_prefix}"
 AC_CANONICAL_TARGET
+program_prefix="${save_program_prefix}"
 
 AM_INIT_AUTOMAKE()
 AC_PREREQ(2.60)
@@ -73,6 +75,8 @@ if test "x$TARGET_CFLAGS" = x; then
   TARGET_CFLAGS="$TARGET_CFLAGS -Os"
 fi
 
+BUILD_CPPFLAGS="$BUILD_CPPFLAGS -DLOCALEDIR=\\\"\$(localedir)\\\""
+
 # Default HOST_CPPFLAGS
 HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
 HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
@@ -96,6 +100,9 @@ case "$target_cpu" in
                 target_cpu=mips;
                machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS=1";
                ;;
+  arm*)
+               target_cpu=arm;
+               ;;
 esac
 
 # Specify the platform (such as firmware).
@@ -116,6 +123,7 @@ if test "x$with_platform" = x; then
     mipsel-*) platform=loongson ;;
     mips-*) platform=arc ;;
     ia64-*) platform=efi ;;
+    arm-*) platform=uboot ;;
     *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
   esac
 else
@@ -151,17 +159,21 @@ case "$target_cpu"-"$platform" in
   mipsel-yeeloong) platform=loongson ;;
   mipsel-fuloong) platform=loongson ;;
   mipsel-loongson) ;;
+  arm-uboot) ;;
+  arm-efi) ;;
   *-emu) ;;
   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
 esac
 
-case "$target_cpu" in
-  i386 | powerpc) target_m32=1 ;;
-  x86_64 | sparc64) target_m64=1 ;;
-esac
+if test x$platform != xemu ; then
+   case "$target_cpu" in
+       i386 | powerpc) target_m32=1 ;;
+       x86_64 | sparc64) target_m64=1 ;;
+   esac
+fi
 
-case "$host_os" in
-  mingw32*) host_os=cygwin ;;
+case "$target_os" in
+  windows* | mingw32*) target_os=cygwin ;;
 esac
 
 # This normalizes the names, and creates a new variable ("host_kernel")
@@ -174,7 +186,7 @@ case "$host_os" in
   netbsd*)                     host_kernel=netbsd ;;
   solaris*)                    host_kernel=illumos ;;
   darwin*)                     host_kernel=xnu ;;
-  cygwin)                      host_kernel=windows ;;
+  cygwin | windows* | mingw32*)        host_kernel=windows ;;
 esac
 
 case "$platform" in
@@ -182,6 +194,7 @@ case "$platform" in
   multiboot)   machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
   efi)         machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
   ieee1275)    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
+  uboot)       machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
   qemu)                machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
   pc)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
   emu)         machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
@@ -190,6 +203,7 @@ case "$platform" in
   arc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
 esac
 case "$target_cpu" in
+  arm)         machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARM=1" ;;
   mips |mipsel)        machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;;
   sparc64)      machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_SPARC64=1" ;;
 esac
@@ -274,23 +288,6 @@ if test "x$YACC" = x; then
   AC_MSG_ERROR([bison is not found])
 fi
 
-FONT_SOURCE=
-
-for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
-  for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni; do
-    if test -f "$dir/unifont.$ext"; then
-      FONT_SOURCE="$dir/unifont.$ext"
-      break 2
-    fi
-  done
-done
-
-if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips); then
-   AC_MSG_ERROR([qemu and loongson ports need unifont])
-fi
-
-AC_SUBST([FONT_SOURCE])
-
 AC_PROG_RANLIB
 AC_PROG_INSTALL
 AC_PROG_AWK
@@ -320,21 +317,34 @@ AC_PATH_PROGS(MAKEINFO, makeinfo true)
 
 AC_PROG_CC
 gl_EARLY
+AC_PROG_CXX
 AM_PROG_CC_C_O
 AM_PROG_AS
 
 # Must be GCC.
 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
 
+AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
+
 AC_GNU_SOURCE
 AM_GNU_GETTEXT([external])
 AC_SYS_LARGEFILE
 
 # Identify characteristics of the host architecture.
+unset ac_cv_c_bigendian
+
 AC_C_BIGENDIAN
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
 
+case "$host_os" in
+  cygwin | windows* | mingw32*)
+     HOST_CPPFLAGS="$HOST_CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
+     CPPFLAGS="$CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
+     AC_CHECK_SIZEOF(TCHAR,,[#include <windows.h>])
+   ;;
+esac
+
 grub_apple_cc
 if test x$grub_cv_apple_cc = xyes ; then
   HOST_CPPFLAGS="$HOST_CPPFLAGS -fnested-functions"
@@ -352,7 +362,7 @@ else
 fi
 
 # Check for functions and headers.
-AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf getextmntent)
+AC_CHECK_FUNCS(posix_memalign memalign getextmntent)
 AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h limits.h)
 
 AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
@@ -395,9 +405,14 @@ fi
 # Check for host and build compilers.
 #
 HOST_CC=$CC
-AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc],
-                 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])])
+AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc])
+test -z "$BUILD_CC" && AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])
+BUILD_CPP="$BUILD_CC -E"
 
+case "$build_os" in
+  haiku*)                              BUILD_LIBM= ;;
+  *)                                   BUILD_LIBM=-lm ;;
+esac
 # For gnulib.
 gl_INIT
 
@@ -412,22 +427,31 @@ if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
 
   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
-  AC_CHECK_TOOL(OBJCOPY, objcopy)
-  AC_CHECK_TOOL(STRIP, strip)
-  AC_CHECK_TOOL(NM, nm)
+  AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
+  AC_CHECK_TOOL(TARGET_STRIP, strip)
+  AC_CHECK_TOOL(TARGET_NM, nm)
+  AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
 
   ac_tool_prefix="$tmp_ac_tool_prefix"
 else
   if test "x$TARGET_CC" = x; then
     TARGET_CC=$CC
   fi
-  AC_CHECK_TOOL(OBJCOPY, objcopy)
-  AC_CHECK_TOOL(STRIP, strip)
-  AC_CHECK_TOOL(NM, nm)
+  AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
+  AC_CHECK_TOOL(TARGET_STRIP, strip)
+  AC_CHECK_TOOL(TARGET_NM, nm)
+  AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
 fi
+
 AC_SUBST(HOST_CC)
 AC_SUBST(BUILD_CC)
+AC_SUBST(BUILD_CFLAGS)
+AC_SUBST(BUILD_CPPFLAGS)
 AC_SUBST(TARGET_CC)
+AC_SUBST(TARGET_NM)
+AC_SUBST(TARGET_RANLIB)
+AC_SUBST(TARGET_STRIP)
+AC_SUBST(TARGET_OBJCOPY)
 
 # Test the C compiler for the target environment.
 tmp_CC="$CC"
@@ -441,8 +465,13 @@ CPPFLAGS="$TARGET_CPPFLAGS"
 LDFLAGS="$TARGET_LDFLAGS"
 LIBS=""
 
+grub_PROG_NM_MINUS_P
+grub_PROG_NM_DEFINED_ONLY
+AC_SUBST(TARGET_NMFLAGS_MINUS_P)
+AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)
+
 # debug flags.
-WARN_FLAGS="-Wall -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Wattributes -Wcast-align -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign"
+WARN_FLAGS="-Wall -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Wattributes -Wcast-align -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign"
 HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS"
 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
@@ -461,12 +490,18 @@ if test "x$target_cpu" = xi386; then
   else
     TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
   fi
+fi
 
+if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
   # Some toolchains enable these features by default, but they need
   # registers that aren't set up properly in GRUB.
   TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow"
 fi
 
+if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
+  TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
+fi
+
 # By default, GCC 4.4 generates .eh_frame sections containing unwind
 # information in some cases where it previously did not. GRUB doesn't need
 # these and they just use up vital space. Restore the old compiler
@@ -484,6 +519,19 @@ if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
 fi
 
+if test x"$target_os" = xcygwin; then
+  AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
+    CFLAGS="$CFLAGS -fno-reorder-functions"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
+                     [grub_cv_cc_no_reorder_functions=yes],
+                     [grub_cv_cc_no_reorder_functions=no])
+  ])
+fi
+
+if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
+  TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
+fi
+
 # By default, GCC 4.6 generates .eh_frame sections containing unwind
 # information in some cases where it previously did not. GRUB doesn't need
 # these and they just use up vital space. Restore the old compiler
@@ -507,11 +555,11 @@ if test x$grub_cv_apple_target_cc = xyes ; then
 
   CFLAGS="$CFLAGS -fnested-functions"
   TARGET_APPLE_CC=1
-  AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
-  if test "x$OBJCONV" = x ; then
-     AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
+  AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
+  if test "x$TARGET_OBJCONV" = x ; then
+     AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
   fi
-  if test "x$OBJCONV" = x ; then
+  if test "x$TARGET_OBJCONV" = x ; then
     AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
   fi
   TARGET_IMG_LDSCRIPT=
@@ -524,10 +572,10 @@ else
   TARGET_APPLE_CC=0
   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
 # Use linker script if present, otherwise use builtin -N script.
-if test -f "${srcdir}/${grub_coredir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
-  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
+if test -f "${srcdir}/${grub_coredir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"; then
+  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
-  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
+  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
 else
   TARGET_IMG_LDSCRIPT=
@@ -542,8 +590,8 @@ AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
 
 # For platforms where ELF is not the default link format.
 AC_MSG_CHECKING([for command to convert module to ELF format])
-case "${host_os}" in
-  cygwin) TARGET_OBJ2ELF='$(top_builddir)/grub-pe2elf';
+case "${target_os}" in
+  cygwin) TARGET_OBJ2ELF='./build-grub-pe2elf';
 # FIXME: put proper test here
   NEED_REGISTER_FRAME_INFO=1
   ;;
@@ -558,6 +606,9 @@ AC_ARG_ENABLE([efiemu],
 if test x"$enable_efiemu" = xno ; then
   efiemu_excuse="explicitly disabled"
 fi
+if test x"$target_os" = xcygwin ; then
+  efiemu_excuse="not available on cygwin"
+fi
 if test x"$target_cpu" != xi386 ; then
   efiemu_excuse="only available on i386"
 fi
@@ -605,7 +656,44 @@ if test "x$target_m64" = x1; then
   TARGET_MODULE_FORMAT="elf64"
 fi
 
-if test "$target_cpu"-"$platform" = x86_64-efi; then
+case "$target_os" in
+  cygwin)
+    ;;
+  freebsd)
+    if test x"$target_cpu" = xi386; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_i386_fbsd"
+    fi
+    if test x"$target_cpu" = xx86_64; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_x86_64_fbsd"
+    fi
+    ;;
+  openbsd*)
+    if test x"$target_cpu" = xi386; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_i386_obsd"
+    fi
+    if test x"$target_cpu" = xx86_64; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_x86_64_obsd"
+    fi
+    ;;
+  haiku*)
+    if test x"$target_cpu" = xi386; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_i386_haiku"
+    fi
+    if test x"$target_cpu" = xx86_64; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_x86_64_haiku"
+    fi
+    ;;
+  *)
+    if test x"$target_cpu" = xi386; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_i386"
+    fi
+    if test x"$target_cpu" = xx86_64; then
+      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,-melf_x86_64"
+    fi
+    ;;
+esac
+
+if test "$target_cpu" = x86_64; then
   # Use large model to support 4G memory
   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
     SAVED_CFLAGS=$CFLAGS
@@ -619,7 +707,9 @@ if test "$target_cpu"-"$platform" = x86_64-efi; then
   else
     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
   fi
+fi
 
+if test "$target_cpu"-"$platform" = x86_64-efi; then
   # EFI writes to stack below %rsp, we must not use the red zone
   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
     CFLAGS="$CFLAGS -m64 -mno-red-zone"
@@ -668,6 +758,14 @@ if test x"$sap_possible" = xyes; then
   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
 fi
 
+# -mno-unaligned-access
+if test "$target_cpu" = arm; then
+  grub_CHECK_NO_UNALIGNED_ACCESS
+  if test x"$nua_possible" = xyes; then
+    TARGET_CFLAGS="$TARGET_CFLAGS -mno-unaligned-access"
+  fi
+fi
+
 AC_ARG_ENABLE([werror],
              [AS_HELP_STRING([--disable-werror],
                              [do not use -Werror when building GRUB])])
@@ -685,7 +783,7 @@ GRUB_PLATFORM="${platform}"
 AC_SUBST(GRUB_TARGET_CPU)
 AC_SUBST(GRUB_PLATFORM)
 
-AC_SUBST(OBJCONV)
+AC_SUBST(TARGET_OBJCONV)
 AC_SUBST(TARGET_CPP)
 AC_SUBST(TARGET_CCAS)
 AC_SUBST(TARGET_OBJ2ELF)
@@ -707,6 +805,8 @@ AC_SUBST(HOST_LDFLAGS)
 AC_SUBST(HOST_CPPFLAGS)
 AC_SUBST(HOST_CCASFLAGS)
 
+AC_SUBST(BUILD_LIBM)
+
 # Set them to their new values for the tests below.
 CC="$TARGET_CC"
 if test "x$TARGET_APPLE_CC" = x1 ; then
@@ -748,7 +848,7 @@ if test "x$target_cpu" = xi386; then
   if test "$platform" != emu && test "x$TARGET_APPLE_CC" != x1 ; then
     if test ! -z "$TARGET_IMG_LDSCRIPT"; then
       # Check symbols provided by linker script.
-      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},8000 -Wl,--defsym,___main=0x8100"
+      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000 -Wl,--defsym,___main=0x8100"
     fi
     grub_CHECK_BSS_START_SYMBOL
     grub_CHECK_END_SYMBOL
@@ -842,22 +942,6 @@ AC_ARG_ENABLE([grub-emu-pci],
                              [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
 
 if test "$platform" = emu; then
-  missing_ncurses=
-[# Check for curses libraries.]
-  AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
-    [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
-      [missing_ncurses=[true]])])
-  AC_SUBST([LIBCURSES])
-[if [ x"$missing_ncurses" = x ]; then ]
-  [# Check for headers.]
-  AC_CHECK_HEADERS([ncurses/curses.h], [],
-    [AC_CHECK_HEADERS([ncurses.h], [],
-      [AC_CHECK_HEADERS([curses.h], [],
-       [missing_ncurses=[true]])])])
-[fi]
-if test x"$missing_ncurses" = xtrue ; then
-  AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
-fi
 
 if test x"$enable_grub_emu_usb" != xyes ; then
    grub_emu_usb_excuse="not enabled"
@@ -942,6 +1026,13 @@ fi
 AC_SUBST([enable_grub_emu_sdl])
 AC_SUBST([enable_grub_emu_usb])
 AC_SUBST([enable_grub_emu_pci])
+
+else
+
+# Ignore --enable-emu-* if platform is not emu
+enable_grub_emu_sdl=no
+enable_grub_emu_usb=no
+enable_grub_emu_pci=no
 fi
 
 AC_ARG_ENABLE([grub-mkfont],
@@ -953,16 +1044,18 @@ fi
 
 if test x"$grub_mkfont_excuse" = x ; then
   # Check for freetype libraries.
-  AC_CHECK_PROGS([FREETYPE], [freetype-config])
+  AC_CHECK_TOOLS([FREETYPE], [freetype-config])
   if test "x$FREETYPE" = x ; then
     grub_mkfont_excuse=["need freetype2 library"]
   fi
 fi
 
+unset ac_cv_header_ft2build_h
+
 if test x"$grub_mkfont_excuse" = x ; then
   # Check for freetype libraries.
-  freetype_cflags=`freetype-config --cflags`
-  freetype_libs=`freetype-config --libs`
+  freetype_cflags=`$FREETYPE --cflags`
+  freetype_libs=`$FREETYPE --libs`
   SAVED_CPPFLAGS="$CPPFLAGS"
   CPPFLAGS="$CPPFLAGS $freetype_cflags"
   AC_CHECK_HEADERS([ft2build.h], [],
@@ -978,19 +1071,80 @@ enable_grub_mkfont=yes
 else
 enable_grub_mkfont=no
 fi
-if test x"$enable_grub_mkfont" = xno && test "x$platform" = xloongson; then
-  AC_MSG_ERROR([loongson port needs grub-mkfont])
-fi
 AC_SUBST([enable_grub_mkfont])
 AC_SUBST([freetype_cflags])
 AC_SUBST([freetype_libs])
 
+SAVED_CC="$CC"
+SAVED_CPP="$CPP"
+SAVED_CFLAGS="$CFLAGS"
+SAVED_CPPFLAGS="$CPPFLAGS"
+CC="$BUILD_CC"
+CPP="$BUILD_CPP"
+CFLAGS="$BUILD_CFLAGS"
+CPPFLAGS="$BUILD_CPPFLAGS"
+
+unset ac_cv_c_bigendian
+unset ac_cv_header_ft2build_h
+
+AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
+AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
+AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
+
+if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
+   AC_MSG_ERROR([couldnt determine build endianness])
+fi
+
+AC_SUBST([BUILD_SIZEOF_LONG])
+AC_SUBST([BUILD_SIZEOF_VOID_P])
+AC_SUBST([BUILD_WORDS_BIGENDIAN])
+
+if test x"$grub_build_mkfont_excuse" = x ; then
+  # Check for freetype libraries.
+  AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
+  if test "x$BUILD_FREETYPE" = x ; then
+    grub_build_mkfont_excuse=["need freetype2 library"]
+  fi
+fi
+
+if test x"$grub_build_mkfont_excuse" = x ; then
+  # Check for freetype libraries.
+  build_freetype_cflags=`$BUILD_FREETYPE --cflags`
+  build_freetype_libs=`$BUILD_FREETYPE --libs`
+  SAVED_CPPFLAGS_2="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $build_freetype_cflags"
+  AC_CHECK_HEADERS([ft2build.h], [],
+       [grub_build_mkfont_excuse=["need freetype2 headers"]])
+  CPPFLAGS="$SAVED_CPPFLAGS_2"
+fi
+
+if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
+  AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled])
+fi
+if test x"$grub_build_mkfont_excuse" = x ; then
+  enable_build_grub_mkfont=yes
+else
+  enable_build_grub_mkfont=no
+fi
+if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 ); then
+  AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports needs build-time grub-mkfont])
+fi
+
+AC_SUBST([build_freetype_cflags])
+AC_SUBST([build_freetype_libs])
+
+CC="$SAVED_CC"
+CPP="$SAVED_CPP"
+CFLAGS="$SAVED_CFLAGS"
+CPPFLAGS="$SAVED_CPPFLAGS"
+
+
 DJVU_FONT_SOURCE=
 
 starfield_excuse=
 
-if test x$enable_grub_mkfont = xno; then
-   starfield_excuse="No grub-mkfont"
+if test x"$enable_build_grub_mkfont" = xno ; then
+  starfield_excuse="No build-time grub-mkfont"
 fi
 
 if test x"$starfield_excuse" = x; then
@@ -1010,6 +1164,32 @@ fi
 
 AC_SUBST([DJVU_FONT_SOURCE])
 
+FONT_SOURCE=
+
+for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
+  for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont /usr/share/fonts/uni /usr/share/fonts/truetype/unifont /usr/share/fonts/misc; do
+    if test -f "$dir/unifont.$ext"; then
+      FONT_SOURCE="$dir/unifont.$ext"
+      break 2
+    fi
+  done
+done
+
+if test x"$enable_build_grub_mkfont" = xno ; then
+  FONT_SOURCE=
+fi
+
+if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 ); then
+   AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports need unifont])
+fi
+
+AC_SUBST([FONT_SOURCE])
+
+if test x"$FONT_SOURCE" = x &&  test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
+  grub_build_mkfont_excuse="no fonts"
+fi
+
+
 AC_ARG_ENABLE([grub-mount],
              [AS_HELP_STRING([--enable-grub-mount],
                              [build and install the `grub-mount' utility (default=guessed)])])
@@ -1109,7 +1289,7 @@ if test x"$libzfs_excuse" = x ; then
 fi
 
 if test x"$libzfs_excuse" = x ; then
-  AC_CHECK_LIB([nvpair], [nvlist_print],
+  AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
                [],
                [libzfs_excuse="need nvpair library"])
 fi
@@ -1146,7 +1326,6 @@ AC_SUBST(BSS_START_SYMBOL)
 AC_SUBST(END_SYMBOL)
 AC_SUBST(PACKAGE)
 AC_SUBST(VERSION)
-AC_SUBST(NEED_ENABLE_EXECUTE_STACK)
 AC_SUBST(NEED_REGISTER_FRAME_INFO)
 
 #
@@ -1170,6 +1349,9 @@ AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platf
 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
 AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
+AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
+AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
+AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
 
 AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
 AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
@@ -1186,14 +1368,15 @@ AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
 AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
 AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
 AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
-AM_CONDITIONAL([COND_GRUB_PE2ELF], [test x$TARGET_OBJ2ELF != x])
 AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1])
 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
 
+AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
+
 AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
-AM_CONDITIONAL([COND_CYGWIN], [test x$host_os = xcygwin])
+AM_CONDITIONAL([COND_CYGWIN], [test x$target_os = xcygwin])
 AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
 
 # Output files.
@@ -1295,5 +1478,21 @@ echo With libzfs support: Yes
 else
 echo With libzfs support: No "($libzfs_excuse)"
 fi
+if [ x"$grub_build_mkfont_excuse" = x ]; then
+  echo Build-time grub-mkfont: Yes
+  if test "x$FONT_SOURCE" = x ; then
+    echo "Without unifont"
+  else
+    echo "With unifont from $FONT_SOURCE"
+  fi
+else
+  echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
+  echo "Without unifont (no build-time grub-mkfont)"
+fi
+if test "x$LIBLZMA" = x ; then
+echo "Without liblzma (no support for XZ-compressed mips images)"
+else
+echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
+fi
 echo "*******************************************************"
 ]