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: nop");
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_MSG_CHECKING([if C symbols get an underscore after compilation])
42 AC_CACHE_VAL(grub_cv_asm_uscore,
43 [cat > conftest.c <<\EOF
53 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
56 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
59 if grep _func conftest.s >/dev/null 2>&1; then
60 grub_cv_asm_uscore=yes
67 if test "x$grub_cv_asm_uscore" = xyes; then
68 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
69 [Define if C symbols get an underscore after compilation])
72 AC_MSG_RESULT([$grub_cv_asm_uscore])
76 dnl Some versions of `objcopy -O binary' vary their output depending
77 dnl on the link address.
78 AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
79 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
80 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
81 [cat > conftest.c <<\EOF
86 *((int *) 0x1000) = 2;
90 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
92 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
94 grub_cv_prog_objcopy_absolute=yes
95 for link_addr in 2000 8000 7C00; do
96 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
98 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
100 if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
102 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
104 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
105 mv -f conftest conftest.old
107 grub_cv_prog_objcopy_absolute=no
112 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
114 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
115 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
120 dnl Supply --build-id=none to ld if building modules.
121 dnl This suppresses warnings from ld on some systems
122 AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE,
123 [AC_MSG_CHECKING([whether linker accepts --build-id=none])
124 AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
125 [save_LDFLAGS="$LDFLAGS"
126 LDFLAGS="$LDFLAGS -Wl,--build-id=none"
127 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
128 [grub_cv_prog_ld_build_id_none=yes],
129 [grub_cv_prog_ld_build_id_none=no])
130 LDFLAGS="$save_LDFLAGS"
132 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
134 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
135 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
141 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
142 dnl instructions, but implicitly insert addr32 and data32 bytes so
143 dnl that the code works in real mode''.
145 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
146 dnl instructions,'' which seems right. This requires the programmer
147 dnl to explicitly insert addr32 and data32 instructions when they want
150 dnl We only support the newer versions, because the old versions cause
151 dnl major pain, by requiring manual assembly to get 16-bit instructions into
153 AC_DEFUN(grub_I386_ASM_ADDR32,
154 [AC_REQUIRE([AC_PROG_CC])
155 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
156 AC_MSG_CHECKING([for .code16 addr32 assembler support])
157 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
158 [cat > conftest.s.in <<\EOF
160 l1: @ADDR32@ movb %al, l1
163 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
164 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
166 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
169 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
170 grub_cv_i386_asm_addr32=yes
172 grub_cv_i386_asm_addr32=no
177 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
179 dnl check if our compiler is apple cc
180 dnl because it requires numerous workarounds
181 AC_DEFUN(grub_apple_cc,
182 [AC_REQUIRE([AC_PROG_CC])
183 AC_MSG_CHECKING([whether our compiler is apple cc])
184 AC_CACHE_VAL(grub_cv_apple_cc,
185 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
192 AC_MSG_RESULT([$grub_cv_apple_cc])])
194 dnl check if our target compiler is apple cc
195 dnl because it requires numerous workarounds
196 AC_DEFUN(grub_apple_target_cc,
197 [AC_REQUIRE([AC_PROG_CC])
198 AC_MSG_CHECKING([whether our target compiler is apple cc])
199 AC_CACHE_VAL(grub_cv_apple_target_cc,
200 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
201 grub_cv_apple_target_cc=yes
203 grub_cv_apple_target_cc=no
207 AC_MSG_RESULT([$grub_cv_apple_target_cc])])
210 dnl Later versions of GAS requires that addr32 and data32 prefixes
211 dnl appear in the same lines as the instructions they modify, while
212 dnl earlier versions requires that they appear in separate lines.
213 AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT,
214 [AC_REQUIRE([AC_PROG_CC])
216 [whether addr32 must be in the same line as the instruction])
217 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
218 [cat > conftest.s <<\EOF
220 l1: addr32 movb %al, l1
223 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
224 grub_cv_i386_asm_prefix_requirement=yes
226 grub_cv_i386_asm_prefix_requirement=no
231 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
232 grub_tmp_addr32="addr32"
233 grub_tmp_data32="data32"
235 grub_tmp_addr32="addr32;"
236 grub_tmp_data32="data32;"
239 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
240 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
241 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
242 [Define it to \"data32\" or \"data32;\" to make GAS happy])
244 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
247 dnl Older versions of GAS require that absolute indirect calls/jumps are
248 dnl not prefixed with `*', while later versions warn if not prefixed.
249 AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK,
250 [AC_REQUIRE([AC_PROG_CC])
252 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
253 AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
254 [cat > conftest.s <<\EOF
261 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
262 grub_cv_i386_asm_absolute_without_asterisk=no
264 grub_cv_i386_asm_absolute_without_asterisk=yes
269 if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
270 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
271 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
274 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
277 dnl Check what symbol is defined as a bss start symbol.
278 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
279 AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
280 [AC_REQUIRE([AC_PROG_CC])
281 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
282 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
283 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
284 [[asm ("incl __bss_start")]])],
285 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
286 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
288 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
290 AC_MSG_CHECKING([if edata is defined by the compiler])
291 AC_CACHE_VAL(grub_cv_check_edata_symbol,
292 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
293 [[asm ("incl edata")]])],
294 [grub_cv_check_edata_symbol=yes],
295 [grub_cv_check_edata_symbol=no])])
297 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
299 AC_MSG_CHECKING([if _edata is defined by the compiler])
300 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
301 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
302 [[asm ("incl _edata")]])],
303 [grub_cv_check_uscore_edata_symbol=yes],
304 [grub_cv_check_uscore_edata_symbol=no])])
306 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
308 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
310 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
311 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
312 elif test "x$grub_cv_check_edata_symbol" = xyes; then
313 AC_DEFINE([BSS_START_SYMBOL], [edata])
314 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
315 AC_DEFINE([BSS_START_SYMBOL], [_edata])
317 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
321 dnl Check what symbol is defined as an end symbol.
322 dnl Written by Yoshinori K. Okuji.
323 AC_DEFUN(grub_CHECK_END_SYMBOL,
324 [AC_REQUIRE([AC_PROG_CC])
325 AC_MSG_CHECKING([if end is defined by the compiler])
326 AC_CACHE_VAL(grub_cv_check_end_symbol,
327 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
328 [[asm ("incl end")]])],
329 [grub_cv_check_end_symbol=yes],
330 [grub_cv_check_end_symbol=no])])
332 AC_MSG_RESULT([$grub_cv_check_end_symbol])
334 AC_MSG_CHECKING([if _end is defined by the compiler])
335 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
336 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
337 [[asm ("incl _end")]])],
338 [grub_cv_check_uscore_end_symbol=yes],
339 [grub_cv_check_uscore_end_symbol=no])])
341 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
343 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
345 if test "x$grub_cv_check_end_symbol" = xyes; then
346 AC_DEFINE([END_SYMBOL], [end])
347 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
348 AC_DEFINE([END_SYMBOL], [_end])
350 AC_MSG_ERROR([neither end nor _end is defined])
354 dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
355 AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[
356 AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
358 void f (int (*p) (void));
361 int nestedfunc (void) { return i; }
365 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
368 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
370 if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
371 AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
372 [Define to 1 if GCC generates calls to __enable_execute_stack()])
381 dnl Check if the C compiler supports `-fstack-protector'.
382 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
383 [# Smashing stack protector.
385 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
386 # Is this a reliable test case?
387 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
388 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
389 # `ac_compile' like this correct, after all?
390 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
392 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
400 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
401 AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[
402 [# Smashing stack arg probe.
404 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
405 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
406 [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
408 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
416 dnl Check if ln can handle directories properly (mingw).
417 AC_DEFUN(grub_CHECK_LINK_DIR,[
418 AC_MSG_CHECKING([whether ln can handle directories properly])
419 [mkdir testdir 2>/dev/null
421 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
422 *) reldir=../$srcdir/include/grub/util ;;
424 if ln -s $reldir testdir/util 2>/dev/null ; then]
434 dnl Check if the C compiler supports `-fPIE'.
435 AC_DEFUN(grub_CHECK_PIE,[
436 [# Position independent executable.
438 AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
439 # Is this a reliable test case?
446 #error NO __PIE__ DEFINED
450 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
451 # `ac_compile' like this correct, after all?
452 if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
454 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?