2013-02-25 23:52:08 -08:00
|
|
|
|
2014-08-04 13:46:00 -07:00
|
|
|
<p align="center">
|
|
|
|
|
<img alt="Logo" src="http://dcjones.github.com/mk/mk.svg">
|
|
|
|
|
</p>
|
2013-02-25 23:52:08 -08:00
|
|
|
|
2013-03-09 20:54:13 -08:00
|
|
|
Mk is a reboot of the Plan 9 mk command, which itself is [a successor to
|
2013-03-10 19:08:43 -07:00
|
|
|
make](http://www.cs.tufts.edu/~nr/cs257/archive/andrew-hume/mk.pdf). This tool
|
|
|
|
|
is for anyone who loves make, but hates all its stupid bullshit.
|
2013-03-09 20:54:13 -08:00
|
|
|
|
|
|
|
|
# Installation
|
|
|
|
|
|
|
|
|
|
1. Install Go.
|
2014-08-04 13:55:54 -07:00
|
|
|
2. Run `go get github.com/dcjones/mk`
|
|
|
|
|
3. Make sure `$GOPATH/bin` is in your `PATH`.
|
2013-02-25 23:52:08 -08:00
|
|
|
|
|
|
|
|
# Why Plan 9 mk is better than make
|
|
|
|
|
|
2013-03-09 20:54:13 -08:00
|
|
|
Way back in the 90s, some smart guys at Bell Labs got together and decided to
|
|
|
|
|
write new operating system to replace Unix. The idea was to keep everything that
|
|
|
|
|
was great about Unix, but totally disregard backwards compatibility in a quest
|
|
|
|
|
for something better. The operating system they designed, Plan 9, had a lot of
|
|
|
|
|
terrific ideas, and though some were cherry picked, the OS as a whole never
|
|
|
|
|
really caught on.
|
|
|
|
|
|
|
|
|
|
Among the gems in Plan 9 was a rewrite of the venerable Unix make
|
|
|
|
|
command, in the form of mk. Simply put, mk is make, but with a large collection
|
|
|
|
|
of relatively minor improvements, adding up to something more consistent,
|
|
|
|
|
elegant, and powerful. To name a few specifics:
|
2013-02-25 23:52:08 -08:00
|
|
|
|
|
|
|
|
1. Recipes are delimited by any indentation, not tab characters in particular.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Phony targets are handled separately from file targets. Your mkfile won't
|
2013-02-25 23:52:08 -08:00
|
|
|
be broken by having a file named 'clean'.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Attributes instead of weird special targets like `.SECONDARY:`.
|
|
|
|
|
1. Special variables like `$target`, `$prereq`, and `$stem` in place of
|
2013-02-25 23:52:08 -08:00
|
|
|
make's pointlessly cryptic `$@`, `$^`, and `$*`.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. In addition to suffix rules (e.g. `%.o: %.c`), mk has more powerful regular
|
2013-02-25 23:52:08 -08:00
|
|
|
expression rules.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Sane handling of rules with multiple targets.
|
|
|
|
|
1. An optional attribute to delete targets when a recipe fails, so you aren't
|
2013-02-25 23:52:08 -08:00
|
|
|
left with corrupt output.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Plan 9 mkfiles can not only include other mkfiles, but pipe in the output of
|
2013-02-25 23:52:08 -08:00
|
|
|
recipes. Your mkfile can configure itself by doing something like
|
|
|
|
|
`<|sh config.sh`.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. A generalized mechanism to determine if a target is out of date, for when
|
2013-02-25 23:52:08 -08:00
|
|
|
timestamps won't cut it.
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Variables are expanded in recipes only if they are defined. They way you
|
|
|
|
|
usually don't have to escape `$`.
|
2013-02-25 23:52:08 -08:00
|
|
|
|
2013-03-10 19:08:43 -07:00
|
|
|
And much more! Read [Maintaining Files on Plan 9 with
|
|
|
|
|
Mk](http://doc.cat-v.org/plan_9/4th_edition/papers/mk) for good overview.
|
2013-02-25 23:52:08 -08:00
|
|
|
|
|
|
|
|
# Improvements over Plan 9 mk
|
|
|
|
|
|
2013-02-28 22:49:34 -08:00
|
|
|
This mk stays mostly faithful to Plan 9, but makes a few (in my opinion)
|
2013-02-25 23:52:08 -08:00
|
|
|
improvements.
|
|
|
|
|
|
2013-03-09 20:54:13 -08:00
|
|
|
1. A clean, modern implementation in Go, that doesn't depend on the whole Plan
|
|
|
|
|
9 stack.
|
2013-03-10 00:34:42 -08:00
|
|
|
1. Parallel by default. Modern computers can build more than one C file at a
|
|
|
|
|
time. Cases that should not be run in parallel are the exception. Use
|
|
|
|
|
`-p=1` if this is the case.
|
2013-03-09 20:54:13 -08:00
|
|
|
1. Use Go regular expressions, which are perl-like. The original mk used plan9
|
2013-02-28 22:49:34 -08:00
|
|
|
regex, which few people know or care to learn.
|
2014-02-01 19:13:27 -08:00
|
|
|
1. Regex matches are substituted into rule prerequisites with `$stem1`,
|
|
|
|
|
`$stem2`, etc, rather than `\1`, `\2`, etc.
|
2013-02-25 23:52:08 -08:00
|
|
|
1. Allow blank lines in recipes. A recipe is any indented block of text, and
|
2013-03-09 20:54:13 -08:00
|
|
|
continues until a non-indented character or the end of the file. (Similar
|
|
|
|
|
to blocks in Python.)
|
2013-02-28 22:49:34 -08:00
|
|
|
1. Add an 'S' attribute to execute recipes with programs other than sh. This
|
2013-02-25 23:52:08 -08:00
|
|
|
way, you don't have to separate your six line python script into its own
|
2013-03-09 20:54:13 -08:00
|
|
|
file. Just stick it directly in the mkfile.
|
|
|
|
|
1. Pretty colors.
|
2013-02-25 23:52:08 -08:00
|
|
|
|
2014-08-04 13:42:57 -07:00
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
|
|
`mk [options] [target] ...`
|
|
|
|
|
|
|
|
|
|
## Options
|
|
|
|
|
|
|
|
|
|
* `-f filename` Use the given file as the mkfile.
|
|
|
|
|
* `-n` Dry run, print commands without actually executing.
|
|
|
|
|
* `-r` Force building of the immediate targets.
|
|
|
|
|
* `-a` Force building the targets and of all their dependencies.
|
|
|
|
|
* `-p` Maximum number of jobs to execute in parallel (default: 8)
|
|
|
|
|
* `-i` Show rules that will execute and prompt before executing.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Non-shell recipes
|
|
|
|
|
|
|
|
|
|
Non-shell recipes are a major addition over Plan 9 mk. They can be used with the
|
|
|
|
|
`S[command]` attribute, where `command` is an arbitrary command that the recipe
|
|
|
|
|
will be piped into. For example, here's a recipe to add the read numbers from a
|
|
|
|
|
file and write their mean to another file. Unlike a typical recipe, it's written
|
|
|
|
|
in Julia.
|
|
|
|
|
|
|
|
|
|
```make
|
|
|
|
|
mean.txt:Sjulia: input.txt
|
|
|
|
|
println(open("$target", "w"),
|
|
|
|
|
mean(map(parseint, eachline(open("$prereq")))))
|
|
|
|
|
```
|
|
|
|
|
|
2013-02-25 23:52:08 -08:00
|
|
|
# Current State
|
|
|
|
|
|
2013-03-09 20:54:13 -08:00
|
|
|
Functional, but with some bugs and some unimplemented minor features. Give it a
|
|
|
|
|
try and see what you think!
|
2013-02-25 23:52:08 -08:00
|
|
|
|
|
|
|
|
|