acinclude.m4 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. dnl grub_ASM_USCORE checks if C symbols get an underscore after
  2. dnl compiling to assembler.
  3. dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
  4. dnl Erich Boleyn and modified by OKUJI Yoshinori
  5. AC_DEFUN([grub_ASM_USCORE],
  6. [AC_REQUIRE([AC_PROG_CC])
  7. AC_MSG_CHECKING([if C symbols get an underscore after compilation])
  8. AC_CACHE_VAL(grub_cv_asm_uscore,
  9. [cat > conftest.c <<\EOF
  10. int
  11. func (int *list)
  12. {
  13. *list = 0;
  14. return *list;
  15. }
  16. EOF
  17. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
  18. true
  19. else
  20. AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
  21. fi
  22. if grep _func conftest.s >/dev/null 2>&1; then
  23. grub_cv_asm_uscore=yes
  24. else
  25. grub_cv_asm_uscore=no
  26. fi
  27. rm -f conftest*])
  28. if test "x$grub_cv_asm_uscore" = xyes; then
  29. AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
  30. [Define if C symbols get an underscore after compilation])
  31. fi
  32. AC_MSG_RESULT([$grub_cv_asm_uscore])
  33. ])
  34. dnl Some versions of `objcopy -O binary' vary their output depending
  35. dnl on the link address.
  36. AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
  37. [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
  38. AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
  39. [cat > conftest.c <<\EOF
  40. void
  41. cmain (void)
  42. {
  43. *((int *) 0x1000) = 2;
  44. }
  45. EOF
  46. if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
  47. else
  48. AC_MSG_ERROR([${CC-cc} cannot compile C source code])
  49. fi
  50. grub_cv_prog_objcopy_absolute=yes
  51. for link_addr in 2000 8000 7C00; do
  52. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
  53. else
  54. AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
  55. fi
  56. if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then :
  57. else
  58. AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
  59. fi
  60. if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
  61. mv -f conftest conftest.old
  62. else
  63. grub_cv_prog_objcopy_absolute=no
  64. break
  65. fi
  66. done
  67. rm -f conftest*])
  68. AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])])
  69. dnl Mass confusion!
  70. dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
  71. dnl instructions, but implicitly insert addr32 and data32 bytes so
  72. dnl that the code works in real mode''.
  73. dnl
  74. dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
  75. dnl instructions,'' which seems right. This requires the programmer
  76. dnl to explicitly insert addr32 and data32 instructions when they want
  77. dnl them.
  78. dnl
  79. dnl We only support the newer versions, because the old versions cause
  80. dnl major pain, by requiring manual assembly to get 16-bit instructions into
  81. dnl stage1/stage1.S.
  82. AC_DEFUN([grub_ASM_ADDR32],
  83. [AC_REQUIRE([AC_PROG_CC])
  84. AC_REQUIRE([grub_ASM_PREFIX_REQUIREMENT])
  85. AC_MSG_CHECKING([for .code16 addr32 assembler support])
  86. AC_CACHE_VAL(grub_cv_asm_addr32,
  87. [cat > conftest.s.in <<\EOF
  88. .code16
  89. l1: @ADDR32@ movb %al, l1
  90. EOF
  91. if test "x$grub_cv_asm_prefix_requirement" = xyes; then
  92. sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
  93. else
  94. sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
  95. fi
  96. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  97. grub_cv_asm_addr32=yes
  98. else
  99. grub_cv_asm_addr32=no
  100. fi
  101. rm -f conftest*])
  102. AC_MSG_RESULT([$grub_cv_asm_addr32])])
  103. dnl
  104. dnl Later versions of GAS requires that addr32 and data32 prefixes
  105. dnl appear in the same lines as the instructions they modify, while
  106. dnl earlier versions requires that they appear in separate lines.
  107. AC_DEFUN([grub_ASM_PREFIX_REQUIREMENT],
  108. [AC_REQUIRE([AC_PROG_CC])
  109. AC_MSG_CHECKING(dnl
  110. [whether addr32 must be in the same line as the instruction])
  111. AC_CACHE_VAL(grub_cv_asm_prefix_requirement,
  112. [cat > conftest.s <<\EOF
  113. .code16
  114. l1: addr32 movb %al, l1
  115. EOF
  116. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  117. grub_cv_asm_prefix_requirement=yes
  118. else
  119. grub_cv_asm_prefix_requirement=no
  120. fi
  121. rm -f conftest*])
  122. if test "x$grub_cv_asm_prefix_requirement" = xyes; then
  123. grub_tmp_addr32="addr32"
  124. grub_tmp_data32="data32"
  125. else
  126. grub_tmp_addr32="addr32;"
  127. grub_tmp_data32="data32;"
  128. fi
  129. AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
  130. [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
  131. AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
  132. [Define it to \"data32\" or \"data32;\" to make GAS happy])
  133. AC_MSG_RESULT([$grub_cv_asm_prefix_requirement])])
  134. dnl
  135. dnl Older versions of GAS require that absolute indirect calls/jumps are
  136. dnl not prefixed with `*', while later versions warn if not prefixed.
  137. AC_DEFUN([grub_ASM_ABSOLUTE_WITHOUT_ASTERISK],
  138. [AC_REQUIRE([AC_PROG_CC])
  139. AC_MSG_CHECKING(dnl
  140. [whether an absolute indirect call/jump must not be prefixed with an asterisk])
  141. AC_CACHE_VAL(grub_cv_asm_absolute_without_asterisk,
  142. [cat > conftest.s <<\EOF
  143. lcall *(offset)
  144. offset:
  145. .long 0
  146. .word 0
  147. EOF
  148. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
  149. grub_cv_asm_absolute_without_asterisk=no
  150. else
  151. grub_cv_asm_absolute_without_asterisk=yes
  152. fi
  153. rm -f conftest*])
  154. if test "x$grub_cv_asm_absolute_without_asterisk" = xyes; then
  155. AC_DEFINE(ABSOLUTE_WITHOUT_ASTERISK, 1, [Define if an absolute indirect call/jump must NOT be prefixed with `*'])
  156. fi
  157. AC_MSG_RESULT([$grub_cv_asm_absolute_without_asterisk])])
  158. dnl
  159. dnl grub_CHECK_START_SYMBOL checks if start is automatically defined by
  160. dnl the compiler.
  161. dnl Written by OKUJI Yoshinori
  162. AC_DEFUN([grub_CHECK_START_SYMBOL],
  163. [AC_REQUIRE([AC_PROG_CC])
  164. AC_MSG_CHECKING([if start is defined by the compiler])
  165. AC_CACHE_VAL(grub_cv_check_start_symbol,
  166. [AC_TRY_LINK([], [asm ("incl start")],
  167. grub_cv_check_start_symbol=yes,
  168. grub_cv_check_start_symbol=no)])
  169. if test "x$grub_cv_check_start_symbol" = xyes; then
  170. AC_DEFINE(HAVE_START_SYMBOL, 1, [Define if start is defined])
  171. fi
  172. AC_MSG_RESULT([$grub_cv_check_start_symbol])
  173. ])
  174. dnl
  175. dnl grub_CHECK_USCORE_START_SYMBOL checks if _start is automatically
  176. dnl defined by the compiler.
  177. dnl Written by OKUJI Yoshinori
  178. AC_DEFUN([grub_CHECK_USCORE_START_SYMBOL],
  179. [AC_REQUIRE([AC_PROG_CC])
  180. AC_MSG_CHECKING([if _start is defined by the compiler])
  181. AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
  182. [AC_TRY_LINK([], [asm ("incl _start")],
  183. grub_cv_check_uscore_start_symbol=yes,
  184. grub_cv_check_uscore_start_symbol=no)])
  185. if test "x$grub_cv_check_uscore_start_symbol" = xyes; then
  186. AC_DEFINE(HAVE_USCORE_START_SYMBOL, 1, [Define if _start is defined])
  187. fi
  188. AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
  189. ])
  190. dnl
  191. dnl grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL checks if __bss_start is
  192. dnl automatically defined by the compiler.
  193. dnl Written by Michael Hohmoth.
  194. AC_DEFUN([grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL],
  195. [AC_REQUIRE([AC_PROG_CC])
  196. AC_MSG_CHECKING([if __bss_start is defined by the compiler])
  197. AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
  198. [AC_TRY_LINK([], [asm ("incl __bss_start")],
  199. grub_cv_check_uscore_uscore_bss_start_symbol=yes,
  200. grub_cv_check_uscore_uscore_bss_start_symbol=no)])
  201. if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
  202. AC_DEFINE(HAVE_USCORE_USCORE_BSS_START_SYMBOL, 1, [Define if __bss_start is defined])
  203. fi
  204. AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
  205. ])
  206. dnl
  207. dnl grub_CHECK_EDATA_SYMBOL checks if edata is automatically defined by the
  208. dnl compiler.
  209. dnl Written by Michael Hohmuth.
  210. AC_DEFUN([grub_CHECK_EDATA_SYMBOL],
  211. [AC_REQUIRE([AC_PROG_CC])
  212. AC_MSG_CHECKING([if edata is defined by the compiler])
  213. AC_CACHE_VAL(grub_cv_check_edata_symbol,
  214. [AC_TRY_LINK([], [asm ("incl edata")],
  215. grub_cv_check_edata_symbol=yes,
  216. grub_cv_check_edata_symbol=no)])
  217. if test "x$grub_cv_check_edata_symbol" = xyes; then
  218. AC_DEFINE(HAVE_EDATA_SYMBOL, 1, [Define if edata is defined])
  219. fi
  220. AC_MSG_RESULT([$grub_cv_check_edata_symbol])
  221. ])
  222. dnl
  223. dnl grub_CHECK_USCORE_EDATA_SYMBOL checks if _edata is automatically
  224. dnl defined by the compiler.
  225. dnl Written by Michael Hohmuth.
  226. AC_DEFUN([grub_CHECK_USCORE_EDATA_SYMBOL],
  227. [AC_REQUIRE([AC_PROG_CC])
  228. AC_MSG_CHECKING([if _edata is defined by the compiler])
  229. AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
  230. [AC_TRY_LINK([], [asm ("incl _edata")],
  231. grub_cv_check_uscore_edata_symbol=yes,
  232. grub_cv_check_uscore_edata_symbol=no)])
  233. if test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
  234. AC_DEFINE(HAVE_USCORE_EDATA_SYMBOL, 1, [Define if _edata is defined])
  235. fi
  236. AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
  237. ])
  238. dnl
  239. dnl grub_CHECK_END_SYMBOL checks if end is automatically defined by the
  240. dnl compiler.
  241. dnl Written by OKUJI Yoshinori
  242. AC_DEFUN([grub_CHECK_END_SYMBOL],
  243. [AC_REQUIRE([AC_PROG_CC])
  244. AC_MSG_CHECKING([if end is defined by the compiler])
  245. AC_CACHE_VAL(grub_cv_check_end_symbol,
  246. [AC_TRY_LINK([], [asm ("incl end")],
  247. grub_cv_check_end_symbol=yes,
  248. grub_cv_check_end_symbol=no)])
  249. if test "x$grub_cv_check_end_symbol" = xyes; then
  250. AC_DEFINE(HAVE_END_SYMBOL, 1, [Define if end is defined])
  251. fi
  252. AC_MSG_RESULT([$grub_cv_check_end_symbol])
  253. ])
  254. dnl
  255. dnl grub_CHECK_USCORE_END_SYMBOL checks if _end is automatically defined
  256. dnl by the compiler.
  257. dnl Written by OKUJI Yoshinori
  258. AC_DEFUN([grub_CHECK_USCORE_END_SYMBOL],
  259. [AC_REQUIRE([AC_PROG_CC])
  260. AC_MSG_CHECKING([if _end is defined by the compiler])
  261. AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
  262. [AC_TRY_LINK([], [asm ("incl _end")],
  263. grub_cv_check_uscore_end_symbol=yes,
  264. grub_cv_check_uscore_end_symbol=no)])
  265. if test "x$grub_cv_check_uscore_end_symbol" = xyes; then
  266. AC_DEFINE(HAVE_USCORE_END_SYMBOL, 1, [Define if end is defined])
  267. fi
  268. AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
  269. ])
  270. dnl grub_DEFINE_FILE(MACRO_NAME, FILE_NAME, DESCRIPTION)
  271. dnl grub_DEFINE_FILE defines a macro as the contents of a file safely.
  272. dnl Replace some escape sequences, because autoconf doesn't handle them
  273. dnl gracefully.
  274. dnl Written by OKUJI Yoshinori.
  275. AC_DEFUN([grub_DEFINE_FILE],
  276. [AC_REQUIRE([AC_PROG_CC])
  277. # Because early versions of GNU sed 3.x are too buggy, use a C program
  278. # instead of shell commands. *sigh*
  279. cat >conftest.c <<\EOF
  280. #include <stdio.h>
  281. int
  282. main (void)
  283. {
  284. int c;
  285. while ((c = getchar ()) != EOF)
  286. {
  287. switch (c)
  288. {
  289. case '\n':
  290. fputs ("\\n", stdout);
  291. break;
  292. case '\r':
  293. fputs ("\\r", stdout);
  294. break;
  295. case '\\':
  296. fputs ("\\\\", stdout);
  297. break;
  298. case '"':
  299. fputs ("\\\"", stdout);
  300. break;
  301. default:
  302. putchar (c);
  303. }
  304. }
  305. return 0;
  306. }
  307. EOF
  308. if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} conftest.c -o conftest]) && test -s conftest; then
  309. grub_tmp_value=`./conftest < "[$2]"`
  310. else
  311. AC_MSG_ERROR([${CC-cc} failed to produce an executable file])
  312. fi
  313. AC_DEFINE_UNQUOTED([$1], "$grub_tmp_value", [$3])
  314. rm -f conftest*
  315. ])