configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. # The name, version, and maintainer of this package
  2. AC_INIT([freedom-metal], [m4_esyscmd_s([./scripts/git-version])], [https://github.com/sifive/freedom-metal/issues], [freedom-metal], [https://github.com/sifive/freedom-metal])
  3. # Initializes automake, enabling maintainer mode by default (which should be
  4. # disabled by the archive generated by "make dist").
  5. AM_INIT_AUTOMAKE([foreign subdir-objects])
  6. AM_MAINTAINER_MODE([disable])
  7. AC_CONFIG_MACRO_DIRS([m4])
  8. # This library is actually an integral part of the toolchain build process on
  9. # METAL toolchains as it's necessary to link any program. To prevent this from
  10. # causing every autoconf test failing we instead place some weak symbols in
  11. # confdefs.h to trick the toolchain into linking.
  12. #
  13. #AC_CANONICAL_HOST -- for now don't canonicalize the host because the *-metal
  14. # tuples aren't upstream in config.*
  15. case "${host_alias}" in
  16. *-metal)
  17. AS_ECHO("long metal_segment_stack_end __attribute__((weak));") >> confdefs.h
  18. AS_ECHO("long metal_segment_data_source_start __attribute__((weak));") >> confdefs.h
  19. AS_ECHO("long metal_segment_data_source_end __attribute__((weak));") >> confdefs.h
  20. AS_ECHO("long metal_segment_data_target_start __attribute__((weak));") >> confdefs.h
  21. AS_ECHO("long metal_segment_data_target_end __attribute__((weak));") >> confdefs.h
  22. AS_ECHO("long metal_segment_bss_target_start __attribute__((weak));") >> confdefs.h
  23. AS_ECHO("long metal_segment_bss_target_end __attribute__((weak));") >> confdefs.h
  24. AS_ECHO("void metal_shutdown(void) __attribute__((weak)); void metal_shutdown(void) {}") >> confdefs.h
  25. ;;
  26. esac
  27. # Probe for tools that we need in order to build.
  28. AC_PROG_CC
  29. AC_PROG_RANLIB
  30. AM_PROG_AR
  31. AM_PROG_AS
  32. # autoconf tries very hard to avoid failing, so it'll even go ahead and try to
  33. # build the project using "gcc" if it can't find a suitable C compiler prefixed
  34. # by the host system. This doesn't work when cross compiling, but it's a
  35. # common error for users so we explicitly check for this right here to quickly
  36. # provide an error message.
  37. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[
  38. #ifndef __riscv
  39. # error "A RISC-V compiler is required to build the Freedom MBI"
  40. #endif
  41. ])], [], [AC_MSG_FAILURE([The C compiler doesn't define __riscv, which means it's probably not a RISC-V compiler. You should specify something like --host=riscv64-sifive-elf when building this, as it will only work on RISC-V systems.])])
  42. ########################################################
  43. # Generic Options
  44. ########################################################
  45. # Allows users to specify some device tree information.
  46. AC_ARG_WITH([machine-name],
  47. [AS_HELP_STRING([--with-machine-name=NAME], [Install this machine with a particular name])],
  48. [],
  49. [with_machine_name="no"]
  50. )
  51. AS_IF([test "x$with_machine_name" != "xno"],
  52. [AC_SUBST([MACHINE_NAME], "$with_machine_name")],
  53. [AC_MSG_FAILURE([--with-machine-name is required])]
  54. )
  55. AC_ARG_WITH([preconfigured],
  56. [AS_HELP_STRING([--with-preconfigured], [Use pre-configured machine support files instead of generating them during the build])],
  57. [with_preconfigured="yes"],
  58. [with_preconfigured="no"]
  59. )
  60. AC_ARG_WITH([builtin-libgloss],
  61. [AS_HELP_STRING([--with-bultin-libgloss], [Build libgloss along with the METAL])],
  62. [with_builtin_libgloss="yes"],
  63. [with_builtin_libgloss="no"]
  64. )
  65. AM_CONDITIONAL([WITH_BUILTIN_LIBGLOSS], [test "x$with_builtin_libgloss" = "xyes"])
  66. ########################################################
  67. # Preconfigured Options (--with-preconfigured)
  68. ########################################################
  69. AC_ARG_WITH([machine-header],
  70. [AS_HELP_STRING([--with-machine-header=PATH], [Path to the machine header file])],
  71. [],
  72. [with_machine_header="no"]
  73. )
  74. AC_ARG_WITH([machine-inline],
  75. [AS_HELP_STRING([--with-machine-inline=PATH], [Path to the machine inline file])],
  76. [],
  77. [with_machine_inline="no"]
  78. )
  79. AC_ARG_WITH([platform-header],
  80. [AS_HELP_STRING([--with-platform-header=PATH], [Path to the platform header file])],
  81. [],
  82. [with_platform_header="no"]
  83. )
  84. AC_ARG_WITH([machine-ldscript],
  85. [AS_HELP_STRING([--with-machine-ldscript=PATH], [Path to the machine ldscript])],
  86. [],
  87. [with_machine_ldscript="no"]
  88. )
  89. ########################################################
  90. # Configuration Options (--without-preconfigured)
  91. ########################################################
  92. AC_ARG_WITH([machine-dts],
  93. [AS_HELP_STRING([--with-machine-dts=PATH], [The full path to the device tree])],
  94. [],
  95. [with_machine_dts="no"]
  96. )
  97. # Allows users to specify a path to DTC
  98. AC_ARG_WITH([dtc],
  99. [AS_HELP_STRING([--with-dtc=PATH], [Use the given path to the device tree compiler])],
  100. [],
  101. [with_dtc=check]
  102. )
  103. AC_ARG_VAR(DTC, [The absolute path to dtc])
  104. # Allows users to specify a path to freedom-metal_header-generator, which
  105. # generates METAL paramaterization headers from the device tree.
  106. AC_ARG_WITH([metal-header-generator],
  107. [AS_HELP_STRING([--with-metal-header-generator=PATH], [Use the given path to freedom-metal_header-generator])],
  108. [],
  109. [with_metal_header_generator=check]
  110. )
  111. AC_ARG_VAR(METAL_HEADER_GENERATOR, [The absolute path of the freedom-metal_header-generator])
  112. AC_ARG_WITH([platform-header-generator],
  113. [AS_HELP_STRING([--with-platform-header-generator=PATH], [Use the given path to freedom-platform_header-generator])],
  114. [],
  115. [with_platform_header_generator=check]
  116. )
  117. AC_ARG_VAR(BARE_HEADER_GENERATOR, [The absolute path of the freedom-platform_header-generator])
  118. # Allows users to specify a path to freedom-ldscript-generator, which generates
  119. # linker scripts that are more suitable for embedded development than the
  120. # default linker script is. This allows the tests to link using the actual
  121. # linker script.
  122. AC_ARG_WITH([ldscript-generator],
  123. [AS_HELP_STRING([--with-ldscript-generator=PATH], [Use the given path to freedom-ldscript-generator])],
  124. [],
  125. [with_ldscript_generator=check]
  126. )
  127. AC_ARG_VAR(LDSCRIPT_GENERATOR, [The absolute path of the freedom-ldscript-generator])
  128. # Allows users to specify a path to freedom-makeattributes-generator, which
  129. # generates makefile fragments that help set up the various CFLAGS that are
  130. # required to target a machine.
  131. AC_ARG_WITH([makeattributes-generator],
  132. [AS_HELP_STRING([--with-makeattributes-generator=PATH], [Use the given path to freedom-makeattributes-generator])],
  133. [],
  134. [with_makeattributes_generator=check]
  135. )
  136. AC_ARG_VAR(MAKEATTRIBUTES_GENERATOR, [The absolute path of the freedom-makeattributes-generator])
  137. # Allows users to specify a path to freedom-metal_specs-generator, which
  138. # generates GCC spec files to control the compilation of METAL based targets.
  139. AC_ARG_WITH([metal_specs-generator],
  140. [AS_HELP_STRING([--with-metal_specs-generator=PATH], [Use the given path to freedom-metal_specs-generator])],
  141. [],
  142. [with_metal_specs_generator=check]
  143. )
  144. AC_ARG_VAR(SPECS_GENERATOR, [The absolute path of the freedom-metal_specs-generator])
  145. ########################################################
  146. # Process the Preconfigured or Configured options
  147. ########################################################
  148. AM_CONDITIONAL([PRECONFIGURED], [test "x$with_preconfigured" = "xyes"])
  149. AS_IF([test "x$with_preconfigured" = "xyes"],
  150. [
  151. # Configure the build system to pass in the preconfigured machine support files
  152. AS_IF([test "x$with_machine_header" != "xno"],
  153. [AC_SUBST([MACHINE_HEADER], "$with_machine_header")],
  154. [AC_MSG_FAILURE([--with-machine-header is required with the --with-preconfigured option])]
  155. )
  156. AS_IF([test "x$with_machine_inline" != "xno"],
  157. [AC_SUBST([MACHINE_INLINE], "$with_machine_inline")],
  158. [AC_MSG_FAILURE([--with-machine-inline is required with the --with-preconfigured option])]
  159. )
  160. AS_IF([test "x$with_platform_header" != "xno"],
  161. [AC_SUBST([PLATFORM_HEADER], "$with_platform_header")],
  162. [AC_MSG_FAILURE([--with-platform-header is required with the --with-preconfigured option])]
  163. )
  164. AS_IF([test "x$with_machine_ldscript" != "xno"],
  165. [AC_SUBST([MACHINE_LDSCRIPT], "$with_machine_ldscript")],
  166. [AC_MSG_FAILURE([--with-machine-ldscript is required with the --with-preconfigured option])]
  167. )
  168. AC_SUBST([MAKEATTRIBUTES_GENERATOR], [false])
  169. AC_SUBST([SPECS_GENERATOR], [false])
  170. ], [
  171. # Configure the build system to generate the machine support files during build
  172. AS_IF([test "x$with_machine_dts" != "xno"],
  173. [AC_SUBST([MACHINE_DTS], "$with_machine_dts")],
  174. [AC_MSG_FAILURE([--with-machine-dts is required])]
  175. )
  176. AS_IF([test "x$with_dtc" == "xcheck"],
  177. [AC_PATH_PROG(DTC, dtc, [no])],
  178. [DTC="$with_dtc"]
  179. )
  180. AS_IF([test "x$DTC" != "xno"],
  181. [AC_SUBST([DTC], "$DTC")],
  182. [AC_MSG_ERROR([Unable to find dtc, either place it in PATH or try the --with-dtc argument.])]
  183. )
  184. AS_IF([test "x$with_metal_header_generator" == "xcheck"],
  185. [AC_PATH_PROG(METAL_HEADER_GENERATOR, freedom-metal_header-generator, [no])],
  186. [METAL_HEADER_GENERATOR=$with_metal_header_generator]
  187. )
  188. AS_IF([test "x$METAL_HEADER_GENERATOR" != "xno"],
  189. [AC_SUBST([METAL_HEADER_GENERATOR], "$METAL_HEADER_GENERATOR")],
  190. [AC_MSG_ERROR([Unable to find freedom-metal_header-generator, either place it in PATH or try the --with-metal-header-generator argument.])]
  191. )
  192. AS_IF([test "x$with_ldscript_generator" == "xcheck"],
  193. [AC_PATH_PROG(LDSCRIPT_GENERATOR, freedom-ldscript-generator, [no])],
  194. [LDSCRIPT_GENERATOR=$with_ldscript_generator]
  195. )
  196. AS_IF([test "x$LDSCRIPT_GENERATOR" != "xno"],
  197. [AC_SUBST([LDSCRIPT_GENERATOR], "$LDSCRIPT_GENERATOR")],
  198. [AC_MSG_ERROR([Unable to find freedom-ldscript-generator, either place it in PATH or try the --with-ldscript-generator argument.])]
  199. )
  200. AS_IF([test "x$with_makeattributes_generator" == "xcheck"],
  201. [AC_PATH_PROG(MAKEATTRIBUTES_GENERATOR, freedom-makeattributes-generator, [no])],
  202. [MAKEATTRIBUTES_GENERATOR=$with_makeattributes_generator]
  203. )
  204. AS_IF([test "x$MAKEATTRIBUTES_GENERATOR" != "xno"],
  205. [AC_SUBST([MAKEATTRIBUTES_GENERATOR], "$MAKEATTRIBUTES_GENERATOR")],
  206. [AC_MSG_ERROR([Unable to find freedom-makeattributes-generator, either place it in PATH or try the --with-makeattributes-generator argument.])]
  207. )
  208. AS_IF([test "x$with_metal_specs_generator" == "xcheck"],
  209. [AC_PATH_PROG(SPECS_GENERATOR, freedom-metal_specs-generator, [no])],
  210. [SPECS_GENERATOR=$with_metal_specs_generator]
  211. )
  212. AS_IF([test "x$SPECS_GENERATOR" != "xno"],
  213. [AC_SUBST([SPECS_GENERATOR], "$SPECS_GENERATOR")],
  214. [AC_MSG_ERROR([Unable to find freedom-metal_specs-generator, either place it in PATH or try the --with-metal_specs-generator argument.])]
  215. )
  216. ])
  217. # Check for the additional compiler flags provided by the METAL toolchains,
  218. # directly substituting in the relevant
  219. AX_CHECK_COMPILE_FLAG([mmachine=$machine_name],
  220. [mmachine_machine_name="-mmachine=$machine_name"],
  221. )
  222. AC_SUBST([MMACHINE_MACHINE_NAME], "$mmachine_machine_name")
  223. AX_CHECK_COMPILE_FLAG([menv=metal],
  224. [menv_metal="-menv=metal"],
  225. [menv_metal="-lriscv_metal_$machine_name"]
  226. )
  227. AC_SUBST([MENV_METAL], "$menv_metal")
  228. # Generates the remainder of the build system.
  229. AC_CONFIG_FILES([Makefile])
  230. AC_OUTPUT