2009-05-04 Felix Zielcke <fzielcke@z-51.de>
[grub2/phcoder.git] / configure.ac
blobd84e2b68d8f05d240df4864bb9a9d1d783309b52
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 if test "x$host_m32" = x1; then
171   # Force 32-bit mode.
172   CFLAGS="$CFLAGS -m32"
173   LDFLAGS="$LDFLAGS -m32"
176 # Check LZO when compiling for the i386-pc.
177 if test "$target_cpu"-"$platform" = i386-pc; then
178   AC_ARG_ENABLE([lzo],
179               [AS_HELP_STRING([--enable-lzo],
180                              [use lzo to compress kernel (default is lzma)])])
181   [if [ x"$enable_lzo" = xyes ]; then
182     # There are three possibilities. LZO version 2 installed with the name
183     # liblzo2, with the name liblzo, and LZO version 1.]
184     AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
185     AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
186       [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
187         [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
188                [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
189     AC_SUBST([LIBLZO])
190     [LIBS="$LIBS $LIBLZO"]
191     AC_CHECK_FUNC([lzo1x_999_compress], ,
192                 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
194     [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
195     AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
196   [else]
197     AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
198   [fi]
199   AC_SUBST([enable_lzo])
202 # Check for functions.
203 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
206 # Check for target programs.
210 # Use linker script if present, otherwise use builtin -N script.
211 AC_MSG_CHECKING([for option to link raw image])
212 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
213   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
214   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
215   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
216 else
217   TARGET_IMG_LDSCRIPT=
218   TARGET_IMG_LDFLAGS='-Wl,-N'
219   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
221 AC_SUBST(TARGET_IMG_LDSCRIPT)
222 AC_SUBST(TARGET_IMG_LDFLAGS)
223 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
225 # For platforms where ELF is not the default link format.
226 AC_MSG_CHECKING([for command to convert module to ELF format])
227 case "${host_os}" in
228   cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
229   *) ;;
230 esac
231 AC_SUBST(TARGET_OBJ2ELF)
232 AC_MSG_RESULT([$TARGET_OBJ2ELF])
234 # Find tools for the target.
235 if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
236   tmp_ac_tool_prefix="$ac_tool_prefix"
237   ac_tool_prefix=$target_alias-
239   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
240                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
241   AC_CHECK_TOOL(OBJCOPY, objcopy)
242   AC_CHECK_TOOL(STRIP, strip)
243   AC_CHECK_TOOL(NM, nm)
245   ac_tool_prefix="$tmp_ac_tool_prefix"
246 else
247   if test "x$TARGET_CC" = x; then
248     TARGET_CC=$CC
249   fi
250   AC_CHECK_TOOL(OBJCOPY, objcopy)
251   AC_CHECK_TOOL(STRIP, strip)
252   AC_CHECK_TOOL(NM, nm)
254 AC_SUBST(TARGET_CC)
257 # Test the C compiler for the target environment.
258 tmp_CC="$CC"
259 tmp_CFLAGS="$CFLAGS"
260 tmp_LDFLAGS="$LDFLAGS"
261 tmp_CPPFLAGS="$CPPFLAGS"
262 tmp_LIBS="$LIBS"
263 CC="$TARGET_CC"
264 CFLAGS="$TARGET_CFLAGS"
265 CPPFLAGS="$TARGET_CPPFLAGS"
266 LDFLAGS="$TARGET_LDFLAGS"
267 LIBS=""
269 if test "x$TARGET_CFLAGS" = x; then
270   # debug flags.
271   TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
272                  -Wundef -Wstrict-prototypes -g"
274   # optimization flags.
275   AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
276     CFLAGS=-Os
277     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
278                       [grub_cv_cc_Os=yes],
279                       [grub_cv_cc_Os=no])
280   ])
281   if test "x$grub_cv_cc_Os" = xyes; then
282     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
283   else
284     TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
285   fi
287   # Force no alignment to save space on i386.
288   if test "x$target_cpu" = xi386; then
289     AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
290       CFLAGS="-falign-loops=1"
291       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
292                         [grub_cv_cc_falign_loop=yes],
293                         [grub_cv_cc_falign_loop=no])
294     ])
296     if test "x$grub_cv_cc_falign_loop" = xyes; then
297       TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
298     else
299       TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
300     fi
301   fi
304 if test "x$target_m32" = x1; then
305   # Force 32-bit mode.
306   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
307   TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
310 if test "x$target_m64" = x1; then
311   # Force 64-bit mode.
312   TARGET_CFLAGS="$TARGET_CFLAGS -m64"
313   TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
316 if test "$target_cpu"-"$platform" = x86_64-efi; then
317   # Use large model to support 4G memory
318   AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
319     CFLAGS="-m64 -mcmodel=large"
320     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
321                       [grub_cv_cc_mcmodel=yes],
322                       [grub_cv_cc_mcmodel=no])
323   ])
324   if test "x$grub_cv_cc_no_mcmodel" = xno; then
325     AC_MSG_ERROR([-mcmodel=large not supported, upgrade your gcc])
326   fi
328   # EFI writes to stack below %rsp, we must not use the red zone
329   AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
330     CFLAGS="-m64 -mno-red-zone"
331     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
332                       [grub_cv_cc_no_red_zone=yes],
333                       [grub_cv_cc_no_red_zone=no])
334   ])
335   if test "x$grub_cv_cc_no_red_zone" = xno; then
336     AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
337   fi
339   TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large -mno-red-zone"
343 # Compiler features.
346 # Need __enable_execute_stack() for nested function trampolines?
347 grub_CHECK_ENABLE_EXECUTE_STACK
349 # Smashing stack protector.
350 grub_CHECK_STACK_PROTECTOR
351 # Need that, because some distributions ship compilers that include
352 # `-fstack-protector' in the default specs.
353 if test "x$ssp_possible" = xyes; then
354   TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
356 grub_CHECK_STACK_ARG_PROBE
357 # Cygwin's GCC uses alloca() to probe the stackframe on static
358 # stack allocations above some threshold.
359 if test x"$sap_possible" = xyes; then
360   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
363 AC_SUBST(TARGET_CFLAGS)
364 AC_SUBST(TARGET_CPPFLAGS)
365 AC_SUBST(TARGET_LDFLAGS)
367 # Set them to their new values for the tests below.
368 CC="$TARGET_CC"
369 CFLAGS="$TARGET_CFLAGS"
370 CPPFLAGS="$TARGET_CPPFLAGS"
371 LDFLAGS="$TARGET_LDFLAGS"
373 # Check for target functions.
374 AC_CHECK_FUNCS(__bswapsi2 __bswapdi2)
376 # Defined in aclocal.m4.
377 grub_PROG_TARGET_CC
378 grub_PROG_OBJCOPY_ABSOLUTE
379 grub_PROG_LD_BUILD_ID_NONE
380 grub_ASM_USCORE
381 if test "x$target_cpu" = xi386; then
382   if test ! -z "$TARGET_IMG_LDSCRIPT"; then
383     # Check symbols provided by linker script.
384     CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
385   fi
386   if test "x$platform" = xpc; then
387     grub_CHECK_BSS_START_SYMBOL
388     grub_CHECK_END_SYMBOL
389   fi
390   CFLAGS="$TARGET_CFLAGS"
391   grub_I386_ASM_PREFIX_REQUIREMENT
392   grub_I386_ASM_ADDR32
393   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
394   grub_I386_CHECK_REGPARM_BUG
395 else
396   AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
399 # Restore the flags.
400 CC="$tmp_CC"
401 CFLAGS="$tmp_CFLAGS"
402 CPPFLAGS="$tmp_CPPFLAGS"
403 LDFLAGS="$tmp_LDFLAGS"
404 LIBS="$tmp_LIBS"
407 # Check for options.
410 # Memory manager debugging.
411 AC_ARG_ENABLE([mm-debug], 
412               AS_HELP_STRING([--enable-mm-debug],
413                              [include memory manager debugging]),
414               [AC_DEFINE([MM_DEBUG], [1],
415                          [Define to 1 if you enable memory manager debugging.])])
417 AC_ARG_ENABLE([grub-emu],
418               [AS_HELP_STRING([--enable-grub-emu],
419                              [build and install the `grub-emu' debugging utility])])
420 AC_ARG_ENABLE([grub-emu-usb],
421               [AS_HELP_STRING([--enable-grub-emu-usb],
422                              [build and install the `grub-emu' debugging utility with USB support])])
423 [if [ x"$enable_grub_emu" = xyes ]; then
424   # Check for curses libraries.]
425   AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
426     [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
427       [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
428   AC_SUBST([LIBCURSES])
430   [# Check for headers.]
431   AC_CHECK_HEADERS([ncurses/curses.h], [],
432     [AC_CHECK_HEADERS([ncurses.h], [],
433       [AC_CHECK_HEADERS([curses.h], [],
434         [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
436   [if [ x"$enable_grub_emu_usb" = xyes ]; then
437     # Check for libusb libraries.]
438     AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
439       [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
440     AC_SUBST([LIBUSB])
442     [# Check for headers.]
443     AC_CHECK_HEADERS([usb.h], [],
444       [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
445   [fi]
446 [fi]
447 AC_SUBST([enable_grub_emu])
448 AC_SUBST([enable_grub_emu_usb])
450 AC_ARG_ENABLE([grub-fstest],
451               [AS_HELP_STRING([--enable-grub-fstest],
452                              [build and install the `grub-fstest' debugging utility])])
453 AC_SUBST([enable_grub_fstest])
455 AC_ARG_ENABLE([grub-pe2elf],
456               [AS_HELP_STRING([--enable-grub-pe2elf],
457                              [build and install the `grub-pe2elf' conversion utility])])
458 AC_SUBST([enable_grub_pe2elf])
460 AC_ARG_ENABLE([grub-mkfont],
461               [AS_HELP_STRING([--enable-grub-mkfont],
462                              [build and install the `grub-mkfont' utility])])
463 if test x"$enable_grub_mkfont" = xyes ; then
464   # Check for freetype libraries.
465   AC_CHECK_PROGS([FREETYPE], [freetype-config])
466   if test "x$FREETYPE" = x ; then
467     AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
468   fi
469   freetype_cflags=`freetype-config --cflags`
470   freetype_libs=`freetype-config --libs`
472 AC_SUBST([enable_grub_mkfont])
473 AC_SUBST([freetype_cflags])
474 AC_SUBST([freetype_libs])
476 AC_ARG_ENABLE([efiemu],
477               [AS_HELP_STRING([--enable-efiemu],
478                              [build and install the efiemu runtimes])])
479 AC_SUBST([enable_efiemu])
481 # Output files.
482 grub_CHECK_LINK_DIR
483 if test x"$link_dir" = xyes ; then
484   AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
485         include/grub/machine:include/grub/$target_cpu/$platform])
486 else
487   mkdir -p include/grub 2>/dev/null
488   rm -rf include/grub/cpu
489   cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
490   rm -rf include/grub/machine
491   cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
493 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
494 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
495 AC_OUTPUT