xref: /netbsd-src/external/gpl3/gdb/dist/sim/m4/sim_ac_toolchain.m4 (revision 32d1c65c71fbdb65a012e8392a62a757dd6853e9)
1dnl Copyright (C) 1997-2024 Free Software Foundation, Inc.
2dnl
3dnl This program is free software; you can redistribute it and/or modify
4dnl it under the terms of the GNU General Public License as published by
5dnl the Free Software Foundation; either version 3 of the License, or
6dnl (at your option) any later version.
7dnl
8dnl This program is distributed in the hope that it will be useful,
9dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11dnl GNU General Public License for more details.
12dnl
13dnl You should have received a copy of the GNU General Public License
14dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
15dnl
16dnl Setup the toolchain variables.
17AC_DEFUN([SIM_AC_TOOLCHAIN],
18[dnl
19AC_CANONICAL_SYSTEM
20AC_REQUIRE([AC_PROG_CC])
21AC_REQUIRE([AC_PROG_CPP])
22AC_C_BIGENDIAN
23AC_ARG_PROGRAM
24AC_PROG_INSTALL
25
26AC_CHECK_TOOL(DTC, dtc)
27
28dnl Setup toolchain settings for build-time tools..
29if test "x$cross_compiling" = "xno"; then
30  : "${AR_FOR_BUILD:=\$(AR)}"
31  : "${CC_FOR_BUILD:=\$(CC)}"
32  : "${RANLIB_FOR_BUILD:=\$(RANLIB)}"
33  : "${CFLAGS_FOR_BUILD:=\$(CFLAGS)}"
34  : "${CPPFLAGS_FOR_BUILD:=\$(CPPFLAGS)}"
35  : "${LDFLAGS_FOR_BUILD:=\$(LDFLAGS)}"
36else
37  : "${AR_FOR_BUILD:=ar}"
38  : "${CC_FOR_BUILD:=gcc}"
39  : "${RANLIB_FOR_BUILD:=ranlib}"
40  : "${CFLAGS_FOR_BUILD:=-g -O}"
41  : "${CPPFLAGS_FOR_BUILD:=}"
42  : "${LDLFAGS_FOR_BUILD:=}"
43fi
44AC_SUBST(AR_FOR_BUILD)
45AC_SUBST(CC_FOR_BUILD)
46AC_SUBST(RANLIB_FOR_BUILD)
47AC_SUBST(CFLAGS_FOR_BUILD)
48AC_SUBST(CPPFLAGS_FOR_BUILD)
49AC_SUBST(LDFLAGS_FOR_BUILD)
50
51AC_SUBST(CFLAGS)
52AC_CHECK_TOOL(AR, ar)
53AC_PROG_RANLIB
54PKG_PROG_PKG_CONFIG
55
56# Require C11 or newer.  Autoconf-2.70 provides ac_cv_prog_cc_c11 when using
57# AC_PROG_CC, but we're still using Autoconf-2.69, and the newest it understands
58# is C99.  So handle it ourselves.
59m4_version_prereq([2.70], [AC_MSG_ERROR([clean this up!])], [:])
60C_DIALECT=
61AC_MSG_CHECKING([whether C11 is supported by default])
62AC_COMPILE_IFELSE([AC_LANG_SOURCE([
63#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
64# error "C11 support not found"
65#endif
66])], [AC_MSG_RESULT([yes])], [
67  AC_MSG_RESULT([no])
68  AC_MSG_CHECKING([for -std=c11 support])
69  ac_save_CC="$CC"
70  CC="$CC -std=c11"
71  AC_COMPILE_IFELSE([AC_LANG_SOURCE([
72#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
73# error "C11 support not found"
74#endif
75])], [
76  AC_MSG_RESULT([yes])
77  CC="$ac_save_CC"
78  C_DIALECT="-std=c11"
79], [AC_MSG_ERROR([C11 is required])])])
80AC_SUBST(C_DIALECT)
81])
82dnl
83
84AC_DEFUN([SIM_AC_CHECK_TOOLCHAIN_FOR_PRIMARY_TARGET],
85[dnl
86GCC_TARGET_TOOL([cc], [CC_FOR_TARGET], [CC], [${target_alias}-gcc])
87GCC_TARGET_TOOL([as], [AS_FOR_TARGET], [AS], [\$(abs_builddir)/../gas/as-new])
88GCC_TARGET_TOOL([ld], [LD_FOR_TARGET], [LD], [\$(abs_builddir)/../ld/ld-new])
89])
90
91SIM_TOOLCHAIN_VARS=
92AC_SUBST(SIM_TOOLCHAIN_VARS)
93AC_DEFUN([_SIM_AC_TOOLCHAIN_FOR_TARGET],
94[dnl
95AC_REQUIRE([SIM_AC_CHECK_TOOLCHAIN_FOR_PRIMARY_TARGET])
96AC_ARG_VAR(AS_FOR_TARGET_$2, [Assembler for $1 tests])
97AC_ARG_VAR(LD_FOR_TARGET_$2, [Linker for $1 tests])
98AC_ARG_VAR(CC_FOR_TARGET_$2, [C compiler for $1 tests])
99m4_bmatch($1, [example-], [dnl
100  : "${AS_FOR_TARGET_$2:=\$(AS_FOR_TARGET)}"
101  : "${LD_FOR_TARGET_$2:=\$(LD_FOR_TARGET)}"
102  : "${CC_FOR_TARGET_$2:=\$(CC)}"
103], [dnl
104  AS_IF([test "$SIM_PRIMARY_TARGET" = "$1"], [dnl
105    : "${AS_FOR_TARGET_$2:=\$(AS_FOR_TARGET)}"
106    : "${LD_FOR_TARGET_$2:=\$(LD_FOR_TARGET)}"
107    : "${CC_FOR_TARGET_$2:=\$(CC_FOR_TARGET)}"
108  ])
109])
110AS_VAR_APPEND([SIM_TOOLCHAIN_VARS], [" AS_FOR_TARGET_$2 LD_FOR_TARGET_$2 CC_FOR_TARGET_$2"])
111])
112AC_DEFUN([SIM_AC_TOOLCHAIN_FOR_TARGET],
113[_SIM_AC_TOOLCHAIN_FOR_TARGET($1, m4_toupper(m4_translit($1, [-], [_])))])
114