1 dnl Check whether target compiler is working
2 AC_DEFUN(grub_PROG_TARGET_CC,
3 [AC_MSG_CHECKING([whether target compiler is working])
4 AC_CACHE_VAL(grub_cv_prog_target_cc,
5 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
6 [grub_cv_prog_target_cc=yes],
7 [grub_cv_prog_target_cc=no])
9 AC_MSG_RESULT([$grub_cv_prog_target_cc])
11 if test "x$grub_cv_prog_target_cc" = xno; then
12 AC_MSG_ERROR([cannot compile for the target])
17 dnl grub_ASM_USCORE checks if C symbols get an underscore after
18 dnl compiling to assembler.
19 dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
20 dnl Erich Boleyn and modified by Yoshinori K. Okuji.
21 AC_DEFUN(grub_ASM_USCORE,
22 [AC_REQUIRE([AC_PROG_CC])
23 AC_MSG_CHECKING([if C symbols get an underscore after compilation])
24 AC_CACHE_VAL(grub_cv_asm_uscore,
25 [cat > conftest.c <<\EOF
34 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
37 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
40 if grep _func conftest.s >/dev/null 2>&1; then
41 grub_cv_asm_uscore=yes
48 if test "x$grub_cv_asm_uscore" = xyes; then
49 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
50 [Define if C symbols get an underscore after compilation])
53 AC_MSG_RESULT([$grub_cv_asm_uscore])
57 dnl Some versions of `objcopy -O binary' vary their output depending
58 dnl on the link address.
59 AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
60 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
61 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
62 [cat > conftest.c <<\EOF
66 *((int *) 0x1000) = 2;
70 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
72 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
74 grub_cv_prog_objcopy_absolute=yes
75 for link_addr in 2000 8000 7C00; do
76 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
78 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
80 if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
82 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
84 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
85 mv -f conftest conftest.old
87 grub_cv_prog_objcopy_absolute=no
92 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
94 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
95 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
100 dnl Supply --build-id=none to ld if building modules.
101 dnl This suppresses warnings from ld on some systems
102 AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE,
103 [AC_MSG_CHECKING([whether linker accepts --build-id=none])
104 AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
105 [save_LDFLAGS="$LDFLAGS"
106 LDFLAGS="$LDFLAGS -Wl,--build-id=none"
107 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
108 [grub_cv_prog_ld_build_id_none=yes],
109 [grub_cv_prog_ld_build_id_none=no])
110 LDFLAGS="$save_LDFLAGS"
112 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
114 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
115 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
121 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
122 dnl instructions, but implicitly insert addr32 and data32 bytes so
123 dnl that the code works in real mode''.
125 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
126 dnl instructions,'' which seems right. This requires the programmer
127 dnl to explicitly insert addr32 and data32 instructions when they want
130 dnl We only support the newer versions, because the old versions cause
131 dnl major pain, by requiring manual assembly to get 16-bit instructions into
133 AC_DEFUN(grub_I386_ASM_ADDR32,
134 [AC_REQUIRE([AC_PROG_CC])
135 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
136 AC_MSG_CHECKING([for .code16 addr32 assembler support])
137 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
138 [cat > conftest.s.in <<\EOF
140 l1: @ADDR32@ movb %al, l1
143 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
144 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
146 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
149 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
150 grub_cv_i386_asm_addr32=yes
152 grub_cv_i386_asm_addr32=no
157 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
159 dnl check if our compiler is apple cc
160 dnl because it requires numerous workarounds
161 AC_DEFUN(grub_apple_cc,
162 [AC_REQUIRE([AC_PROG_CC])
163 AC_MSG_CHECKING([whether our compiler is apple cc])
164 AC_CACHE_VAL(grub_cv_apple_cc,
165 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
172 AC_MSG_RESULT([$grub_cv_apple_cc])])
174 dnl check if our target compiler is apple cc
175 dnl because it requires numerous workarounds
176 AC_DEFUN(grub_apple_target_cc,
177 [AC_REQUIRE([AC_PROG_CC])
178 AC_MSG_CHECKING([whether our target compiler is apple cc])
179 AC_CACHE_VAL(grub_cv_apple_target_cc,
180 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
181 grub_cv_apple_target_cc=yes
183 grub_cv_apple_target_cc=no
187 AC_MSG_RESULT([$grub_cv_apple_target_cc])])
190 dnl Later versions of GAS requires that addr32 and data32 prefixes
191 dnl appear in the same lines as the instructions they modify, while
192 dnl earlier versions requires that they appear in separate lines.
193 AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT,
194 [AC_REQUIRE([AC_PROG_CC])
196 [whether addr32 must be in the same line as the instruction])
197 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
198 [cat > conftest.s <<\EOF
200 l1: addr32 movb %al, l1
203 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
204 grub_cv_i386_asm_prefix_requirement=yes
206 grub_cv_i386_asm_prefix_requirement=no
211 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
212 grub_tmp_addr32="addr32"
213 grub_tmp_data32="data32"
215 grub_tmp_addr32="addr32;"
216 grub_tmp_data32="data32;"
219 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
220 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
221 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
222 [Define it to \"data32\" or \"data32;\" to make GAS happy])
224 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
227 dnl Older versions of GAS require that absolute indirect calls/jumps are
228 dnl not prefixed with `*', while later versions warn if not prefixed.
229 AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK,
230 [AC_REQUIRE([AC_PROG_CC])
232 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
233 AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
234 [cat > conftest.s <<\EOF
241 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
242 grub_cv_i386_asm_absolute_without_asterisk=no
244 grub_cv_i386_asm_absolute_without_asterisk=yes
249 if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
250 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
251 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
254 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
257 dnl Check what symbol is defined as a bss start symbol.
258 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
259 AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
260 [AC_REQUIRE([AC_PROG_CC])
261 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
262 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
263 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
264 [[asm ("incl __bss_start")]])],
265 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
266 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
268 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
270 AC_MSG_CHECKING([if edata is defined by the compiler])
271 AC_CACHE_VAL(grub_cv_check_edata_symbol,
272 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
273 [[asm ("incl edata")]])],
274 [grub_cv_check_edata_symbol=yes],
275 [grub_cv_check_edata_symbol=no])])
277 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
279 AC_MSG_CHECKING([if _edata is defined by the compiler])
280 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
281 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
282 [[asm ("incl _edata")]])],
283 [grub_cv_check_uscore_edata_symbol=yes],
284 [grub_cv_check_uscore_edata_symbol=no])])
286 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
288 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
290 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
291 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
292 elif test "x$grub_cv_check_edata_symbol" = xyes; then
293 AC_DEFINE([BSS_START_SYMBOL], [edata])
294 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
295 AC_DEFINE([BSS_START_SYMBOL], [_edata])
297 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
301 dnl Check what symbol is defined as an end symbol.
302 dnl Written by Yoshinori K. Okuji.
303 AC_DEFUN(grub_CHECK_END_SYMBOL,
304 [AC_REQUIRE([AC_PROG_CC])
305 AC_MSG_CHECKING([if end is defined by the compiler])
306 AC_CACHE_VAL(grub_cv_check_end_symbol,
307 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
308 [[asm ("incl end")]])],
309 [grub_cv_check_end_symbol=yes],
310 [grub_cv_check_end_symbol=no])])
312 AC_MSG_RESULT([$grub_cv_check_end_symbol])
314 AC_MSG_CHECKING([if _end is defined by the compiler])
315 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
316 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
317 [[asm ("incl _end")]])],
318 [grub_cv_check_uscore_end_symbol=yes],
319 [grub_cv_check_uscore_end_symbol=no])])
321 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
323 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
325 if test "x$grub_cv_check_end_symbol" = xyes; then
326 AC_DEFINE([END_SYMBOL], [end])
327 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
328 AC_DEFINE([END_SYMBOL], [_end])
330 AC_MSG_ERROR([neither end nor _end is defined])
334 dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
335 AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[
336 AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
338 void f (int (*p) (void));
341 int nestedfunc (void) { return i; }
345 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
348 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
350 if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
351 AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
352 [Define to 1 if GCC generates calls to __enable_execute_stack()])
361 dnl Check if the C compiler supports `-fstack-protector'.
362 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
363 [# Smashing stack protector.
365 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
366 # Is this a reliable test case?
367 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
368 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
369 # `ac_compile' like this correct, after all?
370 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
372 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
380 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
381 AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[
382 [# Smashing stack arg probe.
384 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
385 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
386 [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
388 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
396 dnl Check if ln can handle directories properly (mingw).
397 AC_DEFUN(grub_CHECK_LINK_DIR,[
398 AC_MSG_CHECKING([whether ln can handle directories properly])
399 [mkdir testdir 2>/dev/null
401 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
402 *) reldir=../$srcdir/include/grub/util ;;
404 if ln -s $reldir testdir/util 2>/dev/null ; then]