]> git.proxmox.com Git - grub2.git/blame - configure.ac
Don't read outside of VGA screen
[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
5519963b 34AC_INIT([GRUB],[1.98],[bug-grub@gnu.org])
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
153
f84b481b 154CFLAGS="$CFLAGS $machine_CFLAGS"
f616f51c 155TARGET_ASFLAGS="$TARGET_ASFLAGS $machine_CFLAGS"
f84b481b
RM
156TARGET_CFLAGS="$TARGET_CFLAGS $machine_CFLAGS"
157
56978920 158AC_SUBST(host_cpu)
159AC_SUBST(host_os)
9304eef1 160AC_SUBST(host_kernel)
6e5a42fe 161
b977bf01 162AC_SUBST(target_cpu)
05568c2e 163AC_SUBST(platform)
6a161fa9 164
b977bf01 165#
166# Checks for build programs.
167#
144f1f98 168
6c826348 169# Although cmp is listed in the GNU Coding Standards as a command which
170# can used directly, OpenBSD lacks cmp in the default installation.
171AC_CHECK_PROGS([CMP], [cmp])
172if test "x$CMP" = x; then
173 AC_MSG_ERROR([cmp is not found])
174fi
175
144f1f98 176AC_CHECK_PROGS([YACC], [bison])
1569ec51 177if test "x$YACC" = x; then
6c826348 178 AC_MSG_ERROR([bison is not found])
1569ec51 179fi
180
4d88b9ae
VS
181FONT_SOURCE=
182
02cf98ca 183for file in /usr/src/unifont.bdf /usr/share/fonts/X11/misc/unifont.pcf.gz /usr/share/fonts/unifont/unifont.pcf.gz; do
4931827f 184 if test -e $file ; then
4d88b9ae 185 FONT_SOURCE=$file
6c09890c 186 AC_SUBST([FONT_SOURCE], [$file])
4931827f 187 break
188 fi
189done
190
4d88b9ae
VS
191if test "x$FONT_SOURCE" == x && ( test "x$platform" = xqemu || test "x$platform" = xyeeloong ); then
192 AC_MSG_ERROR([qemu and yeeloong ports need unifont])
193fi
194
b977bf01 195AC_PROG_INSTALL
196AC_PROG_AWK
09220190 197AC_PROG_LEX
b977bf01 198AC_PROG_MAKE_SET
ff420223 199AC_PROG_MKDIR_P
b977bf01 200
09220190
BC
201if test "x$LEX" = x; then
202 AC_MSG_ERROR([flex is not found])
203else
2663fb5f 204 version=`$LEX --version | $AWK '{ split($NF,x,"."); print x[[1]]*10000+x[[2]]*100+x[[3]]; }'`
b777c18e 205 if test -n "$version" -a "$version" -ge 20535; then
09220190
BC
206 :
207 else
208 AC_MSG_ERROR([flex is too old. GRUB requires 2.5.35 or above])
209 fi
210fi
211
68807e5f 212# These are not a "must".
b977bf01 213AC_PATH_PROG(RUBY, ruby)
c44c90db 214AC_PATH_PROG(MAKEINFO, makeinfo)
6a161fa9 215
b977bf01 216#
217# Checks for host programs.
218#
219
220AC_PROG_CC
6a161fa9 221# Must be GCC.
222test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
223
4889bdec 224AC_GNU_SOURCE
2f1a3acf 225AM_GNU_GETTEXT([external])
b977bf01 226AC_SYS_LARGEFILE
227
228# Identify characteristics of the host architecture.
229AC_C_BIGENDIAN
230AC_CHECK_SIZEOF(void *)
231AC_CHECK_SIZEOF(long)
232
2b167a72 233grub_apple_cc
c9da87d0 234if test x$grub_cv_apple_cc = xyes ; then
2b167a72 235 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
236 ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
237fi
b977bf01 238
86695375 239if test "x$cross_compiling" = xyes; then
240 AC_MSG_WARN([cannot generate manual pages while cross compiling])
241else
242 AC_PATH_PROG(HELP2MAN, help2man)
243fi
244
4889bdec 245# Check for functions.
d6ceebf1 246AC_CHECK_FUNCS(posix_memalign memalign asprintf vasprintf)
4889bdec 247
7c4e16ff
RM
248# For grub-mkisofs
249AC_HEADER_MAJOR
250AC_HEADER_DIRENT
4825d790 251AC_CHECK_FUNCS(memmove sbrk strdup lstat getuid getgid)
7c4e16ff 252AC_CHECK_HEADERS(sys/mkdev.h sys/sysmacros.h malloc.h termios.h sys/types.h)
ea4a7e35 253AC_CHECK_HEADERS(unistd.h string.h strings.h sys/stat.h sys/fcntl.h limits.h)
7c4e16ff 254
2c7031b1
GS
255# For opendisk() and getrawpartition() on NetBSD.
256# Used in util/deviceiter.c and in util/hostdisk.c.
257AC_CHECK_HEADER([util.h], [
258 AC_CHECK_LIB([util], [opendisk], [
259 LIBUTIL="-lutil"
260 AC_DEFINE(HAVE_OPENDISK, 1, [Define if opendisk() in -lutil can be used])
261 ])
262 AC_CHECK_LIB([util], [getrawpartition], [
263 LIBUTIL="-lutil"
264 AC_DEFINE(HAVE_GETRAWPARTITION, 1, [Define if getrawpartition() in -lutil can be used])
265 ])
266])
267AC_SUBST([LIBUTIL])
268
b977bf01 269#
270# Check for target programs.
271#
272
5b5d4aa5 273# Find tools for the target.
274if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
b977bf01 275 tmp_ac_tool_prefix="$ac_tool_prefix"
276 ac_tool_prefix=$target_alias-
277
278 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
279 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
280 AC_CHECK_TOOL(OBJCOPY, objcopy)
281 AC_CHECK_TOOL(STRIP, strip)
282 AC_CHECK_TOOL(NM, nm)
283
284 ac_tool_prefix="$tmp_ac_tool_prefix"
285else
286 if test "x$TARGET_CC" = x; then
287 TARGET_CC=$CC
288 fi
289 AC_CHECK_TOOL(OBJCOPY, objcopy)
290 AC_CHECK_TOOL(STRIP, strip)
291 AC_CHECK_TOOL(NM, nm)
292fi
293AC_SUBST(TARGET_CC)
294
295
296# Test the C compiler for the target environment.
297tmp_CC="$CC"
298tmp_CFLAGS="$CFLAGS"
299tmp_LDFLAGS="$LDFLAGS"
300tmp_CPPFLAGS="$CPPFLAGS"
aa6d7826 301tmp_LIBS="$LIBS"
b977bf01 302CC="$TARGET_CC"
303CFLAGS="$TARGET_CFLAGS"
304CPPFLAGS="$TARGET_CPPFLAGS"
305LDFLAGS="$TARGET_LDFLAGS"
aa6d7826 306LIBS=""
b977bf01 307
90d1e879
RM
308# debug flags.
309TARGET_CFLAGS="$TARGET_CFLAGS -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
310 -Wundef -Wstrict-prototypes -g"
6a161fa9 311
90d1e879
RM
312# Force no alignment to save space on i386.
313if test "x$target_cpu" = xi386; then
314 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
315 CFLAGS="$CFLAGS -falign-loops=1"
eb73121d 316 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
90d1e879
RM
317 [grub_cv_cc_falign_loop=yes],
318 [grub_cv_cc_falign_loop=no])
6a161fa9 319 ])
6a161fa9 320
90d1e879
RM
321 if test "x$grub_cv_cc_falign_loop" = xyes; then
322 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
6a161fa9 323 else
90d1e879 324 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 325 fi
326
90d1e879
RM
327 # Some toolchains enable these features by default, but they need
328 # registers that aren't set up properly in GRUB.
329 TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-3dnow"
330fi
77c55a87 331
90d1e879
RM
332# By default, GCC 4.4 generates .eh_frame sections containing unwind
333# information in some cases where it previously did not. GRUB doesn't need
334# these and they just use up vital space. Restore the old compiler
335# behaviour.
336AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
337 SAVE_CFLAGS="$CFLAGS"
338 CFLAGS="$CFLAGS -fno-dwarf2-cfi-asm"
339 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
340 [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
341 [grub_cv_cc_fno_dwarf2_cfi_asm=no])
342 CFLAGS="$SAVE_CFLAGS"
343])
77c55a87 344
90d1e879
RM
345if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
346 TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
b977bf01 347fi
6a161fa9 348
2b167a72 349grub_apple_target_cc
c9da87d0 350if test x$grub_cv_apple_target_cc = xyes ; then
2b167a72 351 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
352 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
353 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
354 TARGET_APPLE_CC=1
cf00df31 355 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
356 if test "x$OBJCONV" = x ; then
357 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
358 fi
359 if test "x$OBJCONV" = x ; then
360 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
361 fi
2b167a72 362 TARGET_IMG_LDSCRIPT=
363 TARGET_IMG_CFLAGS="-static"
364 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
365 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
366else
367 TARGET_APPLE_CC=0
368# Use linker script if present, otherwise use builtin -N script.
2b167a72 369if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
370 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
371 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
38e55e90 372 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc -Wl,-Ttext,"
2b167a72 373else
374 TARGET_IMG_LDSCRIPT=
375 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
376 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
377fi
378TARGET_IMG_CFLAGS=
379fi
380
381AC_SUBST(TARGET_IMG_LDSCRIPT)
382AC_SUBST(TARGET_IMG_LDFLAGS)
383AC_SUBST(TARGET_IMG_CFLAGS)
2b167a72 384
385# For platforms where ELF is not the default link format.
386AC_MSG_CHECKING([for command to convert module to ELF format])
387case "${host_os}" in
4b0cd8f8
VS
388 cygwin) TARGET_OBJ2ELF='grub-pe2elf';
389# FIXME: put proper test here
390 AC_DEFINE([NEED_REGISTER_FRAME_INFO], 1,
391 [Define to 1 if GCC generates calls to __register_frame_info()])
392 ;;
2b167a72 393 *) ;;
394esac
395AC_SUBST(TARGET_OBJ2ELF)
396AC_MSG_RESULT([$TARGET_OBJ2ELF])
397
398
b977bf01 399if test "x$target_m32" = x1; then
400 # Force 32-bit mode.
401 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
5c2ee771 402 TARGET_ASFLAGS="$TARGET_CFLAGS -m32"
b977bf01 403 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
2b167a72 404 TARGET_MODULE_FORMAT="elf32"
6a161fa9 405fi
b977bf01 406
20011694 407if test "x$target_m64" = x1; then
408 # Force 64-bit mode.
7e9ca17a 409 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
5c2ee771 410 TARGET_ASFLAGS="$TARGET_ASFLAGS -m64"
7e9ca17a 411 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
2b167a72 412 TARGET_MODULE_FORMAT="elf64"
7e9ca17a 413fi
414
415if test "$target_cpu"-"$platform" = x86_64-efi; then
416 # Use large model to support 4G memory
6e09b8b7 417 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
c8600122 418 SAVED_CFLAGS=$CFLAGS
419 CFLAGS="$CFLAGS -m64 -mcmodel=large"
6e09b8b7 420 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
421 [grub_cv_cc_mcmodel=yes],
422 [grub_cv_cc_mcmodel=no])
423 ])
c8600122 424 if test "x$grub_cv_cc_mcmodel" = xno; then
4ba8d354 425 AC_MSG_ERROR([-mcmodel=large not supported. Upgrade your gcc.])
c8600122 426 else
427 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
6e09b8b7 428 fi
7e9ca17a 429
430 # EFI writes to stack below %rsp, we must not use the red zone
431 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
c8600122 432 CFLAGS="$CFLAGS -m64 -mno-red-zone"
7e9ca17a 433 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
434 [grub_cv_cc_no_red_zone=yes],
435 [grub_cv_cc_no_red_zone=no])
436 ])
437 if test "x$grub_cv_cc_no_red_zone" = xno; then
438 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
439 fi
440
c8600122 441 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
20011694 442fi
443
baa2a121 444#
445# Compiler features.
446#
447
9035dce4 448# Need __enable_execute_stack() for nested function trampolines?
449grub_CHECK_ENABLE_EXECUTE_STACK
450
93a81088 451# Position independent executable.
452grub_CHECK_PIE
453[# Need that, because some distributions ship compilers that include
454# `-fPIE' in the default specs.
455if [ x"$pie_possible" = xyes ]; then
456 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
457fi]
458
baa2a121 459# Smashing stack protector.
460grub_CHECK_STACK_PROTECTOR
c3db8364 461# Need that, because some distributions ship compilers that include
baa2a121 462# `-fstack-protector' in the default specs.
c3db8364 463if test "x$ssp_possible" = xyes; then
464 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
465fi
2a8a80e4 466grub_CHECK_STACK_ARG_PROBE
467# Cygwin's GCC uses alloca() to probe the stackframe on static
468# stack allocations above some threshold.
469if test x"$sap_possible" = xyes; then
470 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
471fi
baa2a121 472
63f745e8 473AC_ARG_ENABLE([werror],
474 [AS_HELP_STRING([--disable-werror],
475 [do not use -Werror when building GRUB])])
476if test x"$enable_werror" != xno ; then
477 TARGET_CFLAGS="$TARGET_CFLAGS -Werror"
478fi
479
b977bf01 480AC_SUBST(TARGET_CFLAGS)
2b167a72 481AC_SUBST(TARGET_MODULE_FORMAT)
cf00df31 482AC_SUBST(OBJCONV)
2b167a72 483AC_SUBST(TARGET_APPLE_CC)
484AC_SUBST(TARGET_ASFLAGS)
b977bf01 485AC_SUBST(TARGET_CPPFLAGS)
486AC_SUBST(TARGET_LDFLAGS)
6a161fa9 487
aa6d7826 488# Set them to their new values for the tests below.
489CC="$TARGET_CC"
26de2bcd 490if test "x$TARGET_APPLE_CC" = x1 ; then
69be5b74 491CFLAGS="$TARGET_CFLAGS -nostdlib -Wno-error"
26de2bcd 492else
01fcf061 493CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100 -Wno-error"
26de2bcd 494fi
aa6d7826 495CPPFLAGS="$TARGET_CPPFLAGS"
496LDFLAGS="$TARGET_LDFLAGS"
69be5b74
VS
497LIBS=-lgcc
498
01fcf061
VS
499grub_ASM_USCORE
500if test x$grub_cv_asm_uscore = xyes; then
501CFLAGS="$CFLAGS -Wl,--defsym,_abort=_main"
502else
503CFLAGS="$CFLAGS -Wl,--defsym,abort=main"
504fi
505
69be5b74
VS
506# Check for libgcc symbols
507AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x)
508
509if test "x$TARGET_APPLE_CC" = x1 ; then
510CFLAGS="$TARGET_CFLAGS -nostdlib"
511else
512CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
513fi
42e0cba3 514LIBS=""
aa6d7826 515
6a161fa9 516# Defined in aclocal.m4.
f6130a12 517grub_PROG_TARGET_CC
2b167a72 518if test "x$TARGET_APPLE_CC" != x1 ; then
b977bf01 519grub_PROG_OBJCOPY_ABSOLUTE
2b167a72 520fi
cb71ba20 521grub_PROG_LD_BUILD_ID_NONE
b977bf01 522if test "x$target_cpu" = xi386; then
2aec1692
CF
523 if test "$platform" != emu && test "x$TARGET_APPLE_CC" != x1 ; then
524 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
525 # Check symbols provided by linker script.
526 CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC}8000 -Wl,--defsym,___main=0x8100"
527 fi
2a8a80e4 528 grub_CHECK_BSS_START_SYMBOL
529 grub_CHECK_END_SYMBOL
530 fi
531 CFLAGS="$TARGET_CFLAGS"
4b13b216 532 grub_I386_ASM_PREFIX_REQUIREMENT
533 grub_I386_ASM_ADDR32
534 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
5aded270 535else
f4917dfd 536 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
6a161fa9 537fi
538
bf6a5fb2 539AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
540#define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
541#else
542#define NESTED_FUNC_ATTR
543#endif])
544
5ce5507f 545AC_ARG_ENABLE([efiemu],
546 [AS_HELP_STRING([--enable-efiemu],
547 [build and install the efiemu runtimes (default=guessed)])])
548if test x"$enable_efiemu" = xno ; then
ce7a733d 549 efiemu_excuse="explicitly disabled"
5ce5507f 550fi
551if test x"$efiemu_excuse" = x ; then
43e6200c 552 AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
d2838156 553 CFLAGS="$CFLAGS -m64 -mcmodel=large -mno-red-zone -nostdlib"
5ce5507f 554 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
555 [grub_cv_cc_efiemu=yes],
556 [grub_cv_cc_efiemu=no])
557 ])
55c70904 558 if test x$grub_cv_cc_efiemu = xno; then
e98cd0c2 559 efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
5ce5507f 560 fi
561fi
562if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
ce7a733d 563 AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled])
5ce5507f 564fi
565if test x"$efiemu_excuse" = x ; then
566enable_efiemu=yes
567else
568enable_efiemu=no
569fi
570AC_SUBST([enable_efiemu])
571
016a671b 572if test "$platform" != emu; then
8f9a632b
VS
573AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [
574 SAVED_CPPFLAGS="$CPPFLAGS"
575 CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
576 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>
577int va_arg_func (int fixed, va_list args);]], [[]])],
578 [grub_cv_cc_isystem=yes],
579 [grub_cv_cc_isystem=no])
580 CPPFLAGS="$SAVED_CPPFLAGS"
581])
582
583if test x"$grub_cv_cc_isystem" = xyes ; then
584 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -nostdinc -isystem `$TARGET_CC -print-file-name=include`"
585fi
dae79b6b 586fi
5ce5507f 587
c9a86192 588# Restore the flags.
9962ed99 589CC="$tmp_CC"
590CFLAGS="$tmp_CFLAGS"
591CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 592LDFLAGS="$tmp_LDFLAGS"
aa6d7826 593LIBS="$tmp_LIBS"
6a161fa9 594
4fe9862e 595#
2965c7cc 596# Check for options.
4fe9862e 597#
598
599# Memory manager debugging.
b39f9d20 600AC_ARG_ENABLE([mm-debug],
2965c7cc 601 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 602 [include memory manager debugging]),
2965c7cc 603 [AC_DEFINE([MM_DEBUG], [1],
604 [Define to 1 if you enable memory manager debugging.])])
605
d64399b5 606AC_ARG_ENABLE([grub-emu-usb],
607 [AS_HELP_STRING([--enable-grub-emu-usb],
5ce5507f 608 [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
5ce5507f 609
927d0134
VS
610AC_ARG_ENABLE([grub-emu-sdl],
611 [AS_HELP_STRING([--enable-grub-emu-sdl],
612 [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
613
3affd0ec 614AC_ARG_ENABLE([grub-emu-pci],
615 [AS_HELP_STRING([--enable-grub-emu-pci],
616 [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
617
f38873b8
VS
618AC_ARG_ENABLE([grub-emu-modules],
619 [AS_HELP_STRING([--enable-grub-emu-modules],
620 [Support module loading in `grub-emu' debugging utility (default=no)])])
621
f84b481b
RM
622if test "$platform" = emu; then
623 missing_ncurses=
624[# Check for curses libraries.]
4fe9862e 625 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
626 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
f84b481b 627 [missing_ncurses=[true]])])
4fe9862e 628 AC_SUBST([LIBCURSES])
f84b481b 629[if [ x"$missing_ncurses" = x ]; then ]
4fe9862e 630 [# Check for headers.]
631 AC_CHECK_HEADERS([ncurses/curses.h], [],
632 [AC_CHECK_HEADERS([ncurses.h], [],
633 [AC_CHECK_HEADERS([curses.h], [],
f84b481b 634 [missing_ncurses=[true]])])])
5ce5507f 635[fi]
f84b481b
RM
636if test x"$missing_ncurses" = xtrue ; then
637 AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
5ce5507f 638fi
f84b481b 639
f38873b8
VS
640if test x"$enable_grub_emu_modules" = xyes ; then
641 TARGET_NO_MODULES=no
642else
643 TARGET_NO_MODULES=yes
644fi
645AC_SUBST(TARGET_NO_MODULES)
646
2aec1692
CF
647if test "$TARGET_NO_MODULES" = yes ; then
648 # Do not convert modules, otherwise linkage may fail (Cygwin only).
649 # FIXME: Should be checked above before TARGET_OBJ2ELF is set first.
650 TARGET_OBJ2ELF=
651fi
652
5ce5507f 653if test x"$enable_grub_emu_usb" = xno ; then
ce7a733d 654 grub_emu_usb_excuse="explicitly disabled"
5ce5507f 655fi
325c8258 656
0e848909
VS
657if test x"$enable_grub_emu_pci" = xyes ; then
658 grub_emu_usb_excuse="conflicts with PCI support"
659fi
660
5ce5507f 661[if [ x"$grub_emu_usb_excuse" = x ]; then
d64399b5 662 # Check for libusb libraries.]
5ce5507f 663AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
e98cd0c2 664 [grub_emu_usb_excuse=["need libusb library"]])
d64399b5 665 AC_SUBST([LIBUSB])
5ce5507f 666[fi]
667[if [ x"$grub_emu_usb_excuse" = x ]; then
668 # Check for headers.]
d64399b5 669 AC_CHECK_HEADERS([usb.h], [],
e98cd0c2 670 [grub_emu_usb_excuse=["need libusb headers"]])
4fe9862e 671[fi]
c6f3b249 672if test x"$enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then
ce7a733d 673 AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled])
5ce5507f 674fi
675if test x"$grub_emu_usb_excuse" = x ; then
676enable_grub_emu_usb=yes
677else
678enable_grub_emu_usb=no
679fi
680
927d0134
VS
681if test x"$enable_grub_emu_sdl" = xno ; then
682 grub_emu_sdl_excuse="explicitely disabled"
683fi
684[if [ x"$grub_emu_sdl_excuse" = x ]; then
685 # Check for libSDL libraries.]
686AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
687 [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
688 AC_SUBST([LIBSDL])
689[fi]
9f293ab0 690
927d0134
VS
691[if [ x"$grub_emu_sdl_excuse" = x ]; then
692 # Check for headers.]
693 AC_CHECK_HEADERS([SDL/SDL.h], [],
694 [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
695[fi]
9f293ab0 696
927d0134
VS
697if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
698 AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
699fi
700if test x"$grub_emu_sdl_excuse" = x ; then
701enable_grub_emu_sdl=yes
702else
703enable_grub_emu_sdl=no
704fi
705
3affd0ec 706if test x"$enable_grub_emu_pci" != xyes ; then
325c8258 707 grub_emu_pci_excuse="not enabled"
708fi
709
710if test x"$enable_grub_emu_usb" = xyes ; then
711 grub_emu_pci_excuse="conflicts with USB support"
712fi
713
714[if [ x"$grub_emu_pci_excuse" = x ]; then
715 # Check for libpci libraries.]
459fed4b 716 AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
717 [grub_emu_pci_excuse=["need libpciaccess library"]])
718 AC_SUBST([LIBPCIACCESS])
325c8258 719[fi]
720[if [ x"$grub_emu_pci_excuse" = x ]; then
721 # Check for headers.]
722 AC_CHECK_HEADERS([pci/pci.h], [],
459fed4b 723 [grub_emu_pci_excuse=["need libpciaccess headers"]])
325c8258 724[fi]
725
726if test x"$grub_emu_pci_excuse" = x ; then
727enable_grub_emu_pci=yes
728else
9f293ab0 729
325c8258 730enable_grub_emu_pci=no
3affd0ec 731fi
732
927d0134 733AC_SUBST([enable_grub_emu_sdl])
d64399b5 734AC_SUBST([enable_grub_emu_usb])
3affd0ec 735AC_SUBST([enable_grub_emu_pci])
f84b481b 736fi
4fe9862e 737
99fadbaa 738AC_ARG_ENABLE([grub-fstest],
739 [AS_HELP_STRING([--enable-grub-fstest],
5ce5507f 740 [build and install the `grub-fstest' debugging utility (default=guessed)])])
741if test x"$enable_grub_fstest" = xno ; then
ce7a733d 742 grub_fstest_excuse="explicitly disabled"
5ce5507f 743fi
744if test x"$grub_fstest_excuse" = x ; then
745enable_grub_fstest=yes
746else
747enable_grub_fstest=no
748fi
99fadbaa 749AC_SUBST([enable_grub_fstest])
750
e52db1f7 751AC_ARG_ENABLE([grub-mkfont],
752 [AS_HELP_STRING([--enable-grub-mkfont],
5ce5507f 753 [build and install the `grub-mkfont' utility (default=guessed)])])
754if test x"$enable_grub_mkfont" = xno ; then
ce7a733d 755 grub_mkfont_excuse="explicitly disabled"
5ce5507f 756fi
757
758if test x"$grub_mkfont_excuse" = x ; then
e52db1f7 759 # Check for freetype libraries.
760 AC_CHECK_PROGS([FREETYPE], [freetype-config])
761 if test "x$FREETYPE" = x ; then
e98cd0c2 762 grub_mkfont_excuse=["need freetype2 library"]
e52db1f7 763 fi
764 freetype_cflags=`freetype-config --cflags`
765 freetype_libs=`freetype-config --libs`
766fi
660960d6
VS
767
768if test x"$grub_mkfont_excuse" = x ; then
769 # Check for freetype libraries.
d1e8a02f
VS
770 SAVED_CPPFLAGS="$CPPFLAGS"
771 CPPFLAGS="$CPPFLAGS $freetype_cflags"
660960d6
VS
772 AC_CHECK_HEADERS([ft2build.h], [],
773 [grub_mkfont_excuse=["need freetype2 headers"]])
d1e8a02f 774 CPPFLAGS="$SAVED_CPPFLAGS"
660960d6
VS
775fi
776
5ce5507f 777if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
ce7a733d 778 AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
5ce5507f 779fi
780if test x"$grub_mkfont_excuse" = x ; then
781enable_grub_mkfont=yes
782else
783enable_grub_mkfont=no
784fi
e52db1f7 785AC_SUBST([enable_grub_mkfont])
786AC_SUBST([freetype_cflags])
787AC_SUBST([freetype_libs])
788
2b167a72 789AC_SUBST(ASFLAGS)
fc45fb58 790
6a161fa9 791# Output files.
1f4147aa 792grub_CHECK_LINK_DIR
793if test x"$link_dir" = xyes ; then
f84b481b
RM
794 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu])
795 if test "$platform" != emu ; then
796 AC_CONFIG_LINKS([include/grub/machine:include/grub/$target_cpu/$platform])
797 fi
1f4147aa 798else
799 mkdir -p include/grub 2>/dev/null
800 rm -rf include/grub/cpu
801 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
f84b481b
RM
802 if test "$platform" != emu ; then
803 rm -rf include/grub/machine
804 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
805 fi
1f4147aa 806fi
7b455f4d 807AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
6a161fa9 808AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
809AC_OUTPUT
5ce5507f 810[
811echo "*******************************************************"
812echo GRUB2 will be compiled with following components:
813echo Platform: "$target_cpu"-"$platform"
f84b481b 814if [ x"$platform" = xemu ]; then
5ce5507f 815if [ x"$grub_emu_usb_excuse" = x ]; then
816echo USB support for grub-emu: Yes
817else
818echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
819fi
927d0134
VS
820if [ x"$grub_emu_sdl_excuse" = x ]; then
821echo SDL support for grub-emu: Yes
822else
823echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
824fi
325c8258 825if [ x"$grub_emu_pci_excuse" = x ]; then
826echo PCI support for grub-emu: Yes
827else
828echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
829fi
f38873b8
VS
830if [ x"$TARGET_NO_MODULES" = xno ]; then
831echo Module support for grub-emu: Yes
832else
833echo Module support for grub-emu: No
834fi
f84b481b 835fi
5ce5507f 836if [ x"$enable_mm_debug" = xyes ]; then
837echo With memory debugging: Yes
838else
839echo With memory debugging: No
840fi
5ce5507f 841if [ x"$efiemu_excuse" = x ]; then
842echo efiemu runtime: Yes
843else
844echo efiemu runtime: No "($efiemu_excuse)"
845fi
846if [ x"$grub_fstest_excuse" = x ]; then
847echo grub-fstest: Yes
848else
849echo grub-fstest: No "($grub_fstest_excuse)"
850fi
851if [ x"$grub_mkfont_excuse" = x ]; then
852echo grub-mkfont: Yes
853else
854echo grub-mkfont: No "($grub_mkfont_excuse)"
855fi
856echo "*******************************************************"
857]