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.
8 dnl From Bruno Haible. Based on as-underscore.m4 in GNU clisp.
10 # gl_ASM_SYMBOL_PREFIX
11 # Tests for the prefix of C symbols at the assembly language level and the
12 # linker level. This prefix is either an underscore or empty. Defines the
13 # C macro USER_LABEL_PREFIX to this prefix, and sets ASM_SYMBOL_PREFIX to
14 # a stringified variant of this prefix.
16 AC_DEFUN([gl_ASM_SYMBOL_PREFIX],
18 AC_REQUIRE([AC_PROG_EGREP])
19 dnl We don't use GCC's __USER_LABEL_PREFIX__ here, because
20 dnl 1. It works only for GCC.
21 dnl 2. It is incorrectly defined on some platforms, in some GCC versions.
22 AC_REQUIRE([gl_C_ASM])
24 [whether C symbols are prefixed with underscore at the linker level],
25 [gl_cv_prog_as_underscore],
26 [cat > conftest.c <<EOF
28 extern "C" int foo (void);
30 int foo(void) { return 0; }
32 # Look for the assembly language name in the .s file.
33 AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
34 if LC_ALL=C $EGREP '(^|[[^a-zA-Z0-9_]])_foo([[^a-zA-Z0-9_]]|$)' conftest.$gl_asmext >/dev/null; then
35 gl_cv_prog_as_underscore=yes
37 gl_cv_prog_as_underscore=no
41 if test $gl_cv_prog_as_underscore = yes; then
46 AC_DEFINE_UNQUOTED([USER_LABEL_PREFIX], [$USER_LABEL_PREFIX],
47 [Define to the prefix of C symbols at the assembler and linker level,
48 either an underscore or empty.])
49 ASM_SYMBOL_PREFIX='"'${USER_LABEL_PREFIX}'"'
50 AC_SUBST([ASM_SYMBOL_PREFIX])
54 # Determines how to produce an assembly language file from C source code.
56 # gl_asmext - the extension of assembly language output,
57 # gl_c_asm_opt - the C compiler option that produces assembly language output.
61 AC_EGREP_CPP([MicrosoftCompiler],
67 [dnl Microsoft's 'cl' and 'clang-cl' produce an .asm file, whereas 'clang'
68 dnl produces a .s file. Need to distinguish 'clang' and 'clang-cl'.
70 echo 'int dummy;' > conftest.c
71 AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c) >/dev/null 2>&1
72 if test -f conftest.o; then