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 ;;
90 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
94 i386 | powerpc) target_m32=1 ;;
95 x86_64 | sparc64) target_m64=1 ;;
99 mingw32) host_os=cygwin ;;
102 # This normalizes the names, and creates a new variable ("host_kernel")
103 # while at it, since the mapping is not always 1:1 (e.g. different OSes
104 # using the same kernel type).
106 gnu*) host_kernel=hurd ;;
107 linux*) host_kernel=linux ;;
108 freebsd* | kfreebsd*-gnu) host_kernel=freebsd ;;
109 cygwin) host_kernel=windows ;;
114 AC_SUBST(host_kernel)
120 # Checks for build programs.
123 # Although cmp is listed in the GNU Coding Standards as a command which
124 # can used directly, OpenBSD lacks cmp in the default installation.
125 AC_CHECK_PROGS([CMP], [cmp])
126 if test "x$CMP" = x; then
127 AC_MSG_ERROR([cmp is not found])
130 AC_CHECK_PROGS([YACC], [bison])
131 if test "x$YACC" = x; then
132 AC_MSG_ERROR([bison is not found])
135 for file in /usr/src/unifont.bdf ; do
136 if test -e $file ; then
137 AC_SUBST([UNIFONT_BDF], [$file])
146 # These are not a "must".
147 AC_PATH_PROG(RUBY, ruby)
148 AC_PATH_PROG(HELP2MAN, help2man)
151 # Checks for host programs.
156 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
161 # Identify characteristics of the host architecture.
163 AC_CHECK_SIZEOF(void *)
164 AC_CHECK_SIZEOF(long)
167 if test x$grub_cv_apple_cc == xyes ; then
168 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
169 ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
172 # Check LZO when compiling for the i386-pc.
173 if test "$target_cpu"-"$platform" = i386-pc; then
175 [AS_HELP_STRING([--enable-lzo],
176 [use lzo to compress kernel (default is lzma)])])
177 [if [ x"$enable_lzo" = xyes ]; then
178 # There are three possibilities. LZO version 2 installed with the name
179 # liblzo2, with the name liblzo, and LZO version 1.]
180 AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
181 AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
182 [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
183 [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
184 [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
186 [LIBS="$LIBS $LIBLZO"]
187 AC_CHECK_FUNC([lzo1x_999_compress], ,
188 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
190 [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
191 AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
193 AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
195 AC_SUBST([enable_lzo])
198 # Check for functions.
199 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
202 # Check for target programs.
205 # Find tools for the target.
206 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
207 tmp_ac_tool_prefix="$ac_tool_prefix"
208 ac_tool_prefix=$target_alias-
210 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
211 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
212 AC_CHECK_TOOL(OBJCOPY, objcopy)
213 AC_CHECK_TOOL(STRIP, strip)
214 AC_CHECK_TOOL(NM, nm)
216 ac_tool_prefix="$tmp_ac_tool_prefix"
218 if test "x$TARGET_CC" = x; then
221 AC_CHECK_TOOL(OBJCOPY, objcopy)
222 AC_CHECK_TOOL(STRIP, strip)
223 AC_CHECK_TOOL(NM, nm)
228 # Test the C compiler for the target environment.
231 tmp_LDFLAGS="$LDFLAGS"
232 tmp_CPPFLAGS="$CPPFLAGS"
235 CFLAGS="$TARGET_CFLAGS"
236 CPPFLAGS="$TARGET_CPPFLAGS"
237 LDFLAGS="$TARGET_LDFLAGS"
240 if test "x$TARGET_CFLAGS" = x; then
242 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
243 -Wundef -Wstrict-prototypes -g"
245 # optimization flags.
246 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
248 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
252 if test "x$grub_cv_cc_Os" = xyes; then
253 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
255 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
258 # Force no alignment to save space on i386.
259 if test "x$target_cpu" = xi386; then
260 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
261 CFLAGS="$CFLAGS -falign-loops=1"
262 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
263 [grub_cv_cc_falign_loop=yes],
264 [grub_cv_cc_falign_loop=no])
267 if test "x$grub_cv_cc_falign_loop" = xyes; then
268 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
270 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
276 if test x$grub_cv_apple_target_cc == xyes ; then
277 TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
278 CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
279 TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
281 AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
282 if test "x$OBJCONV" = x ; then
283 AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
285 if test "x$OBJCONV" = x ; then
286 AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
289 TARGET_IMG_CFLAGS="-static"
290 TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
291 TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
294 # Use linker script if present, otherwise use builtin -N script.
295 AC_MSG_CHECKING([for option to link raw image])
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)
311 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
313 # For platforms where ELF is not the default link format.
314 AC_MSG_CHECKING([for command to convert module to ELF format])
316 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
319 AC_SUBST(TARGET_OBJ2ELF)
320 AC_MSG_RESULT([$TARGET_OBJ2ELF])
323 if test "x$target_m32" = x1; then
325 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
326 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
327 TARGET_MODULE_FORMAT="elf32"
330 if test "x$target_m64" = x1; then
332 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
333 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
334 TARGET_MODULE_FORMAT="elf64"
337 if test "$target_cpu"-"$platform" = x86_64-efi; then
338 # Use large model to support 4G memory
339 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
341 CFLAGS="$CFLAGS -m64 -mcmodel=large"
342 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
343 [grub_cv_cc_mcmodel=yes],
344 [grub_cv_cc_mcmodel=no])
346 if test "x$grub_cv_cc_mcmodel" = xno; then
347 CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
348 TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
349 AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
351 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
354 # EFI writes to stack below %rsp, we must not use the red zone
355 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
356 CFLAGS="$CFLAGS -m64 -mno-red-zone"
357 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
358 [grub_cv_cc_no_red_zone=yes],
359 [grub_cv_cc_no_red_zone=no])
361 if test "x$grub_cv_cc_no_red_zone" = xno; then
362 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
365 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
372 # Need __enable_execute_stack() for nested function trampolines?
373 grub_CHECK_ENABLE_EXECUTE_STACK
375 # Smashing stack protector.
376 grub_CHECK_STACK_PROTECTOR
377 # Need that, because some distributions ship compilers that include
378 # `-fstack-protector' in the default specs.
379 if test "x$ssp_possible" = xyes; then
380 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
382 grub_CHECK_STACK_ARG_PROBE
383 # Cygwin's GCC uses alloca() to probe the stackframe on static
384 # stack allocations above some threshold.
385 if test x"$sap_possible" = xyes; then
386 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
389 AC_SUBST(TARGET_CFLAGS)
390 AC_SUBST(TARGET_MODULE_FORMAT)
392 AC_SUBST(TARGET_APPLE_CC)
393 AC_SUBST(TARGET_ASFLAGS)
394 AC_SUBST(TARGET_CPPFLAGS)
395 AC_SUBST(TARGET_LDFLAGS)
397 # Set them to their new values for the tests below.
399 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
400 CPPFLAGS="$TARGET_CPPFLAGS"
401 LDFLAGS="$TARGET_LDFLAGS"
403 # Defined in aclocal.m4.
405 if test "x$TARGET_APPLE_CC" != x1 ; then
406 grub_PROG_OBJCOPY_ABSOLUTE
408 grub_PROG_LD_BUILD_ID_NONE
410 if test "x$target_cpu" = xi386; then
411 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
412 # Check symbols provided by linker script.
413 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
415 if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then
416 grub_CHECK_BSS_START_SYMBOL
417 grub_CHECK_END_SYMBOL
419 CFLAGS="$TARGET_CFLAGS"
420 grub_I386_ASM_PREFIX_REQUIREMENT
422 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
424 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
427 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
428 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
430 #define NESTED_FUNC_ATTR
436 CPPFLAGS="$tmp_CPPFLAGS"
437 LDFLAGS="$tmp_LDFLAGS"
444 # Memory manager debugging.
445 AC_ARG_ENABLE([mm-debug],
446 AS_HELP_STRING([--enable-mm-debug],
447 [include memory manager debugging]),
448 [AC_DEFINE([MM_DEBUG], [1],
449 [Define to 1 if you enable memory manager debugging.])])
451 AC_ARG_ENABLE([grub-emu],
452 [AS_HELP_STRING([--enable-grub-emu],
453 [build and install the `grub-emu' debugging utility])])
454 AC_ARG_ENABLE([grub-emu-usb],
455 [AS_HELP_STRING([--enable-grub-emu-usb],
456 [build and install the `grub-emu' debugging utility with USB support])])
457 [if [ x"$enable_grub_emu" = xyes ]; then
458 # Check for curses libraries.]
459 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
460 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
461 [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
462 AC_SUBST([LIBCURSES])
464 [# Check for headers.]
465 AC_CHECK_HEADERS([ncurses/curses.h], [],
466 [AC_CHECK_HEADERS([ncurses.h], [],
467 [AC_CHECK_HEADERS([curses.h], [],
468 [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
470 [if [ x"$enable_grub_emu_usb" = xyes ]; then
471 # Check for libusb libraries.]
472 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
473 [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
476 [# Check for headers.]
477 AC_CHECK_HEADERS([usb.h], [],
478 [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
481 AC_SUBST([enable_grub_emu])
482 AC_SUBST([enable_grub_emu_usb])
484 AC_ARG_ENABLE([grub-fstest],
485 [AS_HELP_STRING([--enable-grub-fstest],
486 [build and install the `grub-fstest' debugging utility])])
487 AC_SUBST([enable_grub_fstest])
489 AC_ARG_ENABLE([grub-pe2elf],
490 [AS_HELP_STRING([--enable-grub-pe2elf],
491 [build and install the `grub-pe2elf' conversion utility])])
492 AC_SUBST([enable_grub_pe2elf])
494 AC_ARG_ENABLE([grub-mkfont],
495 [AS_HELP_STRING([--enable-grub-mkfont],
496 [build and install the `grub-mkfont' utility])])
497 if test x"$enable_grub_mkfont" = xyes ; then
498 # Check for freetype libraries.
499 AC_CHECK_PROGS([FREETYPE], [freetype-config])
500 if test "x$FREETYPE" = x ; then
501 AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
503 freetype_cflags=`freetype-config --cflags`
504 freetype_libs=`freetype-config --libs`
506 AC_SUBST([enable_grub_mkfont])
507 AC_SUBST([freetype_cflags])
508 AC_SUBST([freetype_libs])
510 AC_ARG_ENABLE([efiemu],
511 [AS_HELP_STRING([--enable-efiemu],
512 [build and install the efiemu runtimes])])
513 AC_SUBST([enable_efiemu])
518 if test x"$link_dir" = xyes ; then
519 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
520 include/grub/machine:include/grub/$target_cpu/$platform])
522 mkdir -p include/grub 2>/dev/null
523 rm -rf include/grub/cpu
524 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
525 rm -rf include/grub/machine
526 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
528 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
529 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])