Skip to content

Commit

Permalink
place all example Make scripts into separate Makefiles and add them v…
Browse files Browse the repository at this point in the history
…ia minted to the slides
  • Loading branch information
chrbeckm committed Sep 21, 2024
1 parent b3d722d commit 5a1cec3
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 129 deletions.
80 changes: 7 additions & 73 deletions make/content/advanced.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,7 @@

\begin{frame}[fragile]{Vergleich: Kuchen backen}
\begin{center}
\begin{minted}{make}
Kuchen: Teig Backofen
Ofen auf 140°C vorheizen
Teig in Backform geben und in den Ofen schieben
Kuchen nach 40 min herausnehmen

Teig: Eier Mehl Zucker Milch Rumrosinen | Schüssel
Eier schlagen
Mehl, Zucker und Milch hinzugeben
Rumrosinen unterrühren

Rumrosinen: Rum Rosinen
Rosinen in Rum einlegen
Vier Wochen stehen lassen

Schüssel:
Rührschüssel auf den Tisch stellen, wenn nicht vorhanden

clean:
Kuchen essen
Küche sauber machen und aufräumen
\end{minted}
\inputminted{make}{example-files/Cake}
\end{center}
\end{frame}

Expand All @@ -34,30 +13,13 @@
Problem: Manchmal führt \texttt{make} Skripte gleichzeitig zweimal aus (hier \texttt{plot.py})
\begin{center}
\small
\begin{minted}{make}
all: report.txt

report.txt: plot1.pdf plot2.pdf
touch report.txt

plot1.pdf plot2.pdf: plot.py data.txt
python plot.py # plot.py produziert sowohl plot1.pdf als auch plot2.pdf
\end{minted}
\inputminted{make}{example-files/Advanced-0}
\end{center}

Lösung: Ein \texttt{make}-Feature (\texttt{v4.3}): \emph{grouped targets}
\begin{center}
\small
\begin{minted}{make}
all: report.txt

report.txt: plot1.pdf plot2.pdf
touch report.txt

plot2.pdf plot1.pdf &: plot.py data.txt # das &: definiert die targets als group
python plot.py

\end{minted}
\inputminted{make}{example-files/Advanced-1}
\end{center}
→ Alle \texttt{targets} werden durch eine einzigen Durchlauf der \texttt{recipe} (gebündelt) erzeugt.
\end{frame}
Expand All @@ -69,30 +31,12 @@

\begin{center}
\small
\begin{minted}{make}
all: report.txt

report.txt: plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf
touch report.txt

plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf & : plot.py data.txt
python plot.py # plot.py produziert alle plot{i}.pdf
\end{minted}
\inputminted{make}{example-files/Advanced-2}
\end{center}
Lösung: Ein weiteres \texttt{make}-Feature: \emph{variables}
\begin{center}
\small
\begin{minted}{make}
all: report.txt

script_targets = plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf # Variablen Definition

report.txt: $(script_targets) # Variablen Verwendung
touch report.txt
$(script_targets) & : plot.py data.txt # Variablen Verwendung
python plot.py
\end{minted}
\inputminted{make}{example-files/Advanced-3}
\end{center}
\end{frame}

Expand All @@ -103,16 +47,6 @@
\texttt{addsuffix .pdf} hängt an jeden Dateinamen die Endung \texttt{.pdf} an.
\begin{center}
\small
\begin{minted}{make}
all: report.txt

plots = $(addprefix build/, $(addsuffix .pdf, plot1 plot2 plot3 plot4)) # Definition

report.txt: $(plots) # Verwendung
touch report.txt
$(plots) & : plot.py data.txt # Verwendung
python plot.py
\end{minted}
\inputminted{make}{example-files/Advanced-4}
\end{center}
\end{frame}
\end{frame}
23 changes: 2 additions & 21 deletions make/content/build.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
(Nützliche) Konvention: \texttt{make clean} löscht alle vom \texttt{Makefile} erstellten Dateien/Ordner.

\begin{center}
\begin{minted}{make}
clean:
rm plot.pdf report.pdf
\end{minted}
\inputminted{make}{example-files/Simple-clean}
\end{center}

Das Projekt sollte dann so aussehen, wie vor dem ersten Ausführen von \texttt{make}.
Expand All @@ -17,23 +14,7 @@
\texttt{build}-Ordner: Projekt sauber halten

\begin{center}
\begin{minted}{make}
all: build/report.pdf

build/plot.pdf: plot.py data.txt | build
python plot.py # savefig('build/plot.pdf')

build/report.pdf: report.tex build/plot.pdf | build
lualatex --output-directory=build report.tex

build:
mkdir -p build

clean:
rm -rf build

.PHONY: all clean
\end{minted}
\inputminted{make}{example-files/First-build-dir}
\end{center}

\begin{itemize}
Expand Down
16 changes: 1 addition & 15 deletions make/content/latexmk.tex
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,7 @@

\begin{frame}[fragile]{\texttt{latexmk} im \texttt{Makefile}}
\begin{block}{Im \texttt{Makefile}}
\begin{minted}{make}
build/file.pdf: FORCE plots... tabellen...
TEXINPUTS=build: \
max_print_line=1048576 \
latexmk \
--lualatex \
--output-directory=build \
--interaction=nonstopmode \
--halt-on-error \
file.tex

FORCE:

.PHONY: FORCE all clean
\end{minted}
\inputminted{make}{example-files/Latexmk}
\end{block}

\begin{itemize}
Expand Down
23 changes: 3 additions & 20 deletions make/content/simple_start.tex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
\item \texttt{Makefile} besteht aus Regeln (Rules):
\end{itemize}
\begin{block}{Rule}
\centering
\begin{minted}{make}
target: prerequisites
recipe
\end{minted}
\inputminted{make}{example-files/Basic-block}
\end{block}
\begin{description}
\item[\texttt{\hphantom{prerequisites}\llap{target}}] Datei(en), die von dieser Rule erzeugt werden
Expand All @@ -26,10 +22,7 @@

\begin{frame}[fragile]{Einfachstes Beispiel}
\begin{center}
\begin{minted}{make}
plot.pdf: plot.py data.txt
python plot.py
\end{minted}
\inputminted{make}{example-files/Basic-block-example}
\end{center}
\begin{itemize}
\item Wir wollen \texttt{plot.pdf} erzeugen (\texttt{target})
Expand All @@ -42,17 +35,7 @@

\begin{frame}[fragile]{Beispiel}
\begin{center}
\begin{minted}{make}
all: report.pdf # convention

plot.pdf: plot.py data.txt
python plot.py

report.pdf: report.tex
lualatex report.tex

report.pdf: plot.pdf # add prerequisite
\end{minted}
\inputminted{make}{example-files/First-report}
\end{center}
\vspace{1em}

Expand Down
7 changes: 7 additions & 0 deletions make/example-files/Advanced-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: report.txt

report.txt: plot1.pdf plot2.pdf
touch report.txt

plot1.pdf plot2.pdf: plot.py data.txt
python plot.py # plot.py produziert sowohl plot1.pdf als auch plot2.pdf
7 changes: 7 additions & 0 deletions make/example-files/Advanced-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: report.txt

report.txt: plot1.pdf plot2.pdf
touch report.txt

plot2.pdf plot1.pdf &: plot.py data.txt # das &: definiert die targets als group
python plot.py
7 changes: 7 additions & 0 deletions make/example-files/Advanced-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: report.txt

report.txt: plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf
touch report.txt

plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf & : plot.py data.txt
python plot.py # plot.py produziert alle plot{i}.pdf
9 changes: 9 additions & 0 deletions make/example-files/Advanced-3
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: report.txt

script_targets = plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf # Variablen Definition

report.txt: $(script_targets) # Variablen Verwendung
touch report.txt

$(script_targets) & : plot.py data.txt # Variablen Verwendung
python plot.py
9 changes: 9 additions & 0 deletions make/example-files/Advanced-4
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: report.txt

plots = $(addprefix build/, $(addsuffix .pdf, plot1 plot2 plot3 plot4)) # Definition

report.txt: $(plots) # Verwendung
touch report.txt

$(plots) & : plot.py data.txt # Verwendung
python plot.py
2 changes: 2 additions & 0 deletions make/example-files/Basic-block
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target: prerequisites
recipe
2 changes: 2 additions & 0 deletions make/example-files/Basic-block-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plot.pdf: plot.py data.txt
python plot.py
20 changes: 20 additions & 0 deletions make/example-files/Cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Kuchen: Teig Backofen
Ofen auf 140°C vorheizen
Teig in Backform geben und in den Ofen schieben
Kuchen nach 40 min herausnehmen

Teig: Eier Mehl Zucker Milch Rumrosinen | Schüssel
Eier schlagen
Mehl, Zucker und Milch hinzugeben
Rumrosinen unterrühren

Rumrosinen: Rum Rosinen
Rosinen in Rum einlegen
Vier Wochen stehen lassen

Schüssel:
Rührschüssel auf den Tisch stellen, wenn nicht vorhanden

clean:
Kuchen essen
Küche sauber machen und aufräumen
15 changes: 15 additions & 0 deletions make/example-files/First-build-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all: build/report.pdf

build/plot.pdf: plot.py data.txt | build
python plot.py # savefig('build/plot.pdf')

build/report.pdf: report.tex build/plot.pdf | build
lualatex --output-directory=build report.tex

build:
mkdir -p build

clean:
rm -rf build

.PHONY: all clean
9 changes: 9 additions & 0 deletions make/example-files/First-report
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: report.pdf # convention

plot.pdf: plot.py data.txt
python plot.py

report.pdf: report.tex
lualatex report.tex

report.pdf: plot.pdf # add prerequisite
13 changes: 13 additions & 0 deletions make/example-files/Latexmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build/file.pdf: FORCE plots... tabellen...
TEXINPUTS=build: \
max_print_line=1048576 \
latexmk \
--lualatex \
--output-directory=build \
--interaction=nonstopmode \
--halt-on-error \
file.tex

FORCE:

.PHONY: FORCE all clean
2 changes: 2 additions & 0 deletions make/example-files/Simple-clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
clean:
rm plot.pdf report.pdf

0 comments on commit 5a1cec3

Please sign in to comment.