diffseq: port to GCC 14.2.1 in ‘patch’
[gnulib.git] / m4 / asm-underscore.m4
blob66bb78f99b341750973a99f0f0a734beae7a654d
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.
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])
23   AC_CACHE_CHECK(
24     [whether C symbols are prefixed with underscore at the linker level],
25     [gl_cv_prog_as_underscore],
26     [cat > conftest.c <<EOF
27 #ifdef __cplusplus
28 extern "C" int foo (void);
29 #endif
30 int foo(void) { return 0; }
31 EOF
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
36      else
37        gl_cv_prog_as_underscore=no
38      fi
39      rm -f conftest*
40     ])
41   if test $gl_cv_prog_as_underscore = yes; then
42     USER_LABEL_PREFIX=_
43   else
44     USER_LABEL_PREFIX=
45   fi
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])
53 # gl_C_ASM
54 # Determines how to produce an assembly language file from C source code.
55 # Sets the variables:
56 #   gl_asmext - the extension of assembly language output,
57 #   gl_c_asm_opt - the C compiler option that produces assembly language output.
59 AC_DEFUN([gl_C_ASM],
61   AC_EGREP_CPP([MicrosoftCompiler],
62     [
63 #ifdef _MSC_VER
64 MicrosoftCompiler
65 #endif
66     ],
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'.
69      rm -f conftest*
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
73        gl_asmext='s'
74        gl_c_asm_opt='-S'
75      else
76        gl_asmext='asm'
77        gl_c_asm_opt='-c -Fa'
78      fi
79      rm -f conftest*
80     ],
81     [gl_asmext='s'
82      gl_c_asm_opt='-S'
83     ])