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 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
296 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
297 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
298 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
301 TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
302 TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
307 AC_SUBST(TARGET_IMG_LDSCRIPT)
308 AC_SUBST(TARGET_IMG_LDFLAGS)
309 AC_SUBST(TARGET_IMG_CFLAGS)
311 # For platforms where ELF is not the default link format.
312 AC_MSG_CHECKING([for command to convert module to ELF format])
314 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
317 AC_SUBST(TARGET_OBJ2ELF)
318 AC_MSG_RESULT([$TARGET_OBJ2ELF])
321 if test "x$target_m32" = x1; then
323 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
324 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
325 TARGET_MODULE_FORMAT="elf32"
328 if test "x$target_m64" = x1; then
330 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
331 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
332 TARGET_MODULE_FORMAT="elf64"
335 if test "$target_cpu"-"$platform" = x86_64-efi; then
336 # Use large model to support 4G memory
337 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
339 CFLAGS="$CFLAGS -m64 -mcmodel=large"
340 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
341 [grub_cv_cc_mcmodel=yes],
342 [grub_cv_cc_mcmodel=no])
344 if test "x$grub_cv_cc_mcmodel" = xno; then
345 CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
346 TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
347 AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
349 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
352 # EFI writes to stack below %rsp, we must not use the red zone
353 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
354 CFLAGS="$CFLAGS -m64 -mno-red-zone"
355 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
356 [grub_cv_cc_no_red_zone=yes],
357 [grub_cv_cc_no_red_zone=no])
359 if test "x$grub_cv_cc_no_red_zone" = xno; then
360 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
363 TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
370 # Need __enable_execute_stack() for nested function trampolines?
371 grub_CHECK_ENABLE_EXECUTE_STACK
373 # Smashing stack protector.
374 grub_CHECK_STACK_PROTECTOR
375 # Need that, because some distributions ship compilers that include
376 # `-fstack-protector' in the default specs.
377 if test "x$ssp_possible" = xyes; then
378 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
380 grub_CHECK_STACK_ARG_PROBE
381 # Cygwin's GCC uses alloca() to probe the stackframe on static
382 # stack allocations above some threshold.
383 if test x"$sap_possible" = xyes; then
384 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
387 AC_SUBST(TARGET_CFLAGS)
388 AC_SUBST(TARGET_MODULE_FORMAT)
390 AC_SUBST(TARGET_APPLE_CC)
391 AC_SUBST(TARGET_ASFLAGS)
392 AC_SUBST(TARGET_CPPFLAGS)
393 AC_SUBST(TARGET_LDFLAGS)
395 # Set them to their new values for the tests below.
397 if test "x$TARGET_APPLE_CC" = x1 ; then
398 CFLAGS="$TARGET_CFLAGS -nostdlib"
400 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
402 CPPFLAGS="$TARGET_CPPFLAGS"
403 LDFLAGS="$TARGET_LDFLAGS"
405 # Defined in aclocal.m4.
407 if test "x$TARGET_APPLE_CC" != x1 ; then
408 grub_PROG_OBJCOPY_ABSOLUTE
410 grub_PROG_LD_BUILD_ID_NONE
412 if test "x$target_cpu" = xi386; then
413 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
414 # Check symbols provided by linker script.
415 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
417 if test "x$TARGET_APPLE_CC" != x1 ; then
418 grub_CHECK_BSS_START_SYMBOL
419 grub_CHECK_END_SYMBOL
421 CFLAGS="$TARGET_CFLAGS"
422 grub_I386_ASM_PREFIX_REQUIREMENT
424 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
426 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
429 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
430 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
432 #define NESTED_FUNC_ATTR
438 CPPFLAGS="$tmp_CPPFLAGS"
439 LDFLAGS="$tmp_LDFLAGS"
446 # Memory manager debugging.
447 AC_ARG_ENABLE([mm-debug],
448 AS_HELP_STRING([--enable-mm-debug],
449 [include memory manager debugging]),
450 [AC_DEFINE([MM_DEBUG], [1],
451 [Define to 1 if you enable memory manager debugging.])])
453 AC_ARG_ENABLE([grub-emu],
454 [AS_HELP_STRING([--enable-grub-emu],
455 [build and install the `grub-emu' debugging utility])])
456 AC_ARG_ENABLE([grub-emu-usb],
457 [AS_HELP_STRING([--enable-grub-emu-usb],
458 [build and install the `grub-emu' debugging utility with USB support])])
459 [if [ x"$enable_grub_emu" = xyes ]; then
460 # Check for curses libraries.]
461 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
462 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
463 [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
464 AC_SUBST([LIBCURSES])
466 [# Check for headers.]
467 AC_CHECK_HEADERS([ncurses/curses.h], [],
468 [AC_CHECK_HEADERS([ncurses.h], [],
469 [AC_CHECK_HEADERS([curses.h], [],
470 [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
472 [if [ x"$enable_grub_emu_usb" = xyes ]; then
473 # Check for libusb libraries.]
474 AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
475 [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
478 [# Check for headers.]
479 AC_CHECK_HEADERS([usb.h], [],
480 [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
483 AC_SUBST([enable_grub_emu])
484 AC_SUBST([enable_grub_emu_usb])
486 AC_ARG_ENABLE([grub-fstest],
487 [AS_HELP_STRING([--enable-grub-fstest],
488 [build and install the `grub-fstest' debugging utility])])
489 AC_SUBST([enable_grub_fstest])
491 AC_ARG_ENABLE([grub-pe2elf],
492 [AS_HELP_STRING([--enable-grub-pe2elf],
493 [build and install the `grub-pe2elf' conversion utility])])
494 AC_SUBST([enable_grub_pe2elf])
496 AC_ARG_ENABLE([grub-mkfont],
497 [AS_HELP_STRING([--enable-grub-mkfont],
498 [build and install the `grub-mkfont' utility])])
499 if test x"$enable_grub_mkfont" = xyes ; then
500 # Check for freetype libraries.
501 AC_CHECK_PROGS([FREETYPE], [freetype-config])
502 if test "x$FREETYPE" = x ; then
503 AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
505 freetype_cflags=`freetype-config --cflags`
506 freetype_libs=`freetype-config --libs`
508 AC_SUBST([enable_grub_mkfont])
509 AC_SUBST([freetype_cflags])
510 AC_SUBST([freetype_libs])
512 AC_ARG_ENABLE([efiemu],
513 [AS_HELP_STRING([--enable-efiemu],
514 [build and install the efiemu runtimes])])
515 AC_SUBST([enable_efiemu])
520 if test x"$link_dir" = xyes ; then
521 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
522 include/grub/machine:include/grub/$target_cpu/$platform])
524 mkdir -p include/grub 2>/dev/null
525 rm -rf include/grub/cpu
526 cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
527 rm -rf include/grub/machine
528 cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
530 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
531 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])