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