]> git.proxmox.com Git - grub2.git/blame - acinclude.m4
* util/grub-install_header: Set localedir here, since this file is
[grub2.git] / acinclude.m4
CommitLineData
63f745e8 1dnl Redefine AC_LANG_PROGRAM with a "-Wstrict-prototypes -Werror"-friendly
2dnl version. Patch submitted to bug-autoconf in 2009-09-16.
3m4_define([AC_LANG_PROGRAM(C)],
4[$1
5int
6main (void)
7{
8dnl Do *not* indent the following line: there may be CPP directives.
9dnl Don't move the `;' right after for the same reason.
10$2
11 ;
12 return 0;
13}])
14
15
f6130a12 16dnl Check whether target compiler is working
fc9e5810 17AC_DEFUN([grub_PROG_TARGET_CC],
f6130a12 18[AC_MSG_CHECKING([whether target compiler is working])
19AC_CACHE_VAL(grub_cv_prog_target_cc,
26586d98 20[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
b2cab848 21asm (".globl start; start:");
26586d98 22int main (void);
23]], [[]])],
eb73121d 24 [grub_cv_prog_target_cc=yes],
25 [grub_cv_prog_target_cc=no])
f6130a12 26])
27AC_MSG_RESULT([$grub_cv_prog_target_cc])
28
29if test "x$grub_cv_prog_target_cc" = xno; then
30 AC_MSG_ERROR([cannot compile for the target])
31fi
32])
33
34
4b13b216 35dnl grub_ASM_USCORE checks if C symbols get an underscore after
6a161fa9 36dnl compiling to assembler.
37dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
38dnl Erich Boleyn and modified by Yoshinori K. Okuji.
fc9e5810 39AC_DEFUN([grub_ASM_USCORE],
6a161fa9 40[AC_REQUIRE([AC_PROG_CC])
9da94e05 41AC_REQUIRE([AC_PROG_EGREP])
6a161fa9 42AC_MSG_CHECKING([if C symbols get an underscore after compilation])
4b13b216 43AC_CACHE_VAL(grub_cv_asm_uscore,
6a161fa9 44[cat > conftest.c <<\EOF
63f745e8 45int func (int *);
6a161fa9 46int
47func (int *list)
48{
49 *list = 0;
50 return *list;
51}
52EOF
53
54if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
55 true
56else
57 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
58fi
59
9da94e05 60if $EGREP '(^|[^_[:alnum]])_func' conftest.s >/dev/null 2>&1; then
742f9232 61 HAVE_ASM_USCORE=1
4b13b216 62 grub_cv_asm_uscore=yes
6a161fa9 63else
742f9232 64 HAVE_ASM_USCORE=0
4b13b216 65 grub_cv_asm_uscore=no
6a161fa9 66fi
67
68rm -f conftest*])
69
4b13b216 70AC_MSG_RESULT([$grub_cv_asm_uscore])
6a161fa9 71])
72
73
74dnl Some versions of `objcopy -O binary' vary their output depending
75dnl on the link address.
fc9e5810 76AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
fc97214f 77[AC_MSG_CHECKING([whether ${TARGET_OBJCOPY} works for absolute addresses])
4b13b216 78AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
6a161fa9 79[cat > conftest.c <<\EOF
63f745e8 80void cmain (void);
6a161fa9 81void
82cmain (void)
83{
84 *((int *) 0x1000) = 2;
85}
86EOF
87
88if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
89else
90 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
91fi
4b13b216 92grub_cv_prog_objcopy_absolute=yes
c926e1d5 93for link_addr in 0x2000 0x8000 0x7C00; do
2d465fb0 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 :
6a161fa9 95 else
96 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
97 fi
fc97214f 98 if AC_TRY_COMMAND([${TARGET_OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
6a161fa9 99 else
fc97214f 100 AC_MSG_ERROR([${TARGET_OBJCOPY-objcopy} cannot create binary files])
6a161fa9 101 fi
102 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
103 mv -f conftest conftest.old
104 else
4b13b216 105 grub_cv_prog_objcopy_absolute=no
6a161fa9 106 break
107 fi
108done
109rm -f conftest*])
4b13b216 110AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
6a161fa9 111
4b13b216 112if test "x$grub_cv_prog_objcopy_absolute" = xno; then
113 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
6a161fa9 114fi
115])
116
117
cb71ba20 118dnl Supply --build-id=none to ld if building modules.
119dnl This suppresses warnings from ld on some systems
fc9e5810 120AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
cb71ba20 121[AC_MSG_CHECKING([whether linker accepts --build-id=none])
122AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
123[save_LDFLAGS="$LDFLAGS"
124LDFLAGS="$LDFLAGS -Wl,--build-id=none"
eb73121d 125AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
126 [grub_cv_prog_ld_build_id_none=yes],
127 [grub_cv_prog_ld_build_id_none=no])
cb71ba20 128LDFLAGS="$save_LDFLAGS"
129])
130AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
131
132if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
5ec9740b 133 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
cb71ba20 134fi
135])
136
20aea949
VS
137dnl Check nm
138AC_DEFUN([grub_PROG_NM_WORKS],
139[AC_MSG_CHECKING([whether nm works])
140AC_CACHE_VAL(grub_cv_prog_nm_works,
141[
142nm_works_tmp_dir="$(mktemp -d "./confXXXXXX")"
143AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
144$TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_works_tmp_dir/ef"
145if $TARGET_NM -P "$nm_works_tmp_dir/ef" > /dev/null; then
146 grub_cv_prog_nm_works=yes
147else
148 grub_cv_prog_nm_minus_p=no
149fi
150rm "$nm_works_tmp_dir/ef"
151rmdir "$nm_works_tmp_dir"
152])
153AC_MSG_RESULT([$grub_cv_prog_nm_works])
154
155if test "x$grub_cv_prog_nm_works" != xyes; then
156 AC_MSG_ERROR([nm does not work])
157fi
158])
159
fc97214f
VS
160dnl Supply -P to nm
161AC_DEFUN([grub_PROG_NM_MINUS_P],
162[AC_MSG_CHECKING([whether nm accepts -P])
163AC_CACHE_VAL(grub_cv_prog_nm_minus_p,
164[
165nm_minus_p_tmp_dir="$(mktemp -d "./confXXXXXX")"
166AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
20aea949 167$TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_minus_p_tmp_dir/ef"
fc97214f
VS
168if $TARGET_NM -P "$nm_minus_p_tmp_dir/ef" 2>&1 > /dev/null; then
169 grub_cv_prog_nm_minus_p=yes
170else
171 grub_cv_prog_nm_minus_p=no
172fi
173rm "$nm_minus_p_tmp_dir/ef"
20aea949 174rmdir "$nm_minus_p_tmp_dir"
fc97214f
VS
175])
176AC_MSG_RESULT([$grub_cv_prog_nm_minus_p])
177
178if test "x$grub_cv_prog_nm_minus_p" = xyes; then
179 TARGET_NMFLAGS_MINUS_P="-P"
180else
181 TARGET_NMFLAGS_MINUS_P=
182fi
183])
184
185dnl Supply --defined-only to nm
186AC_DEFUN([grub_PROG_NM_DEFINED_ONLY],
187[AC_MSG_CHECKING([whether nm accepts --defined-only])
188AC_CACHE_VAL(grub_cv_prog_nm_defined_only,
189[
190nm_defined_only_tmp_dir="$(mktemp -d "./confXXXXXX")"
191AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
20aea949 192$TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_defined_only_tmp_dir/ef"
fc97214f
VS
193if $TARGET_NM --defined-only "$nm_defined_only_tmp_dir/ef" 2>&1 > /dev/null; then
194 grub_cv_prog_nm_defined_only=yes
195else
196 grub_cv_prog_nm_defined_only=no
197fi
198rm "$nm_defined_only_tmp_dir/ef"
20aea949 199rmdir "$nm_defined_only_tmp_dir"
fc97214f
VS
200])
201AC_MSG_RESULT([$grub_cv_prog_nm_defined_only])
202
203if test "x$grub_cv_prog_nm_defined_only" = xyes; then
204 TARGET_NMFLAGS_DEFINED_ONLY=--defined-only
205else
206 TARGET_NMFLAGS_DEFINED_ONLY=
207fi
208])
209
cb71ba20 210
6a161fa9 211dnl Mass confusion!
212dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
213dnl instructions, but implicitly insert addr32 and data32 bytes so
214dnl that the code works in real mode''.
215dnl
216dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
217dnl instructions,'' which seems right. This requires the programmer
218dnl to explicitly insert addr32 and data32 instructions when they want
219dnl them.
220dnl
221dnl We only support the newer versions, because the old versions cause
222dnl major pain, by requiring manual assembly to get 16-bit instructions into
223dnl asm files.
fc9e5810 224AC_DEFUN([grub_I386_ASM_ADDR32],
6a161fa9 225[AC_REQUIRE([AC_PROG_CC])
4b13b216 226AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
6a161fa9 227AC_MSG_CHECKING([for .code16 addr32 assembler support])
4b13b216 228AC_CACHE_VAL(grub_cv_i386_asm_addr32,
6a161fa9 229[cat > conftest.s.in <<\EOF
230 .code16
231l1: @ADDR32@ movb %al, l1
232EOF
233
4b13b216 234if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
6a161fa9 235 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
236else
237 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
238fi
239
05f3a0d7 240if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
4b13b216 241 grub_cv_i386_asm_addr32=yes
6a161fa9 242else
4b13b216 243 grub_cv_i386_asm_addr32=no
6a161fa9 244fi
245
246rm -f conftest*])
247
4b13b216 248AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
6a161fa9 249
2b167a72 250dnl check if our target compiler is apple cc
251dnl because it requires numerous workarounds
fc9e5810 252AC_DEFUN([grub_apple_target_cc],
2b167a72 253[AC_REQUIRE([AC_PROG_CC])
254AC_MSG_CHECKING([whether our target compiler is apple cc])
255AC_CACHE_VAL(grub_cv_apple_target_cc,
256[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
257 grub_cv_apple_target_cc=yes
258else
259 grub_cv_apple_target_cc=no
260fi
261])
262
263AC_MSG_RESULT([$grub_cv_apple_target_cc])])
264
6a161fa9 265
266dnl Later versions of GAS requires that addr32 and data32 prefixes
267dnl appear in the same lines as the instructions they modify, while
268dnl earlier versions requires that they appear in separate lines.
fc9e5810 269AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
6a161fa9 270[AC_REQUIRE([AC_PROG_CC])
271AC_MSG_CHECKING(dnl
272[whether addr32 must be in the same line as the instruction])
4b13b216 273AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
6a161fa9 274[cat > conftest.s <<\EOF
275 .code16
276l1: addr32 movb %al, l1
277EOF
278
05f3a0d7 279if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
4b13b216 280 grub_cv_i386_asm_prefix_requirement=yes
6a161fa9 281else
4b13b216 282 grub_cv_i386_asm_prefix_requirement=no
6a161fa9 283fi
284
285rm -f conftest*])
286
4b13b216 287if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
288 grub_tmp_addr32="addr32"
289 grub_tmp_data32="data32"
6a161fa9 290else
4b13b216 291 grub_tmp_addr32="addr32;"
292 grub_tmp_data32="data32;"
6a161fa9 293fi
294
742f9232
VS
295ADDR32=$grub_tmp_addr32
296DATA32=$grub_tmp_data32
6a161fa9 297
4b13b216 298AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
6a161fa9 299
300
6a161fa9 301dnl Check what symbol is defined as a bss start symbol.
302dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
fc9e5810 303AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
6a161fa9 304[AC_REQUIRE([AC_PROG_CC])
305AC_MSG_CHECKING([if __bss_start is defined by the compiler])
4b13b216 306AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
eb73121d 307[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
308 [[asm ("incl __bss_start")]])],
309 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
310 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
6a161fa9 311
4b13b216 312AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
6a161fa9 313
314AC_MSG_CHECKING([if edata is defined by the compiler])
4b13b216 315AC_CACHE_VAL(grub_cv_check_edata_symbol,
eb73121d 316[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
317 [[asm ("incl edata")]])],
318 [grub_cv_check_edata_symbol=yes],
319 [grub_cv_check_edata_symbol=no])])
6a161fa9 320
4b13b216 321AC_MSG_RESULT([$grub_cv_check_edata_symbol])
6a161fa9 322
323AC_MSG_CHECKING([if _edata is defined by the compiler])
4b13b216 324AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
eb73121d 325[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
326 [[asm ("incl _edata")]])],
327 [grub_cv_check_uscore_edata_symbol=yes],
328 [grub_cv_check_uscore_edata_symbol=no])])
6a161fa9 329
4b13b216 330AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
6a161fa9 331
4b13b216 332if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
742f9232 333 BSS_START_SYMBOL=__bss_start
4b13b216 334elif test "x$grub_cv_check_edata_symbol" = xyes; then
742f9232 335 BSS_START_SYMBOL=edata
4b13b216 336elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
742f9232 337 BSS_START_SYMBOL=_edata
6a161fa9 338else
339 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
340fi
341])
342
343dnl Check what symbol is defined as an end symbol.
344dnl Written by Yoshinori K. Okuji.
fc9e5810 345AC_DEFUN([grub_CHECK_END_SYMBOL],
6a161fa9 346[AC_REQUIRE([AC_PROG_CC])
347AC_MSG_CHECKING([if end is defined by the compiler])
4b13b216 348AC_CACHE_VAL(grub_cv_check_end_symbol,
eb73121d 349[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
350 [[asm ("incl end")]])],
351 [grub_cv_check_end_symbol=yes],
352 [grub_cv_check_end_symbol=no])])
6a161fa9 353
4b13b216 354AC_MSG_RESULT([$grub_cv_check_end_symbol])
6a161fa9 355
356AC_MSG_CHECKING([if _end is defined by the compiler])
4b13b216 357AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
eb73121d 358[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
359 [[asm ("incl _end")]])],
360 [grub_cv_check_uscore_end_symbol=yes],
361 [grub_cv_check_uscore_end_symbol=no])])
6a161fa9 362
4b13b216 363AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
6a161fa9 364
4b13b216 365if test "x$grub_cv_check_end_symbol" = xyes; then
742f9232 366 END_SYMBOL=end
4b13b216 367elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
742f9232 368 END_SYMBOL=_end
6a161fa9 369else
370 AC_MSG_ERROR([neither end nor _end is defined])
371fi
372])
5aded270 373
baa2a121 374\f
375dnl Check if the C compiler supports `-fstack-protector'.
fc9e5810 376AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
baa2a121 377[# Smashing stack protector.
378ssp_possible=yes]
379AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
380# Is this a reliable test case?
ab178c08
SJ
381AC_LANG_CONFTEST([AC_LANG_SOURCE([[
382void foo (void) { volatile char a[8]; a[3]; }
383]])])
baa2a121 384[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
385# `ac_compile' like this correct, after all?
386if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
387 AC_MSG_RESULT([yes])
388 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
389 rm -f conftest.s
390else
391 ssp_possible=no]
392 AC_MSG_RESULT([no])
393[fi]
394])
2a8a80e4 395
396dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
fc9e5810 397AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
2a8a80e4 398[# Smashing stack arg probe.
399sap_possible=yes]
400AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
ab178c08
SJ
401AC_LANG_CONFTEST([AC_LANG_SOURCE([[
402void foo (void) { volatile char a[8]; a[3]; }
403]])])
b35ec299 404[if eval "$ac_compile -S -mstack-arg-probe -Werror -o conftest.s" 2> /dev/null; then]
2a8a80e4 405 AC_MSG_RESULT([yes])
406 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
407 rm -f conftest.s
408else
409 sap_possible=no]
410 AC_MSG_RESULT([no])
411[fi]
412])
1f4147aa 413
414dnl Check if ln can handle directories properly (mingw).
fc9e5810 415AC_DEFUN([grub_CHECK_LINK_DIR],[
1f4147aa 416AC_MSG_CHECKING([whether ln can handle directories properly])
417[mkdir testdir 2>/dev/null
418case $srcdir in
419[\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
420 *) reldir=../$srcdir/include/grub/util ;;
421esac
422if ln -s $reldir testdir/util 2>/dev/null ; then]
423 AC_MSG_RESULT([yes])
424 [link_dir=yes
425else
426 link_dir=no]
427 AC_MSG_RESULT([no])
428[fi
429rm -rf testdir]
430])
93a81088 431
432dnl Check if the C compiler supports `-fPIE'.
fc9e5810 433AC_DEFUN([grub_CHECK_PIE],[
93a81088 434[# Position independent executable.
435pie_possible=yes]
436AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
437# Is this a reliable test case?
ab178c08 438AC_LANG_CONFTEST([AC_LANG_SOURCE([[
93a81088 439#ifdef __PIE__
440int main() {
441 return 0;
442}
443#else
444#error NO __PIE__ DEFINED
445#endif
ab178c08 446]])])
93a81088 447
448[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
449# `ac_compile' like this correct, after all?
450if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
451 AC_MSG_RESULT([yes])
452 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
453 rm -f conftest.s
454else
455 pie_possible=no]
456 AC_MSG_RESULT([no])
457[fi]
458])
7bd8b0c7
VS
459
460dnl Check if the C compiler supports `-fPIC'.
461AC_DEFUN([grub_CHECK_PIC],[
462[# Position independent executable.
463pic_possible=yes]
464AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default])
465# Is this a reliable test case?
466AC_LANG_CONFTEST([AC_LANG_SOURCE([[
467#ifdef __PIC__
468int main() {
469 return 0;
470}
471#else
472#error NO __PIC__ DEFINED
473#endif
474]])])
475
476[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
477# `ac_compile' like this correct, after all?
478if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
479 AC_MSG_RESULT([yes])
480 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
481 rm -f conftest.s
482else
483 pic_possible=no]
484 AC_MSG_RESULT([no])
485[fi]
486])
fd49ceb3
CW
487
488dnl Create an output variable with the transformed name of a GRUB utility
489dnl program.
490AC_DEFUN([grub_TRANSFORM],[dnl
491AC_SUBST(AS_TR_SH([$1]), [`AS_ECHO([$1]) | sed "$program_transform_name"`])dnl
492])
bb9f92b9
LL
493
494dnl Check if the C compiler supports `-mno-unaligned-access'.
495AC_DEFUN([grub_CHECK_NO_UNALIGNED_ACCESS],[
496[# foobar
497nua_possible=yes]
498AC_MSG_CHECKING([whether `$CC' supports `-mno-unaligned-access'])
499AC_LANG_CONFTEST([AC_LANG_SOURCE([[
500int main() {
501 return 0;
502}
503]])])
504
505[if eval "$ac_compile -S -mno-unaligned-access -o conftest.s" 2> /dev/null; then]
506 AC_MSG_RESULT([yes])
507 [rm -f conftest.s
508else
509 nua_possible=no]
510 AC_MSG_RESULT([no])
511[fi]
512])