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
18 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
21 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
24 if grep _func conftest.s >/dev/null 2>&1; then
25 grub_cv_asm_uscore=yes
32 if test "x$grub_cv_asm_uscore" = xyes; then
33 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
34 [Define if C symbols get an underscore after compilation])
37 AC_MSG_RESULT([$grub_cv_asm_uscore])
41 dnl Some versions of `objcopy -O binary' vary their output depending
42 dnl on the link address.
43 AC_DEFUN([grub_PROG_OBJCOPY_ABSOLUTE],
44 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
45 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
46 [cat > conftest.c <<\EOF
50 *((int *) 0x1000) = 2;
54 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
56 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
58 grub_cv_prog_objcopy_absolute=yes
59 for link_addr in 2000 8000 7C00; do
60 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
62 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
64 if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then :
66 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
68 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
69 mv -f conftest conftest.old
71 grub_cv_prog_objcopy_absolute=no
76 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])])
79 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
80 dnl instructions, but implicitly insert addr32 and data32 bytes so
81 dnl that the code works in real mode''.
83 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
84 dnl instructions,'' which seems right. This requires the programmer
85 dnl to explicitly insert addr32 and data32 instructions when they want
88 dnl We only support the newer versions, because the old versions cause
89 dnl major pain, by requiring manual assembly to get 16-bit instructions into
91 AC_DEFUN([grub_ASM_ADDR32],
92 [AC_REQUIRE([AC_PROG_CC])
93 AC_REQUIRE([grub_ASM_PREFIX_REQUIREMENT])
94 AC_MSG_CHECKING([for .code16 addr32 assembler support])
95 AC_CACHE_VAL(grub_cv_asm_addr32,
96 [cat > conftest.s.in <<\EOF
98 l1: @ADDR32@ movb %al, l1
101 if test "x$grub_cv_asm_prefix_requirement" = xyes; then
102 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
104 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
107 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
108 grub_cv_asm_addr32=yes
110 grub_cv_asm_addr32=no
115 AC_MSG_RESULT([$grub_cv_asm_addr32])])
118 dnl Later versions of GAS requires that addr32 and data32 prefixes
119 dnl appear in the same lines as the instructions they modify, while
120 dnl earlier versions requires that they appear in separate lines.
121 AC_DEFUN([grub_ASM_PREFIX_REQUIREMENT],
122 [AC_REQUIRE([AC_PROG_CC])
124 [whether addr32 must be in the same line as the instruction])
125 AC_CACHE_VAL(grub_cv_asm_prefix_requirement,
126 [cat > conftest.s <<\EOF
128 l1: addr32 movb %al, l1
131 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
132 grub_cv_asm_prefix_requirement=yes
134 grub_cv_asm_prefix_requirement=no
139 if test "x$grub_cv_asm_prefix_requirement" = xyes; then
140 grub_tmp_addr32="addr32"
141 grub_tmp_data32="data32"
143 grub_tmp_addr32="addr32;"
144 grub_tmp_data32="data32;"
147 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
148 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
149 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
150 [Define it to \"data32\" or \"data32;\" to make GAS happy])
152 AC_MSG_RESULT([$grub_cv_asm_prefix_requirement])])
155 dnl Older versions of GAS require that absolute indirect calls/jumps are
156 dnl not prefixed with `*', while later versions warn if not prefixed.
157 AC_DEFUN([grub_ASM_ABSOLUTE_WITHOUT_ASTERISK],
158 [AC_REQUIRE([AC_PROG_CC])
160 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
161 AC_CACHE_VAL(grub_cv_asm_absolute_without_asterisk,
162 [cat > conftest.s <<\EOF
169 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
170 grub_cv_asm_absolute_without_asterisk=no
172 grub_cv_asm_absolute_without_asterisk=yes
177 if test "x$grub_cv_asm_absolute_without_asterisk" = xyes; then
178 AC_DEFINE(ABSOLUTE_WITHOUT_ASTERISK, 1, [Define if an absolute indirect call/jump must NOT be prefixed with `*'])
181 AC_MSG_RESULT([$grub_cv_asm_absolute_without_asterisk])])
184 dnl grub_CHECK_START_SYMBOL checks if start is automatically defined by
186 dnl Written by OKUJI Yoshinori
187 AC_DEFUN([grub_CHECK_START_SYMBOL],
188 [AC_REQUIRE([AC_PROG_CC])
189 AC_MSG_CHECKING([if start is defined by the compiler])
190 AC_CACHE_VAL(grub_cv_check_start_symbol,
191 [AC_TRY_LINK([], [asm ("incl start")],
192 grub_cv_check_start_symbol=yes,
193 grub_cv_check_start_symbol=no)])
195 if test "x$grub_cv_check_start_symbol" = xyes; then
196 AC_DEFINE(HAVE_START_SYMBOL, 1, [Define if start is defined])
199 AC_MSG_RESULT([$grub_cv_check_start_symbol])
203 dnl grub_CHECK_USCORE_START_SYMBOL checks if _start is automatically
204 dnl defined by the compiler.
205 dnl Written by OKUJI Yoshinori
206 AC_DEFUN([grub_CHECK_USCORE_START_SYMBOL],
207 [AC_REQUIRE([AC_PROG_CC])
208 AC_MSG_CHECKING([if _start is defined by the compiler])
209 AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
210 [AC_TRY_LINK([], [asm ("incl _start")],
211 grub_cv_check_uscore_start_symbol=yes,
212 grub_cv_check_uscore_start_symbol=no)])
214 if test "x$grub_cv_check_uscore_start_symbol" = xyes; then
215 AC_DEFINE(HAVE_USCORE_START_SYMBOL, 1, [Define if _start is defined])
218 AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
222 dnl grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL checks if __bss_start is
223 dnl automatically defined by the compiler.
224 dnl Written by Michael Hohmoth.
225 AC_DEFUN([grub_CHECK_USCORE_USCORE_BSS_START_SYMBOL],
226 [AC_REQUIRE([AC_PROG_CC])
227 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
228 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
229 [AC_TRY_LINK([], [asm ("incl __bss_start")],
230 grub_cv_check_uscore_uscore_bss_start_symbol=yes,
231 grub_cv_check_uscore_uscore_bss_start_symbol=no)])
233 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
234 AC_DEFINE(HAVE_USCORE_USCORE_BSS_START_SYMBOL, 1, [Define if __bss_start is defined])
237 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
241 dnl grub_CHECK_EDATA_SYMBOL checks if edata is automatically defined by the
243 dnl Written by Michael Hohmuth.
244 AC_DEFUN([grub_CHECK_EDATA_SYMBOL],
245 [AC_REQUIRE([AC_PROG_CC])
246 AC_MSG_CHECKING([if edata is defined by the compiler])
247 AC_CACHE_VAL(grub_cv_check_edata_symbol,
248 [AC_TRY_LINK([], [asm ("incl edata")],
249 grub_cv_check_edata_symbol=yes,
250 grub_cv_check_edata_symbol=no)])
252 if test "x$grub_cv_check_edata_symbol" = xyes; then
253 AC_DEFINE(HAVE_EDATA_SYMBOL, 1, [Define if edata is defined])
256 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
260 dnl grub_CHECK_USCORE_EDATA_SYMBOL checks if _edata is automatically
261 dnl defined by the compiler.
262 dnl Written by Michael Hohmuth.
263 AC_DEFUN([grub_CHECK_USCORE_EDATA_SYMBOL],
264 [AC_REQUIRE([AC_PROG_CC])
265 AC_MSG_CHECKING([if _edata is defined by the compiler])
266 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
267 [AC_TRY_LINK([], [asm ("incl _edata")],
268 grub_cv_check_uscore_edata_symbol=yes,
269 grub_cv_check_uscore_edata_symbol=no)])
271 if test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
272 AC_DEFINE(HAVE_USCORE_EDATA_SYMBOL, 1, [Define if _edata is defined])
275 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
279 dnl grub_CHECK_END_SYMBOL checks if end is automatically defined by the
281 dnl Written by OKUJI Yoshinori
282 AC_DEFUN([grub_CHECK_END_SYMBOL],
283 [AC_REQUIRE([AC_PROG_CC])
284 AC_MSG_CHECKING([if end is defined by the compiler])
285 AC_CACHE_VAL(grub_cv_check_end_symbol,
286 [AC_TRY_LINK([], [asm ("incl end")],
287 grub_cv_check_end_symbol=yes,
288 grub_cv_check_end_symbol=no)])
290 if test "x$grub_cv_check_end_symbol" = xyes; then
291 AC_DEFINE(HAVE_END_SYMBOL, 1, [Define if end is defined])
294 AC_MSG_RESULT([$grub_cv_check_end_symbol])
298 dnl grub_CHECK_USCORE_END_SYMBOL checks if _end is automatically defined
300 dnl Written by OKUJI Yoshinori
301 AC_DEFUN([grub_CHECK_USCORE_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_uscore_end_symbol,
305 [AC_TRY_LINK([], [asm ("incl _end")],
306 grub_cv_check_uscore_end_symbol=yes,
307 grub_cv_check_uscore_end_symbol=no)])
309 if test "x$grub_cv_check_uscore_end_symbol" = xyes; then
310 AC_DEFINE(HAVE_USCORE_END_SYMBOL, 1, [Define if end is defined])
313 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
316 dnl grub_DEFINE_FILE(MACRO_NAME, FILE_NAME, DESCRIPTION)
317 dnl grub_DEFINE_FILE defines a macro as the contents of a file safely.
318 dnl Replace some escape sequences, because autoconf doesn't handle them
320 dnl Written by OKUJI Yoshinori.
321 AC_DEFUN([grub_DEFINE_FILE],
322 [AC_REQUIRE([AC_PROG_CC])
323 # Because early versions of GNU sed 3.x are too buggy, use a C program
324 # instead of shell commands. *sigh*
325 cat >conftest.c <<\EOF
333 while ((c = getchar ()) != EOF)
338 fputs ("\\n", stdout);
341 fputs ("\\r", stdout);
344 fputs ("\\\\", stdout);
347 fputs ("\\\"", stdout);
358 if AC_TRY_COMMAND([${CC_FOR_BUILD-cc} ${CFLAGS} conftest.c -o conftest]) && test -s conftest; then
359 grub_tmp_value=`./conftest < "[$2]"`
361 AC_MSG_ERROR([${CC-cc} failed to produce an executable file])
364 AC_DEFINE_UNQUOTED([$1], "$grub_tmp_value", [$3])