]> git.proxmox.com Git - grub2.git/blame - configure.ac
2009-02-08 Vesa Jääskeläinen <chaac@nic.fi>
[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
106case "$target_os" in
107 mingw32) target_os=cygwin ;;
108esac
109
b977bf01 110AC_SUBST(target_cpu)
2d05bc6a 111AC_SUBST(target_os)
05568c2e 112AC_SUBST(platform)
6a161fa9 113
b977bf01 114#
115# Checks for build programs.
116#
144f1f98 117
6c826348 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.
120AC_CHECK_PROGS([CMP], [cmp])
121if test "x$CMP" = x; then
122 AC_MSG_ERROR([cmp is not found])
123fi
124
144f1f98 125AC_CHECK_PROGS([YACC], [bison])
1569ec51 126if test "x$YACC" = x; then
6c826348 127 AC_MSG_ERROR([bison is not found])
1569ec51 128fi
129
1e901a75 130for file in /usr/src/unifont.bdf ; do
4931827f 131 if test -e $file ; then
1e901a75 132 AC_SUBST([UNIFONT_BDF], [$file])
4931827f 133 break
134 fi
135done
136
b977bf01 137AC_PROG_INSTALL
138AC_PROG_AWK
139AC_PROG_MAKE_SET
140
68807e5f 141# These are not a "must".
b977bf01 142AC_PATH_PROG(RUBY, ruby)
68807e5f 143AC_PATH_PROG(HELP2MAN, help2man)
6a161fa9 144
b977bf01 145#
146# Checks for host programs.
147#
148
149AC_PROG_CC
6a161fa9 150# Must be GCC.
151test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])
152
4889bdec 153AC_GNU_SOURCE
b977bf01 154AC_SYS_LARGEFILE
155
156# Identify characteristics of the host architecture.
157AC_C_BIGENDIAN
158AC_CHECK_SIZEOF(void *)
159AC_CHECK_SIZEOF(long)
160
161if test "x$host_m32" = x1; then
162 # Force 32-bit mode.
163 CFLAGS="$CFLAGS -m32"
164 LDFLAGS="$LDFLAGS -m32"
165fi
166
167# Check LZO when compiling for the i386-pc.
168if test "$target_cpu"-"$platform" = i386-pc; then
aa24b516 169 AC_ARG_ENABLE([lzo],
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])])])])
180 AC_SUBST([LIBLZO])
181 [LIBS="$LIBS $LIBLZO"]
182 AC_CHECK_FUNC([lzo1x_999_compress], ,
b977bf01 183 [AC_MSG_ERROR([LZO1X-999 must be enabled])])
184
aa24b516 185 [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
186 AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
187 [else]
188 AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
189 [fi]
190 AC_SUBST([enable_lzo])
b977bf01 191fi
192
4889bdec 193# Check for functions.
6e5a42fe 194AC_CHECK_FUNCS(posix_memalign memalign asprintf)
4889bdec 195
b977bf01 196#
197# Check for target programs.
198#
199
2a8a80e4 200
201# Use linker script if present, otherwise use builtin -N script.
202AC_MSG_CHECKING([for option to link raw image])
203if 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"
207else
208 TARGET_IMG_LDSCRIPT=
209 TARGET_IMG_LDFLAGS='-Wl,-N'
210 TARGET_IMG_LDFLAGS_AC='-Wl,-N'
211fi
212AC_SUBST(TARGET_IMG_LDSCRIPT)
213AC_SUBST(TARGET_IMG_LDFLAGS)
214AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
215
216# For platforms where ELF is not the default link format.
217AC_MSG_CHECKING([for command to convert module to ELF format])
2d05bc6a 218case "${host_os}:${target_os}" in
219 cygwin:cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
220 *) ;;
221esac
2a8a80e4 222AC_SUBST(TARGET_OBJ2ELF)
223AC_MSG_RESULT([$TARGET_OBJ2ELF])
224
b977bf01 225# For cross-compiling.
580b2a0f 226if test "x$build" != "x$host"; then
b977bf01 227 # XXX this depends on the implementation of autoconf!
228 tmp_ac_tool_prefix="$ac_tool_prefix"
229 ac_tool_prefix=$target_alias-
230
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)
236
237 ac_tool_prefix="$tmp_ac_tool_prefix"
238else
239 if test "x$TARGET_CC" = x; then
240 TARGET_CC=$CC
241 fi
242 AC_CHECK_TOOL(OBJCOPY, objcopy)
243 AC_CHECK_TOOL(STRIP, strip)
244 AC_CHECK_TOOL(NM, nm)
245fi
246AC_SUBST(TARGET_CC)
247
248
249# Test the C compiler for the target environment.
250tmp_CC="$CC"
251tmp_CFLAGS="$CFLAGS"
252tmp_LDFLAGS="$LDFLAGS"
253tmp_CPPFLAGS="$CPPFLAGS"
aa6d7826 254tmp_LIBS="$LIBS"
b977bf01 255CC="$TARGET_CC"
256CFLAGS="$TARGET_CFLAGS"
257CPPFLAGS="$TARGET_CPPFLAGS"
258LDFLAGS="$TARGET_LDFLAGS"
aa6d7826 259LIBS=""
b977bf01 260
261if test "x$TARGET_CFLAGS" = x; then
6a161fa9 262 # debug flags.
b977bf01 263 TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
264 -Wundef -Wstrict-prototypes -g"
6a161fa9 265
266 # optimization flags.
322562ea 267 AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
6a161fa9 268 CFLAGS=-Os
eb73121d 269 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
270 [grub_cv_cc_Os=yes],
271 [grub_cv_cc_Os=no])
6a161fa9 272 ])
322562ea 273 if test "x$grub_cv_cc_Os" = xyes; then
b977bf01 274 TARGET_CFLAGS="$TARGET_CFLAGS -Os"
6a161fa9 275 else
b977bf01 276 TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
6a161fa9 277 fi
278
279 # Force no alignment to save space on i386.
b977bf01 280 if test "x$target_cpu" = xi386; then
322562ea 281 AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
6a161fa9 282 CFLAGS="-falign-loops=1"
eb73121d 283 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
284 [grub_cv_cc_falign_loop=yes],
285 [grub_cv_cc_falign_loop=no])
6a161fa9 286 ])
287
322562ea 288 if test "x$grub_cv_cc_falign_loop" = xyes; then
b977bf01 289 TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
6a161fa9 290 else
b977bf01 291 TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
6a161fa9 292 fi
293 fi
b977bf01 294fi
6a161fa9 295
b977bf01 296if test "x$target_m32" = x1; then
297 # Force 32-bit mode.
298 TARGET_CFLAGS="$TARGET_CFLAGS -m32"
299 TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
6a161fa9 300fi
b977bf01 301
20011694 302if test "x$target_m64" = x1; then
303 # Force 64-bit mode.
304 TARGET_CFLAGS="$TARGET_CFLAGS -m64"
305 TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
306fi
307
baa2a121 308#
309# Compiler features.
310#
311
9035dce4 312# Need __enable_execute_stack() for nested function trampolines?
313grub_CHECK_ENABLE_EXECUTE_STACK
314
baa2a121 315# Smashing stack protector.
316grub_CHECK_STACK_PROTECTOR
c3db8364 317# Need that, because some distributions ship compilers that include
baa2a121 318# `-fstack-protector' in the default specs.
c3db8364 319if test "x$ssp_possible" = xyes; then
320 TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
321fi
2a8a80e4 322grub_CHECK_STACK_ARG_PROBE
323# Cygwin's GCC uses alloca() to probe the stackframe on static
324# stack allocations above some threshold.
325if test x"$sap_possible" = xyes; then
326 TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
327fi
baa2a121 328
b977bf01 329AC_SUBST(TARGET_CFLAGS)
330AC_SUBST(TARGET_CPPFLAGS)
331AC_SUBST(TARGET_LDFLAGS)
cb71ba20 332AC_SUBST(MODULE_LDFLAGS)
6a161fa9 333
aa6d7826 334# Set them to their new values for the tests below.
335CC="$TARGET_CC"
336CFLAGS="$TARGET_CFLAGS"
337CPPFLAGS="$TARGET_CPPFLAGS"
338LDFLAGS="$TARGET_LDFLAGS"
339
6a161fa9 340# Defined in aclocal.m4.
f6130a12 341grub_PROG_TARGET_CC
b977bf01 342grub_PROG_OBJCOPY_ABSOLUTE
cb71ba20 343grub_PROG_LD_BUILD_ID_NONE
4b13b216 344grub_ASM_USCORE
b977bf01 345if test "x$target_cpu" = xi386; then
2a8a80e4 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"
349 fi
7810e747 350 if test "x$platform" = xpc; then
2a8a80e4 351 grub_CHECK_START_SYMBOL
352 grub_CHECK_BSS_START_SYMBOL
353 grub_CHECK_END_SYMBOL
354 fi
355 CFLAGS="$TARGET_CFLAGS"
4b13b216 356 grub_I386_ASM_PREFIX_REQUIREMENT
357 grub_I386_ASM_ADDR32
358 grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
359 grub_I386_CHECK_REGPARM_BUG
5aded270 360else
f4917dfd 361 AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
6a161fa9 362fi
363
c9a86192 364# Restore the flags.
9962ed99 365CC="$tmp_CC"
366CFLAGS="$tmp_CFLAGS"
367CPPFLAGS="$tmp_CPPFLAGS"
c9a86192 368LDFLAGS="$tmp_LDFLAGS"
aa6d7826 369LIBS="$tmp_LIBS"
6a161fa9 370
4fe9862e 371#
2965c7cc 372# Check for options.
4fe9862e 373#
374
375# Memory manager debugging.
2965c7cc 376AC_ARG_ENABLE([mm-debug],
377 AS_HELP_STRING([--enable-mm-debug],
90ce5d56 378 [include memory manager debugging]),
2965c7cc 379 [AC_DEFINE([MM_DEBUG], [1],
380 [Define to 1 if you enable memory manager debugging.])])
381
4fe9862e 382AC_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])
391
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'])])])])
397[fi]
398AC_SUBST([enable_grub_emu])
399
99fadbaa 400AC_ARG_ENABLE([grub-fstest],
401 [AS_HELP_STRING([--enable-grub-fstest],
402 [build and install the `grub-fstest' debugging utility])])
403AC_SUBST([enable_grub_fstest])
404
2d05bc6a 405AC_ARG_ENABLE([grub-pe2elf],
406 [AS_HELP_STRING([--enable-grub-pe2elf],
407 [build and install the `grub-pe2elf' conversion utility])])
408AC_SUBST([enable_grub_pe2elf])
409
e52db1f7 410AC_ARG_ENABLE([grub-mkfont],
411 [AS_HELP_STRING([--enable-grub-mkfont],
412 [build and install the `grub-mkfont' utility])])
413if test x"$enable_grub_mkfont" = xyes ; then
414 # Check for freetype libraries.
415 AC_CHECK_PROGS([FREETYPE], [freetype-config])
416 if test "x$FREETYPE" = x ; then
417 AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
418 fi
419 freetype_cflags=`freetype-config --cflags`
420 freetype_libs=`freetype-config --libs`
421fi
422AC_SUBST([enable_grub_mkfont])
423AC_SUBST([freetype_cflags])
424AC_SUBST([freetype_libs])
425
6a161fa9 426# Output files.
b977bf01 427AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
428 include/grub/machine:include/grub/$target_cpu/$platform])
7b455f4d 429AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
6a161fa9 430AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
431AC_OUTPUT