outline makefiles

This commit is contained in:
2025-02-07 23:40:13 +01:00
parent 7427b05b0b
commit 2250275be5
3 changed files with 257 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
---
title: "Makefile Graphs"
tags: [ "system", "makefiles", "graph" ]
---
If you have `graph-easy` (often in the package `perl-graph-easy` or similar), you can make a graph from the makefile with `make2graph` (the package is often called `makefile2graph`).
Start with the command to 'make all targets' (`-B`), and 'do a dummy run' (`-n`) with debug into (`-d`):
```bash
make -Bnd
make -Bnd | make2graph
make -Bnd | make2graph | graph-easy --boxart
```

View File

@@ -0,0 +1,57 @@
---
title: "Makefile Patterns"
tags: [ "system", "makefiles" ]
---
Using the [basic example](../Makefile.md), you can make a complete backup of all backup files.
This file will depend upon everything inside the `$(storage_directory)`.
Unlike `bash`, you can't just say `storage_directory/*`: the pattern must be stated as a 'wildcard'.
```make
$(storage_directory)/backup.tgz: $(wildcard $(storage_directory)/*.md)
tar czf $@ $^
```
The `make` rules start by processing variables:
```make
backups/backup.tgz: $(wildcard backups/*.md)
tar czf backups/backup.tgz $^
```
Then the `wildcard` variable equals whichever backup files are in the `backups/` directory:
```make
backups/backup.tgz: backups/backup_29.md backups/backup_30.md
tar czf backups/backup.tgz backups/backup_29.md backups/backup_30.md
```
The phony `backup` target should now point to this tar backup.
```make
current_minute != date +%M
storage_directory = backups
.PHONY: backup
backup: $(storage_directory)/backup.tgz
$(storage_directory)/backup.tgz: $(wildcard $(storage_directory)/*.md)
tar czf $@ $^
README.md: Makefile
echo "Basic makefile example." > $@
echo "" >> $@
echo '```' >> $@
cat $< >> $@
echo '```' >> $@
$(storage_directory)/backup_$(current_minute).md: README.md
mkdir -p $(@D)
cp $< $@
```