sim_ac_toolchain.m4 3.6 KB

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