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
62 grub_cv_asm_uscore=yes
70 AC_MSG_RESULT([$grub_cv_asm_uscore])
74 dnl Some versions of `objcopy -O binary' vary their output depending
75 dnl on the link address.
76 AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
77 [AC_MSG_CHECKING([whether ${TARGET_OBJCOPY} works for absolute addresses])
78 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
79 [cat > conftest.c <<\EOF
84 *((int *) 0x1000) = 2;
88 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
90 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
92 grub_cv_prog_objcopy_absolute=yes
93 for link_addr in 0x2000 0x8000 0x7C00; do
94 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
96 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
98 if AC_TRY_COMMAND([${TARGET_OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
100 AC_MSG_ERROR([${TARGET_OBJCOPY-objcopy} cannot create binary files])
102 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
103 mv -f conftest conftest.old
105 grub_cv_prog_objcopy_absolute=no
110 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
112 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
113 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
118 dnl Supply --build-id=none to ld if building modules.
119 dnl This suppresses warnings from ld on some systems
120 AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
121 [AC_MSG_CHECKING([whether linker accepts --build-id=none])
122 AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
123 [save_LDFLAGS="$LDFLAGS"
124 LDFLAGS="$LDFLAGS -Wl,--build-id=none"
125 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
126 [grub_cv_prog_ld_build_id_none=yes],
127 [grub_cv_prog_ld_build_id_none=no])
128 LDFLAGS="$save_LDFLAGS"
130 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
132 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
133 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
138 AC_DEFUN([grub_PROG_NM_MINUS_P],
139 [AC_MSG_CHECKING([whether nm accepts -P])
140 AC_CACHE_VAL(grub_cv_prog_nm_minus_p,
142 nm_minus_p_tmp_dir="$(mktemp -d "./confXXXXXX")"
143 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
144 $TARGET_CC conftest.c -o "$nm_minus_p_tmp_dir/ef"
145 if $TARGET_NM -P "$nm_minus_p_tmp_dir/ef" 2>&1 > /dev/null; then
146 grub_cv_prog_nm_minus_p=yes
148 grub_cv_prog_nm_minus_p=no
150 rm "$nm_minus_p_tmp_dir/ef"
152 AC_MSG_RESULT([$grub_cv_prog_nm_minus_p])
154 if test "x$grub_cv_prog_nm_minus_p" = xyes; then
155 TARGET_NMFLAGS_MINUS_P="-P"
157 TARGET_NMFLAGS_MINUS_P=
161 dnl Supply --defined-only to nm
162 AC_DEFUN([grub_PROG_NM_DEFINED_ONLY],
163 [AC_MSG_CHECKING([whether nm accepts --defined-only])
164 AC_CACHE_VAL(grub_cv_prog_nm_defined_only,
166 nm_defined_only_tmp_dir="$(mktemp -d "./confXXXXXX")"
167 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
168 $TARGET_CC conftest.c -o "$nm_defined_only_tmp_dir/ef"
169 if $TARGET_NM --defined-only "$nm_defined_only_tmp_dir/ef" 2>&1 > /dev/null; then
170 grub_cv_prog_nm_defined_only=yes
172 grub_cv_prog_nm_defined_only=no
174 rm "$nm_defined_only_tmp_dir/ef"
176 AC_MSG_RESULT([$grub_cv_prog_nm_defined_only])
178 if test "x$grub_cv_prog_nm_defined_only" = xyes; then
179 TARGET_NMFLAGS_DEFINED_ONLY=--defined-only
181 TARGET_NMFLAGS_DEFINED_ONLY=
187 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
188 dnl instructions, but implicitly insert addr32 and data32 bytes so
189 dnl that the code works in real mode''.
191 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
192 dnl instructions,'' which seems right. This requires the programmer
193 dnl to explicitly insert addr32 and data32 instructions when they want
196 dnl We only support the newer versions, because the old versions cause
197 dnl major pain, by requiring manual assembly to get 16-bit instructions into
199 AC_DEFUN([grub_I386_ASM_ADDR32],
200 [AC_REQUIRE([AC_PROG_CC])
201 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
202 AC_MSG_CHECKING([for .code16 addr32 assembler support])
203 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
204 [cat > conftest.s.in <<\EOF
206 l1: @ADDR32@ movb %al, l1
209 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
210 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
212 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
215 if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
216 grub_cv_i386_asm_addr32=yes
218 grub_cv_i386_asm_addr32=no
223 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
225 dnl check if our target compiler is apple cc
226 dnl because it requires numerous workarounds
227 AC_DEFUN([grub_apple_target_cc],
228 [AC_REQUIRE([AC_PROG_CC])
229 AC_MSG_CHECKING([whether our target compiler is apple cc])
230 AC_CACHE_VAL(grub_cv_apple_target_cc,
231 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
232 grub_cv_apple_target_cc=yes
234 grub_cv_apple_target_cc=no
238 AC_MSG_RESULT([$grub_cv_apple_target_cc])])
241 dnl Later versions of GAS requires that addr32 and data32 prefixes
242 dnl appear in the same lines as the instructions they modify, while
243 dnl earlier versions requires that they appear in separate lines.
244 AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
245 [AC_REQUIRE([AC_PROG_CC])
247 [whether addr32 must be in the same line as the instruction])
248 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
249 [cat > conftest.s <<\EOF
251 l1: addr32 movb %al, l1
254 if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
255 grub_cv_i386_asm_prefix_requirement=yes
257 grub_cv_i386_asm_prefix_requirement=no
262 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
263 grub_tmp_addr32="addr32"
264 grub_tmp_data32="data32"
266 grub_tmp_addr32="addr32;"
267 grub_tmp_data32="data32;"
270 ADDR32=$grub_tmp_addr32
271 DATA32=$grub_tmp_data32
273 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
276 dnl Check what symbol is defined as a bss start symbol.
277 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
278 AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
279 [AC_REQUIRE([AC_PROG_CC])
280 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
281 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
282 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
283 [[asm ("incl __bss_start")]])],
284 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
285 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
287 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
289 AC_MSG_CHECKING([if edata is defined by the compiler])
290 AC_CACHE_VAL(grub_cv_check_edata_symbol,
291 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
292 [[asm ("incl edata")]])],
293 [grub_cv_check_edata_symbol=yes],
294 [grub_cv_check_edata_symbol=no])])
296 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
298 AC_MSG_CHECKING([if _edata is defined by the compiler])
299 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
300 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
301 [[asm ("incl _edata")]])],
302 [grub_cv_check_uscore_edata_symbol=yes],
303 [grub_cv_check_uscore_edata_symbol=no])])
305 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
307 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
308 BSS_START_SYMBOL=__bss_start
309 elif test "x$grub_cv_check_edata_symbol" = xyes; then
310 BSS_START_SYMBOL=edata
311 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
312 BSS_START_SYMBOL=_edata
314 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
318 dnl Check what symbol is defined as an end symbol.
319 dnl Written by Yoshinori K. Okuji.
320 AC_DEFUN([grub_CHECK_END_SYMBOL],
321 [AC_REQUIRE([AC_PROG_CC])
322 AC_MSG_CHECKING([if end is defined by the compiler])
323 AC_CACHE_VAL(grub_cv_check_end_symbol,
324 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
325 [[asm ("incl end")]])],
326 [grub_cv_check_end_symbol=yes],
327 [grub_cv_check_end_symbol=no])])
329 AC_MSG_RESULT([$grub_cv_check_end_symbol])
331 AC_MSG_CHECKING([if _end is defined by the compiler])
332 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
333 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
334 [[asm ("incl _end")]])],
335 [grub_cv_check_uscore_end_symbol=yes],
336 [grub_cv_check_uscore_end_symbol=no])])
338 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
340 if test "x$grub_cv_check_end_symbol" = xyes; then
342 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
345 AC_MSG_ERROR([neither end nor _end is defined])
350 dnl Check if the C compiler supports `-fstack-protector'.
351 AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
352 [# Smashing stack protector.
354 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
355 # Is this a reliable test case?
356 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
357 void foo (void) { volatile char a[8]; a[3]; }
359 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
360 # `ac_compile' like this correct, after all?
361 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
363 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
371 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
372 AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
373 [# Smashing stack arg probe.
375 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
376 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
377 void foo (void) { volatile char a[8]; a[3]; }
379 [if eval "$ac_compile -S -mstack-arg-probe -Werror -o conftest.s" 2> /dev/null; then]
381 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
389 dnl Check if ln can handle directories properly (mingw).
390 AC_DEFUN([grub_CHECK_LINK_DIR],[
391 AC_MSG_CHECKING([whether ln can handle directories properly])
392 [mkdir testdir 2>/dev/null
394 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
395 *) reldir=../$srcdir/include/grub/util ;;
397 if ln -s $reldir testdir/util 2>/dev/null ; then]
407 dnl Check if the C compiler supports `-fPIE'.
408 AC_DEFUN([grub_CHECK_PIE],[
409 [# Position independent executable.
411 AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
412 # Is this a reliable test case?
413 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
419 #error NO __PIE__ DEFINED
423 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
424 # `ac_compile' like this correct, after all?
425 if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
427 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
435 dnl Check if the C compiler supports `-fPIC'.
436 AC_DEFUN([grub_CHECK_PIC],[
437 [# Position independent executable.
439 AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default])
440 # Is this a reliable test case?
441 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
447 #error NO __PIC__ 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'?
463 dnl Create an output variable with the transformed name of a GRUB utility
465 AC_DEFUN([grub_TRANSFORM],[dnl
466 AC_SUBST(AS_TR_SH([$1]), [`AS_ECHO([$1]) | sed "$program_transform_name"`])dnl
469 dnl Check if the C compiler supports `-mno-unaligned-access'.
470 AC_DEFUN([grub_CHECK_NO_UNALIGNED_ACCESS],[
473 AC_MSG_CHECKING([whether `$CC' supports `-mno-unaligned-access'])
474 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
480 [if eval "$ac_compile -S -mno-unaligned-access -o conftest.s" 2> /dev/null; then]