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