]> git.proxmox.com Git - grub2.git/blame - configure.ac
* configure.ac: Fix a typo.
[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
29dnl CC, CFLAGS, etc.) for the host type as well as the build type,
30dnl because GRUB does not need to use those variables for the build
31dnl type, so there is no conflict. Variables with the prefix "TARGET_"
32dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
33dnl type.
34
5f91f701 35AC_INIT([GRUB],[2.00],[bug-grub@gnu.org])
6a161fa9 36
15c69261
YB
37AC_CONFIG_AUX_DIR([build-aux])
38
76ed06b9
BC
39# We don't want -g -O2 by default in CFLAGS
40: ${CFLAGS=""}
6a161fa9 41
b977bf01 42# Checks for host and target systems.
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])
1d543c3e 72
90d1e879
RM
73# Optimization flag. Allow user to override.
74if test "x$TARGET_CFLAGS" = x; then
75 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
76fi
77
76ed06b9
BC
78# Default HOST_CPPFLAGS
79HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
76ed06b9 80HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
76ed06b9 81HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"
76ed06b9
BC
82
83TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W"
84TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
85TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"
86
b977bf01 87case "$target_cpu" in
02164e1b 88 i[[3456]]86) target_cpu=i386 ;;
c7ef54aa 89 amd64) target_cpu=x86_64 ;;
02164e1b 90 sparc) target_cpu=sparc64 ;;
ade85305 91 mipsel|mips64el)
4959e111 92 target_cpu=mipsel;
c721825b 93 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1";
4a1eefb6 94 ;;
ade85305 95 mips|mips64)
76ed06b9 96 target_cpu=mips;
c721825b 97 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS=1";
4a1eefb6 98 ;;
389b31cd
LL
99 arm*)
100 target_cpu=arm;
101 ;;
15a463d7
LL
102 aarch64*)
103 target_cpu=arm64;
104 ;;
6a161fa9 105esac
106
05568c2e 107# Specify the platform (such as firmware).
108AC_ARG_WITH([platform],
109 AS_HELP_STRING([--with-platform=PLATFORM],
83b984de 110 [select the host platform [[guessed]]]))
05568c2e 111
112# Guess the platform if not specified.
113if test "x$with_platform" = x; then
b977bf01 114 case "$target_cpu"-"$target_vendor" in
05568c2e 115 i386-apple) platform=efi ;;
116 i386-*) platform=pc ;;
58393a2d 117 x86_64-apple) platform=efi ;;
737feb35 118 x86_64-*) platform=pc ;;
05568c2e 119 powerpc-*) platform=ieee1275 ;;
58393a2d 120 powerpc64-*) platform=ieee1275 ;;
05568c2e 121 sparc64-*) platform=ieee1275 ;;
4959e111
VS
122 mipsel-*) platform=loongson ;;
123 mips-*) platform=arc ;;
e68d3b24 124 ia64-*) platform=efi ;;
389b31cd 125 arm-*) platform=uboot ;;
15a463d7 126 arm64-*) platform=efi ;;
58393a2d 127 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
05568c2e 128 esac
129else
130 platform="$with_platform"
131fi
132
ec1dfd63
VS
133case "$target_cpu"-"$platform" in
134 x86_64-efi) ;;
135 x86_64-emu) ;;
9612ebc0 136 x86_64-xen) ;;
ec1dfd63
VS
137 x86_64-*) target_cpu=i386 ;;
138 powerpc64-ieee1275) target_cpu=powerpc ;;
139esac
20011694 140
58393a2d 141# Check if the platform is supported, make final adjustments.
b977bf01 142case "$target_cpu"-"$platform" in
05568c2e 143 i386-efi) ;;
3f4ce737 144 x86_64-efi) ;;
9612ebc0
VS
145 i386-xen) ;;
146 x86_64-xen) ;;
05568c2e 147 i386-pc) ;;
7210dca9 148 i386-multiboot) ;;
546f966a 149 i386-coreboot) ;;
58393a2d 150 i386-linuxbios) platform=coreboot ;;
3d04eab8 151 i386-ieee1275) ;;
8231fb77 152 i386-qemu) ;;
05568c2e 153 powerpc-ieee1275) ;;
154 sparc64-ieee1275) ;;
2c40cc78 155 ia64-efi) ;;
f440c33f 156 mips-qemu_mips) ;;
3666d5f6 157 mips-qemu-mips) platform=qemu_mips;;
8906c3dd 158 mips-arc) ;;
7f63a64f 159 mipsel-arc) ;;
4959e111
VS
160 mipsel-qemu_mips) ;;
161 mipsel-qemu-mips) platform=qemu_mips;;
162 mipsel-yeeloong) platform=loongson ;;
163 mipsel-fuloong) platform=loongson ;;
164 mipsel-loongson) ;;
389b31cd
LL
165 arm-uboot) ;;
166 arm-efi) ;;
15a463d7 167 arm64-efi) ;;
f84b481b 168 *-emu) ;;
58393a2d 169 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
6a161fa9 170esac
171
48145ea3 172if test x$platform != xemu ; then
dd614590
VS
173 case "$target_cpu" in
174 i386 | powerpc) target_m32=1 ;;
175 x86_64 | sparc64) target_m64=1 ;;
176 esac
177fi
3f4ce737 178
fc97214f 179case "$target_os" in
c3302aa5 180 windows* | mingw32*) target_os=cygwin ;;
fc97214f
VS
181esac
182
9304eef1 183# This normalizes the names, and creates a new variable ("host_kernel")
184# while at it, since the mapping is not always 1:1 (e.g. different OSes
185# using the same kernel type).
186case "$host_os" in
187 gnu*) host_kernel=hurd ;;
188 linux*) host_kernel=linux ;;
67937d4d 189 freebsd* | kfreebsd*-gnu) host_kernel=kfreebsd ;;
2c7031b1 190 netbsd*) host_kernel=netbsd ;;
958ee221 191 solaris*) host_kernel=illumos ;;
b105df76 192 darwin*) host_kernel=xnu ;;
7e518ca8 193 cygwin | windows* | mingw32*) host_kernel=windows ;;
9304eef1 194esac
195
cd46aa6c
VS
196case "$host_os" in
197 cygwin | windows* | mingw32*) have_exec=n ;;
198 aros*) have_exec=n ;;
199 *) have_exec=y;;
200esac
201
f84b481b 202case "$platform" in
c721825b
BC
203 coreboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_COREBOOT=1" ;;
204 multiboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
205 efi) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
9612ebc0 206 xen) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
c721825b 207 ieee1275) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
389b31cd 208 uboot) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
c721825b
BC
209 qemu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
210 pc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
211 emu) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
54da1feb 212 loongson) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
3666d5f6
VS
213 qemu_mips) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
214 arc) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
f84b481b 215esac
6bea3f89 216case "$target_cpu" in
389b31cd 217 arm) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARM=1" ;;
15a463d7 218 arm64) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARM64=1" ;;
4959e111 219 mips |mipsel) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS=1" ;;
c721825b 220 sparc64) machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_SPARC64=1" ;;
6bea3f89 221esac
4959e111
VS
222if test x${target_cpu} = xmipsel ; then
223 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
224else
3ec0fc1c 225 machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,` -DGRUB_TARGET_CPU_`echo ${target_cpu} | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`=1"
4959e111 226fi
6bea3f89 227
7f63a64f
VS
228case "${target_cpu}-$platform" in
229 mips-arc)
230 TARGET_LINK_ADDR=0x88200000
231 TARGET_DECOMPRESSOR_LINK_ADDR=0x88100000
232 ;;
233 mipsel-arc)
234 TARGET_LINK_ADDR=0x80700000
235 TARGET_DECOMPRESSOR_LINK_ADDR=0x80600000
236 ;;
5fe67f39 237 mips*-qemu_mips | mips*-loongson)
7f63a64f
VS
238 TARGET_DECOMPRESSOR_LINK_ADDR=0x80100000
239 ;;
240esac
241
242AC_SUBST(TARGET_LINK_ADDR)
243AC_SUBST(TARGET_DECOMPRESSOR_LINK_ADDR)
244
c721825b 245TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS"
f84b481b 246
56978920 247AC_SUBST(host_cpu)
248AC_SUBST(host_os)
9304eef1 249AC_SUBST(host_kernel)
6e5a42fe 250
071114bb
VS
251AC_SUBST(target_cpu)
252AC_SUBST(platform)
253
d87aedff 254# Define default variables
7134247c
VS
255
256have_with_bootdir=n
257AC_ARG_WITH([bootdir],
258 AS_HELP_STRING([--with-bootdir=DIR],
259 [set the name of /boot directory [[guessed]]]),
260 [have_with_bootdir=y],
261 [have_with_bootdir=n])
262if test x$have_with_bootdir = xy; then
263 bootdirname="$with_bootdir"
264else
265 case "$host_os" in
266 netbsd* | openbsd*)
d87aedff 267 # Because /boot is used for the boot block in NetBSD and OpenBSD,
7134247c
VS
268 bootdirname='' ;;
269 *) bootdirname='boot' ;;
270 esac
271fi
272
d87aedff 273AC_SUBST(bootdirname)
a4c1d277
YB
274AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname",
275 [Default boot directory name]")
d87aedff 276
7134247c
VS
277AC_ARG_WITH([grubdir],
278 AS_HELP_STRING([--with-grubdir=DIR],
279 [set the name of grub directory [[guessed]]]),
280 [grubdirname="$with_grubdir"],
281 [grubdirname="$PACKAGE"])
282
d87aedff 283AC_SUBST(grubdirname)
a4c1d277
YB
284AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
285 [Default grub directory name])
d87aedff 286
b977bf01 287#
288# Checks for build programs.
289#
144f1f98 290
6c826348 291# Although cmp is listed in the GNU Coding Standards as a command which
292# can used directly, OpenBSD lacks cmp in the default installation.
293AC_CHECK_PROGS([CMP], [cmp])
294if test "x$CMP" = x; then
295 AC_MSG_ERROR([cmp is not found])
296fi
297
144f1f98 298AC_CHECK_PROGS([YACC], [bison])
1569ec51 299if test "x$YACC" = x; then
6c826348 300 AC_MSG_ERROR([bison is not found])
1569ec51 301fi
302
76ed06b9 303AC_PROG_RANLIB
b977bf01 304AC_PROG_INSTALL
305AC_PROG_AWK
09220190 306AC_PROG_LEX
76ed06b9 307AC_PROG_YACC
b977bf01 308AC_PROG_MAKE_SET
ff420223 309AC_PROG_MKDIR_P
e1fd1939 310AC_PROG_LN_S
b977bf01 311
c7c75cf4 312if test "x$LEX" = "x:"; then
09220190
BC
313 AC_MSG_ERROR([flex is not found])
314else
2663fb5f 315 version=`$LEX --version | $AWK '{ split($NF,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
b777c18e 316 if test -n "$version" -a "$version" -ge 20535; then
09220190
BC
317 :
318 else
319 AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
320 fi
321fi
322
68807e5f 323# These are not a "must".
51fa856c 324AC_PATH_PROGS(MAKEINFO, makeinfo true)
6a161fa9 325
b977bf01 326#
327# Checks for host programs.
328#
329
330AC_PROG_CC
15c69261 331gl_EARLY
1eed0e6e 332AC_PROG_CXX
76ed06b9
BC
333AM_PROG_CC_C_O
334AM_PROG_AS
335
6a161fa9 336# Must be GCC.
337test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
338
1eed0e6e
VS
339AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
340
4889bdec 341AC_GNU_SOURCE
2f1a3acf 342AM_GNU_GETTEXT([external])
b977bf01 343AC_SYS_LARGEFILE
344
345# Identify characteristics of the host architecture.
7b780018
VS
346unset ac_cv_c_bigendian
347
b977bf01 348AC_C_BIGENDIAN
349AC_CHECK_SIZEOF(void *)
350AC_CHECK_SIZEOF(long)
351
7e518ca8
VS
352case "$host_os" in
353 cygwin | windows* | mingw32*)
354 HOST_CPPFLAGS="$HOST_CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
355 CPPFLAGS="$CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
356 AC_CHECK_SIZEOF(TCHAR,,[#include <windows.h>])
357 ;;
358esac
359
aad32b14
VS
360if test x$USE_NLS = xno; then
361 HOST_CFLAGS="$HOST_CFLAGS -fno-builtin-gettext"
362fi
363
86695375 364if test "x$cross_compiling" = xyes; then
365 AC_MSG_WARN([cannot generate manual pages while cross compiling])
366else
367 AC_PATH_PROG(HELP2MAN, help2man)
368fi
369
3169f4c7 370# Check for functions and headers.
0f7e980b 371AC_CHECK_FUNCS(posix_memalign memalign getextmntent)
e4c498a1 372AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h limits.h)
7c4e16ff 373
fb90b546
RM
374AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
375#include <sys/param.h>
376#include <sys/mount.h>])
377
378AC_CHECK_MEMBERS([struct statfs.f_mntfromname],,,[$ac_includes_default
379#include <sys/param.h>
380#include <sys/mount.h>])
381
2c7031b1
GS
382# For opendisk() and getrawpartition() on NetBSD.
383# Used in util/deviceiter.c and in util/hostdisk.c.
384AC_CHECK_HEADER([util.h], [
385 AC_CHECK_LIB([util], [opendisk], [
386 LIBUTIL="-lutil"
387 AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
388 ])
389 AC_CHECK_LIB([util], [getrawpartition], [
390 LIBUTIL="-lutil"
391 AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
392 ])
393])
394AC_SUBST([LIBUTIL])
395
19ce697d 396AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_host_cc_wtrampolines], [
00c05e22 397 SAVED_CFLAGS="$CFLAGS"
b35ec299 398 CFLAGS="$HOST_CFLAGS -Wtrampolines -Werror"
00c05e22
VS
399 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
400int va_arg_func (int fixed, va_list args);]], [[]])],
19ce697d
VS
401 [grub_cv_host_cc_wtrampolines=yes],
402 [grub_cv_host_cc_wtrampolines=no])
00c05e22
VS
403 CFLAGS="$SAVED_CFLAGS"
404])
405
19ce697d
VS
406if test x"$grub_host_cv_cc_wtrampolines" = xyes ; then
407 HOST_CFLAGS="$HOST_CFLAGS -Wtrampolines"
00c05e22
VS
408fi
409
76ed06b9
BC
410#
411# Check for host and build compilers.
412#
413HOST_CC=$CC
816719c8
VS
414AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc])
415test -z "$BUILD_CC" && AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])
b224c266 416BUILD_CPP="$BUILD_CC -E"
76ed06b9 417
29013cba
VS
418case "$build_os" in
419 haiku*) BUILD_LIBM= ;;
420 *) BUILD_LIBM=-lm ;;
421esac
15c69261
YB
422# For gnulib.
423gl_INIT
424
382b500e
VS
425WARN_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 -Wpointer-arith -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes"
426EXTRA_WARN_FLAGS="-Wold-style-definition -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"
60d5e9cb
VS
427
428HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS -Wcast-align"
429
430AC_CACHE_CHECK([which extra warnings work], [grub_cv_cc_w_extra_flags], [
431 SAVED_CFLAGS="$CFLAGS"
432 grub_cv_cc_w_extra_flags=
433 for x in $EXTRA_WARN_FLAGS; do
434 CFLAGS="$HOST_CFLAGS $x -Werror"
435 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
436 if test x$flag = x1 ; then
437 grub_cv_cc_w_extra_flags="$grub_cv_cc_w_extra_flags $x"
438 fi
439 done
440 CFLAGS="$SAVED_CFLAGS"
441])
442
443HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags"
444
b977bf01 445#
446# Check for target programs.
447#
448
5b5d4aa5 449# Find tools for the target.
450if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
b977bf01 451 tmp_ac_tool_prefix="$ac_tool_prefix"
452 ac_tool_prefix=$target_alias-
453
454 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
455 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
fc97214f
VS
456 AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
457 AC_CHECK_TOOL(TARGET_STRIP, strip)
458 AC_CHECK_TOOL(TARGET_NM, nm)
0e8daad0 459 AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
b977bf01 460
461 ac_tool_prefix="$tmp_ac_tool_prefix"
462else
463 if test "x$TARGET_CC" = x; then
464 TARGET_CC=$CC
465 fi
fc97214f
VS
466 AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
467 AC_CHECK_TOOL(TARGET_STRIP, strip)
468 AC_CHECK_TOOL(TARGET_NM, nm)
0e8daad0 469 AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
b977bf01 470fi
fc97214f 471
76ed06b9
BC
472AC_SUBST(HOST_CC)
473AC_SUBST(BUILD_CC)
7c9d0c39
VS
474AC_SUBST(BUILD_CFLAGS)
475AC_SUBST(BUILD_CPPFLAGS)
b977bf01 476AC_SUBST(TARGET_CC)
fc97214f 477AC_SUBST(TARGET_NM)
1bd73025 478AC_SUBST(TARGET_RANLIB)
fc97214f
VS
479AC_SUBST(TARGET_STRIP)
480AC_SUBST(TARGET_OBJCOPY)
b977bf01 481
b977bf01 482# Test the C compiler for the target environment.
483tmp_CC="$CC"
484tmp_CFLAGS="$CFLAGS"
485tmp_LDFLAGS="$LDFLAGS"
486tmp_CPPFLAGS="$CPPFLAGS"
aa6d7826 487tmp_LIBS="$LIBS"
b977bf01 488CC="$TARGET_CC"
489CFLAGS="$TARGET_CFLAGS"
490CPPFLAGS="$TARGET_CPPFLAGS"
491LDFLAGS="$TARGET_LDFLAGS"
aa6d7826 492LIBS=""
b977bf01 493
90d1e879 494# debug flags.
4e27343f 495TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
76ed06b9 496TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
6a161fa9 497
c12936c5
VS
498if test "x$target_cpu" != xi386 && test "x$target_cpu" != xx86_64; then
499TARGET_CFLAGS="$TARGET_CFLAGS -Wcast-align"
500fi
501
60d5e9cb
VS
502AC_CACHE_CHECK([which extra warnings work], [grub_cv_target_cc_w_extra_flags], [
503 LDFLAGS="$TARGET_LDFLAGS -nostdlib -static"
504
505 grub_cv_target_cc_w_extra_flags=
506 for x in $EXTRA_WARN_FLAGS; do
507 CFLAGS="$TARGET_CFLAGS $x -Werror"
508 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
509 if test x$flag = x1 ; then
510 grub_cv_target_cc_w_extra_flags="$grub_cv_target_cc_w_extra_flags $x"
511 fi
512 done
513])
514
515TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_w_extra_flags"
516
60375a88 517AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang]
b73b70eb
VS
518[
519CFLAGS="$TARGET_CFLAGS"
520AC_COMPILE_IFELSE(
60375a88
VS
521[AC_LANG_PROGRAM([], [[
522#ifdef __clang__
523#error "is clang"
524#endif
525]])],
526[grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
527
2312f06c
VS
528# on x86 clang doesn't support .code16
529# on arm clang doesn't support .arch directive
63a45330
VS
530# on mips clang doesn't support privilegied instructions, doubleword store/load
531# and crashes with hand-written assembly
532if test "x$grub_cv_cc_target_clang" = xyes && ( test "x$target_cpu" = xi386 \
533 || test "x$target_cpu" = xx86_64 || test "x$target_cpu" = xarm \
534 || test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ); then
60375a88
VS
535 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
536fi
537
b73b70eb
VS
538if test "x$grub_cv_cc_target_clang" = xyes && test "x$target_cpu" = xpowerpc; then
539AC_CACHE_CHECK([if clang can handle ame instruction], [grub_cv_cc_target_clang_ame]
540[
541CFLAGS="$TARGET_CFLAGS"
542AC_COMPILE_IFELSE(
543[AC_LANG_PROGRAM([], [[
544 unsigned int a = 0, b = 0;
545 asm volatile ("{ame|addme} %0,%1" : "=r" (a) : "r" (b));
546 if (a)
547 return 1;
548]])],
549[grub_cv_cc_target_clang_ame=yes], [grub_cv_cc_target_clang_ame=no])])
550 # clang <= 3.3 doesn't handle most of ppc assembly, not even inline assembly
551 # used by gcrypt
552 if test x$grub_cv_cc_target_clang_ame = xno ; then
553 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
896f483d 554 TARGET_CFLAGS="$TARGET_CFLAGS -no-integrated-as"
b73b70eb
VS
555 fi
556fi
557
60375a88
VS
558if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
559 TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
560fi
561
562if test "x$target_m32" = x1; then
563 # Force 32-bit mode.
564 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
565 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
566 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
567 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
568 TARGET_MODULE_FORMAT="elf32"
569fi
570
571if test "x$target_m64" = x1; then
572 # Force 64-bit mode.
573 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
574 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
575 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
576 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
577 TARGET_MODULE_FORMAT="elf64"
578fi
579
580if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
581 TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
582fi
583
f93ddcfd
VS
584# on mips redirect cache flushing function to non-existant one.
585if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
586 AC_CACHE_CHECK([whether -mflush-func=grub_red_herring works], [grub_cv_cc_mflush_func], [
587 CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring -Werror"
588 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
589 [grub_cv_cc_mflush_func=yes],
590 [grub_cv_cc_mflush_func=no])
591 ])
592
593 if test "x$grub_cv_cc_mflush_func" = xyes; then
594 TARGET_CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring"
595 fi
596fi
597
598
90d1e879
RM
599# Force no alignment to save space on i386.
600if test "x$target_cpu" = xi386; then
601 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
b35ec299 602 CFLAGS="$TARGET_CFLAGS -falign-loops=1 -Werror"
eb73121d 603 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
90d1e879
RM
604 [grub_cv_cc_falign_loop=yes],
605 [grub_cv_cc_falign_loop=no])
6a161fa9 606 ])
6a161fa9 607
c966a489 608 AC_CACHE_CHECK([whether -malign-loops works], [grub_cv_cc_malign_loop], [
b35ec299 609 CFLAGS="$TARGET_CFLAGS -malign-loops=1 -Werror"
c966a489
VS
610 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
611 [grub_cv_cc_malign_loop=yes],
612 [grub_cv_cc_malign_loop=no])
613 ])
614
90d1e879
RM
615 if test "x$grub_cv_cc_falign_loop" = xyes; then
616 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
c966a489 617 elif test "x$grub_cv_cc_malign_loop" = xyes; then
90d1e879 618 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 619 fi
89e0240c 620fi
6a161fa9 621
cdc17f60
VS
622AC_CACHE_CHECK([whether -freg-struct-return works], [grub_cv_cc_freg_struct_return], [
623 CFLAGS="$TARGET_CFLAGS -freg-struct-return -Werror"
624 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
625 [grub_cv_cc_freg_struct_return=yes],
626 [grub_cv_cc_freg_struct_return=no])
627])
628
629if test "x$grub_cv_cc_freg_struct_return" = xyes; then
630 TARGET_CFLAGS="$TARGET_CFLAGS -freg-struct-return"
631fi
632
ee0220bc 633if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
90d1e879
RM
634 # Some toolchains enable these features by default, but they need
635 # registers that aren't set up properly in GRUB.
636 TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow"
637fi
77c55a87 638
90d1e879
RM
639# By default, GCC 4.4 generates .eh_frame sections containing unwind
640# information in some cases where it previously did not. GRUB doesn't need
641# these and they just use up vital space. Restore the old compiler
642# behaviour.
643AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
24f4e57c 644 CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
90d1e879
RM
645 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
646 [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
647 [grub_cv_cc_fno_dwarf2_cfi_asm=no])
90d1e879 648])
77c55a87 649
90d1e879
RM
650if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
651 TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
b977bf01 652fi
6a161fa9 653
1c1f31e5
VS
654if test x"$target_os" = xcygwin; then
655 AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
24f4e57c 656 CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
1c1f31e5
VS
657 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
658 [grub_cv_cc_no_reorder_functions=yes],
659 [grub_cv_cc_no_reorder_functions=no])
660 ])
661fi
662
663if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
664 TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
665fi
666
e9d3421c
VS
667# By default, GCC 4.6 generates .eh_frame sections containing unwind
668# information in some cases where it previously did not. GRUB doesn't need
669# these and they just use up vital space. Restore the old compiler
670# behaviour.
671AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [
24f4e57c 672 CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
e9d3421c
VS
673 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
674 [grub_cv_cc_fno_asynchronous_unwind_tables=yes],
675 [grub_cv_cc_fno_asynchronous_unwind_tables=no])
e9d3421c
VS
676])
677
678if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then
679 TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
680fi
681
2b167a72 682# For platforms where ELF is not the default link format.
fc97214f 683case "${target_os}" in
a9f25a08 684 cygwin)
4b0cd8f8 685# FIXME: put proper test here
742f9232 686 NEED_REGISTER_FRAME_INFO=1
4b0cd8f8 687 ;;
742f9232 688 *) NEED_REGISTER_FRAME_INFO=0 ;;
2b167a72 689esac
2b167a72 690
30c7d3ce
VS
691
692AC_ARG_ENABLE([efiemu],
693 [AS_HELP_STRING([--enable-efiemu],
694 [build and install the efiemu runtimes (default=guessed)])])
695if test x"$enable_efiemu" = xno ; then
696 efiemu_excuse="explicitly disabled"
697fi
1c1f31e5
VS
698if test x"$target_os" = xcygwin ; then
699 efiemu_excuse="not available on cygwin"
700fi
30c7d3ce
VS
701if test x"$target_cpu" != xi386 ; then
702 efiemu_excuse="only available on i386"
703fi
704if test x"$platform" = xefi ; then
705 efiemu_excuse="not available on efi"
706fi
707if test x"$efiemu_excuse" = x ; then
708 AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
3c2304d5 709 CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
30c7d3ce
VS
710 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
711 [grub_cv_cc_efiemu=yes],
712 [grub_cv_cc_efiemu=no])
713 ])
714 if test x$grub_cv_cc_efiemu = xno; then
715 efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
716 fi
717fi
c2b70d09
AB
718if test x"$efiemu_excuse" = x ; then
719 AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [
720 grub_cv_target_cc_efiemu64_link_format=unknown
721 for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do
722 CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
723 LDFLAGS="-m64 -Wl,$format -nostdlib -static"
724 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
725 asm (".globl start; start:");
726 asm (".globl _start; _start:");
727 asm (".globl __start; __start:");
728 void __main (void);
729 void __main (void) {}
730 ]], [[]])], [flag=1], [flag=0])
731 if test x"$flag" = x1; then
732 grub_cv_target_cc_efiemu64_link_format="$format"
733 break;
734 fi
735 done])
736 if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then
737 efiemu_excuse="no suitable link format for efiemu64 found"
738 else
739 EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format"
740 fi
741fi
30c7d3ce
VS
742if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
743 AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled])
744fi
745if test x"$efiemu_excuse" = x ; then
746enable_efiemu=yes
747else
748enable_efiemu=no
749fi
750AC_SUBST([enable_efiemu])
c2b70d09 751AC_SUBST([EFIEMU64_LINK_FORMAT])
30c7d3ce 752
a9f25a08
VS
753CFLAGS="$TARGET_CFLAGS"
754
755if test x"$target_cpu" = xi386 || test x"$target_cpu" = xx86_64; then
c2b70d09 756 AC_CACHE_CHECK([for target linking format], [grub_cv_target_cc_link_format], [
a9f25a08
VS
757 grub_cv_target_cc_link_format=unknown
758 for format in -melf_${target_cpu} -melf_${target_cpu}_fbsd -melf_${target_cpu}_obsd -melf_${target_cpu}_haiku -m${target_cpu}pe -arch,${target_cpu}; do
759 if test x${target_cpu} != xi386 && test x$format = x${target_cpu}pe; then
760 continue
761 fi
246a434f
VS
762 CFLAGS="$TARGET_CFLAGS"
763 LDFLAGS="$TARGET_LDFLAGS -Wl,$format -nostdlib -static"
a9f25a08
VS
764 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
765 asm (".globl start; start:");
766 asm (".globl _start; _start:");
767 asm (".globl __start; __start:");
768 void __main (void);
769 void __main (void) {}
c2b70d09 770 ]], [[]])], [flag=1], [flag=0])
a9f25a08
VS
771 if test x"$flag" = x1; then
772 grub_cv_target_cc_link_format="$format"
773 break;
774 fi
775 done])
776 if test x"$grub_cv_target_cc_link_format" = xunknown; then
777 AC_MSG_ERROR([no suitable link format found])
778 fi
779 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
780 if test x"$grub_cv_target_cc_link_format" = x-mi386pe; then
781 TARGET_OBJ2ELF='./build-grub-pe2elf';
782 fi
783fi
784
785if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_cc_link_format = x-arch,x86_64; then
786 TARGET_APPLE_LINKER=1
787 AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
788 if test "x$TARGET_OBJCONV" = x ; then
789 AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
790 fi
791 if test "x$TARGET_OBJCONV" = x ; then
792 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
793 fi
794 TARGET_IMG_LDSCRIPT=
795 TARGET_IMG_CFLAGS="-static"
796 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
797 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
798 TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
799 TARGET_LDFLAGS_OLDMAGIC=""
800elif test x$grub_cv_target_cc_link_format = x-mi386pe && test x$platform = xpc; then
801 TARGET_APPLE_LINKER=0
802 TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
803 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/i386-pc-cygwin-img-ld.sc"
804 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
805 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/i386-pc-cygwin-img-ld.sc"
806 TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
807 TARGET_IMG_CFLAGS=
808else
809 TARGET_APPLE_LINKER=0
810 TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
811 TARGET_IMG_LDSCRIPT=
812 TARGET_IMG_LDFLAGS='-Wl,-N'
813 TARGET_IMG_LDFLAGS_AC='-Wl,-N'
814 TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
815 TARGET_IMG_CFLAGS=
816fi
817
818AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
819
820
821LDFLAGS="$TARGET_LDFLAGS"
8f0baaac 822
46546fc5 823if test "$target_cpu" = x86_64; then
7e9ca17a 824 # Use large model to support 4G memory
6e09b8b7 825 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
24f4e57c 826 CFLAGS="$TARGET_CFLAGS -m64 -mcmodel=large"
6e09b8b7 827 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
828 [grub_cv_cc_mcmodel=yes],
829 [grub_cv_cc_mcmodel=no])
830 ])
a3ba7410 831 if test "x$grub_cv_cc_mcmodel" = xyes; then
c8600122 832 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
6e09b8b7 833 fi
46546fc5 834fi
7e9ca17a 835
46546fc5 836if test "$target_cpu"-"$platform" = x86_64-efi; then
7e9ca17a 837 # EFI writes to stack below %rsp, we must not use the red zone
838 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
24f4e57c 839 CFLAGS="$TARGET_CFLAGS -m64 -mno-red-zone"
7e9ca17a 840 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
841 [grub_cv_cc_no_red_zone=yes],
842 [grub_cv_cc_no_red_zone=no])
843 ])
844 if test "x$grub_cv_cc_no_red_zone" = xno; then
845 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
846 fi
847
c8600122 848 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
20011694 849fi
850
baa2a121 851#
852# Compiler features.
853#
854
28668d80
VS
855CFLAGS="$TARGET_CFLAGS"
856
93a81088 857# Position independent executable.
858grub_CHECK_PIE
859[# Need that, because some distributions ship compilers that include
860# `-fPIE' in the default specs.
861if [ x"$pie_possible" = xyes ]; then
862 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
863fi]
864
28668d80
VS
865CFLAGS="$TARGET_CFLAGS"
866
7bd8b0c7
VS
867# Position independent executable.
868grub_CHECK_PIC
9cf12b20
VS
869[# On most platforms we don't want PIC as it only makes relocations harder
870# and code less efficient. On mips we want to have one got table per module
871# and reload $gp in every function.
872# GCC implements it using symbol __gnu_local_gp in non-PIC as well.
873# However with clang we need PIC for this reloading to happen.
874# Since default varies across dictributions use either -fPIC or -fno-PIC
875# explicitly.
876if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then
877 TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
878elif [ x"$pic_possible" = xyes ]; then
879 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
7bd8b0c7
VS
880fi]
881
28668d80
VS
882CFLAGS="$TARGET_CFLAGS"
883
baa2a121 884# Smashing stack protector.
885grub_CHECK_STACK_PROTECTOR
c3db8364 886# Need that, because some distributions ship compilers that include
baa2a121 887# `-fstack-protector' in the default specs.
c3db8364 888if test "x$ssp_possible" = xyes; then
889 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
890fi
28668d80
VS
891
892CFLAGS="$TARGET_CFLAGS"
893
2a8a80e4 894grub_CHECK_STACK_ARG_PROBE
895# Cygwin's GCC uses alloca() to probe the stackframe on static
896# stack allocations above some threshold.
897if test x"$sap_possible" = xyes; then
898 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
899fi
baa2a121 900
28668d80
VS
901CFLAGS="$TARGET_CFLAGS"
902
d74b9a1d 903# -mno-unaligned-access -mstrict-align
bb9f92b9 904if test "$target_cpu" = arm; then
d74b9a1d 905 AC_CACHE_CHECK([for compile options to get strict alignment], [grub_cv_target_cc_strict_align], [
bdb6090d 906 grub_cv_target_cc_strict_align=
d74b9a1d
VS
907 for arg in -mno-unaligned-access "-Xclang -mstrict-align" -mstrict-align; do
908 CFLAGS="$TARGET_CFLAGS $arg -Werror"
909 LDFLAGS="$TARGET_LDFLAGS"
910 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
911 if test x"$flag" = x1; then
912 grub_cv_target_cc_strict_align="$arg"
913 break;
914 fi
915 done])
916
d74b9a1d
VS
917 TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_strict_align"
918 if test x"$grub_cv_target_cc_strict_align" = x"-Xclang -mstrict-align"; then
919 TARGET_LDFLAGS="$TARGET_LDFLAGS -Qunused-arguments"
bb9f92b9 920 fi
bdb6090d
VS
921 AC_CACHE_CHECK([if compiler generates unaligned accesses], [grub_cv_cc_target_emits_unaligned],
922 [CFLAGS="$TARGET_CFLAGS"
923 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
924#ifdef __ARM_FEATURE_UNALIGNED
925#error "unaligned"
926#endif
927 ]])],
928 [grub_cv_cc_target_emits_unaligned=no], [grub_cv_cc_target_emits_unaligned=yes])])
929 if test x$grub_cv_cc_target_emits_unaligned = xyes; then
930 AC_MSG_ERROR([compiler generates unaligned accesses])
931 fi
bb9f92b9
LL
932fi
933
aa6d7826 934# Set them to their new values for the tests below.
935CC="$TARGET_CC"
a9f25a08 936if test "x$TARGET_APPLE_LINKER" = x1 ; then
246a434f 937CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error"
26de2bcd 938else
01fcf061 939CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wno-error"
26de2bcd 940fi
aa6d7826 941CPPFLAGS="$TARGET_CPPFLAGS"
d5524ca8
VS
942if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then
943TARGET_LIBGCC=
03f80960 944else
d5524ca8 945TARGET_LIBGCC=-lgcc
03f80960 946fi
69be5b74 947
d5524ca8
VS
948LIBS="$TARGET_LIBGCC"
949
01fcf061 950grub_ASM_USCORE
a9f25a08 951if test "x$TARGET_APPLE_LINKER" = x0 ; then
01fcf061 952if test x$grub_cv_asm_uscore = xyes; then
31c0cd43 953CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,_abort=_main"
01fcf061 954else
31c0cd43 955CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,abort=main"
01fcf061 956fi
a9f25a08 957fi
01fcf061 958
69be5b74 959# Check for libgcc symbols
6fcec439 960AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x)
69be5b74 961
a9f25a08 962if test "x$TARGET_APPLE_LINKER" = x1 ; then
246a434f 963CFLAGS="$TARGET_CFLAGS -nostdlib -static"
69be5b74
VS
964else
965CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
966fi
42e0cba3 967LIBS=""
aa6d7826 968
6a161fa9 969# Defined in aclocal.m4.
f6130a12 970grub_PROG_TARGET_CC
a9f25a08 971if test "x$TARGET_APPLE_LINKER" != x1 ; then
b977bf01 972grub_PROG_OBJCOPY_ABSOLUTE
2b167a72 973fi
cb71ba20 974grub_PROG_LD_BUILD_ID_NONE
b977bf01 975if test "x$target_cpu" = xi386; then
a9f25a08 976 if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
2aec1692
CF
977 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
978 # Check symbols provided by linker script.
5cf9459c 979 CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000 -Wl,--defsym,___main=0x8100"
2aec1692 980 fi
2a8a80e4 981 grub_CHECK_BSS_START_SYMBOL
982 grub_CHECK_END_SYMBOL
983 fi
984 CFLAGS="$TARGET_CFLAGS"
4b13b216 985 grub_I386_ASM_PREFIX_REQUIREMENT
986 grub_I386_ASM_ADDR32
6a161fa9 987fi
988
20aea949
VS
989grub_PROG_NM_WORKS
990grub_PROG_NM_MINUS_P
991grub_PROG_NM_DEFINED_ONLY
992AC_SUBST(TARGET_NMFLAGS_MINUS_P)
993AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)
994
016a671b 995if test "$platform" != emu; then
8f9a632b
VS
996AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
997 SAVED_CPPFLAGS="$CPPFLAGS"
998 CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
999 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
ce938140 1000#include <stddef.h>
8f9a632b
VS
1001int va_arg_func (int fixed, va_list args);]], [[]])],
1002 [grub_cv_cc_isystem=yes],
1003 [grub_cv_cc_isystem=no])
1004 CPPFLAGS="$SAVED_CPPFLAGS"
1005])
1006
1007if test x"$grub_cv_cc_isystem" = xyes ; then
1008 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
1009fi
dae79b6b 1010fi
5ce5507f 1011
19ce697d 1012AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_cc_wtrampolines], [
24f4e57c 1013 CFLAGS="$TARGET_CFLAGS -Wtrampolines -Werror"
779dc15b
VS
1014 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1015int va_arg_func (int fixed, va_list args);]], [[]])],
19ce697d
VS
1016 [grub_cv_cc_wtrampolines=yes],
1017 [grub_cv_cc_wtrampolines=no])
779dc15b
VS
1018])
1019
19ce697d
VS
1020if test x"$grub_cv_cc_wtrampolines" = xyes ; then
1021 TARGET_CFLAGS="$TARGET_CFLAGS -Wtrampolines"
779dc15b
VS
1022fi
1023
c9a86192 1024# Restore the flags.
9962ed99 1025CC="$tmp_CC"
1026CFLAGS="$tmp_CFLAGS"
1027CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 1028LDFLAGS="$tmp_LDFLAGS"
aa6d7826 1029LIBS="$tmp_LIBS"
6a161fa9 1030
4fe9862e 1031#
2965c7cc 1032# Check for options.
4fe9862e 1033#
1034
1035# Memory manager debugging.
b39f9d20 1036AC_ARG_ENABLE([mm-debug],
2965c7cc 1037 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 1038 [include memory manager debugging]),
2965c7cc 1039 [AC_DEFINE([MM_DEBUG], [1],
1040 [Define to 1 if you enable memory manager debugging.])])
1041
c5dc1690
SJ
1042AC_ARG_ENABLE([cache-stats],
1043 AS_HELP_STRING([--enable-cache-stats],
055e2b8b 1044 [enable disk cache statistics collection]))
c5dc1690
SJ
1045
1046if test x$enable_cache_stats = xyes; then
1047 DISK_CACHE_STATS=1
1048else
1049 DISK_CACHE_STATS=0
1050fi
1051AC_SUBST([DISK_CACHE_STATS])
1052
e744219b
VS
1053AC_ARG_ENABLE([boot-time],
1054 AS_HELP_STRING([--enable-boot-time],
1055 [enable boot time statistics collection]))
1056
1057if test x$enable_boot_time = xyes; then
1058 BOOT_TIME_STATS=1
1059else
1060 BOOT_TIME_STATS=0
1061fi
1062AC_SUBST([BOOT_TIME_STATS])
1063
d64399b5 1064AC_ARG_ENABLE([grub-emu-usb],
1065 [AS_HELP_STRING([--enable-grub-emu-usb],
5ce5507f 1066 [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
5ce5507f 1067
927d0134
VS
1068AC_ARG_ENABLE([grub-emu-sdl],
1069 [AS_HELP_STRING([--enable-grub-emu-sdl],
1070 [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
1071
3affd0ec 1072AC_ARG_ENABLE([grub-emu-pci],
1073 [AS_HELP_STRING([--enable-grub-emu-pci],
1074 [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
1075
f84b481b 1076if test "$platform" = emu; then
f84b481b 1077
62a747cb
VS
1078if test x"$enable_grub_emu_usb" != xyes ; then
1079 grub_emu_usb_excuse="not enabled"
5ce5507f 1080fi
325c8258 1081
0e848909
VS
1082if test x"$enable_grub_emu_pci" = xyes ; then
1083 grub_emu_usb_excuse="conflicts with PCI support"
1084fi
1085
5ce5507f 1086[if [ x"$grub_emu_usb_excuse" = x ]; then
d64399b5 1087 # Check for libusb libraries.]
5ce5507f 1088AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
e98cd0c2 1089 [grub_emu_usb_excuse=["need libusb library"]])
d64399b5 1090 AC_SUBST([LIBUSB])
5ce5507f 1091[fi]
1092[if [ x"$grub_emu_usb_excuse" = x ]; then
1093 # Check for headers.]
d64399b5 1094 AC_CHECK_HEADERS([usb.h], [],
e98cd0c2 1095 [grub_emu_usb_excuse=["need libusb headers"]])
4fe9862e 1096[fi]
c6f3b249 1097if test x"$enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then
ce7a733d 1098 AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled])
5ce5507f 1099fi
1100if test x"$grub_emu_usb_excuse" = x ; then
1101enable_grub_emu_usb=yes
1102else
1103enable_grub_emu_usb=no
1104fi
1105
927d0134
VS
1106if test x"$enable_grub_emu_sdl" = xno ; then
1107 grub_emu_sdl_excuse="explicitely disabled"
1108fi
1109[if [ x"$grub_emu_sdl_excuse" = x ]; then
1110 # Check for libSDL libraries.]
1111AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
1112 [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
1113 AC_SUBST([LIBSDL])
1114[fi]
9f293ab0 1115
927d0134
VS
1116[if [ x"$grub_emu_sdl_excuse" = x ]; then
1117 # Check for headers.]
1118 AC_CHECK_HEADERS([SDL/SDL.h], [],
1119 [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
1120[fi]
9f293ab0 1121
927d0134
VS
1122if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
1123 AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
1124fi
1125if test x"$grub_emu_sdl_excuse" = x ; then
1126enable_grub_emu_sdl=yes
1127else
1128enable_grub_emu_sdl=no
1129fi
1130
3affd0ec 1131if test x"$enable_grub_emu_pci" != xyes ; then
325c8258 1132 grub_emu_pci_excuse="not enabled"
1133fi
1134
1135if test x"$enable_grub_emu_usb" = xyes ; then
1136 grub_emu_pci_excuse="conflicts with USB support"
1137fi
1138
1139[if [ x"$grub_emu_pci_excuse" = x ]; then
1140 # Check for libpci libraries.]
459fed4b 1141 AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
1142 [grub_emu_pci_excuse=["need libpciaccess library"]])
1143 AC_SUBST([LIBPCIACCESS])
325c8258 1144[fi]
1145[if [ x"$grub_emu_pci_excuse" = x ]; then
1146 # Check for headers.]
1147 AC_CHECK_HEADERS([pci/pci.h], [],
459fed4b 1148 [grub_emu_pci_excuse=["need libpciaccess headers"]])
325c8258 1149[fi]
1150
1151if test x"$grub_emu_pci_excuse" = x ; then
1152enable_grub_emu_pci=yes
1153else
9f293ab0 1154
325c8258 1155enable_grub_emu_pci=no
3affd0ec 1156fi
1157
927d0134 1158AC_SUBST([enable_grub_emu_sdl])
d64399b5 1159AC_SUBST([enable_grub_emu_usb])
3affd0ec 1160AC_SUBST([enable_grub_emu_pci])
e7d09ac4
AB
1161
1162else
1163
1164# Ignore --enable-emu-* if platform is not emu
1165enable_grub_emu_sdl=no
1166enable_grub_emu_usb=no
1167enable_grub_emu_pci=no
f84b481b 1168fi
4fe9862e 1169
e52db1f7 1170AC_ARG_ENABLE([grub-mkfont],
1171 [AS_HELP_STRING([--enable-grub-mkfont],
5ce5507f 1172 [build and install the `grub-mkfont' utility (default=guessed)])])
1173if test x"$enable_grub_mkfont" = xno ; then
ce7a733d 1174 grub_mkfont_excuse="explicitly disabled"
5ce5507f 1175fi
1176
1177if test x"$grub_mkfont_excuse" = x ; then
e52db1f7 1178 # Check for freetype libraries.
a5b55c4b 1179 AC_CHECK_TOOLS([FREETYPE], [freetype-config])
e52db1f7 1180 if test "x$FREETYPE" = x ; then
e98cd0c2 1181 grub_mkfont_excuse=["need freetype2 library"]
e52db1f7 1182 fi
e52db1f7 1183fi
660960d6 1184
7b780018
VS
1185unset ac_cv_header_ft2build_h
1186
660960d6
VS
1187if test x"$grub_mkfont_excuse" = x ; then
1188 # Check for freetype libraries.
a5b55c4b
DM
1189 freetype_cflags=`$FREETYPE --cflags`
1190 freetype_libs=`$FREETYPE --libs`
d1e8a02f
VS
1191 SAVED_CPPFLAGS="$CPPFLAGS"
1192 CPPFLAGS="$CPPFLAGS $freetype_cflags"
660960d6
VS
1193 AC_CHECK_HEADERS([ft2build.h], [],
1194 [grub_mkfont_excuse=["need freetype2 headers"]])
d1e8a02f 1195 CPPFLAGS="$SAVED_CPPFLAGS"
660960d6
VS
1196fi
1197
5ce5507f 1198if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
ce7a733d 1199 AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
5ce5507f 1200fi
1201if test x"$grub_mkfont_excuse" = x ; then
1202enable_grub_mkfont=yes
1203else
1204enable_grub_mkfont=no
1205fi
e52db1f7 1206AC_SUBST([enable_grub_mkfont])
1207AC_SUBST([freetype_cflags])
1208AC_SUBST([freetype_libs])
1209
7c9d0c39 1210SAVED_CC="$CC"
b224c266 1211SAVED_CPP="$CPP"
7c9d0c39
VS
1212SAVED_CFLAGS="$CFLAGS"
1213SAVED_CPPFLAGS="$CPPFLAGS"
1214CC="$BUILD_CC"
b224c266 1215CPP="$BUILD_CPP"
7c9d0c39 1216CFLAGS="$BUILD_CFLAGS"
7b780018
VS
1217CPPFLAGS="$BUILD_CPPFLAGS"
1218
1219unset ac_cv_c_bigendian
1220unset ac_cv_header_ft2build_h
1221
1222AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
1223AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
1224AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
1225
1226if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
1227 AC_MSG_ERROR([couldnt determine build endianness])
1228fi
1229
1230AC_SUBST([BUILD_SIZEOF_LONG])
1231AC_SUBST([BUILD_SIZEOF_VOID_P])
1232AC_SUBST([BUILD_WORDS_BIGENDIAN])
c5884973 1233
7c9d0c39
VS
1234if test x"$grub_build_mkfont_excuse" = x ; then
1235 # Check for freetype libraries.
7b780018 1236 AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
7c9d0c39
VS
1237 if test "x$BUILD_FREETYPE" = x ; then
1238 grub_build_mkfont_excuse=["need freetype2 library"]
1239 fi
1240fi
c5884973 1241
7c9d0c39
VS
1242if test x"$grub_build_mkfont_excuse" = x ; then
1243 # Check for freetype libraries.
1244 build_freetype_cflags=`$BUILD_FREETYPE --cflags`
1245 build_freetype_libs=`$BUILD_FREETYPE --libs`
1246 SAVED_CPPFLAGS_2="$CPPFLAGS"
1247 CPPFLAGS="$CPPFLAGS $build_freetype_cflags"
1248 AC_CHECK_HEADERS([ft2build.h], [],
1249 [grub_build_mkfont_excuse=["need freetype2 headers"]])
1250 CPPFLAGS="$SAVED_CPPFLAGS_2"
1251fi
1252
1253if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
1254 AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled])
1255fi
1256if test x"$grub_build_mkfont_excuse" = x ; then
1257 enable_build_grub_mkfont=yes
1258else
1259 enable_build_grub_mkfont=no
c5884973 1260fi
b2e9d276
VS
1261if test x"$enable_build_grub_mkfont" = xno && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 ); then
1262 AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports needs build-time grub-mkfont])
7c9d0c39
VS
1263fi
1264
1265AC_SUBST([build_freetype_cflags])
1266AC_SUBST([build_freetype_libs])
1267
1268CC="$SAVED_CC"
b224c266 1269CPP="$SAVED_CPP"
7c9d0c39
VS
1270CFLAGS="$SAVED_CFLAGS"
1271CPPFLAGS="$SAVED_CPPFLAGS"
1272
1273
1274DJVU_FONT_SOURCE=
1275
1276starfield_excuse=
c5884973 1277
300f48c5
VS
1278AC_ARG_ENABLE([grub-themes],
1279 [AS_HELP_STRING([--enable-grub-themes],
1280 [build and install GRUB themes (default=guessed)])])
1281if test x"$enable_grub_themes" = xno ; then
1282 starfield_excuse="explicitly disabled"
1283fi
1284
1285if test x"$starfield_excuse" = x && test x"$enable_build_grub_mkfont" = xno ; then
7b966834
VS
1286 starfield_excuse="No build-time grub-mkfont"
1287fi
1288
501b9e4b 1289if test x"$starfield_excuse" = x; then
c5884973 1290 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
32745f51 1291 for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu; do
c5884973
DO
1292 if test -f "$dir/DejaVuSans.$ext"; then
1293 DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
1294 break 2
1295 fi
1296 done
1297 done
1298
1299 if test "x$DJVU_FONT_SOURCE" = x; then
1300 starfield_excuse="No DejaVu found"
1301 fi
1302fi
1303
300f48c5
VS
1304if test x"$enable_grub_themes" = xyes && test x"$starfield_excuse" != x; then
1305 AC_MSG_ERROR([themes were explicitly requested but requirements are not satisfied])
1306fi
1307
c5884973
DO
1308AC_SUBST([DJVU_FONT_SOURCE])
1309
7c9d0c39
VS
1310FONT_SOURCE=
1311
1312for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1313 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
1314 if test -f "$dir/unifont.$ext"; then
1315 FONT_SOURCE="$dir/unifont.$ext"
1316 break 2
1317 fi
1318 done
1319done
1320
7b966834
VS
1321if test x"$enable_build_grub_mkfont" = xno ; then
1322 FONT_SOURCE=
1323fi
1324
b2e9d276
VS
1325if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xloongson || test "x$platform" = xqemu_mips || test "x$target_cpu"-"$platform" = xpowerpc-ieee1275 ); then
1326 AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports need unifont])
7c9d0c39
VS
1327fi
1328
1329AC_SUBST([FONT_SOURCE])
1330
7b780018 1331if test x"$FONT_SOURCE" = x && test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
7c9d0c39
VS
1332 grub_build_mkfont_excuse="no fonts"
1333fi
1334
1335
897e6207
CW
1336AC_ARG_ENABLE([grub-mount],
1337 [AS_HELP_STRING([--enable-grub-mount],
1338 [build and install the `grub-mount' utility (default=guessed)])])
1339if test x"$enable_grub_mount" = xno ; then
1340 grub_mount_excuse="explicitly disabled"
92bb0786
VS
1341fi
1342
897e6207 1343if test x"$grub_mount_excuse" = x ; then
92bb0786 1344 AC_CHECK_LIB([fuse], [fuse_main_real], [],
897e6207 1345 [grub_mount_excuse="need FUSE library"])
92bb0786
VS
1346fi
1347
897e6207 1348if test x"$grub_mount_excuse" = x ; then
92bb0786
VS
1349 # Check for fuse headers.
1350 SAVED_CPPFLAGS="$CPPFLAGS"
338c7fab 1351 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26"
92bb0786 1352 AC_CHECK_HEADERS([fuse/fuse.h], [],
897e6207 1353 [grub_mount_excuse=["need FUSE headers"]])
92bb0786
VS
1354 CPPFLAGS="$SAVED_CPPFLAGS"
1355fi
1356
897e6207 1357if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then
89644ef1 1358 AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled])
92bb0786 1359fi
897e6207
CW
1360if test x"$grub_mount_excuse" = x ; then
1361enable_grub_mount=yes
92bb0786 1362else
897e6207 1363enable_grub_mount=no
92bb0786 1364fi
897e6207 1365AC_SUBST([enable_grub_mount])
92bb0786 1366
7181e228
CW
1367AC_ARG_ENABLE([device-mapper],
1368 [AS_HELP_STRING([--enable-device-mapper],
1369 [enable Linux device-mapper support (default=guessed)])])
1370if test x"$enable_device_mapper" = xno ; then
1371 device_mapper_excuse="explicitly disabled"
1372fi
1373
53798c4b
GS
1374if test x"$device_mapper_excuse" = x ; then
1375 # Check for device-mapper header.
1376 AC_CHECK_HEADER([libdevmapper.h], [],
1377 [device_mapper_excuse="need libdevmapper header"])
1378fi
1379
7181e228
CW
1380if test x"$device_mapper_excuse" = x ; then
1381 # Check for device-mapper library.
61d720e5 1382 AC_CHECK_LIB([devmapper], [dm_task_create], [],
7181e228 1383 [device_mapper_excuse="need devmapper library"])
7181e228 1384fi
61d720e5
VS
1385
1386if test x"$device_mapper_excuse" = x ; then
1387 # Check for device-mapper library.
1388 AC_CHECK_LIB([devmapper], [dm_log_with_errno_init],
1389 [],
1390 [device_mapper_excuse="need devmapper library"])
1391fi
1392
1393if test x"$device_mapper_excuse" = x ; then
1394 LIBDEVMAPPER="-ldevmapper";
1395 AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
1396 [Define to 1 if you have the devmapper library.])
1397fi
1398
62f7d208 1399AC_SUBST([LIBDEVMAPPER])
76ed06b9 1400
f4727da9
VS
1401LIBGEOM=
1402if test x$host_kernel = xkfreebsd; then
1403 AC_CHECK_LIB([geom], [geom_gettree], [],
1404 [AC_MSG_ERROR([Your platform requires libgeom])])
1405 LIBGEOM="-lgeom"
1406fi
1407
1408AC_SUBST([LIBGEOM])
1409
0d2d30bb
VS
1410AC_ARG_ENABLE([liblzma],
1411 [AS_HELP_STRING([--enable-liblzma],
1412 [enable liblzma integration (default=guessed)])])
1413if test x"$enable_liblzma" = xno ; then
1414 liblzma_excuse="explicitly disabled"
1415fi
1416
1417if test x"$liblzma_excuse" = x ; then
2c44e493 1418AC_CHECK_LIB([lzma], [lzma_code],
0d2d30bb
VS
1419 [],[liblzma_excuse="need lzma library"])
1420fi
1421if test x"$liblzma_excuse" = x ; then
1422AC_CHECK_HEADER([lzma.h], [], [liblzma_excuse="need lzma header"])
1423fi
1424
1425if test x"$enable_liblzma" = xyes && test x"$liblzma_excuse" != x ; then
1426 AC_MSG_ERROR([liblzma support was explicitly requested but requirements are not satisfied])
1427fi
1428
1429
1430if test x"$liblzma_excuse" = x ; then
1431 LIBLZMA="-llzma"
1432 AC_DEFINE([USE_LIBLZMA], [1],
1433 [Define to 1 if you have the LZMA library.])
1434fi
1435
2c44e493
VS
1436AC_SUBST([LIBLZMA])
1437
e4c498a1
MG
1438AC_ARG_ENABLE([libzfs],
1439 [AS_HELP_STRING([--enable-libzfs],
1440 [enable libzfs integration (default=guessed)])])
1441if test x"$enable_libzfs" = xno ; then
1442 libzfs_excuse="explicitly disabled"
1443fi
16c7cb32 1444
e4c498a1
MG
1445if test x"$libzfs_excuse" = x ; then
1446 # Only check for system headers if libzfs support has not been disabled.
1447 AC_CHECK_HEADERS(libzfs.h libnvpair.h)
1448fi
1449
1450if test x"$libzfs_excuse" = x ; then
1451 AC_CHECK_LIB([zfs], [libzfs_init],
1452 [],
1453 [libzfs_excuse="need zfs library"])
1454fi
1455
1456if test x"$libzfs_excuse" = x ; then
27f9d02e 1457 AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
e4c498a1
MG
1458 [],
1459 [libzfs_excuse="need nvpair library"])
1460fi
1461
1462if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
1463 AC_MSG_ERROR([libzfs support was explicitly requested but requirements are not satisfied])
1464fi
1465
1466if test x"$libzfs_excuse" = x ; then
1467 # We need both libzfs and libnvpair for a successful build.
1468 LIBZFS="-lzfs"
1469 AC_DEFINE([HAVE_LIBZFS], [1],
1470 [Define to 1 if you have the ZFS library.])
1471 LIBNVPAIR="-lnvpair"
1472 AC_DEFINE([HAVE_LIBNVPAIR], [1],
1473 [Define to 1 if you have the NVPAIR library.])
1474fi
1475
1476AC_SUBST([LIBZFS])
16c7cb32
BC
1477AC_SUBST([LIBNVPAIR])
1478
9f915872
VS
1479LIBS=""
1480
76ed06b9 1481AC_SUBST([FONT_SOURCE])
76ed06b9
BC
1482AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
1483 [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
7181e228 1484
742f9232
VS
1485AC_SUBST(HAVE_ASM_USCORE)
1486AC_SUBST(ADDR32)
1487AC_SUBST(DATA32)
1488AC_SUBST(BSS_START_SYMBOL)
1489AC_SUBST(END_SYMBOL)
1490AC_SUBST(PACKAGE)
1491AC_SUBST(VERSION)
742f9232
VS
1492AC_SUBST(NEED_REGISTER_FRAME_INFO)
1493
d5524ca8
VS
1494AC_ARG_ENABLE([werror],
1495 [AS_HELP_STRING([--disable-werror],
1496 [do not use -Werror when building GRUB])])
1497if test x"$enable_werror" != xno ; then
1498 TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
1499 HOST_CFLAGS="$HOST_CFLAGS -Werror"
1500fi
1501
1502if test "x$grub_cv_cc_target_clang" = xno; then
1503 TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
1504else
1505 TARGET_LDFLAGS_STATIC_LIBGCC=
1506fi
1507
1508TARGET_CPP="$TARGET_CC -E"
1509TARGET_CCAS=$TARGET_CC
1510
1511GRUB_TARGET_CPU="${target_cpu}"
1512GRUB_PLATFORM="${platform}"
1513
1514AC_SUBST(GRUB_TARGET_CPU)
1515AC_SUBST(GRUB_PLATFORM)
1516
1517AC_SUBST(TARGET_OBJCONV)
1518AC_SUBST(TARGET_LIBGCC)
1519AC_SUBST(TARGET_LDFLAGS_STATIC_LIBGCC)
1520AC_SUBST(TARGET_CPP)
1521AC_SUBST(TARGET_CCAS)
1522AC_SUBST(TARGET_OBJ2ELF)
d5524ca8
VS
1523AC_SUBST(TARGET_MODULE_FORMAT)
1524
1525AC_SUBST(TARGET_CFLAGS)
1526AC_SUBST(TARGET_LDFLAGS)
1527AC_SUBST(TARGET_CPPFLAGS)
1528AC_SUBST(TARGET_CCASFLAGS)
1529
1530AC_SUBST(TARGET_IMG_LDSCRIPT)
1531AC_SUBST(TARGET_IMG_LDFLAGS)
1532AC_SUBST(TARGET_IMG_CFLAGS)
1533AC_SUBST(TARGET_IMG_BASE_LDOPT)
a9f25a08 1534AC_SUBST(TARGET_APPLE_LINKER)
d5524ca8
VS
1535
1536AC_SUBST(HOST_CFLAGS)
1537AC_SUBST(HOST_LDFLAGS)
1538AC_SUBST(HOST_CPPFLAGS)
1539AC_SUBST(HOST_CCASFLAGS)
1540
1541AC_SUBST(BUILD_LIBM)
1542
76ed06b9
BC
1543#
1544# Automake conditionals
1545#
8c411768 1546
76ed06b9 1547AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
d59849b2 1548AM_CONDITIONAL([COND_clang], [test x$grub_cv_cc_target_clang = xyes])
76ed06b9
BC
1549AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
1550AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
6585de4c 1551AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
76ed06b9
BC
1552AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
1553AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
1554AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
1555AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
1556AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
9612ebc0
VS
1557AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
1558AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
4959e111
VS
1559AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
1560AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips])
7f63a64f 1561AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xarc])
76ed06b9
BC
1562AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
1563AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
4959e111 1564AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
37ba07eb
VS
1565AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
1566AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
389b31cd
LL
1567AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
1568AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
1569AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
15a463d7
LL
1570AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
1571AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
f7711f5e
BC
1572
1573AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
1574AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
1575AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
1576AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
1577AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
b105df76 1578AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
958ee221 1579AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])
2d465fb0 1580
76ed06b9
BC
1581AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
1582AM_CONDITIONAL([COND_GRUB_EMU_USB], [test x$enable_grub_emu_usb = xyes])
1583AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
1584AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
1585AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
897e6207 1586AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
76ed06b9 1587AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
6f07c4e4
VS
1588if test x$FONT_SOURCE != x ; then
1589 HAVE_FONT_SOURCE=1
1590else
1591 HAVE_FONT_SOURCE=0
1592fi
1593AC_SUBST(HAVE_FONT_SOURCE)
a9f25a08 1594AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
76ed06b9 1595AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
c5dc1690 1596AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
e744219b 1597AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
fc45fb58 1598
1eed0e6e
VS
1599AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
1600
742f9232 1601AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
fc97214f 1602AM_CONDITIONAL([COND_CYGWIN], [test x$target_os = xcygwin])
c5884973 1603AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
cd46aa6c
VS
1604AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])
1605
1606test "x$prefix" = xNONE && prefix="$ac_default_prefix"
1607test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
1608datarootdir="$(eval echo "$datarootdir")"
1609grub_libdir="$(eval echo "$libdir")"
1610grub_localedir="$(eval echo "$localedir")"
1611grub_datadir="$(eval echo "$datadir")"
1612grub_sysconfdir="$(eval echo "$sysconfdir")"
1613AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
1614AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
1615AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
1616AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
1617
742f9232 1618
6a161fa9 1619# Output files.
4959e111
VS
1620cpudir="${target_cpu}"
1621if test x${cpudir} = xmipsel; then
1622 cpudir=mips;
1623fi
1f4147aa 1624grub_CHECK_LINK_DIR
1625if test x"$link_dir" = xyes ; then
4959e111 1626 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
f84b481b 1627 if test "$platform" != emu ; then
4959e111 1628 AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
f84b481b 1629 fi
1f4147aa 1630else
1631 mkdir -p include/grub 2>/dev/null
1632 rm -rf include/grub/cpu
4959e111 1633 cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
f84b481b
RM
1634 if test "$platform" != emu ; then
1635 rm -rf include/grub/machine
4959e111 1636 cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
f84b481b 1637 fi
1f4147aa 1638fi
6304d292 1639
8c411768 1640AC_CONFIG_FILES([Makefile])
6304d292 1641AC_CONFIG_FILES([grub-core/Makefile])
15c69261 1642AC_CONFIG_FILES([grub-core/gnulib/Makefile])
269004c1 1643AC_CONFIG_FILES([po/Makefile.in])
8c411768 1644AC_CONFIG_FILES([docs/Makefile])
b23ffd70 1645AC_CONFIG_FILES([util/bash-completion.d/Makefile])
6a161fa9 1646AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
742f9232 1647AC_CONFIG_FILES([config.h])
8c411768 1648
6a161fa9 1649AC_OUTPUT
5ce5507f 1650[
1651echo "*******************************************************"
1652echo GRUB2 will be compiled with following components:
1653echo Platform: "$target_cpu"-"$platform"
f84b481b 1654if [ x"$platform" = xemu ]; then
5ce5507f 1655if [ x"$grub_emu_usb_excuse" = x ]; then
1656echo USB support for grub-emu: Yes
1657else
1658echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
1659fi
927d0134
VS
1660if [ x"$grub_emu_sdl_excuse" = x ]; then
1661echo SDL support for grub-emu: Yes
1662else
1663echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
1664fi
325c8258 1665if [ x"$grub_emu_pci_excuse" = x ]; then
1666echo PCI support for grub-emu: Yes
1667else
1668echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
1669fi
f84b481b 1670fi
61d720e5
VS
1671if test x"$device_mapper_excuse" = x ; then
1672echo With devmapper support: Yes
1673else
1674echo With devmapper support: No "($device_mapper_excuse)"
1675fi
5ce5507f 1676if [ x"$enable_mm_debug" = xyes ]; then
1677echo With memory debugging: Yes
1678else
1679echo With memory debugging: No
1680fi
c5dc1690
SJ
1681if [ x"$enable_cache_stats" = xyes ]; then
1682echo With disk cache statistics: Yes
1683else
1684echo With disk cache statistics: No
1685fi
e744219b
VS
1686
1687if [ x"$enable_boot_time" = xyes ]; then
1688echo With boot time statistics: Yes
1689else
1690echo With boot time statistics: No
1691fi
1692
5ce5507f 1693if [ x"$efiemu_excuse" = x ]; then
1694echo efiemu runtime: Yes
1695else
1696echo efiemu runtime: No "($efiemu_excuse)"
1697fi
5ce5507f 1698if [ x"$grub_mkfont_excuse" = x ]; then
1699echo grub-mkfont: Yes
1700else
1701echo grub-mkfont: No "($grub_mkfont_excuse)"
1702fi
897e6207 1703if [ x"$grub_mount_excuse" = x ]; then
89644ef1 1704echo grub-mount: Yes
92bb0786 1705else
897e6207 1706echo grub-mount: No "($grub_mount_excuse)"
92bb0786 1707fi
c5884973
DO
1708if [ x"$starfield_excuse" = x ]; then
1709echo starfield theme: Yes
1710else
1711echo starfield theme: No "($starfield_excuse)"
1712fi
e4c498a1
MG
1713if [ x"$libzfs_excuse" = x ]; then
1714echo With libzfs support: Yes
1715else
1716echo With libzfs support: No "($libzfs_excuse)"
1717fi
7b780018 1718if [ x"$grub_build_mkfont_excuse" = x ]; then
7c9d0c39
VS
1719 echo Build-time grub-mkfont: Yes
1720 if test "x$FONT_SOURCE" = x ; then
1721 echo "Without unifont"
1722 else
1723 echo "With unifont from $FONT_SOURCE"
1724 fi
4b80e43c 1725else
7b780018 1726 echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
7c9d0c39 1727 echo "Without unifont (no build-time grub-mkfont)"
4b80e43c 1728fi
0d2d30bb
VS
1729if test x"$liblzma_excuse" != x ; then
1730echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excuse)"
64fce2d8
VS
1731else
1732echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
1733fi
5ce5507f 1734echo "*******************************************************"
1735]