]> git.proxmox.com Git - grub2.git/blob - acinclude.m4
Release 2.06-13+deb12u1
[grub2.git] / acinclude.m4
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)],
4 [$1
5 int
6 main (void)
7 {
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.
10 $2
11 ;
12 return 0;
13 }])
14
15
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:");
22 void __main (void);
23 void __main (void) {}
24 int main (void);
25 ]], [[]])],
26 [grub_cv_prog_target_cc=yes],
27 [grub_cv_prog_target_cc=no])
28 ])
29 AC_MSG_RESULT([$grub_cv_prog_target_cc])
30
31 if test "x$grub_cv_prog_target_cc" = xno; then
32 AC_MSG_ERROR([cannot compile for the target])
33 fi
34 ])
35
36
37 dnl grub_ASM_USCORE checks if C symbols get an underscore after
38 dnl compiling to assembler.
39 dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
40 dnl Erich Boleyn and modified by Yoshinori K. Okuji.
41 AC_DEFUN([grub_ASM_USCORE],
42 [AC_REQUIRE([AC_PROG_CC])
43 AC_REQUIRE([AC_PROG_EGREP])
44 AC_MSG_CHECKING([if C symbols get an underscore after compilation])
45 AC_CACHE_VAL(grub_cv_asm_uscore,
46 [cat > conftest.c <<\EOF
47 int func (int *);
48 int
49 func (int *list)
50 {
51 *list = 0;
52 return *list;
53 }
54 EOF
55
56 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
57 true
58 else
59 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
60 fi
61
62 if $EGREP '(^|[^_[:alnum]])_func' conftest.s >/dev/null 2>&1; then
63 HAVE_ASM_USCORE=1
64 grub_cv_asm_uscore=yes
65 else
66 HAVE_ASM_USCORE=0
67 grub_cv_asm_uscore=no
68 fi
69
70 rm -f conftest*])
71
72 AC_MSG_RESULT([$grub_cv_asm_uscore])
73 ])
74
75
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 ${TARGET_OBJCOPY} works for absolute addresses])
80 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
81 [cat > conftest.c <<\EOF
82 void cmain (void);
83 void
84 cmain (void)
85 {
86 *((int *) 0x1000) = 2;
87 }
88 EOF
89
90 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
91 else
92 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
93 fi
94 grub_cv_prog_objcopy_absolute=yes
95 for link_addr in 0x2000 0x8000 0x7C00; do
96 if AC_TRY_COMMAND([${CC-cc} ${TARGET_CFLAGS} ${TARGET_LDFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then :
97 else
98 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
99 fi
100 if AC_TRY_COMMAND([${TARGET_OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
101 else
102 AC_MSG_ERROR([${TARGET_OBJCOPY-objcopy} cannot create binary files])
103 fi
104 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
105 mv -f conftest conftest.old
106 else
107 grub_cv_prog_objcopy_absolute=no
108 break
109 fi
110 done
111 rm -f conftest*])
112 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
113
114 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
115 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
116 fi
117 ])
118
119
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"
131 ])
132 AC_MSG_RESULT([$grub_cv_prog_ld_build_id_none])
133
134 if test "x$grub_cv_prog_ld_build_id_none" = xyes; then
135 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
136 fi
137 ])
138
139 dnl Check nm
140 AC_DEFUN([grub_PROG_NM_WORKS],
141 [AC_MSG_CHECKING([whether nm works])
142 AC_CACHE_VAL(grub_cv_prog_nm_works,
143 [
144 nm_works_tmp_dir="$(mktemp -d "./confXXXXXX")"
145 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
146 $TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_works_tmp_dir/ef"
147 if $TARGET_NM "$nm_works_tmp_dir/ef" > /dev/null; then
148 grub_cv_prog_nm_works=yes
149 else
150 grub_cv_prog_nm_minus_p=no
151 fi
152 rm "$nm_works_tmp_dir/ef"
153 rmdir "$nm_works_tmp_dir"
154 ])
155 AC_MSG_RESULT([$grub_cv_prog_nm_works])
156
157 if test "x$grub_cv_prog_nm_works" != xyes; then
158 AC_MSG_ERROR([nm does not work])
159 fi
160 ])
161
162 dnl Supply -P to nm
163 AC_DEFUN([grub_PROG_NM_MINUS_P],
164 [AC_MSG_CHECKING([whether nm accepts -P])
165 AC_CACHE_VAL(grub_cv_prog_nm_minus_p,
166 [
167 nm_minus_p_tmp_dir="$(mktemp -d "./confXXXXXX")"
168 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
169 $TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_minus_p_tmp_dir/ef"
170 if $TARGET_NM -P "$nm_minus_p_tmp_dir/ef" 2>&1 > /dev/null; then
171 grub_cv_prog_nm_minus_p=yes
172 else
173 grub_cv_prog_nm_minus_p=no
174 fi
175 rm "$nm_minus_p_tmp_dir/ef"
176 rmdir "$nm_minus_p_tmp_dir"
177 ])
178 AC_MSG_RESULT([$grub_cv_prog_nm_minus_p])
179
180 if test "x$grub_cv_prog_nm_minus_p" = xyes; then
181 TARGET_NMFLAGS_MINUS_P="-P"
182 else
183 TARGET_NMFLAGS_MINUS_P=
184 fi
185 ])
186
187 dnl Supply --defined-only to nm
188 AC_DEFUN([grub_PROG_NM_DEFINED_ONLY],
189 [AC_MSG_CHECKING([whether nm accepts --defined-only])
190 AC_CACHE_VAL(grub_cv_prog_nm_defined_only,
191 [
192 nm_defined_only_tmp_dir="$(mktemp -d "./confXXXXXX")"
193 AC_LANG_CONFTEST([AC_LANG_PROGRAM([[]], [[]])])
194 $TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_defined_only_tmp_dir/ef"
195 if $TARGET_NM --defined-only "$nm_defined_only_tmp_dir/ef" 2>&1 > /dev/null; then
196 grub_cv_prog_nm_defined_only=yes
197 else
198 grub_cv_prog_nm_defined_only=no
199 fi
200 rm "$nm_defined_only_tmp_dir/ef"
201 rmdir "$nm_defined_only_tmp_dir"
202 ])
203 AC_MSG_RESULT([$grub_cv_prog_nm_defined_only])
204
205 if test "x$grub_cv_prog_nm_defined_only" = xyes; then
206 TARGET_NMFLAGS_DEFINED_ONLY=--defined-only
207 else
208 TARGET_NMFLAGS_DEFINED_ONLY=
209 fi
210 ])
211
212
213 dnl Check what symbol is defined as a bss start symbol.
214 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
215 AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
216 [AC_REQUIRE([AC_PROG_CC])
217 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
218 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
219 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
220 asm (".globl start; start:");
221 void __main (void);
222 void __main (void) {}
223 int main (void);
224 ]],
225 [[asm ("incl __bss_start")]])],
226 [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
227 [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
228
229 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
230
231 AC_MSG_CHECKING([if edata is defined by the compiler])
232 AC_CACHE_VAL(grub_cv_check_edata_symbol,
233 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
234 asm (".globl start; start:");
235 void __main (void);
236 void __main (void) {}
237 int main (void);]],
238 [[asm ("incl edata")]])],
239 [grub_cv_check_edata_symbol=yes],
240 [grub_cv_check_edata_symbol=no])])
241
242 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
243
244 AC_MSG_CHECKING([if _edata is defined by the compiler])
245 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
246 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
247 asm (".globl start; start:");
248 void __main (void);
249 void __main (void) {}
250 int main (void);]],
251 [[asm ("incl _edata")]])],
252 [grub_cv_check_uscore_edata_symbol=yes],
253 [grub_cv_check_uscore_edata_symbol=no])])
254
255 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
256
257 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
258 BSS_START_SYMBOL=__bss_start
259 elif test "x$grub_cv_check_edata_symbol" = xyes; then
260 BSS_START_SYMBOL=edata
261 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
262 BSS_START_SYMBOL=_edata
263 else
264 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
265 fi
266 ])
267
268 dnl Check what symbol is defined as an end symbol.
269 dnl Written by Yoshinori K. Okuji.
270 AC_DEFUN([grub_CHECK_END_SYMBOL],
271 [AC_REQUIRE([AC_PROG_CC])
272 AC_MSG_CHECKING([if end is defined by the compiler])
273 AC_CACHE_VAL(grub_cv_check_end_symbol,
274 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
275 asm (".globl start; start:");
276 void __main (void);
277 void __main (void) {}
278 int main (void);]],
279 [[asm ("incl end")]])],
280 [grub_cv_check_end_symbol=yes],
281 [grub_cv_check_end_symbol=no])])
282
283 AC_MSG_RESULT([$grub_cv_check_end_symbol])
284
285 AC_MSG_CHECKING([if _end is defined by the compiler])
286 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
287 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
288 asm (".globl start; start:");
289 void __main (void);
290 void __main (void) {}
291 int main (void);]],
292 [[asm ("incl _end")]])],
293 [grub_cv_check_uscore_end_symbol=yes],
294 [grub_cv_check_uscore_end_symbol=no])])
295
296 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
297
298 if test "x$grub_cv_check_end_symbol" = xyes; then
299 END_SYMBOL=end
300 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
301 END_SYMBOL=_end
302 else
303 AC_MSG_ERROR([neither end nor _end is defined])
304 fi
305 ])
306
307 \f
308 dnl Check if the C compiler supports the stack protector
309 AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
310 [# Stack smashing protector.
311 ssp_possible=yes]
312 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
313 # Is this a reliable test case?
314 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
315 void foo (void) { volatile char a[8]; a[3]; }
316 ]])])
317 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
318 # `ac_compile' like this correct, after all?
319 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
320 AC_MSG_RESULT([yes])
321 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
322 rm -f conftest.s
323 else
324 ssp_possible=no]
325 AC_MSG_RESULT([no])
326 [fi]
327 [# Strong stack smashing protector.
328 ssp_strong_possible=yes]
329 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector-strong'])
330 # Is this a reliable test case?
331 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
332 void foo (void) { volatile char a[8]; a[3]; }
333 ]])])
334 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
335 # `ac_compile' like this correct, after all?
336 if eval "$ac_compile -S -fstack-protector-strong -o conftest.s" 2> /dev/null; then]
337 AC_MSG_RESULT([yes])
338 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
339 rm -f conftest.s
340 else
341 ssp_strong_possible=no]
342 AC_MSG_RESULT([no])
343 [fi]
344 [# Global stack smashing protector.
345 ssp_global_possible=yes]
346 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-protector-guard=global'])
347 # Is this a reliable test case?
348 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
349 void foo (void) { volatile char a[8]; a[3]; }
350 ]])])
351 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
352 # `ac_compile' like this correct, after all?
353 if eval "$ac_compile -S -fstack-protector -mstack-protector-guard=global -o conftest.s" 2> /dev/null; then]
354 AC_MSG_RESULT([yes])
355 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
356 rm -f conftest.s
357 else
358 ssp_global_possible=no]
359 AC_MSG_RESULT([no])
360 [fi]
361 ])
362
363 dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
364 AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
365 [# Smashing stack arg probe.
366 sap_possible=yes]
367 AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
368 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
369 void foo (void) { volatile char a[8]; a[3]; }
370 ]])])
371 [if eval "$ac_compile -S -mstack-arg-probe -Werror -o conftest.s" 2> /dev/null; then]
372 AC_MSG_RESULT([yes])
373 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
374 rm -f conftest.s
375 else
376 sap_possible=no]
377 AC_MSG_RESULT([no])
378 [fi]
379 ])
380
381 dnl Check if ln -s can handle directories properly (mingw).
382 AC_DEFUN([grub_CHECK_LINK_DIR],[
383 AC_MSG_CHECKING([whether ln -s can handle directories properly])
384 [mkdir testdir 2>/dev/null
385 case $srcdir in
386 [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
387 *) reldir=../$srcdir/include/grub/util ;;
388 esac
389 if ln -s $reldir testdir/util 2>/dev/null && rm -f testdir/util 2>/dev/null ; then]
390 AC_MSG_RESULT([yes])
391 [link_dir=yes
392 else
393 link_dir=no]
394 AC_MSG_RESULT([no])
395 [fi
396 rm -rf testdir]
397 ])
398
399 dnl Check if the C compiler supports `-fPIE'.
400 AC_DEFUN([grub_CHECK_PIE],[
401 [# Position independent executable.
402 pie_possible=yes]
403 AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
404 # Is this a reliable test case?
405 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
406 #ifdef __PIE__
407 int main() {
408 return 0;
409 }
410 #else
411 #error NO __PIE__ DEFINED
412 #endif
413 ]])])
414
415 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
416 # `ac_compile' like this correct, after all?
417 if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
418 AC_MSG_RESULT([yes])
419 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
420 rm -f conftest.s
421 else
422 pie_possible=no]
423 AC_MSG_RESULT([no])
424 [fi]
425 ])
426
427 AC_DEFUN([grub_CHECK_LINK_PIE],[
428 [# Position independent executable.
429 link_nopie_needed=no]
430 AC_MSG_CHECKING([whether linker needs disabling of PIE to work])
431 AC_LANG_CONFTEST([AC_LANG_SOURCE([[]])])
432
433 [if eval "$ac_compile -Wl,-r,-d -nostdlib -Werror -o conftest.o" 2> /dev/null; then]
434 AC_MSG_RESULT([no])
435 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
436 rm -f conftest.o
437 else
438 link_nopie_needed=yes]
439 AC_MSG_RESULT([yes])
440 [fi]
441 ])
442
443
444 dnl Check if the Linker supports `-no-pie'.
445 AC_DEFUN([grub_CHECK_NO_PIE],
446 [AC_MSG_CHECKING([whether linker accepts -no-pie])
447 AC_CACHE_VAL(grub_cv_cc_ld_no_pie,
448 [save_LDFLAGS="$LDFLAGS"
449 LDFLAGS="$LDFLAGS -no-pie -nostdlib -Werror"
450 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
451 [grub_cv_cc_ld_no_pie=yes],
452 [grub_cv_cc_ld_no_pie=no])
453 LDFLAGS="$save_LDFLAGS"
454 ])
455 AC_MSG_RESULT([$grub_cv_cc_ld_no_pie])
456 nopie_possible=no
457 if test "x$grub_cv_cc_ld_no_pie" = xyes ; then
458 nopie_possible=yes
459 fi
460 ])
461
462 AC_DEFUN([grub_CHECK_NO_PIE_ONEWORD],
463 [AC_MSG_CHECKING([whether linker accepts -nopie])
464 AC_CACHE_VAL(grub_cv_cc_ld_no_pie_oneword,
465 [save_LDFLAGS="$LDFLAGS"
466 LDFLAGS="$LDFLAGS -nopie -nostdlib -Werror"
467 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
468 [grub_cv_cc_ld_no_pie_oneword=yes],
469 [grub_cv_cc_ld_no_pie_oneword=no])
470 LDFLAGS="$save_LDFLAGS"
471 ])
472 AC_MSG_RESULT([$grub_cv_cc_ld_no_pie_oneword])
473 nopie_oneword_possible=no
474 if test "x$grub_cv_cc_ld_no_pie_oneword" = xyes ; then
475 nopie_oneword_possible=yes
476 fi
477 ])
478
479 dnl Check if the C compiler supports `-fPIC'.
480 AC_DEFUN([grub_CHECK_PIC],[
481 [# Position independent executable.
482 pic_possible=yes]
483 AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default])
484 # Is this a reliable test case?
485 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
486 #ifdef __PIC__
487 int main() {
488 return 0;
489 }
490 #else
491 #error NO __PIC__ DEFINED
492 #endif
493 ]])])
494
495 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
496 # `ac_compile' like this correct, after all?
497 if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
498 AC_MSG_RESULT([yes])
499 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
500 rm -f conftest.s
501 else
502 pic_possible=no]
503 AC_MSG_RESULT([no])
504 [fi]
505 ])
506
507 dnl Create an output variable with the transformed name of a GRUB utility
508 dnl program.
509 AC_DEFUN([grub_TRANSFORM],[dnl
510 AC_SUBST(AS_TR_SH([$1]), [`AS_ECHO([$1]) | sed "$program_transform_name"`])dnl
511 ])