acinclude.m4 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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} ${CFLAGS} -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 Mass confusion!
  190. dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
  191. dnl instructions, but implicitly insert addr32 and data32 bytes so
  192. dnl that the code works in real mode''.
  193. dnl
  194. dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
  195. dnl instructions,'' which seems right. This requires the programmer
  196. dnl to explicitly insert addr32 and data32 instructions when they want
  197. dnl them.
  198. dnl
  199. dnl We only support the newer versions, because the old versions cause
  200. dnl major pain, by requiring manual assembly to get 16-bit instructions into
  201. dnl asm files.
  202. AC_DEFUN([grub_I386_ASM_ADDR32],
  203. [AC_REQUIRE([AC_PROG_CC])
  204. AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
  205. AC_MSG_CHECKING([for .code16 addr32 assembler support])
  206. AC_CACHE_VAL(grub_cv_i386_asm_addr32,
  207. [cat > conftest.s.in <<\EOF
  208. .code16
  209. l1: @ADDR32@ movb %al, l1
  210. EOF
  211. if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
  212. sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
  213. else
  214. sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
  215. fi
  216. if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  217. grub_cv_i386_asm_addr32=yes
  218. else
  219. grub_cv_i386_asm_addr32=no
  220. fi
  221. rm -f conftest*])
  222. AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
  223. dnl Later versions of GAS requires that addr32 and data32 prefixes
  224. dnl appear in the same lines as the instructions they modify, while
  225. dnl earlier versions requires that they appear in separate lines.
  226. AC_DEFUN([grub_I386_ASM_PREFIX_REQUIREMENT],
  227. [AC_REQUIRE([AC_PROG_CC])
  228. AC_MSG_CHECKING(dnl
  229. [whether addr32 must be in the same line as the instruction])
  230. AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
  231. [cat > conftest.s <<\EOF
  232. .code16
  233. l1: addr32 movb %al, l1
  234. EOF
  235. if AC_TRY_COMMAND([${CC-cc} ${TARGET_CCASFLAGS} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  236. grub_cv_i386_asm_prefix_requirement=yes
  237. else
  238. grub_cv_i386_asm_prefix_requirement=no
  239. fi
  240. rm -f conftest*])
  241. if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
  242. grub_tmp_addr32="addr32"
  243. grub_tmp_data32="data32"
  244. else
  245. grub_tmp_addr32="addr32;"
  246. grub_tmp_data32="data32;"
  247. fi
  248. ADDR32=$grub_tmp_addr32
  249. DATA32=$grub_tmp_data32
  250. AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
  251. dnl Check what symbol is defined as a bss start symbol.
  252. dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
  253. AC_DEFUN([grub_CHECK_BSS_START_SYMBOL],
  254. [AC_REQUIRE([AC_PROG_CC])
  255. AC_MSG_CHECKING([if __bss_start is defined by the compiler])
  256. AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
  257. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  258. asm (".globl start; start:");
  259. void __main (void);
  260. void __main (void) {}
  261. int main (void);
  262. ]],
  263. [[asm ("incl __bss_start")]])],
  264. [grub_cv_check_uscore_uscore_bss_start_symbol=yes],
  265. [grub_cv_check_uscore_uscore_bss_start_symbol=no])])
  266. AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
  267. AC_MSG_CHECKING([if edata is defined by the compiler])
  268. AC_CACHE_VAL(grub_cv_check_edata_symbol,
  269. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  270. asm (".globl start; start:");
  271. void __main (void);
  272. void __main (void) {}
  273. int main (void);]],
  274. [[asm ("incl edata")]])],
  275. [grub_cv_check_edata_symbol=yes],
  276. [grub_cv_check_edata_symbol=no])])
  277. AC_MSG_RESULT([$grub_cv_check_edata_symbol])
  278. AC_MSG_CHECKING([if _edata is defined by the compiler])
  279. AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
  280. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  281. asm (".globl start; start:");
  282. void __main (void);
  283. void __main (void) {}
  284. int main (void);]],
  285. [[asm ("incl _edata")]])],
  286. [grub_cv_check_uscore_edata_symbol=yes],
  287. [grub_cv_check_uscore_edata_symbol=no])])
  288. AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
  289. if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
  290. BSS_START_SYMBOL=__bss_start
  291. elif test "x$grub_cv_check_edata_symbol" = xyes; then
  292. BSS_START_SYMBOL=edata
  293. elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
  294. BSS_START_SYMBOL=_edata
  295. else
  296. AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
  297. fi
  298. ])
  299. dnl Check what symbol is defined as an end symbol.
  300. dnl Written by Yoshinori K. Okuji.
  301. AC_DEFUN([grub_CHECK_END_SYMBOL],
  302. [AC_REQUIRE([AC_PROG_CC])
  303. AC_MSG_CHECKING([if end is defined by the compiler])
  304. AC_CACHE_VAL(grub_cv_check_end_symbol,
  305. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  306. asm (".globl start; start:");
  307. void __main (void);
  308. void __main (void) {}
  309. int main (void);]],
  310. [[asm ("incl end")]])],
  311. [grub_cv_check_end_symbol=yes],
  312. [grub_cv_check_end_symbol=no])])
  313. AC_MSG_RESULT([$grub_cv_check_end_symbol])
  314. AC_MSG_CHECKING([if _end is defined by the compiler])
  315. AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
  316. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  317. asm (".globl start; start:");
  318. void __main (void);
  319. void __main (void) {}
  320. int main (void);]],
  321. [[asm ("incl _end")]])],
  322. [grub_cv_check_uscore_end_symbol=yes],
  323. [grub_cv_check_uscore_end_symbol=no])])
  324. AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
  325. if test "x$grub_cv_check_end_symbol" = xyes; then
  326. END_SYMBOL=end
  327. elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
  328. END_SYMBOL=_end
  329. else
  330. AC_MSG_ERROR([neither end nor _end is defined])
  331. fi
  332. ])
  333. dnl Check if the C compiler supports `-fstack-protector'.
  334. AC_DEFUN([grub_CHECK_STACK_PROTECTOR],[
  335. [# Smashing stack protector.
  336. ssp_possible=yes]
  337. AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
  338. # Is this a reliable test case?
  339. AC_LANG_CONFTEST([AC_LANG_SOURCE([[
  340. void foo (void) { volatile char a[8]; a[3]; }
  341. ]])])
  342. [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
  343. # `ac_compile' like this correct, after all?
  344. if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
  345. AC_MSG_RESULT([yes])
  346. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  347. rm -f conftest.s
  348. else
  349. ssp_possible=no]
  350. AC_MSG_RESULT([no])
  351. [fi]
  352. ])
  353. dnl Check if the C compiler supports `-mstack-arg-probe' (Cygwin).
  354. AC_DEFUN([grub_CHECK_STACK_ARG_PROBE],[
  355. [# Smashing stack arg probe.
  356. sap_possible=yes]
  357. AC_MSG_CHECKING([whether `$CC' accepts `-mstack-arg-probe'])
  358. AC_LANG_CONFTEST([AC_LANG_SOURCE([[
  359. void foo (void) { volatile char a[8]; a[3]; }
  360. ]])])
  361. [if eval "$ac_compile -S -mstack-arg-probe -Werror -o conftest.s" 2> /dev/null; then]
  362. AC_MSG_RESULT([yes])
  363. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  364. rm -f conftest.s
  365. else
  366. sap_possible=no]
  367. AC_MSG_RESULT([no])
  368. [fi]
  369. ])
  370. dnl Check if ln -s can handle directories properly (mingw).
  371. AC_DEFUN([grub_CHECK_LINK_DIR],[
  372. AC_MSG_CHECKING([whether ln -s can handle directories properly])
  373. [mkdir testdir 2>/dev/null
  374. case $srcdir in
  375. [\\/$]* | ?:[\\/]* ) reldir=$srcdir/include/grub/util ;;
  376. *) reldir=../$srcdir/include/grub/util ;;
  377. esac
  378. if ln -s $reldir testdir/util 2>/dev/null && rm -f testdir/util 2>/dev/null ; then]
  379. AC_MSG_RESULT([yes])
  380. [link_dir=yes
  381. else
  382. link_dir=no]
  383. AC_MSG_RESULT([no])
  384. [fi
  385. rm -rf testdir]
  386. ])
  387. dnl Check if the C compiler supports `-fPIE'.
  388. AC_DEFUN([grub_CHECK_PIE],[
  389. [# Position independent executable.
  390. pie_possible=yes]
  391. AC_MSG_CHECKING([whether `$CC' has `-fPIE' as default])
  392. # Is this a reliable test case?
  393. AC_LANG_CONFTEST([AC_LANG_SOURCE([[
  394. #ifdef __PIE__
  395. int main() {
  396. return 0;
  397. }
  398. #else
  399. #error NO __PIE__ DEFINED
  400. #endif
  401. ]])])
  402. [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
  403. # `ac_compile' like this correct, after all?
  404. if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
  405. AC_MSG_RESULT([yes])
  406. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  407. rm -f conftest.s
  408. else
  409. pie_possible=no]
  410. AC_MSG_RESULT([no])
  411. [fi]
  412. ])
  413. dnl Check if the C compiler supports `-fPIC'.
  414. AC_DEFUN([grub_CHECK_PIC],[
  415. [# Position independent executable.
  416. pic_possible=yes]
  417. AC_MSG_CHECKING([whether `$CC' has `-fPIC' as default])
  418. # Is this a reliable test case?
  419. AC_LANG_CONFTEST([AC_LANG_SOURCE([[
  420. #ifdef __PIC__
  421. int main() {
  422. return 0;
  423. }
  424. #else
  425. #error NO __PIC__ DEFINED
  426. #endif
  427. ]])])
  428. [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
  429. # `ac_compile' like this correct, after all?
  430. if eval "$ac_compile -S -o conftest.s" 2> /dev/null; then]
  431. AC_MSG_RESULT([yes])
  432. [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?
  433. rm -f conftest.s
  434. else
  435. pic_possible=no]
  436. AC_MSG_RESULT([no])
  437. [fi]
  438. ])
  439. dnl Create an output variable with the transformed name of a GRUB utility
  440. dnl program.
  441. AC_DEFUN([grub_TRANSFORM],[dnl
  442. AC_SUBST(AS_TR_SH([$1]), [`AS_ECHO([$1]) | sed "$program_transform_name"`])dnl
  443. ])