tpm2_key_protector: Enable build for powerpc_ieee1275
[grub.git] / configure.ac
blobad1e7bea5f12b3273f1a651189ae6b0412419e67
1 # -*- autoconf -*-
3 # Process this file with autoconf to produce a configure script.
5 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
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.
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.
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 and target type, variables with
30 dnl prefix "BUILD_" (such as BUILD_CC, BUILD_CFLAGS, etc.) for the
31 dnl build type, variables with prefix "HOST_" (such as HOST_CC,
32 dnl HOST_CFLAGS, etc.) for the host type and variables with the prefix
33 dnl "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for
34 dnl the target type. See INSTALL for full list of variables and
35 dnl description of the relationships between them.
37 AC_INIT([GRUB],[2.13],[bug-grub@gnu.org])
39 AS_CASE(["$ERROR_PLATFORM_NOT_SUPPORT_SSP"],
40   [n | no | nO | N | No | NO], [ERROR_PLATFORM_NOT_SUPPORT_SSP=no],
41   [ERROR_PLATFORM_NOT_SUPPORT_SSP=yes])
43 # We don't want -g -O2 by default in CFLAGS
44 : ${CFLAGS=""}
46 AC_USE_SYSTEM_EXTENSIONS
47 AC_CONFIG_AUX_DIR([build-aux])
49 # Checks for build, host and target systems.
50 AC_CANONICAL_BUILD
51 AC_CANONICAL_HOST
52 save_program_prefix="${program_prefix}"
53 AC_CANONICAL_TARGET
54 program_prefix="${save_program_prefix}"
56 AM_INIT_AUTOMAKE([1.11])
57 AC_PREREQ(2.64)
58 AC_CONFIG_SRCDIR([include/grub/dl.h])
59 AC_CONFIG_HEADERS([config-util.h])
61 # Explicitly check for pkg-config early on, since otherwise conditional
62 # calls are problematic.
63 PKG_PROG_PKG_CONFIG
65 # Program name transformations
66 AC_ARG_PROGRAM
67 grub_TRANSFORM([grub-bios-setup])
68 grub_TRANSFORM([grub-editenv])
69 grub_TRANSFORM([grub-install])
70 grub_TRANSFORM([grub-mkconfig])
71 grub_TRANSFORM([grub-mkfont])
72 grub_TRANSFORM([grub-mkimage])
73 grub_TRANSFORM([grub-glue-efi])
74 grub_TRANSFORM([grub-mklayout])
75 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
76 grub_TRANSFORM([grub-mkrelpath])
77 grub_TRANSFORM([grub-mkrescue])
78 grub_TRANSFORM([grub-probe])
79 grub_TRANSFORM([grub-protect])
80 grub_TRANSFORM([grub-reboot])
81 grub_TRANSFORM([grub-script-check])
82 grub_TRANSFORM([grub-set-default])
83 grub_TRANSFORM([grub-sparc64-setup])
84 grub_TRANSFORM([grub-render-label])
85 grub_TRANSFORM([grub-file])
87 # Allow HOST_CC to override CC.
88 if test "x$HOST_CC" != x; then
89   CC=$HOST_CC
92 # Optimization flag.  Allow user to override.
93 if test "x$TARGET_CFLAGS" = x; then
94   TARGET_CFLAGS=-Os
97 # Enable support for "restrict" keyword and other
98 # features from gnu99 C language standard.
99 BUILD_CFLAGS="-std=gnu99 -fno-common $BUILD_CFLAGS"
100 HOST_CFLAGS="-std=gnu99 -fno-common $HOST_CFLAGS"
101 TARGET_CFLAGS="-std=gnu99 -fno-common $TARGET_CFLAGS"
103 # Default HOST_CPPFLAGS
104 HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
105 HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"
107 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W"
109 case "$target_cpu" in
110   i[[3456]]86)  target_cpu=i386 ;;
111   amd64)        target_cpu=x86_64 ;;
112   sparc)        target_cpu=sparc64 ;;
113   mipsel|mips64el)
114                 target_cpu=mipsel
115                 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1"
116                 ;;
117   mips|mips64)
118                 target_cpu=mips
119                 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS=1"
120                 ;;
121   arm*)         target_cpu=arm ;;
122   aarch64*)     target_cpu=arm64 ;;
123   loongarch64)  target_cpu=loongarch64 ;;
124   riscv32*)     target_cpu=riscv32 ;;
125   riscv64*)     target_cpu=riscv64 ;;
126 esac
128 # Specify the platform (such as firmware).
129 AC_ARG_WITH([platform],
130             AS_HELP_STRING([--with-platform=PLATFORM],
131                            [select the host platform [[guessed]]]))
133 # Guess the platform if not specified.
134 if test "x$with_platform" = x; then
135   case "$target_cpu"-"$target_vendor" in
136     i386-apple) platform=efi ;;
137     i386-*) platform=pc ;;
138     x86_64-apple) platform=efi ;;
139     x86_64-*) platform=pc ;;
140     powerpc-*) platform=ieee1275 ;;
141     powerpc64-*) platform=ieee1275 ;;
142     powerpc64le-*) platform=ieee1275 ;;
143     sparc64-*) platform=ieee1275 ;;
144     mipsel-*) platform=loongson ;;
145     mips-*) platform=arc ;;
146     ia64-*) platform=efi ;;
147     arm-*) platform=uboot ;;
148     arm64-*) platform=efi ;;
149     loongarch64-*) platform=efi;;
150     riscv32-*) platform=efi ;;
151     riscv64-*) platform=efi ;;
152     *)
153       AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities])
154       platform=none
155       ;;
156   esac
157 else
158   platform="$with_platform"
161 case "$target_cpu"-"$platform" in
162   x86_64-efi) ;;
163   x86_64-emu) ;;
164   x86_64-xen) ;;
165   x86_64-none) ;;
166   x86_64-*) target_cpu=i386 ;;
167   powerpc64-ieee1275) target_cpu=powerpc ;;
168   powerpc64le-ieee1275) target_cpu=powerpc ;;
169 esac
171 # Check if the platform is supported, make final adjustments.
172 case "$target_cpu"-"$platform" in
173   i386-efi) ;;
174   x86_64-efi) ;;
175   i386-xen) ;;
176   i386-xen_pvh) ;;
177   x86_64-xen) ;;
178   i386-pc) ;;
179   i386-multiboot) ;;
180   i386-coreboot) ;;
181   i386-linuxbios) platform=coreboot ;;
182   i386-ieee1275) ;;
183   i386-qemu) ;;
184   powerpc-ieee1275) ;;
185   sparc64-ieee1275) ;;
186   ia64-efi) ;;
187   mips-qemu_mips) ;;
188   mips-qemu-mips) platform=qemu_mips;;
189   mips-arc) ;;
190   mipsel-arc) ;;
191   mipsel-qemu_mips) ;;
192   mipsel-qemu-mips) platform=qemu_mips;;
193   mipsel-yeeloong) platform=loongson ;;
194   mipsel-fuloong) platform=loongson ;;
195   mipsel-loongson) ;;
196   arm-uboot) ;;
197   arm-coreboot) ;;
198   arm-efi) ;;
199   arm64-efi) ;;
200   loongarch64-efi) ;;
201   riscv32-efi) ;;
202   riscv64-efi) ;;
203   *-emu) ;;
204   *-none) ;;
205   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
206 esac
208 if test x$platform != xemu ; then
209    case "$target_cpu" in
210         i386 | powerpc) target_m32=1 ;;
211         x86_64 | sparc64) target_m64=1 ;;
212    esac
215 if test x"$target_cpu-$platform" = xsparc64-emu ; then
216    target_m64=1
219 case "$target_os" in
220   windows* | mingw32*) target_os=cygwin ;;
221 esac
223 # This normalizes the names, and creates a new variable ("host_kernel")
224 # while at it, since the mapping is not always 1:1 (e.g. different OSes
225 # using the same kernel type).
226 case "$host_os" in
227   gnu*)                         host_kernel=hurd ;;
228   linux*)                       host_kernel=linux ;;
229   freebsd* | kfreebsd*-gnu)     host_kernel=kfreebsd ;;
230   netbsd*)                      host_kernel=netbsd ;;
231   solaris*)                     host_kernel=illumos ;;
232   darwin*)                      host_kernel=xnu ;;
233   cygwin | windows* | mingw32*) host_kernel=windows ;;
234 esac
236 case "$host_os" in
237   cygwin) have_exec=y ;;
238   windows* | mingw32*) have_exec=n ;;
239   aros*) have_exec=n ;;
240   *) have_exec=y;;
241 esac
243 case "$platform" in
244   coreboot)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_COREBOOT=1" ;;
245   multiboot)    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
246   efi)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
247   xen)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
248   xen_pvh)      machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN_PVH=1" ;;
249   ieee1275)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
250   uboot)        machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
251   qemu)         machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
252   pc)           machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
253   emu)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
254   loongson)     machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1" ;;
255   qemu_mips)    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1" ;;
256   arc)          machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
257 esac
258 if test x${target_cpu} = xmipsel ; then
259    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
260 else
261    machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
264 case "${target_cpu}-$platform" in
265      mips-arc)
266         TARGET_LINK_ADDR=0x88200000
267         TARGET_DECOMPRESSOR_LINK_ADDR=0x88100000
268         ;;
269      mipsel-arc)
270         TARGET_LINK_ADDR=0x80700000
271         TARGET_DECOMPRESSOR_LINK_ADDR=0x80600000
272         ;;
273      mips*-qemu_mips | mips*-loongson)
274         TARGET_DECOMPRESSOR_LINK_ADDR=0x80100000
275         ;;
276 esac
278 AC_SUBST(TARGET_LINK_ADDR)
279 AC_SUBST(TARGET_DECOMPRESSOR_LINK_ADDR)
281 TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS"
283 AC_SUBST(host_cpu)
284 AC_SUBST(host_os)
285 AC_SUBST(host_kernel)
287 AC_SUBST(target_cpu)
288 AC_SUBST(platform)
290 # Define default variables
292 have_with_bootdir=n
293 AC_ARG_WITH([bootdir],
294             AS_HELP_STRING([--with-bootdir=DIR],
295                            [set the name of /boot directory [[guessed]]]),
296                            [have_with_bootdir=y],
297                            [have_with_bootdir=n])
298 if test x$have_with_bootdir = xy; then
299    bootdirname="$with_bootdir"
300 else
301    case "$host_os" in
302      netbsd* | openbsd*)
303         # Because /boot is used for the boot block in NetBSD and OpenBSD,
304            bootdirname=''      ;;
305      *)    bootdirname='boot'  ;;
306    esac
309 AC_SUBST(bootdirname)
310 AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname",
311     [Default boot directory name])
313 AC_ARG_WITH([grubdir],
314             AS_HELP_STRING([--with-grubdir=DIR],
315                            [set the name of grub directory [[guessed]]]),
316                            [grubdirname="$with_grubdir"],
317                            [grubdirname="$PACKAGE"])
319 AC_SUBST(grubdirname)
320 AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
321     [Default grub directory name])
324 # Checks for build programs.
327 # Although cmp is listed in the GNU Coding Standards as a command which
328 # can used directly, OpenBSD lacks cmp in the default installation.
329 AC_CHECK_PROGS([CMP], [cmp])
330 if test "x$CMP" = x; then
331   AC_MSG_ERROR([cmp is not found])
334 AC_CHECK_PROGS([YACC], [bison])
335 if test "x$YACC" = x; then
336   AC_MSG_ERROR([bison is not found])
339 AC_PROG_RANLIB
340 AC_PROG_INSTALL
341 AC_PROG_AWK
342 AC_PROG_LEX([noyywrap])
343 AC_PROG_YACC
344 AC_PROG_MAKE_SET
345 AC_PROG_MKDIR_P
346 AC_PROG_LN_S
348 if test "x$LEX" = "x:"; then
349   AC_MSG_ERROR([flex is not found])
350 else
351   version=`$LEX --version | $AWK '{ split($2,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
352   if test -n "$version" -a "$version" -ge 20535; then
353     :
354   else
355     AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
356   fi
359 # These are not a "must".
360 AC_PATH_PROGS(MAKEINFO, makeinfo true)
363 # Checks for host programs.
366 AC_PROG_CC
367 gl_EARLY
368 AC_PROG_CXX
369 AM_PROG_CC_C_O
370 AM_PROG_AS
371 AM_PATH_PYTHON([2.6])
373 # Must be GCC.
374 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
376 AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
378 AM_GNU_GETTEXT([external])
379 AM_GNU_GETTEXT_VERSION([0.18.3])
380 AC_SYS_LARGEFILE
382 PLATFORMS_PCI=" $(PYTHONPATH="${srcdir}" $PYTHON -c 'import gentpl; print(" ".join(gentpl.GROUPS[["pci"]]))') "
383 if test x"${PLATFORMS_PCI##* ${target_cpu}_${platform} *}" = x ; then
384   have_pci=y
387 # Identify characteristics of the host architecture.
388 unset ac_cv_c_bigendian
390 if test x"$target_cpu-$platform" = xsparc64-emu ; then
391   CFLAGS="$CFLAGS -m64"
392   HOST_CFLAGS="$HOST_CFLAGS -m64"
395 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
396 HOST_CPPFLAGS="$HOST_CPPFLAGS -D_FILE_OFFSET_BITS=64"
398 AC_C_BIGENDIAN
399 AC_CHECK_SIZEOF(void *)
400 AC_CHECK_SIZEOF(long)
402 case "$host_os" in
403   cygwin | windows* | mingw32*)
404      HOST_CPPFLAGS="$HOST_CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
405      CPPFLAGS="$CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
406      AC_CHECK_SIZEOF(TCHAR,,[#include <windows.h>])
407    ;;
408 esac
410 case "$host_os" in
411   cygwin | windows* | mingw32* | aros*)
412      ;;
413   *)
414      AC_CHECK_SIZEOF(off_t)
415      if test x"$ac_cv_sizeof_off_t" != x8 ; then
416        AC_CHECK_SIZEOF(off64_t)
417        test x"$ac_cv_sizeof_off64_t" = x8 || AC_MSG_ERROR([Large file support is required])
418      fi;;
419 esac
421 if test x$USE_NLS = xno; then
422   HOST_CFLAGS="$HOST_CFLAGS -fno-builtin-gettext"
425 if test "x$cross_compiling" = xyes; then
426   AC_MSG_WARN([cannot generate manual pages while cross compiling])
427 else
428   AC_PATH_PROG(HELP2MAN, help2man)
431 # Check for functions and headers.
432 AC_CHECK_FUNCS(posix_memalign memalign getextmntent atexit)
433 AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h limits.h)
435 # glibc 2.25 still includes sys/sysmacros.h in sys/types.h but emits deprecation
436 # warning which causes compilation failure later with -Werror. So use -Werror here
437 # as well to force proper sys/sysmacros.h detection. Used in include/grub/osdep/major.h.
438 SAVED_CFLAGS="$CFLAGS"
439 CFLAGS="$HOST_CFLAGS -Werror"
440 AC_HEADER_MAJOR
441 CFLAGS="$SAVED_CFLAGS"
443 AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
444 #include <sys/param.h>
445 #include <sys/mount.h>])
447 AC_CHECK_MEMBERS([struct statfs.f_mntfromname],,,[$ac_includes_default
448 #include <sys/param.h>
449 #include <sys/mount.h>])
451 # For opendisk() and getrawpartition() on NetBSD.
452 # Used in util/deviceiter.c and in util/hostdisk.c.
453 AC_CHECK_HEADER([util.h], [
454   AC_CHECK_LIB([util], [opendisk], [
455     LIBUTIL="-lutil"
456     AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
457   ])
458   AC_CHECK_LIB([util], [getrawpartition], [
459     LIBUTIL="-lutil"
460     AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
461   ])
463 AC_SUBST([LIBUTIL])
465 AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_host_cc_wtrampolines], [
466   SAVED_CFLAGS="$CFLAGS"
467   CFLAGS="$HOST_CFLAGS -Wtrampolines -Werror"
468   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
469 int va_arg_func (int fixed, va_list args);]], [[]])],
470       [grub_cv_host_cc_wtrampolines=yes],
471       [grub_cv_host_cc_wtrampolines=no])
472   CFLAGS="$SAVED_CFLAGS"
475 if test x"$grub_host_cv_cc_wtrampolines" = xyes ; then
476   HOST_CFLAGS="$HOST_CFLAGS -Wtrampolines"
480 # Check for host and build compilers.
482 HOST_CC=$CC
483 AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc])
484 test -z "$BUILD_CC" && AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])
485 BUILD_CPP="$BUILD_CC -E"
487 case "$build_os" in
488   haiku*)                               BUILD_LIBM= ;;
489   *)                                    BUILD_LIBM=-lm ;;
490 esac
492 dnl FIXME proper test seems to require too deep dive into Autoconf internals.
493 dnl For now just list known platforms that we support.
495 case "$build_os" in
496   cygwin*|mingw32*|mingw64*)            BUILD_EXEEXT=.exe ;;
497   *)                                    BUILD_EXEEXT= ;;
498 esac
499 AC_SUBST(BUILD_EXEEXT)
501 # In some build environments like termux /bin/sh is not a valid
502 # shebang. Use $SHELL instead if it's executable and /bin/sh isn't
503 BUILD_SHEBANG=/bin/sh
504 for she in /bin/sh "$SHELL"; do
505   if test -x "$she" ; then
506     BUILD_SHEBANG="$she"
507   fi
508 done
509 AC_SUBST(BUILD_SHEBANG)
511 # For gnulib.
512 gl_INIT
514 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"
515 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"
517 HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS -Wcast-align"
519 AC_CACHE_CHECK([which extra warnings work], [grub_cv_cc_w_extra_flags], [
520   SAVED_CFLAGS="$CFLAGS"
521   grub_cv_cc_w_extra_flags=
522   for x in $EXTRA_WARN_FLAGS; do
523       CFLAGS="$HOST_CFLAGS $x -Werror"
524       AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
525       if test x$flag = x1 ; then
526          grub_cv_cc_w_extra_flags="$grub_cv_cc_w_extra_flags $x"
527       fi
528   done
529   CFLAGS="$SAVED_CFLAGS"
532 HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags"
535 # Check for target programs.
538 # Find tools for the target.
539 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
540   tmp_ac_tool_prefix="$ac_tool_prefix"
541   ac_tool_prefix=$target_alias-
543   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
544                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
545   AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
546   AC_CHECK_TOOL(TARGET_STRIP, strip)
547   AC_CHECK_TOOL(TARGET_NM, nm)
548   AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
550   ac_tool_prefix="$tmp_ac_tool_prefix"
551 else
552   if test "x$TARGET_CC" = x; then
553     TARGET_CC=$CC
554   fi
555   AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
556   AC_CHECK_TOOL(TARGET_STRIP, strip)
557   AC_CHECK_TOOL(TARGET_NM, nm)
558   AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
561 AC_SUBST(HOST_CC)
562 AC_SUBST(BUILD_CC)
563 AC_SUBST(BUILD_CFLAGS)
564 AC_SUBST(BUILD_CPPFLAGS)
565 AC_SUBST(BUILD_LDFLAGS)
566 AC_SUBST(TARGET_CC)
567 AC_SUBST(TARGET_NM)
568 AC_SUBST(TARGET_RANLIB)
569 AC_SUBST(TARGET_STRIP)
570 AC_SUBST(TARGET_OBJCOPY)
572 # Test the C compiler for the target environment.
573 tmp_CC="$CC"
574 tmp_CFLAGS="$CFLAGS"
575 tmp_LDFLAGS="$LDFLAGS"
576 tmp_CPPFLAGS="$CPPFLAGS"
577 tmp_LIBS="$LIBS"
578 CC="$TARGET_CC"
579 CFLAGS="$TARGET_CFLAGS"
580 CPPFLAGS="$TARGET_CPPFLAGS"
581 LDFLAGS="$TARGET_LDFLAGS"
582 LIBS=""
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"
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"
602 # debug flags.
603 TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
604 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
606 if test "x$target_cpu" != xi386 && test "x$target_cpu" != xx86_64; then
607 TARGET_CFLAGS="$TARGET_CFLAGS -Wcast-align"
610 TARGET_CC_VERSION="$(LC_ALL=C $TARGET_CC --version | head -n1)"
612 AC_CACHE_CHECK([which extra warnings work], [grub_cv_target_cc_w_extra_flags], [
613   LDFLAGS="$TARGET_LDFLAGS -nostdlib -static"
615   grub_cv_target_cc_w_extra_flags=
616   for x in $EXTRA_WARN_FLAGS; do
617       CFLAGS="$TARGET_CFLAGS $x -Werror"
618       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
619 asm (".globl start; start:");
620 void __main (void);
621 void __main (void) {}
622 int main (void);
623 ]], [[]])], [flag=1], [flag=0])
624       if test x$flag = x1 ; then
625          grub_cv_target_cc_w_extra_flags="$grub_cv_target_cc_w_extra_flags $x"
626       fi
627   done
630 TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_w_extra_flags"
632 AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang],
634 CFLAGS="$TARGET_CFLAGS"
635 AC_COMPILE_IFELSE(
636 [AC_LANG_PROGRAM([], [[
637 #ifdef __clang__
638 #error "is clang"
639 #endif
640 ]])],
641 [grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
643 if test x$target_cpu = xpowerpc -o x$target_cpu = xmips; then
644   AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
645     grub_cv_target_cc_big_endian=no
646     for cand in "-target $target_cpu -Wl,-EB" "-target $target_cpu" \
647                 "-target $target_cpu-linux-gnu -Wl,-EB" "-target $target_cpu-linux-gnu" \
648                 "-EB" "-mbig-endian"; do
649       if test x"$grub_cv_target_cc_big_endian" != xno ; then
650         break
651       fi
652       CFLAGS="$TARGET_CFLAGS $cand -Werror"
653       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
654 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
655 #error still little endian
656 #endif
657 asm (".globl start; start:");
658 asm (".globl _start; _start:");
659 asm (".globl __start; __start:");
660 void __main (void);
661 void __main (void) {}
662 int main (void);
663 ]], [[]])],
664                         [grub_cv_target_cc_big_endian="$cand"], [])
665     done
666   ])
668   if test x"$grub_cv_target_cc_big_endian" = xno ; then
669     AC_MSG_ERROR([could not force big-endian])
670   fi
672   skip_linkflags="$(echo "$grub_cv_target_cc_big_endian"|sed 's@-Wl,-EB@@')"
674   TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
675   TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
676   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
677   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian"
678 elif test x$target_cpu = xmipsel; then
679   AC_CACHE_CHECK([for options to get little-endian compilation], grub_cv_target_cc_little_endian, [
680     grub_cv_target_cc_little_endian=no
681     for cand in "-target $target_cpu -Wl,-EL" "-target $target_cpu" \
682                 "-target $target_cpu-linux-gnu -Wl,-EL" "-target $target_cpu-linux-gnu" \
683                 "-EL"; do
684       if test x"$grub_cv_target_cc_little_endian" != xno ; then
685         break
686       fi
687       CFLAGS="$TARGET_CFLAGS $cand -Werror"
688       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
689 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ == __BYTE_ORDER__)
690 #error still big endian
691 #endif
692 asm (".globl start; start:");
693 asm (".globl _start; _start:");
694 asm (".globl __start; __start:");
695 void __main (void);
696 void __main (void) {}
697 int main (void);
698 ]], [[]])],
699                         [grub_cv_target_cc_little_endian="$cand"], [])
700     done
701   ])
703   if test x"$grub_cv_target_cc_little_endian" = xno ; then
704     AC_MSG_ERROR([could not force little-endian])
705   fi
707   skip_linkflags="$(echo "$grub_cv_target_cc_little_endian"|sed 's@-Wl,-EL@@')"
709   TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
710   TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
711   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
712   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian"
715 # GRUB code is N32-compliant but it's experimental and we would prefer to
716 # avoid having too much variety when it doesn't result in any real improvement.
717 # Moreover N64 isn't supported.
718 if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
719   AC_CACHE_CHECK([for options to force MIPS o32 ABI], grub_cv_target_cc_mips_o32_abi, [
720     grub_cv_target_cc_mips_o32_abi=no
721     for arg in "" "-mabi=32" "-target $target_cpu -mabi=32" ; do
722       if test x"$grub_cv_target_cc_mips_o32_abi" != xno ; then
723         break
724       fi
725       CFLAGS="$TARGET_CFLAGS $arg -Werror"
726       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
727 #if !defined(_ABIO32) || !defined(_MIPS_SIM) || (_MIPS_SIM != _ABIO32)
728 #error not o32 ABI
729 #endif
730 asm (".globl start; start:");
731 asm (".globl _start; _start:");
732 asm (".globl __start; __start:");
733 void __main (void);
734 void __main (void) {}
735 int main (void);
736 ]], [[]])],
737                         [grub_cv_target_cc_mips_o32_abi="$arg"], [])
738     done
739   ])
741   if test x"$grub_cv_target_cc_mips_o32_abi" = xno ; then
742     AC_MSG_ERROR([could not force MIPS o32 ABI])
743   fi
745   TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mips_o32_abi"
746   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mips_o32_abi"
749 AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [
750 test_program=
751 case "x$target_cpu-$platform" in
752      xmips-* | xmipsel-*)
753         test_program=mips
754         ;;
755      xi386-pc)
756        test_program=i386-pc
757         ;;
758      xi386-* | xx86_64-*)
759        test_program=i386
760         ;;
761      xpowerpc-* | xsparc64-* | xarm-*)
762         test_program=$target_cpu
763         ;;
764 esac
765 if test x"$test_program" = x ; then
766   grub_cv_cc_target_asm_compile=
767 else
768   found=no
769   for arg in "" "-no-integrated-as"; do
770     cmdline="$TARGET_CC -c -o /dev/null $TARGET_CCASFLAGS $arg $TARGET_CPPFLAGS $srcdir/asm-tests/$test_program.S"
771     echo "Running $cmdline" >&AS_MESSAGE_LOG_FD
772     if $cmdline >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
773       grub_cv_cc_target_asm_compile="$arg"
774       found=yes
775       break
776     fi
777   done
778   if test x"$found" = xno ; then
779     AC_MSG_ERROR([could not compile assembly])
780   fi
784 TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_cc_target_asm_compile"
786 if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
787   TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
790 if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
791    TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
794 # on mips redirect cache flushing function to non-existant one.
795 if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
796   AC_CACHE_CHECK([whether -mflush-func=grub_red_herring works], [grub_cv_cc_mflush_func], [
797     CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring -Werror"
798     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
799         [grub_cv_cc_mflush_func=yes],
800         [grub_cv_cc_mflush_func=no])
801   ])
803   if test "x$grub_cv_cc_mflush_func" = xyes; then
804     TARGET_CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring"
805   fi
807   AC_CACHE_CHECK([whether -mno-gpopt works], [grub_cv_cc_mno_gpopt], [
808     CFLAGS="$TARGET_CFLAGS -mno-gpopt -Werror"
809     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
810         [grub_cv_cc_mno_gpopt=yes],
811         [grub_cv_cc_mno_gpopt=no])
812   ])
814   if test "x$grub_cv_cc_mno_gpopt" = xyes; then
815     TARGET_CFLAGS="$TARGET_CFLAGS -mno-gpopt"
816   fi
820 # Force no alignment to save space on i386.
821 if test "x$target_cpu" = xi386; then
822   TARGET_CFLAGS="$TARGET_CFLAGS -falign-functions=1"
824   AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
825     CFLAGS="$TARGET_CFLAGS -falign-loops=1 -Werror"
826     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
827         [grub_cv_cc_falign_loop=yes],
828         [grub_cv_cc_falign_loop=no])
829   ])
831   if test "x$grub_cv_cc_falign_loop" = xyes; then
832     TARGET_CFLAGS="$TARGET_CFLAGS -falign-loops=1"
833   fi
835   AC_CACHE_CHECK([whether -falign-jumps works], [grub_cv_cc_falign_jumps], [
836     CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -Werror"
837     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
838         [grub_cv_cc_falign_jumps=yes],
839         [grub_cv_cc_falign_jumps=no])
840   ])
842   if test "x$grub_cv_cc_falign_jumps" = xyes; then
843     TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1"
844   fi
847 AC_CACHE_CHECK([whether -freg-struct-return works], [grub_cv_cc_freg_struct_return], [
848     CFLAGS="$TARGET_CFLAGS -freg-struct-return -Werror"
849     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
850         [grub_cv_cc_freg_struct_return=yes],
851         [grub_cv_cc_freg_struct_return=no])
854 if test "x$grub_cv_cc_freg_struct_return" = xyes; then
855     TARGET_CFLAGS="$TARGET_CFLAGS -freg-struct-return"
858 if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
859   # Some toolchains enable these features by default, but they need
860   # registers that aren't set up properly in GRUB.
861   TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow"
864 if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ); then
865   AC_CACHE_CHECK([whether -Wa,-mx86-used-note works], [grub_cv_cc_mx86_used_note], [
866     CFLAGS="$TARGET_CFLAGS -Wa,-mx86-used-note=no -Werror"
867     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
868         [grub_cv_cc_mx86_used_note=yes],
869         [grub_cv_cc_mx86_used_note=no])
870   ])
872   if test "x$grub_cv_cc_mx86_used_note" = xyes; then
873     TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mx86-used-note=no"
874     TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mx86-used-note=no"
875   fi
878 if test "x$target_cpu" = xloongarch64; then
879   AC_CACHE_CHECK([whether _mno_explicit_relocs works], [grub_cv_cc_mno_explicit_relocs], [
880     CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -Werror"
881     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
882         [grub_cv_cc_mno_explicit_relocs=yes],
883         [grub_cv_cc_mno_explicit_relocs=no])
884   ])
885   if test "x$grub_cv_cc_mno_explicit_relocs" = xyes; then
886     TARGET_CFLAGS="$TARGET_CFLAGS -mno-explicit-relocs -fno-plt"
887     TARGET_CCASFLAGS="$TARGET_CCASFLAGS -mno-explicit-relocs -fno-plt"
888   fi
890   AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [
891     grub_cv_target_cc_mno_relax=no
892     for cand in "-mno-relax" "-Wa,-mno-relax"; do
893       if test x"$grub_cv_target_cc_mno_relax" != xno ; then
894         break
895       fi
896       CFLAGS="$TARGET_CFLAGS $cand -Werror"
897       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
898             asm (".globl start; start:");
899             void __main (void);
900             void __main (void) {}
901             int main (void);
902             ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], [])
903     done
904   ])
905   CFLAGS="$TARGET_CFLAGS"
907   if test x"$grub_cv_target_cc_mno_relax" != xno ; then
908     TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_relax"
909     TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mno_relax"
910   fi
912   TARGET_CFLAGS="$TARGET_CFLAGS -Wa,-mla-global-with-abs"
913   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -Wa,-mla-global-with-abs"
916 # GRUB doesn't use float or doubles at all. Yet some toolchains may decide
917 # that floats are a good fit to run instead of what's written in the code.
918 # Given that floating point unit is disabled (if present to begin with)
919 # when GRUB is running which may result in various hard crashes.
920 if test x"$platform" != xemu ; then
921   AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [
922     grub_cv_target_cc_soft_float=no
923     if test "x$target_cpu" = xarm64; then
924        CFLAGS="$TARGET_CFLAGS -mgeneral-regs-only -Werror"
925        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
926                          [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], [])
927     fi
928     if test "x$target_cpu" = xriscv32; then
929        CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror"
930        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
931                          [grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], [])
932        # ISA spec version 20191213 factored out extensions Zicsr and Zifencei
933        CFLAGS="$TARGET_CFLAGS -march=rv32imac_zicsr_zifencei -mabi=ilp32 -Werror"
934        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
935                          [grub_cv_target_cc_soft_float="-march=rv32imac_zicsr_zifencei -mabi=ilp32"], [])
936     fi
937     if test "x$target_cpu" = xriscv64; then
938        CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror"
939        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
940                          [grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], [])
941        # ISA spec version 20191213 factored out extensions Zicsr and Zifencei
942        CFLAGS="$TARGET_CFLAGS -march=rv64imac_zicsr_zifencei -mabi=lp64 -Werror"
943        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
944                          [grub_cv_target_cc_soft_float="-march=rv64imac_zicsr_zifencei -mabi=lp64"], [])
945     fi
946     if test "x$target_cpu" = xia64; then
947        CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
948        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
949                          [grub_cv_target_cc_soft_float="-mno-inline-float-divide -mno-inline-sqrt"], [])
950     fi
951     if test "x$target_cpu" = xsh4; then
952        CFLAGS="$TARGET_CFLAGS -m4-nofpu -Werror"
953        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
954                          [grub_cv_target_cc_soft_float="-m4-nofpu"], [])
955     fi
956     for cand in "-msoft-float -Xclang -msoft-float -Xclang -no-implicit-float" \
957                 "-Xclang -msoft-float -Xclang -no-implicit-float" \
958                 "-Xclang -msoft-float" "-msoft-float"; do
959       if test x"$grub_cv_target_cc_soft_float" != xno ; then
960         break
961       fi
962       CFLAGS="$TARGET_CFLAGS $cand -Werror"
963       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
964                         [grub_cv_target_cc_soft_float="$cand"], [])
965     done
966   ])
968   if test x"$grub_cv_target_cc_soft_float" = xno ; then
969     AC_MSG_ERROR([could not force soft-float])
970   fi
972   case x"$grub_cv_target_cc_soft_float" in
973     x*"-Xclang"*)
974       # A trick so that clang doesn't see it on link stаge
975       TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_soft_float"
976       ;;
977     *)
978       TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_soft_float"
979       ;;
980   esac
981   TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_soft_float"
985 if test x"$target_cpu" = xsparc64 ; then
986   AC_CACHE_CHECK([for options to reserve application registers], grub_cv_target_cc_mno_app_regs, [
987     grub_cv_target_cc_mno_app_regs=no
988     for cand in "-mllvm -sparc-reserve-app-registers" \
989                 "-mno-app-regs"; do
990       if test x"$grub_cv_target_cc_mno_app_regs" != xno ; then
991         break
992       fi
993       CFLAGS="$TARGET_CFLAGS $cand -Werror"
994       CPPFLAGS="$TARGET_CPPFLAGS"
995       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
996                         [grub_cv_target_cc_mno_app_regs="$cand"], [])
997     done
998   ])
1000   if test x"$grub_cv_target_cc_mno_app_regs" = xno ; then
1001     AC_MSG_ERROR([could not reserve application registers])
1002   fi
1003   if test x"$grub_cv_target_cc_mno_app_regs" = x"-mllvm -sparc-reserve-app-registers" ; then
1004     # A trick so that clang doesn't see it on link stаge
1005     TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_app_regs"
1006   else
1007     TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_app_regs"
1008   fi
1010   AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [
1011     grub_cv_target_cc_mno_relax=no
1012     for cand in "-mno-relax" "-Wl,--no-relax"; do
1013       if test x"$grub_cv_target_cc_mno_relax" != xno ; then
1014         break
1015       fi
1016       LDFLAGS="$TARGET_LDFLAGS $cand -nostdlib -static"
1017       CFLAGS="$TARGET_CFLAGS -Werror"
1018       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1019             asm (".globl start; start:");
1020             void __main (void);
1021             void __main (void) {}
1022             int main (void);
1023             ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], [])
1024     done
1025   ])
1026   LDFLAGS="$TARGET_LDFLAGS"
1027   CFLAGS="$TARGET_CFLAGS"
1029   if test x"$grub_cv_target_cc_mno_relax" = xno ; then
1030     AC_MSG_ERROR([could not find no-relax options])
1031   fi
1032   TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_mno_relax"
1035 # The backtrace module relies on frame pointers and the default optimization
1036 # level, -Os, omits them. Make sure they are enabled.
1037 AC_CACHE_CHECK([whether -fno-omit-frame-pointer works], [grub_cv_cc_fno_omit_frame_pointer], [
1038   CFLAGS="$TARGET_CFLAGS -fno-omit-frame-pointer"
1039   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1040       [grub_cv_cc_fno_omit_frame_pointer=yes],
1041       [grub_cv_cc_fno_omit_frame_pointer=no])
1044 if test "x$grub_cv_cc_fno_omit_frame_pointer" = xyes; then
1045   TARGET_CFLAGS="$TARGET_CFLAGS -fno-omit-frame-pointer"
1048 # By default, GCC 4.4 generates .eh_frame sections containing unwind
1049 # information in some cases where it previously did not. GRUB doesn't need
1050 # these and they just use up vital space. Restore the old compiler
1051 # behaviour.
1052 AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
1053   CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
1054   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1055       [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
1056       [grub_cv_cc_fno_dwarf2_cfi_asm=no])
1059 if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
1060   TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
1063 if test x"$target_os" = xcygwin; then
1064   AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
1065     CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
1066     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1067                       [grub_cv_cc_no_reorder_functions=yes],
1068                       [grub_cv_cc_no_reorder_functions=no])
1069   ])
1072 if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
1073   TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
1076 AC_CACHE_CHECK([whether -mno-stack-arg-probe works], [grub_cv_cc_mno_stack_arg_probe], [
1077   CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
1078   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1079       [grub_cv_cc_mno_stack_arg_probe=yes],
1080       [grub_cv_cc_mno_stack_arg_probe=no])
1083 if test "x$grub_cv_cc_mno_stack_arg_probe" = xyes; then
1084   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
1088 # By default, GCC 4.6 generates .eh_frame sections containing unwind
1089 # information in some cases where it previously did not. GRUB doesn't need
1090 # these and they just use up vital space. Restore the old compiler
1091 # behaviour.
1092 AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [
1093   CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
1094   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1095       [grub_cv_cc_fno_asynchronous_unwind_tables=yes],
1096       [grub_cv_cc_fno_asynchronous_unwind_tables=no])
1099 if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then
1100   TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
1103 AC_CACHE_CHECK([whether -fno-unwind-tables works], [grub_cv_cc_fno_unwind_tables], [
1104   CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
1105   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1106       [grub_cv_cc_fno_unwind_tables=yes],
1107       [grub_cv_cc_fno_unwind_tables=no])
1110 if test "x$grub_cv_cc_fno_unwind_tables" = xyes; then
1111   TARGET_CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
1114 # Do not generate .ident sections.
1115 AC_CACHE_CHECK([whether -fno-ident works], [grub_cv_cc_fno_ident], [
1116   CFLAGS="$TARGET_CFLAGS -fno-ident"
1117   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1118       [grub_cv_cc_fno_ident=yes],
1119       [grub_cv_cc_fno_ident=no])
1122 if test "x$grub_cv_cc_fno_ident" = xyes; then
1123   TARGET_CFLAGS="$TARGET_CFLAGS -fno-ident"
1126 CFLAGS="$TARGET_CFLAGS"
1129 if test x"$platform" = xemu ; then
1130   TARGET_OBJ2ELF=
1131   grub_cv_target_cc_link_format=
1132   case "$host_os" in
1133     *darwin* | *mac*)
1134        grub_cv_target_cc_link_format="-arch,${target_cpu}"
1135        TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
1136         ;;
1137     *windows* | *cygwin* | *mingw*)
1138       if test x${target_cpu} = xi386 ; then
1139         grub_cv_target_cc_link_format=-mi386pe
1140         TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
1141       fi
1142       if test x${target_cpu} = xx86_64 ; then
1143         grub_cv_target_cc_link_format=-mi386pep
1144         TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
1145       fi
1146       TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
1147       ;;
1148   esac
1149 elif test x"$target_cpu" = xi386 || test x"$target_cpu" = xx86_64; then
1150   AC_CACHE_CHECK([for target linking format], [grub_cv_target_cc_link_format], [
1151     grub_cv_target_cc_link_format=unknown
1152     for format in -melf_${target_cpu} -melf_${target_cpu}_fbsd -melf_${target_cpu}_obsd -melf_${target_cpu}_haiku -mi386pe -mi386pep -arch,${target_cpu}; do
1153       if test x${target_cpu} != xi386 && test x$format = x-mi386pe; then
1154         continue
1155       fi
1156       if test x${target_cpu} != xx86_64 && test x$format = x-mi386pep; then
1157         continue
1158       fi
1159       CFLAGS="$TARGET_CFLAGS"
1160       LDFLAGS="$TARGET_LDFLAGS -Wl,$format -nostdlib -static"
1161       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1162       asm (".globl start; start:");
1163       asm (".globl _start; _start:");
1164       asm (".globl __start; __start:");
1165       void __main (void);
1166       void __main (void) {}
1167       ]], [[]])], [flag=1], [flag=0])
1168       if test x"$flag" = x1; then
1169         grub_cv_target_cc_link_format="$format"
1170         break
1171       fi
1172     done])
1173   if test x"$grub_cv_target_cc_link_format" = xunknown; then
1174     AC_MSG_ERROR([no suitable link format found])
1175   fi
1176   TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
1177   if test x"$grub_cv_target_cc_link_format" = x-mi386pe ; then
1178     TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
1179   fi
1180   if test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
1181     TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
1182   fi
1185 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
1186    TARGET_APPLE_LINKER=1
1187    AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
1188    if test "x$TARGET_OBJCONV" = x ; then
1189       AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
1190    fi
1191    if test "x$TARGET_OBJCONV" = x ; then
1192       AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
1193    fi
1194    TARGET_IMG_LDSCRIPT=
1195    TARGET_IMG_CFLAGS="-static"
1196    TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
1197    TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
1198    TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
1199    TARGET_LDFLAGS_OLDMAGIC=""
1200 elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
1201   TARGET_APPLE_LINKER=0
1202   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
1203   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/i386-cygwin-img-ld.sc"
1204   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
1205   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/i386-cygwin-img-ld.sc"
1206   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
1207   TARGET_IMG_CFLAGS=
1208 else
1209   TARGET_APPLE_LINKER=0
1210   TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
1211   TARGET_IMG_LDSCRIPT=
1212   TARGET_IMG_LDFLAGS='-Wl,-N'
1213   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
1214   TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
1215   TARGET_IMG_CFLAGS=
1218 CFLAGS="$TARGET_CFLAGS"
1220 AC_ARG_ENABLE([efiemu],
1221               [AS_HELP_STRING([--enable-efiemu],
1222                              [build and install the efiemu runtimes (default=guessed)])])
1223 if test x"$enable_efiemu" = xno ; then
1224   efiemu_excuse="explicitly disabled"
1227 if test x"$grub_cv_target_cc_link_format" = x-mi386pe || test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
1228   efiemu_excuse="not available on cygwin"
1230 if test x"$target_cpu" != xi386 ; then
1231   efiemu_excuse="only available on i386"
1233 if test x"$platform" = xefi ; then
1234   efiemu_excuse="not available on efi"
1237 if test x"$efiemu_excuse" = x ; then
1238   AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
1239     CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
1240     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1241                       [grub_cv_cc_efiemu=yes],
1242                       [grub_cv_cc_efiemu=no])
1243   ])
1244   if test x$grub_cv_cc_efiemu = xno; then
1245      efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
1246   fi
1248 if test x"$efiemu_excuse" = x ; then
1249   AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [
1250     grub_cv_target_cc_efiemu64_link_format=unknown
1251     for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do
1252       CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
1253       LDFLAGS="-m64 -Wl,$format -nostdlib -static"
1254       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1255       asm (".globl start; start:");
1256       asm (".globl _start; _start:");
1257       asm (".globl __start; __start:");
1258       void __main (void);
1259       void __main (void) {}
1260       ]], [[]])], [flag=1], [flag=0])
1261       if test x"$flag" = x1; then
1262         grub_cv_target_cc_efiemu64_link_format="$format"
1263         break
1264       fi
1265     done])
1266   if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then
1267     efiemu_excuse="no suitable link format for efiemu64 found"
1268   else
1269     EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format"
1270   fi
1272 if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
1273   AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled ($efiemu_excuse)])
1275 if test x"$efiemu_excuse" = x ; then
1276 enable_efiemu=yes
1277 else
1278 enable_efiemu=no
1280 AC_SUBST([enable_efiemu])
1281 AC_SUBST([EFIEMU64_LINK_FORMAT])
1283 CFLAGS="$TARGET_CFLAGS"
1285 AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
1288 LDFLAGS="$TARGET_LDFLAGS"
1290 if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64 ; then
1291   # Use large model to support 4G memory
1292   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
1293     CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1294     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1295                       [grub_cv_cc_mcmodel=yes],
1296                       [grub_cv_cc_mcmodel=no])
1297   ])
1298   if test "x$grub_cv_cc_mcmodel" = xyes; then
1299     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1300   elif test "$target_cpu" = sparc64 || test "$target_cpu" = riscv64; then
1301     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
1302   fi
1305 if test "$target_cpu"-"$platform" = x86_64-efi; then
1306   # EFI writes to stack below %rsp, we must not use the red zone
1307   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
1308     CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1309     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1310                       [grub_cv_cc_no_red_zone=yes],
1311                       [grub_cv_cc_no_red_zone=no])
1312   ])
1313   if test "x$grub_cv_cc_no_red_zone" = xno; then
1314     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
1315   fi
1317   TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1320 if test "x$target_cpu" = xarm; then
1321   AC_CACHE_CHECK([for options to disable movt and movw], grub_cv_target_cc_mno_movt, [
1322     grub_cv_target_cc_mno_movt=no
1323     for cand in "-mno-movt" \
1324                 "-mllvm -arm-use-movt=0" \
1325                 "-mword-relocations"; do
1326       if test x"$grub_cv_target_cc_mno_movt" != xno ; then
1327         break
1328       fi
1329       CFLAGS="$TARGET_CFLAGS $cand -Werror"
1330       CPPFLAGS="$TARGET_CPPFLAGS"
1331       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1332                         [grub_cv_target_cc_mno_movt="$cand"], [])
1333     done
1334   ])
1336   if test x"$grub_cv_target_cc_mno_movt" != xno ; then
1337     # A trick so that clang doesn't see it on link stage
1338     TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_movt"
1339   fi
1340   AC_CACHE_CHECK([whether option -mthumb-interwork works], grub_cv_cc_mthumb_interwork, [
1341     CFLAGS="$TARGET_CFLAGS -mthumb-interwork -Werror"
1342     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1343                       [grub_cv_cc_mthumb_interwork=yes],
1344                       [grub_cv_cc_mthumb_interwork=no])
1345   ])
1346   if test "x$grub_cv_cc_mthumb_interwork" = xyes; then
1347     TARGET_CFLAGS="$TARGET_CFLAGS -mthumb-interwork"
1348   # Clang defaults to thumb interworking
1349   elif test "x$grub_cv_cc_target_clang" = xno ; then
1350     AC_MSG_ERROR([your compiler doesn't support -mthumb-interwork])
1351   fi
1354 AC_CACHE_CHECK([whether option -Qn works], grub_cv_target_cc_qn, [
1355   CFLAGS="$TARGET_CFLAGS -Qn -Qunused-arguments -Werror"
1356   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
1357                     [grub_cv_target_cc_qn=yes],
1358                     [grub_cv_target_cc_qn=no])])
1359 if test "x$grub_cv_target_cc_qn" = xyes; then
1360   TARGET_CFLAGS="$TARGET_CFLAGS -Qn -Qunused-arguments"
1364 # Compiler features.
1367 CFLAGS="$TARGET_CFLAGS"
1369 # Position independent executable.
1370 grub_CHECK_PIE
1371 grub_CHECK_NO_PIE
1372 grub_CHECK_NO_PIE_ONEWORD
1373 grub_CHECK_LINK_PIE
1374 [# Need that, because some distributions ship compilers that include
1375 # `-fPIE' or '-fpie' and '-pie' in the default specs.
1376 if [ x"$pie_possible" = xyes ]; then
1377   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE -fno-pie"
1378   TARGET_CCASFLAGS="$TARGET_CCASFLAGS -fno-PIE -fno-pie"
1381 if [ x"$link_nopie_needed" = xyes ] || [ x"$pie_possible" = xyes ]; then
1382   if [ x"$nopie_possible" = xyes ]; then
1383     TARGET_LDFLAGS="$TARGET_LDFLAGS -no-pie"
1384   fi
1385   if [ x"$nopie_oneword_possible" = xyes ]; then
1386     TARGET_LDFLAGS="$TARGET_LDFLAGS -nopie"
1387   fi
1390 CFLAGS="$TARGET_CFLAGS"
1391 LDFLAGS="$TARGET_LDFLAGS"
1393 # Position independent executable.
1394 grub_CHECK_PIC
1395 [# On most platforms we don't want PIC as it only makes relocations harder
1396 # and code less efficient. On mips we want to have one got table per module
1397 # and reload $gp in every function.
1398 # GCC implements it using symbol __gnu_local_gp in non-PIC as well.
1399 # However with clang we need PIC for this reloading to happen.
1400 # With arm64 we need relocations that are in some way representable in
1401 # PE as we need to support arm64-efi. Without -fPIC clang generates
1402 # movk's which aren't representable.
1403 # Since default varies across dictributions use either -fPIC or -fno-PIC
1404 # explicitly.
1405 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
1406    TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
1407 elif [ x"$pic_possible" = xyes ]; then
1408    TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
1411 CFLAGS="$TARGET_CFLAGS"
1413 # Stack smashing protector.
1414 grub_CHECK_STACK_PROTECTOR
1415 AC_ARG_ENABLE([stack-protector],
1416               AS_HELP_STRING([--enable-stack-protector],
1417                              [enable the stack protector]),
1418               [],
1419               [enable_stack_protector=no])
1420 if test "x$enable_stack_protector" = xno; then
1421   if test "x$ssp_possible" = xyes; then
1422     # Need that, because some distributions ship compilers that include
1423     # `-fstack-protector' in the default specs.
1424     TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
1425   fi
1426 elif test "x$platform" != xefi; then
1427   if test "$ERROR_PLATFORM_NOT_SUPPORT_SSP" = "yes"; then
1428     AC_MSG_ERROR([--enable-stack-protector is only supported on EFI platforms])
1429   else
1430     AC_MSG_WARN([--enable-stack-protector is only supported on EFI platforms])
1431   fi
1432   enable_stack_protector=no
1433 elif test "x$ssp_global_possible" != xyes; then
1434   AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -mstack-protector-guard=global)])
1435 else
1436   TARGET_CFLAGS="$TARGET_CFLAGS -mstack-protector-guard=global"
1437   if test "x$enable_stack_protector" = xyes; then
1438     if test "x$ssp_possible" != xyes; then
1439       AC_MSG_ERROR([--enable-stack-protector is not supported (compiler doesn't support -fstack-protector)])
1440     fi
1441     TARGET_CFLAGS="$TARGET_CFLAGS -fstack-protector"
1442   elif test "x$enable_stack_protector" = xstrong; then
1443     if test "x$ssp_strong_possible" != xyes; then
1444       AC_MSG_ERROR([--enable-stack-protector=strong is not supported (compiler doesn't support -fstack-protector-strong)])
1445     fi
1446     TARGET_CFLAGS="$TARGET_CFLAGS -fstack-protector-strong"
1447   else
1448     # Note, -fstack-protector-all requires that the protector is disabled for
1449     # functions that appear in the call stack when the canary is initialized.
1450     AC_MSG_ERROR([invalid value $enable_stack_protector for --enable-stack-protector])
1451   fi
1452   TARGET_CPPFLAGS="$TARGET_CPPFLAGS -DGRUB_STACK_PROTECTOR=1"
1454   if test -n "$SOURCE_DATE_EPOCH"; then
1455      GRUB_STACK_PROTECTOR_INIT="0x00f2b7e2$(printf "%x" "$SOURCE_DATE_EPOCH" | sed 's/.*\(........\)$/\1/')"
1456   elif test -r /dev/urandom; then
1457      # Generate the 8 byte stack protector canary at build time if /dev/urandom
1458      # is able to be read. The first byte should be NUL to filter out string
1459      # buffer overflow attacks.
1460      GRUB_STACK_PROTECTOR_INIT="$($PYTHON -c 'import codecs; rf=open("/dev/urandom", "rb"); print("0x00"+codecs.encode(rf.read(7), "hex").decode("ascii"))')"
1461   else
1462     # Some hosts may not have a urandom, e.g. Windows, so use statically
1463     # generated random bytes
1464     GRUB_STACK_PROTECTOR_INIT="0x00f2b7e2f193b25c"
1465   fi
1467   if test x"$target_m32" = x1 ; then
1468     # Make sure that the canary default value is 24-bits by only using the
1469     # lower 3 bytes on 32 bit systems. This allows the upper byte to be NUL
1470     # to filter out string buffer overflow attacks.
1471     GRUB_STACK_PROTECTOR_INIT="0x00$(echo "$GRUB_STACK_PROTECTOR_INIT" | sed 's/.*\(......\)$/\1/')"
1472   fi
1474   AC_SUBST([GRUB_STACK_PROTECTOR_INIT])
1477 CFLAGS="$TARGET_CFLAGS"
1479 grub_CHECK_STACK_ARG_PROBE
1480 # Cygwin's GCC uses alloca() to probe the stackframe on static
1481 # stack allocations above some threshold.
1482 if test x"$sap_possible" = xyes; then
1483   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
1486 CFLAGS="$TARGET_CFLAGS"
1488 # -mno-unaligned-access -mstrict-align
1489 if test "$target_cpu" = arm; then
1490   AC_CACHE_CHECK([for compile options to get strict alignment], [grub_cv_target_cc_strict_align], [
1491     grub_cv_target_cc_strict_align=
1492     for arg in -mno-unaligned-access "-Xclang -mstrict-align" -mstrict-align; do
1493       CFLAGS="$TARGET_CFLAGS $arg -Werror"
1494       LDFLAGS="$TARGET_LDFLAGS"
1495       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
1496       if test x"$flag" = x1; then
1497         grub_cv_target_cc_strict_align="$arg"
1498         break
1499       fi
1500     done])
1502   TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_strict_align"
1503   if test x"$grub_cv_target_cc_strict_align" = x"-Xclang -mstrict-align"; then
1504     TARGET_LDFLAGS="$TARGET_LDFLAGS -Qunused-arguments"
1505   fi
1506   AC_CACHE_CHECK([if compiler generates unaligned accesses], [grub_cv_cc_target_emits_unaligned],
1507   [CFLAGS="$TARGET_CFLAGS"
1508    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1509 #ifdef __ARM_FEATURE_UNALIGNED
1510 #error "unaligned"
1511 #endif
1512      ]])],
1513      [grub_cv_cc_target_emits_unaligned=no], [grub_cv_cc_target_emits_unaligned=yes])])
1514   if test x$grub_cv_cc_target_emits_unaligned = xyes; then
1515     AC_MSG_ERROR([compiler generates unaligned accesses])
1516   fi
1519 # Set them to their new values for the tests below.
1520 CC="$TARGET_CC"
1521 CPPFLAGS="$TARGET_CPPFLAGS"
1523 # Check for libgcc symbols
1524 if test x"$platform" = xemu; then
1525 CFLAGS="$TARGET_CFLAGS -Wno-error"
1526 AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __clzdi2 __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)
1529 if test "x$TARGET_APPLE_LINKER" = x1 ; then
1530 CFLAGS="$TARGET_CFLAGS -nostdlib -static"
1531 else
1532 CFLAGS="$TARGET_CFLAGS -nostdlib"
1534 LIBS=""
1536 # Defined in acinclude.m4.
1537 grub_ASM_USCORE
1538 grub_PROG_TARGET_CC
1539 if test "x$TARGET_APPLE_LINKER" != x1 ; then
1540 grub_PROG_OBJCOPY_ABSOLUTE
1542 grub_PROG_LD_BUILD_ID_NONE
1543 if test "x$target_cpu" = xi386; then
1544   if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
1545     if test ! -z "$TARGET_IMG_LDSCRIPT"; then
1546       # Check symbols provided by linker script.
1547       CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
1548     fi
1549     grub_CHECK_BSS_START_SYMBOL
1550     grub_CHECK_END_SYMBOL
1551   fi
1552   CFLAGS="$TARGET_CFLAGS"
1555 grub_PROG_NM_WORKS
1556 grub_PROG_NM_MINUS_P
1557 grub_PROG_NM_DEFINED_ONLY
1558 AC_SUBST(TARGET_NMFLAGS_MINUS_P)
1559 AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)
1561 if test "$platform" != emu; then
1562 AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
1563   SAVED_CPPFLAGS="$CPPFLAGS"
1564   CPPFLAGS="$TARGET_CPPFLAGS -nostdlib -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
1565   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1566 #include <stddef.h>
1567 int va_arg_func (int fixed, va_list args);]], [[]])],
1568       [grub_cv_cc_isystem=yes],
1569       [grub_cv_cc_isystem=no])
1570   CPPFLAGS="$SAVED_CPPFLAGS"
1573   if test x"$grub_cv_cc_isystem" = xyes ; then
1574     TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
1575   fi
1578 AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_cc_wtrampolines], [
1579   CFLAGS="$TARGET_CFLAGS -Wtrampolines -Werror"
1580   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1581 int va_arg_func (int fixed, va_list args);]], [[]])],
1582       [grub_cv_cc_wtrampolines=yes],
1583       [grub_cv_cc_wtrampolines=no])
1586 if test x"$grub_cv_cc_wtrampolines" = xyes ; then
1587   TARGET_CFLAGS="$TARGET_CFLAGS -Wtrampolines"
1590 # Restore the flags.
1591 CC="$tmp_CC"
1592 CFLAGS="$tmp_CFLAGS"
1593 CPPFLAGS="$tmp_CPPFLAGS"
1594 LDFLAGS="$tmp_LDFLAGS"
1595 LIBS="$tmp_LIBS"
1598 # Check for options.
1601 # Memory manager debugging.
1602 AC_ARG_ENABLE([mm-debug],
1603               AS_HELP_STRING([--enable-mm-debug],
1604                              [include memory manager debugging]))
1605 if test x$enable_mm_debug = xyes; then
1606   MM_DEBUG=1
1607 else
1608   MM_DEBUG=0
1610 AC_SUBST([MM_DEBUG])
1611 AM_CONDITIONAL([COND_MM_DEBUG], [test x$MM_DEBUG = x1])
1613 AC_ARG_ENABLE([cache-stats],
1614               AS_HELP_STRING([--enable-cache-stats],
1615                              [enable disk cache statistics collection]))
1617 if test x$enable_cache_stats = xyes; then
1618   DISK_CACHE_STATS=1
1619 else
1620   DISK_CACHE_STATS=0
1622 AC_SUBST([DISK_CACHE_STATS])
1624 AC_ARG_ENABLE([boot-time],
1625               AS_HELP_STRING([--enable-boot-time],
1626                              [enable boot time statistics collection]))
1628 if test x$enable_boot_time = xyes; then
1629   BOOT_TIME_STATS=1
1630 else
1631   BOOT_TIME_STATS=0
1633 AC_SUBST([BOOT_TIME_STATS])
1635 AC_ARG_ENABLE([grub-emu-sdl2],
1636               [AS_HELP_STRING([--enable-grub-emu-sdl2],
1637                              [build and install the `grub-emu' debugging utility with SDL2 support (default=guessed)])])
1639 AC_ARG_ENABLE([grub-emu-sdl],
1640               [AS_HELP_STRING([--enable-grub-emu-sdl],
1641                              [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
1643 AC_ARG_ENABLE([grub-emu-pci],
1644               [AS_HELP_STRING([--enable-grub-emu-pci],
1645                              [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
1647 if test "$platform" = emu; then
1648   if test x"$enable_grub_emu_sdl2" = xno ; then
1649     grub_emu_sdl2_excuse="explicitly disabled"
1650   fi
1651   [if [ x"$grub_emu_sdl2_excuse" = x ]; then
1652     # Check for libSDL libraries.]
1653     PKG_CHECK_MODULES([SDL2], [sdl2], [
1654             AC_DEFINE([HAVE_SDL2], [1], [Define to 1 if you have SDL2 library.])
1655             AC_SUBST(HAVE_SDL2)],
1656             [grub_emu_sdl2_excuse="libSDL2 libraries are required to build \`grub-emu' with SDL2 support"])
1657   [fi]
1658   if test x"$enable_grub_emu_sdl2" = xyes && test x"$grub_emu_sdl2_excuse" != x ; then
1659     AC_MSG_ERROR([SDL2 support for grub-emu was explicitly requested but can't be compiled ($grub_emu_sdl2_excuse)])
1660   fi
1661   if test x"$grub_emu_sdl2_excuse" = x ; then
1662     enable_grub_emu_sdl2=yes
1663   else
1664     enable_grub_emu_sdl2=no
1665   fi
1666   if test x"$enable_grub_emu_sdl2" = xyes ; then
1667     grub_emu_sdl_excuse="disabled by sdl2"
1668   fi
1671   if test x"$enable_grub_emu_sdl" = xno ; then
1672     grub_emu_sdl_excuse="explicitly disabled"
1673   fi
1674   [if [ x"$grub_emu_sdl_excuse" = x ]; then
1675     # Check for libSDL libraries.]
1676 AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
1677     [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
1678     AC_SUBST([LIBSDL])
1679   [fi]
1681   [if [ x"$grub_emu_sdl_excuse" = x ]; then
1682     # Check for headers.]
1683     AC_CHECK_HEADERS([SDL/SDL.h], [],
1684       [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
1685   [fi]
1687   if test x"$enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
1688     AC_MSG_ERROR([SDL support for grub-emu was explicitly requested but can't be compiled ($grub_emu_sdl_excuse)])
1689   fi
1690   if test x"$grub_emu_sdl_excuse" = x ; then
1691     enable_grub_emu_sdl=yes
1692   else
1693     enable_grub_emu_sdl=no
1694   fi
1696   if test x"$enable_grub_emu_pci" != xyes ; then
1697     grub_emu_pci_excuse="not enabled"
1698   fi
1700   [if [ x"$grub_emu_pci_excuse" = x ]; then
1701     # Check for libpci libraries.]
1702     AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
1703       [grub_emu_pci_excuse=["need libpciaccess library"]])
1704     AC_SUBST([LIBPCIACCESS])
1705   [fi]
1706   [if [ x"$grub_emu_pci_excuse" = x ]; then
1707     # Check for headers.]
1708     AC_CHECK_HEADERS([pciaccess.h], [],
1709       [grub_emu_pci_excuse=["need libpciaccess headers"]])
1710   [fi]
1712   if test x"$grub_emu_pci_excuse" = x ; then
1713     enable_grub_emu_pci=yes
1714   else
1715     enable_grub_emu_pci=no
1716   fi
1718   AC_SUBST([enable_grub_emu_sdl2])
1719   AC_SUBST([enable_grub_emu_sdl])
1720   AC_SUBST([enable_grub_emu_pci])
1722 else
1724   # Ignore --enable-emu-* if platform is not emu
1725   enable_grub_emu_sdl2=no
1726   enable_grub_emu_sdl=no
1727   enable_grub_emu_pci=no
1730 AC_ARG_ENABLE([grub-mkfont],
1731               [AS_HELP_STRING([--enable-grub-mkfont],
1732                              [build and install the `grub-mkfont' utility (default=guessed)])])
1733 if test x"$enable_grub_mkfont" = xno ; then
1734   grub_mkfont_excuse="explicitly disabled"
1737 unset ac_cv_header_ft2build_h
1739 if test x"$grub_mkfont_excuse" = x ; then
1740   # Check for freetype libraries.
1741   PKG_CHECK_MODULES([FREETYPE], [freetype2], [
1742     SAVED_CPPFLAGS="$CPPFLAGS"
1743     SAVED_LIBS="$LIBS"
1744     CPPFLAGS="$CPPFLAGS $FREETYPE_CFLAGS"
1745     LIBS="$LIBS $FREETYPE_LIBS"
1746     AC_CHECK_HEADERS([ft2build.h], [],
1747       [grub_mkfont_excuse=["need freetype2 headers"]])
1748     AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [],
1749       [grub_mkfont_excuse=["freetype2 library unusable"]])
1750     CPPFLAGS="$SAVED_CPPFLAGS"
1751     LIBS="$SAVED_LIBS"
1752   ], [grub_mkfont_excuse=["need freetype2 library"]])
1753   if test x"$grub_mkfont_excuse" = x && test x"$host_kernel" = xnetbsd ; then
1754       FREETYPE_LIBS="$FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;
1755   fi
1758 if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
1759   AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled ($grub_mkfont_excuse)])
1761 if test x"$grub_mkfont_excuse" = x ; then
1762   enable_grub_mkfont=yes
1763 else
1764   enable_grub_mkfont=no
1766 AC_SUBST([enable_grub_mkfont])
1768 SAVED_CC="$CC"
1769 SAVED_CPP="$CPP"
1770 SAVED_CFLAGS="$CFLAGS"
1771 SAVED_CPPFLAGS="$CPPFLAGS"
1772 SAVED_LDFLAGS="$LDFLAGS"
1773 CC="$BUILD_CC"
1774 CPP="$BUILD_CPP"
1775 CFLAGS="$BUILD_CFLAGS"
1776 CPPFLAGS="$BUILD_CPPFLAGS"
1777 LDFLAGS="$BUILD_LDFLAGS"
1779 unset ac_cv_c_bigendian
1780 unset ac_cv_header_ft2build_h
1782 AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
1783 AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
1784 AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
1786 if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
1787    AC_MSG_ERROR([couldnt determine build endianness])
1790 AC_SUBST([BUILD_SIZEOF_LONG])
1791 AC_SUBST([BUILD_SIZEOF_VOID_P])
1792 AC_SUBST([BUILD_WORDS_BIGENDIAN])
1794 if test x"$grub_build_mkfont_excuse" = x ; then
1795   # Check for freetype libraries.
1796   SAVED_PKG_CONFIG="$PKG_CONFIG"
1797   test -z "$BUILD_PKG_CONFIG" || PKG_CONFIG="$BUILD_PKG_CONFIG"
1798   PKG_CHECK_MODULES([BUILD_FREETYPE], [freetype2], [
1799     SAVED_CPPFLAGS_2="$CPPFLAGS"
1800     SAVED_LIBS="$LIBS"
1801     CPPFLAGS="$CPPFLAGS $BUILD_FREETYPE_CFLAGS"
1802     LIBS="$LIBS $BUILD_FREETYPE_LIBS"
1803     AC_CHECK_HEADERS([ft2build.h], [],
1804       [grub_build_mkfont_excuse=["need freetype2 headers"]])
1805     AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [],
1806       [grub_build_mkfont_excuse=["freetype2 library unusable"]])
1807     LIBS="$SAVED_LIBS"
1808     CPPFLAGS="$SAVED_CPPFLAGS_2"
1809   ], [grub_build_mkfont_excuse=["need freetype2 library"]])
1810   if test x"$grub_build_mkfont_excuse" = x ; then
1811     case x"$build_os" in
1812       xnetbsd*) BUILD_FREETYPE_LIBS="$BUILD_FREETYPE_LIBS -Wl,-R,/usr/pkg/lib" ;;
1813     esac
1814   fi
1815   PKG_CONFIG="$SAVED_PKG_CONFIG"
1818 if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
1819   AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled ($grub_build_mkfont_excuse)])
1821 if test x"$grub_build_mkfont_excuse" = x ; then
1822   enable_build_grub_mkfont=yes
1823 else
1824   enable_build_grub_mkfont=no
1826 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
1827   if test x"$grub_build_mkfont_excuse" = x ; then
1828     AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont])
1829   else
1830     AC_MSG_ERROR([qemu, coreboot and loongson ports need build-time grub-mkfont ($grub_build_mkfont_excuse)])
1831   fi
1834 CC="$SAVED_CC"
1835 CPP="$SAVED_CPP"
1836 CFLAGS="$SAVED_CFLAGS"
1837 CPPFLAGS="$SAVED_CPPFLAGS"
1838 LDFLAGS="$SAVED_LDFLAGS"
1841 starfield_excuse=
1843 AC_ARG_ENABLE([grub-themes],
1844               [AS_HELP_STRING([--enable-grub-themes],
1845                              [build and install GRUB themes (default=guessed)])])
1846 if test x"$enable_grub_themes" = xno ; then
1847   starfield_excuse="explicitly disabled"
1850 if test x"$starfield_excuse" = x && test x"$enable_build_grub_mkfont" = xno ; then
1851   starfield_excuse="No build-time grub-mkfont"
1854 AC_ARG_WITH([dejavufont],
1855             AS_HELP_STRING([--with-dejavufont=FILE],
1856                            [set the DejeVu source [[guessed]]]))
1858 if test "x$with_dejavufont" = x; then
1859   # search in well-known directories
1860   if test x"$starfield_excuse" = x; then
1861      for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1862        for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype /usr/pkg/share/fonts/X11/TTF /usr/local/share/fonts/dejavu /usr/X11R6/lib/X11/fonts/TTF /usr/share/fonts/dejavu-sans-fonts /usr/share/fonts/truetype/dejavu; do
1863           if test -f "$dir/DejaVuSans.$ext"; then
1864             DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
1865             break 2
1866           fi
1867        done
1868      done
1870      if test "x$DJVU_FONT_SOURCE" = x; then
1871        starfield_excuse="No DejaVu found"
1872      fi
1873   fi
1874 else
1875   DJVU_FONT_SOURCE="$with_dejavufont"
1878 if test x"$enable_grub_themes" = xyes &&  test x"$starfield_excuse" != x; then
1879    AC_MSG_ERROR([themes were explicitly requested but requirements are not satisfied ($starfield_excuse)])
1882 AC_SUBST([DJVU_FONT_SOURCE])
1884 AC_ARG_WITH([unifont],
1885             AS_HELP_STRING([--with-unifont=FILE],
1886                            [set the unifont source [[guessed]]]))
1888 if test "x$with_unifont" = x; then
1889   # search in well-known directories
1890   for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz otf otf.gz; do
1891     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 /usr/pkg/share/fonts/X11/misc /usr/local/share/fonts/gnu-unifont /usr/local/share/fonts/unifont; do
1892       if test -f "$dir/unifont.$ext"; then
1893         md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
1894         # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
1895         if test "$md5" = 0a54834d2788c83886a3e1785a6a1e61 || test "$md5" = 28f2565c7a41d8d407e2551159385edb || test "$md5" = dae5e588461b3b92b87b6ffee734f936 || test "$md5" = 4a3d687aa5bb329ed05f4263a1016791 ; then
1896           continue
1897         fi
1898         FONT_SOURCE="$dir/unifont.$ext"
1899         break 2
1900       fi
1901     done
1902   done
1903 else
1904   FONT_SOURCE="$with_unifont"
1907 if test x"$enable_build_grub_mkfont" = xno ; then
1908   FONT_SOURCE=
1911 if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$platform" = xcoreboot ); then
1912   if test x"$grub_build_mkfont_excuse" = x ; then
1913     AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont])
1914   else
1915     AC_MSG_ERROR([qemu, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)])
1916   fi
1919 AC_SUBST([FONT_SOURCE])
1921 if test x"$FONT_SOURCE" = x &&  test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
1922   grub_build_mkfont_excuse="no fonts"
1926 AC_ARG_ENABLE([grub-mount],
1927               [AS_HELP_STRING([--enable-grub-mount],
1928                              [build and install the `grub-mount' utility (default=guessed)])])
1929 if test x"$enable_grub_mount" = xno ; then
1930   grub_mount_excuse="explicitly disabled"
1933 if test x"$grub_mount_excuse" = x ; then
1934   PKG_CHECK_MODULES([FUSE], [fuse3], [FUSE_CFLAGS="$FUSE_CFLAGS -DFUSE_USE_VERSION=32"], [
1935     PKG_CHECK_MODULES([FUSE], [fuse], [FUSE_CFLAGS="$FUSE_CFLAGS -DFUSE_USE_VERSION=26"], [
1936       grub_mount_excuse="need fuse or fuse3 libraries"
1937     ])
1938   ])
1941 if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then
1942   AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled ($grub_mount_excuse)])
1944 if test x"$grub_mount_excuse" = x ; then
1945 enable_grub_mount=yes
1946 else
1947 enable_grub_mount=no
1949 AC_SUBST([enable_grub_mount])
1951 AC_ARG_ENABLE([device-mapper],
1952               [AS_HELP_STRING([--enable-device-mapper],
1953                               [enable Linux device-mapper support (default=guessed)])])
1954 if test x"$enable_device_mapper" = xno ; then
1955   device_mapper_excuse="explicitly disabled"
1958 if test x"$device_mapper_excuse" = x ; then
1959   # Check for device-mapper header.
1960   AC_CHECK_HEADER([libdevmapper.h], [],
1961                [device_mapper_excuse="need libdevmapper header"])
1964 if test x"$device_mapper_excuse" = x ; then
1965   # Check for device-mapper library.
1966   AC_CHECK_LIB([devmapper], [dm_task_create], [],
1967                [device_mapper_excuse="need devmapper library"])
1970 if test x"$device_mapper_excuse" = x ; then
1971   # Check for device-mapper library.
1972   AC_CHECK_LIB([devmapper], [dm_log_with_errno_init],
1973                [],
1974                [device_mapper_excuse="need devmapper library"])
1977 if test x"$device_mapper_excuse" = x ; then
1978    LIBDEVMAPPER="-ldevmapper"
1979    AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
1980              [Define to 1 if you have the devmapper library.])
1983 AC_SUBST([LIBDEVMAPPER])
1985 LIBGEOM=
1986 if test x$host_kernel = xkfreebsd; then
1987   AC_CHECK_LIB([geom], [geom_gettree], [],
1988                [AC_MSG_ERROR([Your platform requires libgeom])])
1989   LIBGEOM="-lgeom"
1992 AC_SUBST([LIBGEOM])
1994 AC_ARG_ENABLE([liblzma],
1995               [AS_HELP_STRING([--enable-liblzma],
1996                               [enable liblzma integration (default=guessed)])])
1997 if test x"$enable_liblzma" = xno ; then
1998   liblzma_excuse="explicitly disabled"
2001 if test x"$liblzma_excuse" = x ; then
2002 AC_CHECK_LIB([lzma], [lzma_code],
2003              [],[liblzma_excuse="need lzma library"])
2005 if test x"$liblzma_excuse" = x ; then
2006 AC_CHECK_HEADER([lzma.h], [], [liblzma_excuse="need lzma header"])
2009 if test x"$enable_liblzma" = xyes && test x"$liblzma_excuse" != x ; then
2010   AC_MSG_ERROR([liblzma support was explicitly requested but requirements are not satisfied ($liblzma_excuse)])
2014 if test x"$liblzma_excuse" = x ; then
2015    LIBLZMA="-llzma"
2016    AC_DEFINE([USE_LIBLZMA], [1],
2017              [Define to 1 if you have the LZMA library.])
2020 AC_SUBST([LIBLZMA])
2022 AC_ARG_ENABLE([libzfs],
2023               [AS_HELP_STRING([--enable-libzfs],
2024                               [enable libzfs integration (default=guessed)])])
2025 if test x"$enable_libzfs" = xno ; then
2026   libzfs_excuse="explicitly disabled"
2029 if test x"$libzfs_excuse" = x ; then
2030   # Only check for system headers if libzfs support has not been disabled.
2031   AC_CHECK_HEADERS(libzfs.h libnvpair.h)
2034 if test x"$libzfs_excuse" = x ; then
2035   AC_CHECK_LIB([zfs], [libzfs_init],
2036                [],
2037                [libzfs_excuse="need zfs library"])
2040 if test x"$libzfs_excuse" = x ; then
2041   AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
2042                [have_normal_nvpair=yes],
2043                [have_normal_nvpair=no])
2044   if test x"$have_normal_nvpair" = xno ; then
2045     AC_CHECK_LIB([nvpair], [opensolaris_nvlist_lookup_string],
2046                  [have_prefixed_nvpair=yes],
2047                  [have_prefixed_nvpair=no])
2048     if test x"$have_prefixed_nvpair" = xyes ; then
2049       AC_DEFINE([GRUB_UTIL_NVPAIR_IS_PREFIXED], [1],
2050             [Define to 1 if libnvpair symbols are prefixed with opensolaris_.])
2051     else
2052       libzfs_excuse="need nvpair library"
2053     fi
2054   fi
2057 if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
2058   AC_MSG_ERROR([libzfs support was explicitly requested but requirements are not satisfied ($libzfs_excuse)])
2061 if test x"$libzfs_excuse" = x ; then
2062   # We need both libzfs and libnvpair for a successful build.
2063   LIBZFS="-lzfs"
2064   LIBNVPAIR="-lnvpair"
2065   AC_DEFINE([USE_LIBZFS], [1],
2066             [Define to 1 if ZFS library should be used.])
2069 AC_SUBST([LIBZFS])
2070 AC_SUBST([LIBNVPAIR])
2072 AC_ARG_ENABLE([grub-protect],
2073               [AS_HELP_STRING([--enable-grub-protect],
2074                              [build and install the `grub-protect' utility (default=guessed)])])
2075 if test x"$enable_grub_protect" = xno ; then
2076   grub_protect_excuse="explicitly disabled"
2079 LIBTASN1=
2080 if test x"$grub_protect_excuse" = x ; then
2081   AC_CHECK_LIB([tasn1], [asn1_write_value], [LIBTASN1="-ltasn1"], [grub_protect_excuse="need libtasn1 library"])
2083 AC_SUBST([LIBTASN1])
2085 if test x"$enable_grub_protect" = xyes && test x"$grub_protect_excuse" != x ; then
2086   AC_MSG_ERROR([grub-protect was explicitly requested but can't be compiled ($grub_protect_excuse)])
2088 if test x"$grub_protect_excuse" = x ; then
2089 enable_grub_protect=yes
2090 else
2091 enable_grub_protect=no
2093 AC_SUBST([enable_grub_protect])
2095 LIBS=""
2097 AC_SUBST([FONT_SOURCE])
2098 AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
2099             [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
2101 AC_SUBST(HAVE_ASM_USCORE)
2102 AC_SUBST(BSS_START_SYMBOL)
2103 AC_SUBST(END_SYMBOL)
2104 AC_SUBST(PACKAGE)
2105 AC_SUBST(VERSION)
2107 AC_ARG_ENABLE([werror],
2108               [AS_HELP_STRING([--disable-werror],
2109                              [do not use -Werror when building GRUB])])
2110 if test x"$enable_werror" != xno ; then
2111   TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
2112   HOST_CFLAGS="$HOST_CFLAGS -Werror"
2113   if test "x$grub_cv_cc_target_clang" = xyes; then
2114     TARGET_CFLAGS="$TARGET_CFLAGS -Wno-error=vla"
2115     HOST_CFLAGS="$HOST_CFLAGS -Wno-error=vla"
2116   fi
2119 TARGET_CPP="$TARGET_CC -E"
2120 TARGET_CCAS=$TARGET_CC
2122 # Includes which include make-time substitutions. They must come last
2123 # as to avoid executing top_builddir in shell.
2124 HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
2125 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
2126 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"
2128 GRUB_TARGET_CPU="${target_cpu}"
2129 GRUB_PLATFORM="${platform}"
2131 AC_SUBST(GRUB_TARGET_CPU)
2132 AC_SUBST(GRUB_PLATFORM)
2134 AC_SUBST(TARGET_OBJCONV)
2135 AC_SUBST(TARGET_CPP)
2136 AC_SUBST(TARGET_CCAS)
2137 AC_SUBST(TARGET_OBJ2ELF)
2138 AC_SUBST(TARGET_MODULE_FORMAT)
2139 AC_SUBST(TARGET_CC_VERSION)
2141 AC_SUBST(TARGET_CFLAGS)
2142 AC_SUBST(TARGET_LDFLAGS)
2143 AC_SUBST(TARGET_CPPFLAGS)
2144 AC_SUBST(TARGET_CCASFLAGS)
2146 AC_SUBST(TARGET_IMG_LDFLAGS)
2147 AC_SUBST(TARGET_IMG_CFLAGS)
2148 AC_SUBST(TARGET_IMG_BASE_LDOPT)
2149 AC_SUBST(TARGET_APPLE_LINKER)
2151 AC_SUBST(HOST_CFLAGS)
2152 AC_SUBST(HOST_LDFLAGS)
2153 AC_SUBST(HOST_CPPFLAGS)
2154 AC_SUBST(HOST_CCASFLAGS)
2156 AC_SUBST(BUILD_LIBM)
2159 # Automake conditionals
2162 AM_CONDITIONAL([COND_real_platform], [test x$platform != xnone])
2163 AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
2164 AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
2165 AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
2166 AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot])
2167 AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
2168 AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
2169 AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
2170 AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
2171 AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
2172 AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
2173 AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
2174 AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
2175 AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
2176 AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
2177 AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
2178 AM_CONDITIONAL([COND_i386_xen_pvh], [test x$target_cpu = xi386 -a x$platform = xxen_pvh])
2179 AM_CONDITIONAL([COND_loongarch64], [test x$target_cpu = xloongarch64])
2180 AM_CONDITIONAL([COND_loongarch64_efi], [test x$target_cpu = xloongarch64 -a x$platform = xefi])
2181 AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
2182 AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xarc])
2183 AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
2184 AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xqemu_mips])
2185 AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
2186 AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
2187 AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
2188 AM_CONDITIONAL([COND_riscv32], [test x$target_cpu = xriscv32 ])
2189 AM_CONDITIONAL([COND_riscv64], [test x$target_cpu = xriscv64 ])
2190 AM_CONDITIONAL([COND_riscv32_efi], [test x$target_cpu = xriscv32 -a x$platform = xefi])
2191 AM_CONDITIONAL([COND_riscv64_efi], [test x$target_cpu = xriscv64 -a x$platform = xefi])
2192 AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
2193 AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform = xemu])
2194 AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
2195 AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
2197 AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
2198 AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
2199 AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
2200 AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
2201 AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
2202 AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
2203 AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])
2205 AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
2206 AM_CONDITIONAL([COND_GRUB_EMU_SDL2], [test x$enable_grub_emu_sdl2 = xyes])
2207 AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
2208 AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
2209 AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
2210 AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
2211 AM_CONDITIONAL([COND_GRUB_PROTECT], [test x$enable_grub_protect = xyes])
2212 AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
2213 if test x$FONT_SOURCE != x ; then
2214    HAVE_FONT_SOURCE=1
2215 else
2216    HAVE_FONT_SOURCE=0
2218 AC_SUBST(HAVE_FONT_SOURCE)
2219 AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
2220 AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
2221 AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
2222 AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
2224 AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
2226 AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
2227 AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
2228 AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])
2229 AM_CONDITIONAL([COND_HAVE_PCI], [test "x$have_pci" = xy])
2231 test "x$prefix" = xNONE && prefix="$ac_default_prefix"
2232 test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
2233 datarootdir="$(eval echo "$datarootdir")"
2234 grub_libdir="$(eval echo "$libdir")"
2235 grub_localedir="$(eval echo "$localedir")"
2236 grub_datadir="$(eval echo "$datadir")"
2237 grub_sysconfdir="$(eval echo "$sysconfdir")"
2238 AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
2239 AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
2240 AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
2241 AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
2244 # Output files.
2245 if test "$platform" != none; then
2246   cpudir="${target_cpu}"
2247   if test x${cpudir} = xmipsel; then
2248     cpudir=mips;
2249   fi
2250   grub_CHECK_LINK_DIR
2251   if test x"$link_dir" = xyes ; then
2252     AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
2253     if test "$platform" != emu ; then
2254       AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
2255     fi
2256   else
2257     mkdir -p include/grub 2>/dev/null
2258     rm -rf include/grub/cpu
2259     cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
2260     if test "$platform" != emu ; then
2261       rm -rf include/grub/machine
2262       cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
2263     fi
2264   fi
2265 else
2266   # Just enough to stop the compiler failing with -I$(srcdir)/include.
2267   mkdir -p include 2>/dev/null
2268   rm -rf include/grub/cpu include/grub/machine
2271 AC_CONFIG_FILES([Makefile])
2272 AC_CONFIG_FILES([grub-core/Makefile])
2273 AC_CONFIG_FILES([grub-core/lib/gnulib/Makefile])
2274 AC_CONFIG_FILES([po/Makefile.in])
2275 AC_CONFIG_FILES([docs/Makefile])
2276 AC_CONFIG_FILES([util/bash-completion.d/Makefile])
2277 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
2278 AC_CONFIG_FILES([config.h])
2280 AC_OUTPUT
2282 echo "*******************************************************"
2283 echo GRUB2 will be compiled with following components:
2284 echo Platform: "$target_cpu"-"$platform"
2285 if [ x"$platform" = xemu ]; then
2286 if [ x"$grub_emu_sdl2_excuse" = x ]; then
2287 echo SDL2 support for grub-emu: Yes
2288 else
2289 echo SDL2 support for grub-emu: No "($grub_emu_sdl2_excuse)"
2291 if [ x"$grub_emu_sdl_excuse" = x ]; then
2292 echo SDL support for grub-emu: Yes
2293 else
2294 echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
2296 if [ x"$grub_emu_pci_excuse" = x ]; then
2297 echo PCI support for grub-emu: Yes
2298 else
2299 echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
2302 if test x"$device_mapper_excuse" = x ; then
2303 echo With devmapper support: Yes
2304 else
2305 echo With devmapper support: No "($device_mapper_excuse)"
2307 if [ x"$enable_mm_debug" = xyes ]; then
2308 echo With memory debugging: Yes
2309 else
2310 echo With memory debugging: No
2312 if [ x"$enable_cache_stats" = xyes ]; then
2313 echo With disk cache statistics: Yes
2314 else
2315 echo With disk cache statistics: No
2318 if [ x"$enable_boot_time" = xyes ]; then
2319 echo With boot time statistics: Yes
2320 else
2321 echo With boot time statistics: No
2324 if [ x"$efiemu_excuse" = x ]; then
2325 echo efiemu runtime: Yes
2326 else
2327 echo efiemu runtime: No "($efiemu_excuse)"
2329 if [ x"$grub_mkfont_excuse" = x ]; then
2330 echo grub-mkfont: Yes
2331 else
2332 echo grub-mkfont: No "($grub_mkfont_excuse)"
2334 if [ x"$grub_mount_excuse" = x ]; then
2335 echo grub-mount: Yes
2336 else
2337 echo grub-mount: No "($grub_mount_excuse)"
2339 if [ x"$grub_protect_excuse" = x ]; then
2340 echo grub-protect: Yes
2341 else
2342 echo grub-protect: No "($grub_protect_excuse)"
2344 if [ x"$starfield_excuse" = x ]; then
2345 echo starfield theme: Yes
2346 echo With DejaVuSans font from $DJVU_FONT_SOURCE
2347 else
2348 echo starfield theme: No "($starfield_excuse)"
2350 if [ x"$libzfs_excuse" = x ]; then
2351 echo With libzfs support: Yes
2352 else
2353 echo With libzfs support: No "($libzfs_excuse)"
2355 if [ x"$grub_build_mkfont_excuse" = x ]; then
2356   echo Build-time grub-mkfont: Yes
2357   if test "x$FONT_SOURCE" = x ; then
2358     echo "Without unifont"
2359   else
2360     echo "With unifont from $FONT_SOURCE"
2361   fi
2362 else
2363   echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
2364   echo "Without unifont (no build-time grub-mkfont)"
2366 if test x"$liblzma_excuse" != x ; then
2367 echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excuse)"
2368 else
2369 echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
2371 if test "x$enable_stack_protector" != xno; then
2372 echo "With stack smashing protector: Yes"
2373 else
2374 echo "With stack smashing protector: No"
2376 echo "*******************************************************"