From 871a4ba4f8bf3194c58b5776ac518b6eb3c3f33b Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Fri, 17 Apr 2015 03:03:21 +0800 Subject: [PATCH] Make --- make-assets.md | 12 +++--- makefile.md | 114 +++++++++++++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 51 deletions(-) diff --git a/make-assets.md b/make-assets.md index df3408a03..0e1ca970d 100644 --- a/make-assets.md +++ b/make-assets.md @@ -1,16 +1,18 @@ --- title: Make for assets -layout: default +hljs_languages: [makefile] --- ## Basic compiling - bin := ./node_modules/.bin +```makefile +bin := ./node_modules/.bin - all: build/foo.js +all: build/foo.js - build/%.js: src/%.coffee - @$(bin)/coffee < $^ > $@ +build/%.js: src/%.coffee + @$(bin)/coffee < $^ > $@ +``` ## Stylus + Autoprefixer diff --git a/makefile.md b/makefile.md index 0ff0365e7..e7d9fae2f 100644 --- a/makefile.md +++ b/makefile.md @@ -1,31 +1,35 @@ --- title: Makefile -layout: default +hljs_languages: [makefile] --- ## Var assignment - uglify = $(uglify) # assignment - compressor := $(uglify) # lazy assignment - prefix ?= /usr/local # safe assignment +```makefile +uglify = $(uglify) # assignment +compressor := $(uglify) # lazy assignment +prefix ?= /usr/local # safe assignment +``` ## Magic variables - out.o: src.c src.h - $@ - "out.o" (target) - $< - "src.c" (first prerequisite) - $^ - "src.c src.h" (all prerequisites) +```makefile +out.o: src.c src.h + $@ # "out.o" (target) + $< # "src.c" (first prerequisite) + $^ # "src.c src.h" (all prerequisites) - %.o: %.c - $% - target member name ("foo" in "foo.c") +%.o: %.c + $% # target member name ("foo" in "foo.c") - also: - $+ - prerequisites (all, with duplication) - $? - prerequisites (new ones) - $| - prerequisites (order-only?) - $* - basename without extension of the target (?) +also: + $+ # prerequisites (all, with duplication) + $? # prerequisites (new ones) + $| # prerequisites (order-only?) + $* # basename without extension of the target (?) - $(@D) - target directory + $(@D) # target directory +``` ## Command prefixes @@ -35,64 +39,82 @@ layout: default | `@` | Don't print command | | `+` | Run even if Make is in 'don't execute' mode | - build: - @echo "compiling" - -gcc $< $@ +```makefile +build: + @echo "compiling" + -gcc $< $@ - -include .depend +-include .depend +``` ## Find files - js_files := $(wildcard test/*.js) - all_files := $(shell find images -name "*") +```makefile +js_files := $(wildcard test/*.js) +all_files := $(shell find images -name "*") +``` ## Substitutions - file = $(SOURCE:.cpp=.o) # foo.cpp => foo.o - outputs = $(files:src/%.coffee=lib/%.js) +```makefile +file = $(SOURCE:.cpp=.o) # foo.cpp => foo.o +outputs = $(files:src/%.coffee=lib/%.js) - outputs = $(patsubst %.c, %.o, $(wildcard *.c)) - assets = $(patsubst images/%, assets/%, $(wildcard images/*)) +outputs = $(patsubst %.c, %.o, $(wildcard *.c)) +assets = $(patsubst images/%, assets/%, $(wildcard images/*)) +``` ## More functions - $(strip $(string_var)) +```makefile +$(strip $(string_var)) - $(filter %.less, $(files)) - $(filter-out %.less, $(files)) +$(filter %.less, $(files)) +$(filter-out %.less, $(files)) +``` ## Building files - %.o: %.c - ffmpeg -i $< > $@ # Input and output - foo $^ +```makefile +%.o: %.c + ffmpeg -i $< > $@ # Input and output + foo $^ +``` ## Includes - -include foo.make +```makefile +-include foo.make +``` ## Options - make - -e, --environment-overrides - -B, --always-make - -s, --silent +```sh +make + -e, --environment-overrides + -B, --always-make + -s, --silent - -j, --jobs=N # parallel processing + -j, --jobs=N # parallel processing +``` ## Conditionals - foo: $(objects) - ifeq ($(CC),gcc) - $(CC) -o foo $(objects) $(libs_for_gcc) - else - $(CC) -o foo $(objects) $(normal_libs) - endif +```makefile +foo: $(objects) +ifeq ($(CC),gcc) + $(CC) -o foo $(objects) $(libs_for_gcc) +else + $(CC) -o foo $(objects) $(normal_libs) +endif +``` ## Recursive - deploy: - $(MAKE) deploy2 +```makefile +deploy: + $(MAKE) deploy2 +``` ## Further reading