source: grub-pc/trunk/fuentes/acinclude.m4 @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 4 years ago

updated version and apply net.ifnames=0 into debian/rules

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