General documentation / cheat sheets for various languages and services

Make(file) Documentation

Other good references:

Variables

Special variables

Modifiers:

Best practices, from Pierce etc.'s post

  1. Every target should be a file (use .PHONY sparingly)
  2. File (non-phony) targets should only depend on file targets
  3. Phony targets should have no commands, only dependencies. This doesn't work for make clean, but otherwise it's a good way to group sub-targets under a single target.

Recipes

favicon.ico

Suppose you've designed a logo, and saved it as logo.psd, and want to build a favicon.ico from it. You only have to do this once, really, since logo.psd won'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 $<[0] -resize $*x$* $@ favicon.ico: favicon-16.png favicon-32.png convert $^ $@

site.css

For compiling LESS into (nice) CSS. 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 >$@

TypeScript declarations

There are TypeScript declaration managers out there, but it's just as easy to do it in Make. The build steps below will: 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/$* > $@

Bundling JavaScript with Closure Compiler

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 $+ > $@