Making websites with Make: a comparison of build tools
Now build times are fast thanks to Make only building files that have changed and compiling branches of the dependency tree in parallel. Make's declarative approach combined with pattern matching just feels right. Most of all, Make is fun. It's not often that you get to write code like this:
@cat $^ > $@
Make is a small language so the esoteric syntax isn't really hard to grasp.
Good Makefile tutorials covering general principles are hard to find, most being too short and focussed on C/C++ details, but Rob has an accompanying blog post and git repo which are a great place to start. The GNU make manual is also rather good.
The basic process is to first gather your input file paths and work out your output file paths. For example:
HTML_INPUTS = $(wildcard src/*.html) HTML_OUTPUTS = $(patsubst src/%,dist/%,$(HTML_INPUTS))
The above stores a list of HTML input file paths in the HTML_INPUTS variable, then creates a list of HTML output file paths by pattern matching; replacing 'src/' with 'dist/' in the list of inputs.
Then work backwards, starting with your outputs, write rules to create them from their dependencies, and their dependencies from their dependencies' dependencies and so on. A rule consists of target(s) (outputs) followed by a colon and their prerequisites (dependencies) on one line. Subsequent tab indented lines define a recipe to make the targets from the prerequisites.
dist/%.html: src/%.html @cp $< $@
This states that the HTML files in dist/ depend on the HTML files in src/, and the recipe simply copies files from one to the other.
- Make is a general purpose, unopinionated build tool which can be used to build everything, easily, which is great if your project includes Python/PHP/whatever.
- Make is just a build tool, there's no conflation with task running.
But Make can't inline your SVGs and pass your PNGs through a Gaussian filter constructed from atmospheric noise whilst making you a cup of tea.
Make isn't portable, QED.
To state the obvious, if your team doesn't use Windows then this doesn't actually matter. If they do, then it's the usual tradeoff between greater software choice/quality and greater compatibility. Or run Linux in Windows, of which there are many ways.
UPDATE 06/07/2018: See our followup on how to watch for file system changes.