2008-08-16 Felix Zielcke <fzielcke@z-51.de>
[grub2/phcoder.git] / configure.ac
blobf561b8bb0aeec8a49ab7c07b681fef8ab35e8cf8
1 # Process this file with autoconf to produce a configure script.
3 # Copyright (C) 2002,2003,2004,2005,2006,2007,2008  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.53)
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 AC_SUBST(target_cpu)
103 AC_SUBST(target_os)
104 AC_SUBST(platform)
107 # Checks for build programs.
110 # Although cmp is listed in the GNU Coding Standards as a command which
111 # can used directly, OpenBSD lacks cmp in the default installation.
112 AC_CHECK_PROGS([CMP], [cmp])
113 if test "x$CMP" = x; then
114   AC_MSG_ERROR([cmp is not found])
117 AC_CHECK_PROGS([YACC], [bison])
118 if test "x$YACC" = x; then
119   AC_MSG_ERROR([bison is not found])
122 for file in /usr/share/unifont/unifont.hex ; do
123   if test -e $file ; then
124     AC_SUBST([UNIFONT_HEX], [$file])
125     break
126   fi
127 done
129 AC_PROG_INSTALL
130 AC_PROG_AWK
131 AC_PROG_MAKE_SET
133 # These are not a "must".
134 AC_PATH_PROG(RUBY, ruby)
135 AC_PATH_PROG(HELP2MAN, help2man)
138 # Checks for host programs.
141 AC_PROG_CC
142 # Must be GCC.
143 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
145 AC_GNU_SOURCE
146 AC_SYS_LARGEFILE
148 # Identify characteristics of the host architecture.
149 AC_C_BIGENDIAN
150 AC_CHECK_SIZEOF(void *)
151 AC_CHECK_SIZEOF(long)
153 if test "x$host_m32" = x1; then
154   # Force 32-bit mode.
155   CFLAGS="$CFLAGS -m32"
156   LDFLAGS="$LDFLAGS -m32"
159 # Check LZO when compiling for the i386-pc.
160 if test "$target_cpu"-"$platform" = i386-pc; then
161   AC_ARG_ENABLE([lzo],
162               [AS_HELP_STRING([--enable-lzo],
163                              [use lzo to compress kernel (default is lzma)])])
164   [if [ x"$enable_lzo" = xyes ]; then
165     # There are three possibilities. LZO version 2 installed with the name
166     # liblzo2, with the name liblzo, and LZO version 1.]
167     AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
168     AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
169       [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
170         [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
171                [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
172     AC_SUBST([LIBLZO])
173     [LIBS="$LIBS $LIBLZO"]
174     AC_CHECK_FUNC([lzo1x_999_compress], ,
175                 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
177     [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
178     AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
179   [else]
180     AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
181   [fi]
182   AC_SUBST([enable_lzo])
185 # Check for functions.
186 AC_CHECK_FUNCS(posix_memalign memalign)
189 # Check for target programs.
193 # Use linker script if present, otherwise use builtin -N script.
194 AC_MSG_CHECKING([for option to link raw image])
195 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"; then
196   TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
197   TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
198   TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
199 else
200   TARGET_IMG_LDSCRIPT=
201   TARGET_IMG_LDFLAGS='-Wl,-N'
202   TARGET_IMG_LDFLAGS_AC='-Wl,-N'
204 AC_SUBST(TARGET_IMG_LDSCRIPT)
205 AC_SUBST(TARGET_IMG_LDFLAGS)
206 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
208 # For platforms where ELF is not the default link format.
209 AC_MSG_CHECKING([for command to convert module to ELF format])
210 case "${host_os}:${target_os}" in
211   cygwin:cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
212   *) ;;
213 esac
214 AC_SUBST(TARGET_OBJ2ELF)
215 AC_MSG_RESULT([$TARGET_OBJ2ELF])
217 # For cross-compiling.
218 if test "x$target" != "x$host"; then
219   # XXX this depends on the implementation of autoconf!
220   tmp_ac_tool_prefix="$ac_tool_prefix"
221   ac_tool_prefix=$target_alias-
223   AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
224                  [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
225   AC_CHECK_TOOL(OBJCOPY, objcopy)
226   AC_CHECK_TOOL(STRIP, strip)
227   AC_CHECK_TOOL(NM, nm)
229   ac_tool_prefix="$tmp_ac_tool_prefix"
230 else
231   if test "x$TARGET_CC" = x; then
232     TARGET_CC=$CC
233   fi
234   AC_CHECK_TOOL(OBJCOPY, objcopy)
235   AC_CHECK_TOOL(STRIP, strip)
236   AC_CHECK_TOOL(NM, nm)
238 AC_SUBST(TARGET_CC)
241 # Test the C compiler for the target environment.
242 tmp_CC="$CC"
243 tmp_CFLAGS="$CFLAGS"
244 tmp_LDFLAGS="$LDFLAGS"
245 tmp_CPPFLAGS="$CPPFLAGS"
246 tmp_LIBS="$LIBS"
247 CC="$TARGET_CC"
248 CFLAGS="$TARGET_CFLAGS"
249 CPPFLAGS="$TARGET_CPPFLAGS"
250 LDFLAGS="$TARGET_LDFLAGS"
251 LIBS=""
253 if test "x$TARGET_CFLAGS" = x; then
254   # debug flags.
255   TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
256                  -Wundef -Wstrict-prototypes -g"
258   # optimization flags.
259   AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
260     CFLAGS=-Os
261     AC_TRY_COMPILE(, , grub_cv_cc_Os=yes, grub_cv_cc_Os=no)
262   ])
263   if test "x$grub_cv_cc_Os" = xyes; then
264     TARGET_CFLAGS="$TARGET_CFLAGS -Os"
265   else
266     TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
267   fi
269   # Force no alignment to save space on i386.
270   if test "x$target_cpu" = xi386; then
271     AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
272       CFLAGS="-falign-loops=1"
273       AC_TRY_COMPILE(, , [grub_cv_cc_falign_loop=yes], [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 if test "x$target_m32" = x1; then
285   # Force 32-bit mode.
286   TARGET_CFLAGS="$TARGET_CFLAGS -m32"
287   TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
290 if test "x$target_m64" = x1; then
291   # Force 64-bit mode.
292   TARGET_CFLAGS="$TARGET_CFLAGS -m64"
293   TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
297 # Compiler features.
300 # Smashing stack protector.
301 grub_CHECK_STACK_PROTECTOR
302 # Need that, because some distributions ship compilers that include
303 # `-fstack-protector' in the default specs.
304 if test "x$ssp_possible" = xyes; then
305   TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
307 grub_CHECK_STACK_ARG_PROBE
308 # Cygwin's GCC uses alloca() to probe the stackframe on static
309 # stack allocations above some threshold.
310 if test x"$sap_possible" = xyes; then
311   TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
314 AC_SUBST(TARGET_CFLAGS)
315 AC_SUBST(TARGET_CPPFLAGS)
316 AC_SUBST(TARGET_LDFLAGS)
317 AC_SUBST(MODULE_LDFLAGS)
319 # Set them to their new values for the tests below.
320 CC="$TARGET_CC"
321 CFLAGS="$TARGET_CFLAGS"
322 CPPFLAGS="$TARGET_CPPFLAGS"
323 LDFLAGS="$TARGET_LDFLAGS"
325 # Defined in aclocal.m4.
326 grub_PROG_TARGET_CC
327 grub_PROG_OBJCOPY_ABSOLUTE
328 grub_PROG_LD_BUILD_ID_NONE
329 grub_ASM_USCORE
330 if test "x$target_cpu" = xi386; then
331   if test ! -z "$TARGET_IMG_LDSCRIPT"; then
332     # Check symbols provided by linker script.
333     CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
334   fi
335   if test "x$platform" = xpc; then
336     grub_CHECK_START_SYMBOL
337     grub_CHECK_BSS_START_SYMBOL
338     grub_CHECK_END_SYMBOL
339   fi
340   CFLAGS="$TARGET_CFLAGS"
341   grub_I386_ASM_PREFIX_REQUIREMENT
342   grub_I386_ASM_ADDR32
343   grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
344   grub_I386_CHECK_REGPARM_BUG
345 else
346   AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
349 # Restore the flags.
350 CC="$tmp_CC"
351 CFLAGS="$tmp_CFLAGS"
352 CPPFLAGS="$tmp_CPPFLAGS"
353 LDFLAGS="$tmp_LDFLAGS"
354 LIBS="$tmp_LIBS"
357 # Check for options.
360 # Memory manager debugging.
361 AC_ARG_ENABLE([mm-debug], 
362               AS_HELP_STRING([--enable-mm-debug],
363                              [include memory manager debugging]),
364               [AC_DEFINE([MM_DEBUG], [1],
365                          [Define to 1 if you enable memory manager debugging.])])
367 AC_ARG_ENABLE([grub-emu],
368               [AS_HELP_STRING([--enable-grub-emu],
369                              [build and install the `grub-emu' debugging utility])])
370 [if [ x"$enable_grub_emu" = xyes ]; then
371   # Check for curses libraries.]
372   AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
373     [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
374       [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
375   AC_SUBST([LIBCURSES])
377   [# Check for headers.]
378   AC_CHECK_HEADERS([ncurses/curses.h], [],
379     [AC_CHECK_HEADERS([ncurses.h], [],
380       [AC_CHECK_HEADERS([curses.h], [],
381         [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
382 [fi]
383 AC_SUBST([enable_grub_emu])
385 AC_ARG_ENABLE([grub-fstest],
386               [AS_HELP_STRING([--enable-grub-fstest],
387                              [build and install the `grub-fstest' debugging utility])])
388 AC_SUBST([enable_grub_fstest])
390 AC_ARG_ENABLE([grub-pe2elf],
391               [AS_HELP_STRING([--enable-grub-pe2elf],
392                              [build and install the `grub-pe2elf' conversion utility])])
393 AC_SUBST([enable_grub_pe2elf])
395 # Output files.
396 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
397         include/grub/machine:include/grub/$target_cpu/$platform])
398 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
399 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
400 AC_OUTPUT