# The name, version, and maintainer of this package 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]) # Initializes automake, enabling maintainer mode by default (which should be # disabled by the archive generated by "make dist"). AM_INIT_AUTOMAKE([foreign subdir-objects]) AM_MAINTAINER_MODE([disable]) AC_CONFIG_MACRO_DIRS([m4]) # This library is actually an integral part of the toolchain build process on # METAL toolchains as it's necessary to link any program. To prevent this from # causing every autoconf test failing we instead place some weak symbols in # confdefs.h to trick the toolchain into linking. # #AC_CANONICAL_HOST -- for now don't canonicalize the host because the *-metal # tuples aren't upstream in config.* case "${host_alias}" in *-metal) AS_ECHO("long metal_segment_stack_end __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_data_source_start __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_data_source_end __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_data_target_start __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_data_target_end __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_bss_target_start __attribute__((weak));") >> confdefs.h AS_ECHO("long metal_segment_bss_target_end __attribute__((weak));") >> confdefs.h AS_ECHO("void metal_shutdown(void) __attribute__((weak)); void metal_shutdown(void) {}") >> confdefs.h ;; esac # Probe for tools that we need in order to build. AC_PROG_CC AC_PROG_RANLIB AM_PROG_AR AM_PROG_AS # autoconf tries very hard to avoid failing, so it'll even go ahead and try to # build the project using "gcc" if it can't find a suitable C compiler prefixed # by the host system. This doesn't work when cross compiling, but it's a # common error for users so we explicitly check for this right here to quickly # provide an error message. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ #ifndef __riscv # error "A RISC-V compiler is required to build the Freedom MBI" #endif ])], [], [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.])]) ######################################################## # Generic Options ######################################################## # Allows users to specify some device tree information. AC_ARG_WITH([machine-name], [AS_HELP_STRING([--with-machine-name=NAME], [Install this machine with a particular name])], [], [with_machine_name="no"] ) AS_IF([test "x$with_machine_name" != "xno"], [AC_SUBST([MACHINE_NAME], "$with_machine_name")], [AC_MSG_FAILURE([--with-machine-name is required])] ) AC_ARG_WITH([preconfigured], [AS_HELP_STRING([--with-preconfigured], [Use pre-configured machine support files instead of generating them during the build])], [with_preconfigured="yes"], [with_preconfigured="no"] ) AC_ARG_WITH([builtin-libgloss], [AS_HELP_STRING([--with-bultin-libgloss], [Build libgloss along with the METAL])], [with_builtin_libgloss="yes"], [with_builtin_libgloss="no"] ) AM_CONDITIONAL([WITH_BUILTIN_LIBGLOSS], [test "x$with_builtin_libgloss" = "xyes"]) ######################################################## # Preconfigured Options (--with-preconfigured) ######################################################## AC_ARG_WITH([machine-header], [AS_HELP_STRING([--with-machine-header=PATH], [Path to the machine header file])], [], [with_machine_header="no"] ) AC_ARG_WITH([machine-inline], [AS_HELP_STRING([--with-machine-inline=PATH], [Path to the machine inline file])], [], [with_machine_inline="no"] ) AC_ARG_WITH([platform-header], [AS_HELP_STRING([--with-platform-header=PATH], [Path to the platform header file])], [], [with_platform_header="no"] ) AC_ARG_WITH([machine-ldscript], [AS_HELP_STRING([--with-machine-ldscript=PATH], [Path to the machine ldscript])], [], [with_machine_ldscript="no"] ) ######################################################## # Configuration Options (--without-preconfigured) ######################################################## AC_ARG_WITH([machine-dts], [AS_HELP_STRING([--with-machine-dts=PATH], [The full path to the device tree])], [], [with_machine_dts="no"] ) # Allows users to specify a path to DTC AC_ARG_WITH([dtc], [AS_HELP_STRING([--with-dtc=PATH], [Use the given path to the device tree compiler])], [], [with_dtc=check] ) AC_ARG_VAR(DTC, [The absolute path to dtc]) # Allows users to specify a path to freedom-metal_header-generator, which # generates METAL paramaterization headers from the device tree. AC_ARG_WITH([metal-header-generator], [AS_HELP_STRING([--with-metal-header-generator=PATH], [Use the given path to freedom-metal_header-generator])], [], [with_metal_header_generator=check] ) AC_ARG_VAR(METAL_HEADER_GENERATOR, [The absolute path of the freedom-metal_header-generator]) AC_ARG_WITH([platform-header-generator], [AS_HELP_STRING([--with-platform-header-generator=PATH], [Use the given path to freedom-platform_header-generator])], [], [with_platform_header_generator=check] ) AC_ARG_VAR(BARE_HEADER_GENERATOR, [The absolute path of the freedom-platform_header-generator]) # Allows users to specify a path to freedom-ldscript-generator, which generates # linker scripts that are more suitable for embedded development than the # default linker script is. This allows the tests to link using the actual # linker script. AC_ARG_WITH([ldscript-generator], [AS_HELP_STRING([--with-ldscript-generator=PATH], [Use the given path to freedom-ldscript-generator])], [], [with_ldscript_generator=check] ) AC_ARG_VAR(LDSCRIPT_GENERATOR, [The absolute path of the freedom-ldscript-generator]) # Allows users to specify a path to freedom-makeattributes-generator, which # generates makefile fragments that help set up the various CFLAGS that are # required to target a machine. AC_ARG_WITH([makeattributes-generator], [AS_HELP_STRING([--with-makeattributes-generator=PATH], [Use the given path to freedom-makeattributes-generator])], [], [with_makeattributes_generator=check] ) AC_ARG_VAR(MAKEATTRIBUTES_GENERATOR, [The absolute path of the freedom-makeattributes-generator]) # Allows users to specify a path to freedom-metal_specs-generator, which # generates GCC spec files to control the compilation of METAL based targets. AC_ARG_WITH([metal_specs-generator], [AS_HELP_STRING([--with-metal_specs-generator=PATH], [Use the given path to freedom-metal_specs-generator])], [], [with_metal_specs_generator=check] ) AC_ARG_VAR(SPECS_GENERATOR, [The absolute path of the freedom-metal_specs-generator]) ######################################################## # Process the Preconfigured or Configured options ######################################################## AM_CONDITIONAL([PRECONFIGURED], [test "x$with_preconfigured" = "xyes"]) AS_IF([test "x$with_preconfigured" = "xyes"], [ # Configure the build system to pass in the preconfigured machine support files AS_IF([test "x$with_machine_header" != "xno"], [AC_SUBST([MACHINE_HEADER], "$with_machine_header")], [AC_MSG_FAILURE([--with-machine-header is required with the --with-preconfigured option])] ) AS_IF([test "x$with_machine_inline" != "xno"], [AC_SUBST([MACHINE_INLINE], "$with_machine_inline")], [AC_MSG_FAILURE([--with-machine-inline is required with the --with-preconfigured option])] ) AS_IF([test "x$with_platform_header" != "xno"], [AC_SUBST([PLATFORM_HEADER], "$with_platform_header")], [AC_MSG_FAILURE([--with-platform-header is required with the --with-preconfigured option])] ) AS_IF([test "x$with_machine_ldscript" != "xno"], [AC_SUBST([MACHINE_LDSCRIPT], "$with_machine_ldscript")], [AC_MSG_FAILURE([--with-machine-ldscript is required with the --with-preconfigured option])] ) AC_SUBST([MAKEATTRIBUTES_GENERATOR], [false]) AC_SUBST([SPECS_GENERATOR], [false]) ], [ # Configure the build system to generate the machine support files during build AS_IF([test "x$with_machine_dts" != "xno"], [AC_SUBST([MACHINE_DTS], "$with_machine_dts")], [AC_MSG_FAILURE([--with-machine-dts is required])] ) AS_IF([test "x$with_dtc" == "xcheck"], [AC_PATH_PROG(DTC, dtc, [no])], [DTC="$with_dtc"] ) AS_IF([test "x$DTC" != "xno"], [AC_SUBST([DTC], "$DTC")], [AC_MSG_ERROR([Unable to find dtc, either place it in PATH or try the --with-dtc argument.])] ) AS_IF([test "x$with_metal_header_generator" == "xcheck"], [AC_PATH_PROG(METAL_HEADER_GENERATOR, freedom-metal_header-generator, [no])], [METAL_HEADER_GENERATOR=$with_metal_header_generator] ) AS_IF([test "x$METAL_HEADER_GENERATOR" != "xno"], [AC_SUBST([METAL_HEADER_GENERATOR], "$METAL_HEADER_GENERATOR")], [AC_MSG_ERROR([Unable to find freedom-metal_header-generator, either place it in PATH or try the --with-metal-header-generator argument.])] ) AS_IF([test "x$with_ldscript_generator" == "xcheck"], [AC_PATH_PROG(LDSCRIPT_GENERATOR, freedom-ldscript-generator, [no])], [LDSCRIPT_GENERATOR=$with_ldscript_generator] ) AS_IF([test "x$LDSCRIPT_GENERATOR" != "xno"], [AC_SUBST([LDSCRIPT_GENERATOR], "$LDSCRIPT_GENERATOR")], [AC_MSG_ERROR([Unable to find freedom-ldscript-generator, either place it in PATH or try the --with-ldscript-generator argument.])] ) AS_IF([test "x$with_makeattributes_generator" == "xcheck"], [AC_PATH_PROG(MAKEATTRIBUTES_GENERATOR, freedom-makeattributes-generator, [no])], [MAKEATTRIBUTES_GENERATOR=$with_makeattributes_generator] ) AS_IF([test "x$MAKEATTRIBUTES_GENERATOR" != "xno"], [AC_SUBST([MAKEATTRIBUTES_GENERATOR], "$MAKEATTRIBUTES_GENERATOR")], [AC_MSG_ERROR([Unable to find freedom-makeattributes-generator, either place it in PATH or try the --with-makeattributes-generator argument.])] ) AS_IF([test "x$with_metal_specs_generator" == "xcheck"], [AC_PATH_PROG(SPECS_GENERATOR, freedom-metal_specs-generator, [no])], [SPECS_GENERATOR=$with_metal_specs_generator] ) AS_IF([test "x$SPECS_GENERATOR" != "xno"], [AC_SUBST([SPECS_GENERATOR], "$SPECS_GENERATOR")], [AC_MSG_ERROR([Unable to find freedom-metal_specs-generator, either place it in PATH or try the --with-metal_specs-generator argument.])] ) ]) # Check for the additional compiler flags provided by the METAL toolchains, # directly substituting in the relevant AX_CHECK_COMPILE_FLAG([mmachine=$machine_name], [mmachine_machine_name="-mmachine=$machine_name"], ) AC_SUBST([MMACHINE_MACHINE_NAME], "$mmachine_machine_name") AX_CHECK_COMPILE_FLAG([menv=metal], [menv_metal="-menv=metal"], [menv_metal="-lriscv_metal_$machine_name"] ) AC_SUBST([MENV_METAL], "$menv_metal") # Generates the remainder of the build system. AC_CONFIG_FILES([Makefile]) AC_OUTPUT