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