]> git.proxmox.com Git - grub2.git/blame - configure.ac
Close #600580
[grub2.git] / configure.ac
CommitLineData
6a161fa9 1# Process this file with autoconf to produce a configure script.
2
2f1a3acf 3# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
6a161fa9 4#
5# This configure.ac is free software; the author
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
11# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12# PARTICULAR PURPOSE.
13
b977bf01 14dnl This configure script is complicated, because GRUB needs to deal
15dnl with three potentially different types:
16dnl
17dnl build -- the environment for building GRUB
18dnl host -- the environment for running utilities
19dnl target -- the environment for running GRUB
20dnl
21dnl In addition, GRUB needs to deal with a platform specification
22dnl which specifies the system running GRUB, such as firmware.
23dnl This is necessary because the target type in autoconf does not
24dnl describe such a system very well.
25dnl
26dnl The current strategy is to use variables with no prefix (such as
27dnl CC, CFLAGS, etc.) for the host type as well as the build type,
28dnl because GRUB does not need to use those variables for the build
29dnl type, so there is no conflict. Variables with the prefix "TARGET_"
30dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
31dnl type.
32
33
216951b0 34AC_INIT([GRUB],[0],[bug-grub@gnu.org]) dnl version is filled by debian/rules
fc22844e 35AM_INIT_AUTOMAKE()
f022876b 36AC_PREREQ(2.60)
4b13b216 37AC_CONFIG_SRCDIR([include/grub/dl.h])
6a161fa9 38AC_CONFIG_HEADER([config.h])
39
b977bf01 40# Checks for host and target systems.
6a161fa9 41AC_CANONICAL_HOST
b977bf01 42AC_CANONICAL_TARGET
6a161fa9 43
1d543c3e 44# Program name transformations
45AC_ARG_PROGRAM
46
90d1e879
RM
47# Optimization flag. Allow user to override.
48if test "x$TARGET_CFLAGS" = x; then
49 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
50fi
51
b977bf01 52case "$target_cpu" in
02164e1b 53 i[[3456]]86) target_cpu=i386 ;;
c7ef54aa 54 amd64) target_cpu=x86_64 ;;
02164e1b 55 sparc) target_cpu=sparc64 ;;
ade85305 56 mipsel|mips64el)
4a1eefb6 57 target_cpu=mips;
58 TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPSEL=1";
59 CFLAGS="$CFLAGS -DGRUB_CPU_MIPSEL=1";
60 ;;
ade85305 61 mips|mips64)
4a1eefb6 62 target_cpu=mips;
63 TARGET_CFLAGS="$TARGET_CFLAGS -DGRUB_CPU_MIPS=1";
64 CFLAGS="$CFLAGS -DGRUB_CPU_MIPS=1";
65 ;;
6a161fa9 66esac
67
05568c2e 68# Specify the platform (such as firmware).
69AC_ARG_WITH([platform],
70 AS_HELP_STRING([--with-platform=PLATFORM],
83b984de 71 [select the host platform [[guessed]]]))
05568c2e 72
73# Guess the platform if not specified.
74if test "x$with_platform" = x; then
b977bf01 75 case "$target_cpu"-"$target_vendor" in
05568c2e 76 i386-apple) platform=efi ;;
77 i386-*) platform=pc ;;
58393a2d 78 x86_64-apple) platform=efi ;;
737feb35 79 x86_64-*) platform=pc ;;
05568c2e 80 powerpc-*) platform=ieee1275 ;;
58393a2d 81 powerpc64-*) platform=ieee1275 ;;
05568c2e 82 sparc64-*) platform=ieee1275 ;;
ad17a401 83 mips-*) platform=yeeloong ;;
58393a2d 84 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
05568c2e 85 esac
86else
87 platform="$with_platform"
88fi
89
58393a2d 90# Adjust CPU unless target was explicitly specified.
91if test -z "$target_alias"; then
92 case "$target_cpu"-"$platform" in
93 x86_64-efi) ;;
909301af 94 x86_64-emu) ;;
3f4ce737 95 x86_64-*) target_cpu=i386 ;;
96 powerpc64-ieee1275) target_cpu=powerpc ;;
20011694 97 esac
98fi
99
58393a2d 100# Check if the platform is supported, make final adjustments.
b977bf01 101case "$target_cpu"-"$platform" in
05568c2e 102 i386-efi) ;;
3f4ce737 103 x86_64-efi) ;;
05568c2e 104 i386-pc) ;;
7210dca9 105 i386-multiboot) ;;
546f966a 106 i386-coreboot) ;;
58393a2d 107 i386-linuxbios) platform=coreboot ;;
3d04eab8 108 i386-ieee1275) ;;
8231fb77 109 i386-qemu) ;;
05568c2e 110 powerpc-ieee1275) ;;
111 sparc64-ieee1275) ;;
7b5f334b 112 mips-qemu-mips) ;;
ad17a401 113 mips-yeeloong) ;;
f84b481b 114 *-emu) ;;
58393a2d 115 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
6a161fa9 116esac
117
3f4ce737 118case "$target_cpu" in
119 i386 | powerpc) target_m32=1 ;;
120 x86_64 | sparc64) target_m64=1 ;;
121esac
122
6e5a42fe 123case "$host_os" in
4825d790 124 mingw32*) host_os=cygwin ;;
6e5a42fe 125esac
126
9304eef1 127# This normalizes the names, and creates a new variable ("host_kernel")
128# while at it, since the mapping is not always 1:1 (e.g. different OSes
129# using the same kernel type).
130case "$host_os" in
131 gnu*) host_kernel=hurd ;;
132 linux*) host_kernel=linux ;;
67937d4d 133 freebsd* | kfreebsd*-gnu) host_kernel=kfreebsd ;;
2c7031b1 134 netbsd*) host_kernel=netbsd ;;
9304eef1 135 cygwin) host_kernel=windows ;;
136esac
137
f84b481b
RM
138case "$platform" in
139 coreboot) machine_CFLAGS="-DGRUB_MACHINE_COREBOOT=1" ;;
7210dca9 140 multiboot) machine_CFLAGS="-DGRUB_MACHINE_MULTIBOOT=1" ;;
f84b481b
RM
141 efi) machine_CFLAGS="-DGRUB_MACHINE_EFI=1" ;;
142 ieee1275) machine_CFLAGS="-DGRUB_MACHINE_IEEE1275=1" ;;
143 qemu) machine_CFLAGS="-DGRUB_MACHINE_QEMU=1" ;;
144 pc) machine_CFLAGS="-DGRUB_MACHINE_PCBIOS=1" ;;
145 emu) machine_CFLAGS="-DGRUB_MACHINE_EMU=1" ;;
6bea3f89
VS
146 yeeloong) machine_CFLAGS="-DGRUB_MACHINE_MIPS_YEELOONG=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
147 qemu-mips) machine_CFLAGS="-DGRUB_MACHINE_MIPS_QEMU_MIPS=1 -DGRUB_MACHINE_MIPS_BONITO=1" ;;
f84b481b 148esac
6bea3f89
VS
149case "$target_cpu" in
150 mips) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_MIPS=1" ;;
151 sparc64) machine_CFLAGS="$machine_CFLAGS -DGRUB_MACHINE_SPARC64=1" ;;
152esac
94ac7906 153machine_CFLAGS="$machine_CFLAGS -DMACHINE=`echo ${target_cpu}_$platform | sed y,abcdefghijklmnopqrstuvwxyz,ABCDEFGHIJKLMNOPQRSTUVWXYZ,`"
6bea3f89 154
f84b481b 155CFLAGS="$CFLAGS $machine_CFLAGS"
f616f51c 156TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS"
f84b481b
RM
157TARGET_CFLAGS="$TARGET_CFLAGS $machine_CFLAGS"
158
56978920 159AC_SUBST(host_cpu)
160AC_SUBST(host_os)
9304eef1 161AC_SUBST(host_kernel)
6e5a42fe 162
b977bf01 163AC_SUBST(target_cpu)
05568c2e 164AC_SUBST(platform)
6a161fa9 165
b977bf01 166#
167# Checks for build programs.
168#
144f1f98 169
6c826348 170# Although cmp is listed in the GNU Coding Standards as a command which
171# can used directly, OpenBSD lacks cmp in the default installation.
172AC_CHECK_PROGS([CMP], [cmp])
173if test "x$CMP" = x; then
174 AC_MSG_ERROR([cmp is not found])
175fi
176
144f1f98 177AC_CHECK_PROGS([YACC], [bison])
1569ec51 178if test "x$YACC" = x; then
6c826348 179 AC_MSG_ERROR([bison is not found])
1569ec51 180fi
181
4d88b9ae
VS
182FONT_SOURCE=
183
f4d095d7
GS
184for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
185 for dir in . /usr/src /usr/share/fonts/X11/misc /usr/share/fonts/unifont; do
186 if test -f "$dir/unifont.$ext"; then
8e50ec9f 187 FONT_SOURCE="$dir/unifont.$ext"
f4d095d7
GS
188 break 2
189 fi
190 done
4931827f 191done
192
57ebd41e 193if test "x$FONT_SOURCE" = x && ( test "x$platform" = xqemu || test "x$platform" = xyeeloong ); then
4d88b9ae
VS
194 AC_MSG_ERROR([qemu and yeeloong ports need unifont])
195fi
196
8e50ec9f
VS
197AC_SUBST([FONT_SOURCE])
198
b977bf01 199AC_PROG_INSTALL
200AC_PROG_AWK
09220190 201AC_PROG_LEX
b977bf01 202AC_PROG_MAKE_SET
ff420223 203AC_PROG_MKDIR_P
b977bf01 204
c7c75cf4 205if test "x$LEX" = "x:"; then
09220190
BC
206 AC_MSG_ERROR([flex is not found])
207else
2663fb5f 208 version=`$LEX --version | $AWK '{ split($NF,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
b777c18e 209 if test -n "$version" -a "$version" -ge 20535; then
09220190
BC
210 :
211 else
212 AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
213 fi
214fi
215
68807e5f 216# These are not a "must".
b977bf01 217AC_PATH_PROG(RUBY, ruby)
c44c90db 218AC_PATH_PROG(MAKEINFO, makeinfo)
6a161fa9 219
b977bf01 220#
221# Checks for host programs.
222#
223
224AC_PROG_CC
6a161fa9 225# Must be GCC.
226test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
227
4889bdec 228AC_GNU_SOURCE
2f1a3acf 229AM_GNU_GETTEXT([external])
b977bf01 230AC_SYS_LARGEFILE
231
232# Identify characteristics of the host architecture.
233AC_C_BIGENDIAN
234AC_CHECK_SIZEOF(void *)
235AC_CHECK_SIZEOF(long)
236
2b167a72 237grub_apple_cc
c9da87d0 238if test x$grub_cv_apple_cc = xyes ; then
2b167a72 239 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
240 ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
241fi
b977bf01 242
86695375 243if test "x$cross_compiling" = xyes; then
244 AC_MSG_WARN([cannot generate manual pages while cross compiling])
245else
246 AC_PATH_PROG(HELP2MAN, help2man)
247fi
248
3169f4c7 249# Check for functions and headers.
62858144 250AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf getfsstat getmntany)
3169f4c7 251AC_CHECK_HEADERS(libzfs.h libnvpair.h)
7c4e16ff 252
2c7031b1
GS
253# For opendisk() and getrawpartition() on NetBSD.
254# Used in util/deviceiter.c and in util/hostdisk.c.
255AC_CHECK_HEADER([util.h], [
256 AC_CHECK_LIB([util], [opendisk], [
257 LIBUTIL="-lutil"
258 AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
259 ])
260 AC_CHECK_LIB([util], [getrawpartition], [
261 LIBUTIL="-lutil"
262 AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
263 ])
264])
265AC_SUBST([LIBUTIL])
266
b977bf01 267#
268# Check for target programs.
269#
270
5b5d4aa5 271# Find tools for the target.
272if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
b977bf01 273 tmp_ac_tool_prefix="$ac_tool_prefix"
274 ac_tool_prefix=$target_alias-
275
276 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
277 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
278 AC_CHECK_TOOL(OBJCOPY, objcopy)
279 AC_CHECK_TOOL(STRIP, strip)
280 AC_CHECK_TOOL(NM, nm)
281
282 ac_tool_prefix="$tmp_ac_tool_prefix"
283else
284 if test "x$TARGET_CC" = x; then
285 TARGET_CC=$CC
286 fi
287 AC_CHECK_TOOL(OBJCOPY, objcopy)
288 AC_CHECK_TOOL(STRIP, strip)
289 AC_CHECK_TOOL(NM, nm)
290fi
291AC_SUBST(TARGET_CC)
292
293
294# Test the C compiler for the target environment.
295tmp_CC="$CC"
296tmp_CFLAGS="$CFLAGS"
297tmp_LDFLAGS="$LDFLAGS"
298tmp_CPPFLAGS="$CPPFLAGS"
aa6d7826 299tmp_LIBS="$LIBS"
b977bf01 300CC="$TARGET_CC"
301CFLAGS="$TARGET_CFLAGS"
302CPPFLAGS="$TARGET_CPPFLAGS"
303LDFLAGS="$TARGET_LDFLAGS"
aa6d7826 304LIBS=""
b977bf01 305
90d1e879
RM
306# debug flags.
307TARGET_CFLAGS="$TARGET_CFLAGS -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
308 -Wundef -Wstrict-prototypes -g"
6a161fa9 309
90d1e879
RM
310# Force no alignment to save space on i386.
311if test "x$target_cpu" = xi386; then
312 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
313 CFLAGS="$CFLAGS -falign-loops=1"
eb73121d 314 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
90d1e879
RM
315 [grub_cv_cc_falign_loop=yes],
316 [grub_cv_cc_falign_loop=no])
6a161fa9 317 ])
6a161fa9 318
90d1e879
RM
319 if test "x$grub_cv_cc_falign_loop" = xyes; then
320 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
321 else
322 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 323 fi
77c55a87 324
90d1e879
RM
325 # Some toolchains enable these features by default, but they need
326 # registers that aren't set up properly in GRUB.
327 TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow"
328fi
77c55a87 329
90d1e879
RM
330# By default, GCC 4.4 generates .eh_frame sections containing unwind
331# information in some cases where it previously did not. GRUB doesn't need
332# these and they just use up vital space. Restore the old compiler
333# behaviour.
334AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
335 SAVE_CFLAGS="$CFLAGS"
336 CFLAGS="$CFLAGS -fno-dwarf2-cfi-asm"
337 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
338 [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
339 [grub_cv_cc_fno_dwarf2_cfi_asm=no])
340 CFLAGS="$SAVE_CFLAGS"
341])
342
343if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
344 TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
b977bf01 345fi
6a161fa9 346
2b167a72 347grub_apple_target_cc
c9da87d0 348if test x$grub_cv_apple_target_cc = xyes ; then
2b167a72 349 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
350 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
351 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
352 TARGET_APPLE_CC=1
cf00df31 353 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
354 if test "x$OBJCONV" = x ; then
355 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
356 fi
357 if test "x$OBJCONV" = x ; then
358 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
359 fi
2b167a72 360 TARGET_IMG_LDSCRIPT=
361 TARGET_IMG_CFLAGS="-static"
362 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
363 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
364else
365 TARGET_APPLE_CC=0
366# Use linker script if present, otherwise use builtin -N script.
2b167a72 367if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
368 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
369 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
38e55e90 370 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc -Wl,-Ttext,"
2b167a72 371else
372 TARGET_IMG_LDSCRIPT=
373 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
374 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
375fi
376TARGET_IMG_CFLAGS=
377fi
378
379AC_SUBST(TARGET_IMG_LDSCRIPT)
380AC_SUBST(TARGET_IMG_LDFLAGS)
381AC_SUBST(TARGET_IMG_CFLAGS)
2b167a72 382
383# For platforms where ELF is not the default link format.
384AC_MSG_CHECKING([for command to convert module to ELF format])
385case "${host_os}" in
4b0cd8f8
VS
386 cygwin) TARGET_OBJ2ELF='grub-pe2elf';
387# FIXME: put proper test here
388 AC_DEFINE([NEED_REGISTER_FRAME_INFO], 1,
389 [Define to 1 if GCC generates calls to __register_frame_info()])
390 ;;
2b167a72 391 *) ;;
392esac
393AC_SUBST(TARGET_OBJ2ELF)
394AC_MSG_RESULT([$TARGET_OBJ2ELF])
395
396
b977bf01 397if test "x$target_m32" = x1; then
398 # Force 32-bit mode.
399 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
5c2ee771 400 TARGET_ASFLAGS="$TARGET_CFLAGS -m32"
b977bf01 401 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
2b167a72 402 TARGET_MODULE_FORMAT="elf32"
6a161fa9 403fi
b977bf01 404
20011694 405if test "x$target_m64" = x1; then
406 # Force 64-bit mode.
7e9ca17a 407 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
5c2ee771 408 TARGET_ASFLAGS="$TARGET_ASFLAGS -m64"
7e9ca17a 409 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
2b167a72 410 TARGET_MODULE_FORMAT="elf64"
7e9ca17a 411fi
412
413if test "$target_cpu"-"$platform" = x86_64-efi; then
414 # Use large model to support 4G memory
6e09b8b7 415 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
c8600122 416 SAVED_CFLAGS=$CFLAGS
417 CFLAGS="$CFLAGS -m64 -mcmodel=large"
6e09b8b7 418 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
419 [grub_cv_cc_mcmodel=yes],
420 [grub_cv_cc_mcmodel=no])
421 ])
c8600122 422 if test "x$grub_cv_cc_mcmodel" = xno; then
4ba8d354 423 AC_MSG_ERROR([-mcmodel=large not supported. Upgrade your gcc.])
c8600122 424 else
425 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
6e09b8b7 426 fi
7e9ca17a 427
428 # EFI writes to stack below %rsp, we must not use the red zone
429 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
c8600122 430 CFLAGS="$CFLAGS -m64 -mno-red-zone"
7e9ca17a 431 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
432 [grub_cv_cc_no_red_zone=yes],
433 [grub_cv_cc_no_red_zone=no])
434 ])
435 if test "x$grub_cv_cc_no_red_zone" = xno; then
436 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
437 fi
438
c8600122 439 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
20011694 440fi
441
baa2a121 442#
443# Compiler features.
444#
445
9035dce4 446# Need __enable_execute_stack() for nested function trampolines?
447grub_CHECK_ENABLE_EXECUTE_STACK
448
93a81088 449# Position independent executable.
450grub_CHECK_PIE
451[# Need that, because some distributions ship compilers that include
452# `-fPIE' in the default specs.
453if [ x"$pie_possible" = xyes ]; then
454 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
455fi]
456
baa2a121 457# Smashing stack protector.
458grub_CHECK_STACK_PROTECTOR
c3db8364 459# Need that, because some distributions ship compilers that include
baa2a121 460# `-fstack-protector' in the default specs.
c3db8364 461if test "x$ssp_possible" = xyes; then
462 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
463fi
2a8a80e4 464grub_CHECK_STACK_ARG_PROBE
465# Cygwin's GCC uses alloca() to probe the stackframe on static
466# stack allocations above some threshold.
467if test x"$sap_possible" = xyes; then
468 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
469fi
baa2a121 470
63f745e8 471AC_ARG_ENABLE([werror],
472 [AS_HELP_STRING([--disable-werror],
473 [do not use -Werror when building GRUB])])
474if test x"$enable_werror" != xno ; then
475 TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
476fi
477
b977bf01 478AC_SUBST(TARGET_CFLAGS)
2b167a72 479AC_SUBST(TARGET_MODULE_FORMAT)
cf00df31 480AC_SUBST(OBJCONV)
2b167a72 481AC_SUBST(TARGET_APPLE_CC)
482AC_SUBST(TARGET_ASFLAGS)
b977bf01 483AC_SUBST(TARGET_CPPFLAGS)
484AC_SUBST(TARGET_LDFLAGS)
6a161fa9 485
aa6d7826 486# Set them to their new values for the tests below.
487CC="$TARGET_CC"
26de2bcd 488if test "x$TARGET_APPLE_CC" = x1 ; then
69be5b74 489CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
26de2bcd 490else
01fcf061 491CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wno-error"
26de2bcd 492fi
aa6d7826 493CPPFLAGS="$TARGET_CPPFLAGS"
494LDFLAGS="$TARGET_LDFLAGS"
69be5b74
VS
495LIBS=-lgcc
496
01fcf061
VS
497grub_ASM_USCORE
498if test x$grub_cv_asm_uscore = xyes; then
499CFLAGS="$CFLAGS -Wl,--defsym,_abort=_main"
500else
501CFLAGS="$CFLAGS -Wl,--defsym,abort=main"
502fi
503
69be5b74
VS
504# Check for libgcc symbols
505AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x)
506
507if test "x$TARGET_APPLE_CC" = x1 ; then
508CFLAGS="$TARGET_CFLAGS -nostdlib"
509else
510CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
511fi
42e0cba3 512LIBS=""
aa6d7826 513
6a161fa9 514# Defined in aclocal.m4.
f6130a12 515grub_PROG_TARGET_CC
2b167a72 516if test "x$TARGET_APPLE_CC" != x1 ; then
b977bf01 517grub_PROG_OBJCOPY_ABSOLUTE
2b167a72 518fi
cb71ba20 519grub_PROG_LD_BUILD_ID_NONE
b977bf01 520if test "x$target_cpu" = xi386; then
2aec1692
CF
521 if test "$platform" != emu && test "x$TARGET_APPLE_CC" != x1 ; then
522 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
523 # Check symbols provided by linker script.
524 CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC}8000 -Wl,--defsym,___main=0x8100"
525 fi
2a8a80e4 526 grub_CHECK_BSS_START_SYMBOL
527 grub_CHECK_END_SYMBOL
528 fi
529 CFLAGS="$TARGET_CFLAGS"
4b13b216 530 grub_I386_ASM_PREFIX_REQUIREMENT
531 grub_I386_ASM_ADDR32
532 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
5aded270 533else
f4917dfd 534 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
6a161fa9 535fi
536
bf6a5fb2 537AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
538#define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
539#else
540#define NESTED_FUNC_ATTR
541#endif])
542
5ce5507f 543AC_ARG_ENABLE([efiemu],
544 [AS_HELP_STRING([--enable-efiemu],
545 [build and install the efiemu runtimes (default=guessed)])])
546if test x"$enable_efiemu" = xno ; then
ce7a733d 547 efiemu_excuse="explicitly disabled"
5ce5507f 548fi
549if test x"$efiemu_excuse" = x ; then
43e6200c 550 AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
d2838156 551 CFLAGS="$CFLAGS -m64 -mcmodel=large -mno-red-zone -nostdlib"
5ce5507f 552 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
553 [grub_cv_cc_efiemu=yes],
554 [grub_cv_cc_efiemu=no])
555 ])
55c70904 556 if test x$grub_cv_cc_efiemu = xno; then
e98cd0c2 557 efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
5ce5507f 558 fi
559fi
560if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
ce7a733d 561 AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled])
5ce5507f 562fi
563if test x"$efiemu_excuse" = x ; then
564enable_efiemu=yes
565else
566enable_efiemu=no
567fi
568AC_SUBST([enable_efiemu])
569
016a671b 570if test "$platform" != emu; then
8f9a632b
VS
571AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
572 SAVED_CPPFLAGS="$CPPFLAGS"
573 CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
574 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
575int va_arg_func (int fixed, va_list args);]], [[]])],
576 [grub_cv_cc_isystem=yes],
577 [grub_cv_cc_isystem=no])
578 CPPFLAGS="$SAVED_CPPFLAGS"
579])
580
581if test x"$grub_cv_cc_isystem" = xyes ; then
582 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
583fi
dae79b6b 584fi
5ce5507f 585
c9a86192 586# Restore the flags.
9962ed99 587CC="$tmp_CC"
588CFLAGS="$tmp_CFLAGS"
589CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 590LDFLAGS="$tmp_LDFLAGS"
aa6d7826 591LIBS="$tmp_LIBS"
6a161fa9 592
4fe9862e 593#
2965c7cc 594# Check for options.
4fe9862e 595#
596
597# Memory manager debugging.
b39f9d20 598AC_ARG_ENABLE([mm-debug],
2965c7cc 599 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 600 [include memory manager debugging]),
2965c7cc 601 [AC_DEFINE([MM_DEBUG], [1],
602 [Define to 1 if you enable memory manager debugging.])])
603
d64399b5 604AC_ARG_ENABLE([grub-emu-usb],
605 [AS_HELP_STRING([--enable-grub-emu-usb],
5ce5507f 606 [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
5ce5507f 607
927d0134
VS
608AC_ARG_ENABLE([grub-emu-sdl],
609 [AS_HELP_STRING([--enable-grub-emu-sdl],
610 [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
611
3affd0ec 612AC_ARG_ENABLE([grub-emu-pci],
613 [AS_HELP_STRING([--enable-grub-emu-pci],
614 [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
615
f38873b8
VS
616AC_ARG_ENABLE([grub-emu-modules],
617 [AS_HELP_STRING([--enable-grub-emu-modules],
618 [Support module loading in `grub-emu' debugging utility (default=no)])])
619
f84b481b
RM
620if test "$platform" = emu; then
621 missing_ncurses=
622[# Check for curses libraries.]
4fe9862e 623 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
624 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
f84b481b 625 [missing_ncurses=[true]])])
4fe9862e 626 AC_SUBST([LIBCURSES])
f84b481b 627[if [ x"$missing_ncurses" = x ]; then ]
4fe9862e 628 [# Check for headers.]
629 AC_CHECK_HEADERS([ncurses/curses.h], [],
630 [AC_CHECK_HEADERS([ncurses.h], [],
631 [AC_CHECK_HEADERS([curses.h], [],
f84b481b 632 [missing_ncurses=[true]])])])
5ce5507f 633[fi]
f84b481b
RM
634if test x"$missing_ncurses" = xtrue ; then
635 AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
5ce5507f 636fi
f84b481b 637
f38873b8
VS
638if test x"$enable_grub_emu_modules" = xyes ; then
639 TARGET_NO_MODULES=no
640else
641 TARGET_NO_MODULES=yes
642fi
643AC_SUBST(TARGET_NO_MODULES)
644
2aec1692
CF
645if test "$TARGET_NO_MODULES" = yes ; then
646 # Do not convert modules, otherwise linkage may fail (Cygwin only).
647 # FIXME: Should be checked above before TARGET_OBJ2ELF is set first.
648 TARGET_OBJ2ELF=
649fi
650
5ce5507f 651if test x"$enable_grub_emu_usb" = xno ; then
ce7a733d 652 grub_emu_usb_excuse="explicitly disabled"
5ce5507f 653fi
325c8258 654
0e848909
VS
655if test x"$enable_grub_emu_pci" = xyes ; then
656 grub_emu_usb_excuse="conflicts with PCI support"
657fi
658
5ce5507f 659[if [ x"$grub_emu_usb_excuse" = x ]; then
d64399b5 660 # Check for libusb libraries.]
5ce5507f 661AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
e98cd0c2 662 [grub_emu_usb_excuse=["need libusb library"]])
d64399b5 663 AC_SUBST([LIBUSB])
5ce5507f 664[fi]
665[if [ x"$grub_emu_usb_excuse" = x ]; then
666 # Check for headers.]
d64399b5 667 AC_CHECK_HEADERS([usb.h], [],
e98cd0c2 668 [grub_emu_usb_excuse=["need libusb headers"]])
4fe9862e 669[fi]
c6f3b249 670if test x"$enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then
ce7a733d 671 AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled])
5ce5507f 672fi
673if test x"$grub_emu_usb_excuse" = x ; then
674enable_grub_emu_usb=yes
675else
676enable_grub_emu_usb=no
677fi
678
927d0134
VS
679if test x"$enable_grub_emu_sdl" = xno ; then
680 grub_emu_sdl_excuse="explicitely disabled"
681fi
682[if [ x"$grub_emu_sdl_excuse" = x ]; then
683 # Check for libSDL libraries.]
684AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
685 [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
686 AC_SUBST([LIBSDL])
687[fi]
9f293ab0 688
927d0134
VS
689[if [ x"$grub_emu_sdl_excuse" = x ]; then
690 # Check for headers.]
691 AC_CHECK_HEADERS([SDL/SDL.h], [],
692 [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
693[fi]
9f293ab0 694
927d0134
VS
695if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
696 AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
697fi
698if test x"$grub_emu_sdl_excuse" = x ; then
699enable_grub_emu_sdl=yes
700else
701enable_grub_emu_sdl=no
702fi
703
3affd0ec 704if test x"$enable_grub_emu_pci" != xyes ; then
325c8258 705 grub_emu_pci_excuse="not enabled"
706fi
707
708if test x"$enable_grub_emu_usb" = xyes ; then
709 grub_emu_pci_excuse="conflicts with USB support"
710fi
711
712[if [ x"$grub_emu_pci_excuse" = x ]; then
713 # Check for libpci libraries.]
459fed4b 714 AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
715 [grub_emu_pci_excuse=["need libpciaccess library"]])
716 AC_SUBST([LIBPCIACCESS])
325c8258 717[fi]
718[if [ x"$grub_emu_pci_excuse" = x ]; then
719 # Check for headers.]
720 AC_CHECK_HEADERS([pci/pci.h], [],
459fed4b 721 [grub_emu_pci_excuse=["need libpciaccess headers"]])
325c8258 722[fi]
723
724if test x"$grub_emu_pci_excuse" = x ; then
725enable_grub_emu_pci=yes
726else
9f293ab0 727
325c8258 728enable_grub_emu_pci=no
3affd0ec 729fi
730
927d0134 731AC_SUBST([enable_grub_emu_sdl])
d64399b5 732AC_SUBST([enable_grub_emu_usb])
3affd0ec 733AC_SUBST([enable_grub_emu_pci])
f84b481b 734fi
4fe9862e 735
99fadbaa 736AC_ARG_ENABLE([grub-fstest],
737 [AS_HELP_STRING([--enable-grub-fstest],
5ce5507f 738 [build and install the `grub-fstest' debugging utility (default=guessed)])])
739if test x"$enable_grub_fstest" = xno ; then
ce7a733d 740 grub_fstest_excuse="explicitly disabled"
5ce5507f 741fi
742if test x"$grub_fstest_excuse" = x ; then
743enable_grub_fstest=yes
744else
745enable_grub_fstest=no
746fi
99fadbaa 747AC_SUBST([enable_grub_fstest])
748
e52db1f7 749AC_ARG_ENABLE([grub-mkfont],
750 [AS_HELP_STRING([--enable-grub-mkfont],
5ce5507f 751 [build and install the `grub-mkfont' utility (default=guessed)])])
752if test x"$enable_grub_mkfont" = xno ; then
ce7a733d 753 grub_mkfont_excuse="explicitly disabled"
5ce5507f 754fi
755
756if test x"$grub_mkfont_excuse" = x ; then
e52db1f7 757 # Check for freetype libraries.
758 AC_CHECK_PROGS([FREETYPE], [freetype-config])
759 if test "x$FREETYPE" = x ; then
e98cd0c2 760 grub_mkfont_excuse=["need freetype2 library"]
e52db1f7 761 fi
762 freetype_cflags=`freetype-config --cflags`
763 freetype_libs=`freetype-config --libs`
764fi
660960d6
VS
765
766if test x"$grub_mkfont_excuse" = x ; then
767 # Check for freetype libraries.
d1e8a02f
VS
768 SAVED_CPPFLAGS="$CPPFLAGS"
769 CPPFLAGS="$CPPFLAGS $freetype_cflags"
660960d6
VS
770 AC_CHECK_HEADERS([ft2build.h], [],
771 [grub_mkfont_excuse=["need freetype2 headers"]])
d1e8a02f 772 CPPFLAGS="$SAVED_CPPFLAGS"
660960d6
VS
773fi
774
5ce5507f 775if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
ce7a733d 776 AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
5ce5507f 777fi
778if test x"$grub_mkfont_excuse" = x ; then
779enable_grub_mkfont=yes
780else
781enable_grub_mkfont=no
782fi
e52db1f7 783AC_SUBST([enable_grub_mkfont])
784AC_SUBST([freetype_cflags])
785AC_SUBST([freetype_libs])
786
7181e228
CW
787AC_ARG_ENABLE([device-mapper],
788 [AS_HELP_STRING([--enable-device-mapper],
789 [enable Linux device-mapper support (default=guessed)])])
790if test x"$enable_device_mapper" = xno ; then
791 device_mapper_excuse="explicitly disabled"
792fi
793
794if test x"$device_mapper_excuse" = x ; then
795 # Check for device-mapper library.
796 AC_CHECK_LIB([devmapper], [dm_task_create],
797 [LDFLAGS="$LDFLAGS -ldevmapper"
798 AC_DEFINE([HAVE_DEVICE_MAPPER], [1],
799 [Define to 1 if you have the devmapper library.])],
800 [device_mapper_excuse="need devmapper library"])
7181e228
CW
801fi
802
a184f9c8
RM
803AC_CHECK_LIB([zfs], [libzfs_init],
804 [LDFLAGS="$LDFLAGS -lzfs"
805 AC_DEFINE([HAVE_LIBZFS], [1],
806 [Define to 1 if you have the ZFS library.])],)
807AC_CHECK_LIB([nvpair], [nvlist_print],
808 [LDFLAGS="$LDFLAGS -lnvpair"
809 AC_DEFINE([HAVE_LIBNVPAIR], [1],
810 [Define to 1 if you have the NVPAIR library.])],)
811
2b167a72 812AC_SUBST(ASFLAGS)
fc45fb58 813
6a161fa9 814# Output files.
1f4147aa 815grub_CHECK_LINK_DIR
816if test x"$link_dir" = xyes ; then
f84b481b
RM
817 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu])
818 if test "$platform" != emu ; then
819 AC_CONFIG_LINKS([include/grub/machine:include/grub/$target_cpu/$platform])
820 fi
1f4147aa 821else
822 mkdir -p include/grub 2>/dev/null
823 rm -rf include/grub/cpu
824 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
f84b481b
RM
825 if test "$platform" != emu ; then
826 rm -rf include/grub/machine
827 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
828 fi
1f4147aa 829fi
7b455f4d 830AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
6a161fa9 831AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
832AC_OUTPUT
5ce5507f 833[
834echo "*******************************************************"
835echo GRUB2 will be compiled with following components:
836echo Platform: "$target_cpu"-"$platform"
f84b481b 837if [ x"$platform" = xemu ]; then
5ce5507f 838if [ x"$grub_emu_usb_excuse" = x ]; then
839echo USB support for grub-emu: Yes
840else
841echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
842fi
927d0134
VS
843if [ x"$grub_emu_sdl_excuse" = x ]; then
844echo SDL support for grub-emu: Yes
845else
846echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
847fi
325c8258 848if [ x"$grub_emu_pci_excuse" = x ]; then
849echo PCI support for grub-emu: Yes
850else
851echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
852fi
f38873b8
VS
853if [ x"$TARGET_NO_MODULES" = xno ]; then
854echo Module support for grub-emu: Yes
855else
856echo Module support for grub-emu: No
857fi
f84b481b 858fi
5ce5507f 859if [ x"$enable_mm_debug" = xyes ]; then
860echo With memory debugging: Yes
861else
862echo With memory debugging: No
863fi
5ce5507f 864if [ x"$efiemu_excuse" = x ]; then
865echo efiemu runtime: Yes
866else
867echo efiemu runtime: No "($efiemu_excuse)"
868fi
869if [ x"$grub_fstest_excuse" = x ]; then
870echo grub-fstest: Yes
871else
872echo grub-fstest: No "($grub_fstest_excuse)"
873fi
874if [ x"$grub_mkfont_excuse" = x ]; then
875echo grub-mkfont: Yes
876else
877echo grub-mkfont: No "($grub_mkfont_excuse)"
878fi
879echo "*******************************************************"
880]