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.96],[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 powerpc64) host_m32=1 ;;
51 i[[3456]]86) target_cpu=i386 ;;
54 # Specify the platform (such as firmware).
55 AC_ARG_WITH([platform],
56 AS_HELP_STRING([--with-platform=PLATFORM],
57 [select the host platform [[guessed]]]))
59 # Guess the platform if not specified.
60 if test "x$with_platform" = x; then
61 case "$target_cpu"-"$target_vendor" in
62 i386-apple) platform=efi ;;
63 i386-*) platform=pc ;;
64 x86_64-apple) platform=efi ;;
65 x86_64-*) platform=pc ;;
66 powerpc-*) platform=ieee1275 ;;
67 powerpc64-*) platform=ieee1275 ;;
68 sparc64-*) platform=ieee1275 ;;
69 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
72 platform="$with_platform"
75 # Adjust CPU unless target was explicitly specified.
76 if test -z "$target_alias"; then
77 case "$target_cpu"-"$platform" in
79 x86_64-*) target_cpu=i386 ;;
80 powerpc64-ieee1275) target_cpu=powerpc ;;
84 # Check if the platform is supported, make final adjustments.
85 case "$target_cpu"-"$platform" in
90 i386-linuxbios) platform=coreboot ;;
94 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
98 i386 | powerpc) target_m32=1 ;;
99 x86_64 | sparc64) target_m64=1 ;;
103 mingw32) host_os=cygwin ;;
106 # This normalizes the names, and creates a new variable ("host_kernel")
107 # while at it, since the mapping is not always 1:1 (e.g. different OSes
108 # using the same kernel type).
110 gnu*) host_kernel=hurd ;;
111 linux*) host_kernel=linux ;;
112 freebsd* | kfreebsd*-gnu) host_kernel=freebsd ;;
113 cygwin) host_kernel=windows ;;
118 AC_SUBST(host_kernel)
124 # Checks for build programs.
127 # Although cmp is listed in the GNU Coding Standards as a command which
128 # can used directly, OpenBSD lacks cmp in the default installation.
129 AC_CHECK_PROGS([CMP], [cmp])
130 if test "x$CMP" = x; then
131 AC_MSG_ERROR([cmp is not found])
134 AC_CHECK_PROGS([YACC], [bison])
135 if test "x$YACC" = x; then
136 AC_MSG_ERROR([bison is not found])
139 for file in /usr/src/unifont.bdf ; do
140 if test -e $file ; then
141 AC_SUBST([UNIFONT_BDF], [$file])
150 # These are not a "must".
151 AC_PATH_PROG(RUBY, ruby)
152 AC_PATH_PROG(HELP2MAN, help2man)
155 # Checks for host programs.
160 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
165 # Identify characteristics of the host architecture.
167 AC_CHECK_SIZEOF(void *)
168 AC_CHECK_SIZEOF(long)
171 if test x$grub_cv_apple_cc == xyes ; then
172 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
173 ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
175 if test "x$host_m32" = x1; then
177 CFLAGS="$CFLAGS -m32"
178 LDFLAGS="$LDFLAGS -m32"
181 # Check LZO when compiling for the i386-pc.
182 if test "$target_cpu"-"$platform" = i386-pc; then
184 [AS_HELP_STRING([--enable-lzo],
185 [use lzo to compress kernel (default is lzma)])])
186 [if [ x"$enable_lzo" = xyes ]; then
187 # There are three possibilities. LZO version 2 installed with the name
188 # liblzo2, with the name liblzo, and LZO version 1.]
189 AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
190 AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
191 [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
192 [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
193 [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
195 [LIBS="$LIBS $LIBLZO"]
196 AC_CHECK_FUNC([lzo1x_999_compress], ,
197 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
199 [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
200 AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
202 AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
204 AC_SUBST([enable_lzo])
207 # Check for functions.
208 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
211 # Check for target programs.
214 # Find tools for the target.
215 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
216 tmp_ac_tool_prefix="$ac_tool_prefix"
217 ac_tool_prefix=$target_alias-
219 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
220 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
221 AC_CHECK_TOOL(OBJCOPY, objcopy)
222 AC_CHECK_TOOL(STRIP, strip)
223 AC_CHECK_TOOL(NM, nm)
225 ac_tool_prefix="$tmp_ac_tool_prefix"
227 if test "x$TARGET_CC" = x; then
230 AC_CHECK_TOOL(OBJCOPY, objcopy)
231 AC_CHECK_TOOL(STRIP, strip)
232 AC_CHECK_TOOL(NM, nm)
237 # Test the C compiler for the target environment.
240 tmp_LDFLAGS="$LDFLAGS"
241 tmp_CPPFLAGS="$CPPFLAGS"
244 CFLAGS="$TARGET_CFLAGS"
245 CPPFLAGS="$TARGET_CPPFLAGS"
246 LDFLAGS="$TARGET_LDFLAGS"
249 if test "x$TARGET_CFLAGS" = x; then
251 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
252 -Wundef -Wstrict-prototypes -g"
254 # optimization flags.
255 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
257 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
261 if test "x$grub_cv_cc_Os" = xyes; then
262 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
264 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
267 # Force no alignment to save space on i386.
268 if test "x$target_cpu" = xi386; then
269 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
270 CFLAGS="$CFLAGS -falign-loops=1"
271 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
272 [grub_cv_cc_falign_loop=yes],
273 [grub_cv_cc_falign_loop=no])
276 if test "x$grub_cv_cc_falign_loop" = xyes; then
277 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
279 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
285 if test x$grub_cv_apple_target_cc == xyes ; then
286 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
287 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
288 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
290 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
291 if test "x$OBJCONV" = x ; then
292 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
294 if test "x$OBJCONV" = x ; then
295 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
298 TARGET_IMG_CFLAGS="-static"
299 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
300 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
303 # Use linker script if present, otherwise use builtin -N script.
304 AC_MSG_CHECKING([for option to link raw image])
305 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
306 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
307 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
308 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
311 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
312 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
317 AC_SUBST(TARGET_IMG_LDSCRIPT)
318 AC_SUBST(TARGET_IMG_LDFLAGS)
319 AC_SUBST(TARGET_IMG_CFLAGS)
320 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
322 # For platforms where ELF is not the default link format.
323 AC_MSG_CHECKING([for command to convert module to ELF format])
325 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
328 AC_SUBST(TARGET_OBJ2ELF)
329 AC_MSG_RESULT([$TARGET_OBJ2ELF])
332 if test "x$target_m32" = x1; then
334 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
335 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
336 TARGET_MODULE_FORMAT="elf32"
339 if test "x$target_m64" = x1; then
341 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
342 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
343 TARGET_MODULE_FORMAT="elf64"
346 if test "$target_cpu"-"$platform" = x86_64-efi; then
347 # Use large model to support 4G memory
348 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
350 CFLAGS="$CFLAGS -m64 -mcmodel=large"
351 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
352 [grub_cv_cc_mcmodel=yes],
353 [grub_cv_cc_mcmodel=no])
355 if test "x$grub_cv_cc_mcmodel" = xno; then
356 CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
357 TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
358 AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
360 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
363 # EFI writes to stack below %rsp, we must not use the red zone
364 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
365 CFLAGS="$CFLAGS -m64 -mno-red-zone"
366 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
367 [grub_cv_cc_no_red_zone=yes],
368 [grub_cv_cc_no_red_zone=no])
370 if test "x$grub_cv_cc_no_red_zone" = xno; then
371 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
374 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
381 # Need __enable_execute_stack() for nested function trampolines?
382 grub_CHECK_ENABLE_EXECUTE_STACK
384 # Smashing stack protector.
385 grub_CHECK_STACK_PROTECTOR
386 # Need that, because some distributions ship compilers that include
387 # `-fstack-protector' in the default specs.
388 if test "x$ssp_possible" = xyes; then
389 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
391 grub_CHECK_STACK_ARG_PROBE
392 # Cygwin's GCC uses alloca() to probe the stackframe on static
393 # stack allocations above some threshold.
394 if test x"$sap_possible" = xyes; then
395 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
398 AC_SUBST(TARGET_CFLAGS)
399 AC_SUBST(TARGET_MODULE_FORMAT)
401 AC_SUBST(TARGET_APPLE_CC)
402 AC_SUBST(TARGET_ASFLAGS)
403 AC_SUBST(TARGET_CPPFLAGS)
404 AC_SUBST(TARGET_LDFLAGS)
406 # Set them to their new values for the tests below.
408 CFLAGS="$TARGET_CFLAGS"
409 CPPFLAGS="$TARGET_CPPFLAGS"
410 LDFLAGS="$TARGET_LDFLAGS"
412 # Check for target functions.
413 AC_CHECK_FUNCS(__bswapsi2 __bswapdi2)
415 # Defined in aclocal.m4.
417 if test "x$TARGET_APPLE_CC" != x1 ; then
418 grub_PROG_OBJCOPY_ABSOLUTE
420 grub_PROG_LD_BUILD_ID_NONE
422 if test "x$target_cpu" = xi386; then
423 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
424 # Check symbols provided by linker script.
425 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
427 if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then
428 grub_CHECK_BSS_START_SYMBOL
429 grub_CHECK_END_SYMBOL
431 CFLAGS="$TARGET_CFLAGS"
432 grub_I386_ASM_PREFIX_REQUIREMENT
434 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
436 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
439 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
440 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
442 #define NESTED_FUNC_ATTR
448 CPPFLAGS="$tmp_CPPFLAGS"
449 LDFLAGS="$tmp_LDFLAGS"
456 # Memory manager debugging.
457 AC_ARG_ENABLE([mm-debug],
458 AS_HELP_STRING([--enable-mm-debug],
459 [include memory manager debugging]),
460 [AC_DEFINE([MM_DEBUG], [1],
461 [Define to 1 if you enable memory manager debugging.])])
463 AC_ARG_ENABLE([grub-emu],
464 [AS_HELP_STRING([--enable-grub-emu],
465 [build and install the `grub-emu' debugging utility])])
466 AC_ARG_ENABLE([grub-emu-usb],
467 [AS_HELP_STRING([--enable-grub-emu-usb],
468 [build and install the `grub-emu' debugging utility with USB support])])
469 [if [ x"$enable_grub_emu" = xyes ]; then
470 # Check for curses libraries.]
471 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
472 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
473 [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
474 AC_SUBST([LIBCURSES])
476 [# Check for headers.]
477 AC_CHECK_HEADERS([ncurses/curses.h], [],
478 [AC_CHECK_HEADERS([ncurses.h], [],
479 [AC_CHECK_HEADERS([curses.h], [],
480 [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
482 [if [ x"$enable_grub_emu_usb" = xyes ]; then
483 # Check for libusb libraries.]
484 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
485 [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
488 [# Check for headers.]
489 AC_CHECK_HEADERS([usb.h], [],
490 [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
493 AC_SUBST([enable_grub_emu])
494 AC_SUBST([enable_grub_emu_usb])
496 AC_ARG_ENABLE([grub-fstest],
497 [AS_HELP_STRING([--enable-grub-fstest],
498 [build and install the `grub-fstest' debugging utility])])
499 AC_SUBST([enable_grub_fstest])
501 AC_ARG_ENABLE([grub-pe2elf],
502 [AS_HELP_STRING([--enable-grub-pe2elf],
503 [build and install the `grub-pe2elf' conversion utility])])
504 AC_SUBST([enable_grub_pe2elf])
506 AC_ARG_ENABLE([grub-mkfont],
507 [AS_HELP_STRING([--enable-grub-mkfont],
508 [build and install the `grub-mkfont' utility])])
509 if test x"$enable_grub_mkfont" = xyes ; then
510 # Check for freetype libraries.
511 AC_CHECK_PROGS([FREETYPE], [freetype-config])
512 if test "x$FREETYPE" = x ; then
513 AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
515 freetype_cflags=`freetype-config --cflags`
516 freetype_libs=`freetype-config --libs`
518 AC_SUBST([enable_grub_mkfont])
519 AC_SUBST([freetype_cflags])
520 AC_SUBST([freetype_libs])
522 AC_ARG_ENABLE([efiemu],
523 [AS_HELP_STRING([--enable-efiemu],
524 [build and install the efiemu runtimes])])
525 AC_SUBST([enable_efiemu])
530 if test x"$link_dir" = xyes ; then
531 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
532 include/grub/machine:include/grub/$target_cpu/$platform])
534 mkdir -p include/grub 2>/dev/null
535 rm -rf include/grub/cpu
536 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
537 rm -rf include/grub/machine
538 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
540 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
541 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])