configure.ac 66.4 KB
Newer Older
1 2
# -*- autoconf -*-

okuji's avatar
okuji committed
3 4
# Process this file with autoconf to produce a configure script.

5
# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010  Free Software Foundation, Inc.
okuji's avatar
okuji committed
6 7 8 9 10 11 12 13 14 15
#
# This configure.ac is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

16 17 18 19 20 21 22 23 24 25 26 27 28
dnl This configure script is complicated, because GRUB needs to deal
dnl with three potentially different types:
dnl
dnl   build  -- the environment for building GRUB
dnl   host   -- the environment for running utilities
dnl   target -- the environment for running GRUB
dnl
dnl In addition, GRUB needs to deal with a platform specification
dnl which specifies the system running GRUB, such as firmware.
dnl This is necessary because the target type in autoconf does not
dnl describe such a system very well.
dnl
dnl The current strategy is to use variables with no prefix (such as
29 30 31 32
dnl CC, CFLAGS, etc.) for the host type, variables with prefix "BUILD_"
dnl (such as BUILD_CC, BUILD_CFLAGS, etc.) for the build type and variables
dnl with the prefix "TARGET_" (such as TARGET_CC, TARGET_CFLAGS, etc.) are
dnl used for the target type. See INSTALL for full list of variables.
33

34
AC_INIT([GRUB],[2.02~beta2],[bug-grub@gnu.org])
okuji's avatar
okuji committed
35

36 37
AC_CONFIG_AUX_DIR([build-aux])

38 39
# We don't want -g -O2 by default in CFLAGS
: ${CFLAGS=""}
okuji's avatar
okuji committed
40

41 42
# Checks for build, host and target systems.
AC_CANONICAL_BUILD
okuji's avatar
okuji committed
43
AC_CANONICAL_HOST
44
save_program_prefix="${program_prefix}"
45
AC_CANONICAL_TARGET
46
program_prefix="${save_program_prefix}"
okuji's avatar
okuji committed
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 54
# Program name transformations
AC_ARG_PROGRAM
55 56 57 58 59 60
grub_TRANSFORM([grub-bios-setup])
grub_TRANSFORM([grub-editenv])
grub_TRANSFORM([grub-install])
grub_TRANSFORM([grub-mkconfig])
grub_TRANSFORM([grub-mkfont])
grub_TRANSFORM([grub-mkimage])
61
grub_TRANSFORM([grub-glue-efi])
62 63 64 65 66 67 68 69 70
grub_TRANSFORM([grub-mklayout])
grub_TRANSFORM([grub-mkpasswd-pbkdf2])
grub_TRANSFORM([grub-mkrelpath])
grub_TRANSFORM([grub-mkrescue])
grub_TRANSFORM([grub-probe])
grub_TRANSFORM([grub-reboot])
grub_TRANSFORM([grub-script-check])
grub_TRANSFORM([grub-set-default])
grub_TRANSFORM([grub-sparc64-setup])
71
grub_TRANSFORM([grub-render-label])
72
grub_TRANSFORM([grub-file])
73

74 75 76 77 78
# Optimization flag.  Allow user to override.
if test "x$TARGET_CFLAGS" = x; then
  TARGET_CFLAGS="$TARGET_CFLAGS -Os"
fi

79 80 81 82 83 84
# Default HOST_CPPFLAGS
HOST_CPPFLAGS="$HOST_CPPFLAGS -Wall -W"
HOST_CPPFLAGS="$HOST_CPPFLAGS -DGRUB_UTIL=1"

TARGET_CPPFLAGS="$TARGET_CPPFLAGS -Wall -W"

85
case "$target_cpu" in
86
  i[[3456]]86)	target_cpu=i386 ;;
87
  amd64)	target_cpu=x86_64 ;;
88
  sparc)	target_cpu=sparc64 ;;
89
  mipsel|mips64el)
90 91
                target_cpu=mipsel
		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPSEL=1"
92
		;;
93
  mips|mips64)
94 95
                target_cpu=mips
		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_CPU_MIPS=1"
96
		;;
97
  arm*)
98
		target_cpu=arm
99
		;;
100
  aarch64*)
101
		target_cpu=arm64
102
		;;
okuji's avatar
okuji committed
103 104
esac

105 106 107
# Specify the platform (such as firmware).
AC_ARG_WITH([platform],
            AS_HELP_STRING([--with-platform=PLATFORM],
108
                           [select the host platform [[guessed]]]))
109 110 111

# Guess the platform if not specified.
if test "x$with_platform" = x; then
112
  case "$target_cpu"-"$target_vendor" in
113 114
    i386-apple) platform=efi ;;
    i386-*) platform=pc ;;
115
    x86_64-apple) platform=efi ;;
116
    x86_64-*) platform=pc ;;
117
    powerpc-*) platform=ieee1275 ;;
118
    powerpc64-*) platform=ieee1275 ;;
119
    powerpc64le-*) platform=ieee1275 ;;
120
    sparc64-*) platform=ieee1275 ;;
121 122
    mipsel-*) platform=loongson ;;
    mips-*) platform=arc ;;
Robert Millan's avatar
Robert Millan committed
123
    ia64-*) platform=efi ;;
124
    arm-*) platform=uboot ;;
125
    arm64-*) platform=efi ;;
126 127 128 129
    *)
      AC_MSG_WARN([unsupported CPU: "$target_cpu" - only building utilities])
      platform=none
      ;;
130 131 132 133 134
  esac
else
  platform="$with_platform"
fi

135 136 137
case "$target_cpu"-"$platform" in
  x86_64-efi) ;;
  x86_64-emu) ;;
138
  x86_64-xen) ;;
139
  x86_64-none) ;;
140 141
  x86_64-*) target_cpu=i386 ;;
  powerpc64-ieee1275) target_cpu=powerpc ;;
142
  powerpc64le-ieee1275) target_cpu=powerpc ;;
143
esac
144

145
# Check if the platform is supported, make final adjustments.
146
case "$target_cpu"-"$platform" in
147
  i386-efi) ;;
148
  x86_64-efi) ;;
149 150
  i386-xen) ;;
  x86_64-xen) ;;
151
  i386-pc) ;;
152
  i386-multiboot) ;;
153
  i386-coreboot) ;;
154
  i386-linuxbios) platform=coreboot ;;
155
  i386-ieee1275) ;;
156
  i386-qemu) ;;
157 158
  powerpc-ieee1275) ;;
  sparc64-ieee1275) ;;
159
  ia64-efi) ;;
160
  mips-qemu_mips) ;;
161
  mips-qemu-mips) platform=qemu_mips;;
162
  mips-arc) ;;
163
  mipsel-arc) ;;
164 165 166 167 168
  mipsel-qemu_mips) ;;
  mipsel-qemu-mips) platform=qemu_mips;;
  mipsel-yeeloong) platform=loongson ;;
  mipsel-fuloong) platform=loongson ;;
  mipsel-loongson) ;;
169
  arm-uboot) ;;
Vladimir Serbinenko's avatar
Vladimir Serbinenko committed
170
  arm-coreboot) ;;
171
  arm-efi) ;;
172
  arm64-efi) ;;
173
  *-emu) ;;
174
  *-none) ;;
175
  *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
okuji's avatar
okuji committed
176 177
esac

Vladimir Serbinenko's avatar
Vladimir Serbinenko committed
178
if test x$platform != xemu ; then
179 180 181 182 183
   case "$target_cpu" in
	i386 | powerpc) target_m32=1 ;;
	x86_64 | sparc64) target_m64=1 ;;
   esac
fi
184

185
if test x"$target_cpu-$platform" = xsparc64-emu ; then
186
   target_m64=1
187 188
fi

189
case "$target_os" in
190
  windows* | mingw32*) target_os=cygwin ;;
191 192
esac

193 194 195 196 197 198
# This normalizes the names, and creates a new variable ("host_kernel")
# while at it, since the mapping is not always 1:1 (e.g. different OSes
# using the same kernel type).
case "$host_os" in
  gnu*)				host_kernel=hurd ;;
  linux*)			host_kernel=linux ;;
199
  freebsd* | kfreebsd*-gnu)	host_kernel=kfreebsd ;;
200
  netbsd*)			host_kernel=netbsd ;;
201
  solaris*)			host_kernel=illumos ;;
202
  darwin*)			host_kernel=xnu ;;
203
  cygwin | windows* | mingw32*)	host_kernel=windows ;;
204 205
esac

206 207 208 209 210 211
case "$host_os" in
  cygwin | windows* | mingw32*)	have_exec=n ;;
  aros*) have_exec=n ;;
  *) have_exec=y;;
esac

212
case "$platform" in
213 214 215
  coreboot)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_COREBOOT=1" ;;
  multiboot)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MULTIBOOT=1" ;;
  efi)		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EFI=1" ;;
216
  xen)		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_XEN=1" ;;
217
  ieee1275)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_IEEE1275=1" ;;
218
  uboot)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_UBOOT=1" ;;
219 220 221
  qemu)		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_QEMU=1" ;;
  pc)		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_PCBIOS=1" ;;
  emu)		machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_EMU=1" ;;
222 223
  loongson)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_LOONGSON=1" ;;
  qemu_mips)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_MIPS_QEMU_MIPS=1" ;;
224
  arc)	machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE_ARC=1" ;;
225
esac
226 227 228
if test x${target_cpu} = xmipsel ; then
   machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo mips_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
else
229
   machine_CPPFLAGS="$machine_CPPFLAGS -DGRUB_MACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
230
fi
231

232 233 234 235 236 237 238 239 240
case "${target_cpu}-$platform" in
     mips-arc)
        TARGET_LINK_ADDR=0x88200000
        TARGET_DECOMPRESSOR_LINK_ADDR=0x88100000
	;;
     mipsel-arc)
        TARGET_LINK_ADDR=0x80700000
	TARGET_DECOMPRESSOR_LINK_ADDR=0x80600000
	;;
241
     mips*-qemu_mips | mips*-loongson)
242 243 244 245 246 247 248
        TARGET_DECOMPRESSOR_LINK_ADDR=0x80100000
	;;
esac

AC_SUBST(TARGET_LINK_ADDR)
AC_SUBST(TARGET_DECOMPRESSOR_LINK_ADDR)

249
TARGET_CPPFLAGS="$TARGET_CPPFLAGS $machine_CPPFLAGS"
250

251 252
AC_SUBST(host_cpu)
AC_SUBST(host_os)
253
AC_SUBST(host_kernel)
254

255 256 257
AC_SUBST(target_cpu)
AC_SUBST(platform)

258
# Define default variables
259 260 261 262 263 264 265 266 267 268 269 270

have_with_bootdir=n
AC_ARG_WITH([bootdir],
            AS_HELP_STRING([--with-bootdir=DIR],
                           [set the name of /boot directory [[guessed]]]),
			   [have_with_bootdir=y],
			   [have_with_bootdir=n])
if test x$have_with_bootdir = xy; then
   bootdirname="$with_bootdir"
else
   case "$host_os" in
     netbsd* | openbsd*)
271
        # Because /boot is used for the boot block in NetBSD and OpenBSD,
272 273 274 275 276
           bootdirname=''      ;;
     *)    bootdirname='boot'  ;;
   esac
fi

277
AC_SUBST(bootdirname)
278 279
AC_DEFINE_UNQUOTED(GRUB_BOOT_DIR_NAME, "$bootdirname",
    [Default boot directory name]")
280

281 282 283 284 285 286
AC_ARG_WITH([grubdir],
            AS_HELP_STRING([--with-grubdir=DIR],
                           [set the name of grub directory [[guessed]]]),
			   [grubdirname="$with_grubdir"],
			   [grubdirname="$PACKAGE"])

287
AC_SUBST(grubdirname)
288 289
AC_DEFINE_UNQUOTED(GRUB_DIR_NAME, "$grubdirname",
    [Default grub directory name])
290

291 292 293
#
# Checks for build programs.
#
294

295 296 297 298 299 300 301
# Although cmp is listed in the GNU Coding Standards as a command which
# can used directly, OpenBSD lacks cmp in the default installation.
AC_CHECK_PROGS([CMP], [cmp])
if test "x$CMP" = x; then
  AC_MSG_ERROR([cmp is not found])
fi

302
AC_CHECK_PROGS([YACC], [bison])
303
if test "x$YACC" = x; then
304
  AC_MSG_ERROR([bison is not found])
305 306
fi

307
AC_PROG_RANLIB
308 309
AC_PROG_INSTALL
AC_PROG_AWK
310
AC_PROG_LEX
311
AC_PROG_YACC
312
AC_PROG_MAKE_SET
313
AC_PROG_MKDIR_P
Colin Watson's avatar
Colin Watson committed
314
AC_PROG_LN_S
315

316
if test "x$LEX" = "x:"; then
317 318
  AC_MSG_ERROR([flex is not found])
else
319
  version=`$LEX --version | $AWK '{ split($2,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
320
  if test -n "$version" -a "$version" -ge 20535; then
321 322 323 324 325 326
    :
  else
    AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
  fi
fi

327
# These are not a "must".
328
AC_PATH_PROGS(MAKEINFO, makeinfo true)
okuji's avatar
okuji committed
329

330 331 332 333 334
#
# Checks for host programs.
#

AC_PROG_CC
335
gl_EARLY
336
AC_PROG_CXX
337 338 339
AM_PROG_CC_C_O
AM_PROG_AS

okuji's avatar
okuji committed
340 341 342
# Must be GCC.
test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])

343 344
AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)

345
AC_GNU_SOURCE
346
AM_GNU_GETTEXT([external])
347 348 349
AC_SYS_LARGEFILE

# Identify characteristics of the host architecture.
350 351
unset ac_cv_c_bigendian

352 353 354 355 356
if test x"$target_cpu-$platform" = xsparc64-emu ; then
  CFLAGS="$CFLAGS -m64"
  HOST_CFLAGS="$HOST_CFLAGS -m64"
fi

357 358 359
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
HOST_CPPFLAGS="$HOST_CPPFLAGS -D_FILE_OFFSET_BITS=64"

360 361 362 363
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long)

364 365 366 367 368 369 370 371
case "$host_os" in
  cygwin | windows* | mingw32*)
     HOST_CPPFLAGS="$HOST_CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
     CPPFLAGS="$CPPFLAGS -DUNICODE=1 -D_WIN32_WINNT=0x0500"
     AC_CHECK_SIZEOF(TCHAR,,[#include <windows.h>])
   ;;
esac

372 373 374 375 376 377 378 379
case "$host_os" in
  cygwin | windows* | mingw32* | aros*)
     ;;
  *)
     AC_CHECK_SIZEOF(off_t)
     test x"$ac_cv_sizeof_off_t" = x8 || AC_MSG_ERROR([Large file support is required]);;
esac

380 381 382 383
if test x$USE_NLS = xno; then
  HOST_CFLAGS="$HOST_CFLAGS -fno-builtin-gettext"
fi

384 385 386 387 388 389
if test "x$cross_compiling" = xyes; then
  AC_MSG_WARN([cannot generate manual pages while cross compiling])
else
  AC_PATH_PROG(HELP2MAN, help2man)
fi

390
# Check for functions and headers.
391
AC_CHECK_FUNCS(posix_memalign memalign getextmntent)
392
AC_CHECK_HEADERS(sys/param.h sys/mount.h sys/mnttab.h sys/mkdev.h limits.h)
393

394 395 396 397 398 399 400 401
AC_CHECK_MEMBERS([struct statfs.f_fstypename],,,[$ac_includes_default
#include <sys/param.h>
#include <sys/mount.h>])

AC_CHECK_MEMBERS([struct statfs.f_mntfromname],,,[$ac_includes_default
#include <sys/param.h>
#include <sys/mount.h>])

402 403 404 405 406 407 408 409 410 411 412 413 414 415
# For opendisk() and getrawpartition() on NetBSD.
# Used in util/deviceiter.c and in util/hostdisk.c.
AC_CHECK_HEADER([util.h], [
  AC_CHECK_LIB([util], [opendisk], [
    LIBUTIL="-lutil"
    AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
  ])
  AC_CHECK_LIB([util], [getrawpartition], [
    LIBUTIL="-lutil"
    AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
  ])
])
AC_SUBST([LIBUTIL])

416
AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_host_cc_wtrampolines], [
417
  SAVED_CFLAGS="$CFLAGS"
418
  CFLAGS="$HOST_CFLAGS -Wtrampolines -Werror"
419 420
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
int va_arg_func (int fixed, va_list args);]], [[]])],
421 422
      [grub_cv_host_cc_wtrampolines=yes],
      [grub_cv_host_cc_wtrampolines=no])
423 424 425
  CFLAGS="$SAVED_CFLAGS"
])

426 427
if test x"$grub_host_cv_cc_wtrampolines" = xyes ; then
  HOST_CFLAGS="$HOST_CFLAGS -Wtrampolines"
428 429
fi

430 431 432 433
#
# Check for host and build compilers.
#
HOST_CC=$CC
434 435
AC_CHECK_PROGS(BUILD_CC, [gcc egcs cc])
test -z "$BUILD_CC" && AC_MSG_ERROR([none of gcc, egcs and cc is found. set BUILD_CC manually.])
436
BUILD_CPP="$BUILD_CC -E"
437

438 439 440 441
case "$build_os" in
  haiku*)				BUILD_LIBM= ;;
  *) 					BUILD_LIBM=-lm ;;
esac
442 443 444 445 446 447 448 449 450 451

dnl FIXME proper test seems to require too deep dive into Autoconf internals.
dnl For now just list known platforms that we support.

case "$build_os" in
  cygwin*|mingw32*|mingw64*)		BUILD_EXEEXT=.exe ;;
  *)					BUILD_EXEEXT= ;;
esac
AC_SUBST(BUILD_EXEEXT)

452 453 454
# For gnulib.
gl_INIT

455
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"
456
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"
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474

HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS -Wcast-align"

AC_CACHE_CHECK([which extra warnings work], [grub_cv_cc_w_extra_flags], [
  SAVED_CFLAGS="$CFLAGS"
  grub_cv_cc_w_extra_flags=
  for x in $EXTRA_WARN_FLAGS; do
      CFLAGS="$HOST_CFLAGS $x -Werror"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
      if test x$flag = x1 ; then
         grub_cv_cc_w_extra_flags="$grub_cv_cc_w_extra_flags $x"
      fi
  done
  CFLAGS="$SAVED_CFLAGS"
])

HOST_CFLAGS="$HOST_CFLAGS $grub_cv_cc_w_extra_flags"

475 476 477 478
#
# Check for target programs.
#

479 480
# Find tools for the target.
if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
481 482 483 484 485
  tmp_ac_tool_prefix="$ac_tool_prefix"
  ac_tool_prefix=$target_alias-

  AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
                 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
486 487 488
  AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
  AC_CHECK_TOOL(TARGET_STRIP, strip)
  AC_CHECK_TOOL(TARGET_NM, nm)
489
  AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
490 491 492 493 494 495

  ac_tool_prefix="$tmp_ac_tool_prefix"
else
  if test "x$TARGET_CC" = x; then
    TARGET_CC=$CC
  fi
496 497 498
  AC_CHECK_TOOL(TARGET_OBJCOPY, objcopy)
  AC_CHECK_TOOL(TARGET_STRIP, strip)
  AC_CHECK_TOOL(TARGET_NM, nm)
499
  AC_CHECK_TOOL(TARGET_RANLIB, ranlib)
500
fi
501

502 503
AC_SUBST(HOST_CC)
AC_SUBST(BUILD_CC)
504 505
AC_SUBST(BUILD_CFLAGS)
AC_SUBST(BUILD_CPPFLAGS)
506
AC_SUBST(BUILD_LDFLAGS)
507
AC_SUBST(TARGET_CC)
508
AC_SUBST(TARGET_NM)
509
AC_SUBST(TARGET_RANLIB)
510 511
AC_SUBST(TARGET_STRIP)
AC_SUBST(TARGET_OBJCOPY)
512 513 514 515 516 517

# Test the C compiler for the target environment.
tmp_CC="$CC"
tmp_CFLAGS="$CFLAGS"
tmp_LDFLAGS="$LDFLAGS"
tmp_CPPFLAGS="$CPPFLAGS"
518
tmp_LIBS="$LIBS"
519 520 521 522
CC="$TARGET_CC"
CFLAGS="$TARGET_CFLAGS"
CPPFLAGS="$TARGET_CPPFLAGS"
LDFLAGS="$TARGET_LDFLAGS"
523
LIBS=""
524

525
# debug flags.
526
TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations"
527
TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g"
okuji's avatar
okuji committed
528

529 530 531 532
if test "x$target_cpu" != xi386 && test "x$target_cpu" != xx86_64; then
TARGET_CFLAGS="$TARGET_CFLAGS -Wcast-align"
fi

533 534
TARGET_CC_VERSION="$(LC_ALL=C $TARGET_CC --version | head -n1)"

535 536 537 538 539 540
AC_CACHE_CHECK([which extra warnings work], [grub_cv_target_cc_w_extra_flags], [
  LDFLAGS="$TARGET_LDFLAGS -nostdlib -static"

  grub_cv_target_cc_w_extra_flags=
  for x in $EXTRA_WARN_FLAGS; do
      CFLAGS="$TARGET_CFLAGS $x -Werror"
541 542 543 544 545 546
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
asm (".globl start; start:");
void __main (void);
void __main (void) {}
int main (void);
]], [[]])], [flag=1], [flag=0])
547 548 549 550 551 552 553 554
      if test x$flag = x1 ; then
         grub_cv_target_cc_w_extra_flags="$grub_cv_target_cc_w_extra_flags $x"
      fi
  done
])

TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_w_extra_flags"

555
AC_CACHE_CHECK([if compiling with clang], [grub_cv_cc_target_clang],
556 557 558
[
CFLAGS="$TARGET_CFLAGS"
AC_COMPILE_IFELSE(
559 560 561 562 563 564 565
[AC_LANG_PROGRAM([], [[
#ifdef __clang__
#error "is clang"
#endif
]])],
[grub_cv_cc_target_clang=no], [grub_cv_cc_target_clang=yes])])

566
if test x$target_cpu = xpowerpc -o x$target_cpu = xmips; then
567 568
  AC_CACHE_CHECK([for options to get big-endian compilation], grub_cv_target_cc_big_endian, [
    grub_cv_target_cc_big_endian=no
569 570 571
    for cand in "-target $target_cpu -Wl,-EB" "-target $target_cpu" \
		"-target $target_cpu-linux-gnu -Wl,-EB" "-target $target_cpu-linux-gnu" \
		"-EB" "-mbig-endian"; do
572 573 574 575 576 577 578 579 580
      if test x"$grub_cv_target_cc_big_endian" != xno ; then
        break
      fi
      CFLAGS="$TARGET_CFLAGS $cand -Werror"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ != __BYTE_ORDER__)
#error still little endian
#endif
asm (".globl start; start:");
581 582
asm (".globl _start; _start:");
asm (".globl __start; __start:");
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
void __main (void);
void __main (void) {}
int main (void);
]], [[]])],
		        [grub_cv_target_cc_big_endian="$cand"], [])
    done
  ])

  if test x"$grub_cv_target_cc_big_endian" = xno ; then
    AC_MSG_ERROR([could not force big-endian])
  fi

  skip_linkflags="$(echo "$grub_cv_target_cc_big_endian"|sed 's@-Wl,-EB@@')"

  TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
  TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
  TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_big_endian"
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
elif test x$target_cpu = xmipsel; then
  AC_CACHE_CHECK([for options to get little-endian compilation], grub_cv_target_cc_little_endian, [
    grub_cv_target_cc_little_endian=no
    for cand in "-target $target_cpu -Wl,-EL" "-target $target_cpu" \
		"-target $target_cpu-linux-gnu -Wl,-EL" "-target $target_cpu-linux-gnu" \
		"-EL"; do
      if test x"$grub_cv_target_cc_little_endian" != xno ; then
        break
      fi
      CFLAGS="$TARGET_CFLAGS $cand -Werror"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__ORDER_BIG_ENDIAN__ == __BYTE_ORDER__)
#error still big endian
#endif
asm (".globl start; start:");
asm (".globl _start; _start:");
asm (".globl __start; __start:");
void __main (void);
void __main (void) {}
int main (void);
]], [[]])],
		        [grub_cv_target_cc_little_endian="$cand"], [])
    done
  ])

  if test x"$grub_cv_target_cc_little_endian" = xno ; then
    AC_MSG_ERROR([could not force little-endian])
  fi

  skip_linkflags="$(echo "$grub_cv_target_cc_little_endian"|sed 's@-Wl,-EL@@')"

  TARGET_CFLAGS="$TARGET_CFLAGS $skip_linkflags"
  TARGET_CPPFLAGS="$TARGET_CPPFLAGS $skip_linkflags"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $skip_linkflags"
  TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_little_endian"
636 637
fi

638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
# GRUB code is N32-compliant but it's experimental and we would prefer to
# avoid having too much variety when it doesn't result in any real improvement.
# Moreover N64 isn't supported.
if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
  AC_CACHE_CHECK([for options to force MIPS o32 ABI], grub_cv_target_cc_mips_o32_abi, [
    grub_cv_target_cc_mips_o32_abi=no
    for arg in "" "-mabi=32" "-target $target_cpu -mabi=32" ; do
      if test x"$grub_cv_target_cc_mips_o32_abi" != xno ; then
        break
      fi
      CFLAGS="$TARGET_CFLAGS $arg -Werror"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#if !defined(_ABIO32) || !defined(_MIPS_SIM) || (_MIPS_SIM != _ABIO32)
#error not o32 ABI
#endif
asm (".globl start; start:");
asm (".globl _start; _start:");
asm (".globl __start; __start:");
void __main (void);
void __main (void) {}
int main (void);
]], [[]])],
		        [grub_cv_target_cc_mips_o32_abi="$arg"], [])
    done
  ])

  if test x"$grub_cv_target_cc_mips_o32_abi" = xno ; then
    AC_MSG_ERROR([could not force MIPS o32 ABI])
  fi

  TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mips_o32_abi"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_mips_o32_abi"
fi

672 673
AC_CACHE_CHECK([for options to compile assembly], [grub_cv_cc_target_asm_compile], [
test_program=
674 675
case "x$target_cpu-$platform" in
     xmips-* | xmipsel-*)
676 677
        test_program=mips
	;;
678 679 680 681
     xi386-pc)
       test_program=i386-pc
	;;
     xi386-* | xx86_64-*)
682 683
       test_program=i386
	;;
684
     xpowerpc-* | xsparc64-* | xarm-*)
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
        test_program=$target_cpu
	;;
esac
if test x"$test_program" = x ; then
  grub_cv_cc_target_asm_compile=
else
  found=no
  for arg in "" "-no-integrated-as"; do
    cmdline="$TARGET_CC -c -o /dev/null $TARGET_CCASFLAGS $arg $TARGET_CPPFLAGS $srcdir/asm-tests/$test_program.S"
    echo "Running $cmdline" >&AS_MESSAGE_LOG_FD
    if $cmdline >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
      grub_cv_cc_target_asm_compile="$arg"
      found=yes
      break
    fi
  done
  if test x"$found" = xno ; then
    AC_MSG_ERROR([could not compile assembly])
  fi
704
fi
705
])
706

707
TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_cc_target_asm_compile"
708

709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
if test "x$target_cpu" = xi386 && test "x$platform" != xemu; then
  TARGET_CFLAGS="$TARGET_CFLAGS -march=i386"
fi

if test "x$target_m32" = x1; then
  # Force 32-bit mode.
  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32"
  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32"
  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
  TARGET_MODULE_FORMAT="elf32"
fi

if test "x$target_m64" = x1; then
  # Force 64-bit mode.
  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64"
  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64"
  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
  TARGET_MODULE_FORMAT="elf64"
fi

if test "x$grub_cv_cc_target_clang" = xno && test "x$target_cpu" = xi386 && test "x$platform" != xemu && test "x$platform" != xefi; then
   TARGET_CFLAGS="$TARGET_CFLAGS -mrtd -mregparm=3"
fi

735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
# on mips redirect cache flushing function to non-existant one.
if test "x$target_cpu" = xmips || test "x$target_cpu" = xmipsel ; then
  AC_CACHE_CHECK([whether -mflush-func=grub_red_herring works], [grub_cv_cc_mflush_func], [
    CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring -Werror"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
        [grub_cv_cc_mflush_func=yes],
	[grub_cv_cc_mflush_func=no])
  ])

  if test "x$grub_cv_cc_mflush_func" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mflush-func=grub_red_herring"
  fi
fi


750 751 752
# Force no alignment to save space on i386.
if test "x$target_cpu" = xi386; then
  AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
753
    CFLAGS="$TARGET_CFLAGS -falign-loops=1 -Werror"
754
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
755 756
        [grub_cv_cc_falign_loop=yes],
	[grub_cv_cc_falign_loop=no])
okuji's avatar
okuji committed
757 758
  ])

759
  AC_CACHE_CHECK([whether -malign-loops works], [grub_cv_cc_malign_loop], [
760
    CFLAGS="$TARGET_CFLAGS -malign-loops=1 -Werror"
761 762 763 764 765
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
        [grub_cv_cc_malign_loop=yes],
	[grub_cv_cc_malign_loop=no])
  ])

766 767
  if test "x$grub_cv_cc_falign_loop" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
768
  elif test "x$grub_cv_cc_malign_loop" = xyes; then
769
    TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
okuji's avatar
okuji committed
770
  fi
771
fi
okuji's avatar
okuji committed
772

773 774 775 776 777 778 779 780 781 782 783
AC_CACHE_CHECK([whether -freg-struct-return works], [grub_cv_cc_freg_struct_return], [
    CFLAGS="$TARGET_CFLAGS -freg-struct-return -Werror"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
        [grub_cv_cc_freg_struct_return=yes],
	[grub_cv_cc_freg_struct_return=no])
])

if test "x$grub_cv_cc_freg_struct_return" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -freg-struct-return"
fi

784
if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$platform" != xemu; then
785 786
  # Some toolchains enable these features by default, but they need
  # registers that aren't set up properly in GRUB.
787
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow"
788
fi
789

790 791 792 793
# GRUB doesn't use float or doubles at all. Yet some toolchains may decide
# that floats are a good fit to run instead of what's written in the code.
# Given that floating point unit is disabled (if present to begin with)
# when GRUB is running which may result in various hard crashes.
794 795 796 797
if test x"$platform" != xemu ; then
  AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [
    grub_cv_target_cc_soft_float=no
    if test "x$target_cpu" = xarm64; then
798
       CFLAGS="$TARGET_CFLAGS -mgeneral-regs-only -Werror"
799
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
800
		         [grub_cv_target_cc_soft_float="-mgeneral-regs-only"], [])
801
    fi
802 803 804 805 806
    if test "x$target_cpu" = xia64; then
       CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		         [grub_cv_target_cc_soft_float="-mno-inline-float-divide -mno-inline-sqrt"], [])
    fi
807 808
    for cand in "-msoft-float -Xclang -msoft-float -Xclang -no-implicit-float" \
		"-Xclang -msoft-float -Xclang -no-implicit-float" \
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
		"-Xclang -msoft-float" "-msoft-float"; do
      if test x"$grub_cv_target_cc_soft_float" != xno ; then
        break
      fi
      CFLAGS="$TARGET_CFLAGS $cand -Werror"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		        [grub_cv_target_cc_soft_float="$cand"], [])
    done
  ])

  if test x"$grub_cv_target_cc_soft_float" = xno ; then
    AC_MSG_ERROR([could not force soft-float])
  fi

  case x"$grub_cv_target_cc_soft_float" in
824
    x*"-Xclang"*)
825 826 827 828 829 830 831
      # A trick so that clang doesn't see it on link stаge
      TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_soft_float"
      ;;
    *)
      TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_soft_float"
      ;;
  esac
832
  TARGET_CCASFLAGS="$TARGET_CCASFLAGS $grub_cv_target_cc_soft_float"
833

834
fi
835

836 837 838 839 840 841 842 843 844
if test x"$target_cpu" = xsparc64 ; then
  AC_CACHE_CHECK([for options to reserve application registers], grub_cv_target_cc_mno_app_regs, [
    grub_cv_target_cc_mno_app_regs=no
    for cand in "-mllvm -sparc-reserve-app-registers" \
		"-mno-app-regs"; do
      if test x"$grub_cv_target_cc_mno_app_regs" != xno ; then
        break
      fi
      CFLAGS="$TARGET_CFLAGS $cand -Werror"
845
      CPPFLAGS="$TARGET_CPPFLAGS"
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		        [grub_cv_target_cc_mno_app_regs="$cand"], [])
    done
  ])

  if test x"$grub_cv_target_cc_mno_app_regs" = xno ; then
    AC_MSG_ERROR([could not reserve application registers])
  fi
  if test x"$grub_cv_target_cc_mno_app_regs" = x"-mllvm -sparc-reserve-app-registers" ; then
    # A trick so that clang doesn't see it on link stаge
    TARGET_CPPFLAGS="$TARGET_CPPFLAGS $grub_cv_target_cc_mno_app_regs"
  else
    TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_mno_app_regs"
  fi

  AC_CACHE_CHECK([for no-relax options], grub_cv_target_cc_mno_relax, [
    grub_cv_target_cc_mno_relax=no
    for cand in "-mno-relax" "-Wl,--no-relax"; do
      if test x"$grub_cv_target_cc_mno_relax" != xno ; then
        break
      fi
      LDFLAGS="$TARGET_LDFLAGS $cand -nostdlib -static"
      CFLAGS="$TARGET_CFLAGS -Werror"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
	    asm (".globl start; start:");
	    void __main (void);
	    void __main (void) {}
	    int main (void);
	    ]], [[]])], [grub_cv_target_cc_mno_relax="$cand"], [])
    done
  ])
  LDFLAGS="$TARGET_LDFLAGS"
  CFLAGS="$TARGET_CFLAGS"

  if test x"$grub_cv_target_cc_mno_relax" = xno ; then
    AC_MSG_ERROR([could not find no-relax options])
  fi
  TARGET_LDFLAGS="$TARGET_LDFLAGS $grub_cv_target_cc_mno_relax"
fi

886 887 888 889 890
# By default, GCC 4.4 generates .eh_frame sections containing unwind
# information in some cases where it previously did not. GRUB doesn't need
# these and they just use up vital space. Restore the old compiler
# behaviour.
AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
891
  CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
892 893 894 895
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
      [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
      [grub_cv_cc_fno_dwarf2_cfi_asm=no])
])
896

897 898
if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
899
fi
okuji's avatar
okuji committed
900

901 902
if test x"$target_os" = xcygwin; then
  AC_CACHE_CHECK([whether option -fno-reorder-functions works], grub_cv_cc_no_reorder_functions, [
903
    CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
904 905 906 907 908 909 910 911 912 913
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_no_reorder_functions=yes],
		      [grub_cv_cc_no_reorder_functions=no])
  ])
fi

if test x"$target_os" = xcygwin && test "x$grub_cv_cc_no_reorder_functions" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-reorder-functions"
fi

914 915 916 917 918 919 920 921 922 923 924 925
AC_CACHE_CHECK([whether -mno-stack-arg-probe works], [grub_cv_cc_mno_stack_arg_probe], [
  CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
      [grub_cv_cc_mno_stack_arg_probe=yes],
      [grub_cv_cc_mno_stack_arg_probe=no])
])

if test "x$grub_cv_cc_mno_stack_arg_probe" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
fi


926 927 928 929 930
# By default, GCC 4.6 generates .eh_frame sections containing unwind
# information in some cases where it previously did not. GRUB doesn't need
# these and they just use up vital space. Restore the old compiler
# behaviour.
AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [
931
  CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
932 933 934 935 936 937 938 939 940
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
      [grub_cv_cc_fno_asynchronous_unwind_tables=yes],
      [grub_cv_cc_fno_asynchronous_unwind_tables=no])
])

if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables"
fi

941 942 943 944 945 946 947 948 949 950 951
AC_CACHE_CHECK([whether -fno-unwind-tables works], [grub_cv_cc_fno_unwind_tables], [
  CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
      [grub_cv_cc_fno_unwind_tables=yes],
      [grub_cv_cc_fno_unwind_tables=no])
])

if test "x$grub_cv_cc_fno_unwind_tables" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-unwind-tables"
fi

952

953 954
CFLAGS="$TARGET_CFLAGS"

955 956 957 958 959 960 961 962 963 964 965

if test x"$platform" = xemu ; then
  TARGET_OBJ2ELF=
  grub_cv_target_cc_link_format=
  case "$host_os" in
    *darwin* | *mac*)
       grub_cv_target_cc_link_format="-arch,${target_cpu}"
       TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
        ;;
    *windows* | *cygwin* | *mingw*)
      if test x${target_cpu} = xi386 ; then
966 967
        grub_cv_target_cc_link_format=-mi386pe
	TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
968 969
      fi
      if test x${target_cpu} = xx86_64 ; then
970 971
        grub_cv_target_cc_link_format=-mi386pep
	TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
972 973 974 975 976
      fi
      TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
      ;;
  esac
elif test x"$target_cpu" = xi386 || test x"$target_cpu" = xx86_64; then
977
  AC_CACHE_CHECK([for target linking format], [grub_cv_target_cc_link_format], [
978
    grub_cv_target_cc_link_format=unknown
979
    for format in -melf_${target_cpu} -melf_${target_cpu}_fbsd -melf_${target_cpu}_obsd -melf_${target_cpu}_haiku -mi386pe -mi386pep -arch,${target_cpu}; do
980
      if test x${target_cpu} != xi386 && test x$format = x-mi386pe; then
981 982
        continue
      fi
983
      if test x${target_cpu} != xx86_64 && test x$format = x-mi386pep; then
984 985
        continue
      fi
986 987
      CFLAGS="$TARGET_CFLAGS"
      LDFLAGS="$TARGET_LDFLAGS -Wl,$format -nostdlib -static"
988 989 990 991 992 993
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
      asm (".globl start; start:");
      asm (".globl _start; _start:");
      asm (".globl __start; __start:");
      void __main (void);
      void __main (void) {}
994
      ]], [[]])], [flag=1], [flag=0])
995 996
      if test x"$flag" = x1; then
        grub_cv_target_cc_link_format="$format"
997
	break
998 999 1000 1001 1002 1003
      fi
    done])
  if test x"$grub_cv_target_cc_link_format" = xunknown; then
    AC_MSG_ERROR([no suitable link format found])
  fi
  TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,$grub_cv_target_cc_link_format"
1004
  if test x"$grub_cv_target_cc_link_format" = x-mi386pe ; then
1005
    TARGET_OBJ2ELF='./build-grub-pe2elf$(BUILD_EXEEXT)'
1006
  fi
1007
  if test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
1008
    TARGET_OBJ2ELF='./build-grub-pep2elf$(BUILD_EXEEXT)'
1009
  fi
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
fi

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
   TARGET_APPLE_LINKER=1
   AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [objconv], [])
   if test "x$TARGET_OBJCONV" = x ; then
      AC_CHECK_PROG([TARGET_OBJCONV], [objconv], [./objconv], [], [.])
   fi
   if test "x$TARGET_OBJCONV" = x ; then
      AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
   fi
   TARGET_IMG_LDSCRIPT=
   TARGET_IMG_CFLAGS="-static"
   TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
   TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20'
   TARGET_IMG_BASE_LDOPT="-Wl,-image_base"
   TARGET_LDFLAGS_OLDMAGIC=""
1027
elif test x$grub_cv_target_cc_link_format = x-mi386pe || test x$grub_cv_target_cc_link_format = x-mi386pep ; then
1028 1029
  TARGET_APPLE_LINKER=0
  TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
1030
  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/${grub_coredir}/conf/i386-cygwin-img-ld.sc"
1031
  TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
1032
  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/${grub_coredir}/conf/i386-cygwin-img-ld.sc"
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
  TARGET_IMG_CFLAGS=
else
  TARGET_APPLE_LINKER=0
  TARGET_LDFLAGS_OLDMAGIC="-Wl,-N"
  TARGET_IMG_LDSCRIPT=
  TARGET_IMG_LDFLAGS='-Wl,-N'
  TARGET_IMG_LDFLAGS_AC='-Wl,-N'
  TARGET_IMG_BASE_LDOPT="-Wl,-Ttext"
  TARGET_IMG_CFLAGS=
fi

1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
CFLAGS="$TARGET_CFLAGS"

AC_ARG_ENABLE([efiemu],
	      [AS_HELP_STRING([--enable-efiemu],
                             [build and install the efiemu runtimes (default=guessed)])])
if test x"$enable_efiemu" = xno ; then
  efiemu_excuse="explicitly disabled"
fi

if test x"$grub_cv_target_cc_link_format" = x-mi386pe || test x"$grub_cv_target_cc_link_format" = x-mi386pep ; then
  efiemu_excuse="not available on cygwin"
fi
if test x"$target_cpu" != xi386 ; then
  efiemu_excuse="only available on i386"
fi
if test x"$platform" = xefi ; then
  efiemu_excuse="not available on efi"
fi

if test x"$efiemu_excuse" = x ; then
  AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
    CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_efiemu=yes],
		      [grub_cv_cc_efiemu=no])
  ])
  if test x$grub_cv_cc_efiemu = xno; then
     efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
  fi
fi
if test x"$efiemu_excuse" = x ; then
  AC_CACHE_CHECK([for efiemu64 linking format], [grub_cv_target_cc_efiemu64_link_format], [
    grub_cv_target_cc_efiemu64_link_format=unknown
    for format in -melf_x86_64 -melf_x86_64_fbsd -melf_x86_64_obsd -melf_x86_64_haiku -arch,x86_64; do
      CFLAGS="-m64 -nostdlib -O2 -mcmodel=large -mno-red-zone"
      LDFLAGS="-m64 -Wl,$format -nostdlib -static"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([[
      asm (".globl start; start:");
      asm (".globl _start; _start:");
      asm (".globl __start; __start:");
      void __main (void);
      void __main (void) {}
      ]], [[]])], [flag=1], [flag=0])
      if test x"$flag" = x1; then
        grub_cv_target_cc_efiemu64_link_format="$format"
	break
      fi
    done])
  if test x"$grub_cv_target_cc_efiemu64_link_format" = xunknown; then
    efiemu_excuse="no suitable link format for efiemu64 found"
  else
    EFIEMU64_LINK_FORMAT="-Wl,$grub_cv_target_cc_efiemu64_link_format"
  fi
fi
if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
  AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled ($efiemu_excuse)])
fi
if test x"$efiemu_excuse" = x ; then
enable_efiemu=yes
else
enable_efiemu=no
fi
AC_SUBST([enable_efiemu])
AC_SUBST([EFIEMU64_LINK_FORMAT])

CFLAGS="$TARGET_CFLAGS"

1112 1113 1114 1115
AC_SUBST(TARGET_LDFLAGS_OLDMAGIC)


LDFLAGS="$TARGET_LDFLAGS"
1116

1117
if test "$target_cpu" = x86_64 || test "$target_cpu" = sparc64 ; then
1118
  # Use large model to support 4G memory
1119
  AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
1120
    CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1121 1122 1123 1124
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_mcmodel=yes],
		      [grub_cv_cc_mcmodel=no])
  ])
1125
  if test "x$grub_cv_cc_mcmodel" = xyes; then
1126
    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
1127
  elif test "$target_cpu" = sparc64; then
1128
    TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=medany"
1129
  fi
1130
fi
1131

1132
if test "$target_cpu"-"$platform" = x86_64-efi; then
1133 1134
  # EFI writes to stack below %rsp, we must not use the red zone
  AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
1135
    CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1136 1137 1138 1139 1140 1141 1142 1143
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_no_red_zone=yes],
		      [grub_cv_cc_no_red_zone=no])
  ])
  if test "x$grub_cv_cc_no_red_zone" = xno; then
    AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
  fi

1144
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
1145 1146
fi

1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
if test "x$target_cpu" = xarm; then
  AC_CACHE_CHECK([whether option -mlong-calls works], grub_cv_cc_mlong_calls, [
    CFLAGS="$TARGET_CFLAGS -mlong-calls -Werror"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_mlong_calls=yes],
		      [grub_cv_cc_mlong_calls=no])
  ])
  if test "x$grub_cv_cc_mlong_calls" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mlong-calls"
  fi
1157 1158 1159 1160 1161 1162 1163 1164
  AC_CACHE_CHECK([whether option -mthumb-interwork works], grub_cv_cc_mthumb_interwork, [
    CFLAGS="$TARGET_CFLAGS -mthumb-interwork -Werror"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_mthumb_interwork=yes],
		      [grub_cv_cc_mthumb_interwork=no])
  ])
  if test "x$grub_cv_cc_mthumb_interwork" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -mthumb-interwork"
1165
  # Clang defaults to thumb interworking
1166 1167 1168
  elif test "x$grub_cv_cc_target_clang" = xno ; then
    AC_MSG_ERROR([your compiler doesn't support -mthumb-interwork])
  fi
1169 1170
fi

1171 1172 1173 1174 1175 1176 1177 1178 1179
AC_CACHE_CHECK([whether option -Qn works], grub_cv_target_cc_qn, [
  CFLAGS="$TARGET_CFLAGS -Qn -Werror"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		    [grub_cv_target_cc_qn=yes],
		    [grub_cv_target_cc_qn=no])])
if test "x$grub_cv_target_cc_qn" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -Qn"
fi

1180 1181 1182 1183
#
# Compiler features.
#

1184 1185
CFLAGS="$TARGET_CFLAGS"

1186 1187 1188 1189 1190 1191 1192 1193
# Position independent executable.
grub_CHECK_PIE
[# Need that, because some distributions ship compilers that include
# `-fPIE' in the default specs.
if [ x"$pie_possible" = xyes ]; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
fi]

1194 1195
CFLAGS="$TARGET_CFLAGS"

1196 1197
# Position independent executable.
grub_CHECK_PIC
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
[# On most platforms we don't want PIC as it only makes relocations harder
# and code less efficient. On mips we want to have one got table per module
# and reload $gp in every function.
# GCC implements it using symbol __gnu_local_gp in non-PIC as well.
# However with clang we need PIC for this reloading to happen.
# Since default varies across dictributions use either -fPIC or -fno-PIC
# explicitly.
if ( test x$target_cpu = xmips || test x$target_cpu = xmipsel ) && test "x$grub_cv_cc_target_clang" = xyes ; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fPIC"
elif [ x"$pic_possible" = xyes ]; then
   TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIC"
1209 1210
fi]

1211 1212
CFLAGS="$TARGET_CFLAGS"

1213 1214
# Smashing stack protector.
grub_CHECK_STACK_PROTECTOR
1215
# Need that, because some distributions ship compilers that include
1216
# `-fstack-protector' in the default specs.
1217 1218 1219
if test "x$ssp_possible" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
fi
1220 1221 1222

CFLAGS="$TARGET_CFLAGS"

1223 1224 1225 1226 1227 1228
grub_CHECK_STACK_ARG_PROBE
# Cygwin's GCC uses alloca() to probe the stackframe on static
# stack allocations above some threshold.
if test x"$sap_possible" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
fi
1229

1230 1231
CFLAGS="$TARGET_CFLAGS"

1232
# -mno-unaligned-access -mstrict-align
Leif Lindholm's avatar
Leif Lindholm committed
1233
if test "$target_cpu" = arm; then
1234
  AC_CACHE_CHECK([for compile options to get strict alignment], [grub_cv_target_cc_strict_align], [
1235
    grub_cv_target_cc_strict_align=
1236 1237 1238 1239 1240 1241
    for arg in -mno-unaligned-access "-Xclang -mstrict-align" -mstrict-align; do
      CFLAGS="$TARGET_CFLAGS $arg -Werror"
      LDFLAGS="$TARGET_LDFLAGS"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [flag=1], [flag=0])
      if test x"$flag" = x1; then
        grub_cv_target_cc_strict_align="$arg"
1242
	break
1243 1244 1245 1246 1247 1248
      fi
    done])

  TARGET_CFLAGS="$TARGET_CFLAGS $grub_cv_target_cc_strict_align"
  if test x"$grub_cv_target_cc_strict_align" = x"-Xclang -mstrict-align"; then
    TARGET_LDFLAGS="$TARGET_LDFLAGS -Qunused-arguments"
Leif Lindholm's avatar
Leif Lindholm committed
1249
  fi
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
  AC_CACHE_CHECK([if compiler generates unaligned accesses], [grub_cv_cc_target_emits_unaligned],
  [CFLAGS="$TARGET_CFLAGS"
   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
#ifdef __ARM_FEATURE_UNALIGNED
#error "unaligned"
#endif
     ]])],
     [grub_cv_cc_target_emits_unaligned=no], [grub_cv_cc_target_emits_unaligned=yes])])
  if test x$grub_cv_cc_target_emits_unaligned = xyes; then
    AC_MSG_ERROR([compiler generates unaligned accesses])
  fi
Leif Lindholm's avatar
Leif Lindholm committed
1261 1262
fi

1263 1264
# Set them to their new values for the tests below.
CC="$TARGET_CC"
1265 1266 1267
if test x"$platform" = xemu ; then
CFLAGS="$TARGET_CFLAGS -Wno-error"
elif test "x$TARGET_APPLE_LINKER" = x1 ; then
1268
CFLAGS="$TARGET_CFLAGS -nostdlib -static -Wno-error"
1269
else
1270
CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
1271
fi
1272
CPPFLAGS="$TARGET_CPPFLAGS"
1273

1274
grub_ASM_USCORE
1275
if test "x$TARGET_APPLE_LINKER" = x0 && test x"$platform" != xemu; then
1276
if test x$grub_cv_asm_uscore = xyes; then
1277
DEFSYM="-Wl,--defsym,_abort=_main -Wl,--defsym,__main=_main"
1278
else
1279
DEFSYM="-Wl,--defsym,abort=main -Wl,--defsym,_main=main -Wl,--defsym,__main=main"
1280
fi
1281
CFLAGS="$TARGET_CFLAGS -nostdlib $DEFSYM"
1282
fi
1283

1284
# Check for libgcc symbols
1285
if test x"$platform" = xemu; then
1286
AC_CHECK_FUNCS(__udivsi3 __umodsi3 __divsi3 __modsi3 __divdi3 __moddi3 __udivdi3 __umoddi3 __ctzdi2 __ctzsi2 __aeabi_uidiv __aeabi_uidivmod __aeabi_idiv __aeabi_idivmod __aeabi_ulcmp __muldi3 __aeabi_lmul __aeabi_memcpy __aeabi_memcpy4 __aeabi_memcpy8 __aeabi_memclr __aeabi_memclr4 __aeabi_memclr8 __aeabi_memset __aeabi_lasr __aeabi_llsl __aeabi_llsr _restgpr_14_x __ucmpdi2 __ashldi3 __ashrdi3 __lshrdi3 __bswapsi2 __bswapdi2 __bzero __register_frame_info __deregister_frame_info ___chkstk_ms __chkstk_ms)
1287
fi
1288

1289
if test "x$TARGET_APPLE_LINKER" = x1 ; then
1290
CFLAGS="$TARGET_CFLAGS -nostdlib -static"
1291
else
1292
CFLAGS="$TARGET_CFLAGS -nostdlib"
1293
fi
1294
LIBS=""
1295

okuji's avatar
okuji committed
1296
# Defined in aclocal.m4.
1297
grub_PROG_TARGET_CC
1298
if test "x$TARGET_APPLE_LINKER" != x1 ; then
1299
grub_PROG_OBJCOPY_ABSOLUTE
1300
fi
1301
grub_PROG_LD_BUILD_ID_NONE
1302
if test "x$target_cpu" = xi386; then
1303
  if test "$platform" != emu && test "x$TARGET_APPLE_LINKER" != x1 ; then
1304 1305
    if test ! -z "$TARGET_IMG_LDSCRIPT"; then
      # Check symbols provided by linker script.
1306
      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},0x8000"
1307
    fi
1308 1309 1310 1311
    grub_CHECK_BSS_START_SYMBOL
    grub_CHECK_END_SYMBOL
  fi
  CFLAGS="$TARGET_CFLAGS"
okuji's avatar
okuji committed
1312 1313
fi

1314 1315 1316 1317 1318 1319
grub_PROG_NM_WORKS
grub_PROG_NM_MINUS_P
grub_PROG_NM_DEFINED_ONLY
AC_SUBST(TARGET_NMFLAGS_MINUS_P)
AC_SUBST(TARGET_NMFLAGS_DEFINED_ONLY)

1320
if test "$platform" != emu; then
1321 1322 1323 1324
AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
  SAVED_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
1325
#include <stddef.h>
1326 1327 1328 1329 1330 1331 1332 1333 1334
int va_arg_func (int fixed, va_list args);]], [[]])],
      [grub_cv_cc_isystem=yes],
      [grub_cv_cc_isystem=no])
  CPPFLAGS="$SAVED_CPPFLAGS"
])

if test x"$grub_cv_cc_isystem" = xyes ; then
  TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
fi
1335
fi
1336

1337
AC_CACHE_CHECK([whether -Wtrampolines work], [grub_cv_cc_wtrampolines], [
1338
  CFLAGS="$TARGET_CFLAGS -Wtrampolines -Werror"
1339 1340
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
int va_arg_func (int fixed, va_list args);]], [[]])],
1341 1342
      [grub_cv_cc_wtrampolines=yes],
      [grub_cv_cc_wtrampolines=no])
1343 1344
])

1345 1346
if test x"$grub_cv_cc_wtrampolines" = xyes ; then
  TARGET_CFLAGS="$TARGET_CFLAGS -Wtrampolines"
1347 1348
fi

1349
# Restore the flags.
1350 1351 1352
CC="$tmp_CC"
CFLAGS="$tmp_CFLAGS"
CPPFLAGS="$tmp_CPPFLAGS"
1353
LDFLAGS="$tmp_LDFLAGS"
1354
LIBS="$tmp_LIBS"
okuji's avatar
okuji committed
1355

1356
#
1357
# Check for options.
1358 1359 1360
#

# Memory manager debugging.
1361
AC_ARG_ENABLE([mm-debug],
1362
	      AS_HELP_STRING([--enable-mm-debug],
1363
                             [include memory manager debugging]),
1364 1365 1366
              [AC_DEFINE([MM_DEBUG], [1],
                         [Define to 1 if you enable memory manager debugging.])])

1367 1368
AC_ARG_ENABLE([cache-stats],
	      AS_HELP_STRING([--enable-cache-stats],
1369
                             [enable disk cache statistics collection]))
1370 1371 1372 1373 1374 1375 1376 1377

if test x$enable_cache_stats = xyes; then
  DISK_CACHE_STATS=1
else
  DISK_CACHE_STATS=0
fi
AC_SUBST([DISK_CACHE_STATS])

1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
AC_ARG_ENABLE([boot-time],
	      AS_HELP_STRING([--enable-boot-time],
                             [enable boot time statistics collection]))

if test x$enable_boot_time = xyes; then
  BOOT_TIME_STATS=1
else
  BOOT_TIME_STATS=0
fi
AC_SUBST([BOOT_TIME_STATS])

Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1389 1390 1391 1392
AC_ARG_ENABLE([grub-emu-sdl],
	      [AS_HELP_STRING([--enable-grub-emu-sdl],
                             [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])

phcoder's avatar
phcoder committed
1393 1394 1395 1396
AC_ARG_ENABLE([grub-emu-pci],
	      [AS_HELP_STRING([--enable-grub-emu-pci],
                             [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])

1397 1398
if test "$platform" = emu; then

Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1399
if test x"$enable_grub_emu_sdl" = xno ; then
1400
  grub_emu_sdl_excuse="explicitly disabled"
Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1401 1402 1403 1404 1405 1406 1407
fi
[if [ x"$grub_emu_sdl_excuse" = x ]; then
    # Check for libSDL libraries.]
AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
    [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
    AC_SUBST([LIBSDL])
[fi]
1408

Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1409 1410 1411 1412 1413
[if [ x"$grub_emu_sdl_excuse" = x ]; then
    # Check for headers.]
    AC_CHECK_HEADERS([SDL/SDL.h], [],
      [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
[fi]
1414

Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1415
if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
1416
  AC_MSG_ERROR([SDL support for grub-emu was explicitly requested but can't be compiled ($grub_emu_sdl_excuse)])
Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1417 1418 1419 1420 1421 1422 1423
fi
if test x"$grub_emu_sdl_excuse" = x ; then
enable_grub_emu_sdl=yes
else
enable_grub_emu_sdl=no
fi

phcoder's avatar
phcoder committed
1424
if test x"$enable_grub_emu_pci" != xyes ; then
phcoder's avatar
phcoder committed
1425 1426 1427 1428 1429
   grub_emu_pci_excuse="not enabled"
fi

[if [ x"$grub_emu_pci_excuse" = x ]; then
      # Check for libpci libraries.]
phcoder's avatar
phcoder committed
1430 1431 1432
   AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
      [grub_emu_pci_excuse=["need libpciaccess library"]])
    AC_SUBST([LIBPCIACCESS])
phcoder's avatar
phcoder committed
1433 1434 1435
[fi]
[if [ x"$grub_emu_pci_excuse" = x ]; then
    # Check for headers.]
1436
    AC_CHECK_HEADERS([pciaccess.h], [],
phcoder's avatar
phcoder committed
1437
      [grub_emu_pci_excuse=["need libpciaccess headers"]])
phcoder's avatar
phcoder committed
1438 1439 1440 1441 1442
[fi]

if test x"$grub_emu_pci_excuse" = x ; then
enable_grub_emu_pci=yes
else
1443

phcoder's avatar
phcoder committed
1444
enable_grub_emu_pci=no
phcoder's avatar
phcoder committed
1445 1446
fi

Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1447
AC_SUBST([enable_grub_emu_sdl])
phcoder's avatar
phcoder committed
1448
AC_SUBST([enable_grub_emu_pci])
1449 1450 1451 1452 1453 1454

else

# Ignore --enable-emu-* if platform is not emu
enable_grub_emu_sdl=no
enable_grub_emu_pci=no
1455
fi
1456

1457 1458
AC_ARG_ENABLE([grub-mkfont],
	      [AS_HELP_STRING([--enable-grub-mkfont],
1459 1460
                             [build and install the `grub-mkfont' utility (default=guessed)])])
if test x"$enable_grub_mkfont" = xno ; then
1461
  grub_mkfont_excuse="explicitly disabled"
1462 1463 1464
fi

if test x"$grub_mkfont_excuse" = x ; then
1465
  # Check for freetype libraries.
1466
  AC_CHECK_TOOLS([FREETYPE], [freetype-config])
1467
  if test "x$FREETYPE" = x ; then
1468
    grub_mkfont_excuse=["need freetype2 library"]
1469 1470
  fi
fi
1471

1472 1473
unset ac_cv_header_ft2build_h

1474 1475
if test x"$grub_mkfont_excuse" = x ; then
  # Check for freetype libraries.
1476 1477
  freetype_cflags=`$FREETYPE --cflags`
  freetype_libs=`$FREETYPE --libs`
1478
  SAVED_CPPFLAGS="$CPPFLAGS"
1479
  SAVED_LIBS="$LIBS"
1480
  CPPFLAGS="$CPPFLAGS $freetype_cflags"
1481
  LIBS="$LIBS $freetype_libs"
1482 1483
  AC_CHECK_HEADERS([ft2build.h], [],
  	[grub_mkfont_excuse=["need freetype2 headers"]])
1484
  AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_mkfont_excuse=["freetype2 library unusable"]])
1485
  CPPFLAGS="$SAVED_CPPFLAGS"
1486
  LIBS="$SAVED_LIBS"
1487 1488
fi

1489
if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
1490
  AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled ($grub_mkfont_excuse)])
1491 1492 1493 1494 1495 1496
fi
if test x"$grub_mkfont_excuse" = x ; then
enable_grub_mkfont=yes
else
enable_grub_mkfont=no
fi
1497 1498 1499 1500
AC_SUBST([enable_grub_mkfont])
AC_SUBST([freetype_cflags])
AC_SUBST([freetype_libs])

1501
SAVED_CC="$CC"
1502
SAVED_CPP="$CPP"
1503 1504
SAVED_CFLAGS="$CFLAGS"
SAVED_CPPFLAGS="$CPPFLAGS"
1505
SAVED_LDFLAGS="$LDFLAGS"
1506
CC="$BUILD_CC"
1507
CPP="$BUILD_CPP"
1508
CFLAGS="$BUILD_CFLAGS"
1509
CPPFLAGS="$BUILD_CPPFLAGS"
1510
LDFLAGS="$BUILD_LDFAGS"
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525

unset ac_cv_c_bigendian
unset ac_cv_header_ft2build_h

AC_COMPUTE_INT([BUILD_SIZEOF_VOID_P], [sizeof (void *)])
AC_COMPUTE_INT([BUILD_SIZEOF_LONG], [sizeof (long)])
AC_C_BIGENDIAN([BUILD_WORDS_BIGENDIAN=1], [BUILD_WORDS_BIGENDIAN=0], [BUILD_WORDS_BIGENDIAN=err], [BUILD_WORDS_BIGENDIAN=err])

if test x$BUILD_WORDS_BIGENDIAN = xerr ; then
   AC_MSG_ERROR([couldnt determine build endianness])
fi

AC_SUBST([BUILD_SIZEOF_LONG])
AC_SUBST([BUILD_SIZEOF_VOID_P])
AC_SUBST([BUILD_WORDS_BIGENDIAN])
Dalet Omega's avatar
Dalet Omega committed
1526

1527 1528
if test x"$grub_build_mkfont_excuse" = x ; then
  # Check for freetype libraries.
1529
  AC_CHECK_PROGS([BUILD_FREETYPE], [freetype-config])
1530 1531 1532 1533
  if test "x$BUILD_FREETYPE" = x ; then
    grub_build_mkfont_excuse=["need freetype2 library"]
  fi
fi
Dalet Omega's avatar
Dalet Omega committed
1534

1535 1536 1537 1538 1539
if test x"$grub_build_mkfont_excuse" = x ; then
  # Check for freetype libraries.
  build_freetype_cflags=`$BUILD_FREETYPE --cflags`
  build_freetype_libs=`$BUILD_FREETYPE --libs`
  SAVED_CPPFLAGS_2="$CPPFLAGS"
1540
  SAVED_LIBS="$LIBS"
1541
  CPPFLAGS="$CPPFLAGS $build_freetype_cflags"
1542
  LIBS="$LIBS $build_freetype_libs"
1543 1544
  AC_CHECK_HEADERS([ft2build.h], [],
  	[grub_build_mkfont_excuse=["need freetype2 headers"]])
1545 1546
  AC_LINK_IFELSE([AC_LANG_CALL([], [FT_Load_Glyph])], [], [grub_build_mkfont_excuse=["freetype2 library unusable"]])
  LIBS="$SAVED_LIBS"
1547 1548 1549 1550
  CPPFLAGS="$SAVED_CPPFLAGS_2"
fi

if test x"$enable_build_grub_mkfont" = xyes && test x"$grub_build_mkfont_excuse" != x ; then
1551
  AC_MSG_ERROR([build-grub-mkfont was explicitly requested but can't be compiled ($grub_build_mkfont_excuse)])
1552 1553 1554 1555 1556
fi
if test x"$grub_build_mkfont_excuse" = x ; then
  enable_build_grub_mkfont=yes
else
  enable_build_grub_mkfont=no
Dalet Omega's avatar
Dalet Omega committed
1557
fi
Vladimir Serbinenko's avatar
Vladimir Serbinenko committed
1558
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
1559 1560 1561 1562 1563
  if test x"$grub_build_mkfont_excuse" = x ; then
    AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont])
  else
    AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports needs build-time grub-mkfont ($grub_build_mkfont_excuse)])
  fi
1564 1565 1566 1567 1568 1569
fi

AC_SUBST([build_freetype_cflags])
AC_SUBST([build_freetype_libs])

CC="$SAVED_CC"
1570
CPP="$SAVED_CPP"
1571 1572
CFLAGS="$SAVED_CFLAGS"
CPPFLAGS="$SAVED_CPPFLAGS"
1573
LDFLAGS="$SAVED_LDFLAGS"
1574 1575 1576 1577 1578


DJVU_FONT_SOURCE=

starfield_excuse=
Dalet Omega's avatar
Dalet Omega committed
1579

1580 1581 1582 1583 1584 1585 1586 1587
AC_ARG_ENABLE([grub-themes],
	      [AS_HELP_STRING([--enable-grub-themes],
                             [build and install GRUB themes (default=guessed)])])
if test x"$enable_grub_themes" = xno ; then
  starfield_excuse="explicitly disabled"
fi

if test x"$starfield_excuse" = x && test x"$enable_build_grub_mkfont" = xno ; then
1588 1589 1590
  starfield_excuse="No build-time grub-mkfont"
fi

1591
if test x"$starfield_excuse" = x; then
Dalet Omega's avatar
Dalet Omega committed
1592
   for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
1593
     for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/truetype/ttf-dejavu /usr/share/fonts/dejavu /usr/share/fonts/truetype; do
Dalet Omega's avatar
Dalet Omega committed
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
        if test -f "$dir/DejaVuSans.$ext"; then
          DJVU_FONT_SOURCE="$dir/DejaVuSans.$ext"
          break 2
        fi
     done
   done

   if test "x$DJVU_FONT_SOURCE" = x; then
     starfield_excuse="No DejaVu found"
   fi
fi

1606
if test x"$enable_grub_themes" = xyes &&  test x"$starfield_excuse" != x; then
1607
   AC_MSG_ERROR([themes were explicitly requested but requirements are not satisfied ($starfield_excuse)])
1608 1609
fi

Dalet Omega's avatar
Dalet Omega committed
1610 1611
AC_SUBST([DJVU_FONT_SOURCE])

1612 1613 1614 1615 1616
FONT_SOURCE=

for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
  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
    if test -f "$dir/unifont.$ext"; then
1617 1618 1619
      md5="$(md5sum "$dir/unifont.$ext"|awk '{ print $1; }')"
      # PCF and BDF from version 6.3 isn't hanled properly by libfreetype.
      if test "$md5" = 0a54834d2788c83886a3e1785a6a1e61 || test "$md5" = 28f2565c7a41d8d407e2551159385edb || test "$md5" = dae5e588461b3b92b87b6ffee734f936 || test "$md5" = 4a3d687aa5bb329ed05f4263a1016791 ; then
1620
        continue
1621
      fi
1622 1623 1624 1625 1626 1627
      FONT_SOURCE="$dir/unifont.$ext"
      break 2
    fi
  done
done

1628 1629 1630 1631
if test x"$enable_build_grub_mkfont" = xno ; then
  FONT_SOURCE=
fi

Vladimir Serbinenko's avatar
Vladimir Serbinenko committed
1632
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
1633 1634 1635 1636 1637
  if test x"$grub_build_mkfont_excuse" = x ; then
    AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont])
  else
    AC_MSG_ERROR([qemu, powerpc-ieee1275, coreboot and loongson ports need unifont ($grub_build_mkfont_excuse)])
  fi
1638 1639 1640 1641
fi

AC_SUBST([FONT_SOURCE])

1642
if test x"$FONT_SOURCE" = x &&  test x"$DJVU_FONT_SOURCE" = x && test x"$grub_build_mkfont_excuse" = x; then
1643 1644 1645 1646
  grub_build_mkfont_excuse="no fonts"
fi


1647 1648 1649 1650 1651
AC_ARG_ENABLE([grub-mount],
	      [AS_HELP_STRING([--enable-grub-mount],
                             [build and install the `grub-mount' utility (default=guessed)])])
if test x"$enable_grub_mount" = xno ; then
  grub_mount_excuse="explicitly disabled"
1652 1653
fi

1654
if test x"$grub_mount_excuse" = x ; then
1655
  AC_CHECK_LIB([fuse], [fuse_main_real], [],
1656
               [grub_mount_excuse="need FUSE library"])
1657 1658
fi

1659
if test x"$grub_mount_excuse" = x ; then
1660 1661
  # Check for fuse headers.
  SAVED_CPPFLAGS="$CPPFLAGS"
1662
  CPPFLAGS="$CPPFLAGS -DFUSE_USE_VERSION=26"
1663
  AC_CHECK_HEADERS([fuse/fuse.h], [],
1664
  	[grub_mount_excuse=["need FUSE headers"]])
1665 1666 1667
  CPPFLAGS="$SAVED_CPPFLAGS"
fi

1668
if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then
1669
  AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled ($grub_mount_excuse)])
1670
fi
1671 1672
if test x"$grub_mount_excuse" = x ; then
enable_grub_mount=yes
1673
else
1674
enable_grub_mount=no
1675
fi
1676
AC_SUBST([enable_grub_mount])
1677

1678 1679 1680 1681 1682 1683 1684
AC_ARG_ENABLE([device-mapper],
              [AS_HELP_STRING([--enable-device-mapper],
                              [enable Linux device-mapper support (default=guessed)])])
if test x"$enable_device_mapper" = xno ; then
  device_mapper_excuse="explicitly disabled"
fi

1685 1686 1687 1688 1689 1690
if test x"$device_mapper_excuse" = x ; then
  # Check for device-mapper header.
  AC_CHECK_HEADER([libdevmapper.h], [],
               [device_mapper_excuse="need libdevmapper header"])
fi

1691 1692
if test x"$device_mapper_excuse" = x ; then
  # Check for device-mapper library.
1693
  AC_CHECK_LIB([devmapper], [dm_task_create], [],
1694 1695
               [device_mapper_excuse="need devmapper library"])
fi
1696 1697 1698 1699 1700 1701 1702 1703 1704

if test x"$device_mapper_excuse" = x ; then
  # Check for device-mapper library.
  AC_CHECK_LIB([devmapper], [dm_log_with_errno_init],
               [],
               [device_mapper_excuse="need devmapper library"])
fi

if test x"$device_mapper_excuse" = x ; then
1705
   LIBDEVMAPPER="-ldevmapper"
1706 1707 1708 1709
   AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
             [Define to 1 if you have the devmapper library.])
fi

BVK Chaitanya's avatar
BVK Chaitanya committed
1710
AC_SUBST([LIBDEVMAPPER])
1711

1712 1713 1714 1715 1716 1717 1718 1719 1720
LIBGEOM=
if test x$host_kernel = xkfreebsd; then
  AC_CHECK_LIB([geom], [geom_gettree], [],
               [AC_MSG_ERROR([Your platform requires libgeom])])
  LIBGEOM="-lgeom"
fi

AC_SUBST([LIBGEOM])

1721 1722 1723 1724 1725 1726 1727 1728
AC_ARG_ENABLE([liblzma],
              [AS_HELP_STRING([--enable-liblzma],
                              [enable liblzma integration (default=guessed)])])
if test x"$enable_liblzma" = xno ; then
  liblzma_excuse="explicitly disabled"
fi

if test x"$liblzma_excuse" = x ; then
1729
AC_CHECK_LIB([lzma], [lzma_code],
1730 1731 1732 1733 1734 1735 1736
             [],[liblzma_excuse="need lzma library"])
fi
if test x"$liblzma_excuse" = x ; then
AC_CHECK_HEADER([lzma.h], [], [liblzma_excuse="need lzma header"])
fi

if test x"$enable_liblzma" = xyes && test x"$liblzma_excuse" != x ; then
1737
  AC_MSG_ERROR([liblzma support was explicitly requested but requirements are not satisfied ($liblzma_excuse)])
1738 1739 1740 1741 1742 1743 1744 1745 1746
fi


if test x"$liblzma_excuse" = x ; then
   LIBLZMA="-llzma"
   AC_DEFINE([USE_LIBLZMA], [1],
   	     [Define to 1 if you have the LZMA library.])
fi

1747 1748
AC_SUBST([LIBLZMA])

1749 1750 1751 1752 1753 1754
AC_ARG_ENABLE([libzfs],
              [AS_HELP_STRING([--enable-libzfs],
                              [enable libzfs integration (default=guessed)])])
if test x"$enable_libzfs" = xno ; then
  libzfs_excuse="explicitly disabled"
fi
BVK Chaitanya's avatar
BVK Chaitanya committed
1755

1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
if test x"$libzfs_excuse" = x ; then
  # Only check for system headers if libzfs support has not been disabled.
  AC_CHECK_HEADERS(libzfs.h libnvpair.h)
fi

if test x"$libzfs_excuse" = x ; then
  AC_CHECK_LIB([zfs], [libzfs_init],
               [],
               [libzfs_excuse="need zfs library"])
fi

if test x"$libzfs_excuse" = x ; then
1768
  AC_CHECK_LIB([nvpair], [nvlist_lookup_string],
1769 1770 1771 1772 1773
               [],
               [libzfs_excuse="need nvpair library"])
fi

if test x"$enable_libzfs" = xyes && test x"$libzfs_excuse" != x ; then
1774
  AC_MSG_ERROR([libzfs support was explicitly requested but requirements are not satisfied ($libzfs_excuse)])
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
fi

if test x"$libzfs_excuse" = x ; then
  # We need both libzfs and libnvpair for a successful build.
  LIBZFS="-lzfs"
  AC_DEFINE([HAVE_LIBZFS], [1],
            [Define to 1 if you have the ZFS library.])
  LIBNVPAIR="-lnvpair"
  AC_DEFINE([HAVE_LIBNVPAIR], [1],
            [Define to 1 if you have the NVPAIR library.])
fi

AC_SUBST([LIBZFS])
BVK Chaitanya's avatar
BVK Chaitanya committed
1788 1789
AC_SUBST([LIBNVPAIR])

1790 1791
LIBS=""

1792 1793 1794
AC_SUBST([FONT_SOURCE])
AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
	    [AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
1795

1796 1797 1798 1799 1800 1801
AC_SUBST(HAVE_ASM_USCORE)
AC_SUBST(BSS_START_SYMBOL)
AC_SUBST(END_SYMBOL)
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)

1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812
AC_ARG_ENABLE([werror],
	      [AS_HELP_STRING([--disable-werror],
                             [do not use -Werror when building GRUB])])
if test x"$enable_werror" != xno ; then
  TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
  HOST_CFLAGS="$HOST_CFLAGS -Werror"
fi

TARGET_CPP="$TARGET_CC -E"
TARGET_CCAS=$TARGET_CC

1813 1814 1815 1816 1817 1818
# Includes which include make-time substitutions. They must come last
# as to avoid executing top_builddir in shell.
HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"

1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
GRUB_TARGET_CPU="${target_cpu}"
GRUB_PLATFORM="${platform}"

AC_SUBST(GRUB_TARGET_CPU)
AC_SUBST(GRUB_PLATFORM)

AC_SUBST(TARGET_OBJCONV)
AC_SUBST(TARGET_CPP)
AC_SUBST(TARGET_CCAS)
AC_SUBST(TARGET_OBJ2ELF)
AC_SUBST(TARGET_MODULE_FORMAT)
1830
AC_SUBST(TARGET_CC_VERSION)
1831 1832 1833 1834 1835 1836 1837 1838 1839

AC_SUBST(TARGET_CFLAGS)
AC_SUBST(TARGET_LDFLAGS)
AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_CCASFLAGS)

AC_SUBST(TARGET_IMG_LDFLAGS)
AC_SUBST(TARGET_IMG_CFLAGS)
AC_SUBST(TARGET_IMG_BASE_LDOPT)
1840
AC_SUBST(TARGET_APPLE_LINKER)
1841 1842 1843 1844 1845 1846 1847 1848

AC_SUBST(HOST_CFLAGS)
AC_SUBST(HOST_LDFLAGS)
AC_SUBST(HOST_CPPFLAGS)
AC_SUBST(HOST_CCASFLAGS)

AC_SUBST(BUILD_LIBM)

1849 1850 1851
#
# Automake conditionals
#
1852

1853
AM_CONDITIONAL([COND_real_platform], [test x$platform != xnone])
1854 1855 1856
AM_CONDITIONAL([COND_emu], [test x$platform = xemu])
AM_CONDITIONAL([COND_i386_pc], [test x$target_cpu = xi386 -a x$platform = xpc])
AM_CONDITIONAL([COND_i386_efi], [test x$target_cpu = xi386 -a x$platform = xefi])
1857
AM_CONDITIONAL([COND_ia64_efi], [test x$target_cpu = xia64 -a x$platform = xefi])
1858 1859 1860 1861 1862
AM_CONDITIONAL([COND_i386_qemu], [test x$target_cpu = xi386 -a x$platform = xqemu])
AM_CONDITIONAL([COND_i386_ieee1275], [test x$target_cpu = xi386 -a x$platform = xieee1275])
AM_CONDITIONAL([COND_i386_coreboot], [test x$target_cpu = xi386 -a x$platform = xcoreboot])
AM_CONDITIONAL([COND_i386_multiboot], [test x$target_cpu = xi386 -a x$platform = xmultiboot])
AM_CONDITIONAL([COND_x86_64_efi], [test x$target_cpu = xx86_64 -a x$platform = xefi])
1863 1864
AM_CONDITIONAL([COND_i386_xen], [test x$target_cpu = xi386 -a x$platform = xxen])
AM_CONDITIONAL([COND_x86_64_xen], [test x$target_cpu = xx86_64 -a x$platform = xxen])
1865 1866
AM_CONDITIONAL([COND_mips_loongson], [test x$target_cpu = xmipsel -a x$platform = xloongson])
AM_CONDITIONAL([COND_mips_qemu_mips], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xqemu_mips])
1867
AM_CONDITIONAL([COND_mips_arc], [test "(" x$target_cpu = xmips -o x$target_cpu = xmipsel ")"  -a x$platform = xarc])
1868
AM_CONDITIONAL([COND_sparc64_ieee1275], [test x$target_cpu = xsparc64 -a x$platform = xieee1275])
1869
AM_CONDITIONAL([COND_sparc64_emu], [test x$target_cpu = xsparc64 -a x$platform = xemu])
1870
AM_CONDITIONAL([COND_powerpc_ieee1275], [test x$target_cpu = xpowerpc -a x$platform = xieee1275])
1871
AM_CONDITIONAL([COND_mips], [test x$target_cpu = xmips -o x$target_cpu = xmipsel])
1872 1873
AM_CONDITIONAL([COND_mipsel], [test x$target_cpu = xmipsel])
AM_CONDITIONAL([COND_mipseb], [test x$target_cpu = xmips])
1874 1875
AM_CONDITIONAL([COND_arm], [test x$target_cpu = xarm ])
AM_CONDITIONAL([COND_arm_uboot], [test x$target_cpu = xarm -a x$platform = xuboot])
1876
AM_CONDITIONAL([COND_arm_coreboot], [test x$target_cpu = xarm -a x$platform = xcoreboot])
1877
AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
1878 1879
AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])
BVK Chaitanya's avatar
BVK Chaitanya committed
1880

1881 1882 1883
AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
BVK Chaitanya's avatar
BVK Chaitanya committed
1884
AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
1885 1886 1887
AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])
BVK Chaitanya's avatar
BVK Chaitanya committed
1888

1889 1890 1891 1892
AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
1893
AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
1894
AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
1895 1896 1897 1898 1899 1900
if test x$FONT_SOURCE != x ; then
   HAVE_FONT_SOURCE=1
else
   HAVE_FONT_SOURCE=0
fi
AC_SUBST(HAVE_FONT_SOURCE)
1901
AM_CONDITIONAL([COND_APPLE_LINKER], [test x$TARGET_APPLE_LINKER = x1])
1902
AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])
1903
AM_CONDITIONAL([COND_ENABLE_CACHE_STATS], [test x$DISK_CACHE_STATS = x1])
1904
AM_CONDITIONAL([COND_ENABLE_BOOT_TIME_STATS], [test x$BOOT_TIME_STATS = x1])
1905

1906 1907
AM_CONDITIONAL([COND_HAVE_CXX], [test x$HAVE_CXX = xyes])

1908
AM_CONDITIONAL([COND_HAVE_ASM_USCORE], [test x$HAVE_ASM_USCORE = x1])
Dalet Omega's avatar
Dalet Omega committed
1909
AM_CONDITIONAL([COND_STARFIELD], [test "x$starfield_excuse" = x])
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
AM_CONDITIONAL([COND_HAVE_EXEC], [test "x$have_exec" = xy])

test "x$prefix" = xNONE && prefix="$ac_default_prefix"
test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
datarootdir="$(eval echo "$datarootdir")"
grub_libdir="$(eval echo "$libdir")"
grub_localedir="$(eval echo "$localedir")"
grub_datadir="$(eval echo "$datadir")"
grub_sysconfdir="$(eval echo "$sysconfdir")"
AC_DEFINE_UNQUOTED(LOCALEDIR, "$grub_localedir", [Locale dir])
AC_DEFINE_UNQUOTED(GRUB_LIBDIR, "$grub_libdir", [Library dir])
AC_DEFINE_UNQUOTED(GRUB_DATADIR, "$grub_datadir", [Data dir])
AC_DEFINE_UNQUOTED(GRUB_SYSCONFDIR, "$grub_sysconfdir", [Configuration dir])

1924

okuji's avatar
okuji committed
1925
# Output files.
1926 1927 1928 1929
if test "$platform" != none; then
  cpudir="${target_cpu}"
  if test x${cpudir} = xmipsel; then
    cpudir=mips;
1930
  fi
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
  grub_CHECK_LINK_DIR
  if test x"$link_dir" = xyes ; then
    AC_CONFIG_LINKS([include/grub/cpu:include/grub/$cpudir])
    if test "$platform" != emu ; then
      AC_CONFIG_LINKS([include/grub/machine:include/grub/$cpudir/$platform])
    fi
  else
    mkdir -p include/grub 2>/dev/null
    rm -rf include/grub/cpu
    cp -rp $srcdir/include/grub/$cpudir include/grub/cpu 2>/dev/null
    if test "$platform" != emu ; then
      rm -rf include/grub/machine
      cp -rp $srcdir/include/grub/$cpudir/$platform include/grub/machine 2>/dev/null
    fi
1945
  fi
1946 1947 1948
else
  # Just enough to stop the compiler failing with -I$(srcdir)/include.
  mkdir -p include 2>/dev/null
1949
  rm -rf include/grub/cpu include/grub/machine
1950
fi
1951

1952
AC_CONFIG_FILES([Makefile])
1953
AC_CONFIG_FILES([grub-core/Makefile])
1954
AC_CONFIG_FILES([grub-core/gnulib/Makefile])
1955
AC_CONFIG_FILES([po/Makefile.in])
1956
AC_CONFIG_FILES([docs/Makefile])
1957
AC_CONFIG_FILES([util/bash-completion.d/Makefile])
okuji's avatar
okuji committed
1958
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
1959
AC_CONFIG_FILES([config.h])
1960

okuji's avatar
okuji committed
1961
AC_OUTPUT
1962 1963 1964 1965
[
echo "*******************************************************"
echo GRUB2 will be compiled with following components:
echo Platform: "$target_cpu"-"$platform"
1966
if [ x"$platform" = xemu ]; then
Vladimir 'phcoder' Serbinenko's avatar
Vladimir 'phcoder' Serbinenko committed
1967 1968 1969 1970 1971
if [ x"$grub_emu_sdl_excuse" = x ]; then
echo SDL support for grub-emu: Yes
else
echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
fi
phcoder's avatar
phcoder committed
1972 1973 1974 1975 1976
if [ x"$grub_emu_pci_excuse" = x ]; then
echo PCI support for grub-emu: Yes
else
echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
fi
1977
fi
1978 1979 1980 1981 1982
if test x"$device_mapper_excuse" = x ; then
echo With devmapper support: Yes
else
echo With devmapper support: No "($device_mapper_excuse)"
fi
1983 1984 1985 1986 1987
if [ x"$enable_mm_debug" = xyes ]; then
echo With memory debugging: Yes
else
echo With memory debugging: No
fi
1988 1989 1990 1991 1992
if [ x"$enable_cache_stats" = xyes ]; then
echo With disk cache statistics: Yes
else
echo With disk cache statistics: No
fi
1993 1994 1995 1996 1997 1998 1999

if [ x"$enable_boot_time" = xyes ]; then
echo With boot time statistics: Yes
else
echo With boot time statistics: No
fi

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
if [ x"$efiemu_excuse" = x ]; then
echo efiemu runtime: Yes
else
echo efiemu runtime: No "($efiemu_excuse)"
fi
if [ x"$grub_mkfont_excuse" = x ]; then
echo grub-mkfont: Yes
else
echo grub-mkfont: No "($grub_mkfont_excuse)"
fi
2010
if [ x"$grub_mount_excuse" = x ]; then
2011
echo grub-mount: Yes
2012
else
2013
echo grub-mount: No "($grub_mount_excuse)"
2014
fi
Dalet Omega's avatar
Dalet Omega committed
2015 2016
if [ x"$starfield_excuse" = x ]; then
echo starfield theme: Yes
2017
echo With DejaVuSans font from $DJVU_FONT_SOURCE
Dalet Omega's avatar
Dalet Omega committed
2018 2019 2020
else
echo starfield theme: No "($starfield_excuse)"
fi
2021 2022 2023 2024 2025
if [ x"$libzfs_excuse" = x ]; then
echo With libzfs support: Yes
else
echo With libzfs support: No "($libzfs_excuse)"
fi
2026
if [ x"$grub_build_mkfont_excuse" = x ]; then
2027 2028 2029 2030 2031 2032
  echo Build-time grub-mkfont: Yes
  if test "x$FONT_SOURCE" = x ; then
    echo "Without unifont"
  else
    echo "With unifont from $FONT_SOURCE"
  fi
2033
else
2034
  echo Build-time grub-mkfont: No "($grub_build_mkfont_excuse)"
2035
  echo "Without unifont (no build-time grub-mkfont)"
2036
fi
2037 2038
if test x"$liblzma_excuse" != x ; then
echo "Without liblzma (no support for XZ-compressed mips images) ($liblzma_excuse)"
2039 2040 2041
else
echo "With liblzma from $LIBLZMA (support for XZ-compressed mips images)"
fi
2042 2043
echo "*******************************************************"
]