~ubuntu-branches/ubuntu/wily/grub2/wily-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# Process this file with autoconf to produce a configure script.

# Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009  Free Software Foundation, Inc.
#
# This configure.ac is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

dnl This configure script is complicated, because GRUB needs to deal
dnl with three potentially different types:
dnl
dnl   build  -- the environment for building GRUB
dnl   host   -- the environment for running utilities
dnl   target -- the environment for running GRUB
dnl
dnl In addition, GRUB needs to deal with a platform specification
dnl which specifies the system running GRUB, such as firmware.
dnl This is necessary because the target type in autoconf does not
dnl describe such a system very well.
dnl
dnl The current strategy is to use variables with no prefix (such as
dnl CC, CFLAGS, etc.) for the host type as well as the build type,
dnl because GRUB does not need to use those variables for the build
dnl type, so there is no conflict. Variables with the prefix "TARGET_"
dnl (such as TARGET_CC, TARGET_CFLAGS, etc.) are used for the target
dnl type.


AC_INIT([GRUB],[1.96],[bug-grub@gnu.org])
AC_PREREQ(2.59)
AC_CONFIG_SRCDIR([include/grub/dl.h])
AC_CONFIG_HEADER([config.h])

# Checks for host and target systems.
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

# Program name transformations
AC_ARG_PROGRAM

case "$host_cpu" in
  powerpc64) host_m32=1 ;;
esac

case "$target_cpu" in
  i[[3456]]86) target_cpu=i386 ;;
esac

# Specify the platform (such as firmware).
AC_ARG_WITH([platform],
            AS_HELP_STRING([--with-platform=PLATFORM],
                           [select the host platform [[guessed]]]))

# Guess the platform if not specified.
if test "x$with_platform" = x; then
  case "$target_cpu"-"$target_vendor" in
    i386-apple) platform=efi ;;
    i386-*) platform=pc ;;
    x86_64-apple) platform=efi ;;
    x86_64-*) platform=pc ;;
    powerpc-*) platform=ieee1275 ;;
    powerpc64-*) platform=ieee1275 ;;
    sparc64-*) platform=ieee1275 ;;
    *) AC_MSG_ERROR([unsupported CPU: "$target_cpu"]) ;;
  esac
else
  platform="$with_platform"
fi

# Adjust CPU unless target was explicitly specified.
if test -z "$target_alias"; then
  case "$target_cpu"-"$platform" in
    x86_64-efi) ;;
    x86_64-*) target_cpu=i386 ;;
    powerpc64-ieee1275) target_cpu=powerpc ;;
  esac
fi

# Check if the platform is supported, make final adjustments.
case "$target_cpu"-"$platform" in
  i386-efi) ;;
  x86_64-efi) ;;
  i386-pc) ;;
  i386-coreboot) ;;
  i386-linuxbios) platform=coreboot ;;
  i386-ieee1275) ;;
  powerpc-ieee1275) ;;
  sparc64-ieee1275) ;;
  *) AC_MSG_ERROR([platform "$platform" is not supported for target CPU "$target_cpu"]) ;;
esac

case "$target_cpu" in
  i386 | powerpc) target_m32=1 ;;
  x86_64 | sparc64) target_m64=1 ;;
esac

case "$host_os" in
  mingw32) host_os=cygwin ;;
esac

# This normalizes the names, and creates a new variable ("host_kernel")
# while at it, since the mapping is not always 1:1 (e.g. different OSes
# using the same kernel type).
case "$host_os" in
  gnu*)				host_kernel=hurd ;;
  linux*)			host_kernel=linux ;;
  freebsd* | kfreebsd*-gnu)	host_kernel=freebsd ;;
  cygwin)			host_kernel=windows ;;
esac

AC_SUBST(host_cpu)
AC_SUBST(host_os)
AC_SUBST(host_kernel)

AC_SUBST(target_cpu)
AC_SUBST(platform)

#
# Checks for build programs.
#

# Although cmp is listed in the GNU Coding Standards as a command which
# can used directly, OpenBSD lacks cmp in the default installation.
AC_CHECK_PROGS([CMP], [cmp])
if test "x$CMP" = x; then
  AC_MSG_ERROR([cmp is not found])
fi

AC_CHECK_PROGS([YACC], [bison])
if test "x$YACC" = x; then
  AC_MSG_ERROR([bison is not found])
fi

for file in /usr/src/unifont.bdf ; do
  if test -e $file ; then
    AC_SUBST([UNIFONT_BDF], [$file])
    break
  fi
done

AC_PROG_INSTALL
AC_PROG_AWK
AC_PROG_MAKE_SET

# These are not a "must".
AC_PATH_PROG(RUBY, ruby)
AC_PATH_PROG(HELP2MAN, help2man)

#
# Checks for host programs.
#

AC_PROG_CC
# Must be GCC.
test "x$GCC" = xyes || AC_MSG_ERROR([GCC is required])

AC_GNU_SOURCE
AC_SYS_LARGEFILE

# Identify characteristics of the host architecture.
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long)

if test "x$host_m32" = x1; then
  # Force 32-bit mode.
  CFLAGS="$CFLAGS -m32"
  LDFLAGS="$LDFLAGS -m32"
fi

# Check LZO when compiling for the i386-pc.
if test "$target_cpu"-"$platform" = i386-pc; then
  AC_ARG_ENABLE([lzo],
	      [AS_HELP_STRING([--enable-lzo],
                             [use lzo to compress kernel (default is lzma)])])
  [if [ x"$enable_lzo" = xyes ]; then
    # There are three possibilities. LZO version 2 installed with the name
    # liblzo2, with the name liblzo, and LZO version 1.]
    AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
    AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
      [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
        [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
	       [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
    AC_SUBST([LIBLZO])
    [LIBS="$LIBS $LIBLZO"]
    AC_CHECK_FUNC([lzo1x_999_compress], ,
	        [AC_MSG_ERROR([LZO1X-999 must be enabled])])

    [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
    AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
  [else]
    AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
  [fi]
  AC_SUBST([enable_lzo])
fi

# Check for functions.
AC_CHECK_FUNCS(posix_memalign memalign asprintf)

#
# Check for target programs.
#


# Use linker script if present, otherwise use builtin -N script.
AC_MSG_CHECKING([for option to link raw image])
if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
  TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
  TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
  TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
else
  TARGET_IMG_LDSCRIPT=
  TARGET_IMG_LDFLAGS='-Wl,-N'
  TARGET_IMG_LDFLAGS_AC='-Wl,-N'
fi
AC_SUBST(TARGET_IMG_LDSCRIPT)
AC_SUBST(TARGET_IMG_LDFLAGS)
AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])

# For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format])
case "${host_os}" in
  cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
  *) ;;
esac
AC_SUBST(TARGET_OBJ2ELF)
AC_MSG_RESULT([$TARGET_OBJ2ELF])

# Find tools for the target.
if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
  tmp_ac_tool_prefix="$ac_tool_prefix"
  ac_tool_prefix=$target_alias-

  AC_CHECK_TOOLS(TARGET_CC, [gcc egcs cc],
                 [AC_MSG_ERROR([none of gcc, egcs and cc is found. set TARGET_CC manually.])])
  AC_CHECK_TOOL(OBJCOPY, objcopy)
  AC_CHECK_TOOL(STRIP, strip)
  AC_CHECK_TOOL(NM, nm)

  ac_tool_prefix="$tmp_ac_tool_prefix"
else
  if test "x$TARGET_CC" = x; then
    TARGET_CC=$CC
  fi
  AC_CHECK_TOOL(OBJCOPY, objcopy)
  AC_CHECK_TOOL(STRIP, strip)
  AC_CHECK_TOOL(NM, nm)
fi
AC_SUBST(TARGET_CC)


# Test the C compiler for the target environment.
tmp_CC="$CC"
tmp_CFLAGS="$CFLAGS"
tmp_LDFLAGS="$LDFLAGS"
tmp_CPPFLAGS="$CPPFLAGS"
tmp_LIBS="$LIBS"
CC="$TARGET_CC"
CFLAGS="$TARGET_CFLAGS"
CPPFLAGS="$TARGET_CPPFLAGS"
LDFLAGS="$TARGET_LDFLAGS"
LIBS=""

if test "x$TARGET_CFLAGS" = x; then
  # debug flags.
  TARGET_CFLAGS="-Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes \
                 -Wundef -Wstrict-prototypes -g"

  # optimization flags.
  AC_CACHE_CHECK([whether optimization for size works], grub_cv_cc_Os, [
    CFLAGS=-Os
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_Os=yes],
		      [grub_cv_cc_Os=no])
  ])
  if test "x$grub_cv_cc_Os" = xyes; then
    TARGET_CFLAGS="$TARGET_CFLAGS -Os"
  else
    TARGET_CFLAGS="$TARGET_CFLAGS -O2 -fno-strength-reduce -fno-unroll-loops"
  fi

  # Force no alignment to save space on i386.
  if test "x$target_cpu" = xi386; then
    AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
      CFLAGS="-falign-loops=1"
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		        [grub_cv_cc_falign_loop=yes],
			[grub_cv_cc_falign_loop=no])
    ])

    if test "x$grub_cv_cc_falign_loop" = xyes; then
      TARGET_CFLAGS="$TARGET_CFLAGS -falign-jumps=1 -falign-loops=1 -falign-functions=1"
    else
      TARGET_CFLAGS="$TARGET_CFLAGS -malign-jumps=1 -malign-loops=1 -malign-functions=1"
    fi
  fi
fi

if test "x$target_m32" = x1; then
  # Force 32-bit mode.
  TARGET_CFLAGS="$TARGET_CFLAGS -m32"
  TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
fi

if test "x$target_m64" = x1; then
  # Force 64-bit mode.
  TARGET_CFLAGS="$TARGET_CFLAGS -m64"
  TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
fi

if test "$target_cpu"-"$platform" = x86_64-efi; then
  # Use large model to support 4G memory
  AC_CACHE_CHECK([whether option -mcmodel=large works], grub_cv_cc_mcmodel, [
    CFLAGS="-m64 -mcmodel=large"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_mcmodel=yes],
		      [grub_cv_cc_mcmodel=no])
  ])
  if test "x$grub_cv_cc_no_mcmodel" = xno; then
    AC_MSG_ERROR([-mcmodel=large not supported, upgrade your gcc])
  fi

  # EFI writes to stack below %rsp, we must not use the red zone
  AC_CACHE_CHECK([whether option -mno-red-zone works], grub_cv_cc_no_red_zone, [
    CFLAGS="-m64 -mno-red-zone"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
		      [grub_cv_cc_no_red_zone=yes],
		      [grub_cv_cc_no_red_zone=no])
  ])
  if test "x$grub_cv_cc_no_red_zone" = xno; then
    AC_MSG_ERROR([-mno-red-zone not supported, upgrade your gcc])
  fi

  TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large -mno-red-zone"
fi

#
# Compiler features.
#

# Need __enable_execute_stack() for nested function trampolines?
grub_CHECK_ENABLE_EXECUTE_STACK

# Smashing stack protector.
grub_CHECK_STACK_PROTECTOR
# Need that, because some distributions ship compilers that include
# `-fstack-protector' in the default specs.
if test "x$ssp_possible" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -fno-stack-protector"
fi
grub_CHECK_STACK_ARG_PROBE
# Cygwin's GCC uses alloca() to probe the stackframe on static
# stack allocations above some threshold.
if test x"$sap_possible" = xyes; then
  TARGET_CFLAGS="$TARGET_CFLAGS -mno-stack-arg-probe"
fi

AC_SUBST(TARGET_CFLAGS)
AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_LDFLAGS)

# Set them to their new values for the tests below.
CC="$TARGET_CC"
CFLAGS="$TARGET_CFLAGS"
CPPFLAGS="$TARGET_CPPFLAGS"
LDFLAGS="$TARGET_LDFLAGS"

# Check for target functions.
AC_CHECK_FUNCS(__bswapsi2 __bswapdi2)

# Defined in aclocal.m4.
grub_PROG_TARGET_CC
grub_PROG_OBJCOPY_ABSOLUTE
grub_PROG_LD_BUILD_ID_NONE
grub_ASM_USCORE
if test "x$target_cpu" = xi386; then
  if test ! -z "$TARGET_IMG_LDSCRIPT"; then
    # Check symbols provided by linker script.
    CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
  fi
  if test "x$platform" = xpc; then
    grub_CHECK_BSS_START_SYMBOL
    grub_CHECK_END_SYMBOL
  fi
  CFLAGS="$TARGET_CFLAGS"
  grub_I386_ASM_PREFIX_REQUIREMENT
  grub_I386_ASM_ADDR32
  grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK
else
  AC_DEFINE([NESTED_FUNC_ATTR], [], [Catch gcc bug])
fi

AH_BOTTOM([#if defined(__i386__) && !defined(GRUB_UTIL)
#define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (1)))
#else
#define NESTED_FUNC_ATTR
#endif])

# Restore the flags.
CC="$tmp_CC"
CFLAGS="$tmp_CFLAGS"
CPPFLAGS="$tmp_CPPFLAGS"
LDFLAGS="$tmp_LDFLAGS"
LIBS="$tmp_LIBS"

#
# Check for options.
#

# Memory manager debugging.
AC_ARG_ENABLE([mm-debug], 
	      AS_HELP_STRING([--enable-mm-debug],
                             [include memory manager debugging]),
              [AC_DEFINE([MM_DEBUG], [1],
                         [Define to 1 if you enable memory manager debugging.])])

AC_ARG_ENABLE([grub-emu],
	      [AS_HELP_STRING([--enable-grub-emu],
                             [build and install the `grub-emu' debugging utility])])
AC_ARG_ENABLE([grub-emu-usb],
	      [AS_HELP_STRING([--enable-grub-emu-usb],
                             [build and install the `grub-emu' debugging utility with USB support])])
[if [ x"$enable_grub_emu" = xyes ]; then
  # Check for curses libraries.]
  AC_CHECK_LIB([ncurses], [wgetch], [LIBCURSES="-lncurses"],
    [AC_CHECK_LIB([curses], [wgetch], [LIBCURSES="-lcurses"],
      [AC_MSG_ERROR([(n)curses libraries are required to build `grub-emu'])])])
  AC_SUBST([LIBCURSES])

  [# Check for headers.]
  AC_CHECK_HEADERS([ncurses/curses.h], [],
    [AC_CHECK_HEADERS([ncurses.h], [],
      [AC_CHECK_HEADERS([curses.h], [],
	[AC_MSG_ERROR([(n)curses header files are required to build `grub-emu'])])])])

  [if [ x"$enable_grub_emu_usb" = xyes ]; then
    # Check for libusb libraries.]
    AC_CHECK_LIB([usb], [usb_claim_interface], [LIBUSB="-lusb"],
      [AC_MSG_ERROR([libusb libraries are required to build `grub-emu' with USB support])])
    AC_SUBST([LIBUSB])

    [# Check for headers.]
    AC_CHECK_HEADERS([usb.h], [],
      [AC_MSG_ERROR([libusb header file is required to build `grub-emu' with USB support])])
  [fi]
[fi]
AC_SUBST([enable_grub_emu])
AC_SUBST([enable_grub_emu_usb])

AC_ARG_ENABLE([grub-fstest],
	      [AS_HELP_STRING([--enable-grub-fstest],
                             [build and install the `grub-fstest' debugging utility])])
AC_SUBST([enable_grub_fstest])

AC_ARG_ENABLE([grub-pe2elf],
	      [AS_HELP_STRING([--enable-grub-pe2elf],
                             [build and install the `grub-pe2elf' conversion utility])])
AC_SUBST([enable_grub_pe2elf])

AC_ARG_ENABLE([grub-mkfont],
	      [AS_HELP_STRING([--enable-grub-mkfont],
                             [build and install the `grub-mkfont' utility])])
if test x"$enable_grub_mkfont" = xyes ; then
  # Check for freetype libraries.
  AC_CHECK_PROGS([FREETYPE], [freetype-config])
  if test "x$FREETYPE" = x ; then
    AC_MSG_ERROR([freetype2 libraries are required to build `grub-mkfont'])
  fi
  freetype_cflags=`freetype-config --cflags`
  freetype_libs=`freetype-config --libs`
fi
AC_SUBST([enable_grub_mkfont])
AC_SUBST([freetype_cflags])
AC_SUBST([freetype_libs])

AC_ARG_ENABLE([efiemu],
	      [AS_HELP_STRING([--enable-efiemu],
                             [build and install the efiemu runtimes])])
AC_SUBST([enable_efiemu])

# Output files.
grub_CHECK_LINK_DIR
if test x"$link_dir" = xyes ; then
  AC_CONFIG_LINKS([include/grub/cpu:include/grub/$target_cpu
	include/grub/machine:include/grub/$target_cpu/$platform])
else
  mkdir -p include/grub 2>/dev/null
  rm -rf include/grub/cpu
  cp -rp $srcdir/include/grub/$target_cpu include/grub/cpu 2>/dev/null
  rm -rf include/grub/machine
  cp -rp $srcdir/include/grub/$target_cpu/$platform include/grub/machine 2>/dev/null
fi
AC_CONFIG_FILES([Makefile gensymlist.sh genkernsyms.sh])
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
AC_OUTPUT