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 i[[3456]]86) target_cpu=i386 ;;
50 # Specify the platform (such as firmware).
51 AC_ARG_WITH([platform],
52 AS_HELP_STRING([--with-platform=PLATFORM],
53 [select the host platform [[guessed]]]))
55 # Guess the platform if not specified.
56 if test "x$with_platform" = x; then
57 case "$target_cpu"-"$target_vendor" in
58 i386-apple) platform=efi ;;
59 i386-*) platform=pc ;;
60 x86_64-apple) platform=efi ;;
61 x86_64-*) platform=pc ;;
62 powerpc-*) platform=ieee1275 ;;
63 powerpc64-*) platform=ieee1275 ;;
64 sparc64-*) platform=ieee1275 ;;
65 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
68 platform="$with_platform"
71 # Adjust CPU unless target was explicitly specified.
72 if test -z "$target_alias"; then
73 case "$target_cpu"-"$platform" in
75 x86_64-*) target_cpu=i386 ;;
76 powerpc64-ieee1275) target_cpu=powerpc ;;
80 # Check if the platform is supported, make final adjustments.
81 case "$target_cpu"-"$platform" in
86 i386-linuxbios) platform=coreboot ;;
91 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
95 i386 | powerpc) target_m32=1 ;;
96 x86_64 | sparc64) target_m64=1 ;;
100 mingw32) host_os=cygwin ;;
103 # This normalizes the names, and creates a new variable ("host_kernel")
104 # while at it, since the mapping is not always 1:1 (e.g. different OSes
105 # using the same kernel type).
107 gnu*) host_kernel=hurd ;;
108 linux*) host_kernel=linux ;;
109 freebsd* | kfreebsd*-gnu) host_kernel=freebsd ;;
110 cygwin) host_kernel=windows ;;
115 AC_SUBST(host_kernel)
121 # Checks for build programs.
124 # Although cmp is listed in the GNU Coding Standards as a command which
125 # can used directly, OpenBSD lacks cmp in the default installation.
126 AC_CHECK_PROGS([CMP], [cmp])
127 if test "x$CMP" = x; then
128 AC_MSG_ERROR([cmp is not found])
131 AC_CHECK_PROGS([YACC], [bison])
132 if test "x$YACC" = x; then
133 AC_MSG_ERROR([bison is not found])
136 for file in /usr/src/unifont.bdf ; do
137 if test -e $file ; then
138 AC_SUBST([UNIFONT_BDF], [$file])
147 # These are not a "must".
148 AC_PATH_PROG(RUBY, ruby)
149 AC_PATH_PROG(HELP2MAN, help2man)
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 # Check LZO when compiling for the i386-pc.
174 if test "$target_cpu"-"$platform" = i386-pc; then
176 [AS_HELP_STRING([--enable-lzo],
177 [use lzo to compress kernel (default is lzma)])])
178 [if [ x"$enable_lzo" = xyes ]; then
179 # There are three possibilities. LZO version 2 installed with the name
180 # liblzo2, with the name liblzo, and LZO version 1.]
181 AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
182 AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
183 [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
184 [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
185 [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
187 [LIBS="$LIBS $LIBLZO"]
188 AC_CHECK_FUNC([lzo1x_999_compress], ,
189 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
191 [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
192 AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
194 AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
196 AC_SUBST([enable_lzo])
199 # Check for functions.
200 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
203 # Check for target programs.
206 # Find tools for the target.
207 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
208 tmp_ac_tool_prefix="$ac_tool_prefix"
209 ac_tool_prefix=$target_alias-
211 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
212 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
213 AC_CHECK_TOOL(OBJCOPY, objcopy)
214 AC_CHECK_TOOL(STRIP, strip)
215 AC_CHECK_TOOL(NM, nm)
217 ac_tool_prefix="$tmp_ac_tool_prefix"
219 if test "x$TARGET_CC" = x; then
222 AC_CHECK_TOOL(OBJCOPY, objcopy)
223 AC_CHECK_TOOL(STRIP, strip)
224 AC_CHECK_TOOL(NM, nm)
229 # Test the C compiler for the target environment.
232 tmp_LDFLAGS="$LDFLAGS"
233 tmp_CPPFLAGS="$CPPFLAGS"
236 CFLAGS="$TARGET_CFLAGS"
237 CPPFLAGS="$TARGET_CPPFLAGS"
238 LDFLAGS="$TARGET_LDFLAGS"
241 if test "x$TARGET_CFLAGS" = x; then
243 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
244 -Wundef -Wstrict-prototypes -g"
246 # optimization flags.
247 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
249 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
253 if test "x$grub_cv_cc_Os" = xyes; then
254 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
256 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
259 # Force no alignment to save space on i386.
260 if test "x$target_cpu" = xi386; then
261 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
262 CFLAGS="$CFLAGS -falign-loops=1"
263 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
264 [grub_cv_cc_falign_loop=yes],
265 [grub_cv_cc_falign_loop=no])
268 if test "x$grub_cv_cc_falign_loop" = xyes; then
269 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
271 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
277 if test x$grub_cv_apple_target_cc = xyes ; then
278 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
279 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
280 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
282 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
283 if test "x$OBJCONV" = x ; then
284 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
286 if test "x$OBJCONV" = x ; then
287 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
290 TARGET_IMG_CFLAGS="-static"
291 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
292 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
295 # Use linker script if present, otherwise use builtin -N script.
296 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
297 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
298 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
299 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
302 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
303 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
308 AC_SUBST(TARGET_IMG_LDSCRIPT)
309 AC_SUBST(TARGET_IMG_LDFLAGS)
310 AC_SUBST(TARGET_IMG_CFLAGS)
312 # For platforms where ELF is not the default link format.
313 AC_MSG_CHECKING([for command to convert module to ELF format])
315 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
318 AC_SUBST(TARGET_OBJ2ELF)
319 AC_MSG_RESULT([$TARGET_OBJ2ELF])
322 if test "x$target_m32" = x1; then
324 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
325 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
326 TARGET_MODULE_FORMAT="elf32"
329 if test "x$target_m64" = x1; then
331 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
332 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
333 TARGET_MODULE_FORMAT="elf64"
336 if test "$target_cpu"-"$platform" = x86_64-efi; then
337 # Use large model to support 4G memory
338 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
340 CFLAGS="$CFLAGS -m64 -mcmodel=large"
341 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
342 [grub_cv_cc_mcmodel=yes],
343 [grub_cv_cc_mcmodel=no])
345 if test "x$grub_cv_cc_mcmodel" = xno; then
346 CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
347 TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
348 AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
350 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
353 # EFI writes to stack below %rsp, we must not use the red zone
354 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
355 CFLAGS="$CFLAGS -m64 -mno-red-zone"
356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
357 [grub_cv_cc_no_red_zone=yes],
358 [grub_cv_cc_no_red_zone=no])
360 if test "x$grub_cv_cc_no_red_zone" = xno; then
361 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
364 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
371 # Need __enable_execute_stack() for nested function trampolines?
372 grub_CHECK_ENABLE_EXECUTE_STACK
374 # Smashing stack protector.
375 grub_CHECK_STACK_PROTECTOR
376 # Need that, because some distributions ship compilers that include
377 # `-fstack-protector' in the default specs.
378 if test "x$ssp_possible" = xyes; then
379 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
381 grub_CHECK_STACK_ARG_PROBE
382 # Cygwin's GCC uses alloca() to probe the stackframe on static
383 # stack allocations above some threshold.
384 if test x"$sap_possible" = xyes; then
385 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
388 AC_SUBST(TARGET_CFLAGS)
389 AC_SUBST(TARGET_MODULE_FORMAT)
391 AC_SUBST(TARGET_APPLE_CC)
392 AC_SUBST(TARGET_ASFLAGS)
393 AC_SUBST(TARGET_CPPFLAGS)
394 AC_SUBST(TARGET_LDFLAGS)
396 # Set them to their new values for the tests below.
398 if test "x$TARGET_APPLE_CC" = x1 ; then
399 CFLAGS="$TARGET_CFLAGS -nostdlib"
401 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
403 CPPFLAGS="$TARGET_CPPFLAGS"
404 LDFLAGS="$TARGET_LDFLAGS"
406 # Defined in aclocal.m4.
408 if test "x$TARGET_APPLE_CC" != x1 ; then
409 grub_PROG_OBJCOPY_ABSOLUTE
411 grub_PROG_LD_BUILD_ID_NONE
413 if test "x$target_cpu" = xi386; then
414 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
415 # Check symbols provided by linker script.
416 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
418 if test "x$TARGET_APPLE_CC" != x1 ; then
419 grub_CHECK_BSS_START_SYMBOL
420 grub_CHECK_END_SYMBOL
422 CFLAGS="$TARGET_CFLAGS"
423 grub_I386_ASM_PREFIX_REQUIREMENT
425 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
427 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
430 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
431 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
433 #define NESTED_FUNC_ATTR
439 CPPFLAGS="$tmp_CPPFLAGS"
440 LDFLAGS="$tmp_LDFLAGS"
447 # Memory manager debugging.
448 AC_ARG_ENABLE([mm-debug],
449 AS_HELP_STRING([--enable-mm-debug],
450 [include memory manager debugging]),
451 [AC_DEFINE([MM_DEBUG], [1],
452 [Define to 1 if you enable memory manager debugging.])])
454 AC_ARG_ENABLE([grub-emu],
455 [AS_HELP_STRING([--enable-grub-emu],
456 [build and install the `grub-emu' debugging utility])])
457 AC_ARG_ENABLE([grub-emu-usb],
458 [AS_HELP_STRING([--enable-grub-emu-usb],
459 [build and install the `grub-emu' debugging utility with USB support])])
460 [if [ x"$enable_grub_emu" = xyes ]; then
461 # Check for curses libraries.]
462 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
463 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
464 [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
465 AC_SUBST([LIBCURSES])
467 [# Check for headers.]
468 AC_CHECK_HEADERS([ncurses/curses.h], [],
469 [AC_CHECK_HEADERS([ncurses.h], [],
470 [AC_CHECK_HEADERS([curses.h], [],
471 [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
473 [if [ x"$enable_grub_emu_usb" = xyes ]; then
474 # Check for libusb libraries.]
475 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
476 [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
479 [# Check for headers.]
480 AC_CHECK_HEADERS([usb.h], [],
481 [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
484 AC_SUBST([enable_grub_emu])
485 AC_SUBST([enable_grub_emu_usb])
487 AC_ARG_ENABLE([grub-fstest],
488 [AS_HELP_STRING([--enable-grub-fstest],
489 [build and install the `grub-fstest' debugging utility])])
490 AC_SUBST([enable_grub_fstest])
492 AC_ARG_ENABLE([grub-pe2elf],
493 [AS_HELP_STRING([--enable-grub-pe2elf],
494 [build and install the `grub-pe2elf' conversion utility])])
495 AC_SUBST([enable_grub_pe2elf])
497 AC_ARG_ENABLE([grub-mkfont],
498 [AS_HELP_STRING([--enable-grub-mkfont],
499 [build and install the `grub-mkfont' utility])])
500 if test x"$enable_grub_mkfont" = xyes ; then
501 # Check for freetype libraries.
502 AC_CHECK_PROGS([FREETYPE], [freetype-config])
503 if test "x$FREETYPE" = x ; then
504 AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
506 freetype_cflags=`freetype-config --cflags`
507 freetype_libs=`freetype-config --libs`
509 AC_SUBST([enable_grub_mkfont])
510 AC_SUBST([freetype_cflags])
511 AC_SUBST([freetype_libs])
513 AC_ARG_ENABLE([efiemu],
514 [AS_HELP_STRING([--enable-efiemu],
515 [build and install the efiemu runtimes])])
516 AC_SUBST([enable_efiemu])
521 if test x"$link_dir" = xyes ; then
522 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
523 include/grub/machine:include/grub/$target_cpu/$platform])
525 mkdir -p include/grub 2>/dev/null
526 rm -rf include/grub/cpu
527 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
528 rm -rf include/grub/machine
529 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
531 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
532 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])