Merge branch 'mainline' into zfs
[grub2/phcoder.git] / configure.ac
blob6a6d8453f7deb659c05656287e4a43edc84920f8
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
12 # PARTICULAR PURPOSE.
14 dnl This configure script is complicated, because GRUB needs to deal
15 dnl with three potentially different types:
16 dnl
17 dnl   build  -- the environment for building GRUB
18 dnl   host   -- the environment for running utilities
19 dnl   target -- the environment for running GRUB
20 dnl
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.
25 dnl
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
31 dnl type.
34 AC_INIT([GRUB],[1.96],[bug-grub@gnu.org])
35 AC_PREREQ(2.59)
36 AC_CONFIG_SRCDIR([include/grub/dl.h])
37 AC_CONFIG_HEADER([config.h])
39 # Checks for host and target systems.
40 AC_CANONICAL_HOST
41 AC_CANONICAL_TARGET
43 # Program name transformations
44 AC_ARG_PROGRAM
46 case "$target_cpu" in
47   i[[3456]]86) target_cpu=i386 ;;
48 esac
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"]) ;;
66   esac
67 else
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
74     x86_64-efi) ;;
75     x86_64-*) target_cpu=i386 ;;
76     powerpc64-ieee1275) target_cpu=powerpc ;;
77   esac
80 # Check if the platform is supported, make final adjustments.
81 case "$target_cpu"-"$platform" in
82   i386-efi) ;;
83   x86_64-efi) ;;
84   i386-pc) ;;
85   i386-coreboot) ;;
86   i386-linuxbios) platform=coreboot ;;
87   i386-ieee1275) ;;
88   powerpc-ieee1275) ;;
89   sparc64-ieee1275) ;;
90   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
91 esac
93 case "$target_cpu" in
94   i386 | powerpc) target_m32=1 ;;
95   x86_64 | sparc64) target_m64=1 ;;
96 esac
98 case "$host_os" in
99   mingw32) host_os=cygwin ;;
100 esac
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).
105 case "$host_os" in
106   gnu*)                         host_kernel=hurd ;;
107   linux*)                       host_kernel=linux ;;
108   freebsd* | kfreebsd*-gnu)     host_kernel=freebsd ;;
109   cygwin)                       host_kernel=windows ;;
110 esac
112 AC_SUBST(host_cpu)
113 AC_SUBST(host_os)
114 AC_SUBST(host_kernel)
116 AC_SUBST(target_cpu)
117 AC_SUBST(platform)
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])
138     break
139   fi
140 done
142 AC_PROG_INSTALL
143 AC_PROG_AWK
144 AC_PROG_MAKE_SET
146 # These are not a "must".
147 AC_PATH_PROG(RUBY, ruby)
148 AC_PATH_PROG(HELP2MAN, help2man)
151 # Checks for host programs.
154 AC_PROG_CC
155 # Must be GCC.
156 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
158 AC_GNU_SOURCE
159 AC_SYS_LARGEFILE
161 # Identify characteristics of the host architecture.
162 AC_C_BIGENDIAN
163 AC_CHECK_SIZEOF(void *)
164 AC_CHECK_SIZEOF(long)
166 grub_apple_cc
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
174   AC_ARG_ENABLE([lzo],
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])])])])
185     AC_SUBST([LIBLZO])
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])
192   [else]
193     AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
194   [fi]
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"
217 else
218   if test "x$TARGET_CC" = x; then
219     TARGET_CC=$CC
220   fi
221   AC_CHECK_TOOL(OBJCOPY, objcopy)
222   AC_CHECK_TOOL(STRIP, strip)
223   AC_CHECK_TOOL(NM, nm)
225 AC_SUBST(TARGET_CC)
228 # Test the C compiler for the target environment.
229 tmp_CC="$CC"
230 tmp_CFLAGS="$CFLAGS"
231 tmp_LDFLAGS="$LDFLAGS"
232 tmp_CPPFLAGS="$CPPFLAGS"
233 tmp_LIBS="$LIBS"
234 CC="$TARGET_CC"
235 CFLAGS="$TARGET_CFLAGS"
236 CPPFLAGS="$TARGET_CPPFLAGS"
237 LDFLAGS="$TARGET_LDFLAGS"
238 LIBS=""
240 if test "x$TARGET_CFLAGS" = x; then
241   # debug flags.
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, [
247     CFLAGS=-Os
248     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
249                       [grub_cv_cc_Os=yes],
250                       [grub_cv_cc_Os=no])
251   ])
252   if test "x$grub_cv_cc_Os" = xyes; then
253     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
254   else
255     TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
256   fi
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])
265     ])
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"
269     else
270       TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
271     fi
272   fi
275 grub_apple_target_cc
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"
280   TARGET_APPLE_CC=1
281   AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
282   if test "x$OBJCONV" = x ; then
283      AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
284   fi
285   if test "x$OBJCONV" = x ; then
286     AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
287   fi
288   TARGET_IMG_LDSCRIPT=
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,'
292 else
293   TARGET_APPLE_CC=0
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"
299 else
300   TARGET_IMG_LDSCRIPT=
301   TARGET_IMG_LDFLAGS='-Wl,-N  -Wl,-Ttext,'
302   TARGET_IMG_LDFLAGS_AC='-Wl,-N  -Wl,-Ttext,'
304 TARGET_IMG_CFLAGS=
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])
313 case "${host_os}" in
314   cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
315   *) ;;
316 esac
317 AC_SUBST(TARGET_OBJ2ELF)
318 AC_MSG_RESULT([$TARGET_OBJ2ELF])
321 if test "x$target_m32" = x1; then
322   # Force 32-bit mode.
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
329   # Force 64-bit mode.
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, [
338     SAVED_CFLAGS=$CFLAGS
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])
343   ])
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])
348   else
349     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
350   fi
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])
358   ])
359   if test "x$grub_cv_cc_no_red_zone" = xno; then
360     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
361   fi
363   TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
367 # Compiler features.
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)
389 AC_SUBST(OBJCONV)
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.
396 CC="$TARGET_CC"
397 if test "x$TARGET_APPLE_CC" = x1 ; then
398 CFLAGS="$TARGET_CFLAGS -nostdlib"
399 else
400 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
402 CPPFLAGS="$TARGET_CPPFLAGS"
403 LDFLAGS="$TARGET_LDFLAGS"
405 # Defined in aclocal.m4.
406 grub_PROG_TARGET_CC
407 if test "x$TARGET_APPLE_CC" != x1 ; then
408 grub_PROG_OBJCOPY_ABSOLUTE
410 grub_PROG_LD_BUILD_ID_NONE
411 grub_ASM_USCORE
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"
416   fi
417   if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then
418     grub_CHECK_BSS_START_SYMBOL
419     grub_CHECK_END_SYMBOL
420   fi
421   CFLAGS="$TARGET_CFLAGS"
422   grub_I386_ASM_PREFIX_REQUIREMENT
423   grub_I386_ASM_ADDR32
424   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
425 else
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)))
431 #else
432 #define NESTED_FUNC_ATTR
433 #endif])
435 # Restore the flags.
436 CC="$tmp_CC"
437 CFLAGS="$tmp_CFLAGS"
438 CPPFLAGS="$tmp_CPPFLAGS"
439 LDFLAGS="$tmp_LDFLAGS"
440 LIBS="$tmp_LIBS"
443 # Check for options.
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])])
476     AC_SUBST([LIBUSB])
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])])
481   [fi]
482 [fi]
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'])
504   fi
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])
516 AC_SUBST(ASFLAGS)
518 # Output files.
519 grub_CHECK_LINK_DIR
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])
523 else
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])
532 AC_OUTPUT