Make
This commit is contained in:
parent
e839dca089
commit
871a4ba4f8
|
@ -1,16 +1,18 @@
|
||||||
---
|
---
|
||||||
title: Make for assets
|
title: Make for assets
|
||||||
layout: default
|
hljs_languages: [makefile]
|
||||||
---
|
---
|
||||||
|
|
||||||
## Basic compiling
|
## Basic compiling
|
||||||
|
|
||||||
bin := ./node_modules/.bin
|
```makefile
|
||||||
|
bin := ./node_modules/.bin
|
||||||
|
|
||||||
all: build/foo.js
|
all: build/foo.js
|
||||||
|
|
||||||
build/%.js: src/%.coffee
|
build/%.js: src/%.coffee
|
||||||
@$(bin)/coffee < $^ > $@
|
@$(bin)/coffee < $^ > $@
|
||||||
|
```
|
||||||
|
|
||||||
## Stylus + Autoprefixer
|
## Stylus + Autoprefixer
|
||||||
|
|
||||||
|
|
92
makefile.md
92
makefile.md
|
@ -1,31 +1,35 @@
|
||||||
---
|
---
|
||||||
title: Makefile
|
title: Makefile
|
||||||
layout: default
|
hljs_languages: [makefile]
|
||||||
---
|
---
|
||||||
|
|
||||||
## Var assignment
|
## Var assignment
|
||||||
|
|
||||||
uglify = $(uglify) # assignment
|
```makefile
|
||||||
compressor := $(uglify) # lazy assignment
|
uglify = $(uglify) # assignment
|
||||||
prefix ?= /usr/local # safe assignment
|
compressor := $(uglify) # lazy assignment
|
||||||
|
prefix ?= /usr/local # safe assignment
|
||||||
|
```
|
||||||
|
|
||||||
## Magic variables
|
## Magic variables
|
||||||
|
|
||||||
out.o: src.c src.h
|
```makefile
|
||||||
$@ - "out.o" (target)
|
out.o: src.c src.h
|
||||||
$< - "src.c" (first prerequisite)
|
$@ # "out.o" (target)
|
||||||
$^ - "src.c src.h" (all prerequisites)
|
$< # "src.c" (first prerequisite)
|
||||||
|
$^ # "src.c src.h" (all prerequisites)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$% - target member name ("foo" in "foo.c")
|
$% # target member name ("foo" in "foo.c")
|
||||||
|
|
||||||
also:
|
also:
|
||||||
$+ - prerequisites (all, with duplication)
|
$+ # prerequisites (all, with duplication)
|
||||||
$? - prerequisites (new ones)
|
$? # prerequisites (new ones)
|
||||||
$| - prerequisites (order-only?)
|
$| # prerequisites (order-only?)
|
||||||
$* - basename without extension of the target (?)
|
$* # basename without extension of the target (?)
|
||||||
|
|
||||||
$(@D) - target directory
|
$(@D) # target directory
|
||||||
|
```
|
||||||
|
|
||||||
## Command prefixes
|
## Command prefixes
|
||||||
|
|
||||||
|
@ -35,64 +39,82 @@ layout: default
|
||||||
| `@` | Don't print command |
|
| `@` | Don't print command |
|
||||||
| `+` | Run even if Make is in 'don't execute' mode |
|
| `+` | Run even if Make is in 'don't execute' mode |
|
||||||
|
|
||||||
build:
|
```makefile
|
||||||
|
build:
|
||||||
@echo "compiling"
|
@echo "compiling"
|
||||||
-gcc $< $@
|
-gcc $< $@
|
||||||
|
|
||||||
-include .depend
|
-include .depend
|
||||||
|
```
|
||||||
|
|
||||||
## Find files
|
## Find files
|
||||||
|
|
||||||
js_files := $(wildcard test/*.js)
|
```makefile
|
||||||
all_files := $(shell find images -name "*")
|
js_files := $(wildcard test/*.js)
|
||||||
|
all_files := $(shell find images -name "*")
|
||||||
|
```
|
||||||
|
|
||||||
## Substitutions
|
## Substitutions
|
||||||
|
|
||||||
file = $(SOURCE:.cpp=.o) # foo.cpp => foo.o
|
```makefile
|
||||||
outputs = $(files:src/%.coffee=lib/%.js)
|
file = $(SOURCE:.cpp=.o) # foo.cpp => foo.o
|
||||||
|
outputs = $(files:src/%.coffee=lib/%.js)
|
||||||
|
|
||||||
outputs = $(patsubst %.c, %.o, $(wildcard *.c))
|
outputs = $(patsubst %.c, %.o, $(wildcard *.c))
|
||||||
assets = $(patsubst images/%, assets/%, $(wildcard images/*))
|
assets = $(patsubst images/%, assets/%, $(wildcard images/*))
|
||||||
|
```
|
||||||
|
|
||||||
## More functions
|
## More functions
|
||||||
|
|
||||||
$(strip $(string_var))
|
```makefile
|
||||||
|
$(strip $(string_var))
|
||||||
|
|
||||||
$(filter %.less, $(files))
|
$(filter %.less, $(files))
|
||||||
$(filter-out %.less, $(files))
|
$(filter-out %.less, $(files))
|
||||||
|
```
|
||||||
|
|
||||||
## Building files
|
## Building files
|
||||||
|
|
||||||
%.o: %.c
|
```makefile
|
||||||
|
%.o: %.c
|
||||||
ffmpeg -i $< > $@ # Input and output
|
ffmpeg -i $< > $@ # Input and output
|
||||||
foo $^
|
foo $^
|
||||||
|
```
|
||||||
|
|
||||||
## Includes
|
## Includes
|
||||||
|
|
||||||
-include foo.make
|
```makefile
|
||||||
|
-include foo.make
|
||||||
|
```
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
make
|
```sh
|
||||||
|
make
|
||||||
-e, --environment-overrides
|
-e, --environment-overrides
|
||||||
-B, --always-make
|
-B, --always-make
|
||||||
-s, --silent
|
-s, --silent
|
||||||
|
|
||||||
-j, --jobs=N # parallel processing
|
-j, --jobs=N # parallel processing
|
||||||
|
```
|
||||||
|
|
||||||
## Conditionals
|
## Conditionals
|
||||||
|
|
||||||
foo: $(objects)
|
```makefile
|
||||||
ifeq ($(CC),gcc)
|
foo: $(objects)
|
||||||
|
ifeq ($(CC),gcc)
|
||||||
$(CC) -o foo $(objects) $(libs_for_gcc)
|
$(CC) -o foo $(objects) $(libs_for_gcc)
|
||||||
else
|
else
|
||||||
$(CC) -o foo $(objects) $(normal_libs)
|
$(CC) -o foo $(objects) $(normal_libs)
|
||||||
endif
|
endif
|
||||||
|
```
|
||||||
|
|
||||||
## Recursive
|
## Recursive
|
||||||
|
|
||||||
deploy:
|
```makefile
|
||||||
|
deploy:
|
||||||
$(MAKE) deploy2
|
$(MAKE) deploy2
|
||||||
|
```
|
||||||
|
|
||||||
## Further reading
|
## Further reading
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue