forked from sifive/freedom-metal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
277 lines (230 loc) · 11.1 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# 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