diff --git a/slides/makefiles/examples/.gitignore b/slides/makefiles/examples/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/slides/makefiles/examples/.gitignore @@ -0,0 +1 @@ +* diff --git a/slides/makefiles/examples/check b/slides/makefiles/examples/check new file mode 100644 index 0000000..57c1f4f --- /dev/null +++ b/slides/makefiles/examples/check @@ -0,0 +1,8 @@ +CHECKER = command -v +.PHONY: check +check: + $(CHECKER) fortune >/dev/null + $(CHECKER) cowsay >/dev/null + +file: | check + fortune | cowsay > $@ diff --git a/slides/makefiles/examples/pats b/slides/makefiles/examples/pats new file mode 100644 index 0000000..a3e489c --- /dev/null +++ b/slides/makefiles/examples/pats @@ -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 $< $@ + diff --git a/slides/makefiles/examples/rules b/slides/makefiles/examples/rules new file mode 100644 index 0000000..0b93dfd --- /dev/null +++ b/slides/makefiles/examples/rules @@ -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 diff --git a/slides/makefiles/examples/vars b/slides/makefiles/examples/vars new file mode 100644 index 0000000..6dec96a --- /dev/null +++ b/slides/makefiles/examples/vars @@ -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) >> $@ + diff --git a/slides/makefiles/makefiles.md b/slides/makefiles/makefiles.md index 7d760b2..e13da97 100644 --- a/slides/makefiles/makefiles.md +++ b/slides/makefiles/makefiles.md @@ -20,7 +20,7 @@ cargo build --release 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 -- This, that, and these +Readable, but slow: + +```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 $@ +forts/short.txt: forts/ + fortune -s > $@ +forts/long.txt: forts/ + fortune -l > $@ +``` -release/index.html: index.html release/ - cp $< $@ +*** -index.html: backups.zip - unzip $< +# Gotcha: Directories + + +```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 -- From your shell. -- New variables. -- Filenames as variables. -- *Gotcha*: no shell variables, only make! +```make vars +include /etc/os-release +DAY != date +%d +MESSAGE != fortune -s -## Equality +motd_$(DAY): + $(info Placing message:) + echo "Welcome to $(NAME)" > $@ + echo $(MESSAGE) >> $@ +``` -- Variables with '=', never ':='. -- *Gotcha*: one shell per line. -- Variables as shell output. +### Gotcha: Hanging Quotes +> 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="