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