From f358103f797f0f0d9b04c4e066fb33d94cf66955 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Mon, 25 Nov 2024 14:28:59 +0100 Subject: [PATCH] dependency ladder example --- slides/makefiles/dependency_ladder/.gitignore | 1 + slides/makefiles/dependency_ladder/makes/books | 16 ++++++++++++++++ slides/makefiles/dependency_ladder/makes/cows | 10 ++++++++++ slides/makefiles/dependency_ladder/makes/forts | 11 +++++++++++ slides/makefiles/dependency_ladder/makes/zoo | 14 ++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 slides/makefiles/dependency_ladder/.gitignore create mode 100644 slides/makefiles/dependency_ladder/makes/books create mode 100644 slides/makefiles/dependency_ladder/makes/cows create mode 100644 slides/makefiles/dependency_ladder/makes/forts create mode 100644 slides/makefiles/dependency_ladder/makes/zoo diff --git a/slides/makefiles/dependency_ladder/.gitignore b/slides/makefiles/dependency_ladder/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/slides/makefiles/dependency_ladder/.gitignore @@ -0,0 +1 @@ +* diff --git a/slides/makefiles/dependency_ladder/makes/books b/slides/makefiles/dependency_ladder/makes/books new file mode 100644 index 0000000..7318a23 --- /dev/null +++ b/slides/makefiles/dependency_ladder/makes/books @@ -0,0 +1,16 @@ +MONTHS != date +%B && date -d '1 month' +%B +IP != dig +short myip.opendns.com @resolver1.opendns.com +CITY != curl -s http://api.db-ip.com/v2/free/$(IP) | grep city | cut -d: -f2 | tr -d '"' + +TITLES = $(MONTHS) +TITLES += $(CITY) + +BOOKS = $(patsubst %,Books/%.md,$(TITLES)) + +$(BOOKS): + @mkdir -p $(@D) + fortune -l > $@ + +progs += $(BOOKS) + +dross += Books/ diff --git a/slides/makefiles/dependency_ladder/makes/cows b/slides/makefiles/dependency_ladder/makes/cows new file mode 100644 index 0000000..fafd761 --- /dev/null +++ b/slides/makefiles/dependency_ladder/makes/cows @@ -0,0 +1,10 @@ +cows = $(patsubst Forts/fortune_%.md,Cows/cow-%.txt,$(wildcard Forts/fortune_*.md)) + +$(cows): Cows/cow-%.txt: Forts/fortune_%.md + @mkdir -p $(@D) + cat $< | cowsay > $@ + +progs += forts +progs += $(cows) +dross += Cows/ + diff --git a/slides/makefiles/dependency_ladder/makes/forts b/slides/makefiles/dependency_ladder/makes/forts new file mode 100644 index 0000000..ee61966 --- /dev/null +++ b/slides/makefiles/dependency_ladder/makes/forts @@ -0,0 +1,11 @@ + +fnums != seq 8 | sort -R | head -2 +forts = $(patsubst %,Forts/fortune_%.md,$(fnums)) + +$(forts): + @mkdir -p $(@D) + fortune -s > $@ + +progs += $(forts) + +dross += Forts/ diff --git a/slides/makefiles/dependency_ladder/makes/zoo b/slides/makefiles/dependency_ladder/makes/zoo new file mode 100644 index 0000000..e4f78b9 --- /dev/null +++ b/slides/makefiles/dependency_ladder/makes/zoo @@ -0,0 +1,14 @@ +filter = $(shell cowsay -l | sort -R | head -1) + +zoo = $(patsubst Forts/fortune_%.md,Zoo/animal-%.md,$(forts)) + +$(zoo): Zoo/animal-%.md: Forts/fortune_%.md + @mkdir -p $(@D) + echo '```' > $@ + cat $< | cowsay -f $(filter) >> $@ + echo '```' >> $@ + +progs += forts +progs += $(zoo) + +dross += Zoo/