2024-11-12 02:58:47 +00:00
|
|
|
---
|
|
|
|
title:
|
|
|
|
- Making Makefiles
|
|
|
|
author:
|
|
|
|
- Malin
|
|
|
|
|
|
|
|
theme:
|
|
|
|
- Warsaw
|
|
|
|
colortheme:
|
|
|
|
- orchid
|
|
|
|
---
|
|
|
|
|
|
|
|
# Intro
|
|
|
|
|
2024-11-13 13:23:44 +00:00
|
|
|
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
|
|
|
|
|
2024-11-12 02:58:47 +00:00
|
|
|
- input, process, output.
|
|
|
|
- automatic idempotence
|
2024-11-13 13:23:44 +00:00
|
|
|
|
|
|
|
```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
|
|
|
|
|
2024-11-12 02:58:47 +00:00
|
|
|
- *Gotcha*: directories
|
|
|
|
- This, that, and these
|
|
|
|
|
|
|
|
***
|
|
|
|
|
2024-11-13 13:23:44 +00:00
|
|
|
## 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 $<
|
|
|
|
```
|
|
|
|
|
|
|
|
***
|
|
|
|
|
2024-11-12 02:58:47 +00:00
|
|
|
# Variables
|
|
|
|
|
|
|
|
- From your shell.
|
|
|
|
- New variables.
|
|
|
|
- Filenames as variables.
|
|
|
|
- *Gotcha*: no shell variables, only make!
|
|
|
|
|
|
|
|
## Equality
|
|
|
|
|
|
|
|
- Variables with '=', never ':='.
|
|
|
|
- *Gotcha*: one shell per line.
|
|
|
|
- Variables as shell output.
|
|
|
|
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
|
|
|
|
# Phonies, and the Problems with Lies
|
|
|
|
|
|
|
|
- clean (common)
|
|
|
|
- check (excellent)
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
|
|
|
|
## Non-Compiling Checks
|
|
|
|
|
|
|
|
- `make` -n
|
|
|
|
- *Gotcha*: shell output variables.
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
|
|
|
|
# The Fourth Sigil: `%`
|
|
|
|
|
|
|
|
- Standard rules, e.g. ImageMagick, copying, et c.
|
|
|
|
- *Gotcha*: intermediaries are deleted.
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
# Bling: make2graph
|
|
|
|
|
|
|
|
- *Gotcha*: completely outdated.
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
# Inclusivity
|
|
|
|
|
|
|
|
- `include dir/Makefile`
|
|
|
|
- *Gotcha*: directory has not changed
|
|
|
|
- `$(MAKEFILE_LIST)`
|
|
|
|
|
|
|
|
|
|
|
|
# Special Commands
|
|
|
|
|
2024-11-13 13:23:44 +00:00
|
|
|
- dir
|
|
|
|
- `DIR = test -d $(dir $@) || mkdir $(dir $@)`
|
2024-11-12 02:58:47 +00:00
|
|
|
- patsubst
|
|
|
|
- Wildcards (or not?)
|
|
|
|
|
|
|
|
# Maintanance
|
|
|
|
|
|
|
|
- backups
|
|
|
|
- saving files
|