finish examples
This commit is contained in:
		
							
								
								
									
										1
									
								
								slides/makefiles/examples/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								slides/makefiles/examples/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | * | ||||||
							
								
								
									
										8
									
								
								slides/makefiles/examples/check
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								slides/makefiles/examples/check
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | CHECKER = command -v | ||||||
|  | .PHONY: check | ||||||
|  | check: | ||||||
|  | 	$(CHECKER) fortune >/dev/null | ||||||
|  | 	$(CHECKER) cowsay >/dev/null | ||||||
|  |  | ||||||
|  | file: | check | ||||||
|  | 	fortune | cowsay > $@ | ||||||
							
								
								
									
										18
									
								
								slides/makefiles/examples/pats
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								slides/makefiles/examples/pats
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | IMAGES = $(wildcard jpgs/*) | ||||||
|  | COL = $(patsubst jpgs/%,collection/%,$(IMAGES)) | ||||||
|  |  | ||||||
|  | .PHONY: help | ||||||
|  | help: | ||||||
|  | 	$(info try 'show' or 'output') | ||||||
|  | .PHONY: show | ||||||
|  | show: | ||||||
|  | 	$(info IMAGES is $(IMAGES)) | ||||||
|  | 	$(info Col is $(COL)) | ||||||
|  |  | ||||||
|  | .PHONY: output | ||||||
|  | output: $(COL) | ||||||
|  |  | ||||||
|  | collection/%.jpg: jpgs/%.jpg | ||||||
|  | 	mkdir -p $(@D) | ||||||
|  | 	cp $< $@ | ||||||
|  |  | ||||||
							
								
								
									
										15
									
								
								slides/makefiles/examples/rules
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								slides/makefiles/examples/rules
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | CP = ln -f | ||||||
|  |  | ||||||
|  | output: pngs/ldap.png | ||||||
|  |  | ||||||
|  | jpgs/ldap.jpg: ../../ldap/ldap.jpg | ||||||
|  | 	mkdir -p $(dir $@) | ||||||
|  | 	$(CP) $< $@ | ||||||
|  |  | ||||||
|  | pngs/%.png: jpgs/%.jpg | ||||||
|  | 	mkdir -p $(dir $@) | ||||||
|  | 	$(info making $(@F) in $(@D)) | ||||||
|  | 	magick $< $@ | ||||||
|  |  | ||||||
|  | clean: | ||||||
|  | 	$(RM) -r pngs jpgs | ||||||
							
								
								
									
										10
									
								
								slides/makefiles/examples/vars
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								slides/makefiles/examples/vars
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | include /etc/os-release | ||||||
|  | DAY != date +%d | ||||||
|  | MESSAGE != fortune -s | ||||||
|  |  | ||||||
|  | motd_$(DAY): | ||||||
|  | 	$(info Hello $(USER)) | ||||||
|  | 	$(info Placing message:) | ||||||
|  | 	echo "Welcome to $(NAME)" > $@ | ||||||
|  | 	echo $(MESSAGE) >> $@ | ||||||
|  |  | ||||||
| @@ -20,7 +20,7 @@ cargo build --release | |||||||
| install -pm755 target/release/tap /usr/local/bin/ | install -pm755 target/release/tap /usr/local/bin/ | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| You can't type this after every test. | *But you can't type this for run.* | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| @@ -67,52 +67,170 @@ target/release/tap: src soundscape/.git | |||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| # Basic | # The Three Sigils | ||||||
|  |  | ||||||
| - *Gotcha*: directories | Readable, but slow: | ||||||
| - This, that, and these |  | ||||||
|  | ```make fort_1 | ||||||
|  | forts/big_fort.txt: forts/short.txt forts/long.txt | ||||||
|  | 	cat forts/short.txt forts/long.txt > forts/big_fort.txt | ||||||
|  |  | ||||||
|  | forts/: | ||||||
|  | 	mkdir forts | ||||||
|  |  | ||||||
|  | forts/short.txt: forts/ | ||||||
|  | 	fortune -s > forts/short.txt | ||||||
|  |  | ||||||
|  | forts/long.txt: forts/ | ||||||
|  | 	fortune -l > forts/long.txt | ||||||
|  | ``` | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| ## Repetition, Repetition, Repetition | | Make this | From That | From These | | ||||||
|  | |:---------:|:---------:|:----------:| | ||||||
|  | |  `$@`     |  `$<`     |   `$^`     | | ||||||
|  |  | ||||||
| ```make |  | ||||||
| .PHONY: output |  | ||||||
| output: release/index.html |  | ||||||
|  |  | ||||||
| release/: backups.zip | ```make fort_2 | ||||||
|  | forts/big_fort.txt: forts/short.txt forts/long.txt | ||||||
|  | 		cat $^ > $@ | ||||||
|  |  | ||||||
|  | forts/: README.md | ||||||
| 	mkdir $@ | 	mkdir $@ | ||||||
|  | forts/short.txt: forts/ | ||||||
|  | 	fortune -s > $@ | ||||||
|  | forts/long.txt: forts/ | ||||||
|  | 	fortune -l > $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
| release/index.html: index.html release/ | *** | ||||||
| 	cp  $< $@ |  | ||||||
|  |  | ||||||
| index.html: backups.zip | # Gotcha: Directories | ||||||
| 	unzip $< |  | ||||||
|  |  | ||||||
|  | ```make fort_2 | ||||||
|  | forts/big_fort.txt: forts/short.txt forts/long.txt | ||||||
|  | 		cat $^ > $@ | ||||||
|  |  | ||||||
|  | forts/: README.md | ||||||
|  | 	mkdir $@ | ||||||
|  | forts/short.txt: forts/ | ||||||
|  | 	fortune -s > $@ | ||||||
|  | forts/long.txt: forts/ | ||||||
|  | 	fortune -l > $@ | ||||||
|  |  | ||||||
|  | README.md: | ||||||
|  |     echo "Find the fortunes in the fort dir" > $@ | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| # Variables | # Variables | ||||||
|  |  | ||||||
| - From your shell. | ```make vars | ||||||
| - New variables. | include /etc/os-release | ||||||
| - Filenames as variables. | DAY != date +%d | ||||||
| - *Gotcha*: no shell variables, only make! | MESSAGE != fortune -s | ||||||
|  |  | ||||||
| ## Equality | motd_$(DAY): | ||||||
|  | 	$(info Placing message:) | ||||||
|  | 	echo "Welcome to $(NAME)" > $@ | ||||||
|  | 	echo $(MESSAGE) >> $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
| - Variables with '=', never ':='. | ### Gotcha: Hanging Quotes | ||||||
| - *Gotcha*: one shell per line. |  | ||||||
| - Variables as shell output. |  | ||||||
|  |  | ||||||
|  | > echo "Welcome to "Arch Linux"" | ||||||
|  |  | ||||||
|  | *** | ||||||
|  |  | ||||||
|  | ## Add New Variables | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | make -f vars -e MESSAGE="Red alert, all hands on deck!" | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### Gotcha: Quote, or Risk Escape | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | make -f vars -e MESSAGE="<h1> HTML Headers </h1>" | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | *** | ||||||
|  |  | ||||||
|  | # Gotcha: Variables from Shell | ||||||
|  |  | ||||||
|  | This works: | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | file: | ||||||
|  |     $(info Hello $(USER)) | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ...but not this: | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | file: | ||||||
|  |     user=bob | ||||||
|  |     echo $user | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | Nor this: | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | numbers: | ||||||
|  |     for x in 1 2 3 4 5; do | ||||||
|  |         echo $x | ||||||
|  |     done > $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | Nor this: | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | numbers: | ||||||
|  |     for x in 1 2 3 4 5; do echo $x ; done > $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | *** | ||||||
|  |  | ||||||
|  | ### Ugly Fixes are Ugly | ||||||
|  |  | ||||||
|  | This works, but don't. | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | file: | ||||||
|  | 	for x in 1 2 ;\ | ||||||
|  | 			do echo $$x ;\ | ||||||
|  | 	done > $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
|  |  | ||||||
| # Phonies, and the Problems with Lies | # Phonies, and the Problems with Lies | ||||||
|  |  | ||||||
| - clean (common) | ## Clean | ||||||
| - check (excellent) |  | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | .PHONY: clean | ||||||
|  | clean: | ||||||
|  |     git clean -fdX | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ## Gotcha: Recompiling without Changes | ||||||
|  |  | ||||||
|  | ```make | ||||||
|  | CHECKER = command -v | ||||||
|  | .PHONY: check | ||||||
|  | check: | ||||||
|  | 	$(CHECKER) fortune >/dev/null | ||||||
|  | 	$(CHECKER) cowsay >/dev/null | ||||||
|  |  | ||||||
|  | file: check # Needs a '|' | ||||||
|  | 	fortune | cowsay > $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| @@ -127,32 +245,79 @@ index.html: backups.zip | |||||||
|  |  | ||||||
| # The Fourth Sigil: `%` | # The Fourth Sigil: `%` | ||||||
|  |  | ||||||
| - Standard rules, e.g. ImageMagick, copying, et c. | Create standardized rules with `%`. | ||||||
| - *Gotcha*: intermediaries are deleted. |  | ||||||
|  |  | ||||||
|  | ```make rules | ||||||
|  | CP = ln -f | ||||||
|  |  | ||||||
|  | output: pngs/ldap.png | ||||||
|  |  | ||||||
|  | jpgs/ldap.jpg: ../../ldap/ldap.jpg | ||||||
|  | 	mkdir -p $(dir $@) | ||||||
|  | 	$(CP) $< $@ | ||||||
|  |  | ||||||
|  | pngs/%.png: jpgs/%.jpg | ||||||
|  | 	mkdir -p $(dir $@) | ||||||
|  | 	$(info making $(@F) in $(@D)) | ||||||
|  | 	magick $< $@ | ||||||
|  | ``` | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| # Bling: make2graph | # Bling: makefile2graph | ||||||
|  |  | ||||||
| - *Gotcha*: completely outdated. | ```graph | ||||||
|  |  | ||||||
|  | ┌────────────────┐     ┌────────────────────┐ | ||||||
|  | │ forts/long.txt │ ◀── │       forts/       │ | ||||||
|  | └────────────────┘     └────────────────────┘ | ||||||
|  |   │                      │ | ||||||
|  |   │                      │ | ||||||
|  |   │                      ▼ | ||||||
|  |   │                    ┌────────────────────┐ | ||||||
|  |   │                    │  forts/short.txt   │ | ||||||
|  |   │                    └────────────────────┘ | ||||||
|  |   │                      │ | ||||||
|  |   │                      │ | ||||||
|  |   │                      ▼ | ||||||
|  |   │                    ┌────────────────────┐ | ||||||
|  |   └──────────────────▶ │ forts/big_fort.txt │ | ||||||
|  |                        └────────────────────┘ | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### Gotcha: The Binary is Called `make2graph` | ||||||
|  |  | ||||||
|  | - Works with GUI tools maybe, IDK, I don't use Windows. | ||||||
|  | - Some systems can use `graph-easy`, but it's outdated. | ||||||
|  |  | ||||||
| *** | *** | ||||||
|  |  | ||||||
| # Inclusivity | # Patsubst and Wildcards | ||||||
|  |  | ||||||
| - `include dir/Makefile` |  | ||||||
| - *Gotcha*: directory has not changed |  | ||||||
| - `$(MAKEFILE_LIST)` |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # Special Commands | ```make pats | ||||||
|  | IMAGES = $(wildcard jpgs/*) | ||||||
|  | COL = $(patsubst jpgs/%,collection/%,$(IMAGES)) | ||||||
|  |  | ||||||
| - dir | .PHONY: show | ||||||
| - `DIR = test -d $(dir $@) || mkdir $(dir $@)` | show: | ||||||
| - patsubst | 	$(info IMAGES is $(IMAGES)) | ||||||
| - Wildcards (or not?) | 	$(info Col is $(COL)) | ||||||
|  |  | ||||||
| # Maintanance | .PHONY: output | ||||||
|  | output: $(COL) | ||||||
|  |  | ||||||
|  | collection/%.jpg: jpgs/%.jpg | ||||||
|  | 	mkdir -p $(@D) | ||||||
|  | 	cp $< $@ | ||||||
|  |  | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | *** | ||||||
|  |  | ||||||
|  | # Use Cases | ||||||
|  |  | ||||||
|  | - Backups | ||||||
|  | - Making Websites | ||||||
|  |  | ||||||
| - backups |  | ||||||
| - saving files |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user