zfs: remove size_t typedef and use grub_size_t instead
[grub.git] / configure.ac
1 # -*- autoconf -*-
2
3 # Process this file with autoconf to produce a configure script.
4
5 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
6 #
7 # This configure.ac is free software; the author
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
13 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 # PARTICULAR PURPOSE.
15
16 dnl This configure script is complicated, because GRUB needs to deal
17 dnl with three potentially different types:
18 dnl
19 dnl   build  -- the environment for building GRUB
20 dnl   host   -- the environment for running utilities
21 dnl   target -- the environment for running GRUB
22 dnl
23 dnl In addition, GRUB needs to deal with a platform specification
24 dnl which specifies the system running GRUB, such as firmware.
25 dnl This is necessary because the target type in autoconf does not
26 dnl describe such a system very well.
27 dnl
28 dnl The current strategy is to use variables with no prefix (such as
29 dnl CC, CFLAGS, etc.) for the host type, variables with prefix "BUILD_"
30 dnl (such as BUILD_CC, BUILD_CFLAGS, etc.) for the build type and variables
31 dnl with the prefix "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are
32 dnl used for the target type. See INSTALL for full list of variables.
33
34 AC_INIT([GRUB],[2.03],[bug-grub@gnu.org])
35
36 AC_CONFIG_AUX_DIR([build-aux])
37
38 # We don't want -g -O2 by default in CFLAGS
39 : ${CFLAGS=""}
40
41 # Checks for build, host and target systems.
42 AC_CANONICAL_BUILD
43 AC_CANONICAL_HOST
44 save_program_prefix="${program_prefix}"
45 AC_CANONICAL_TARGET
46 program_prefix="${save_program_prefix}"
47
48 AM_INIT_AUTOMAKE([1.10.1])
49 AC_PREREQ(2.60)
50 AC_CONFIG_SRCDIR([include/grub/dl.h])
51 AC_CONFIG_HEADER([config-util.h])
52
53 # Program name transformations
54 AC_ARG_PROGRAM
55 grub_TRANSFORM([grub-bios-setup])
56 grub_TRANSFORM([grub-editenv])
57 grub_TRANSFORM([grub-install])
58 grub_TRANSFORM([grub-mkconfig])
59 grub_TRANSFORM([grub-mkfont])
60 grub_TRANSFORM([grub-mkimage])
61 grub_TRANSFORM([grub-glue-efi])
62 grub_TRANSFORM([grub-mklayout])
63 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
64 grub_TRANSFORM([grub-mkrelpath])
65 grub_TRANSFORM([grub-mkrescue])
66 grub_TRANSFORM([grub-probe])
67 grub_TRANSFORM([grub-reboot])
68 grub_TRANSFORM([grub-script-check])
69 grub_TRANSFORM([grub-set-default])
70 grub_TRANSFORM([grub-sparc64-setup])
71 grub_TRANSFORM([grub-render-label])
72 grub_TRANSFORM([grub-file])
73
74 # Optimization flag.  Allow user to override.
75 if test "x$TARGET_CFLAGS" = x; then
76   TARGET_CFLAGS="$TARGET_CFLAGS -Os"
77 fi
78
79 # Default HOST_CPPFLAGS
80 HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
81 HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"
82
83 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W"
84
85 case "$target_cpu" in
86   i[[3456]]86)  target_cpu=i386 ;;
87   amd64)        target_cpu=x86_64 ;;
88   sparc)        target_cpu=sparc64 ;;
89   mipsel|mips64el)
90                 target_cpu=mipsel
91                 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1"
92                 ;;
93   mips|mips64)
94                 target_cpu=mips
95                 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS=1"
96                 ;;
97   arm*)
98                 target_cpu=arm
99                 ;;
100   aarch64*)
101                 target_cpu=arm64
102                 ;;
103 esac
104
105 # Specify the platform (such as firmware).
106 AC_ARG_WITH([platform],
107             AS_HELP_STRING([--with-platform=PLATFORM],
108                            [select the host platform [[guessed]]]))
109
110 # Guess the platform if not specified.
111 if test "x$with_platform" = x; then
112   case "$target_cpu"-"$target_vendor" in
113     i386-apple) platform=efi ;;
114     i386-*) platform=pc ;;
115     x86_64-apple) platform=efi ;;
116     x86_64-*) platform=pc ;;
117     powerpc-*) platform=ieee1275 ;;
118     powerpc64-*) platform=ieee1275 ;;
119     powerpc64le-*) platform=ieee1275 ;;
120     sparc64-*) platform=ieee1275 ;;
121     mipsel-*) platform=loongson ;;
122     mips-*) platform=arc ;;
123     ia64-*) platform=efi ;;
124     arm-*) platform=uboot ;;
125     arm64-*) platform=efi ;;
126     *)
127       AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities])
128       platform=none
129       ;;
130   esac
131 else
132   platform="$with_platform"
133 fi
134
135 case "$target_cpu"-"$platform" in
136   x86_64-efi) ;;
137   x86_64-emu) ;;
138   x86_64-xen) ;;
139   x86_64-none) ;;
140   x86_64-*) target_cpu=i386 ;;
141   powerpc64-ieee1275) target_cpu=powerpc ;;
142   powerpc64le-ieee1275) target_cpu=powerpc ;;
143 esac
144
145 # Check if the platform is supported, make final adjustments.
146 case "$target_cpu"-"$platform" in
147   i386-efi) ;;
148   x86_64-efi) ;;
149   i386-xen) ;;
150   x86_64-xen) ;;
151   i386-pc) ;;
152   i386-multiboot) ;;
153   i386-coreboot) ;;
154   i386-linuxbios) platform=coreboot ;;
155   i386-ieee1275) ;;
156   i386-qemu) ;;
157   powerpc-ieee1275) ;;
158   sparc64-ieee1275) ;;
159   ia64-efi) ;;
160   mips-qemu_mips) ;;
161   mips-qemu-mips) platform=qemu_mips;;
162   mips-arc) ;;
163   mipsel-arc) ;;
164   mipsel-qemu_mips) ;;
165   mipsel-qemu-mips) platform=qemu_mips;;
166   mipsel-yeeloong) platform=loongson ;;
167   mipsel-fuloong) platform=loongson ;;
168   mipsel-loongson) ;;
169   arm-uboot) ;;
170   arm-coreboot) ;;
171   arm-efi) ;;
172   arm64-efi) ;;
173   *-emu) ;;
174   *-none) ;;
175   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
176 esac
177
178 if test x$platform != xemu ; then
179    case "$target_cpu" in
180         i386 | powerpc) target_m32=1 ;;
181         x86_64 | sparc64) target_m64=1 ;;
182    esac
183 fi
184
185 if test x"$target_cpu-$platform" = xsparc64-emu ; then
186    target_m64=1
187 fi
188
189 case "$target_os" in
190   windows* | mingw32*) target_os=cygwin ;;
191 esac
192
193 # This normalizes the names, and creates a new variable ("host_kernel")
194 # while at it, since the mapping is not always 1:1 (e.g. different OSes
195 # using the same kernel type).
196 case "$host_os" in
197   gnu*)                         host_kernel=hurd ;;
198   linux*)                       host_kernel=linux ;;
199   freebsd* | kfreebsd*-gnu)     host_kernel=kfreebsd ;;
200   netbsd*)                      host_kernel=netbsd ;;
201   solaris*)                     host_kernel=illumos ;;
202   darwin*)                      host_kernel=xnu ;;
203   cygwin | windows* | mingw32*) host_kernel=windows ;;
204 esac
205
206 case "$host_os" in
207   cygwin | windows* | mingw32*) have_exec=n ;;
208   aros*) have_exec=n ;;
209   *) have_exec=y;;
210 esac
211
212 case "$platform" in
213   coreboot)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_COREBOOT=1" ;;
214   multiboot)    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
215   efi)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
216   xen)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
217   ieee1275)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
218   uboot)        machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
219   qemu)         machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
220   pc)           machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
221   emu)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
222   loongson)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1" ;;
223   qemu_mips)    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1" ;;
224   arc)  machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
225 esac
226 if test x${target_cpu} = xmipsel ; then
227    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
228 else
229    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
230 fi
231
232 case "${target_cpu}-$platform" in
233      mips-arc)
234         TARGET_LINK_ADDR=0x88200000
235         TARGET_DECOMPRESSOR_LINK_ADDR=0x88100000
236         ;;
237      mipsel-arc)
238         TARGET_LINK_ADDR=0x80700000
239         TARGET_DECOMPRESSOR_LINK_ADDR=0x80600000
240         ;;
241      mips*-qemu_mips | mips*-loongson)
242         TARGET_DECOMPRESSOR_LINK_ADDR=0x80100000
243         ;;
244 esac
245
246 AC_SUBST(TARGET_LINK_ADDR)
247 AC_SUBST(TARGET_DECOMPRESSOR_LINK_ADDR)
248
249 TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS"
250
251 AC_SUBST(host_cpu)
252 AC_SUBST(host_os)
253 AC_SUBST(host_kernel)
254
255 AC_SUBST(target_cpu)
256 AC_SUBST(platform)
257
258 # Define default variables
259
260 have_with_bootdir=n
261 AC_ARG_WITH([bootdir],
262             AS_HELP_STRING([--with-bootdir=DIR],
263                            [set the name of /boot directory [[guessed]]]),
264                            [have_with_bootdir=y],
265                            [have_with_bootdir=n])
266 if test x$have_with_bootdir = xy; then
267    bootdirname="$with_bootdir"
268 else
269    case "$host_os" in
270      netbsd* | openbsd*)
271         # Because /boot is used for the boot block in NetBSD and OpenBSD,
272            bootdirname=''      ;;
273      *)    bootdirname='boot'  ;;
274    esac
275 fi
276
277 AC_SUBST(bootdirname)
278 AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname",
279     [Default boot directory name]")
280
281 AC_ARG_WITH([grubdir],
282             AS_HELP_STRING([--with-grubdir=DIR],
283                            [set the name of grub directory [[guessed]]]),
284                            [grubdirname="$with_grubdir"],
285                            [grubdirname="$PACKAGE"])
286
287 AC_SUBST(grubdirname)
288 AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
289     [Default grub directory name])
290
291 #
292 # Checks for build programs.
293 #
294
295 # Although cmp is listed in the GNU Coding Standards as a command which
296 # can used directly, OpenBSD lacks cmp in the default installation.
297 AC_CHECK_PROGS([CMP], [cmp])
298 if test "x$CMP" = x; then
299   AC_MSG_ERROR([cmp is not found])
300 fi
301
302 AC_CHECK_PROGS([YACC], [bison])
303 if test "x$YACC" = x; then
304   AC_MSG_ERROR([bison is not found])
305 fi
306
307 AC_PROG_RANLIB
308 AC_PROG_INSTALL
309 AC_PROG_AWK
310 AC_PROG_LEX
311 AC_PROG_YACC
312 AC_PROG_MAKE_SET
313 AC_PROG_MKDIR_P
314 AC_PROG_LN_S
315
316 if test "x$LEX" = "x:"; then
317   AC_MSG_ERROR([flex is not found])
318 else
319   version=`$LEX --version | $AWK '{ split($2,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
320   if test -n "$version" -a "$version" -ge 20535; then
321     :
322   else
323     AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
324   fi
325 fi
326
327 # These are not a "must".
328 AC_PATH_PROGS(MAKEINFO, makeinfo true)
329
330 #
331 # Checks for host programs.
332 #
333
334 AC_PROG_CC
335 gl_EARLY
336 AC_PROG_CXX
337 AM_PROG_CC_C_O
338 AM_PROG_AS
339
340 # Must be GCC.
341 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
342
343 AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
344
345 AC_GNU_SOURCE
346 AM_GNU_GETTEXT([external])
347 AC_SYS_LARGEFILE
348
349 # Identify characteristics of the host architecture.
350 unset ac_cv_c_bigendian
351
352 if test x"$target_cpu-$platform" = xsparc64-emu ; then
353   CFLAGS="$CFLAGS -m64"
354   HOST_CFLAGS="$HOST_CFLAGS -m64"
355 fi
356
357 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
358 HOST_CPPFLAGS="$HOST_CPPFLAGS -D_FILE_OFFSET_BITS=64"
359
360 AC_C_BIGENDIAN
361 AC_CHECK_SIZEOF(void *)
362 AC_CHECK_SIZEOF(long)
363
364 case "$host_os" in
365   cygwin | windows* | mingw32*)
366      HOST_CPPFLAGS="$HOST_CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
367      CPPFLAGS="$CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
368      AC_CHECK_SIZEOF(TCHAR,,[#include <windows.h>])
369    ;;
370 esac
371
372 case "$host_os" in
373   cygwin | windows* | mingw32* | aros*)
374      ;;
375   *)
376      AC_CHECK_SIZEOF(off_t)
377      if test x"$ac_cv_sizeof_off_t" != x8 ; then
378        AC_CHECK_SIZEOF(off64_t)
379        test x"$ac_cv_sizeof_off64_t" = x8 || AC_MSG_ERROR([Large file support is required])
380      fi;;
381 esac
382
383 if test x$USE_NLS = xno; then
384   HOST_CFLAGS="$HOST_CFLAGS -fno-builtin-gettext"
385 fi
386
387 if test "x$cross_compiling" = xyes; then
388   AC_MSG_WARN([cannot generate manual pages while cross compiling])
389 else
390   AC_PATH_PROG(HELP2MAN, help2man)
391 fi
392
393 # Check for functions and headers.
394 AC_CHECK_FUNCS(posix_memalign memalign getextmntent)
395 AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h limits.h)
396
397 # glibc 2.25 still includes sys/sysmacros.h in sys/types.h but emits deprecation
398 # warning which causes compilation failure later with -Werror. So use -Werror here
399 # as well to force proper sys/sysmacros.h detection.
400 SAVED_CFLAGS="$CFLAGS"
401 CFLAGS="$HOST_CFLAGS -Werror"
402 AC_HEADER_MAJOR
403 CFLAGS="$SAVED_CFLAGS"
404
405 AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
406 #include <sys/param.h>
407 #include <sys/mount.h>])
408
409 AC_CHECK_MEMBERS([struct statfs.f_mntfromname],,,[$ac_includes_default
410 #include <sys/param.h>
411 #include <sys/mount.h>])
412
413 # For opendisk() and getrawpartition() on NetBSD.
414 # Used in util/deviceiter.c and in util/hostdisk.c.
415 AC_CHECK_HEADER([util.h], [
416   AC_CHECK_LIB([util], [opendisk], [
417     LIBUTIL="-lutil"
418     AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
419   ])
420   AC_CHECK_LIB([util], [getrawpartition], [
421     LIBUTIL="-lutil"
422     AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
423   ])
424 ])
425 AC_SUBST([LIBUTIL])
426
427 AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_host_cc_wtrampolines], [
428   SAVED_CFLAGS="$CFLAGS"
429   CFLAGS="$HOST_CFLAGS -Wtrampolines -Werror"
430   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
431 int va_arg_func (int fixed, va_list args);]], [[]])],
432       [grub_cv_host_cc_wtrampolines=yes],
433       [grub_cv_host_cc_wtrampolines=no])
434   CFLAGS="$SAVED_CFLAGS"
435 ])
436
437 if test x"$grub_host_cv_cc_wtrampolines" = xyes ; then
438   HOST_CFLAGS="$HOST_CFLAGS -Wtrampolines"
439 fi
440
441 #
442 # Check for host and build compilers.
443 #
444 HOST_CC=$CC
445 AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc])
446 test -z "$BUILD_CC" && AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])
447 BUILD_CPP="$BUILD_CC -E"
448
449 case "$build_os" in
450   haiku*)                               BUILD_LIBM= ;;
451   *)                                    BUILD_LIBM=-lm ;;
452 esac
453
454 dnl FIXME proper test seems to require too deep dive into Autoconf internals.
455 dnl For now just list known platforms that we support.
456
457 case "$build_os" in
458   cygwin*|mingw32*|mingw64*)            BUILD_EXEEXT=.exe ;;
459   *)                                    BUILD_EXEEXT= ;;
460 esac
461 AC_SUBST(BUILD_EXEEXT)
462
463 # In some build environments like termux /bin/sh is not a valid
464 # shebang. Use $SHELL instead if it's executable and /bin/sh isn't
465 BUILD_SHEBANG=/bin/sh
466 for she in /bin/sh "$SHELL"; do
467   if test -x "$she" ; then
468     BUILD_SHEBANG="$she"
469   fi
470 done
471 AC_SUBST(BUILD_SHEBANG)
472
473 # For gnulib.
474 gl_INIT
475
476 WARN_FLAGS="-Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes"
477 EXTRA_WARN_FLAGS="-Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2"
478
479 HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS -Wcast-align"
480
481 AC_CACHE_CHECK([which extra warnings work], [grub_cv_cc_w_extra_flags], [
482   SAVED_CFLAGS="$CFLAGS"
483   grub_cv_cc_w_extra_flags=
484   for x in $EXTRA_WARN_FLAGS; do
485       CFLAGS="$HOST_CFLAGS $x -Werror"
486       AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
487       if test x$flag = x1 ; then
488          grub_cv_cc_w_extra_flags="$grub_cv_cc_w_extra_flags $x"
489       fi
490   done
491   CFLAGS="$SAVED_CFLAGS"
492 ])
493
494 HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags"
495
496 #
497 # Check for target programs.
498 #
499
500 # Find tools for the target.
501 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
502   tmp_ac_tool_prefix="$ac_tool_prefix"
503   ac_tool_prefix=$target_alias-
504
505   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
506                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
507   AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
508   AC_CHECK_TOOL(TARGET_STRIP, strip)
509   AC_CHECK_TOOL(TARGET_NM, nm)
510   AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
511
512   ac_tool_prefix="$tmp_ac_tool_prefix"
513 else
514   if test "x$TARGET_CC" = x; then
515     TARGET_CC=$CC
516   fi
517   AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
518   AC_CHECK_TOOL(TARGET_STRIP, strip)
519   AC_CHECK_TOOL(TARGET_NM, nm)
520   AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
521 fi
522
523 AC_SUBST(HOST_CC)
524 AC_SUBST(BUILD_CC)
525 AC_SUBST(BUILD_CFLAGS)
526 AC_SUBST(BUILD_CPPFLAGS)
527 AC_SUBST(BUILD_LDFLAGS)
528 AC_SUBST(TARGET_CC)
529 AC_SUBST(TARGET_NM)
530 AC_SUBST(TARGET_RANLIB)
531 AC_SUBST(TARGET_STRIP)
532 AC_SUBST(TARGET_OBJCOPY)
533
534 # Test the C compiler for the target environment.
535 tmp_CC="$CC"
536 tmp_CFLAGS="$CFLAGS"
537 tmp_LDFLAGS="$LDFLAGS"
538 tmp_CPPFLAGS="$CPPFLAGS"
539 tmp_LIBS="$LIBS"
540 CC="$TARGET_CC"
541 CFLAGS="$TARGET_CFLAGS"
542 CPPFLAGS="$TARGET_CPPFLAGS"
543 LDFLAGS="$TARGET_LDFLAGS"
544 LIBS=""
545
546 # debug flags.
547 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
548 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
549
550 if test "x$target_cpu" != xi386 && test "x$target_cpu" != xx86_64; then
551 TARGET_CFLAGS="$TARGET_CFLAGS -Wcast-align"
552 fi
553
554 TARGET_CC_VERSION="$(LC_ALL=C $TARGET_CC --version | head -n1)"
555
556 AC_CACHE_CHECK([which extra warnings work], [grub_cv_target_cc_w_extra_flags], [
557   LDFLAGS="$TARGET_LDFLAGS -nostdlib -static"
558
559   grub_cv_target_cc_w_extra_flags=
560   for x in $EXTRA_WARN_FLAGS; do
561       CFLAGS="$TARGET_CFLAGS $x -Werror"
562       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
563 asm (".globl start; start:");
564 void __main (void);
565 void __main (void) {}
566 int main (void);
567 ]], [[]])], [flag=1], [flag=0])
568       if test x$flag = x1 ; then
569          grub_cv_target_cc_w_extra_flags="$grub_cv_target_cc_w_extra_flags $x"
570       fi
571   done
572 ])
573
574 TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_w_extra_flags"
575
576 AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang],
577 [
578 CFLAGS="$TARGET_CFLAGS"
579 AC_COMPILE_IFELSE(
580 [AC_LANG_PROGRAM([], [[
581 #ifdef __clang__
582 #error "is clang"
583 #endif
584 ]])],
585 [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
586
587 if test x$target_cpu = xpowerpc -o x$target_cpu = xmips; then
588   AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
589     grub_cv_target_cc_big_endian=no
590     for cand in "-target $target_cpu -Wl,-EB" "-target $target_cpu" \
591                 "-target $target_cpu-linux-gnu -Wl,-EB" "-target $target_cpu-linux-gnu" \
592                 "-EB" "-mbig-endian"; do
593       if test x"$grub_cv_target_cc_big_endian" != xno ; then
594         break
595       fi
596       CFLAGS="$TARGET_CFLAGS $cand -Werror"
597       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
598 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
599 #error still little endian
600 #endif
601 asm (".globl start; start:");
602 asm (".globl _start; _start:");
603 asm (".globl __start; __start:");
604 void __main (void);
605 void __main (void) {}
606 int main (void);
607 ]], [[]])],
608                         [grub_cv_target_cc_big_endian="$cand"], [])
609     done
610   ])
611
612   if test x"$grub_cv_target_cc_big_endian" = xno ; then
613     AC_MSG_ERROR([could not force big-endian])
614   fi
615
616   skip_linkflags="$(echo "$grub_cv_target_cc_big_endian"|sed 's@-Wl,-EB@@')"
617
618   TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
619   TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
620   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
621   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian"
622 elif test x$target_cpu = xmipsel; then
623   AC_CACHE_CHECK([for options to get little-endian compilation], grub_cv_target_cc_little_endian, [
624     grub_cv_target_cc_little_endian=no
625     for cand in "-target $target_cpu -Wl,-EL" "-target $target_cpu" \
626                 "-target $target_cpu-linux-gnu -Wl,-EL" "-target $target_cpu-linux-gnu" \
627                 "-EL"; do
628       if test x"$grub_cv_target_cc_little_endian" != xno ; then
629         break
630       fi
631       CFLAGS="$TARGET_CFLAGS $cand -Werror"
632       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
633 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ == __BYTE_ORDER__)
634 #error still big endian
635 #endif
636 asm (".globl start; start:");
637 asm (".globl _start; _start:");
638 asm (".globl __start; __start:");
639 void __main (void);
640 void __main (void) {}
641 int main (void);
642 ]], [[]])],
643                         [grub_cv_target_cc_little_endian="$cand"], [])
644     done
645   ])
646
647   if test x"$grub_cv_target_cc_little_endian" = xno ; then
648     AC_MSG_ERROR([could not force little-endian])
649   fi
650
651   skip_linkflags="$(echo "$grub_cv_target_cc_little_endian"|sed 's@-Wl,-EL@@')"
652
653   TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
654   TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
655   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
656   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian"
657 fi
658
659 # GRUB code is N32-compliant but it's experimental and we would prefer to
660 # avoid having too much variety when it doesn't result in any real improvement.
661 # Moreover N64 isn't supported.
662 if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
663   AC_CACHE_CHECK([for options to force MIPS o32 ABI], grub_cv_target_cc_mips_o32_abi, [
664     grub_cv_target_cc_mips_o32_abi=no
665     for arg in "" "-mabi=32" "-target $target_cpu -mabi=32" ; do
666       if test x"$grub_cv_target_cc_mips_o32_abi" != xno ; then
667         break
668       fi
669       CFLAGS="$TARGET_CFLAGS $arg -Werror"
670       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
671 #if !defined(_ABIO32) || !defined(_MIPS_SIM) || (_MIPS_SIM != _ABIO32)
672 #error not o32 ABI
673 #endif
674 asm (".globl start; start:");
675 asm (".globl _start; _start:");
676 asm (".globl __start; __start:");
677 void __main (void);
678 void __main (void) {}
679 int main (void);
680 ]], [[]])],
681                         [grub_cv_target_cc_mips_o32_abi="$arg"], [])
682     done
683   ])
684
685   if test x"$grub_cv_target_cc_mips_o32_abi" = xno ; then
686     AC_MSG_ERROR([could not force MIPS o32 ABI])
687   fi
688
689   TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mips_o32_abi"
690   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mips_o32_abi"
691 fi
692
693 AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [
694 test_program=
695 case "x$target_cpu-$platform" in
696      xmips-* | xmipsel-*)
697         test_program=mips
698         ;;
699      xi386-pc)
700        test_program=i386-pc
701         ;;
702      xi386-* | xx86_64-*)
703        test_program=i386
704         ;;
705      xpowerpc-* | xsparc64-* | xarm-*)
706         test_program=$target_cpu
707         ;;
708 esac
709 if test x"$test_program" = x ; then
710   grub_cv_cc_target_asm_compile=
711 else
712   found=no
713   for arg in "" "-no-integrated-as"; do
714     cmdline="$TARGET_CC -c -o /dev/null $TARGET_CCASFLAGS $arg $TARGET_CPPFLAGS $srcdir/asm-tests/$test_program.S"
715     echo "Running $cmdline" >&AS_MESSAGE_LOG_FD
716     if $cmdline >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
717       grub_cv_cc_target_asm_compile="$arg"
718       found=yes
719       break
720     fi
721   done
722   if test x"$found" = xno ; then
723     AC_MSG_ERROR([could not compile assembly])
724   fi
725 fi
726 ])
727
728 TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_cc_target_asm_compile"
729
730 if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
731   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
732 fi
733
734 if test "x$target_m32" = x1; then
735   # Force 32-bit mode.
736   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
737   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
738   TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
739   TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
740   TARGET_MODULE_FORMAT="elf32"
741 fi
742
743 if test "x$target_m64" = x1; then
744   # Force 64-bit mode.
745   TARGET_CFLAGS="$TARGET_CFLAGS -m64"
746   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
747   TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
748   TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
749   TARGET_MODULE_FORMAT="elf64"
750 fi
751
752 if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
753    TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
754 fi
755
756 # on mips redirect cache flushing function to non-existant one.
757 if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
758   AC_CACHE_CHECK([whether -mflush-func=grub_red_herring works], [grub_cv_cc_mflush_func], [
759     CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring -Werror"
760     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
761         [grub_cv_cc_mflush_func=yes],
762         [grub_cv_cc_mflush_func=no])
763   ])
764
765   if test "x$grub_cv_cc_mflush_func" = xyes; then
766     TARGET_CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring"
767   fi
768 fi
769
770
771 # Force no alignment to save space on i386.
772 if test "x$target_cpu" = xi386; then
773   AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
774     CFLAGS="$TARGET_CFLAGS -falign-loops=1 -Werror"
775     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
776         [grub_cv_cc_falign_loop=yes],
777         [grub_cv_cc_falign_loop=no])
778   ])
779
780   AC_CACHE_CHECK([whether -malign-loops works], [grub_cv_cc_malign_loop], [
781     CFLAGS="$TARGET_CFLAGS -malign-loops=1 -Werror"
782     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
783         [grub_cv_cc_malign_loop=yes],
784         [grub_cv_cc_malign_loop=no])
785   ])
786
787   if test "x$grub_cv_cc_falign_loop" = xyes; then
788     TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
789   elif test "x$grub_cv_cc_malign_loop" = xyes; then
790     TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
791   fi
792 fi
793
794 AC_CACHE_CHECK([whether -freg-struct-return works], [grub_cv_cc_freg_struct_return], [
795     CFLAGS="$TARGET_CFLAGS -freg-struct-return -Werror"
796     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
797         [grub_cv_cc_freg_struct_return=yes],
798         [grub_cv_cc_freg_struct_return=no])
799 ])
800
801 if test "x$grub_cv_cc_freg_struct_return" = xyes; then
802     TARGET_CFLAGS="$TARGET_CFLAGS -freg-struct-return"
803 fi
804
805 if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
806   # Some toolchains enable these features by default, but they need
807   # registers that aren't set up properly in GRUB.
808   TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow"
809 fi
810
811 # GRUB doesn't use float or doubles at all. Yet some toolchains may decide
812 # that floats are a good fit to run instead of what's written in the code.
813 # Given that floating point unit is disabled (if present to begin with)
814 # when GRUB is running which may result in various hard crashes.
815 if test x"$platform" != xemu ; then
816   AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [
817     grub_cv_target_cc_soft_float=no
818     if test "x$target_cpu" = xarm64; then
819        CFLAGS="$TARGET_CFLAGS -mgeneral-regs-only -Werror"
820        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
821                          [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], [])
822     fi
823     if test "x$target_cpu" = xia64; then
824        CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
825        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
826                          [grub_cv_target_cc_soft_float="-mno-inline-float-divide -mno-inline-sqrt"], [])
827     fi
828     for cand in "-msoft-float -Xclang -msoft-float -Xclang -no-implicit-float" \
829                 "-Xclang -msoft-float -Xclang -no-implicit-float" \
830                 "-Xclang -msoft-float" "-msoft-float"; do
831       if test x"$grub_cv_target_cc_soft_float" != xno ; then
832         break
833       fi
834       CFLAGS="$TARGET_CFLAGS $cand -Werror"
835       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
836                         [grub_cv_target_cc_soft_float="$cand"], [])
837     done
838   ])
839
840   if test x"$grub_cv_target_cc_soft_float" = xno ; then
841     AC_MSG_ERROR([could not force soft-float])
842   fi
843
844   case x"$grub_cv_target_cc_soft_float" in
845     x*"-Xclang"*)
846       # A trick so that clang doesn't see it on link stаge
847       TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_soft_float"
848       ;;
849     *)
850       TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_soft_float"
851       ;;
852   esac
853   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_soft_float"
854
855 fi
856
857 if test x"$target_cpu" = xsparc64 ; then
858   AC_CACHE_CHECK([for options to reserve application registers], grub_cv_target_cc_mno_app_regs, [
859     grub_cv_target_cc_mno_app_regs=no
860     for cand in "-mllvm -sparc-reserve-app-registers" \
861                 "-mno-app-regs"; do
862       if test x"$grub_cv_target_cc_mno_app_regs" != xno ; then
863         break
864       fi
865       CFLAGS="$TARGET_CFLAGS $cand -Werror"
866       CPPFLAGS="$TARGET_CPPFLAGS"
867       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
868                         [grub_cv_target_cc_mno_app_regs="$cand"], [])
869     done
870   ])
871
872   if test x"$grub_cv_target_cc_mno_app_regs" = xno ; then
873     AC_MSG_ERROR([could not reserve application registers])
874   fi
875   if test x"$grub_cv_target_cc_mno_app_regs" = x"-mllvm -sparc-reserve-app-registers" ; then
876     # A trick so that clang doesn't see it on link stаge
877     TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_app_regs"
878   else
879     TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_app_regs"
880   fi
881
882   AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [
883     grub_cv_target_cc_mno_relax=no
884     for cand in "-mno-relax" "-Wl,--no-relax"; do
885       if test x"$grub_cv_target_cc_mno_relax" != xno ; then
886         break
887       fi
888       LDFLAGS="$TARGET_LDFLAGS $cand -nostdlib -static"
889       CFLAGS="$TARGET_CFLAGS -Werror"
890       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
891             asm (".globl start; start:");
892             void __main (void);
893             void __main (void) {}
894             int main (void);
895             ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], [])
896     done
897   ])
898   LDFLAGS="$TARGET_LDFLAGS"
899   CFLAGS="$TARGET_CFLAGS"
900
901   if test x"$grub_cv_target_cc_mno_relax" = xno ; then
902     AC_MSG_ERROR([could not find no-relax options])
903   fi
904   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_mno_relax"
905 fi
906
907 # By default, GCC 4.4 generates .eh_frame sections containing unwind
908 # information in some cases where it previously did not. GRUB doesn't need
909 # these and they just use up vital space. Restore the old compiler
910 # behaviour.
911 AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
912   CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
913   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
914       [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
915       [grub_cv_cc_fno_dwarf2_cfi_asm=no])
916 ])
917
918 if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
919   TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
920 fi
921
922 if test x"$target_os" = xcygwin; then
923   AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
924     CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
925     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
926                       [grub_cv_cc_no_reorder_functions=yes],
927                       [grub_cv_cc_no_reorder_functions=no])
928   ])
929 fi
930
931 if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
932   TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
933 fi
934
935 AC_CACHE_CHECK([whether -mno-stack-arg-probe works], [grub_cv_cc_mno_stack_arg_probe], [
936   CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
937   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
938       [grub_cv_cc_mno_stack_arg_probe=yes],
939       [grub_cv_cc_mno_stack_arg_probe=no])
940 ])
941
942 if test "x$grub_cv_cc_mno_stack_arg_probe" = xyes; then
943   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
944 fi
945
946
947 # By default, GCC 4.6 generates .eh_frame sections containing unwind
948 # information in some cases where it previously did not. GRUB doesn't need
949 # these and they just use up vital space. Restore the old compiler
950 # behaviour.
951 AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [
952   CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
953   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
954       [grub_cv_cc_fno_asynchronous_unwind_tables=yes],
955       [grub_cv_cc_fno_asynchronous_unwind_tables=no])
956 ])
957
958 if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then
959   TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
960 fi
961
962 AC_CACHE_CHECK([whether -fno-unwind-tables works], [grub_cv_cc_fno_unwind_tables], [
963   CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
964   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
965       [grub_cv_cc_fno_unwind_tables=yes],
966       [grub_cv_cc_fno_unwind_tables=no])
967 ])
968
969 if test "x$grub_cv_cc_fno_unwind_tables" = xyes; then
970   TARGET_CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
971 fi
972
973
974 CFLAGS="$TARGET_CFLAGS"
975
976
977 if test x"$platform" = xemu ; then
978   TARGET_OBJ2ELF=
979   grub_cv_target_cc_link_format=
980   case "$host_os" in
981     *darwin* | *mac*)
982        grub_cv_target_cc_link_format="-arch,${target_cpu}"
983        TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
984         ;;
985     *windows* | *cygwin* | *mingw*)
986       if test x${target_cpu} = xi386 ; then
987         grub_cv_target_cc_link_format=-mi386pe
988         TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
989       fi
990       if test x${target_cpu} = xx86_64 ; then
991         grub_cv_target_cc_link_format=-mi386pep
992         TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
993       fi
994       TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
995       ;;
996   esac
997 elif test x"$target_cpu" = xi386 || test x"$target_cpu" = xx86_64; then
998   AC_CACHE_CHECK([for target linking format], [grub_cv_target_cc_link_format], [
999     grub_cv_target_cc_link_format=unknown
1000     for format in -melf_${target_cpu} -melf_${target_cpu}_fbsd -melf_${target_cpu}_obsd -melf_${target_cpu}_haiku -mi386pe -mi386pep -arch,${target_cpu}; do
1001       if test x${target_cpu} != xi386 && test x$format = x-mi386pe; then
1002         continue
1003       fi
1004       if test x${target_cpu} != xx86_64 && test x$format = x-mi386pep; then
1005         continue
1006       fi
1007       CFLAGS="$TARGET_CFLAGS"
1008       LDFLAGS="$TARGET_LDFLAGS -Wl,$format -nostdlib -static"
1009       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1010       asm (".globl start; start:");
1011       asm (".globl _start; _start:");
1012       asm (".globl __start; __start:");
1013       void __main (void);
1014       void __main (void) {}
1015       ]], [[]])], [flag=1], [flag=0])
1016       if test x"$flag" = x1; then
1017         grub_cv_target_cc_link_format="$format"
1018         break
1019       fi
1020     done])
1021   if test x"$grub_cv_target_cc_link_format" = xunknown; then
1022     AC_MSG_ERROR([no suitable link format found])
1023   fi
1024   TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
1025   if test x"$grub_cv_target_cc_link_format" = x-mi386pe ; then
1026     TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
1027   fi
1028   if test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
1029     TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
1030   fi
1031 fi
1032
1033 if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_cc_link_format = x-arch,x86_64; then
1034    TARGET_APPLE_LINKER=1
1035    AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
1036    if test "x$TARGET_OBJCONV" = x ; then
1037       AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
1038    fi
1039    if test "x$TARGET_OBJCONV" = x ; then
1040       AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
1041    fi
1042    TARGET_IMG_LDSCRIPT=
1043    TARGET_IMG_CFLAGS="-static"
1044    TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
1045    TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
1046    TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
1047    TARGET_LDFLAGS_OLDMAGIC=""
1048 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
1049   TARGET_APPLE_LINKER=0
1050   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
1051   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/i386-cygwin-img-ld.sc"
1052   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
1053   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/i386-cygwin-img-ld.sc"
1054   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
1055   TARGET_IMG_CFLAGS=
1056 else
1057   TARGET_APPLE_LINKER=0
1058   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
1059   TARGET_IMG_LDSCRIPT=
1060   TARGET_IMG_LDFLAGS='-Wl,-N'
1061   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
1062   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
1063   TARGET_IMG_CFLAGS=
1064 fi
1065
1066 CFLAGS="$TARGET_CFLAGS"
1067
1068 AC_ARG_ENABLE([efiemu],
1069               [AS_HELP_STRING([--enable-efiemu],
1070                              [build and install the efiemu runtimes (default=guessed)])])
1071 if test x"$enable_efiemu" = xno ; then
1072   efiemu_excuse="explicitly disabled"
1073 fi
1074
1075 if test x"$grub_cv_target_cc_link_format" = x-mi386pe || test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
1076   efiemu_excuse="not available on cygwin"
1077 fi
1078 if test x"$target_cpu" != xi386 ; then
1079   efiemu_excuse="only available on i386"
1080 fi
1081 if test x"$platform" = xefi ; then
1082   efiemu_excuse="not available on efi"
1083 fi
1084
1085 if test x"$efiemu_excuse" = x ; then
1086   AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
1087     CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
1088     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1089                       [grub_cv_cc_efiemu=yes],
1090                       [grub_cv_cc_efiemu=no])
1091   ])
1092   if test x$grub_cv_cc_efiemu = xno; then
1093      efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
1094   fi
1095 fi
1096 if test x"$efiemu_excuse" = x ; then
1097   AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [
1098     grub_cv_target_cc_efiemu64_link_format=unknown
1099     for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do
1100       CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
1101       LDFLAGS="-m64 -Wl,$format -nostdlib -static"
1102       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1103       asm (".globl start; start:");
1104       asm (".globl _start; _start:");
1105       asm (".globl __start; __start:");
1106       void __main (void);
1107       void __main (void) {}
1108       ]], [[]])], [flag=1], [flag=0])
1109       if test x"$flag" = x1; then
1110         grub_cv_target_cc_efiemu64_link_format="$format"
1111         break
1112       fi
1113     done])
1114   if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then
1115     efiemu_excuse="no suitable link format for efiemu64 found"
1116   else
1117     EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format"
1118   fi
1119 fi
1120 if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
1121   AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled ($efiemu_excuse)])
1122 fi
1123 if test x"$efiemu_excuse" = x ; then
1124 enable_efiemu=yes
1125 else
1126 enable_efiemu=no
1127 fi
1128 AC_SUBST([enable_efiemu])
1129 AC_SUBST([EFIEMU64_LINK_FORMAT])
1130
1131 CFLAGS="$TARGET_CFLAGS"
1132
1133 AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
1134
1135
1136 LDFLAGS="$TARGET_LDFLAGS"
1137
1138 if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
1139   # Use large model to support 4G memory
1140   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
1141     CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1142     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1143                       [grub_cv_cc_mcmodel=yes],
1144                       [grub_cv_cc_mcmodel=no])
1145   ])
1146   if test "x$grub_cv_cc_mcmodel" = xyes; then
1147     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1148   elif test "$target_cpu" = sparc64; then
1149     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
1150   fi
1151 fi
1152
1153 if test "$target_cpu"-"$platform" = x86_64-efi; then
1154   # EFI writes to stack below %rsp, we must not use the red zone
1155   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
1156     CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1157     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1158                       [grub_cv_cc_no_red_zone=yes],
1159                       [grub_cv_cc_no_red_zone=no])
1160   ])
1161   if test "x$grub_cv_cc_no_red_zone" = xno; then
1162     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
1163   fi
1164
1165   TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1166 fi
1167
1168 if test "x$target_cpu" = xarm; then
1169   AC_CACHE_CHECK([for options to disable movt and movw], grub_cv_target_cc_mno_movt, [
1170     grub_cv_target_cc_mno_movt=no
1171     for cand in "-mno-movt" \
1172                 "-mllvm -arm-use-movt=0"; do
1173       if test x"$grub_cv_target_cc_mno_movt" != xno ; then
1174         break
1175       fi
1176       CFLAGS="$TARGET_CFLAGS $cand -Werror"
1177       CPPFLAGS="$TARGET_CPPFLAGS"
1178       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1179                         [grub_cv_target_cc_mno_movt="$cand"], [])
1180     done
1181   ])
1182
1183   if test x"$grub_cv_target_cc_mno_movt" != xno ; then
1184     # A trick so that clang doesn't see it on link stage
1185     TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt"
1186   fi
1187   AC_CACHE_CHECK([whether option -mthumb-interwork works], grub_cv_cc_mthumb_interwork, [
1188     CFLAGS="$TARGET_CFLAGS -mthumb-interwork -Werror"
1189     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1190                       [grub_cv_cc_mthumb_interwork=yes],
1191                       [grub_cv_cc_mthumb_interwork=no])
1192   ])
1193   if test "x$grub_cv_cc_mthumb_interwork" = xyes; then
1194     TARGET_CFLAGS="$TARGET_CFLAGS -mthumb-interwork"
1195   # Clang defaults to thumb interworking
1196   elif test "x$grub_cv_cc_target_clang" = xno ; then
1197     AC_MSG_ERROR([your compiler doesn't support -mthumb-interwork])
1198   fi
1199 fi
1200
1201 AC_CACHE_CHECK([whether option -Qn works], grub_cv_target_cc_qn, [
1202   CFLAGS="$TARGET_CFLAGS -Qn -Werror"
1203   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1204                     [grub_cv_target_cc_qn=yes],
1205                     [grub_cv_target_cc_qn=no])])
1206 if test "x$grub_cv_target_cc_qn" = xyes; then
1207   TARGET_CFLAGS="$TARGET_CFLAGS -Qn"
1208 fi
1209
1210 #
1211 # Compiler features.
1212 #
1213
1214 CFLAGS="$TARGET_CFLAGS"
1215
1216 # Position independent executable.
1217 grub_CHECK_PIE
1218 grub_CHECK_NO_PIE
1219 grub_CHECK_NO_PIE_ONEWORD
1220 grub_CHECK_LINK_PIE
1221 [# Need that, because some distributions ship compilers that include
1222 # `-fPIE' or '-fpie' and '-pie' in the default specs.
1223 if [ x"$pie_possible" = xyes ]; then
1224   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
1225 fi
1226
1227 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then
1228   if [ x"$nopie_possible" = xyes ]; then
1229     TARGET_LDFLAGS="$TARGET_LDFLAGS -no-pie"
1230   fi
1231   if [ x"$nopie_oneword_possible" = xyes ]; then
1232     TARGET_LDFLAGS="$TARGET_LDFLAGS -nopie"
1233   fi
1234 fi]
1235
1236 CFLAGS="$TARGET_CFLAGS"
1237 LDFLAGS="$TARGET_LDFLAGS"
1238
1239 # Position independent executable.
1240 grub_CHECK_PIC
1241 [# On most platforms we don't want PIC as it only makes relocations harder
1242 # and code less efficient. On mips we want to have one got table per module
1243 # and reload $gp in every function.
1244 # GCC implements it using symbol __gnu_local_gp in non-PIC as well.
1245 # However with clang we need PIC for this reloading to happen.
1246 # With arm64 we need relocations that are in some way representable in
1247 # PE as we need to support arm64-efi. Without -fPIC clang generates
1248 # movk's which aren't representable.
1249 # Since default varies across dictributions use either -fPIC or -fno-PIC
1250 # explicitly.
1251 if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel || test x$target_cpu = xarm64 ) && test "x$grub_cv_cc_target_clang" = xyes ; then
1252    TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
1253 elif [ x"$pic_possible" = xyes ]; then
1254    TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
1255 fi]
1256
1257 CFLAGS="$TARGET_CFLAGS"
1258
1259 # Smashing stack protector.
1260 grub_CHECK_STACK_PROTECTOR
1261 # Need that, because some distributions ship compilers that include
1262 # `-fstack-protector' in the default specs.
1263 if test "x$ssp_possible" = xyes; then
1264   TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
1265 fi
1266
1267 CFLAGS="$TARGET_CFLAGS"
1268
1269 grub_CHECK_STACK_ARG_PROBE
1270 # Cygwin's GCC uses alloca() to probe the stackframe on static
1271 # stack allocations above some threshold.
1272 if test x"$sap_possible" = xyes; then
1273   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
1274 fi
1275
1276 CFLAGS="$TARGET_CFLAGS"
1277
1278 # -mno-unaligned-access -mstrict-align
1279 if test "$target_cpu" = arm; then
1280   AC_CACHE_CHECK([for compile options to get strict alignment], [grub_cv_target_cc_strict_align], [
1281     grub_cv_target_cc_strict_align=
1282     for arg in -mno-unaligned-access "-Xclang -mstrict-align" -mstrict-align; do
1283       CFLAGS="$TARGET_CFLAGS $arg -Werror"
1284       LDFLAGS="$TARGET_LDFLAGS"
1285       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
1286       if test x"$flag" = x1; then
1287         grub_cv_target_cc_strict_align="$arg"
1288         break
1289       fi
1290     done])
1291
1292   TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_strict_align"
1293   if test x"$grub_cv_target_cc_strict_align" = x"-Xclang -mstrict-align"; then
1294     TARGET_LDFLAGS="$TARGET_LDFLAGS -Qunused-arguments"
1295   fi
1296   AC_CACHE_CHECK([if compiler generates unaligned accesses], [grub_cv_cc_target_emits_unaligned],
1297   [CFLAGS="$TARGET_CFLAGS"
1298    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1299 #ifdef __ARM_FEATURE_UNALIGNED
1300 #error "unaligned"
1301 #endif
1302      ]])],
1303      [grub_cv_cc_target_emits_unaligned=no], [grub_cv_cc_target_emits_unaligned=yes])])
1304   if test x$grub_cv_cc_target_emits_unaligned = xyes; then
1305     AC_MSG_ERROR([compiler generates unaligned accesses])
1306   fi
1307 fi
1308
1309 # Set them to their new values for the tests below.
1310 CC="$TARGET_CC"
1311 if test x"$platform" = xemu ; then
1312 CFLAGS="$TARGET_CFLAGS -Wno-error"
1313 elif test "x$TARGET_APPLE_LINKER" = x1 ; then
1314 CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error"
1315 else
1316 CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
1317 fi
1318 CPPFLAGS="$TARGET_CPPFLAGS"
1319
1320 grub_ASM_USCORE
1321 if test "x$TARGET_APPLE_LINKER" = x0 && test x"$platform" != xemu; then
1322 if test x$grub_cv_asm_uscore = xyes; then
1323 DEFSYM="-Wl,--defsym,_abort=_main -Wl,--defsym,__main=_main"
1324 else
1325 DEFSYM="-Wl,--defsym,abort=main -Wl,--defsym,_main=main -Wl,--defsym,__main=main"
1326 fi
1327 CFLAGS="$TARGET_CFLAGS -nostdlib $DEFSYM"
1328 fi
1329
1330 # Check for libgcc symbols
1331 if test x"$platform" = xemu; then
1332 AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms)
1333 fi
1334
1335 if test "x$TARGET_APPLE_LINKER" = x1 ; then
1336 CFLAGS="$TARGET_CFLAGS -nostdlib -static"
1337 else
1338 CFLAGS="$TARGET_CFLAGS -nostdlib"
1339 fi
1340 LIBS=""
1341
1342 # Defined in aclocal.m4.
1343 grub_PROG_TARGET_CC
1344 if test "x$TARGET_APPLE_LINKER" != x1 ; then
1345 grub_PROG_OBJCOPY_ABSOLUTE
1346 fi
1347 grub_PROG_LD_BUILD_ID_NONE
1348 if test "x$target_cpu" = xi386; then
1349   if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
1350     if test ! -z "$TARGET_IMG_LDSCRIPT"; then
1351       # Check symbols provided by linker script.
1352       CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
1353     fi
1354     grub_CHECK_BSS_START_SYMBOL
1355     grub_CHECK_END_SYMBOL
1356   fi
1357   CFLAGS="$TARGET_CFLAGS"
1358 fi
1359
1360 grub_PROG_NM_WORKS
1361 grub_PROG_NM_MINUS_P
1362 grub_PROG_NM_DEFINED_ONLY
1363 AC_SUBST(TARGET_NMFLAGS_MINUS_P)
1364 AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)
1365
1366 if test "$platform" != emu; then
1367 AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
1368   SAVED_CPPFLAGS="$CPPFLAGS"
1369   CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
1370   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1371 #include <stddef.h>
1372 int va_arg_func (int fixed, va_list args);]], [[]])],
1373       [grub_cv_cc_isystem=yes],
1374       [grub_cv_cc_isystem=no])
1375   CPPFLAGS="$SAVED_CPPFLAGS"
1376 ])
1377
1378 if test x"$grub_cv_cc_isystem" = xyes ; then
1379   TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
1380 fi
1381 fi
1382
1383 AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_cc_wtrampolines], [
1384   CFLAGS="$TARGET_CFLAGS -Wtrampolines -Werror"
1385   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1386 int va_arg_func (int fixed, va_list args);]], [[]])],
1387       [grub_cv_cc_wtrampolines=yes],
1388       [grub_cv_cc_wtrampolines=no])
1389 ])
1390
1391 if test x"$grub_cv_cc_wtrampolines" = xyes ; then
1392   TARGET_CFLAGS="$TARGET_CFLAGS -Wtrampolines"
1393 fi
1394
1395 # Restore the flags.
1396 CC="$tmp_CC"
1397 CFLAGS="$tmp_CFLAGS"
1398 CPPFLAGS="$tmp_CPPFLAGS"
1399 LDFLAGS="$tmp_LDFLAGS"
1400 LIBS="$tmp_LIBS"
1401
1402 #
1403 # Check for options.
1404 #
1405
1406 # Memory manager debugging.
1407 AC_ARG_ENABLE([mm-debug],
1408               AS_HELP_STRING([--enable-mm-debug],
1409                              [include memory manager debugging]),
1410               [AC_DEFINE([MM_DEBUG], [1],
1411                          [Define to 1 if you enable memory manager debugging.])])
1412
1413 AC_ARG_ENABLE([cache-stats],
1414               AS_HELP_STRING([--enable-cache-stats],
1415                              [enable disk cache statistics collection]))
1416
1417 if test x$enable_cache_stats = xyes; then
1418   DISK_CACHE_STATS=1
1419 else
1420   DISK_CACHE_STATS=0
1421 fi
1422 AC_SUBST([DISK_CACHE_STATS])
1423
1424 AC_ARG_ENABLE([boot-time],
1425               AS_HELP_STRING([--enable-boot-time],
1426                              [enable boot time statistics collection]))
1427
1428 if test x$enable_boot_time = xyes; then
1429   BOOT_TIME_STATS=1
1430 else
1431   BOOT_TIME_STATS=0
1432 fi
1433 AC_SUBST([BOOT_TIME_STATS])
1434
1435 AC_ARG_ENABLE([grub-emu-sdl],
1436               [AS_HELP_STRING([--enable-grub-emu-sdl],
1437                              [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
1438
1439 AC_ARG_ENABLE([grub-emu-pci],
1440               [AS_HELP_STRING([--enable-grub-emu-pci],
1441                              [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
1442
1443 if test "$platform" = emu; then
1444
1445 if test x"$enable_grub_emu_sdl" = xno ; then
1446   grub_emu_sdl_excuse="explicitly disabled"
1447 fi
1448 [if [ x"$grub_emu_sdl_excuse" = x ]; then
1449     # Check for libSDL libraries.]
1450 AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
1451     [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
1452     AC_SUBST([LIBSDL])
1453 [fi]
1454
1455 [if [ x"$grub_emu_sdl_excuse" = x ]; then
1456     # Check for headers.]
1457     AC_CHECK_HEADERS([SDL/SDL.h], [],
1458       [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
1459 [fi]
1460
1461 if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
1462   AC_MSG_ERROR([SDL support for grub-emu was explicitly requested but can't be compiled ($grub_emu_sdl_excuse)])
1463 fi
1464 if test x"$grub_emu_sdl_excuse" = x ; then
1465 enable_grub_emu_sdl=yes
1466 else
1467 enable_grub_emu_sdl=no
1468 fi
1469
1470 if test x"$enable_grub_emu_pci" != xyes ; then
1471    grub_emu_pci_excuse="not enabled"
1472 fi
1473
1474 [if [ x"$grub_emu_pci_excuse" = x ]; then
1475       # Check for libpci libraries.]
1476    AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
1477       [grub_emu_pci_excuse=["need libpciaccess library"]])
1478     AC_SUBST([LIBPCIACCESS])
1479 [fi]
1480 [if [ x"$grub_emu_pci_excuse" = x ]; then
1481     # Check for headers.]
1482     AC_CHECK_HEADERS([pciaccess.h], [],
1483       [grub_emu_pci_excuse=["need libpciaccess headers"]])
1484 [fi]
1485
1486 if test x"$grub_emu_pci_excuse" = x ; then
1487 enable_grub_emu_pci=yes
1488 else
1489
1490 enable_grub_emu_pci=no
1491 fi
1492
1493 AC_SUBST([enable_grub_emu_sdl])
1494 AC_SUBST([enable_grub_emu_pci])
1495
1496 else
1497
1498 # Ignore --enable-emu-* if platform is not emu
1499 enable_grub_emu_sdl=no
1500 enable_grub_emu_pci=no
1501 fi
1502
1503 AC_ARG_ENABLE([grub-mkfont],
1504               [AS_HELP_STRING([--enable-grub-mkfont],
1505                              [build and install the `grub-mkfont' utility (default=guessed)])])
1506 if test x"$enable_grub_mkfont" = xno ; then
1507   grub_mkfont_excuse="explicitly disabled"
1508 fi
1509
1510 if test x"$grub_mkfont_excuse" = x ; then
1511   # Check for freetype libraries.
1512   AC_CHECK_TOOLS([FREETYPE], [freetype-config])
1513   if test "x$FREETYPE" = x ; then
1514     grub_mkfont_excuse=["need freetype2 library"]
1515   fi
1516 fi
1517
1518 unset ac_cv_header_ft2build_h
1519
1520 if test x"$grub_mkfont_excuse" = x ; then
1521   # Check for freetype libraries.
1522   freetype_cflags=`$FREETYPE --cflags`
1523   freetype_libs=`$FREETYPE --libs`
1524   SAVED_CPPFLAGS="$CPPFLAGS"
1525   SAVED_LIBS="$LIBS"
1526   CPPFLAGS="$CPPFLAGS $freetype_cflags"
1527   LIBS="$LIBS $freetype_libs"
1528   AC_CHECK_HEADERS([ft2build.h], [],
1529         [grub_mkfont_excuse=["need freetype2 headers"]])
1530   AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_mkfont_excuse=["freetype2 library unusable"]])
1531   CPPFLAGS="$SAVED_CPPFLAGS"
1532   LIBS="$SAVED_LIBS"
1533 fi
1534
1535 if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
1536   AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled ($grub_mkfont_excuse)])
1537 fi
1538 if test x"$grub_mkfont_excuse" = x ; then
1539 enable_grub_mkfont=yes
1540 else
1541 enable_grub_mkfont=no
1542 fi
1543 AC_SUBST([enable_grub_mkfont])
1544 AC_SUBST([freetype_cflags])
1545 AC_SUBST([freetype_libs])
1546
1547 SAVED_CC="$CC"
1548 SAVED_CPP="$CPP"
1549 SAVED_CFLAGS="$CFLAGS"
1550 SAVED_CPPFLAGS="$CPPFLAGS"
1551 SAVED_LDFLAGS="$LDFLAGS"
1552 CC="$BUILD_CC"
1553 CPP="$BUILD_CPP"
1554 CFLAGS="$BUILD_CFLAGS"
1555 CPPFLAGS="$BUILD_CPPFLAGS"
1556 LDFLAGS="$BUILD_LDFAGS"
1557
1558 unset ac_cv_c_bigendian
1559 unset ac_cv_header_ft2build_h
1560
1561 AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
1562 AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
1563 AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
1564
1565 if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
1566    AC_MSG_ERROR([couldnt determine build endianness])
1567 fi
1568
1569 AC_SUBST([BUILD_SIZEOF_LONG])
1570 AC_SUBST([BUILD_SIZEOF_VOID_P])
1571 AC_SUBST([BUILD_WORDS_BIGENDIAN])
1572
1573 if test x"$grub_build_mkfont_excuse" = x ; then
1574   # Check for freetype libraries.
1575   AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
1576   if test "x$BUILD_FREETYPE" = x ; then
1577     grub_build_mkfont_excuse=["need freetype2 library"]
1578   fi
1579 fi
1580
1581 if test x"$grub_build_mkfont_excuse" = x ; then
1582   # Check for freetype libraries.
1583   build_freetype_cflags=`$BUILD_FREETYPE --cflags`
1584   build_freetype_libs=`$BUILD_FREETYPE --libs`
1585   SAVED_CPPFLAGS_2="$CPPFLAGS"
1586   SAVED_LIBS="$LIBS"
1587   CPPFLAGS="$CPPFLAGS $build_freetype_cflags"
1588   LIBS="$LIBS $build_freetype_libs"
1589   AC_CHECK_HEADERS([ft2build.h], [],
1590         [grub_build_mkfont_excuse=["need freetype2 headers"]])
1591   AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_build_mkfont_excuse=["freetype2 library unusable"]])
1592   LIBS="$SAVED_LIBS"
1593   CPPFLAGS="$SAVED_CPPFLAGS_2"
1594 fi
1595
1596 if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
1597   AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled ($grub_build_mkfont_excuse)])
1598 fi
1599 if test x"$grub_build_mkfont_excuse" = x ; then
1600   enable_build_grub_mkfont=yes
1601 else
1602   enable_build_grub_mkfont=no
1603 fi
1604 if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then
1605   if test x"$grub_build_mkfont_excuse" = x ; then
1606     AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont])
1607   else
1608     AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont ($grub_build_mkfont_excuse)])
1609   fi
1610 fi
1611
1612 AC_SUBST([build_freetype_cflags])
1613 AC_SUBST([build_freetype_libs])
1614
1615 CC="$SAVED_CC"
1616 CPP="$SAVED_CPP"
1617 CFLAGS="$SAVED_CFLAGS"
1618 CPPFLAGS="$SAVED_CPPFLAGS"
1619 LDFLAGS="$SAVED_LDFLAGS"
1620
1621
1622 DJVU_FONT_SOURCE=
1623
1624 starfield_excuse=
1625
1626 AC_ARG_ENABLE([grub-themes],
1627               [AS_HELP_STRING([--enable-grub-themes],
1628                              [build and install GRUB themes (default=guessed)])])
1629 if test x"$enable_grub_themes" = xno ; then
1630   starfield_excuse="explicitly disabled"
1631 fi
1632
1633 if test x"$starfield_excuse" = x && test x"$enable_build_grub_mkfont" = xno ; then
1634   starfield_excuse="No build-time grub-mkfont"
1635 fi
1636
1637 if test x"$starfield_excuse" = x; then
1638    for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1639      for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype; do
1640         if test -f "$dir/DejaVuSans.$ext"; then
1641           DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
1642           break 2
1643         fi
1644      done
1645    done
1646
1647    if test "x$DJVU_FONT_SOURCE" = x; then
1648      starfield_excuse="No DejaVu found"
1649    fi
1650 fi
1651
1652 if test x"$enable_grub_themes" = xyes &&  test x"$starfield_excuse" != x; then
1653    AC_MSG_ERROR([themes were explicitly requested but requirements are not satisfied ($starfield_excuse)])
1654 fi
1655
1656 AC_SUBST([DJVU_FONT_SOURCE])
1657
1658 FONT_SOURCE=
1659
1660 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1661   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
1662     if test -f "$dir/unifont.$ext"; then
1663       md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
1664       # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
1665       if test "$md5" = 0a54834d2788c83886a3e1785a6a1e61 || test "$md5" = 28f2565c7a41d8d407e2551159385edb || test "$md5" = dae5e588461b3b92b87b6ffee734f936 || test "$md5" = 4a3d687aa5bb329ed05f4263a1016791 ; then
1666         continue
1667       fi
1668       FONT_SOURCE="$dir/unifont.$ext"
1669       break 2
1670     fi
1671   done
1672 done
1673
1674 if test x"$enable_build_grub_mkfont" = xno ; then
1675   FONT_SOURCE=
1676 fi
1677
1678 if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then
1679   if test x"$grub_build_mkfont_excuse" = x ; then
1680     AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont])
1681   else
1682     AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)])
1683   fi
1684 fi
1685
1686 AC_SUBST([FONT_SOURCE])
1687
1688 if test x"$FONT_SOURCE" = x &&  test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
1689   grub_build_mkfont_excuse="no fonts"
1690 fi
1691
1692
1693 AC_ARG_ENABLE([grub-mount],
1694               [AS_HELP_STRING([--enable-grub-mount],
1695                              [build and install the `grub-mount' utility (default=guessed)])])
1696 if test x"$enable_grub_mount" = xno ; then
1697   grub_mount_excuse="explicitly disabled"
1698 fi
1699
1700 if test x"$grub_mount_excuse" = x ; then
1701   AC_CHECK_LIB([fuse], [fuse_main_real], [],
1702                [grub_mount_excuse="need FUSE library"])
1703 fi
1704
1705 if test x"$grub_mount_excuse" = x ; then
1706   # Check for fuse headers.
1707   SAVED_CPPFLAGS="$CPPFLAGS"
1708   CPPFLAGS="$CPPFLAGS -DFUSE_USE_VERSION=26"
1709   AC_CHECK_HEADERS([fuse/fuse.h], [],
1710         [grub_mount_excuse=["need FUSE headers"]])
1711   CPPFLAGS="$SAVED_CPPFLAGS"
1712 fi
1713
1714 if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then
1715   AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled ($grub_mount_excuse)])
1716 fi
1717 if test x"$grub_mount_excuse" = x ; then
1718 enable_grub_mount=yes
1719 else
1720 enable_grub_mount=no
1721 fi
1722 AC_SUBST([enable_grub_mount])
1723
1724 AC_ARG_ENABLE([device-mapper],
1725               [AS_HELP_STRING([--enable-device-mapper],
1726                               [enable Linux device-mapper support (default=guessed)])])
1727 if test x"$enable_device_mapper" = xno ; then
1728   device_mapper_excuse="explicitly disabled"
1729 fi
1730
1731 if test x"$device_mapper_excuse" = x ; then
1732   # Check for device-mapper header.
1733   AC_CHECK_HEADER([libdevmapper.h], [],
1734                [device_mapper_excuse="need libdevmapper header"])
1735 fi
1736
1737 if test x"$device_mapper_excuse" = x ; then
1738   # Check for device-mapper library.
1739   AC_CHECK_LIB([devmapper], [dm_task_create], [],
1740                [device_mapper_excuse="need devmapper library"])
1741 fi
1742
1743 if test x"$device_mapper_excuse" = x ; then
1744   # Check for device-mapper library.
1745   AC_CHECK_LIB([devmapper], [dm_log_with_errno_init],
1746                [],
1747                [device_mapper_excuse="need devmapper library"])
1748 fi
1749
1750 if test x"$device_mapper_excuse" = x ; then
1751    LIBDEVMAPPER="-ldevmapper"
1752    AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
1753              [Define to 1 if you have the devmapper library.])
1754 fi
1755
1756 AC_SUBST([LIBDEVMAPPER])
1757
1758 LIBGEOM=
1759 if test x$host_kernel = xkfreebsd; then
1760   AC_CHECK_LIB([geom], [geom_gettree], [],
1761                [AC_MSG_ERROR([Your platform requires libgeom])])
1762   LIBGEOM="-lgeom"
1763 fi
1764
1765 AC_SUBST([LIBGEOM])
1766
1767 AC_ARG_ENABLE([liblzma],
1768               [AS_HELP_STRING([--enable-liblzma],
1769                               [enable liblzma integration (default=guessed)])])
1770 if test x"$enable_liblzma" = xno ; then
1771   liblzma_excuse="explicitly disabled"
1772 fi
1773
1774 if test x"$liblzma_excuse" = x ; then
1775 AC_CHECK_LIB([lzma], [lzma_code],
1776              [],[liblzma_excuse="need lzma library"])
1777 fi
1778 if test x"$liblzma_excuse" = x ; then
1779 AC_CHECK_HEADER([lzma.h], [], [liblzma_excuse="need lzma header"])
1780 fi
1781
1782 if test x"$enable_liblzma" = xyes && test x"$liblzma_excuse" != x ; then
1783   AC_MSG_ERROR([liblzma support was explicitly requested but requirements are not satisfied ($liblzma_excuse)])
1784 fi
1785
1786
1787 if test x"$liblzma_excuse" = x ; then
1788    LIBLZMA="-llzma"
1789    AC_DEFINE([USE_LIBLZMA], [1],
1790              [Define to 1 if you have the LZMA library.])
1791 fi
1792
1793 AC_SUBST([LIBLZMA])
1794
1795 AC_ARG_ENABLE([libzfs],
1796               [AS_HELP_STRING([--enable-libzfs],
1797                               [enable libzfs integration (default=guessed)])])
1798 if test x"$enable_libzfs" = xno ; then
1799   libzfs_excuse="explicitly disabled"
1800 fi
1801
1802 if test x"$libzfs_excuse" = x ; then
1803   # Only check for system headers if libzfs support has not been disabled.
1804   AC_CHECK_HEADERS(libzfs.h libnvpair.h)
1805 fi
1806
1807 if test x"$libzfs_excuse" = x ; then
1808   AC_CHECK_LIB([zfs], [libzfs_init],
1809                [],
1810                [libzfs_excuse="need zfs library"])
1811 fi
1812
1813 if test x"$libzfs_excuse" = x ; then
1814   AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
1815                [],
1816                [libzfs_excuse="need nvpair library"])
1817 fi
1818
1819 if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
1820   AC_MSG_ERROR([libzfs support was explicitly requested but requirements are not satisfied ($libzfs_excuse)])
1821 fi
1822
1823 if test x"$libzfs_excuse" = x ; then
1824   # We need both libzfs and libnvpair for a successful build.
1825   LIBZFS="-lzfs"
1826   AC_DEFINE([HAVE_LIBZFS], [1],
1827             [Define to 1 if you have the ZFS library.])
1828   LIBNVPAIR="-lnvpair"
1829   AC_DEFINE([HAVE_LIBNVPAIR], [1],
1830             [Define to 1 if you have the NVPAIR library.])
1831 fi
1832
1833 AC_SUBST([LIBZFS])
1834 AC_SUBST([LIBNVPAIR])
1835
1836 LIBS=""
1837
1838 AC_SUBST([FONT_SOURCE])
1839 AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
1840             [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
1841
1842 AC_SUBST(HAVE_ASM_USCORE)
1843 AC_SUBST(BSS_START_SYMBOL)
1844 AC_SUBST(END_SYMBOL)
1845 AC_SUBST(PACKAGE)
1846 AC_SUBST(VERSION)
1847
1848 AC_ARG_ENABLE([werror],
1849               [AS_HELP_STRING([--disable-werror],
1850                              [do not use -Werror when building GRUB])])
1851 if test x"$enable_werror" != xno ; then
1852   TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
1853   HOST_CFLAGS="$HOST_CFLAGS -Werror"
1854 fi
1855
1856 TARGET_CPP="$TARGET_CC -E"
1857 TARGET_CCAS=$TARGET_CC
1858
1859 # Includes which include make-time substitutions. They must come last
1860 # as to avoid executing top_builddir in shell.
1861 HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
1862 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
1863 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"
1864
1865 GRUB_TARGET_CPU="${target_cpu}"
1866 GRUB_PLATFORM="${platform}"
1867
1868 AC_SUBST(GRUB_TARGET_CPU)
1869 AC_SUBST(GRUB_PLATFORM)
1870
1871 AC_SUBST(TARGET_OBJCONV)
1872 AC_SUBST(TARGET_CPP)
1873 AC_SUBST(TARGET_CCAS)
1874 AC_SUBST(TARGET_OBJ2ELF)
1875 AC_SUBST(TARGET_MODULE_FORMAT)
1876 AC_SUBST(TARGET_CC_VERSION)
1877
1878 AC_SUBST(TARGET_CFLAGS)
1879 AC_SUBST(TARGET_LDFLAGS)
1880 AC_SUBST(TARGET_CPPFLAGS)
1881 AC_SUBST(TARGET_CCASFLAGS)
1882
1883 AC_SUBST(TARGET_IMG_LDFLAGS)
1884 AC_SUBST(TARGET_IMG_CFLAGS)
1885 AC_SUBST(TARGET_IMG_BASE_LDOPT)
1886 AC_SUBST(TARGET_APPLE_LINKER)
1887
1888 AC_SUBST(HOST_CFLAGS)
1889 AC_SUBST(HOST_LDFLAGS)
1890 AC_SUBST(HOST_CPPFLAGS)
1891 AC_SUBST(HOST_CCASFLAGS)
1892
1893 AC_SUBST(BUILD_LIBM)
1894
1895 #
1896 # Automake conditionals
1897 #
1898
1899 AM_CONDITIONAL([COND_real_platform], [test x$platform != xnone])
1900 AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
1901 AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
1902 AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
1903 AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
1904 AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
1905 AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
1906 AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
1907 AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
1908 AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
1909 AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
1910 AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
1911 AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
1912 AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xqemu_mips])
1913 AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xarc])
1914 AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
1915 AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform = xemu])
1916 AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
1917 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
1918 AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
1919 AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
1920 AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
1921 AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
1922 AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot])
1923 AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
1924 AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
1925 AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
1926
1927 AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
1928 AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
1929 AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
1930 AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
1931 AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
1932 AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
1933 AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])
1934
1935 AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
1936 AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
1937 AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
1938 AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
1939 AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
1940 AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
1941 if test x$FONT_SOURCE != x ; then
1942    HAVE_FONT_SOURCE=1
1943 else
1944    HAVE_FONT_SOURCE=0
1945 fi
1946 AC_SUBST(HAVE_FONT_SOURCE)
1947 AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
1948 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
1949 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
1950 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
1951
1952 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
1953
1954 AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
1955 AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
1956 AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])
1957
1958 test "x$prefix" = xNONE && prefix="$ac_default_prefix"
1959 test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
1960 datarootdir="$(eval echo "$datarootdir")"
1961 grub_libdir="$(eval echo "$libdir")"
1962 grub_localedir="$(eval echo "$localedir")"
1963 grub_datadir="$(eval echo "$datadir")"
1964 grub_sysconfdir="$(eval echo "$sysconfdir")"
1965 AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
1966 AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
1967 AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
1968 AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
1969
1970
1971 # Output files.
1972 if test "$platform" != none; then
1973   cpudir="${target_cpu}"
1974   if test x${cpudir} = xmipsel; then
1975     cpudir=mips;
1976   fi
1977   grub_CHECK_LINK_DIR
1978   if test x"$link_dir" = xyes ; then
1979     AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
1980     if test "$platform" != emu ; then
1981       AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
1982     fi
1983   else
1984     mkdir -p include/grub 2>/dev/null
1985     rm -rf include/grub/cpu
1986     cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
1987     if test "$platform" != emu ; then
1988       rm -rf include/grub/machine
1989       cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
1990     fi
1991   fi
1992 else
1993   # Just enough to stop the compiler failing with -I$(srcdir)/include.
1994   mkdir -p include 2>/dev/null
1995   rm -rf include/grub/cpu include/grub/machine
1996 fi
1997
1998 AC_CONFIG_FILES([Makefile])
1999 AC_CONFIG_FILES([grub-core/Makefile])
2000 AC_CONFIG_FILES([grub-core/gnulib/Makefile])
2001 AC_CONFIG_FILES([po/Makefile.in])
2002 AC_CONFIG_FILES([docs/Makefile])
2003 AC_CONFIG_FILES([util/bash-completion.d/Makefile])
2004 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
2005 AC_CONFIG_FILES([config.h])
2006
2007 AC_OUTPUT
2008 [
2009 echo "*******************************************************"
2010 echo GRUB2 will be compiled with following components:
2011 echo Platform: "$target_cpu"-"$platform"
2012 if [ x"$platform" = xemu ]; then
2013 if [ x"$grub_emu_sdl_excuse" = x ]; then
2014 echo SDL support for grub-emu: Yes
2015 else
2016 echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
2017 fi
2018 if [ x"$grub_emu_pci_excuse" = x ]; then
2019 echo PCI support for grub-emu: Yes
2020 else
2021 echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
2022 fi
2023 fi
2024 if test x"$device_mapper_excuse" = x ; then
2025 echo With devmapper support: Yes
2026 else
2027 echo With devmapper support: No "($device_mapper_excuse)"
2028 fi
2029 if [ x"$enable_mm_debug" = xyes ]; then
2030 echo With memory debugging: Yes
2031 else
2032 echo With memory debugging: No
2033 fi
2034 if [ x"$enable_cache_stats" = xyes ]; then
2035 echo With disk cache statistics: Yes
2036 else
2037 echo With disk cache statistics: No
2038 fi
2039
2040 if [ x"$enable_boot_time" = xyes ]; then
2041 echo With boot time statistics: Yes
2042 else
2043 echo With boot time statistics: No
2044 fi
2045
2046 if [ x"$efiemu_excuse" = x ]; then
2047 echo efiemu runtime: Yes
2048 else
2049 echo efiemu runtime: No "($efiemu_excuse)"
2050 fi
2051 if [ x"$grub_mkfont_excuse" = x ]; then
2052 echo grub-mkfont: Yes
2053 else
2054 echo grub-mkfont: No "($grub_mkfont_excuse)"
2055 fi
2056 if [ x"$grub_mount_excuse" = x ]; then
2057 echo grub-mount: Yes
2058 else
2059 echo grub-mount: No "($grub_mount_excuse)"
2060 fi
2061 if [ x"$starfield_excuse" = x ]; then
2062 echo starfield theme: Yes
2063 echo With DejaVuSans font from $DJVU_FONT_SOURCE
2064 else
2065 echo starfield theme: No "($starfield_excuse)"
2066 fi
2067 if [ x"$libzfs_excuse" = x ]; then
2068 echo With libzfs support: Yes
2069 else
2070 echo With libzfs support: No "($libzfs_excuse)"
2071 fi
2072 if [ x"$grub_build_mkfont_excuse" = x ]; then
2073   echo Build-time grub-mkfont: Yes
2074   if test "x$FONT_SOURCE" = x ; then
2075     echo "Without unifont"
2076   else
2077     echo "With unifont from $FONT_SOURCE"
2078   fi
2079 else
2080   echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
2081   echo "Without unifont (no build-time grub-mkfont)"
2082 fi
2083 if test x"$liblzma_excuse" != x ; then
2084 echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excuse)"
2085 else
2086 echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
2087 fi
2088 echo "*******************************************************"
2089 ]