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