2009-06-05 Colin D Bennett <colin@gibibit.com>
[grub2/phcoder.git] / configure.ac
blobe448c2fd1b3a00b6574e48ef47b5dd2d3bb04cd8
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 "$host_cpu" in
47   powerpc64) host_m32=1 ;;
48 esac
50 case "$target_cpu" in
51   i[[3456]]86) target_cpu=i386 ;;
52 esac
54 # Specify the platform (such as firmware).
55 AC_ARG_WITH([platform],
56             AS_HELP_STRING([--with-platform=PLATFORM],
57                            [select the host platform [[guessed]]]))
59 # Guess the platform if not specified.
60 if test "x$with_platform" = x; then
61   case "$target_cpu"-"$target_vendor" in
62     i386-apple) platform=efi ;;
63     i386-*) platform=pc ;;
64     x86_64-apple) platform=efi ;;
65     x86_64-*) platform=pc ;;
66     powerpc-*) platform=ieee1275 ;;
67     powerpc64-*) platform=ieee1275 ;;
68     sparc64-*) platform=ieee1275 ;;
69     *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
70   esac
71 else
72   platform="$with_platform"
75 # Adjust CPU unless target was explicitly specified.
76 if test -z "$target_alias"; then
77   case "$target_cpu"-"$platform" in
78     x86_64-efi) ;;
79     x86_64-*) target_cpu=i386 ;;
80     powerpc64-ieee1275) target_cpu=powerpc ;;
81   esac
84 # Check if the platform is supported, make final adjustments.
85 case "$target_cpu"-"$platform" in
86   i386-efi) ;;
87   x86_64-efi) ;;
88   i386-pc) ;;
89   i386-coreboot) ;;
90   i386-linuxbios) platform=coreboot ;;
91   i386-ieee1275) ;;
92   powerpc-ieee1275) ;;
93   sparc64-ieee1275) ;;
94   *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
95 esac
97 case "$target_cpu" in
98   i386 | powerpc) target_m32=1 ;;
99   x86_64 | sparc64) target_m64=1 ;;
100 esac
102 case "$host_os" in
103   mingw32) host_os=cygwin ;;
104 esac
106 # This normalizes the names, and creates a new variable ("host_kernel")
107 # while at it, since the mapping is not always 1:1 (e.g. different OSes
108 # using the same kernel type).
109 case "$host_os" in
110   gnu*)                         host_kernel=hurd ;;
111   linux*)                       host_kernel=linux ;;
112   freebsd* | kfreebsd*-gnu)     host_kernel=freebsd ;;
113   cygwin)                       host_kernel=windows ;;
114 esac
116 AC_SUBST(host_cpu)
117 AC_SUBST(host_os)
118 AC_SUBST(host_kernel)
120 AC_SUBST(target_cpu)
121 AC_SUBST(platform)
124 # Checks for build programs.
127 # Although cmp is listed in the GNU Coding Standards as a command which
128 # can used directly, OpenBSD lacks cmp in the default installation.
129 AC_CHECK_PROGS([CMP], [cmp])
130 if test "x$CMP" = x; then
131   AC_MSG_ERROR([cmp is not found])
134 AC_CHECK_PROGS([YACC], [bison])
135 if test "x$YACC" = x; then
136   AC_MSG_ERROR([bison is not found])
139 for file in /usr/src/unifont.bdf ; do
140   if test -e $file ; then
141     AC_SUBST([UNIFONT_BDF], [$file])
142     break
143   fi
144 done
146 AC_PROG_INSTALL
147 AC_PROG_AWK
148 AC_PROG_MAKE_SET
150 # These are not a "must".
151 AC_PATH_PROG(RUBY, ruby)
152 AC_PATH_PROG(HELP2MAN, help2man)
155 # Checks for host programs.
158 AC_PROG_CC
159 # Must be GCC.
160 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
162 AC_GNU_SOURCE
163 AC_SYS_LARGEFILE
165 # Identify characteristics of the host architecture.
166 AC_C_BIGENDIAN
167 AC_CHECK_SIZEOF(void *)
168 AC_CHECK_SIZEOF(long)
170 grub_apple_cc
171 if test x$grub_cv_apple_cc == xyes ; then
172   CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
173   ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
175 if test "x$host_m32" = x1; then
176   # Force 32-bit mode.
177   CFLAGS="$CFLAGS -m32"
178   LDFLAGS="$LDFLAGS -m32"
181 # Check LZO when compiling for the i386-pc.
182 if test "$target_cpu"-"$platform" = i386-pc; then
183   AC_ARG_ENABLE([lzo],
184               [AS_HELP_STRING([--enable-lzo],
185                              [use lzo to compress kernel (default is lzma)])])
186   [if [ x"$enable_lzo" = xyes ]; then
187     # There are three possibilities. LZO version 2 installed with the name
188     # liblzo2, with the name liblzo, and LZO version 1.]
189     AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
190     AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
191       [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
192         [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
193                [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
194     AC_SUBST([LIBLZO])
195     [LIBS="$LIBS $LIBLZO"]
196     AC_CHECK_FUNC([lzo1x_999_compress], ,
197                 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
199     [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
200     AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
201   [else]
202     AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
203   [fi]
204   AC_SUBST([enable_lzo])
207 # Check for functions.
208 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
211 # Check for target programs.
214 # Find tools for the target.
215 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
216   tmp_ac_tool_prefix="$ac_tool_prefix"
217   ac_tool_prefix=$target_alias-
219   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
220                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
221   AC_CHECK_TOOL(OBJCOPY, objcopy)
222   AC_CHECK_TOOL(STRIP, strip)
223   AC_CHECK_TOOL(NM, nm)
225   ac_tool_prefix="$tmp_ac_tool_prefix"
226 else
227   if test "x$TARGET_CC" = x; then
228     TARGET_CC=$CC
229   fi
230   AC_CHECK_TOOL(OBJCOPY, objcopy)
231   AC_CHECK_TOOL(STRIP, strip)
232   AC_CHECK_TOOL(NM, nm)
234 AC_SUBST(TARGET_CC)
237 # Test the C compiler for the target environment.
238 tmp_CC="$CC"
239 tmp_CFLAGS="$CFLAGS"
240 tmp_LDFLAGS="$LDFLAGS"
241 tmp_CPPFLAGS="$CPPFLAGS"
242 tmp_LIBS="$LIBS"
243 CC="$TARGET_CC"
244 CFLAGS="$TARGET_CFLAGS"
245 CPPFLAGS="$TARGET_CPPFLAGS"
246 LDFLAGS="$TARGET_LDFLAGS"
247 LIBS=""
249 if test "x$TARGET_CFLAGS" = x; then
250   # debug flags.
251   TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
252                  -Wundef -Wstrict-prototypes -g"
254   # optimization flags.
255   AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
256     CFLAGS=-Os
257     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
258                       [grub_cv_cc_Os=yes],
259                       [grub_cv_cc_Os=no])
260   ])
261   if test "x$grub_cv_cc_Os" = xyes; then
262     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
263   else
264     TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
265   fi
267   # Force no alignment to save space on i386.
268   if test "x$target_cpu" = xi386; then
269     AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
270       CFLAGS="$CFLAGS -falign-loops=1"
271       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
272                         [grub_cv_cc_falign_loop=yes],
273                         [grub_cv_cc_falign_loop=no])
274     ])
276     if test "x$grub_cv_cc_falign_loop" = xyes; then
277       TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
278     else
279       TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
280     fi
281   fi
284 grub_apple_target_cc
285 if test x$grub_cv_apple_target_cc == xyes ; then
286   TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
287   CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
288   TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
289   TARGET_APPLE_CC=1
290   AC_CHECK_PROG([OBJCONV], [objconv], [objconv], [])
291   if test "x$OBJCONV" = x ; then
292      AC_CHECK_PROG([OBJCONV], [objconv], [./objconv], [], [.])
293   fi
294   if test "x$OBJCONV" = x ; then
295     AC_MSG_ERROR([objconv not found which is required when building with apple compiler])
296   fi
297   TARGET_IMG_LDSCRIPT=
298   TARGET_IMG_CFLAGS="-static"
299   TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
300   TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
301 else
302   TARGET_APPLE_CC=0
303 # Use linker script if present, otherwise use builtin -N script.
304 AC_MSG_CHECKING([for option to link raw image])
305 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
306   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
307   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}  -Wl,-Ttext,"
308   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
309 else
310   TARGET_IMG_LDSCRIPT=
311   TARGET_IMG_LDFLAGS='-Wl,-N  -Wl,-Ttext,'
312   TARGET_IMG_LDFLAGS_AC='-Wl,-N  -Wl,-Ttext,'
314 TARGET_IMG_CFLAGS=
317 AC_SUBST(TARGET_IMG_LDSCRIPT)
318 AC_SUBST(TARGET_IMG_LDFLAGS)
319 AC_SUBST(TARGET_IMG_CFLAGS)
320 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
322 # For platforms where ELF is not the default link format.
323 AC_MSG_CHECKING([for command to convert module to ELF format])
324 case "${host_os}" in
325   cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
326   *) ;;
327 esac
328 AC_SUBST(TARGET_OBJ2ELF)
329 AC_MSG_RESULT([$TARGET_OBJ2ELF])
332 if test "x$target_m32" = x1; then
333   # Force 32-bit mode.
334   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
335   TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
336   TARGET_MODULE_FORMAT="elf32"
339 if test "x$target_m64" = x1; then
340   # Force 64-bit mode.
341   TARGET_CFLAGS="$TARGET_CFLAGS -m64"
342   TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
343   TARGET_MODULE_FORMAT="elf64"
346 if test "$target_cpu"-"$platform" = x86_64-efi; then
347   # Use large model to support 4G memory
348   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
349     SAVED_CFLAGS=$CFLAGS
350     CFLAGS="$CFLAGS -m64 -mcmodel=large"
351     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
352                       [grub_cv_cc_mcmodel=yes],
353                       [grub_cv_cc_mcmodel=no])
354   ])
355   if test "x$grub_cv_cc_mcmodel" = xno; then
356     CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
357     TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"    
358     AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
359   else
360     TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
361   fi
363   # EFI writes to stack below %rsp, we must not use the red zone
364   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
365     CFLAGS="$CFLAGS -m64 -mno-red-zone"
366     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
367                       [grub_cv_cc_no_red_zone=yes],
368                       [grub_cv_cc_no_red_zone=no])
369   ])
370   if test "x$grub_cv_cc_no_red_zone" = xno; then
371     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
372   fi
374   TARGET_CFLAGS="$TARGET_CFLAGS -mno-red-zone"
378 # Compiler features.
381 # Need __enable_execute_stack() for nested function trampolines?
382 grub_CHECK_ENABLE_EXECUTE_STACK
384 # Smashing stack protector.
385 grub_CHECK_STACK_PROTECTOR
386 # Need that, because some distributions ship compilers that include
387 # `-fstack-protector' in the default specs.
388 if test "x$ssp_possible" = xyes; then
389   TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
391 grub_CHECK_STACK_ARG_PROBE
392 # Cygwin's GCC uses alloca() to probe the stackframe on static
393 # stack allocations above some threshold.
394 if test x"$sap_possible" = xyes; then
395   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
398 AC_SUBST(TARGET_CFLAGS)
399 AC_SUBST(TARGET_MODULE_FORMAT)
400 AC_SUBST(OBJCONV)
401 AC_SUBST(TARGET_APPLE_CC)
402 AC_SUBST(TARGET_ASFLAGS)
403 AC_SUBST(TARGET_CPPFLAGS)
404 AC_SUBST(TARGET_LDFLAGS)
406 # Set them to their new values for the tests below.
407 CC="$TARGET_CC"
408 CFLAGS="$TARGET_CFLAGS"
409 CPPFLAGS="$TARGET_CPPFLAGS"
410 LDFLAGS="$TARGET_LDFLAGS"
412 # Check for target functions.
413 AC_CHECK_FUNCS(__bswapsi2 __bswapdi2)
415 # Defined in aclocal.m4.
416 grub_PROG_TARGET_CC
417 if test "x$TARGET_APPLE_CC" != x1 ; then
418 grub_PROG_OBJCOPY_ABSOLUTE
420 grub_PROG_LD_BUILD_ID_NONE
421 grub_ASM_USCORE
422 if test "x$target_cpu" = xi386; then
423   if test ! -z "$TARGET_IMG_LDSCRIPT"; then
424     # Check symbols provided by linker script.
425     CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
426   fi
427   if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then
428     grub_CHECK_BSS_START_SYMBOL
429     grub_CHECK_END_SYMBOL
430   fi
431   CFLAGS="$TARGET_CFLAGS"
432   grub_I386_ASM_PREFIX_REQUIREMENT
433   grub_I386_ASM_ADDR32
434   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
435 else
436   AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
439 AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
440 #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
441 #else
442 #define NESTED_FUNC_ATTR
443 #endif])
445 # Restore the flags.
446 CC="$tmp_CC"
447 CFLAGS="$tmp_CFLAGS"
448 CPPFLAGS="$tmp_CPPFLAGS"
449 LDFLAGS="$tmp_LDFLAGS"
450 LIBS="$tmp_LIBS"
453 # Check for options.
456 # Memory manager debugging.
457 AC_ARG_ENABLE([mm-debug], 
458               AS_HELP_STRING([--enable-mm-debug],
459                              [include memory manager debugging]),
460               [AC_DEFINE([MM_DEBUG], [1],
461                          [Define to 1 if you enable memory manager debugging.])])
463 AC_ARG_ENABLE([grub-emu],
464               [AS_HELP_STRING([--enable-grub-emu],
465                              [build and install the `grub-emu' debugging utility])])
466 AC_ARG_ENABLE([grub-emu-usb],
467               [AS_HELP_STRING([--enable-grub-emu-usb],
468                              [build and install the `grub-emu' debugging utility with USB support])])
469 [if [ x"$enable_grub_emu" = xyes ]; then
470   # Check for curses libraries.]
471   AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
472     [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
473       [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
474   AC_SUBST([LIBCURSES])
476   [# Check for headers.]
477   AC_CHECK_HEADERS([ncurses/curses.h], [],
478     [AC_CHECK_HEADERS([ncurses.h], [],
479       [AC_CHECK_HEADERS([curses.h], [],
480         [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
482   [if [ x"$enable_grub_emu_usb" = xyes ]; then
483     # Check for libusb libraries.]
484     AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
485       [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
486     AC_SUBST([LIBUSB])
488     [# Check for headers.]
489     AC_CHECK_HEADERS([usb.h], [],
490       [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
491   [fi]
492 [fi]
493 AC_SUBST([enable_grub_emu])
494 AC_SUBST([enable_grub_emu_usb])
496 AC_ARG_ENABLE([grub-fstest],
497               [AS_HELP_STRING([--enable-grub-fstest],
498                              [build and install the `grub-fstest' debugging utility])])
499 AC_SUBST([enable_grub_fstest])
501 AC_ARG_ENABLE([grub-pe2elf],
502               [AS_HELP_STRING([--enable-grub-pe2elf],
503                              [build and install the `grub-pe2elf' conversion utility])])
504 AC_SUBST([enable_grub_pe2elf])
506 AC_ARG_ENABLE([grub-mkfont],
507               [AS_HELP_STRING([--enable-grub-mkfont],
508                              [build and install the `grub-mkfont' utility])])
509 if test x"$enable_grub_mkfont" = xyes ; then
510   # Check for freetype libraries.
511   AC_CHECK_PROGS([FREETYPE], [freetype-config])
512   if test "x$FREETYPE" = x ; then
513     AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
514   fi
515   freetype_cflags=`freetype-config --cflags`
516   freetype_libs=`freetype-config --libs`
518 AC_SUBST([enable_grub_mkfont])
519 AC_SUBST([freetype_cflags])
520 AC_SUBST([freetype_libs])
522 AC_ARG_ENABLE([efiemu],
523               [AS_HELP_STRING([--enable-efiemu],
524                              [build and install the efiemu runtimes])])
525 AC_SUBST([enable_efiemu])
526 AC_SUBST(ASFLAGS)
528 # Output files.
529 grub_CHECK_LINK_DIR
530 if test x"$link_dir" = xyes ; then
531   AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
532         include/grub/machine:include/grub/$target_cpu/$platform])
533 else
534   mkdir -p include/grub 2>/dev/null
535   rm -rf include/grub/cpu
536   cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
537   rm -rf include/grub/machine
538   cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
540 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
541 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
542 AC_OUTPUT