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