| 1 |
# asm-underscore.m4 |
| 2 |
# serial 5 |
| 3 |
dnl Copyright (C) 2010-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp. |
| 10 |
|
| 11 |
# gl_ASM_SYMBOL_PREFIX |
| 12 |
# Tests for the prefix of C symbols at the assembly language level and the |
| 13 |
# linker level. This prefix is either an underscore or empty. Defines the |
| 14 |
# C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to |
| 15 |
# a stringified variant of this prefix. |
| 16 |
|
| 17 |
AC_DEFUN([gl_ASM_SYMBOL_PREFIX], |
| 18 |
[ |
| 19 |
AC_REQUIRE([AC_PROG_EGREP]) |
| 20 |
dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because |
| 21 |
dnl 1. It works only for GCC. |
| 22 |
dnl 2. It is incorrectly defined on some platforms, in some GCC versions. |
| 23 |
AC_REQUIRE([gl_C_ASM]) |
| 24 |
AC_CACHE_CHECK( |
| 25 |
[whether C symbols are prefixed with underscore at the linker level], |
| 26 |
[gl_cv_prog_as_underscore], |
| 27 |
[cat > conftest.c <<EOF |
| 28 |
#ifdef __cplusplus |
| 29 |
extern "C" int foo (void); |
| 30 |
#endif |
| 31 |
int foo(void) { return 0; } |
| 32 |
EOF |
| 33 |
# Look for the assembly language name in the .s file. |
| 34 |
AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1 |
| 35 |
if LC_ALL=C $EGREP '(^|[[^a-zA-Z0-9_]])_foo([[^a-zA-Z0-9_]]|$)' conftest.$gl_asmext >/dev/null; then |
| 36 |
gl_cv_prog_as_underscore=yes |
| 37 |
else |
| 38 |
gl_cv_prog_as_underscore=no |
| 39 |
fi |
| 40 |
rm -f conftest* |
| 41 |
]) |
| 42 |
if test $gl_cv_prog_as_underscore = yes; then |
| 43 |
USER_LABEL_PREFIX=_ |
| 44 |
else |
| 45 |
USER_LABEL_PREFIX= |
| 46 |
fi |
| 47 |
AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX], |
| 48 |
[Define to the prefix of C symbols at the assembler and linker level, |
| 49 |
either an underscore or empty.]) |
| 50 |
ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"' |
| 51 |
AC_SUBST([ASM_SYMBOL_PREFIX]) |
| 52 |
]) |
| 53 |
|
| 54 |
# gl_C_ASM |
| 55 |
# Determines how to produce an assembly language file from C source code. |
| 56 |
# Sets the variables: |
| 57 |
# gl_asmext - the extension of assembly language output, |
| 58 |
# gl_c_asm_opt - the C compiler option that produces assembly language output. |
| 59 |
|
| 60 |
AC_DEFUN([gl_C_ASM], |
| 61 |
[ |
| 62 |
AC_EGREP_CPP([MicrosoftCompiler], |
| 63 |
[ |
| 64 |
#ifdef _MSC_VER |
| 65 |
MicrosoftCompiler |
| 66 |
#endif |
| 67 |
], |
| 68 |
[dnl Microsoft's 'cl' and 'clang-cl' produce an .asm file, whereas 'clang' |
| 69 |
dnl produces a .s file. Need to distinguish 'clang' and 'clang-cl'. |
| 70 |
rm -f conftest* |
| 71 |
echo 'int dummy;' > conftest.c |
| 72 |
AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c) >/dev/null 2>&1 |
| 73 |
if test -f conftest.o; then |
| 74 |
gl_asmext='s' |
| 75 |
gl_c_asm_opt='-S' |
| 76 |
else |
| 77 |
gl_asmext='asm' |
| 78 |
gl_c_asm_opt='-c -Fa' |
| 79 |
fi |
| 80 |
rm -f conftest* |
| 81 |
], |
| 82 |
[gl_asmext='s' |
| 83 |
gl_c_asm_opt='-S' |
| 84 |
]) |
| 85 |
]) |