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
14 dnl This configure script is complicated, because GRUB needs to deal
15 dnl with three potentially different types:
17 dnl build -- the environment for building GRUB
18 dnl host -- the environment for running utilities
19 dnl target -- the environment for running GRUB
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.
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
34 AC_INIT([GRUB],[1.96],[bug-grub@gnu.org])
36 AC_CONFIG_SRCDIR([include/grub/dl.h])
37 AC_CONFIG_HEADER([config.h])
39 # Checks for host and target systems.
43 # Program name transformations
47 powerpc64) host_m32=1 ;;
51 i[[3456]]86) target_cpu=i386 ;;
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"]) ;;
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
79 x86_64-*) target_cpu=i386 ;;
80 powerpc64-ieee1275) target_cpu=powerpc ;;
84 # Check if the platform is supported, make final adjustments.
85 case "$target_cpu"-"$platform" in
90 i386-linuxbios) platform=coreboot ;;
94 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
98 i386 | powerpc) target_m32=1 ;;
99 x86_64 | sparc64) target_m64=1 ;;
103 mingw32) host_os=cygwin ;;
107 mingw32) target_os=cygwin ;;
115 # Checks for build programs.
118 # Although cmp is listed in the GNU Coding Standards as a command which
119 # can used directly, OpenBSD lacks cmp in the default installation.
120 AC_CHECK_PROGS([CMP], [cmp])
121 if test "x$CMP" = x; then
122 AC_MSG_ERROR([cmp is not found])
125 AC_CHECK_PROGS([YACC], [bison])
126 if test "x$YACC" = x; then
127 AC_MSG_ERROR([bison is not found])
130 for file in /usr/share/unifont/unifont.hex ; do
131 if test -e $file ; then
132 AC_SUBST([UNIFONT_HEX], [$file])
141 # These are not a "must".
142 AC_PATH_PROG(RUBY, ruby)
143 AC_PATH_PROG(HELP2MAN, help2man)
146 # Checks for host programs.
151 test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
156 # Identify characteristics of the host architecture.
158 AC_CHECK_SIZEOF(void *)
159 AC_CHECK_SIZEOF(long)
161 if test "x$host_m32" = x1; then
163 CFLAGS="$CFLAGS -m32"
164 LDFLAGS="$LDFLAGS -m32"
167 # Check LZO when compiling for the i386-pc.
168 if test "$target_cpu"-"$platform" = i386-pc; then
170 [AS_HELP_STRING([--enable-lzo],
171 [use lzo to compress kernel (default is lzma)])])
172 [if [ x"$enable_lzo" = xyes ]; then
173 # There are three possibilities. LZO version 2 installed with the name
174 # liblzo2, with the name liblzo, and LZO version 1.]
175 AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
176 AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
177 [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
178 [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
179 [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
181 [LIBS="$LIBS $LIBLZO"]
182 AC_CHECK_FUNC([lzo1x_999_compress], ,
183 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
185 [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
186 AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
188 AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
190 AC_SUBST([enable_lzo])
193 # Check for functions.
194 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
197 # Check for target programs.
201 # Use linker script if present, otherwise use builtin -N script.
202 AC_MSG_CHECKING([for option to link raw image])
203 if test -f "${srcdir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"; then
204 TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
205 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
206 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${target_os}-img-ld.sc"
209 TARGET_IMG_LDFLAGS='-Wl,-N'
210 TARGET_IMG_LDFLAGS_AC='-Wl,-N'
212 AC_SUBST(TARGET_IMG_LDSCRIPT)
213 AC_SUBST(TARGET_IMG_LDFLAGS)
214 AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
216 # For platforms where ELF is not the default link format.
217 AC_MSG_CHECKING([for command to convert module to ELF format])
218 case "${host_os}:${target_os}" in
219 cygwin:cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
222 AC_SUBST(TARGET_OBJ2ELF)
223 AC_MSG_RESULT([$TARGET_OBJ2ELF])
225 # For cross-compiling.
226 if test "x$target" != "x$host"; then
227 # XXX this depends on the implementation of autoconf!
228 tmp_ac_tool_prefix="$ac_tool_prefix"
229 ac_tool_prefix=$target_alias-
231 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
232 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
233 AC_CHECK_TOOL(OBJCOPY, objcopy)
234 AC_CHECK_TOOL(STRIP, strip)
235 AC_CHECK_TOOL(NM, nm)
237 ac_tool_prefix="$tmp_ac_tool_prefix"
239 if test "x$TARGET_CC" = x; then
242 AC_CHECK_TOOL(OBJCOPY, objcopy)
243 AC_CHECK_TOOL(STRIP, strip)
244 AC_CHECK_TOOL(NM, nm)
249 # Test the C compiler for the target environment.
252 tmp_LDFLAGS="$LDFLAGS"
253 tmp_CPPFLAGS="$CPPFLAGS"
256 CFLAGS="$TARGET_CFLAGS"
257 CPPFLAGS="$TARGET_CPPFLAGS"
258 LDFLAGS="$TARGET_LDFLAGS"
261 if test "x$TARGET_CFLAGS" = x; then
263 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
264 -Wundef -Wstrict-prototypes -g"
266 # optimization flags.
267 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
269 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
273 if test "x$grub_cv_cc_Os" = xyes; then
274 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
276 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
279 # Force no alignment to save space on i386.
280 if test "x$target_cpu" = xi386; then
281 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
282 CFLAGS="-falign-loops=1"
283 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
284 [grub_cv_cc_falign_loop=yes],
285 [grub_cv_cc_falign_loop=no])
288 if test "x$grub_cv_cc_falign_loop" = xyes; then
289 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
291 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
296 if test "x$target_m32" = x1; then
298 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
299 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
302 if test "x$target_m64" = x1; then
304 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
305 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
312 # Need __enable_execute_stack() for nested function trampolines?
313 grub_CHECK_ENABLE_EXECUTE_STACK
315 # Smashing stack protector.
316 grub_CHECK_STACK_PROTECTOR
317 # Need that, because some distributions ship compilers that include
318 # `-fstack-protector' in the default specs.
319 if test "x$ssp_possible" = xyes; then
320 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
322 grub_CHECK_STACK_ARG_PROBE
323 # Cygwin's GCC uses alloca() to probe the stackframe on static
324 # stack allocations above some threshold.
325 if test x"$sap_possible" = xyes; then
326 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
329 AC_SUBST(TARGET_CFLAGS)
330 AC_SUBST(TARGET_CPPFLAGS)
331 AC_SUBST(TARGET_LDFLAGS)
332 AC_SUBST(MODULE_LDFLAGS)
334 # Set them to their new values for the tests below.
336 CFLAGS="$TARGET_CFLAGS"
337 CPPFLAGS="$TARGET_CPPFLAGS"
338 LDFLAGS="$TARGET_LDFLAGS"
340 # Defined in aclocal.m4.
342 grub_PROG_OBJCOPY_ABSOLUTE
343 grub_PROG_LD_BUILD_ID_NONE
345 if test "x$target_cpu" = xi386; then
346 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
347 # Check symbols provided by linker script.
348 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
350 if test "x$platform" = xpc; then
351 grub_CHECK_START_SYMBOL
352 grub_CHECK_BSS_START_SYMBOL
353 grub_CHECK_END_SYMBOL
355 CFLAGS="$TARGET_CFLAGS"
356 grub_I386_ASM_PREFIX_REQUIREMENT
358 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
359 grub_I386_CHECK_REGPARM_BUG
361 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
367 CPPFLAGS="$tmp_CPPFLAGS"
368 LDFLAGS="$tmp_LDFLAGS"
375 # Memory manager debugging.
376 AC_ARG_ENABLE([mm-debug],
377 AS_HELP_STRING([--enable-mm-debug],
378 [include memory manager debugging]),
379 [AC_DEFINE([MM_DEBUG], [1],
380 [Define to 1 if you enable memory manager debugging.])])
382 AC_ARG_ENABLE([grub-emu],
383 [AS_HELP_STRING([--enable-grub-emu],
384 [build and install the `grub-emu' debugging utility])])
385 [if [ x"$enable_grub_emu" = xyes ]; then
386 # Check for curses libraries.]
387 AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
388 [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
389 [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
390 AC_SUBST([LIBCURSES])
392 [# Check for headers.]
393 AC_CHECK_HEADERS([ncurses/curses.h], [],
394 [AC_CHECK_HEADERS([ncurses.h], [],
395 [AC_CHECK_HEADERS([curses.h], [],
396 [AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])
398 AC_SUBST([enable_grub_emu])
400 AC_ARG_ENABLE([grub-fstest],
401 [AS_HELP_STRING([--enable-grub-fstest],
402 [build and install the `grub-fstest' debugging utility])])
403 AC_SUBST([enable_grub_fstest])
405 AC_ARG_ENABLE([grub-pe2elf],
406 [AS_HELP_STRING([--enable-grub-pe2elf],
407 [build and install the `grub-pe2elf' conversion utility])])
408 AC_SUBST([enable_grub_pe2elf])
411 AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
412 include/grub/machine:include/grub/$target_cpu/$platform])
413 AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
414 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])