1 dnl Redefine AC_LANG_PROGRAM with a "-Wstrict-prototypes -Werror"-friendly
2 dnl version. Patch submitted to bug-autoconf in 2009-09-16.
3 m4_define([AC_LANG_PROGRAM(C)],
8 dnl Do *not* indent the following line: there may be CPP directives.
9 dnl Don't move the `;' right after for the same reason.
16 dnl Check whether target compiler is working
17 AC_DEFUN([grub_PROG_TARGET_CC],
18 [AC_MSG_CHECKING([whether target compiler is working])
19 AC_CACHE_VAL(grub_cv_prog_target_cc,
20 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
21 asm (".globl start; start:");
24 [grub_cv_prog_target_cc=yes],
25 [grub_cv_prog_target_cc=no])
27 AC_MSG_RESULT([$grub_cv_prog_target_cc])
29 if test "x$grub_cv_prog_target_cc" = xno; then
30 AC_MSG_ERROR([cannot compile for the target])
35 dnl grub_ASM_USCORE checks if C symbols get an underscore after
36 dnl compiling to assembler.
37 dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
38 dnl Erich Boleyn and modified by Yoshinori K. Okuji.
39 AC_DEFUN([grub_ASM_USCORE],
40 [AC_REQUIRE([AC_PROG_CC])
41 AC_REQUIRE([AC_PROG_EGREP])
42 AC_MSG_CHECKING([if C symbols get an underscore after compilation])
43 AC_CACHE_VAL(grub_cv_asm_uscore,
44 [cat > conftest.c <<\EOF
54 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
57 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
60 if $EGREP '(^|[^_[:alnum]])_func' conftest.s >/dev/null 2>&1; then
61 grub_cv_asm_uscore=yes
68 if test "x$grub_cv_asm_uscore" = xyes; then
69 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
70 [Define if C symbols get an underscore after compilation])
73 AC_MSG_RESULT([$grub_cv_asm_uscore])
77 dnl Some versions of `objcopy -O binary' vary their output depending
78 dnl on the link address.
79 AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
80 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
81 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
82 [cat > conftest.c <<\EOF
87 *((int *) 0x1000) = 2;
91 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
93 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
95 grub_cv_prog_objcopy_absolute=yes
96 for link_addr in 0x2000 0x8000 0x7C00; do
97 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
99 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
101 if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
103 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
105 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
106 mv -f conftest conftest.old
108 grub_cv_prog_objcopy_absolute=no
113 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
115 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
116 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
121 dnl Supply --build-id=none to ld if building modules.
122 dnl This suppresses warnings from ld on some systems
123 AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
124 [AC_MSG_CHECKING([whether linker accepts --build-id=none])
125 AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
126 [save_LDFLAGS="$LDFLAGS"
127 LDFLAGS="$LDFLAGS -Wl,--build-id=none"
128 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
129 [grub_cv_prog_ld_build_id_none=yes],
130 [grub_cv_prog_ld_build_id_none=no])
131 LDFLAGS="$save_LDFLAGS"
133 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
135 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
136 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
142 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
143 dnl instructions, but implicitly insert addr32 and data32 bytes so
144 dnl that the code works in real mode''.
146 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
147 dnl instructions,'' which seems right. This requires the programmer
148 dnl to explicitly insert addr32 and data32 instructions when they want
151 dnl We only support the newer versions, because the old versions cause
152 dnl major pain, by requiring manual assembly to get 16-bit instructions into
154 AC_DEFUN([grub_I386_ASM_ADDR32],
155 [AC_REQUIRE([AC_PROG_CC])
156 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
157 AC_MSG_CHECKING([for .code16 addr32 assembler support])
158 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
159 [cat > conftest.s.in <<\EOF
161 l1: @ADDR32@ movb %al, l1
164 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
165 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
167 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
170 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
171 grub_cv_i386_asm_addr32=yes
173 grub_cv_i386_asm_addr32=no
178 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
180 dnl check if our compiler is apple cc
181 dnl because it requires numerous workarounds
182 AC_DEFUN([grub_apple_cc],
183 [AC_REQUIRE([AC_PROG_CC])
184 AC_MSG_CHECKING([whether our compiler is apple cc])
185 AC_CACHE_VAL(grub_cv_apple_cc,
186 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
193 AC_MSG_RESULT([$grub_cv_apple_cc])])
195 dnl check if our target compiler is apple cc
196 dnl because it requires numerous workarounds
197 AC_DEFUN([grub_apple_target_cc],
198 [AC_REQUIRE([AC_PROG_CC])
199 AC_MSG_CHECKING([whether our target compiler is apple cc])
200 AC_CACHE_VAL(grub_cv_apple_target_cc,
201 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
202 grub_cv_apple_target_cc=yes
204 grub_cv_apple_target_cc=no
208 AC_MSG_RESULT([$grub_cv_apple_target_cc])])
211 dnl Later versions of GAS requires that addr32 and data32 prefixes
212 dnl appear in the same lines as the instructions they modify, while
213 dnl earlier versions requires that they appear in separate lines.
214 AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
215 [AC_REQUIRE([AC_PROG_CC])
217 [whether addr32 must be in the same line as the instruction])
218 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
219 [cat > conftest.s <<\EOF
221 l1: addr32 movb %al, l1
224 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
225 grub_cv_i386_asm_prefix_requirement=yes
227 grub_cv_i386_asm_prefix_requirement=no
232 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
233 grub_tmp_addr32="addr32"
234 grub_tmp_data32="data32"
236 grub_tmp_addr32="addr32;"
237 grub_tmp_data32="data32;"
240 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
241 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
242 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
243 [Define it to \"data32\" or \"data32;\" to make GAS happy])
245 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
248 dnl Older versions of GAS require that absolute indirect calls/jumps are
249 dnl not prefixed with `*', while later versions warn if not prefixed.
250 AC_DEFUN([grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK],
251 [AC_REQUIRE([AC_PROG_CC])
253 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
254 AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
255 [cat > conftest.s <<\EOF
262 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
263 grub_cv_i386_asm_absolute_without_asterisk=no
265 grub_cv_i386_asm_absolute_without_asterisk=yes
270 if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
271 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
272 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
275 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
278 dnl Check what symbol is defined as a bss start symbol.
279 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
280 AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
281 [AC_REQUIRE([AC_PROG_CC])
282 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
283 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
284 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
285 [[asm ("incl __bss_start")]])],
286 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
287 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
289 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
291 AC_MSG_CHECKING([if edata is defined by the compiler])
292 AC_CACHE_VAL(grub_cv_check_edata_symbol,
293 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
294 [[asm ("incl edata")]])],
295 [grub_cv_check_edata_symbol=yes],
296 [grub_cv_check_edata_symbol=no])])
298 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
300 AC_MSG_CHECKING([if _edata is defined by the compiler])
301 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
302 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
303 [[asm ("incl _edata")]])],
304 [grub_cv_check_uscore_edata_symbol=yes],
305 [grub_cv_check_uscore_edata_symbol=no])])
307 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
309 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
311 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
312 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
313 elif test "x$grub_cv_check_edata_symbol" = xyes; then
314 AC_DEFINE([BSS_START_SYMBOL], [edata])
315 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
316 AC_DEFINE([BSS_START_SYMBOL], [_edata])
318 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
322 dnl Check what symbol is defined as an end symbol.
323 dnl Written by Yoshinori K. Okuji.
324 AC_DEFUN([grub_CHECK_END_SYMBOL],
325 [AC_REQUIRE([AC_PROG_CC])
326 AC_MSG_CHECKING([if end is defined by the compiler])
327 AC_CACHE_VAL(grub_cv_check_end_symbol,
328 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
329 [[asm ("incl end")]])],
330 [grub_cv_check_end_symbol=yes],
331 [grub_cv_check_end_symbol=no])])
333 AC_MSG_RESULT([$grub_cv_check_end_symbol])
335 AC_MSG_CHECKING([if _end is defined by the compiler])
336 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
337 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
338 [[asm ("incl _end")]])],
339 [grub_cv_check_uscore_end_symbol=yes],
340 [grub_cv_check_uscore_end_symbol=no])])
342 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
344 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
346 if test "x$grub_cv_check_end_symbol" = xyes; then
347 AC_DEFINE([END_SYMBOL], [end])
348 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
349 AC_DEFINE([END_SYMBOL], [_end])
351 AC_MSG_ERROR([neither end nor _end is defined])
355 dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
356 AC_DEFUN([grub_CHECK_ENABLE_EXECUTE_STACK],[
357 AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
359 void f (int (*p) (void));
362 int nestedfunc (void) { return i; }
366 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
369 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
371 if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
372 AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
373 [Define to 1 if GCC generates calls to __enable_execute_stack()])
382 dnl Check if the C compiler supports `-fstack-protector'.
383 AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
384 [# Smashing stack protector.
386 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
387 # Is this a reliable test case?
388 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
389 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
390 # `ac_compile' like this correct, after all?
391 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
393 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
401 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
402 AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
403 [# Smashing stack arg probe.
405 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
406 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
407 [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
409 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
417 dnl Check if ln can handle directories properly (mingw).
418 AC_DEFUN([grub_CHECK_LINK_DIR],[
419 AC_MSG_CHECKING([whether ln can handle directories properly])
420 [mkdir testdir 2>/dev/null
422 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
423 *) reldir=../$srcdir/include/grub/util ;;
425 if ln -s $reldir testdir/util 2>/dev/null ; then]
435 dnl Check if the C compiler supports `-fPIE'.
436 AC_DEFUN([grub_CHECK_PIE],[
437 [# Position independent executable.
439 AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
440 # Is this a reliable test case?
447 #error NO __PIE__ DEFINED
451 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
452 # `ac_compile' like this correct, after all?
453 if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
455 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?