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 asm (".globl start; start: nop");
9 [grub_cv_prog_target_cc=yes],
10 [grub_cv_prog_target_cc=no])
12 AC_MSG_RESULT([$grub_cv_prog_target_cc])
14 if test "x$grub_cv_prog_target_cc" = xno; then
15 AC_MSG_ERROR([cannot compile for the target])
20 dnl grub_ASM_USCORE checks if C symbols get an underscore after
21 dnl compiling to assembler.
22 dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
23 dnl Erich Boleyn and modified by Yoshinori K. Okuji.
24 AC_DEFUN(grub_ASM_USCORE,
25 [AC_REQUIRE([AC_PROG_CC])
26 AC_MSG_CHECKING([if C symbols get an underscore after compilation])
27 AC_CACHE_VAL(grub_cv_asm_uscore,
28 [cat > conftest.c <<\EOF
37 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
40 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
43 if grep _func conftest.s >/dev/null 2>&1; then
44 grub_cv_asm_uscore=yes
51 if test "x$grub_cv_asm_uscore" = xyes; then
52 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
53 [Define if C symbols get an underscore after compilation])
56 AC_MSG_RESULT([$grub_cv_asm_uscore])
60 dnl Some versions of `objcopy -O binary' vary their output depending
61 dnl on the link address.
62 AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
63 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
64 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
65 [cat > conftest.c <<\EOF
69 *((int *) 0x1000) = 2;
73 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
75 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
77 grub_cv_prog_objcopy_absolute=yes
78 for link_addr in 2000 8000 7C00; do
79 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
81 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
83 if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
85 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
87 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
88 mv -f conftest conftest.old
90 grub_cv_prog_objcopy_absolute=no
95 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
97 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
98 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
103 dnl Supply --build-id=none to ld if building modules.
104 dnl This suppresses warnings from ld on some systems
105 AC_DEFUN(grub_PROG_LD_BUILD_ID_NONE,
106 [AC_MSG_CHECKING([whether linker accepts --build-id=none])
107 AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
108 [save_LDFLAGS="$LDFLAGS"
109 LDFLAGS="$LDFLAGS -Wl,--build-id=none"
110 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
111 [grub_cv_prog_ld_build_id_none=yes],
112 [grub_cv_prog_ld_build_id_none=no])
113 LDFLAGS="$save_LDFLAGS"
115 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
117 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
118 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
124 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
125 dnl instructions, but implicitly insert addr32 and data32 bytes so
126 dnl that the code works in real mode''.
128 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
129 dnl instructions,'' which seems right. This requires the programmer
130 dnl to explicitly insert addr32 and data32 instructions when they want
133 dnl We only support the newer versions, because the old versions cause
134 dnl major pain, by requiring manual assembly to get 16-bit instructions into
136 AC_DEFUN(grub_I386_ASM_ADDR32,
137 [AC_REQUIRE([AC_PROG_CC])
138 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
139 AC_MSG_CHECKING([for .code16 addr32 assembler support])
140 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
141 [cat > conftest.s.in <<\EOF
143 l1: @ADDR32@ movb %al, l1
146 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
147 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
149 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
152 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
153 grub_cv_i386_asm_addr32=yes
155 grub_cv_i386_asm_addr32=no
160 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
162 dnl check if our compiler is apple cc
163 dnl because it requires numerous workarounds
164 AC_DEFUN(grub_apple_cc,
165 [AC_REQUIRE([AC_PROG_CC])
166 AC_MSG_CHECKING([whether our compiler is apple cc])
167 AC_CACHE_VAL(grub_cv_apple_cc,
168 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
175 AC_MSG_RESULT([$grub_cv_apple_cc])])
177 dnl check if our target compiler is apple cc
178 dnl because it requires numerous workarounds
179 AC_DEFUN(grub_apple_target_cc,
180 [AC_REQUIRE([AC_PROG_CC])
181 AC_MSG_CHECKING([whether our target compiler is apple cc])
182 AC_CACHE_VAL(grub_cv_apple_target_cc,
183 [if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
184 grub_cv_apple_target_cc=yes
186 grub_cv_apple_target_cc=no
190 AC_MSG_RESULT([$grub_cv_apple_target_cc])])
193 dnl Later versions of GAS requires that addr32 and data32 prefixes
194 dnl appear in the same lines as the instructions they modify, while
195 dnl earlier versions requires that they appear in separate lines.
196 AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT,
197 [AC_REQUIRE([AC_PROG_CC])
199 [whether addr32 must be in the same line as the instruction])
200 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
201 [cat > conftest.s <<\EOF
203 l1: addr32 movb %al, l1
206 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
207 grub_cv_i386_asm_prefix_requirement=yes
209 grub_cv_i386_asm_prefix_requirement=no
214 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
215 grub_tmp_addr32="addr32"
216 grub_tmp_data32="data32"
218 grub_tmp_addr32="addr32;"
219 grub_tmp_data32="data32;"
222 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
223 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
224 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
225 [Define it to \"data32\" or \"data32;\" to make GAS happy])
227 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
230 dnl Older versions of GAS require that absolute indirect calls/jumps are
231 dnl not prefixed with `*', while later versions warn if not prefixed.
232 AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK,
233 [AC_REQUIRE([AC_PROG_CC])
235 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
236 AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
237 [cat > conftest.s <<\EOF
244 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
245 grub_cv_i386_asm_absolute_without_asterisk=no
247 grub_cv_i386_asm_absolute_without_asterisk=yes
252 if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
253 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
254 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
257 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
260 dnl Check what symbol is defined as a bss start symbol.
261 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
262 AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
263 [AC_REQUIRE([AC_PROG_CC])
264 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
265 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
266 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
267 [[asm ("incl __bss_start")]])],
268 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
269 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
271 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
273 AC_MSG_CHECKING([if edata is defined by the compiler])
274 AC_CACHE_VAL(grub_cv_check_edata_symbol,
275 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
276 [[asm ("incl edata")]])],
277 [grub_cv_check_edata_symbol=yes],
278 [grub_cv_check_edata_symbol=no])])
280 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
282 AC_MSG_CHECKING([if _edata is defined by the compiler])
283 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
284 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
285 [[asm ("incl _edata")]])],
286 [grub_cv_check_uscore_edata_symbol=yes],
287 [grub_cv_check_uscore_edata_symbol=no])])
289 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
291 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
293 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
294 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
295 elif test "x$grub_cv_check_edata_symbol" = xyes; then
296 AC_DEFINE([BSS_START_SYMBOL], [edata])
297 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
298 AC_DEFINE([BSS_START_SYMBOL], [_edata])
300 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
304 dnl Check what symbol is defined as an end symbol.
305 dnl Written by Yoshinori K. Okuji.
306 AC_DEFUN(grub_CHECK_END_SYMBOL,
307 [AC_REQUIRE([AC_PROG_CC])
308 AC_MSG_CHECKING([if end is defined by the compiler])
309 AC_CACHE_VAL(grub_cv_check_end_symbol,
310 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
311 [[asm ("incl end")]])],
312 [grub_cv_check_end_symbol=yes],
313 [grub_cv_check_end_symbol=no])])
315 AC_MSG_RESULT([$grub_cv_check_end_symbol])
317 AC_MSG_CHECKING([if _end is defined by the compiler])
318 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
319 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
320 [[asm ("incl _end")]])],
321 [grub_cv_check_uscore_end_symbol=yes],
322 [grub_cv_check_uscore_end_symbol=no])])
324 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
326 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
328 if test "x$grub_cv_check_end_symbol" = xyes; then
329 AC_DEFINE([END_SYMBOL], [end])
330 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
331 AC_DEFINE([END_SYMBOL], [_end])
333 AC_MSG_ERROR([neither end nor _end is defined])
337 dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
338 AC_DEFUN(grub_CHECK_ENABLE_EXECUTE_STACK,[
339 AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
341 void f (int (*p) (void));
344 int nestedfunc (void) { return i; }
348 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
351 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
353 if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
354 AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
355 [Define to 1 if GCC generates calls to __enable_execute_stack()])
364 dnl Check if the C compiler supports `-fstack-protector'.
365 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
366 [# Smashing stack protector.
368 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
369 # Is this a reliable test case?
370 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
371 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
372 # `ac_compile' like this correct, after all?
373 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
375 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
383 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
384 AC_DEFUN(grub_CHECK_STACK_ARG_PROBE,[
385 [# Smashing stack arg probe.
387 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
388 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
389 [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
391 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
399 dnl Check if ln can handle directories properly (mingw).
400 AC_DEFUN(grub_CHECK_LINK_DIR,[
401 AC_MSG_CHECKING([whether ln can handle directories properly])
402 [mkdir testdir 2>/dev/null
404 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
405 *) reldir=../$srcdir/include/grub/util ;;
407 if ln -s $reldir testdir/util 2>/dev/null ; then]