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:
LIBGRADES variable. It will also build and install the
necessary interface files. The variable INSTALL specifies
the name of the command to use to install each file, by default
‘cp’. The variable INSTALL_MKDIR specifies 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:
MAIN_TARGETMCGRADEFLAGS and EXTRA_GRADEFLAGSmmc, mgnuc, ml, and c2init).
MCFLAGS and EXTRA_MCFLAGSGRADEFLAGS, not in MCFLAGS.)
MGNUCMGNUCFLAGS and EXTRA_MGNUCFLAGSCFLAGS and EXTRA_CFLAGSJAVACFLAGS and EXTRA_JAVACFLAGSERLANG_FLAGS and EXTRA_ERLANG_FLAGSMLLINKAGEMERCURY_LINKAGEMLFLAGS and EXTRA_MLFLAGSGRADEFLAGS, not in MLFLAGS.)
These variables have no effect with ‘mmc --make’.
LDFLAGS and EXTRA_LDFLAGSml --print-link-command to find out
what command is used, usually the C compiler).
LD_LIBFLAGS and EXTRA_LD_LIBFLAGSml --print-shared-lib-link-command
to find out what command is used, usually the C compiler
or the system linker, depending on the platform).
MLLIBS and EXTRA_MLLIBSMLOBJS and EXTRA_MLOBJSC2INITFLAGS and EXTRA_C2INITFLAGSC2INITFLAGS and EXTRA_C2INITFLAGS are obsolete synonyms
for MLFLAGS and EXTRA_MLFLAGS (ml and c2init
take 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 GRADEFLAGS and C2INITARGS, respectively.)
C2INITARGS and EXTRA_C2INITARGSMLFLAGS) since they are also used to derive extra dependency
information.
EXTRA_LIBRARIESEXTRA_LIB_DIRSINSTALL_PREFIXINSTALLINSTALL_MKDIRLIBGRADESGRADEFLAGS settings 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.
LIB_LINKAGESOther 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’.
MERCURY_MAIN_MODULESMC_BUILD_FILESMC_MAKE_FLAGS and EXTRA_MC_MAKE_FLAGSThe following variables can also appear in options files but are only supported by ‘mmc --make’.
GCC_FLAGSCLANG_FLAGSMSVC_FLAGS[1] We might eventually add support for ordinary “Make” programs, but currently only GNU Make is supported.