James Coglan (@jcoglan) was taking about make at Scotland.js, these are my notes from his talk.
I have a project that I need to build. If I'm using grunt I need to pick an apater module and there are numerous choices for the same thing - I want my build tools to use what my app is using. Everything needs it's own adaptor, often things bundle several adaptors which suggests they weren't able to talk to each other.
Making files out of files out of files. Make is a language for describing the relationships between files.
- Target - file we are building
- Dependencies - what do we need to build the target, will build them if it can and needs to
- Recipie - (tab) what we do to the dependencies into the target
$@ is a special var that represents the current target.
$(dir $@) directory name of the file
Varibles are defined as
NAME := value - used as in bash.
It looks at modification times and won't run a rule if it doesn't need running.
Target pattern match:
build/%.js will allow it to figure out what rule applies to a file.
$< The first dependency.
Explicitly enumerate wildcards:
source_files:= $(source_files:%.coffee=build.%.js) Allows us to re-use rules.
Conventional to have a target called
all that will do everything. Add a
.PHONY target that tells it that the target
all isn't a file called "all".
Browserify can list all the dependencies required, we can use the
$(shell ...) command in make to get this.
Make a webpage that can run the test - you can then run that anywhere. This can be run in Phantom or anything that we can run in a shell.
Conventional to have a phony task called
clean - this will do everything from the ground up.
With grunt you have to define the sequence of tasks, with make you define dependencies which means it can figure out what it needs to do for any given task.