From e59538a3bdcfd53ef3e84f346b94102281ec1891 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Wed, 13 Nov 2024 14:23:44 +0100 Subject: [PATCH] place example makefiles --- slides/makefiles/examples/fort_1 | 13 ++++++ slides/makefiles/examples/fort_2 | 15 ++++++ slides/makefiles/makefiles.md | 78 ++++++++++++++++++++++++++++++-- 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 slides/makefiles/examples/fort_1 create mode 100644 slides/makefiles/examples/fort_2 diff --git a/slides/makefiles/examples/fort_1 b/slides/makefiles/examples/fort_1 new file mode 100644 index 0000000..ce17c40 --- /dev/null +++ b/slides/makefiles/examples/fort_1 @@ -0,0 +1,13 @@ + +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 + diff --git a/slides/makefiles/examples/fort_2 b/slides/makefiles/examples/fort_2 new file mode 100644 index 0000000..e9202a1 --- /dev/null +++ b/slides/makefiles/examples/fort_2 @@ -0,0 +1,15 @@ + +forts/big_fort.txt: forts/short.txt forts/long.txt + cat $^ > $@ + +forts/: + mkdir $@ + +forts/short.txt: forts/ + fortune -s > $@ + +forts/long.txt: forts/ + fortune -l > $@ + +clean: + rm -rf forts diff --git a/slides/makefiles/makefiles.md b/slides/makefiles/makefiles.md index 56980cc..7d760b2 100644 --- a/slides/makefiles/makefiles.md +++ b/slides/makefiles/makefiles.md @@ -12,13 +12,86 @@ colortheme: # Intro +The fundamental problem: + +```bash +git submodule update --init soundscape +cargo build --release +install -pm755 target/release/tap /usr/local/bin/ +``` + +You can't type this after every test. + +*** + +## First Solution + +```bash +#!/bin/sh +git submodule update --init soundscape +cargo build --release +install -pm755 target/release/tap /usr/local/bin/ +``` + +At this point, every test takes 10 minutes. + +## Second Solution + +```bash +#!/bin/sh +[ -f soundscape/.git ] || git submodule update --init soundscape +[ -f target/release/tap ] || cargo build --release +[ -f target/release/tap ] || \ + install -pm755 target/release/tap /usr/local/bin/ +``` + +*** + +# Makefile Solutions + - input, process, output. - automatic idempotence + +```bash +INSTALL_DIR = /usr/local/bin + +soundscape/.git: + git submodule update --init soundscape + +/usr/local/bin/tap: target/release/tap + install -pm755 target/release/tap $(INSTALL_DIR) + +target/release/tap: src soundscape/.git + cargo build --release +``` + +*** + +# Basic + - *Gotcha*: directories - This, that, and these *** +## Repetition, Repetition, Repetition + +```make +.PHONY: output +output: release/index.html + +release/: backups.zip + mkdir $@ + +release/index.html: index.html release/ + cp $< $@ + +index.html: backups.zip + unzip $< +``` + +*** + # Variables - From your shell. @@ -59,7 +132,6 @@ colortheme: *** - # Bling: make2graph - *Gotcha*: completely outdated. @@ -75,8 +147,8 @@ colortheme: # Special Commands -- dirname -- `DIR = test -d $(dirname $@) || mkdir $(dirname $@)` +- dir +- `DIR = test -d $(dir $@) || mkdir $(dir $@)` - patsubst - Wildcards (or not?)