acinclude.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. dnl Check whether target compiler is working
  15. AC_DEFUN([grub_PROG_TARGET_CC],
  16. [AC_MSG_CHECKING([whether target compiler is working])
  17. AC_CACHE_VAL(grub_cv_prog_target_cc,
  18. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  19. asm (".globl start,_start\n start:\n _start:\n");
  20. int main (void);
  21. ]], [[]])],
  22. [grub_cv_prog_target_cc=yes],
  23. [grub_cv_prog_target_cc=no])
  24. ])
  25. AC_MSG_RESULT([$grub_cv_prog_target_cc])
  26. if test "x$grub_cv_prog_target_cc" = xno; then
  27. AC_MSG_ERROR([cannot compile for the target])
  28. fi
  29. ])
  30. dnl grub_ASM_USCORE checks if C symbols get an underscore after
  31. dnl compiling to assembler.
  32. dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
  33. dnl Erich Boleyn and modified by Yoshinori K. Okuji.
  34. AC_DEFUN([grub_ASM_USCORE],
  35. [AC_REQUIRE([AC_PROG_CC])
  36. AC_MSG_CHECKING([if C symbols get an underscore after compilation])
  37. AC_CACHE_VAL(grub_cv_asm_uscore,
  38. [cat > conftest.c <<\EOF
  39. int func (int *);
  40. int
  41. func (int *list)
  42. {
  43. *list = 0;
  44. return *list;
  45. }
  46. EOF
  47. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
  48. true
  49. else
  50. AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
  51. fi
  52. if grep _func conftest.s >/dev/null 2>&1; then
  53. grub_cv_asm_uscore=yes
  54. else
  55. grub_cv_asm_uscore=no
  56. fi
  57. rm -f conftest*])
  58. if test "x$grub_cv_asm_uscore" = xyes; then
  59. AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
  60. [Define if C symbols get an underscore after compilation])
  61. fi
  62. AC_MSG_RESULT([$grub_cv_asm_uscore])
  63. ])
  64. dnl Some versions of `objcopy -O binary' vary their output depending
  65. dnl on the link address.
  66. AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
  67. [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
  68. AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
  69. [cat > conftest.c <<\EOF
  70. void cmain (void);
  71. void
  72. cmain (void)
  73. {
  74. *((int *) 0x1000) = 2;
  75. }
  76. EOF
  77. if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
  78. else
  79. AC_MSG_ERROR([${CC-cc} cannot compile C source code])
  80. fi
  81. grub_cv_prog_objcopy_absolute=yes
  82. for link_addr in 0x2000 0x8000 0x7C00; do
  83. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC}$link_addr conftest.o -o conftest.exec]); then :
  84. else
  85. AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
  86. fi
  87. if AC_TRY_COMMAND([${OBJCOPY-objcopy} --only-section=.text -O binary conftest.exec conftest]); then :
  88. else
  89. AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
  90. fi
  91. if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
  92. mv -f conftest conftest.old
  93. else
  94. grub_cv_prog_objcopy_absolute=no
  95. break
  96. fi
  97. done
  98. rm -f conftest*])
  99. AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
  100. if test "x$grub_cv_prog_objcopy_absolute" = xno; then
  101. AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
  102. fi
  103. ])
  104. dnl Supply --build-id=none to ld if building modules.
  105. dnl This suppresses warnings from ld on some systems
  106. AC_DEFUN([grub_PROG_LD_BUILD_ID_NONE],
  107. [AC_MSG_CHECKING([whether linker accepts --build-id=none])
  108. AC_CACHE_VAL(grub_cv_prog_ld_build_id_none,
  109. [save_LDFLAGS="$LDFLAGS"
  110. LDFLAGS="$LDFLAGS -Wl,--build-id=none"
  111. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
  112. [grub_cv_prog_ld_build_id_none=yes],
  113. [grub_cv_prog_ld_build_id_none=no])
  114. LDFLAGS="$save_LDFLAGS"
  115. ])
  116. 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"
  119. fi
  120. ])
  121. dnl Mass confusion!
  122. dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
  123. dnl instructions, but implicitly insert addr32 and data32 bytes so
  124. dnl that the code works in real mode''.
  125. dnl
  126. dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
  127. dnl instructions,'' which seems right. This requires the programmer
  128. dnl to explicitly insert addr32 and data32 instructions when they want
  129. dnl them.
  130. dnl
  131. dnl We only support the newer versions, because the old versions cause
  132. dnl major pain, by requiring manual assembly to get 16-bit instructions into
  133. dnl asm files.
  134. AC_DEFUN([grub_I386_ASM_ADDR32],
  135. [AC_REQUIRE([AC_PROG_CC])
  136. AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
  137. AC_MSG_CHECKING([for .code16 addr32 assembler support])
  138. AC_CACHE_VAL(grub_cv_i386_asm_addr32,
  139. [cat > conftest.s.in <<\EOF
  140. .code16
  141. l1: @ADDR32@ movb %al, l1
  142. EOF
  143. if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
  144. sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
  145. else
  146. sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
  147. fi
  148. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  149. grub_cv_i386_asm_addr32=yes
  150. else
  151. grub_cv_i386_asm_addr32=no
  152. fi
  153. rm -f conftest*])
  154. AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
  155. dnl check if our compiler is apple cc
  156. dnl because it requires numerous workarounds
  157. AC_DEFUN([grub_apple_cc],
  158. [AC_REQUIRE([AC_PROG_CC])
  159. AC_MSG_CHECKING([whether our compiler is apple cc])
  160. AC_CACHE_VAL(grub_cv_apple_cc,
  161. [if $CC -v 2>&1 | grep "Apple" > /dev/null; then
  162. grub_cv_apple_cc=yes
  163. else
  164. grub_cv_apple_cc=no
  165. fi
  166. ])
  167. AC_MSG_RESULT([$grub_cv_apple_cc])])
  168. dnl check if our target compiler is apple cc
  169. dnl because it requires numerous workarounds
  170. AC_DEFUN([grub_apple_target_cc],
  171. [AC_REQUIRE([AC_PROG_CC])
  172. AC_MSG_CHECKING([whether our target compiler is apple cc])
  173. AC_CACHE_VAL(grub_cv_apple_target_cc,
  174. [if $CC -v 2>&1 | grep "Apple" > /dev/null; then
  175. grub_cv_apple_target_cc=yes
  176. else
  177. grub_cv_apple_target_cc=no
  178. fi
  179. ])
  180. AC_MSG_RESULT([$grub_cv_apple_target_cc])])
  181. dnl Later versions of GAS requires that addr32 and data32 prefixes
  182. dnl appear in the same lines as the instructions they modify, while
  183. dnl earlier versions requires that they appear in separate lines.
  184. AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
  185. [AC_REQUIRE([AC_PROG_CC])
  186. AC_MSG_CHECKING(dnl
  187. [whether addr32 must be in the same line as the instruction])
  188. AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
  189. [cat > conftest.s <<\EOF
  190. .code16
  191. l1: addr32 movb %al, l1
  192. EOF
  193. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  194. grub_cv_i386_asm_prefix_requirement=yes
  195. else
  196. grub_cv_i386_asm_prefix_requirement=no
  197. fi
  198. rm -f conftest*])
  199. if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
  200. grub_tmp_addr32="addr32"
  201. grub_tmp_data32="data32"
  202. else
  203. grub_tmp_addr32="addr32;"
  204. grub_tmp_data32="data32;"
  205. fi
  206. AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
  207. [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
  208. AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
  209. [Define it to \"data32\" or \"data32;\" to make GAS happy])
  210. AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
  211. dnl Older versions of GAS require that absolute indirect calls/jumps are
  212. dnl not prefixed with `*', while later versions warn if not prefixed.
  213. AC_DEFUN([grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK],
  214. [AC_REQUIRE([AC_PROG_CC])
  215. AC_MSG_CHECKING(dnl
  216. [whether an absolute indirect call/jump must not be prefixed with an asterisk])
  217. AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
  218. [cat > conftest.s <<\EOF
  219. lcall *(offset)
  220. offset:
  221. .long 0
  222. .word 0
  223. EOF
  224. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  225. grub_cv_i386_asm_absolute_without_asterisk=no
  226. else
  227. grub_cv_i386_asm_absolute_without_asterisk=yes
  228. fi
  229. rm -f conftest*])
  230. if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
  231. AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
  232. [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
  233. fi
  234. AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
  235. dnl Check what symbol is defined as a bss start symbol.
  236. dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
  237. AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
  238. [AC_REQUIRE([AC_PROG_CC])
  239. AC_MSG_CHECKING([if __bss_start is defined by the compiler])
  240. AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
  241. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  242. [[asm ("incl __bss_start")]])],
  243. [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
  244. [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
  245. AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
  246. AC_MSG_CHECKING([if edata is defined by the compiler])
  247. AC_CACHE_VAL(grub_cv_check_edata_symbol,
  248. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  249. [[asm ("incl edata")]])],
  250. [grub_cv_check_edata_symbol=yes],
  251. [grub_cv_check_edata_symbol=no])])
  252. AC_MSG_RESULT([$grub_cv_check_edata_symbol])
  253. AC_MSG_CHECKING([if _edata is defined by the compiler])
  254. AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
  255. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  256. [[asm ("incl _edata")]])],
  257. [grub_cv_check_uscore_edata_symbol=yes],
  258. [grub_cv_check_uscore_edata_symbol=no])])
  259. AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
  260. AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
  261. if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
  262. AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
  263. elif test "x$grub_cv_check_edata_symbol" = xyes; then
  264. AC_DEFINE([BSS_START_SYMBOL], [edata])
  265. elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
  266. AC_DEFINE([BSS_START_SYMBOL], [_edata])
  267. else
  268. AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
  269. fi
  270. ])
  271. dnl Check what symbol is defined as an end symbol.
  272. dnl Written by Yoshinori K. Okuji.
  273. AC_DEFUN([grub_CHECK_END_SYMBOL],
  274. [AC_REQUIRE([AC_PROG_CC])
  275. AC_MSG_CHECKING([if end is defined by the compiler])
  276. AC_CACHE_VAL(grub_cv_check_end_symbol,
  277. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  278. [[asm ("incl end")]])],
  279. [grub_cv_check_end_symbol=yes],
  280. [grub_cv_check_end_symbol=no])])
  281. AC_MSG_RESULT([$grub_cv_check_end_symbol])
  282. AC_MSG_CHECKING([if _end is defined by the compiler])
  283. AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
  284. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
  285. [[asm ("incl _end")]])],
  286. [grub_cv_check_uscore_end_symbol=yes],
  287. [grub_cv_check_uscore_end_symbol=no])])
  288. AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
  289. AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
  290. if test "x$grub_cv_check_end_symbol" = xyes; then
  291. AC_DEFINE([END_SYMBOL], [end])
  292. elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
  293. AC_DEFINE([END_SYMBOL], [_end])
  294. else
  295. AC_MSG_ERROR([neither end nor _end is defined])
  296. fi
  297. ])
  298. dnl Check if the C compiler generates calls to `__enable_execute_stack()'.
  299. AC_DEFUN([grub_CHECK_ENABLE_EXECUTE_STACK],[
  300. AC_MSG_CHECKING([whether `$CC' generates calls to `__enable_execute_stack()'])
  301. AC_LANG_CONFTEST([[
  302. void f (int (*p) (void));
  303. void g (int i)
  304. {
  305. int nestedfunc (void) { return i; }
  306. f (nestedfunc);
  307. }
  308. ]])
  309. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
  310. true
  311. else
  312. AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
  313. fi
  314. if grep __enable_execute_stack conftest.s >/dev/null 2>&1; then
  315. AC_DEFINE([NEED_ENABLE_EXECUTE_STACK], 1,
  316. [Define to 1 if GCC generates calls to __enable_execute_stack()])
  317. AC_MSG_RESULT([yes])
  318. else
  319. AC_MSG_RESULT([no])
  320. fi
  321. rm -f conftest*
  322. ])
  323. dnl Check if the C compiler supports `-fstack-protector'.
  324. AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
  325. [# Smashing stack protector.
  326. ssp_possible=yes]
  327. AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
  328. # Is this a reliable test case?
  329. AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
  330. [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
  331. # `ac_compile' like this correct, after all?
  332. if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
  333. AC_MSG_RESULT([yes])
  334. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  335. rm -f conftest.s
  336. else
  337. ssp_possible=no]
  338. AC_MSG_RESULT([no])
  339. [fi]
  340. ])
  341. dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
  342. AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
  343. [# Smashing stack arg probe.
  344. sap_possible=yes]
  345. AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
  346. AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
  347. [if eval "$ac_compile -S -mstack-arg-probe -o conftest.s" 2> /dev/null; then]
  348. AC_MSG_RESULT([yes])
  349. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  350. rm -f conftest.s
  351. else
  352. sap_possible=no]
  353. AC_MSG_RESULT([no])
  354. [fi]
  355. ])
  356. dnl Check if ln can handle directories properly (mingw).
  357. AC_DEFUN([grub_CHECK_LINK_DIR],[
  358. AC_MSG_CHECKING([whether ln can handle directories properly])
  359. [mkdir testdir 2>/dev/null
  360. case $srcdir in
  361. [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
  362. *) reldir=../$srcdir/include/grub/util ;;
  363. esac
  364. if ln -s $reldir testdir/util 2>/dev/null ; then]
  365. AC_MSG_RESULT([yes])
  366. [link_dir=yes
  367. else
  368. link_dir=no]
  369. AC_MSG_RESULT([no])
  370. [fi
  371. rm -rf testdir]
  372. ])
  373. dnl Check if the C compiler supports `-fPIE'.
  374. AC_DEFUN([grub_CHECK_PIE],[
  375. [# Position independent executable.
  376. pie_possible=yes]
  377. AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
  378. # Is this a reliable test case?
  379. AC_LANG_CONFTEST([[
  380. #ifdef __PIE__
  381. int main() {
  382. return 0;
  383. }
  384. #else
  385. #error NO __PIE__ DEFINED
  386. #endif
  387. ]])
  388. [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
  389. # `ac_compile' like this correct, after all?
  390. if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
  391. AC_MSG_RESULT([yes])
  392. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  393. rm -f conftest.s
  394. else
  395. pie_possible=no]
  396. AC_MSG_RESULT([no])
  397. [fi]
  398. ])
  399. dnl Check if --defsym is supported
  400. AC_DEFUN([grub_PROG_LD_DEFSYM],
  401. [AC_MSG_CHECKING([whether linker accepts --defsym])
  402. AC_CACHE_VAL(grub_cv_prog_ld_defsym,
  403. [save_LDFLAGS="$LDFLAGS"
  404. LDFLAGS="$LDFLAGS -Wl,--defsym,__main=0x8100"
  405. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
  406. [grub_cv_prog_ld_defsym=yes],
  407. [grub_cv_prog_ld_defsym=no])
  408. LDFLAGS="$save_LDFLAGS"
  409. ])
  410. AC_MSG_RESULT([$grub_cv_prog_ld_defsym])
  411. ])
  412. dnl Check if returns_twice attribute is supported
  413. AC_DEFUN([grub_CHECK_RETURNS_TWICE],
  414. [AC_REQUIRE([AC_PROG_CC])
  415. AC_MSG_CHECKING([if returns_twice attribute is supported])
  416. AC_CACHE_VAL(grub_cv_returns_twice,
  417. [cat > conftest.c <<\EOF
  418. int func (void) __attribute__ ((return_twice));
  419. int
  420. func (void)
  421. {
  422. return 0;
  423. }
  424. EOF
  425. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c -Werror conftest.c]) ; then
  426. grub_cv_returns_twice=yes
  427. else
  428. grub_cv_returns_twice=no
  429. fi
  430. rm -f conftest*])
  431. if test "x$grub_cv_returns_twice" = xyes; then
  432. AC_DEFINE_UNQUOTED([HAVE_RETURNS_TWICE], $grub_cv_returns_twice,
  433. [Define if returns_twice attribute is supported])
  434. fi
  435. AC_MSG_RESULT([$grub_cv_returns_twice])
  436. ])