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