1 # Process this file with autoconf to produce a configure script.
3 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
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.
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
14 dnl This configure script is complicated, because GRUB needs to deal
15 dnl with three potentially different types:
17 dnl build -- the environment for building GRUB
18 dnl host -- the environment for running utilities
19 dnl target -- the environment for running GRUB
21 dnl In addition, GRUB needs to deal with a platform specification
22 dnl which specifies the system running GRUB, such as firmware.
23 dnl This is necessary because the target type in autoconf does not
24 dnl describe such a system very well.
26 dnl The current strategy is to use variables with no prefix (such as
27 dnl CC, CFLAGS, etc.) for the host type as well as the build type,
28 dnl because GRUB does not need to use those variables for the build
29 dnl type, so there is no conflict. Variables with the prefix "TARGET_"
30 dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
34 AC_INIT([GRUB],[1.97~beta2],[bug-grub@gnu.org])
36 AC_CONFIG_SRCDIR([include/grub/dl.h])
37 AC_CONFIG_HEADER([config.h])
39 # Checks for host and target systems.
43 # Program name transformations
47 i[[3456]]86) target_cpu=i386 ;;
48 sparc) target_cpu=sparc64 ;;
51 # Specify the platform (such as firmware).
52 AC_ARG_WITH([platform],
53 AS_HELP_STRING([--with-platform=PLATFORM],
54 [select the host platform [[guessed]]]))
56 # Guess the platform if not specified.
57 if test "x$with_platform" = x; then
58 case "$target_cpu"-"$target_vendor" in
59 i386-apple) platform=efi ;;
60 i386-*) platform=pc ;;
61 x86_64-apple) platform=efi ;;
62 x86_64-*) platform=pc ;;
63 powerpc-*) platform=ieee1275 ;;
64 powerpc64-*) platform=ieee1275 ;;
65 sparc64-*) platform=ieee1275 ;;
66 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
69 platform="$with_platform"
72 # Adjust CPU unless target was explicitly specified.
73 if test -z "$target_alias"; then
74 case "$target_cpu"-"$platform" in
76 x86_64-*) target_cpu=i386 ;;
77 powerpc64-ieee1275) target_cpu=powerpc ;;
81 # Check if the platform is supported, make final adjustments.
82 case "$target_cpu"-"$platform" in
87 i386-linuxbios) platform=coreboot ;;
92 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
96 i386 | powerpc) target_m32=1 ;;
97 x86_64 | sparc64) target_m64=1 ;;
101 mingw32) host_os=cygwin ;;
104 # This normalizes the names, and creates a new variable ("host_kernel")
105 # while at it, since the mapping is not always 1:1 (e.g. different OSes
106 # using the same kernel type).
108 gnu*) host_kernel=hurd ;;
109 linux*) host_kernel=linux ;;
110 freebsd* | kfreebsd*-gnu) host_kernel=freebsd ;;
111 cygwin) host_kernel=windows ;;
116 AC_SUBST(host_kernel)
122 # Checks for build programs.
125 # Although cmp is listed in the GNU Coding Standards as a command which
126 # can used directly, OpenBSD lacks cmp in the default installation.
127 AC_CHECK_PROGS([CMP], [cmp])
128 if test "x$CMP" = x; then
129 AC_MSG_ERROR([cmp is not found])
132 AC_CHECK_PROGS([YACC], [bison])
133 if test "x$YACC" = x; then
134 AC_MSG_ERROR([bison is not found])
137 for file in /usr/src/unifont.bdf ; do
138 if test -e $file ; then
139 AC_SUBST([UNIFONT_BDF], [$file])
148 # These are not a "must".
149 AC_PATH_PROG(RUBY, ruby)
152 # Checks for host programs.
157 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
162 # Identify characteristics of the host architecture.
164 AC_CHECK_SIZEOF(void *)
165 AC_CHECK_SIZEOF(long)
168 if test x$grub_cv_apple_cc = xyes ; then
169 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
170 ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
173 if test "x$cross_compiling" = xyes; then
174 AC_MSG_WARN([cannot generate manual pages while cross compiling])
176 AC_PATH_PROG(HELP2MAN, help2man)
179 # Check for functions.
180 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
183 # Check for target programs.
186 # Find tools for the target.
187 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
188 tmp_ac_tool_prefix="$ac_tool_prefix"
189 ac_tool_prefix=$target_alias-
191 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
192 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
193 AC_CHECK_TOOL(OBJCOPY, objcopy)
194 AC_CHECK_TOOL(STRIP, strip)
195 AC_CHECK_TOOL(NM, nm)
197 ac_tool_prefix="$tmp_ac_tool_prefix"
199 if test "x$TARGET_CC" = x; then
202 AC_CHECK_TOOL(OBJCOPY, objcopy)
203 AC_CHECK_TOOL(STRIP, strip)
204 AC_CHECK_TOOL(NM, nm)
209 # Test the C compiler for the target environment.
212 tmp_LDFLAGS="$LDFLAGS"
213 tmp_CPPFLAGS="$CPPFLAGS"
216 CFLAGS="$TARGET_CFLAGS"
217 CPPFLAGS="$TARGET_CPPFLAGS"
218 LDFLAGS="$TARGET_LDFLAGS"
221 if test "x$TARGET_CFLAGS" = x; then
223 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
224 -Wundef -Wstrict-prototypes -g"
226 # optimization flags.
227 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
229 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
233 if test "x$grub_cv_cc_Os" = xyes; then
234 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
236 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
239 # Force no alignment to save space on i386.
240 if test "x$target_cpu" = xi386; then
241 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
242 CFLAGS="$CFLAGS -falign-loops=1"
243 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
244 [grub_cv_cc_falign_loop=yes],
245 [grub_cv_cc_falign_loop=no])
248 if test "x$grub_cv_cc_falign_loop" = xyes; then
249 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
251 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
255 # By default, GCC 4.4 generates .eh_frame sections containing unwind
256 # information in some cases where it previously did not. GRUB doesn't need
257 # these and they just use up vital space. Restore the old compiler
259 AC_CACHE_CHECK([whether -fno-dwarf2-cfi-asm works], [grub_cv_cc_fno_dwarf2_cfi_asm], [
260 SAVE_CFLAGS="$CFLAGS"
261 CFLAGS="$CFLAGS -fno-dwarf2-cfi-asm"
262 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
263 [grub_cv_cc_fno_dwarf2_cfi_asm=yes],
264 [grub_cv_cc_fno_dwarf2_cfi_asm=no])
265 CFLAGS="$SAVE_CFLAGS"
268 if test "x$grub_cv_cc_fno_dwarf2_cfi_asm" = xyes; then
269 TARGET_CFLAGS="$TARGET_CFLAGS -fno-dwarf2-cfi-asm"
274 if test x$grub_cv_apple_target_cc = xyes ; then
275 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
276 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
277 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
279 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
280 if test "x$OBJCONV" = x ; then
281 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
283 if test "x$OBJCONV" = x ; then
284 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
287 TARGET_IMG_CFLAGS="-static"
288 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
289 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
292 # Use linker script if present, otherwise use builtin -N script.
293 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
294 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
295 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
296 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
299 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
300 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
305 AC_SUBST(TARGET_IMG_LDSCRIPT)
306 AC_SUBST(TARGET_IMG_LDFLAGS)
307 AC_SUBST(TARGET_IMG_CFLAGS)
309 # For platforms where ELF is not the default link format.
310 AC_MSG_CHECKING([for command to convert module to ELF format])
312 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
315 AC_SUBST(TARGET_OBJ2ELF)
316 AC_MSG_RESULT([$TARGET_OBJ2ELF])
319 if test "x$target_m32" = x1; then
321 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
322 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
323 TARGET_MODULE_FORMAT="elf32"
326 if test "x$target_m64" = x1; then
328 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
329 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
330 TARGET_MODULE_FORMAT="elf64"
333 if test "$target_cpu"-"$platform" = x86_64-efi; then
334 # Use large model to support 4G memory
335 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
337 CFLAGS="$CFLAGS -m64 -mcmodel=large"
338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
339 [grub_cv_cc_mcmodel=yes],
340 [grub_cv_cc_mcmodel=no])
342 if test "x$grub_cv_cc_mcmodel" = xno; then
343 CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
344 TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
345 AC_MSG_WARN([-mcmodel=large not supported. You won't be able to use the memory over 4GiB. Upgrade your gcc])
347 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
350 # EFI writes to stack below %rsp, we must not use the red zone
351 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
352 CFLAGS="$CFLAGS -m64 -mno-red-zone"
353 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
354 [grub_cv_cc_no_red_zone=yes],
355 [grub_cv_cc_no_red_zone=no])
357 if test "x$grub_cv_cc_no_red_zone" = xno; then
358 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
361 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
368 # Need __enable_execute_stack() for nested function trampolines?
369 grub_CHECK_ENABLE_EXECUTE_STACK
371 # Position independent executable.
373 [# Need that, because some distributions ship compilers that include
374 # `-fPIE' in the default specs.
375 if [ x"$pie_possible" = xyes ]; then
376 TARGET_CFLAGS="$TARGET_CFLAGS -fno-PIE"
379 # Smashing stack protector.
380 grub_CHECK_STACK_PROTECTOR
381 # Need that, because some distributions ship compilers that include
382 # `-fstack-protector' in the default specs.
383 if test "x$ssp_possible" = xyes; then
384 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
386 grub_CHECK_STACK_ARG_PROBE
387 # Cygwin's GCC uses alloca() to probe the stackframe on static
388 # stack allocations above some threshold.
389 if test x"$sap_possible" = xyes; then
390 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
393 AC_SUBST(TARGET_CFLAGS)
394 AC_SUBST(TARGET_MODULE_FORMAT)
396 AC_SUBST(TARGET_APPLE_CC)
397 AC_SUBST(TARGET_ASFLAGS)
398 AC_SUBST(TARGET_CPPFLAGS)
399 AC_SUBST(TARGET_LDFLAGS)
401 # Set them to their new values for the tests below.
403 if test "x$TARGET_APPLE_CC" = x1 ; then
404 CFLAGS="$TARGET_CFLAGS -nostdlib"
406 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
408 CPPFLAGS="$TARGET_CPPFLAGS"
409 LDFLAGS="$TARGET_LDFLAGS"
411 # Defined in aclocal.m4.
413 if test "x$TARGET_APPLE_CC" != x1 ; then
414 grub_PROG_OBJCOPY_ABSOLUTE
416 grub_PROG_LD_BUILD_ID_NONE
418 if test "x$target_cpu" = xi386; then
419 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
420 # Check symbols provided by linker script.
421 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
423 if test "x$TARGET_APPLE_CC" != x1 ; then
424 grub_CHECK_BSS_START_SYMBOL
425 grub_CHECK_END_SYMBOL
427 CFLAGS="$TARGET_CFLAGS"
428 grub_I386_ASM_PREFIX_REQUIREMENT
430 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
432 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
435 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
436 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
438 #define NESTED_FUNC_ATTR
441 AC_ARG_ENABLE([efiemu],
442 [AS_HELP_STRING([--enable-efiemu],
443 [build and install the efiemu runtimes (default=guessed)])])
444 if test x"$enable_efiemu" = xno ; then
445 efiemu_excuse="explicitly disabled"
447 if test x"$efiemu_excuse" = x ; then
448 AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [
449 CFLAGS="$CFLAGS -m64 -mcmodel=large -mno-red-zone -nostdlib"
450 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
451 [grub_cv_cc_efiemu=yes],
452 [grub_cv_cc_efiemu=no])
454 if test x$grub_cv_cc_efiemu = xno; then
455 efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib"
458 if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then
459 AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled])
461 if test x"$efiemu_excuse" = x ; then
466 AC_SUBST([enable_efiemu])
472 CPPFLAGS="$tmp_CPPFLAGS"
473 LDFLAGS="$tmp_LDFLAGS"
480 # Memory manager debugging.
481 AC_ARG_ENABLE([mm-debug],
482 AS_HELP_STRING([--enable-mm-debug],
483 [include memory manager debugging]),
484 [AC_DEFINE([MM_DEBUG], [1],
485 [Define to 1 if you enable memory manager debugging.])])
487 AC_ARG_ENABLE([grub-emu],
488 [AS_HELP_STRING([--enable-grub-emu],
489 [build and install the `grub-emu' debugging utility (default=guessed)])])
490 AC_ARG_ENABLE([grub-emu-usb],
491 [AS_HELP_STRING([--enable-grub-emu-usb],
492 [build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
493 if test x"$enable_grub_emu" = xno ; then
494 grub_emu_excuse="explicitly disabled"
497 [# Check for curses libraries.]
498 [if [ x"$grub_emu_excuse" = x ]; then ]
499 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
500 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
501 [grub_emu_excuse=["need (n)curses libraries"]])])
502 AC_SUBST([LIBCURSES])
504 [if [ x"$grub_emu_excuse" = x ]; then ]
505 [# Check for headers.]
506 AC_CHECK_HEADERS([ncurses/curses.h], [],
507 [AC_CHECK_HEADERS([ncurses.h], [],
508 [AC_CHECK_HEADERS([curses.h], [],
509 [grub_emu_excuse=["need (n)curses headers"]])])])
512 if test x"$enable_grub_emu" = xyes && test x"$grub_emu_excuse" != x ; then
513 AC_MSG_ERROR([grub-emu was explicitly requested but can't be compiled])
515 if test x"$grub_emu_excuse" = x ; then
519 grub_emu_usb_excuse="grub-emu isn't built"
521 if test x"$enable_grub_emu_usb" = xno ; then
522 grub_emu_usb_excuse="explicitly disabled"
524 [if [ x"$grub_emu_usb_excuse" = x ]; then
525 # Check for libusb libraries.]
526 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
527 [grub_emu_usb_excuse=["need libusb library"]])
530 [if [ x"$grub_emu_usb_excuse" = x ]; then
531 # Check for headers.]
532 AC_CHECK_HEADERS([usb.h], [],
533 [grub_emu_usb_excuse=["need libusb headers"]])
535 if test x"enable_grub_emu_usb" = xyes && test x"$grub_emu_usb_excuse" != x ; then
536 AC_MSG_ERROR([USB support for grub-emu was explicitly requested but can't be compiled])
538 if test x"$grub_emu_usb_excuse" = x ; then
539 enable_grub_emu_usb=yes
541 enable_grub_emu_usb=no
544 AC_SUBST([enable_grub_emu])
545 AC_SUBST([enable_grub_emu_usb])
547 AC_ARG_ENABLE([grub-fstest],
548 [AS_HELP_STRING([--enable-grub-fstest],
549 [build and install the `grub-fstest' debugging utility (default=guessed)])])
550 if test x"$enable_grub_fstest" = xno ; then
551 grub_fstest_excuse="explicitly disabled"
553 if test x"$grub_fstest_excuse" = x ; then
554 enable_grub_fstest=yes
556 enable_grub_fstest=no
558 AC_SUBST([enable_grub_fstest])
560 AC_ARG_ENABLE([grub-pe2elf],
561 [AS_HELP_STRING([--enable-grub-pe2elf],
562 [build and install the `grub-pe2elf' conversion utility])])
563 AC_SUBST([enable_grub_pe2elf])
565 AC_ARG_ENABLE([grub-mkfont],
566 [AS_HELP_STRING([--enable-grub-mkfont],
567 [build and install the `grub-mkfont' utility (default=guessed)])])
568 if test x"$enable_grub_mkfont" = xno ; then
569 grub_mkfont_excuse="explicitly disabled"
572 if test x"$grub_mkfont_excuse" = x ; then
573 # Check for freetype libraries.
574 AC_CHECK_PROGS([FREETYPE], [freetype-config])
575 if test "x$FREETYPE" = x ; then
576 grub_mkfont_excuse=["need freetype2 library"]
578 freetype_cflags=`freetype-config --cflags`
579 freetype_libs=`freetype-config --libs`
581 if test x"$enable_grub_mkfont" = xyes && test x"$grub_mkfont_excuse" != x ; then
582 AC_MSG_ERROR([grub-mkfont was explicitly requested but can't be compiled])
584 if test x"$grub_mkfont_excuse" = x ; then
585 enable_grub_mkfont=yes
587 enable_grub_mkfont=no
589 AC_SUBST([enable_grub_mkfont])
590 AC_SUBST([freetype_cflags])
591 AC_SUBST([freetype_libs])
597 if test x"$link_dir" = xyes ; then
598 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
599 include/grub/machine:include/grub/$target_cpu/$platform])
601 mkdir -p include/grub 2>/dev/null
602 rm -rf include/grub/cpu
603 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
604 rm -rf include/grub/machine
605 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
607 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
608 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
611 echo "*******************************************************"
612 echo GRUB2 will be compiled with following components:
613 echo Platform: "$target_cpu"-"$platform"
614 if [ x"$grub_emu_excuse" = x ]; then
617 echo grub-emu: No "($grub_emu_excuse)"
619 if [ x"$grub_emu_usb_excuse" = x ]; then
620 echo USB support for grub-emu: Yes
622 echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
624 if [ x"$enable_mm_debug" = xyes ]; then
625 echo With memory debugging: Yes
627 echo With memory debugging: No
629 if [ x"$enable_grub_pe2elf" = xyes ]; then
630 echo grub-pe2elf will be built and installed
631 elif [ x$TARGET_OBJ2ELF = xgrub-pe2elf ]; then
632 echo grub-pe2elf will be built but not installed
634 echo grub-pe2elf will not be built
636 if [ x"$efiemu_excuse" = x ]; then
637 echo efiemu runtime: Yes
639 echo efiemu runtime: No "($efiemu_excuse)"
641 if [ x"$grub_fstest_excuse" = x ]; then
642 echo grub-fstest: Yes
644 echo grub-fstest: No "($grub_fstest_excuse)"
646 if [ x"$grub_mkfont_excuse" = x ]; then
647 echo grub-mkfont: Yes
649 echo grub-mkfont: No "($grub_mkfont_excuse)"
651 echo "*******************************************************"