]> git.proxmox.com Git - grub2.git/blame - configure.ac
2009-03-21 Bean <bean123ch@gmail.com>
[grub2.git] / configure.ac
CommitLineData
6a161fa9 1# Process this file with autoconf to produce a configure script.
2
1e901a75 3# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
6a161fa9 4#
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.
8#
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.
13
b977bf01 14dnl This configure script is complicated, because GRUB needs to deal
15dnl with three potentially different types:
16dnl
17dnl build -- the environment for building GRUB
18dnl host -- the environment for running utilities
19dnl target -- the environment for running GRUB
20dnl
21dnl In addition, GRUB needs to deal with a platform specification
22dnl which specifies the system running GRUB, such as firmware.
23dnl This is necessary because the target type in autoconf does not
24dnl describe such a system very well.
25dnl
26dnl The current strategy is to use variables with no prefix (such as
27dnl CC, CFLAGS, etc.) for the host type as well as the build type,
28dnl because GRUB does not need to use those variables for the build
29dnl type, so there is no conflict. Variables with the prefix "TARGET_"
30dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
31dnl type.
32
33
eb73121d 34AC_INIT([GRUB],[1.96],[bug-grub@gnu.org])
46e04eb9 35AC_PREREQ(2.59)
4b13b216 36AC_CONFIG_SRCDIR([include/grub/dl.h])
6a161fa9 37AC_CONFIG_HEADER([config.h])
38
b977bf01 39# Checks for host and target systems.
6a161fa9 40AC_CANONICAL_HOST
b977bf01 41AC_CANONICAL_TARGET
6a161fa9 42
1d543c3e 43# Program name transformations
44AC_ARG_PROGRAM
45
6a161fa9 46case "$host_cpu" in
b977bf01 47 powerpc64) host_m32=1 ;;
48esac
49
50case "$target_cpu" in
51 i[[3456]]86) target_cpu=i386 ;;
6a161fa9 52esac
53
05568c2e 54# Specify the platform (such as firmware).
55AC_ARG_WITH([platform],
56 AS_HELP_STRING([--with-platform=PLATFORM],
83b984de 57 [select the host platform [[guessed]]]))
05568c2e 58
59# Guess the platform if not specified.
60if test "x$with_platform" = x; then
b977bf01 61 case "$target_cpu"-"$target_vendor" in
05568c2e 62 i386-apple) platform=efi ;;
63 i386-*) platform=pc ;;
58393a2d 64 x86_64-apple) platform=efi ;;
737feb35 65 x86_64-*) platform=pc ;;
05568c2e 66 powerpc-*) platform=ieee1275 ;;
58393a2d 67 powerpc64-*) platform=ieee1275 ;;
05568c2e 68 sparc64-*) platform=ieee1275 ;;
58393a2d 69 *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
05568c2e 70 esac
71else
72 platform="$with_platform"
73fi
74
58393a2d 75# Adjust CPU unless target was explicitly specified.
76if test -z "$target_alias"; then
77 case "$target_cpu"-"$platform" in
78 x86_64-efi) ;;
3f4ce737 79 x86_64-*) target_cpu=i386 ;;
80 powerpc64-ieee1275) target_cpu=powerpc ;;
20011694 81 esac
82fi
83
58393a2d 84# Check if the platform is supported, make final adjustments.
b977bf01 85case "$target_cpu"-"$platform" in
05568c2e 86 i386-efi) ;;
3f4ce737 87 x86_64-efi) ;;
05568c2e 88 i386-pc) ;;
546f966a 89 i386-coreboot) ;;
58393a2d 90 i386-linuxbios) platform=coreboot ;;
3d04eab8 91 i386-ieee1275) ;;
05568c2e 92 powerpc-ieee1275) ;;
93 sparc64-ieee1275) ;;
58393a2d 94 *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
6a161fa9 95esac
96
3f4ce737 97case "$target_cpu" in
98 i386 | powerpc) target_m32=1 ;;
99 x86_64 | sparc64) target_m64=1 ;;
100esac
101
6e5a42fe 102case "$host_os" in
103 mingw32) host_os=cygwin ;;
104esac
105
9304eef1 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).
109case "$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 ;;
114esac
115
56978920 116AC_SUBST(host_cpu)
117AC_SUBST(host_os)
9304eef1 118AC_SUBST(host_kernel)
6e5a42fe 119
b977bf01 120AC_SUBST(target_cpu)
05568c2e 121AC_SUBST(platform)
6a161fa9 122
b977bf01 123#
124# Checks for build programs.
125#
144f1f98 126
6c826348 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.
129AC_CHECK_PROGS([CMP], [cmp])
130if test "x$CMP" = x; then
131 AC_MSG_ERROR([cmp is not found])
132fi
133
144f1f98 134AC_CHECK_PROGS([YACC], [bison])
1569ec51 135if test "x$YACC" = x; then
6c826348 136 AC_MSG_ERROR([bison is not found])
1569ec51 137fi
138
1e901a75 139for file in /usr/src/unifont.bdf ; do
4931827f 140 if test -e $file ; then
1e901a75 141 AC_SUBST([UNIFONT_BDF], [$file])
4931827f 142 break
143 fi
144done
145
b977bf01 146AC_PROG_INSTALL
147AC_PROG_AWK
148AC_PROG_MAKE_SET
149
68807e5f 150# These are not a "must".
b977bf01 151AC_PATH_PROG(RUBY, ruby)
68807e5f 152AC_PATH_PROG(HELP2MAN, help2man)
6a161fa9 153
b977bf01 154#
155# Checks for host programs.
156#
157
158AC_PROG_CC
6a161fa9 159# Must be GCC.
160test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
161
4889bdec 162AC_GNU_SOURCE
b977bf01 163AC_SYS_LARGEFILE
164
165# Identify characteristics of the host architecture.
166AC_C_BIGENDIAN
167AC_CHECK_SIZEOF(void *)
168AC_CHECK_SIZEOF(long)
169
170if test "x$host_m32" = x1; then
171 # Force 32-bit mode.
172 CFLAGS="$CFLAGS -m32"
173 LDFLAGS="$LDFLAGS -m32"
174fi
175
176# Check LZO when compiling for the i386-pc.
177if test "$target_cpu"-"$platform" = i386-pc; then
aa24b516 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], ,
b977bf01 192 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
193
aa24b516 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])
b977bf01 200fi
201
4889bdec 202# Check for functions.
6e5a42fe 203AC_CHECK_FUNCS(posix_memalign memalign asprintf)
4889bdec 204
b977bf01 205#
206# Check for target programs.
207#
208
2a8a80e4 209
210# Use linker script if present, otherwise use builtin -N script.
211AC_MSG_CHECKING([for option to link raw image])
56978920 212if 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"
2a8a80e4 214 TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
56978920 215 TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
2a8a80e4 216else
217 TARGET_IMG_LDSCRIPT=
218 TARGET_IMG_LDFLAGS='-Wl,-N'
219 TARGET_IMG_LDFLAGS_AC='-Wl,-N'
220fi
221AC_SUBST(TARGET_IMG_LDSCRIPT)
222AC_SUBST(TARGET_IMG_LDFLAGS)
223AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
224
225# For platforms where ELF is not the default link format.
226AC_MSG_CHECKING([for command to convert module to ELF format])
56978920 227case "${host_os}" in
228 cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
2d05bc6a 229 *) ;;
230esac
2a8a80e4 231AC_SUBST(TARGET_OBJ2ELF)
232AC_MSG_RESULT([$TARGET_OBJ2ELF])
233
b977bf01 234# For cross-compiling.
580b2a0f 235if test "x$build" != "x$host"; then
b977bf01 236 # XXX this depends on the implementation of autoconf!
237 tmp_ac_tool_prefix="$ac_tool_prefix"
238 ac_tool_prefix=$target_alias-
239
240 AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
241 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
242 AC_CHECK_TOOL(OBJCOPY, objcopy)
243 AC_CHECK_TOOL(STRIP, strip)
244 AC_CHECK_TOOL(NM, nm)
245
246 ac_tool_prefix="$tmp_ac_tool_prefix"
247else
248 if test "x$TARGET_CC" = x; then
249 TARGET_CC=$CC
250 fi
251 AC_CHECK_TOOL(OBJCOPY, objcopy)
252 AC_CHECK_TOOL(STRIP, strip)
253 AC_CHECK_TOOL(NM, nm)
254fi
255AC_SUBST(TARGET_CC)
256
257
258# Test the C compiler for the target environment.
259tmp_CC="$CC"
260tmp_CFLAGS="$CFLAGS"
261tmp_LDFLAGS="$LDFLAGS"
262tmp_CPPFLAGS="$CPPFLAGS"
aa6d7826 263tmp_LIBS="$LIBS"
b977bf01 264CC="$TARGET_CC"
265CFLAGS="$TARGET_CFLAGS"
266CPPFLAGS="$TARGET_CPPFLAGS"
267LDFLAGS="$TARGET_LDFLAGS"
aa6d7826 268LIBS=""
b977bf01 269
270if test "x$TARGET_CFLAGS" = x; then
6a161fa9 271 # debug flags.
b977bf01 272 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
273 -Wundef -Wstrict-prototypes -g"
6a161fa9 274
275 # optimization flags.
322562ea 276 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
6a161fa9 277 CFLAGS=-Os
eb73121d 278 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
279 [grub_cv_cc_Os=yes],
280 [grub_cv_cc_Os=no])
6a161fa9 281 ])
322562ea 282 if test "x$grub_cv_cc_Os" = xyes; then
b977bf01 283 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
6a161fa9 284 else
b977bf01 285 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
6a161fa9 286 fi
287
288 # Force no alignment to save space on i386.
b977bf01 289 if test "x$target_cpu" = xi386; then
322562ea 290 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
6a161fa9 291 CFLAGS="-falign-loops=1"
eb73121d 292 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
293 [grub_cv_cc_falign_loop=yes],
294 [grub_cv_cc_falign_loop=no])
6a161fa9 295 ])
296
322562ea 297 if test "x$grub_cv_cc_falign_loop" = xyes; then
b977bf01 298 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
6a161fa9 299 else
b977bf01 300 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 301 fi
302 fi
b977bf01 303fi
6a161fa9 304
b977bf01 305if test "x$target_m32" = x1; then
306 # Force 32-bit mode.
307 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
308 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
6a161fa9 309fi
b977bf01 310
20011694 311if test "x$target_m64" = x1; then
312 # Force 64-bit mode.
7e9ca17a 313 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
314 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
315fi
316
317if test "$target_cpu"-"$platform" = x86_64-efi; then
318 # Use large model to support 4G memory
6e09b8b7 319 AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
320 CFLAGS="-m64 -mcmodel=large"
321 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
322 [grub_cv_cc_mcmodel=yes],
323 [grub_cv_cc_mcmodel=no])
324 ])
7e9ca17a 325 if test "x$grub_cv_cc_no_mcmodel" = xno; then
6e09b8b7 326 AC_MSG_ERROR([-mcmodel=large not supported, upgrade your gcc])
327 fi
7e9ca17a 328
329 # EFI writes to stack below %rsp, we must not use the red zone
330 AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
331 CFLAGS="-m64 -mno-red-zone"
332 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
333 [grub_cv_cc_no_red_zone=yes],
334 [grub_cv_cc_no_red_zone=no])
335 ])
336 if test "x$grub_cv_cc_no_red_zone" = xno; then
337 AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
338 fi
339
340 TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large -mno-red-zone"
20011694 341fi
342
baa2a121 343#
344# Compiler features.
345#
346
9035dce4 347# Need __enable_execute_stack() for nested function trampolines?
348grub_CHECK_ENABLE_EXECUTE_STACK
349
baa2a121 350# Smashing stack protector.
351grub_CHECK_STACK_PROTECTOR
c3db8364 352# Need that, because some distributions ship compilers that include
baa2a121 353# `-fstack-protector' in the default specs.
c3db8364 354if test "x$ssp_possible" = xyes; then
355 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
356fi
2a8a80e4 357grub_CHECK_STACK_ARG_PROBE
358# Cygwin's GCC uses alloca() to probe the stackframe on static
359# stack allocations above some threshold.
360if test x"$sap_possible" = xyes; then
361 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
362fi
baa2a121 363
b977bf01 364AC_SUBST(TARGET_CFLAGS)
365AC_SUBST(TARGET_CPPFLAGS)
366AC_SUBST(TARGET_LDFLAGS)
cb71ba20 367AC_SUBST(MODULE_LDFLAGS)
6a161fa9 368
aa6d7826 369# Set them to their new values for the tests below.
370CC="$TARGET_CC"
371CFLAGS="$TARGET_CFLAGS"
372CPPFLAGS="$TARGET_CPPFLAGS"
373LDFLAGS="$TARGET_LDFLAGS"
374
6a161fa9 375# Defined in aclocal.m4.
f6130a12 376grub_PROG_TARGET_CC
b977bf01 377grub_PROG_OBJCOPY_ABSOLUTE
cb71ba20 378grub_PROG_LD_BUILD_ID_NONE
4b13b216 379grub_ASM_USCORE
b977bf01 380if test "x$target_cpu" = xi386; then
2a8a80e4 381 if test ! -z "$TARGET_IMG_LDSCRIPT"; then
382 # Check symbols provided by linker script.
383 CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
384 fi
7810e747 385 if test "x$platform" = xpc; then
2a8a80e4 386 grub_CHECK_START_SYMBOL
387 grub_CHECK_BSS_START_SYMBOL
388 grub_CHECK_END_SYMBOL
389 fi
390 CFLAGS="$TARGET_CFLAGS"
4b13b216 391 grub_I386_ASM_PREFIX_REQUIREMENT
392 grub_I386_ASM_ADDR32
393 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
394 grub_I386_CHECK_REGPARM_BUG
5aded270 395else
f4917dfd 396 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
6a161fa9 397fi
398
c9a86192 399# Restore the flags.
9962ed99 400CC="$tmp_CC"
401CFLAGS="$tmp_CFLAGS"
402CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 403LDFLAGS="$tmp_LDFLAGS"
aa6d7826 404LIBS="$tmp_LIBS"
6a161fa9 405
4fe9862e 406#
2965c7cc 407# Check for options.
4fe9862e 408#
409
410# Memory manager debugging.
2965c7cc 411AC_ARG_ENABLE([mm-debug],
412 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 413 [include memory manager debugging]),
2965c7cc 414 [AC_DEFINE([MM_DEBUG], [1],
415 [Define to 1 if you enable memory manager debugging.])])
416
4fe9862e 417AC_ARG_ENABLE([grub-emu],
418 [AS_HELP_STRING([--enable-grub-emu],
419 [build and install the `grub-emu' debugging utility])])
d64399b5 420AC_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])])
4fe9862e 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])
429
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'])])])])
d64399b5 435
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])
441
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]
4fe9862e 446[fi]
447AC_SUBST([enable_grub_emu])
d64399b5 448AC_SUBST([enable_grub_emu_usb])
4fe9862e 449
99fadbaa 450AC_ARG_ENABLE([grub-fstest],
451 [AS_HELP_STRING([--enable-grub-fstest],
452 [build and install the `grub-fstest' debugging utility])])
453AC_SUBST([enable_grub_fstest])
454
2d05bc6a 455AC_ARG_ENABLE([grub-pe2elf],
456 [AS_HELP_STRING([--enable-grub-pe2elf],
457 [build and install the `grub-pe2elf' conversion utility])])
458AC_SUBST([enable_grub_pe2elf])
459
e52db1f7 460AC_ARG_ENABLE([grub-mkfont],
461 [AS_HELP_STRING([--enable-grub-mkfont],
462 [build and install the `grub-mkfont' utility])])
463if 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`
471fi
472AC_SUBST([enable_grub_mkfont])
473AC_SUBST([freetype_cflags])
474AC_SUBST([freetype_libs])
475
6a161fa9 476# Output files.
b977bf01 477AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
478 include/grub/machine:include/grub/$target_cpu/$platform])
7b455f4d 479AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
6a161fa9 480AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
481AC_OUTPUT