]> git.proxmox.com Git - grub2.git/blame - configure.ac
* configure.ac: Add -Wvla if compiler supports it.
[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
60d5e9cb
VS
425WARN_FLAGS="-Wall -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Wattributes -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign"
426EXTRA_WARN_FLAGS="-Wvla"
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
VS
517AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang]
518[AC_COMPILE_IFELSE(
519[AC_LANG_PROGRAM([], [[
520#ifdef __clang__
521#error "is clang"
522#endif
523]])],
524[grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])
525
2312f06c
VS
526# on x86 clang doesn't support .code16
527# on arm clang doesn't support .arch directive
63a45330
VS
528# on mips clang doesn't support privilegied instructions, doubleword store/load
529# and crashes with hand-written assembly
530if test "x$grub_cv_cc_target_clang" = xyes && ( test "x$target_cpu" = xi386 \
531 || test "x$target_cpu" = xx86_64 || test "x$target_cpu" = xarm \
532 || test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ); then
60375a88
VS
533 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -no-integrated-as"
534fi
535
536if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
537 TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
538fi
539
540if test "x$target_m32" = x1; then
541 # Force 32-bit mode.
542 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
543 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
544 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
545 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
546 TARGET_MODULE_FORMAT="elf32"
547fi
548
549if test "x$target_m64" = x1; then
550 # Force 64-bit mode.
551 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
552 TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
553 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
554 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
555 TARGET_MODULE_FORMAT="elf64"
556fi
557
558if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
559 TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
560fi
561
f93ddcfd
VS
562# on mips redirect cache flushing function to non-existant one.
563if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
564 AC_CACHE_CHECK([whether -mflush-func=grub_red_herring works], [grub_cv_cc_mflush_func], [
565 CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring -Werror"
566 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
567 [grub_cv_cc_mflush_func=yes],
568 [grub_cv_cc_mflush_func=no])
569 ])
570
571 if test "x$grub_cv_cc_mflush_func" = xyes; then
572 TARGET_CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring"
573 fi
574fi
575
576
90d1e879
RM
577# Force no alignment to save space on i386.
578if test "x$target_cpu" = xi386; then
579 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
b35ec299 580 CFLAGS="$TARGET_CFLAGS -falign-loops=1 -Werror"
eb73121d 581 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
90d1e879
RM
582 [grub_cv_cc_falign_loop=yes],
583 [grub_cv_cc_falign_loop=no])
6a161fa9 584 ])
6a161fa9 585
c966a489 586 AC_CACHE_CHECK([whether -malign-loops works], [grub_cv_cc_malign_loop], [
b35ec299 587 CFLAGS="$TARGET_CFLAGS -malign-loops=1 -Werror"
c966a489
VS
588 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
589 [grub_cv_cc_malign_loop=yes],
590 [grub_cv_cc_malign_loop=no])
591 ])
592
90d1e879
RM
593 if test "x$grub_cv_cc_falign_loop" = xyes; then
594 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
c966a489 595 elif test "x$grub_cv_cc_malign_loop" = xyes; then
90d1e879 596 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 597 fi
89e0240c 598fi
6a161fa9 599
cdc17f60
VS
600AC_CACHE_CHECK([whether -freg-struct-return works], [grub_cv_cc_freg_struct_return], [
601 CFLAGS="$TARGET_CFLAGS -freg-struct-return -Werror"
602 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
603 [grub_cv_cc_freg_struct_return=yes],
604 [grub_cv_cc_freg_struct_return=no])
605])
606
607if test "x$grub_cv_cc_freg_struct_return" = xyes; then
608 TARGET_CFLAGS="$TARGET_CFLAGS -freg-struct-return"
609fi
610
ee0220bc 611if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
90d1e879
RM
612 # Some toolchains enable these features by default, but they need
613 # registers that aren't set up properly in GRUB.
614 TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow"
615fi
77c55a87 616
90d1e879
RM
617# By default, GCC 4.4 generates .eh_frame sections containing unwind
618# information in some cases where it previously did not. GRUB doesn't need
619# these and they just use up vital space. Restore the old compiler
620# behaviour.
621AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
24f4e57c 622 CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
90d1e879
RM
623 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
624 [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
625 [grub_cv_cc_fno_dwarf2_cfi_asm=no])
90d1e879 626])
77c55a87 627
90d1e879
RM
628if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
629 TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
b977bf01 630fi
6a161fa9 631
1c1f31e5
VS
632if test x"$target_os" = xcygwin; then
633 AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
24f4e57c 634 CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
1c1f31e5
VS
635 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
636 [grub_cv_cc_no_reorder_functions=yes],
637 [grub_cv_cc_no_reorder_functions=no])
638 ])
639fi
640
641if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
642 TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
643fi
644
e9d3421c
VS
645# By default, GCC 4.6 generates .eh_frame sections containing unwind
646# information in some cases where it previously did not. GRUB doesn't need
647# these and they just use up vital space. Restore the old compiler
648# behaviour.
649AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [
24f4e57c 650 CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
e9d3421c
VS
651 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
652 [grub_cv_cc_fno_asynchronous_unwind_tables=yes],
653 [grub_cv_cc_fno_asynchronous_unwind_tables=no])
e9d3421c
VS
654])
655
656if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then
657 TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
658fi
659
2b167a72 660# For platforms where ELF is not the default link format.
fc97214f 661case "${target_os}" in
a9f25a08 662 cygwin)
4b0cd8f8 663# FIXME: put proper test here
742f9232 664 NEED_REGISTER_FRAME_INFO=1
4b0cd8f8 665 ;;
742f9232 666 *) NEED_REGISTER_FRAME_INFO=0 ;;
2b167a72 667esac
2b167a72 668
30c7d3ce
VS
669
670AC_ARG_ENABLE([efiemu],
671 [AS_HELP_STRING([--enable-efiemu],
672 [build and install the efiemu runtimes (default=guessed)])])
673if test x"$enable_efiemu" = xno ; then
674 efiemu_excuse="explicitly disabled"
675fi
1c1f31e5
VS
676if test x"$target_os" = xcygwin ; then
677 efiemu_excuse="not available on cygwin"
678fi
30c7d3ce
VS
679if test x"$target_cpu" != xi386 ; then
680 efiemu_excuse="only available on i386"
681fi
682if test x"$platform" = xefi ; then
683 efiemu_excuse="not available on efi"
684fi
685if test x"$efiemu_excuse" = x ; then
686 AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
3c2304d5 687 CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
30c7d3ce
VS
688 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
689 [grub_cv_cc_efiemu=yes],
690 [grub_cv_cc_efiemu=no])
691 ])
692 if test x$grub_cv_cc_efiemu = xno; then
693 efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
694 fi
695fi
c2b70d09
AB
696if test x"$efiemu_excuse" = x ; then
697 AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [
698 grub_cv_target_cc_efiemu64_link_format=unknown
699 for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do
700 CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
701 LDFLAGS="-m64 -Wl,$format -nostdlib -static"
702 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
703 asm (".globl start; start:");
704 asm (".globl _start; _start:");
705 asm (".globl __start; __start:");
706 void __main (void);
707 void __main (void) {}
708 ]], [[]])], [flag=1], [flag=0])
709 if test x"$flag" = x1; then
710 grub_cv_target_cc_efiemu64_link_format="$format"
711 break;
712 fi
713 done])
714 if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then
715 efiemu_excuse="no suitable link format for efiemu64 found"
716 else
717 EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format"
718 fi
719fi
30c7d3ce
VS
720if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
721 AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled])
722fi
723if test x"$efiemu_excuse" = x ; then
724enable_efiemu=yes
725else
726enable_efiemu=no
727fi
728AC_SUBST([enable_efiemu])
c2b70d09 729AC_SUBST([EFIEMU64_LINK_FORMAT])
30c7d3ce 730
a9f25a08
VS
731CFLAGS="$TARGET_CFLAGS"
732
733if test x"$target_cpu" = xi386 || test x"$target_cpu" = xx86_64; then
c2b70d09 734 AC_CACHE_CHECK([for target linking format], [grub_cv_target_cc_link_format], [
a9f25a08
VS
735 grub_cv_target_cc_link_format=unknown
736 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
737 if test x${target_cpu} != xi386 && test x$format = x${target_cpu}pe; then
738 continue
739 fi
246a434f
VS
740 CFLAGS="$TARGET_CFLAGS"
741 LDFLAGS="$TARGET_LDFLAGS -Wl,$format -nostdlib -static"
a9f25a08
VS
742 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
743 asm (".globl start; start:");
744 asm (".globl _start; _start:");
745 asm (".globl __start; __start:");
746 void __main (void);
747 void __main (void) {}
c2b70d09 748 ]], [[]])], [flag=1], [flag=0])
a9f25a08
VS
749 if test x"$flag" = x1; then
750 grub_cv_target_cc_link_format="$format"
751 break;
752 fi
753 done])
754 if test x"$grub_cv_target_cc_link_format" = xunknown; then
755 AC_MSG_ERROR([no suitable link format found])
756 fi
757 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
758 if test x"$grub_cv_target_cc_link_format" = x-mi386pe; then
759 TARGET_OBJ2ELF='./build-grub-pe2elf';
760 fi
761fi
762
763if test x$grub_cv_target_cc_link_format = x-arch,i386 || test x$grub_cv_target_cc_link_format = x-arch,x86_64; then
764 TARGET_APPLE_LINKER=1
765 AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
766 if test "x$TARGET_OBJCONV" = x ; then
767 AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
768 fi
769 if test "x$TARGET_OBJCONV" = x ; then
770 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
771 fi
772 TARGET_IMG_LDSCRIPT=
773 TARGET_IMG_CFLAGS="-static"
774 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
775 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
776 TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
777 TARGET_LDFLAGS_OLDMAGIC=""
778elif test x$grub_cv_target_cc_link_format = x-mi386pe && test x$platform = xpc; then
779 TARGET_APPLE_LINKER=0
780 TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
781 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/i386-pc-cygwin-img-ld.sc"
782 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
783 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/i386-pc-cygwin-img-ld.sc"
784 TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
785 TARGET_IMG_CFLAGS=
786else
787 TARGET_APPLE_LINKER=0
788 TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
789 TARGET_IMG_LDSCRIPT=
790 TARGET_IMG_LDFLAGS='-Wl,-N'
791 TARGET_IMG_LDFLAGS_AC='-Wl,-N'
792 TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
793 TARGET_IMG_CFLAGS=
794fi
795
796AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)
797
798
799LDFLAGS="$TARGET_LDFLAGS"
8f0baaac 800
46546fc5 801if test "$target_cpu" = x86_64; then
7e9ca17a 802 # Use large model to support 4G memory
6e09b8b7 803 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
24f4e57c 804 CFLAGS="$TARGET_CFLAGS -m64 -mcmodel=large"
6e09b8b7 805 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
806 [grub_cv_cc_mcmodel=yes],
807 [grub_cv_cc_mcmodel=no])
808 ])
a3ba7410 809 if test "x$grub_cv_cc_mcmodel" = xyes; then
c8600122 810 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
6e09b8b7 811 fi
46546fc5 812fi
7e9ca17a 813
46546fc5 814if test "$target_cpu"-"$platform" = x86_64-efi; then
7e9ca17a 815 # EFI writes to stack below %rsp, we must not use the red zone
816 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
24f4e57c 817 CFLAGS="$TARGET_CFLAGS -m64 -mno-red-zone"
7e9ca17a 818 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
819 [grub_cv_cc_no_red_zone=yes],
820 [grub_cv_cc_no_red_zone=no])
821 ])
822 if test "x$grub_cv_cc_no_red_zone" = xno; then
823 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
824 fi
825
c8600122 826 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
20011694 827fi
828
baa2a121 829#
830# Compiler features.
831#
832
28668d80
VS
833CFLAGS="$TARGET_CFLAGS"
834
93a81088 835# Position independent executable.
836grub_CHECK_PIE
837[# Need that, because some distributions ship compilers that include
838# `-fPIE' in the default specs.
839if [ x"$pie_possible" = xyes ]; then
840 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
841fi]
842
28668d80
VS
843CFLAGS="$TARGET_CFLAGS"
844
7bd8b0c7
VS
845# Position independent executable.
846grub_CHECK_PIC
9cf12b20
VS
847[# On most platforms we don't want PIC as it only makes relocations harder
848# and code less efficient. On mips we want to have one got table per module
849# and reload $gp in every function.
850# GCC implements it using symbol __gnu_local_gp in non-PIC as well.
851# However with clang we need PIC for this reloading to happen.
852# Since default varies across dictributions use either -fPIC or -fno-PIC
853# explicitly.
854if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then
855 TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
856elif [ x"$pic_possible" = xyes ]; then
857 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
7bd8b0c7
VS
858fi]
859
28668d80
VS
860CFLAGS="$TARGET_CFLAGS"
861
baa2a121 862# Smashing stack protector.
863grub_CHECK_STACK_PROTECTOR
c3db8364 864# Need that, because some distributions ship compilers that include
baa2a121 865# `-fstack-protector' in the default specs.
c3db8364 866if test "x$ssp_possible" = xyes; then
867 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
868fi
28668d80
VS
869
870CFLAGS="$TARGET_CFLAGS"
871
2a8a80e4 872grub_CHECK_STACK_ARG_PROBE
873# Cygwin's GCC uses alloca() to probe the stackframe on static
874# stack allocations above some threshold.
875if test x"$sap_possible" = xyes; then
876 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
877fi
baa2a121 878
28668d80
VS
879CFLAGS="$TARGET_CFLAGS"
880
d74b9a1d 881# -mno-unaligned-access -mstrict-align
bb9f92b9 882if test "$target_cpu" = arm; then
d74b9a1d
VS
883 AC_CACHE_CHECK([for compile options to get strict alignment], [grub_cv_target_cc_strict_align], [
884 grub_cv_target_cc_strict_align=unknown
885 for arg in -mno-unaligned-access "-Xclang -mstrict-align" -mstrict-align; do
886 CFLAGS="$TARGET_CFLAGS $arg -Werror"
887 LDFLAGS="$TARGET_LDFLAGS"
888 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
889 if test x"$flag" = x1; then
890 grub_cv_target_cc_strict_align="$arg"
891 break;
892 fi
893 done])
894
895 if test x"$grub_cv_target_cc_strict_align" = xunknown; then
896 AC_MSG_ERROR([couldnt instruct compiler not to use unaligned access])
897 fi
898 TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_strict_align"
899 if test x"$grub_cv_target_cc_strict_align" = x"-Xclang -mstrict-align"; then
900 TARGET_LDFLAGS="$TARGET_LDFLAGS -Qunused-arguments"
bb9f92b9
LL
901 fi
902fi
903
aa6d7826 904# Set them to their new values for the tests below.
905CC="$TARGET_CC"
a9f25a08 906if test "x$TARGET_APPLE_LINKER" = x1 ; then
246a434f 907CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error"
26de2bcd 908else
01fcf061 909CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wno-error"
26de2bcd 910fi
aa6d7826 911CPPFLAGS="$TARGET_CPPFLAGS"
d5524ca8
VS
912if test x$target_cpu = xi386 || test x$target_cpu = xx86_64 || test "x$grub_cv_cc_target_clang" = xyes ; then
913TARGET_LIBGCC=
03f80960 914else
d5524ca8 915TARGET_LIBGCC=-lgcc
03f80960 916fi
69be5b74 917
d5524ca8
VS
918LIBS="$TARGET_LIBGCC"
919
01fcf061 920grub_ASM_USCORE
a9f25a08 921if test "x$TARGET_APPLE_LINKER" = x0 ; then
01fcf061 922if test x$grub_cv_asm_uscore = xyes; then
31c0cd43 923CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,_abort=_main"
01fcf061 924else
31c0cd43 925CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,abort=main"
01fcf061 926fi
a9f25a08 927fi
01fcf061 928
69be5b74 929# Check for libgcc symbols
6fcec439 930AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x)
69be5b74 931
a9f25a08 932if test "x$TARGET_APPLE_LINKER" = x1 ; then
246a434f 933CFLAGS="$TARGET_CFLAGS -nostdlib -static"
69be5b74
VS
934else
935CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
936fi
42e0cba3 937LIBS=""
aa6d7826 938
6a161fa9 939# Defined in aclocal.m4.
f6130a12 940grub_PROG_TARGET_CC
a9f25a08 941if test "x$TARGET_APPLE_LINKER" != x1 ; then
b977bf01 942grub_PROG_OBJCOPY_ABSOLUTE
2b167a72 943fi
cb71ba20 944grub_PROG_LD_BUILD_ID_NONE
b977bf01 945if test "x$target_cpu" = xi386; then
a9f25a08 946 if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
2aec1692
CF
947 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
948 # Check symbols provided by linker script.
5cf9459c 949 CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000 -Wl,--defsym,___main=0x8100"
2aec1692 950 fi
2a8a80e4 951 grub_CHECK_BSS_START_SYMBOL
952 grub_CHECK_END_SYMBOL
953 fi
954 CFLAGS="$TARGET_CFLAGS"
4b13b216 955 grub_I386_ASM_PREFIX_REQUIREMENT
956 grub_I386_ASM_ADDR32
6a161fa9 957fi
958
20aea949
VS
959grub_PROG_NM_WORKS
960grub_PROG_NM_MINUS_P
961grub_PROG_NM_DEFINED_ONLY
962AC_SUBST(TARGET_NMFLAGS_MINUS_P)
963AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)
964
016a671b 965if test "$platform" != emu; then
8f9a632b
VS
966AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
967 SAVED_CPPFLAGS="$CPPFLAGS"
968 CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
969 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
ce938140 970#include <stddef.h>
8f9a632b
VS
971int va_arg_func (int fixed, va_list args);]], [[]])],
972 [grub_cv_cc_isystem=yes],
973 [grub_cv_cc_isystem=no])
974 CPPFLAGS="$SAVED_CPPFLAGS"
975])
976
977if test x"$grub_cv_cc_isystem" = xyes ; then
978 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
979fi
dae79b6b 980fi
5ce5507f 981
19ce697d 982AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_cc_wtrampolines], [
24f4e57c 983 CFLAGS="$TARGET_CFLAGS -Wtrampolines -Werror"
779dc15b
VS
984 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
985int va_arg_func (int fixed, va_list args);]], [[]])],
19ce697d
VS
986 [grub_cv_cc_wtrampolines=yes],
987 [grub_cv_cc_wtrampolines=no])
779dc15b
VS
988])
989
19ce697d
VS
990if test x"$grub_cv_cc_wtrampolines" = xyes ; then
991 TARGET_CFLAGS="$TARGET_CFLAGS -Wtrampolines"
779dc15b
VS
992fi
993
c9a86192 994# Restore the flags.
9962ed99 995CC="$tmp_CC"
996CFLAGS="$tmp_CFLAGS"
997CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 998LDFLAGS="$tmp_LDFLAGS"
aa6d7826 999LIBS="$tmp_LIBS"
6a161fa9 1000
4fe9862e 1001#
2965c7cc 1002# Check for options.
4fe9862e 1003#
1004
1005# Memory manager debugging.
b39f9d20 1006AC_ARG_ENABLE([mm-debug],
2965c7cc 1007 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 1008 [include memory manager debugging]),
2965c7cc 1009 [AC_DEFINE([MM_DEBUG], [1],
1010 [Define to 1 if you enable memory manager debugging.])])
1011
c5dc1690
SJ
1012AC_ARG_ENABLE([cache-stats],
1013 AS_HELP_STRING([--enable-cache-stats],
055e2b8b 1014 [enable disk cache statistics collection]))
c5dc1690
SJ
1015
1016if test x$enable_cache_stats = xyes; then
1017 DISK_CACHE_STATS=1
1018else
1019 DISK_CACHE_STATS=0
1020fi
1021AC_SUBST([DISK_CACHE_STATS])
1022
e744219b
VS
1023AC_ARG_ENABLE([boot-time],
1024 AS_HELP_STRING([--enable-boot-time],
1025 [enable boot time statistics collection]))
1026
1027if test x$enable_boot_time = xyes; then
1028 BOOT_TIME_STATS=1
1029else
1030 BOOT_TIME_STATS=0
1031fi
1032AC_SUBST([BOOT_TIME_STATS])
1033
d64399b5 1034AC_ARG_ENABLE([grub-emu-usb],
1035 [AS_HELP_STRING([--enable-grub-emu-usb],
5ce5507f 1036 [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
5ce5507f 1037
927d0134
VS
1038AC_ARG_ENABLE([grub-emu-sdl],
1039 [AS_HELP_STRING([--enable-grub-emu-sdl],
1040 [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
1041
3affd0ec 1042AC_ARG_ENABLE([grub-emu-pci],
1043 [AS_HELP_STRING([--enable-grub-emu-pci],
1044 [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
1045
f84b481b 1046if test "$platform" = emu; then
f84b481b 1047
62a747cb
VS
1048if test x"$enable_grub_emu_usb" != xyes ; then
1049 grub_emu_usb_excuse="not enabled"
5ce5507f 1050fi
325c8258 1051
0e848909
VS
1052if test x"$enable_grub_emu_pci" = xyes ; then
1053 grub_emu_usb_excuse="conflicts with PCI support"
1054fi
1055
5ce5507f 1056[if [ x"$grub_emu_usb_excuse" = x ]; then
d64399b5 1057 # Check for libusb libraries.]
5ce5507f 1058AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
e98cd0c2 1059 [grub_emu_usb_excuse=["need libusb library"]])
d64399b5 1060 AC_SUBST([LIBUSB])
5ce5507f 1061[fi]
1062[if [ x"$grub_emu_usb_excuse" = x ]; then
1063 # Check for headers.]
d64399b5 1064 AC_CHECK_HEADERS([usb.h], [],
e98cd0c2 1065 [grub_emu_usb_excuse=["need libusb headers"]])
4fe9862e 1066[fi]
c6f3b249 1067if test x"$enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then
ce7a733d 1068 AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled])
5ce5507f 1069fi
1070if test x"$grub_emu_usb_excuse" = x ; then
1071enable_grub_emu_usb=yes
1072else
1073enable_grub_emu_usb=no
1074fi
1075
927d0134
VS
1076if test x"$enable_grub_emu_sdl" = xno ; then
1077 grub_emu_sdl_excuse="explicitely disabled"
1078fi
1079[if [ x"$grub_emu_sdl_excuse" = x ]; then
1080 # Check for libSDL libraries.]
1081AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
1082 [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
1083 AC_SUBST([LIBSDL])
1084[fi]
9f293ab0 1085
927d0134
VS
1086[if [ x"$grub_emu_sdl_excuse" = x ]; then
1087 # Check for headers.]
1088 AC_CHECK_HEADERS([SDL/SDL.h], [],
1089 [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
1090[fi]
9f293ab0 1091
927d0134
VS
1092if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
1093 AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
1094fi
1095if test x"$grub_emu_sdl_excuse" = x ; then
1096enable_grub_emu_sdl=yes
1097else
1098enable_grub_emu_sdl=no
1099fi
1100
3affd0ec 1101if test x"$enable_grub_emu_pci" != xyes ; then
325c8258 1102 grub_emu_pci_excuse="not enabled"
1103fi
1104
1105if test x"$enable_grub_emu_usb" = xyes ; then
1106 grub_emu_pci_excuse="conflicts with USB support"
1107fi
1108
1109[if [ x"$grub_emu_pci_excuse" = x ]; then
1110 # Check for libpci libraries.]
459fed4b 1111 AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
1112 [grub_emu_pci_excuse=["need libpciaccess library"]])
1113 AC_SUBST([LIBPCIACCESS])
325c8258 1114[fi]
1115[if [ x"$grub_emu_pci_excuse" = x ]; then
1116 # Check for headers.]
1117 AC_CHECK_HEADERS([pci/pci.h], [],
459fed4b 1118 [grub_emu_pci_excuse=["need libpciaccess headers"]])
325c8258 1119[fi]
1120
1121if test x"$grub_emu_pci_excuse" = x ; then
1122enable_grub_emu_pci=yes
1123else
9f293ab0 1124
325c8258 1125enable_grub_emu_pci=no
3affd0ec 1126fi
1127
927d0134 1128AC_SUBST([enable_grub_emu_sdl])
d64399b5 1129AC_SUBST([enable_grub_emu_usb])
3affd0ec 1130AC_SUBST([enable_grub_emu_pci])
e7d09ac4
AB
1131
1132else
1133
1134# Ignore --enable-emu-* if platform is not emu
1135enable_grub_emu_sdl=no
1136enable_grub_emu_usb=no
1137enable_grub_emu_pci=no
f84b481b 1138fi
4fe9862e 1139
e52db1f7 1140AC_ARG_ENABLE([grub-mkfont],
1141 [AS_HELP_STRING([--enable-grub-mkfont],
5ce5507f 1142 [build and install the `grub-mkfont' utility (default=guessed)])])
1143if test x"$enable_grub_mkfont" = xno ; then
ce7a733d 1144 grub_mkfont_excuse="explicitly disabled"
5ce5507f 1145fi
1146
1147if test x"$grub_mkfont_excuse" = x ; then
e52db1f7 1148 # Check for freetype libraries.
a5b55c4b 1149 AC_CHECK_TOOLS([FREETYPE], [freetype-config])
e52db1f7 1150 if test "x$FREETYPE" = x ; then
e98cd0c2 1151 grub_mkfont_excuse=["need freetype2 library"]
e52db1f7 1152 fi
e52db1f7 1153fi
660960d6 1154
7b780018
VS
1155unset ac_cv_header_ft2build_h
1156
660960d6
VS
1157if test x"$grub_mkfont_excuse" = x ; then
1158 # Check for freetype libraries.
a5b55c4b
DM
1159 freetype_cflags=`$FREETYPE --cflags`
1160 freetype_libs=`$FREETYPE --libs`
d1e8a02f
VS
1161 SAVED_CPPFLAGS="$CPPFLAGS"
1162 CPPFLAGS="$CPPFLAGS $freetype_cflags"
660960d6
VS
1163 AC_CHECK_HEADERS([ft2build.h], [],
1164 [grub_mkfont_excuse=["need freetype2 headers"]])
d1e8a02f 1165 CPPFLAGS="$SAVED_CPPFLAGS"
660960d6
VS
1166fi
1167
5ce5507f 1168if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
ce7a733d 1169 AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
5ce5507f 1170fi
1171if test x"$grub_mkfont_excuse" = x ; then
1172enable_grub_mkfont=yes
1173else
1174enable_grub_mkfont=no
1175fi
e52db1f7 1176AC_SUBST([enable_grub_mkfont])
1177AC_SUBST([freetype_cflags])
1178AC_SUBST([freetype_libs])
1179
7c9d0c39 1180SAVED_CC="$CC"
b224c266 1181SAVED_CPP="$CPP"
7c9d0c39
VS
1182SAVED_CFLAGS="$CFLAGS"
1183SAVED_CPPFLAGS="$CPPFLAGS"
1184CC="$BUILD_CC"
b224c266 1185CPP="$BUILD_CPP"
7c9d0c39 1186CFLAGS="$BUILD_CFLAGS"
7b780018
VS
1187CPPFLAGS="$BUILD_CPPFLAGS"
1188
1189unset ac_cv_c_bigendian
1190unset ac_cv_header_ft2build_h
1191
1192AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
1193AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
1194AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])
1195
1196if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
1197 AC_MSG_ERROR([couldnt determine build endianness])
1198fi
1199
1200AC_SUBST([BUILD_SIZEOF_LONG])
1201AC_SUBST([BUILD_SIZEOF_VOID_P])
1202AC_SUBST([BUILD_WORDS_BIGENDIAN])
c5884973 1203
7c9d0c39
VS
1204if test x"$grub_build_mkfont_excuse" = x ; then
1205 # Check for freetype libraries.
7b780018 1206 AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
7c9d0c39
VS
1207 if test "x$BUILD_FREETYPE" = x ; then
1208 grub_build_mkfont_excuse=["need freetype2 library"]
1209 fi
1210fi
c5884973 1211
7c9d0c39
VS
1212if test x"$grub_build_mkfont_excuse" = x ; then
1213 # Check for freetype libraries.
1214 build_freetype_cflags=`$BUILD_FREETYPE --cflags`
1215 build_freetype_libs=`$BUILD_FREETYPE --libs`
1216 SAVED_CPPFLAGS_2="$CPPFLAGS"
1217 CPPFLAGS="$CPPFLAGS $build_freetype_cflags"
1218 AC_CHECK_HEADERS([ft2build.h], [],
1219 [grub_build_mkfont_excuse=["need freetype2 headers"]])
1220 CPPFLAGS="$SAVED_CPPFLAGS_2"
1221fi
1222
1223if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
1224 AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled])
1225fi
1226if test x"$grub_build_mkfont_excuse" = x ; then
1227 enable_build_grub_mkfont=yes
1228else
1229 enable_build_grub_mkfont=no
c5884973 1230fi
b2e9d276
VS
1231if 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
1232 AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports needs build-time grub-mkfont])
7c9d0c39
VS
1233fi
1234
1235AC_SUBST([build_freetype_cflags])
1236AC_SUBST([build_freetype_libs])
1237
1238CC="$SAVED_CC"
b224c266 1239CPP="$SAVED_CPP"
7c9d0c39
VS
1240CFLAGS="$SAVED_CFLAGS"
1241CPPFLAGS="$SAVED_CPPFLAGS"
1242
1243
1244DJVU_FONT_SOURCE=
1245
1246starfield_excuse=
c5884973 1247
300f48c5
VS
1248AC_ARG_ENABLE([grub-themes],
1249 [AS_HELP_STRING([--enable-grub-themes],
1250 [build and install GRUB themes (default=guessed)])])
1251if test x"$enable_grub_themes" = xno ; then
1252 starfield_excuse="explicitly disabled"
1253fi
1254
1255if test x"$starfield_excuse" = x && test x"$enable_build_grub_mkfont" = xno ; then
7b966834
VS
1256 starfield_excuse="No build-time grub-mkfont"
1257fi
1258
501b9e4b 1259if test x"$starfield_excuse" = x; then
c5884973 1260 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
32745f51 1261 for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu; do
c5884973
DO
1262 if test -f "$dir/DejaVuSans.$ext"; then
1263 DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
1264 break 2
1265 fi
1266 done
1267 done
1268
1269 if test "x$DJVU_FONT_SOURCE" = x; then
1270 starfield_excuse="No DejaVu found"
1271 fi
1272fi
1273
300f48c5
VS
1274if test x"$enable_grub_themes" = xyes && test x"$starfield_excuse" != x; then
1275 AC_MSG_ERROR([themes were explicitly requested but requirements are not satisfied])
1276fi
1277
c5884973
DO
1278AC_SUBST([DJVU_FONT_SOURCE])
1279
7c9d0c39
VS
1280FONT_SOURCE=
1281
1282for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1283 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
1284 if test -f "$dir/unifont.$ext"; then
1285 FONT_SOURCE="$dir/unifont.$ext"
1286 break 2
1287 fi
1288 done
1289done
1290
7b966834
VS
1291if test x"$enable_build_grub_mkfont" = xno ; then
1292 FONT_SOURCE=
1293fi
1294
b2e9d276
VS
1295if 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
1296 AC_MSG_ERROR([qemu, powerpc-ieee1275 and loongson ports need unifont])
7c9d0c39
VS
1297fi
1298
1299AC_SUBST([FONT_SOURCE])
1300
7b780018 1301if test x"$FONT_SOURCE" = x && test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
7c9d0c39
VS
1302 grub_build_mkfont_excuse="no fonts"
1303fi
1304
1305
897e6207
CW
1306AC_ARG_ENABLE([grub-mount],
1307 [AS_HELP_STRING([--enable-grub-mount],
1308 [build and install the `grub-mount' utility (default=guessed)])])
1309if test x"$enable_grub_mount" = xno ; then
1310 grub_mount_excuse="explicitly disabled"
92bb0786
VS
1311fi
1312
897e6207 1313if test x"$grub_mount_excuse" = x ; then
92bb0786 1314 AC_CHECK_LIB([fuse], [fuse_main_real], [],
897e6207 1315 [grub_mount_excuse="need FUSE library"])
92bb0786
VS
1316fi
1317
897e6207 1318if test x"$grub_mount_excuse" = x ; then
92bb0786
VS
1319 # Check for fuse headers.
1320 SAVED_CPPFLAGS="$CPPFLAGS"
338c7fab 1321 CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26"
92bb0786 1322 AC_CHECK_HEADERS([fuse/fuse.h], [],
897e6207 1323 [grub_mount_excuse=["need FUSE headers"]])
92bb0786
VS
1324 CPPFLAGS="$SAVED_CPPFLAGS"
1325fi
1326
897e6207 1327if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then
89644ef1 1328 AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled])
92bb0786 1329fi
897e6207
CW
1330if test x"$grub_mount_excuse" = x ; then
1331enable_grub_mount=yes
92bb0786 1332else
897e6207 1333enable_grub_mount=no
92bb0786 1334fi
897e6207 1335AC_SUBST([enable_grub_mount])
92bb0786 1336
7181e228
CW
1337AC_ARG_ENABLE([device-mapper],
1338 [AS_HELP_STRING([--enable-device-mapper],
1339 [enable Linux device-mapper support (default=guessed)])])
1340if test x"$enable_device_mapper" = xno ; then
1341 device_mapper_excuse="explicitly disabled"
1342fi
1343
53798c4b
GS
1344if test x"$device_mapper_excuse" = x ; then
1345 # Check for device-mapper header.
1346 AC_CHECK_HEADER([libdevmapper.h], [],
1347 [device_mapper_excuse="need libdevmapper header"])
1348fi
1349
7181e228
CW
1350if test x"$device_mapper_excuse" = x ; then
1351 # Check for device-mapper library.
61d720e5 1352 AC_CHECK_LIB([devmapper], [dm_task_create], [],
7181e228 1353 [device_mapper_excuse="need devmapper library"])
7181e228 1354fi
61d720e5
VS
1355
1356if test x"$device_mapper_excuse" = x ; then
1357 # Check for device-mapper library.
1358 AC_CHECK_LIB([devmapper], [dm_log_with_errno_init],
1359 [],
1360 [device_mapper_excuse="need devmapper library"])
1361fi
1362
1363if test x"$device_mapper_excuse" = x ; then
1364 LIBDEVMAPPER="-ldevmapper";
1365 AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
1366 [Define to 1 if you have the devmapper library.])
1367fi
1368
62f7d208 1369AC_SUBST([LIBDEVMAPPER])
76ed06b9 1370
f4727da9
VS
1371LIBGEOM=
1372if test x$host_kernel = xkfreebsd; then
1373 AC_CHECK_LIB([geom], [geom_gettree], [],
1374 [AC_MSG_ERROR([Your platform requires libgeom])])
1375 LIBGEOM="-lgeom"
1376fi
1377
1378AC_SUBST([LIBGEOM])
1379
0d2d30bb
VS
1380AC_ARG_ENABLE([liblzma],
1381 [AS_HELP_STRING([--enable-liblzma],
1382 [enable liblzma integration (default=guessed)])])
1383if test x"$enable_liblzma" = xno ; then
1384 liblzma_excuse="explicitly disabled"
1385fi
1386
1387if test x"$liblzma_excuse" = x ; then
2c44e493 1388AC_CHECK_LIB([lzma], [lzma_code],
0d2d30bb
VS
1389 [],[liblzma_excuse="need lzma library"])
1390fi
1391if test x"$liblzma_excuse" = x ; then
1392AC_CHECK_HEADER([lzma.h], [], [liblzma_excuse="need lzma header"])
1393fi
1394
1395if test x"$enable_liblzma" = xyes && test x"$liblzma_excuse" != x ; then
1396 AC_MSG_ERROR([liblzma support was explicitly requested but requirements are not satisfied])
1397fi
1398
1399
1400if test x"$liblzma_excuse" = x ; then
1401 LIBLZMA="-llzma"
1402 AC_DEFINE([USE_LIBLZMA], [1],
1403 [Define to 1 if you have the LZMA library.])
1404fi
1405
2c44e493
VS
1406AC_SUBST([LIBLZMA])
1407
e4c498a1
MG
1408AC_ARG_ENABLE([libzfs],
1409 [AS_HELP_STRING([--enable-libzfs],
1410 [enable libzfs integration (default=guessed)])])
1411if test x"$enable_libzfs" = xno ; then
1412 libzfs_excuse="explicitly disabled"
1413fi
16c7cb32 1414
e4c498a1
MG
1415if test x"$libzfs_excuse" = x ; then
1416 # Only check for system headers if libzfs support has not been disabled.
1417 AC_CHECK_HEADERS(libzfs.h libnvpair.h)
1418fi
1419
1420if test x"$libzfs_excuse" = x ; then
1421 AC_CHECK_LIB([zfs], [libzfs_init],
1422 [],
1423 [libzfs_excuse="need zfs library"])
1424fi
1425
1426if test x"$libzfs_excuse" = x ; then
27f9d02e 1427 AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
e4c498a1
MG
1428 [],
1429 [libzfs_excuse="need nvpair library"])
1430fi
1431
1432if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
1433 AC_MSG_ERROR([libzfs support was explicitly requested but requirements are not satisfied])
1434fi
1435
1436if test x"$libzfs_excuse" = x ; then
1437 # We need both libzfs and libnvpair for a successful build.
1438 LIBZFS="-lzfs"
1439 AC_DEFINE([HAVE_LIBZFS], [1],
1440 [Define to 1 if you have the ZFS library.])
1441 LIBNVPAIR="-lnvpair"
1442 AC_DEFINE([HAVE_LIBNVPAIR], [1],
1443 [Define to 1 if you have the NVPAIR library.])
1444fi
1445
1446AC_SUBST([LIBZFS])
16c7cb32
BC
1447AC_SUBST([LIBNVPAIR])
1448
9f915872
VS
1449LIBS=""
1450
76ed06b9 1451AC_SUBST([FONT_SOURCE])
76ed06b9
BC
1452AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
1453 [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
7181e228 1454
742f9232
VS
1455AC_SUBST(HAVE_ASM_USCORE)
1456AC_SUBST(ADDR32)
1457AC_SUBST(DATA32)
1458AC_SUBST(BSS_START_SYMBOL)
1459AC_SUBST(END_SYMBOL)
1460AC_SUBST(PACKAGE)
1461AC_SUBST(VERSION)
742f9232
VS
1462AC_SUBST(NEED_REGISTER_FRAME_INFO)
1463
d5524ca8
VS
1464AC_ARG_ENABLE([werror],
1465 [AS_HELP_STRING([--disable-werror],
1466 [do not use -Werror when building GRUB])])
1467if test x"$enable_werror" != xno ; then
1468 TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
1469 HOST_CFLAGS="$HOST_CFLAGS -Werror"
1470fi
1471
1472if test "x$grub_cv_cc_target_clang" = xno; then
1473 TARGET_LDFLAGS_STATIC_LIBGCC="-static-libgcc"
1474else
1475 TARGET_LDFLAGS_STATIC_LIBGCC=
1476fi
1477
1478TARGET_CPP="$TARGET_CC -E"
1479TARGET_CCAS=$TARGET_CC
1480
1481GRUB_TARGET_CPU="${target_cpu}"
1482GRUB_PLATFORM="${platform}"
1483
1484AC_SUBST(GRUB_TARGET_CPU)
1485AC_SUBST(GRUB_PLATFORM)
1486
1487AC_SUBST(TARGET_OBJCONV)
1488AC_SUBST(TARGET_LIBGCC)
1489AC_SUBST(TARGET_LDFLAGS_STATIC_LIBGCC)
1490AC_SUBST(TARGET_CPP)
1491AC_SUBST(TARGET_CCAS)
1492AC_SUBST(TARGET_OBJ2ELF)
d5524ca8
VS
1493AC_SUBST(TARGET_MODULE_FORMAT)
1494
1495AC_SUBST(TARGET_CFLAGS)
1496AC_SUBST(TARGET_LDFLAGS)
1497AC_SUBST(TARGET_CPPFLAGS)
1498AC_SUBST(TARGET_CCASFLAGS)
1499
1500AC_SUBST(TARGET_IMG_LDSCRIPT)
1501AC_SUBST(TARGET_IMG_LDFLAGS)
1502AC_SUBST(TARGET_IMG_CFLAGS)
1503AC_SUBST(TARGET_IMG_BASE_LDOPT)
a9f25a08 1504AC_SUBST(TARGET_APPLE_LINKER)
d5524ca8
VS
1505
1506AC_SUBST(HOST_CFLAGS)
1507AC_SUBST(HOST_LDFLAGS)
1508AC_SUBST(HOST_CPPFLAGS)
1509AC_SUBST(HOST_CCASFLAGS)
1510
1511AC_SUBST(BUILD_LIBM)
1512
76ed06b9
BC
1513#
1514# Automake conditionals
1515#
8c411768 1516
76ed06b9 1517AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
d59849b2 1518AM_CONDITIONAL([COND_clang], [test x$grub_cv_cc_target_clang = xyes])
76ed06b9
BC
1519AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
1520AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
6585de4c 1521AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
76ed06b9
BC
1522AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
1523AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
1524AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
1525AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
1526AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
9612ebc0
VS
1527AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
1528AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
4959e111
VS
1529AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
1530AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xqemu_mips])
7f63a64f 1531AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")" -a x$platform = xarc])
76ed06b9
BC
1532AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
1533AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
4959e111 1534AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
37ba07eb
VS
1535AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
1536AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
389b31cd
LL
1537AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
1538AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
1539AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
15a463d7
LL
1540AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
1541AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
f7711f5e
BC
1542
1543AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
1544AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
1545AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
1546AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
1547AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
b105df76 1548AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
958ee221 1549AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])
2d465fb0 1550
76ed06b9
BC
1551AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
1552AM_CONDITIONAL([COND_GRUB_EMU_USB], [test x$enable_grub_emu_usb = xyes])
1553AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
1554AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
1555AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
897e6207 1556AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
76ed06b9 1557AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
a9f25a08 1558AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
76ed06b9 1559AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
c5dc1690 1560AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
e744219b 1561AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
fc45fb58 1562
1eed0e6e
VS
1563AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])
1564
742f9232 1565AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
fc97214f 1566AM_CONDITIONAL([COND_CYGWIN], [test x$target_os = xcygwin])
c5884973 1567AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
cd46aa6c
VS
1568AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])
1569
1570test "x$prefix" = xNONE && prefix="$ac_default_prefix"
1571test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
1572datarootdir="$(eval echo "$datarootdir")"
1573grub_libdir="$(eval echo "$libdir")"
1574grub_localedir="$(eval echo "$localedir")"
1575grub_datadir="$(eval echo "$datadir")"
1576grub_sysconfdir="$(eval echo "$sysconfdir")"
1577AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
1578AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
1579AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
1580AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])
1581
742f9232 1582
6a161fa9 1583# Output files.
4959e111
VS
1584cpudir="${target_cpu}"
1585if test x${cpudir} = xmipsel; then
1586 cpudir=mips;
1587fi
1f4147aa 1588grub_CHECK_LINK_DIR
1589if test x"$link_dir" = xyes ; then
4959e111 1590 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
f84b481b 1591 if test "$platform" != emu ; then
4959e111 1592 AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
f84b481b 1593 fi
1f4147aa 1594else
1595 mkdir -p include/grub 2>/dev/null
1596 rm -rf include/grub/cpu
4959e111 1597 cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
f84b481b
RM
1598 if test "$platform" != emu ; then
1599 rm -rf include/grub/machine
4959e111 1600 cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
f84b481b 1601 fi
1f4147aa 1602fi
6304d292 1603
8c411768 1604AC_CONFIG_FILES([Makefile])
6304d292 1605AC_CONFIG_FILES([grub-core/Makefile])
15c69261 1606AC_CONFIG_FILES([grub-core/gnulib/Makefile])
269004c1 1607AC_CONFIG_FILES([po/Makefile.in])
8c411768 1608AC_CONFIG_FILES([docs/Makefile])
b23ffd70 1609AC_CONFIG_FILES([util/bash-completion.d/Makefile])
6a161fa9 1610AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
742f9232 1611AC_CONFIG_FILES([config.h])
8c411768 1612
6a161fa9 1613AC_OUTPUT
5ce5507f 1614[
1615echo "*******************************************************"
1616echo GRUB2 will be compiled with following components:
1617echo Platform: "$target_cpu"-"$platform"
f84b481b 1618if [ x"$platform" = xemu ]; then
5ce5507f 1619if [ x"$grub_emu_usb_excuse" = x ]; then
1620echo USB support for grub-emu: Yes
1621else
1622echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
1623fi
927d0134
VS
1624if [ x"$grub_emu_sdl_excuse" = x ]; then
1625echo SDL support for grub-emu: Yes
1626else
1627echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
1628fi
325c8258 1629if [ x"$grub_emu_pci_excuse" = x ]; then
1630echo PCI support for grub-emu: Yes
1631else
1632echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
1633fi
f84b481b 1634fi
61d720e5
VS
1635if test x"$device_mapper_excuse" = x ; then
1636echo With devmapper support: Yes
1637else
1638echo With devmapper support: No "($device_mapper_excuse)"
1639fi
5ce5507f 1640if [ x"$enable_mm_debug" = xyes ]; then
1641echo With memory debugging: Yes
1642else
1643echo With memory debugging: No
1644fi
c5dc1690
SJ
1645if [ x"$enable_cache_stats" = xyes ]; then
1646echo With disk cache statistics: Yes
1647else
1648echo With disk cache statistics: No
1649fi
e744219b
VS
1650
1651if [ x"$enable_boot_time" = xyes ]; then
1652echo With boot time statistics: Yes
1653else
1654echo With boot time statistics: No
1655fi
1656
5ce5507f 1657if [ x"$efiemu_excuse" = x ]; then
1658echo efiemu runtime: Yes
1659else
1660echo efiemu runtime: No "($efiemu_excuse)"
1661fi
5ce5507f 1662if [ x"$grub_mkfont_excuse" = x ]; then
1663echo grub-mkfont: Yes
1664else
1665echo grub-mkfont: No "($grub_mkfont_excuse)"
1666fi
897e6207 1667if [ x"$grub_mount_excuse" = x ]; then
89644ef1 1668echo grub-mount: Yes
92bb0786 1669else
897e6207 1670echo grub-mount: No "($grub_mount_excuse)"
92bb0786 1671fi
c5884973
DO
1672if [ x"$starfield_excuse" = x ]; then
1673echo starfield theme: Yes
1674else
1675echo starfield theme: No "($starfield_excuse)"
1676fi
e4c498a1
MG
1677if [ x"$libzfs_excuse" = x ]; then
1678echo With libzfs support: Yes
1679else
1680echo With libzfs support: No "($libzfs_excuse)"
1681fi
7b780018 1682if [ x"$grub_build_mkfont_excuse" = x ]; then
7c9d0c39
VS
1683 echo Build-time grub-mkfont: Yes
1684 if test "x$FONT_SOURCE" = x ; then
1685 echo "Without unifont"
1686 else
1687 echo "With unifont from $FONT_SOURCE"
1688 fi
4b80e43c 1689else
7b780018 1690 echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
7c9d0c39 1691 echo "Without unifont (no build-time grub-mkfont)"
4b80e43c 1692fi
0d2d30bb
VS
1693if test x"$liblzma_excuse" != x ; then
1694echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excuse)"
64fce2d8
VS
1695else
1696echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
1697fi
5ce5507f 1698echo "*******************************************************"
1699]