2009-06-28 Pavel Roskin <proski@gnu.org>
[grub2/bean.git] / configure.ac
blobcf1b197a57e1f5d8e425d14da5b9ccc6a99898db
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   i386-qemu) ;;
89   powerpc-ieee1275) ;;
90   sparc64-ieee1275) ;;
91   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
92 esac
94 case "$target_cpu" in
95   i386 | powerpc) target_m32=1 ;;
96   x86_64 | sparc64) target_m64=1 ;;
97 esac
99 case "$host_os" in
100   mingw32) host_os=cygwin ;;
101 esac
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).
106 case "$host_os" in
107   gnu*)                         host_kernel=hurd ;;
108   linux*)                       host_kernel=linux ;;
109   freebsd* | kfreebsd*-gnu)     host_kernel=freebsd ;;
110   cygwin)                       host_kernel=windows ;;
111 esac
113 AC_SUBST(host_cpu)
114 AC_SUBST(host_os)
115 AC_SUBST(host_kernel)
117 AC_SUBST(target_cpu)
118 AC_SUBST(platform)
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])
139     break
140   fi
141 done
143 AC_PROG_INSTALL
144 AC_PROG_AWK
145 AC_PROG_MAKE_SET
147 # These are not a "must".
148 AC_PATH_PROG(RUBY, ruby)
149 AC_PATH_PROG(HELP2MAN, help2man)
152 # Checks for host programs.
155 AC_PROG_CC
156 # Must be GCC.
157 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
159 AC_GNU_SOURCE
160 AC_SYS_LARGEFILE
162 # Identify characteristics of the host architecture.
163 AC_C_BIGENDIAN
164 AC_CHECK_SIZEOF(void *)
165 AC_CHECK_SIZEOF(long)
167 grub_apple_cc
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
175   AC_ARG_ENABLE([lzo],
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])])])])
186     AC_SUBST([LIBLZO])
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])
193   [else]
194     AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
195   [fi]
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"
218 else
219   if test "x$TARGET_CC" = x; then
220     TARGET_CC=$CC
221   fi
222   AC_CHECK_TOOL(OBJCOPY, objcopy)
223   AC_CHECK_TOOL(STRIP, strip)
224   AC_CHECK_TOOL(NM, nm)
226 AC_SUBST(TARGET_CC)
229 # Test the C compiler for the target environment.
230 tmp_CC="$CC"
231 tmp_CFLAGS="$CFLAGS"
232 tmp_LDFLAGS="$LDFLAGS"
233 tmp_CPPFLAGS="$CPPFLAGS"
234 tmp_LIBS="$LIBS"
235 CC="$TARGET_CC"
236 CFLAGS="$TARGET_CFLAGS"
237 CPPFLAGS="$TARGET_CPPFLAGS"
238 LDFLAGS="$TARGET_LDFLAGS"
239 LIBS=""
241 if test "x$TARGET_CFLAGS" = x; then
242   # debug flags.
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, [
248     CFLAGS=-Os
249     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
250                       [grub_cv_cc_Os=yes],
251                       [grub_cv_cc_Os=no])
252   ])
253   if test "x$grub_cv_cc_Os" = xyes; then
254     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
255   else
256     TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
257   fi
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])
266     ])
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"
270     else
271       TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
272     fi
273   fi
276 grub_apple_target_cc
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"
281   TARGET_APPLE_CC=1
282   AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
283   if test "x$OBJCONV" = x ; then
284      AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
285   fi
286   if test "x$OBJCONV" = x ; then
287     AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
288   fi
289   TARGET_IMG_LDSCRIPT=
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,'
293 else
294   TARGET_APPLE_CC=0
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"
300 else
301   TARGET_IMG_LDSCRIPT=
302   TARGET_IMG_LDFLAGS='-Wl,-N  -Wl,-Ttext,'
303   TARGET_IMG_LDFLAGS_AC='-Wl,-N  -Wl,-Ttext,'
305 TARGET_IMG_CFLAGS=
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])
314 case "${host_os}" in
315   cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
316   *) ;;
317 esac
318 AC_SUBST(TARGET_OBJ2ELF)
319 AC_MSG_RESULT([$TARGET_OBJ2ELF])
322 if test "x$target_m32" = x1; then
323   # Force 32-bit mode.
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
330   # Force 64-bit mode.
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, [
339     SAVED_CFLAGS=$CFLAGS
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])
344   ])
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])
349   else
350     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
351   fi
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])
359   ])
360   if test "x$grub_cv_cc_no_red_zone" = xno; then
361     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
362   fi
364   TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
368 # Compiler features.
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)
390 AC_SUBST(OBJCONV)
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.
397 CC="$TARGET_CC"
398 if test "x$TARGET_APPLE_CC" = x1 ; then
399 CFLAGS="$TARGET_CFLAGS -nostdlib"
400 else
401 CFLAGS="$TARGET_CFLAGS -nostdlib -Wl,--defsym,___main=0x8100"
403 CPPFLAGS="$TARGET_CPPFLAGS"
404 LDFLAGS="$TARGET_LDFLAGS"
406 # Defined in aclocal.m4.
407 grub_PROG_TARGET_CC
408 if test "x$TARGET_APPLE_CC" != x1 ; then
409 grub_PROG_OBJCOPY_ABSOLUTE
411 grub_PROG_LD_BUILD_ID_NONE
412 grub_ASM_USCORE
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"
417   fi
418   if test "x$TARGET_APPLE_CC" != x1 ; then
419     grub_CHECK_BSS_START_SYMBOL
420     grub_CHECK_END_SYMBOL
421   fi
422   CFLAGS="$TARGET_CFLAGS"
423   grub_I386_ASM_PREFIX_REQUIREMENT
424   grub_I386_ASM_ADDR32
425   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
426 else
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)))
432 #else
433 #define NESTED_FUNC_ATTR
434 #endif])
436 # Restore the flags.
437 CC="$tmp_CC"
438 CFLAGS="$tmp_CFLAGS"
439 CPPFLAGS="$tmp_CPPFLAGS"
440 LDFLAGS="$tmp_LDFLAGS"
441 LIBS="$tmp_LIBS"
444 # Check for options.
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])])
477     AC_SUBST([LIBUSB])
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])])
482   [fi]
483 [fi]
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'])
505   fi
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])
517 AC_SUBST(ASFLAGS)
519 # Output files.
520 grub_CHECK_LINK_DIR
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])
524 else
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])
533 AC_OUTPUT