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