Other good references:
VAR, must be accessed using
$VAR(which would be interpreted as
=defines a recursively expanded variable; the right-hand side is expanded lazily (when the variable's value is used elsewhere), so it can contain references to variables defined later.
:=defines a simply expanded variable; it is expanded immediately and set permanently.
?=defines a variable iff it not already defined.
$@: The file on the left side of the rule, i.e., the file currently being made; the "target".
$<: The first dependency on the right side of the rule. This should the main dependency. Often we see the sequence
<$<in a build step;
$<is the input, and it looks like the STDIN file descriptor.
$+: A list of all dependencies on the right side of the rule.
$+, but unique'd.
$?: All of the dependencies that are newer than the target — the files that are triggering the rule, i.e., the why?
$|: Everything after a
|in the dependencies.
$*: The value matched by the
%wildcard in the build step's rule.
$$: A literal dollar sign. Useful when writing bash scripts in make build steps.
Dto any special variable to get just the directory part of the filepath, e.g.,
$(+D); shorthand for
Fto any special variable to get just the file part of the filepath.
make clean, but otherwise it's a good way to group sub-targets under a single target.
$| to skip existing files:
%.min.js: | %.js ng-annotate -a $| | closure-compiler --language_in ECMASCRIPT5 --warning_level QUIET > $@
logo.psd, and want to build a
favicon.icofrom it. You only have to do this once, really, since
logo.psdwon't change (often), but it's nice to just stick the process in your Makefile and let make handle it.
all: favicon.ico .INTERMEDIATE: favicon-16.png favicon-32.png favicon-%.png: logo.psd convert $< -resize $*x$* $@ favicon.ico: favicon-16.png favicon-32.png convert $^ $@
filenametells ImageMagick to pull off the composited layer from the original PSD.
.INTERMEDIATEtarget tells Make to remove the resized images after they've been composed into
package.jsonwill install the LESS compiler and the
clean-cssminifier, run the command:
npm install --save-dev clean-css less
BIN := node_modules/.bin all: site.css $(BIN)/lessc $(BIN)/cleancss: npm install %.css: %.less $(BIN)/lessc $(BIN)/cleancss $(BIN)/lessc $< | $(BIN)/cleancss --keep-line-breaks --skip-advanced >$@
DTS := mocha/mocha node/node yargs/yargs all: type_declarations type_declarations: $(DTS:%=type_declarations/%.d.ts) type_declarations/%: mkdir -p $(@D) curl -s https://raw.githubusercontent.com/chbrown/DefinitelyTyped/master/$* > $@
Declare a list of scripts that will all be in a predictable place, by name:
SCRIPTS = underscore jquery angular ngStorage
Now both minify them, for production, and cat them together, for development, without having to repeat the names:
compiled.min.js: $(SCRIPTS:%=scripts/%.min.js) closure-compiler --js $+ > $@ compiled.max.js: $(SCRIPTS:%=scripts/%.js) cat $+ > $@