]> git.proxmox.com Git - grub2.git/blame - acinclude.m4
grub-module-verifier: Ignore all_video emptiness on xen.
[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:");
37378f74
VS
22void __main (void);
23void __main (void) {}
26586d98 24int main (void);
25]], [[]])],
eb73121d 26 [grub_cv_prog_target_cc=yes],
27 [grub_cv_prog_target_cc=no])
f6130a12 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
4b13b216 37dnl grub_ASM_USCORE checks if C symbols get an underscore after
6a161fa9 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.
fc9e5810 41AC_DEFUN([grub_ASM_USCORE],
6a161fa9 42[AC_REQUIRE([AC_PROG_CC])
9da94e05 43AC_REQUIRE([AC_PROG_EGREP])
6a161fa9 44AC_MSG_CHECKING([if C symbols get an underscore after compilation])
4b13b216 45AC_CACHE_VAL(grub_cv_asm_uscore,
6a161fa9 46[cat > conftest.c <<\EOF
63f745e8 47int func (int *);
6a161fa9 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
9da94e05 62if $EGREP '(^|[^_[:alnum]])_func' conftest.s >/dev/null 2>&1; then
742f9232 63 HAVE_ASM_USCORE=1
4b13b216 64 grub_cv_asm_uscore=yes
6a161fa9 65else
742f9232 66 HAVE_ASM_USCORE=0
4b13b216 67 grub_cv_asm_uscore=no
6a161fa9 68fi
69
70rm -f conftest*])
71
4b13b216 72AC_MSG_RESULT([$grub_cv_asm_uscore])
6a161fa9 73])
74
75
76dnl Some versions of `objcopy -O binary' vary their output depending
77dnl on the link address.
fc9e5810 78AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
fc97214f 79[AC_MSG_CHECKING([whether ${TARGET_OBJCOPY} works for absolute addresses])
4b13b216 80AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
6a161fa9 81[cat > conftest.c <<\EOF
63f745e8 82void cmain (void);
6a161fa9 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
4b13b216 94grub_cv_prog_objcopy_absolute=yes
c926e1d5 95for link_addr in 0x2000 0x8000 0x7C00; do
0d7c7f75 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 :
6a161fa9 97 else
98 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
99 fi
fc97214f 100 if AC_TRY_COMMAND([${TARGET_OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
6a161fa9 101 else
fc97214f 102 AC_MSG_ERROR([${TARGET_OBJCOPY-objcopy} cannot create binary files])
6a161fa9 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
4b13b216 107 grub_cv_prog_objcopy_absolute=no
6a161fa9 108 break
109 fi
110done
111rm -f conftest*])
4b13b216 112AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
6a161fa9 113
4b13b216 114if test "x$grub_cv_prog_objcopy_absolute" = xno; then
115 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
6a161fa9 116fi
117])
118
119
cb71ba20 120dnl Supply --build-id=none to ld if building modules.
121dnl This suppresses warnings from ld on some systems
fc9e5810 122AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
cb71ba20 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"
eb73121d 127AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
128 [grub_cv_prog_ld_build_id_none=yes],
129 [grub_cv_prog_ld_build_id_none=no])
cb71ba20 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
5ec9740b 135 TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
cb71ba20 136fi
137])
138
20aea949
VS
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"
5757a93e 147if $TARGET_NM "$nm_works_tmp_dir/ef" > /dev/null; then
20aea949
VS
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
fc97214f
VS
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([[]], [[]])])
20aea949 169$TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_minus_p_tmp_dir/ef"
fc97214f
VS
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"
20aea949 176rmdir "$nm_minus_p_tmp_dir"
fc97214f
VS
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([[]], [[]])])
20aea949 194$TARGET_CC $TARGET_CFLAGS -c conftest.c -o "$nm_defined_only_tmp_dir/ef"
fc97214f
VS
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"
20aea949 201rmdir "$nm_defined_only_tmp_dir"
fc97214f
VS
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
cb71ba20 212
6a161fa9 213dnl Check what symbol is defined as a bss start symbol.
214dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
fc9e5810 215AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
6a161fa9 216[AC_REQUIRE([AC_PROG_CC])
217AC_MSG_CHECKING([if __bss_start is defined by the compiler])
4b13b216 218AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
37378f74
VS
219[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
220asm (".globl start; start:");
221void __main (void);
222void __main (void) {}
223int main (void);
224]],
eb73121d 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])])
6a161fa9 228
4b13b216 229AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
6a161fa9 230
231AC_MSG_CHECKING([if edata is defined by the compiler])
4b13b216 232AC_CACHE_VAL(grub_cv_check_edata_symbol,
37378f74
VS
233[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
234asm (".globl start; start:");
235void __main (void);
236void __main (void) {}
237int main (void);]],
eb73121d 238 [[asm ("incl edata")]])],
239 [grub_cv_check_edata_symbol=yes],
240 [grub_cv_check_edata_symbol=no])])
6a161fa9 241
4b13b216 242AC_MSG_RESULT([$grub_cv_check_edata_symbol])
6a161fa9 243
244AC_MSG_CHECKING([if _edata is defined by the compiler])
4b13b216 245AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
37378f74
VS
246[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
247asm (".globl start; start:");
248void __main (void);
249void __main (void) {}
250int main (void);]],
eb73121d 251 [[asm ("incl _edata")]])],
252 [grub_cv_check_uscore_edata_symbol=yes],
253 [grub_cv_check_uscore_edata_symbol=no])])
6a161fa9 254
4b13b216 255AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
6a161fa9 256
4b13b216 257if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
742f9232 258 BSS_START_SYMBOL=__bss_start
4b13b216 259elif test "x$grub_cv_check_edata_symbol" = xyes; then
742f9232 260 BSS_START_SYMBOL=edata
4b13b216 261elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
742f9232 262 BSS_START_SYMBOL=_edata
6a161fa9 263else
264 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
265fi
266])
267
268dnl Check what symbol is defined as an end symbol.
269dnl Written by Yoshinori K. Okuji.
fc9e5810 270AC_DEFUN([grub_CHECK_END_SYMBOL],
6a161fa9 271[AC_REQUIRE([AC_PROG_CC])
272AC_MSG_CHECKING([if end is defined by the compiler])
4b13b216 273AC_CACHE_VAL(grub_cv_check_end_symbol,
37378f74
VS
274[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
275asm (".globl start; start:");
276void __main (void);
277void __main (void) {}
278int main (void);]],
eb73121d 279 [[asm ("incl end")]])],
280 [grub_cv_check_end_symbol=yes],
281 [grub_cv_check_end_symbol=no])])
6a161fa9 282
4b13b216 283AC_MSG_RESULT([$grub_cv_check_end_symbol])
6a161fa9 284
285AC_MSG_CHECKING([if _end is defined by the compiler])
4b13b216 286AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
37378f74
VS
287[AC_LINK_IFELSE([AC_LANG_PROGRAM([[
288asm (".globl start; start:");
289void __main (void);
290void __main (void) {}
291int main (void);]],
eb73121d 292 [[asm ("incl _end")]])],
293 [grub_cv_check_uscore_end_symbol=yes],
294 [grub_cv_check_uscore_end_symbol=no])])
6a161fa9 295
4b13b216 296AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
6a161fa9 297
4b13b216 298if test "x$grub_cv_check_end_symbol" = xyes; then
742f9232 299 END_SYMBOL=end
4b13b216 300elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
742f9232 301 END_SYMBOL=_end
6a161fa9 302else
303 AC_MSG_ERROR([neither end nor _end is defined])
304fi
305])
5aded270 306
baa2a121 307\f
308dnl Check if the C compiler supports `-fstack-protector'.
fc9e5810 309AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
baa2a121 310[# Smashing stack protector.
311ssp_possible=yes]
312AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
313# Is this a reliable test case?
ab178c08
SJ
314AC_LANG_CONFTEST([AC_LANG_SOURCE([[
315void foo (void) { volatile char a[8]; a[3]; }
316]])])
baa2a121 317[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
318# `ac_compile' like this correct, after all?
319if 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
323else
324 ssp_possible=no]
325 AC_MSG_RESULT([no])
326[fi]
327])
2a8a80e4 328
329dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
fc9e5810 330AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
2a8a80e4 331[# Smashing stack arg probe.
332sap_possible=yes]
333AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
ab178c08
SJ
334AC_LANG_CONFTEST([AC_LANG_SOURCE([[
335void foo (void) { volatile char a[8]; a[3]; }
336]])])
b35ec299 337[if eval "$ac_compile -S -mstack-arg-probe -Werror -o conftest.s" 2> /dev/null; then]
2a8a80e4 338 AC_MSG_RESULT([yes])
339 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
340 rm -f conftest.s
341else
342 sap_possible=no]
343 AC_MSG_RESULT([no])
344[fi]
345])
1f4147aa 346
e0a85094 347dnl Check if ln -s can handle directories properly (mingw).
fc9e5810 348AC_DEFUN([grub_CHECK_LINK_DIR],[
e0a85094 349AC_MSG_CHECKING([whether ln -s can handle directories properly])
1f4147aa 350[mkdir testdir 2>/dev/null
351case $srcdir in
352[\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
353 *) reldir=../$srcdir/include/grub/util ;;
354esac
e0a85094 355if ln -s $reldir testdir/util 2>/dev/null && rm -f testdir/util 2>/dev/null ; then]
1f4147aa 356 AC_MSG_RESULT([yes])
357 [link_dir=yes
358else
359 link_dir=no]
360 AC_MSG_RESULT([no])
361[fi
362rm -rf testdir]
363])
93a81088 364
365dnl Check if the C compiler supports `-fPIE'.
fc9e5810 366AC_DEFUN([grub_CHECK_PIE],[
93a81088 367[# Position independent executable.
368pie_possible=yes]
369AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
370# Is this a reliable test case?
ab178c08 371AC_LANG_CONFTEST([AC_LANG_SOURCE([[
93a81088 372#ifdef __PIE__
373int main() {
374 return 0;
375}
376#else
377#error NO __PIE__ DEFINED
378#endif
ab178c08 379]])])
93a81088 380
381[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
382# `ac_compile' like this correct, after all?
383if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
384 AC_MSG_RESULT([yes])
385 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
386 rm -f conftest.s
387else
388 pie_possible=no]
389 AC_MSG_RESULT([no])
390[fi]
391])
7bd8b0c7 392
a3e9da05
MG
393dnl Check if the Linker supports `-no-pie'.
394AC_DEFUN([grub_CHECK_NO_PIE],
395[AC_MSG_CHECKING([whether linker accepts -no-pie])
396AC_CACHE_VAL(grub_cv_cc_ld_no_pie,
397[save_LDFLAGS="$LDFLAGS"
398LDFLAGS="$LDFLAGS -no-pie"
399AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
400 [grub_cv_cc_ld_no_pie=yes],
401 [grub_cv_cc_ld_no_pie=no])
402LDFLAGS="$save_LDFLAGS"
403])
404AC_MSG_RESULT([$grub_cv_cc_ld_no_pie])
405nopie_possible=no
406if test "x$grub_cv_cc_ld_no_pie" = xyes ; then
407 nopie_possible=yes
408fi
409])
410
7bd8b0c7
VS
411dnl Check if the C compiler supports `-fPIC'.
412AC_DEFUN([grub_CHECK_PIC],[
413[# Position independent executable.
414pic_possible=yes]
415AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default])
416# Is this a reliable test case?
417AC_LANG_CONFTEST([AC_LANG_SOURCE([[
418#ifdef __PIC__
419int main() {
420 return 0;
421}
422#else
423#error NO __PIC__ DEFINED
424#endif
425]])])
426
427[# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
428# `ac_compile' like this correct, after all?
429if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
430 AC_MSG_RESULT([yes])
431 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
432 rm -f conftest.s
433else
434 pic_possible=no]
435 AC_MSG_RESULT([no])
436[fi]
437])
fd49ceb3
CW
438
439dnl Create an output variable with the transformed name of a GRUB utility
440dnl program.
441AC_DEFUN([grub_TRANSFORM],[dnl
442AC_SUBST(AS_TR_SH([$1]), [`AS_ECHO([$1]) | sed "$program_transform_name"`])dnl
443])