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 18 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then 19 true 20 else 21 AC_MSG_ERROR([${CC-cc} failed to produce assembly code]) 22 fi 23 24 if grep _func conftest.s >/dev/null 2>&1; then 25 grub_cv_asm_uscore=yes 26 else 27 grub_cv_asm_uscore=no 28 fi 29 30 rm -f conftest*]) 31 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]) 35 fi 36 37 AC_MSG_RESULT([$grub_cv_asm_uscore]) 38 ]) 39 40 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 47 void 48 cmain (void) 49 { 50 *((int *) 0x1000) = 2; 51 } 52 EOF 53 54 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then : 55 else 56 AC_MSG_ERROR([${CC-cc} cannot compile C source code]) 57 fi 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 : 61 else 62 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr]) 63 fi 64 if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then : 65 else 66 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files]) 67 fi 68 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then 69 mv -f conftest conftest.old 70 else 71 grub_cv_prog_objcopy_absolute=no 72 break 73 fi 74 done 75 rm -f conftest*]) 76 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])]) 77 78 dnl Mass confusion! 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''. 82 dnl 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 86 dnl them. 87 dnl 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 90 dnl stage1/stage1.S. 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 97 .code16 98 l1: @ADDR32@ movb %al, l1 99 EOF 100 101 if test "x$grub_cv_asm_prefix_requirement" = xyes; then 102 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s 103 else 104 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s 105 fi 106 107 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then 108 grub_cv_asm_addr32=yes 109 else 110 grub_cv_asm_addr32=no 111 fi 112 113 rm -f conftest*]) 114 115 AC_MSG_RESULT([$grub_cv_asm_addr32])]) 116 117 dnl 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]) 123 AC_MSG_CHECKING(dnl 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 127 .code16 128 l1: addr32 movb %al, l1 129 EOF 130 131 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then 132 grub_cv_asm_prefix_requirement=yes 133 else 134 grub_cv_asm_prefix_requirement=no 135 fi 136 137 rm -f conftest*]) 138 139 if test "x$grub_cv_asm_prefix_requirement" = xyes; then 140 grub_tmp_addr32="addr32" 141 grub_tmp_data32="data32" 142 else 143 grub_tmp_addr32="addr32;" 144 grub_tmp_data32="data32;" 145 fi 146 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]) 151 152 AC_MSG_RESULT([$grub_cv_asm_prefix_requirement])]) 153 154 dnl 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]) 159 AC_MSG_CHECKING(dnl 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 163 lcall *(offset) 164 offset: 165 .long 0 166 .word 0 167 EOF 168 169 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then 170 grub_cv_asm_absolute_without_asterisk=no 171 else 172 grub_cv_asm_absolute_without_asterisk=yes 173 fi 174 175 rm -f conftest*]) 176 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 `*']) 179 fi 180 181 AC_MSG_RESULT([$grub_cv_asm_absolute_without_asterisk])]) 182 183 dnl 184 dnl grub_CHECK_START_SYMBOL checks if start is automatically defined by 185 dnl the compiler. 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)]) 194 195 if test "x$grub_cv_check_start_symbol" = xyes; then 196 AC_DEFINE(HAVE_START_SYMBOL, 1, [Define if start is defined]) 197 fi 198 199 AC_MSG_RESULT([$grub_cv_check_start_symbol]) 200 ]) 201 202 dnl 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)]) 213 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]) 216 fi 217 218 AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol]) 219 ]) 220 221 dnl 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)]) 232 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]) 235 fi 236 237 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol]) 238 ]) 239 240 dnl 241 dnl grub_CHECK_EDATA_SYMBOL checks if edata is automatically defined by the 242 dnl compiler. 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)]) 251 252 if test "x$grub_cv_check_edata_symbol" = xyes; then 253 AC_DEFINE(HAVE_EDATA_SYMBOL, 1, [Define if edata is defined]) 254 fi 255 256 AC_MSG_RESULT([$grub_cv_check_edata_symbol]) 257 ]) 258 259 dnl 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)]) 270 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]) 273 fi 274 275 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol]) 276 ]) 277 278 dnl 279 dnl grub_CHECK_END_SYMBOL checks if end is automatically defined by the 280 dnl compiler. 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)]) 289 290 if test "x$grub_cv_check_end_symbol" = xyes; then 291 AC_DEFINE(HAVE_END_SYMBOL, 1, [Define if end is defined]) 292 fi 293 294 AC_MSG_RESULT([$grub_cv_check_end_symbol]) 295 ]) 296 297 dnl 298 dnl grub_CHECK_USCORE_END_SYMBOL checks if _end is automatically defined 299 dnl by the compiler. 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)]) 308 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]) 311 fi 312 313 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol]) 314 ]) 315 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 319 dnl gracefully. 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 326 #include <stdio.h> 327 328 int 329 main (void) 330 { 331 int c; 332 333 while ((c = getchar ()) != EOF) 334 { 335 switch (c) 336 { 337 case '\n': 338 fputs ("\\n", stdout); 339 break; 340 case '\r': 341 fputs ("\\r", stdout); 342 break; 343 case '\\': 344 fputs ("\\\\", stdout); 345 break; 346 case '"': 347 fputs ("\\\"", stdout); 348 break; 349 default: 350 putchar (c); 351 } 352 } 353 354 return 0; 355 } 356 EOF 357 358 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} conftest.c -o conftest]) && test -s conftest; then 359 grub_tmp_value=`./conftest < "[$2]"` 360 else 361 AC_MSG_ERROR([${CC-cc} failed to produce an executable file]) 362 fi 363 364 AC_DEFINE_UNQUOTED([$1], "$grub_tmp_value", [$3]) 365 rm -f conftest* 366 ]) 367