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