Mmake, short for “Mercury Make”, is a tool for building Mercury programs. The same functionality is now provided in ‘mmc’ directly by using the ‘--make’ option:
mmc --make main-module
The usage of Mmake is discouraged.
Mmake is built on top of ordinary or GNU Make 1. With Mmake, building even a complicated Mercury program consisting of a number of modules is as simple as
mmc -f source-files mmake main-module.depend mmake main-module
Mmake only recompiles those files that need to be recompiled, based on automatically generated dependency information. Most of the dependencies are stored in .d files that are automatically recomputed every time you recompile, so they are never out-of-date. A little bit of the dependency information is stored in .dep and .dv files which are more expensive to recompute. The ‘mmake main-module.depend’ command which recreates the main-module.dep and main-module.dv files needs to be repeated only when you add or remove a module from your program, and there is no danger of getting an inconsistent executable if you forget this step — instead you will get a compile or link error.
The ‘mmc -f’ step above is only required if there are any source files for which the file name does not match the module name. ‘mmc -f’ generates a file Mercury.modules containing a mapping from module name to source file. The Mercury.modules file must be updated when a source file for which the file name does not match the module name is added to or removed from the directory.
‘mmake’ allows you to build more than one program in the same directory. Each program must have its own .dep and .dv files, and therefore you must run ‘mmake program.depend’ for each program. The ‘Mercury.modules’ file is used for all programs in the directory.
If there is a file called ‘Mmake’ or ‘Mmakefile’ in the current directory, Mmake will include that file in its automatically-generated Makefile. The ‘Mmake’ file can override the default values of various variables used by Mmake's builtin rules, or it can add additional rules, dependencies, and actions.
Mmake's builtin rules are defined by the file prefix/lib/mercury/mmake/Mmake.rules (where prefix is /usr/local/mercury-version by default, and version is the version number, e.g. ‘0.6’), as well as the rules and variables in the automatically-generated .dep and .dv files. These rules define the following targets:
LIBGRADESvariable. It will also build and install the necessary interface files. The variable
INSTALLspecifies the name of the command to use to install each file, by default ‘cp’. The variable
INSTALL_MKDIRspecifies the command to use to create directories, by default ‘mkdir -p’.
The variables used by the builtin rules (and their default values) are defined in the file prefix/lib/mercury/mmake/Mmake.vars, however these may be overridden by user ‘Mmake’ files. Some of the more useful variables are:
GRADEFLAGS and EXTRA_GRADEFLAGS
MCFLAGS and EXTRA_MCFLAGS
GRADEFLAGS, not in
MGNUCFLAGS and EXTRA_MGNUCFLAGS
CFLAGS and EXTRA_CFLAGS
JAVACFLAGS and EXTRA_JAVACFLAGS
ERLANG_FLAGS and EXTRA_ERLANG_FLAGS
MLFLAGS and EXTRA_MLFLAGS
GRADEFLAGS, not in
MLFLAGS.) These variables have no effect with ‘mmc --make’.
LDFLAGS and EXTRA_LDFLAGS
ml --print-link-commandto find out what command is used, usually the C compiler).
LD_LIBFLAGS and EXTRA_LD_LIBFLAGS
ml --print-shared-lib-link-commandto find out what command is used, usually the C compiler or the system linker, depending on the platform).
MLLIBS and EXTRA_MLLIBS
MLOBJS and EXTRA_MLOBJS
C2INITFLAGS and EXTRA_C2INITFLAGS
EXTRA_C2INITFLAGSare obsolete synonyms for
c2inittake the same set of options). (Note that compilation model options and extra files to be processed by c2init should not be specified in
C2INITFLAGS— they should be specified in
C2INITARGS and EXTRA_C2INITARGS
MLFLAGS) since they are also used to derive extra dependency information.
GRADEFLAGSsettings will also be applied when the library is built in each of the listed grades, so you may not get what you expect if those options are not subsumed by each of the grades listed.
Other variables also exist — see prefix/lib/mercury/mmake/Mmake.vars for a complete list.
If you wish to temporarily change the flags passed to an executable, rather than setting the various ‘FLAGS’ variables directly, you can set an ‘EXTRA_’ variable. This is particularly intended for use where a shell script needs to call mmake and add an extra parameter, without interfering with the flag settings in the ‘Mmakefile’.
For each of the variables for which there is version with an ‘EXTRA_’ prefix, there is also a version with an ‘ALL_’ prefix that is defined to include both the ordinary and the ‘EXTRA_’ version. If you wish to use the values any of these variables in your Mmakefile (as opposed to setting the values), then you should use the ‘ALL_’ version.
It is also possible to override these variables on a per-file basis.
For example, if you have a module called say bad_style.m
which triggers lots of compiler warnings, and you want to disable
the warnings just for that file, but keep them for all the other modules,
then you can override
MCFLAGS just for that file. This is done by
setting the variable ‘MCFLAGS-bad_style’, as shown here:
MCFLAGS-bad_style = --inhibit-warnings
Mmake has a few options, including ‘--use-subdirs’, ‘--use-mmc-make’, ‘--save-makefile’, ‘--verbose’, and ‘--no-warn-undefined-vars’. For details about these options, see the man page or type ‘mmake --help’.
Finally, since Mmake is built on top of Make or GNU Make, you can also make use of the features and options supported by the underlying Make. In particular, GNU Make has support for running jobs in parallel, which is very useful if you have a machine with more than one CPU.
As an alternative to Mmake, the Mercury compiler now contains a significant part of the functionality of Mmake, using ‘mmc’'s ‘--make’ option. The advantages of the ‘mmc --make’ over Mmake are that there is no ‘mmake depend’ step and the dependencies are more accurate.
Note that ‘--use-subdirs’ is automatically enabled if you specify ‘mmc --make’.
The Mmake variables above can be used by ‘mmc --make’ if they are set in a file called Mercury.options. The Mercury.options file has the same syntax as an Mmakefile, but only variable assignments and ‘include’ directives are allowed. All variables in Mercury.options are treated as if they are assigned using ‘:=’. Variables may also be set in the environment, overriding settings in options files.
‘mmc --make’ can be used in conjunction with Mmake. This is useful for projects which include source code written in languages other than Mercury. The ‘--use-mmc-make’ Mmake option disables Mmake's Mercury-specific rules. Mmake will then process source files written in other languages, but all Mercury compilation will be done by ‘mmc --make’. The following variables can be set in the Mmakefile to control the use of ‘mmc --make’.
MC_MAKE_FLAGS and EXTRA_MC_MAKE_FLAGS
The following variables can also appear in options files but are only supported by ‘mmc --make’.
 We might eventually add support for ordinary “Make” programs, but currently only GNU Make is supported.