Sv57 and Sv64 are not spec'd yet
[riscv-isa-sim.git] / aclocal.m4
1 #=========================================================================
2 # Local Autoconf Macros
3 #=========================================================================
4 # This file contains the macros for the Modular C++ Build System and
5 # additional autoconf macros which developers can use in their
6 # configure.ac scripts. Please read the documentation in
7 # 'mcppbs-doc.txt' for more details on how the Modular C++ Build System
8 # works. The documenation for each macro should include information
9 # about the author, date, and copyright.
10
11 #-------------------------------------------------------------------------
12 # MCPPBS_PROG_INSTALL
13 #-------------------------------------------------------------------------
14 # This macro will add an --enable-stow command line option to the
15 # configure script. When enabled, this macro will first check to see if
16 # the stow program is available and if so it will set the $stow shell
17 # variable to the binary name and the $enable_stow shell variable to
18 # "yes". These variables can be used in a makefile to conditionally use
19 # stow for installation.
20 #
21 # This macro uses two environment variables to help setup default stow
22 # locations. The $STOW_PREFIX is used for stowing native built packages.
23 # The packages are staged in $STOW_PREFIX/pkgs and then symlinks are
24 # created from within $STOW_PREFIX into the pkgs subdirectory. If you
25 # only do native builds then this is all you need to set. If you don't
26 # set $STOW_PREFIX then the default is just the normal default prefix
27 # which is almost always /usr/local.
28 #
29 # For non-native builds we probably want to install the packages in a
30 # different location which includes the host architecture name as part
31 # of the prefix. For these kind of builds, we can specify the $STOW_ROOT
32 # environment variable and the effective prefix will be
33 # $STOW_ROOT/${host_alias} where ${host_alias} is specified on the
34 # configure command line with "--host".
35 #
36 # Here is an example setup:
37 #
38 # STOW_ROOT="$HOME/install"
39 # STOW_ARCH="i386-macosx10.4"
40 # STOW_PREFIX="${STOW_ROOT}/${STOW_ARCH}"
41 #
42
43 AC_DEFUN([MCPPBS_PROG_INSTALL],
44 [
45
46 # Configure command line option
47
48 AC_ARG_ENABLE(stow,
49 AS_HELP_STRING(--enable-stow,[Enable stow-based install]),
50 [enable_stow="yes"],[enable_stow="no"])
51
52 AC_SUBST([enable_stow])
53
54 # Environment variables
55
56 AC_ARG_VAR([STOW_ROOT], [Root for non-native stow-based installs])
57 AC_ARG_VAR([STOW_PREFIX], [Prefix for stow-based installs])
58
59 # Check for install script
60
61 AC_PROG_INSTALL
62
63 # Deterimine if native build and set prefix appropriately
64
65 AS_IF([ test ${enable_stow} = "yes" ],
66 [
67 AC_CHECK_PROGS([stow],[stow],[no])
68 AS_IF([ test ${stow} = "no" ],
69 [
70 AC_MSG_ERROR([Cannot use --enable-stow since stow is not available])
71 ])
72
73 # Check if native or non-native build
74
75 AS_IF([ test "${build}" = "${host}" ],
76 [
77
78 # build == host so this is a native build. Make sure --prefix not
79 # set and $STOW_PREFIX is set, then set prefix=$STOW_PREFIX.
80
81 AS_IF([ test "${prefix}" = "NONE" && test -n "${STOW_PREFIX}" ],
82 [
83 prefix="${STOW_PREFIX}"
84 AC_MSG_NOTICE([Using \$STOW_PREFIX from environment])
85 AC_MSG_NOTICE([prefix=${prefix}])
86 ])
87
88 ],[
89
90 # build != host so this is a non-native build. Make sure --prefix
91 # not set and $STOW_ROOT is set, then set
92 # prefix=$STOW_ROOT/${host_alias}.
93
94 AS_IF([ test "${prefix}" = "NONE" && test -n "${STOW_ROOT}" ],
95 [
96 prefix="${STOW_ROOT}/${host_alias}"
97 AC_MSG_NOTICE([Using \$STOW_ROOT from environment])
98 AC_MSG_NOTICE([prefix=${prefix}])
99 ])
100
101 ])
102
103 ])
104
105 ])
106
107 #-------------------------------------------------------------------------
108 # MCPPBS_PROG_RUN
109 # -------------------------------------------------------------------------
110 # If we are doing a non-native build then we look for an isa simulator
111 # to use for running tests. We set the RUN substitution variable to be
112 # empty for native builds or to the name of the isa simulator for
113 # non-native builds. Thus a makefile can run compiled programs
114 # regardless if we are doing a native or non-native build like this:
115 #
116 # $(RUN) $(RUNFLAGS) ./test-program
117 #
118
119 AC_DEFUN([MCPPBS_PROG_RUN],
120 [
121 AS_IF([ test "${build}" != "${host}" ],
122 [
123 AC_CHECK_TOOLS([RUN],[isa-run run],[no])
124 AS_IF([ test ${RUN} = "no" ],
125 [
126 AC_MSG_ERROR([Cannot find simulator for target ${target_alias}])
127 ])
128 ],[
129 RUN=""
130 ])
131 AC_SUBST([RUN])
132 AC_SUBST([RUNFLAGS])
133 ])
134
135 #-------------------------------------------------------------------------
136 # MCPPBS_SUBPROJECTS([ sproj1, sproj2, ... ])
137 #-------------------------------------------------------------------------
138 # The developer should call this macro with a list of the subprojects
139 # which make up this project. One should order the list such that any
140 # given subproject only depends on subprojects listed before it. The
141 # subproject names can also include an * suffix which indicates that
142 # this is an optional subproject. Optional subprojects are only included
143 # as part of the project build if enabled on the configure command line
144 # with a --enable-<subproject> flag. The user can also specify that all
145 # optional subprojects should be included in the build with the
146 # --enable-optional-subprojects flag.
147 #
148 # Subproject names can also include a ** suffix which indicates that it
149 # is an optional subproject, but there is a group with the same name.
150 # Thus the --enable-<sproj> command line option will enable not just the
151 # subproject sproj but all of the subprojects which are in the group.
152 # There is no error checking to make sure that if you use the ** suffix
153 # you actually define a group so be careful.
154 #
155 # Both required and optional subprojects should have a 'subproject.ac'
156 # file. The script's filename should be the abbreivated subproject name
157 # (assuming the subproject name is sproj then we would use 'sproj.ac')
158 # The MCPPBS_SUBPROJECTS macro includes the 'subproject.ac' files for
159 # enabled subprojects. Whitespace and newlines are allowed within the
160 # list.
161 #
162 # Author : Christopher Batten
163 # Date : September 10, 2008
164
165 AC_DEFUN([MCPPBS_SUBPROJECTS],
166 [
167
168 # Add command line argument to enable all optional subprojects
169
170 AC_ARG_ENABLE(optional-subprojects,
171 AS_HELP_STRING([--enable-optional-subprojects],
172 [Enable all optional subprojects]))
173
174 # Loop through the subprojects given in the macro argument
175
176 m4_foreach([MCPPBS_SPROJ],[$1],
177 [
178
179 # Determine if this is a required or an optional subproject
180
181 m4_define([MCPPBS_IS_REQ],
182 m4_bmatch(MCPPBS_SPROJ,[\*+],[false],[true]))
183
184 # Determine if there is a group with the same name
185
186 m4_define([MCPPBS_IS_GROUP],
187 m4_bmatch(MCPPBS_SPROJ,[\*\*],[true],[false]))
188
189 # Create variations of the subproject name suitable for use as a CPP
190 # enabled define, a shell enabled variable, and a shell function
191
192 m4_define([MCPPBS_SPROJ_NORM],
193 m4_normalize(m4_bpatsubsts(MCPPBS_SPROJ,[*],[])))
194
195 m4_define([MCPPBS_SPROJ_DEFINE],
196 m4_toupper(m4_bpatsubst(MCPPBS_SPROJ_NORM[]_ENABLED,[-],[_])))
197
198 m4_define([MCPPBS_SPROJ_FUNC],
199 m4_bpatsubst(_mpbp_[]MCPPBS_SPROJ_NORM[]_configure,[-],[_]))
200
201 m4_define([MCPPBS_SPROJ_UNDERSCORES],
202 m4_bpatsubsts(MCPPBS_SPROJ,[-],[_]))
203
204 m4_define([MCPPBS_SPROJ_SHVAR],
205 m4_bpatsubst(enable_[]MCPPBS_SPROJ_NORM[]_sproj,[-],[_]))
206
207 # Add subproject to our running list
208
209 subprojects="$subprojects MCPPBS_SPROJ_NORM"
210
211 # Process the subproject appropriately. If enabled add it to the
212 # $enabled_subprojects running shell variable, set a
213 # SUBPROJECT_ENABLED C define, and include the appropriate
214 # 'subproject.ac'.
215
216 m4_if(MCPPBS_IS_REQ,[true],
217 [
218 AC_MSG_NOTICE([configuring default subproject : MCPPBS_SPROJ_NORM])
219 AC_CONFIG_FILES(MCPPBS_SPROJ_NORM[].mk:MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].mk.in)
220 MCPPBS_SPROJ_SHVAR="yes"
221 subprojects_enabled="$subprojects_enabled MCPPBS_SPROJ_NORM"
222 AC_DEFINE(MCPPBS_SPROJ_DEFINE,,
223 [Define if subproject MCPPBS_SPROJ_NORM is enabled])
224 m4_include(MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].ac)
225 ],[
226
227 # For optional subprojects we capture the 'subproject.ac' as a
228 # shell function so that in the MCPPBS_GROUP macro we can just
229 # call this shell function instead of reading in 'subproject.ac'
230 # again.
231
232 MCPPBS_SPROJ_FUNC ()
233 {
234 AC_MSG_NOTICE([configuring optional subproject : MCPPBS_SPROJ_NORM])
235 AC_CONFIG_FILES(MCPPBS_SPROJ_NORM[].mk:MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].mk.in)
236 MCPPBS_SPROJ_SHVAR="yes"
237 subprojects_enabled="$subprojects_enabled MCPPBS_SPROJ_NORM"
238 AC_DEFINE(MCPPBS_SPROJ_DEFINE,,
239 [Define if subproject MCPPBS_SPROJ_NORM is enabled])
240 m4_include(MCPPBS_SPROJ_NORM[]/MCPPBS_SPROJ_NORM[].ac)
241 };
242
243 # Optional subprojects add --enable-subproject command line
244 # options, _if_ the subproject name is not also a group name.
245
246 m4_if(MCPPBS_IS_GROUP,[false],
247 [
248 AC_ARG_ENABLE(MCPPBS_SPROJ_NORM,
249 AS_HELP_STRING(--enable-MCPPBS_SPROJ_NORM,
250 [Subproject MCPPBS_SPROJ_NORM]),
251 [MCPPBS_SPROJ_SHVAR="yes"],[MCPPBS_SPROJ_SHVAR="no"])
252
253 AS_IF([test "$MCPPBS_SPROJ_SHVAR" = "yes"],
254 [
255 eval "MCPPBS_SPROJ_FUNC"
256 ],[
257 AC_MSG_NOTICE([processing optional subproject : MCPPBS_SPROJ_NORM])
258 ])
259
260 ],[
261
262 # If the subproject name is also a group name then we need to
263 # make sure that we set the shell variable for that subproject to
264 # no so that the group code knows we haven't run it yet.
265
266 AC_MSG_NOTICE([processing optional subproject : MCPPBS_SPROJ_NORM])
267 MCPPBS_SPROJ_SHVAR="no"
268
269 ])
270
271 # Always execute the subproject configure code if we are enabling
272 # all subprojects.
273
274 AS_IF([ test "$enable_optional_subprojects" = "yes" \
275 && test "$MCPPBS_SPROJ_SHVAR" = "no" ],
276 [
277 eval "MCPPBS_SPROJ_FUNC"
278 ])
279
280 ])
281
282 ])
283
284 # Output make variables
285
286 AC_SUBST([subprojects])
287 AC_SUBST([subprojects_enabled])
288
289 ])
290
291 #-------------------------------------------------------------------------
292 # MCPPBS_GROUP( [group-name], [ sproj1, sproj2, ... ] )
293 #-------------------------------------------------------------------------
294 # This macro creates a subproject group with the given group-name. When
295 # a user specifies --enable-<group-name> the listed subprojects will be
296 # enabled. Groups can have the same name as a subproject and in that
297 # case whenever a user specifies --enable-<subproject> the subprojects
298 # listed in the corresponding group will also be enabled. Groups are
299 # useful for specifying related subprojects which are usually enabled
300 # together, as well as for specifying that a specific optional
301 # subproject has dependencies on other optional subprojects.
302 #
303 # Author : Christopher Batten
304 # Date : September 10, 2008
305
306 AC_DEFUN([MCPPBS_GROUP],
307 [
308
309 m4_define([MCPPBS_GROUP_NORM],
310 m4_normalize([$1]))
311
312 m4_define([MCPPBS_GROUP_SHVAR],
313 m4_bpatsubst(enable_[]MCPPBS_GROUP_NORM[]_group,[-],[_]))
314
315 AC_ARG_ENABLE(MCPPBS_GROUP_NORM,
316 AS_HELP_STRING(--enable-MCPPBS_GROUP_NORM,
317 [Group MCPPBS_GROUP_NORM: $2]),
318 [MCPPBS_GROUP_SHVAR="yes"],[MCPPBS_GROUP_SHVAR="no"])
319
320 AS_IF([test "$MCPPBS_GROUP_SHVAR" = "yes" ],
321 [
322 AC_MSG_NOTICE([configuring optional group : MCPPBS_GROUP_NORM])
323 ])
324
325 m4_foreach([MCPPBS_SPROJ],[$2],
326 [
327
328 m4_define([MCPPBS_SPROJ_NORM],
329 m4_normalize(MCPPBS_SPROJ))
330
331 m4_define([MCPPBS_SPROJ_SHVAR],
332 m4_bpatsubst(enable_[]MCPPBS_SPROJ_NORM[]_sproj,[-],[_]))
333
334 m4_define([MCPPBS_SPROJ_FUNC],
335 m4_bpatsubst(_mpbp_[]MCPPBS_SPROJ_NORM[]_configure,[-],[_]))
336
337 AS_IF([ test "$MCPPBS_GROUP_SHVAR" = "yes" \
338 && test "$MCPPBS_SPROJ_SHVAR" = "no" ],
339 [
340 eval "MCPPBS_SPROJ_FUNC"
341 ])
342
343 ])
344
345 ])