This main purpose of this application was to help me learn Mercury and at the same time produce some tools that would be useful on that journey.
I assume that you have a fully working installation of mercury on your system
and all accessible from the command line. The Makefile was generated by this
application once I had written it, sure it might seem overkill for a single
file application, after all mmc --make
is all you need in that case but you
never know when a project will grow and being able to clean the directory too
is nice.
19 Nov 2021: Revamped with everything I've learned in the last few months!
- Hopefully more idiomatic code.
- Use of custom command type.
- Improved content of main().
- Makefile tweaks (-E added)
It really couldn't be simpler, if you DON'T have make installed then just use
mmc mcnew.m
and then copy the executable somewhere on your path so you can use it from any folder going forward.
If you do have make
installed then it's even easier just type make!
make install
That's it, all done, ready to use.
There are two commands available and they both take the basic name of the
module, let's call it foo
. If you enter foo.m then be prepared for
interesting times ahead. If you don't pipe the output to a file then by default
it just gets written to stdout
and then you could cut and paste it from the
terminal window into a file or whatever you want to do.
If this is only ever used by you, you can set an environment variabled like so and this will be automatically used to fill in the [author] slot. If you don't provide an author and one is not passed on the command line it remains blank.
export MCNEW_AUTHOR="Your name here"
To create a stubbed out -main- application:
mcnew stub foo [author]> foo.m
The reason I don't save to a file explicitly in the code is because I wanted to keep it simple! Otherwise I would have had to get into the file system libraries, that will come. Indeed I may well extend this utility over time to include that sort of thing.
If you want a makefile to go with your new project then issue:
mmcnew makefile foo [author] > makefile
And you are done. As your project grows all you have to do as add the new
source file names to the DEPS
variable and the make magic should take care of
the rest.
Stock build:
$ make
Install to your local $BIN folder (*nix only), no idea how it would go on Windows!
$ make install
The value of $HOME/bin is used as the target for the copy.