acinclude.m4 13 KB

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