From ed40d92b6654372c831986bce9bc51e0980b8bb8 Mon Sep 17 00:00:00 2001 From: Joshua Luckey Date: Thu, 19 Sep 2024 00:04:40 +0200 Subject: [PATCH 1/4] changed solution to parallelisation to use grouped targets --- make/content/advanced.tex | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/make/content/advanced.tex b/make/content/advanced.tex index 7ec2f577..4b337289 100644 --- a/make/content/advanced.tex +++ b/make/content/advanced.tex @@ -33,6 +33,7 @@ Problem: Manchmal führt \texttt{make} Skripte gleichzeitig zweimal aus (hier \texttt{plot.py}) \begin{center} + \small \begin{minted}{make} all: report.txt @@ -44,16 +45,21 @@ \end{minted} \end{center} - Lösung: manuell synchronisieren + Lösung: Ein \texttt{make}-Feature (\texttt{v4.3}): \emph{grouped targets} \begin{center} - $\vdots$ \\ + \small \begin{minted}{make} - plot1.pdf: plot.py data.txt + 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 - plot2.pdf: plot1.pdf \end{minted} \end{center} + → Alle \texttt{targets} werden durch eine einzigen Durchlauf der \texttt{recipe} (gebündelt) erzeugt. +\end{frame} - Wenn man \texttt{plot2.pdf} aber nicht \texttt{plot1.pdf} löscht, kann \texttt{make} nicht mehr \texttt{plot2.pdf} erstellen. \end{frame} From 680378e5ed6a8b8ca537d71d728123490f722a95 Mon Sep 17 00:00:00 2001 From: Joshua Luckey Date: Thu, 19 Sep 2024 00:06:45 +0200 Subject: [PATCH 2/4] added slide for variables this way the duplication of filenames in the Makefile is reduced --- make/content/advanced.tex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/make/content/advanced.tex b/make/content/advanced.tex index 4b337289..7999deca 100644 --- a/make/content/advanced.tex +++ b/make/content/advanced.tex @@ -62,4 +62,36 @@ → Alle \texttt{targets} werden durch eine einzigen Durchlauf der \texttt{recipe} (gebündelt) erzeugt. \end{frame} +\begin{frame}[fragile]{Expert} + Wenn ein Skript sehr viele Dateien erzeugt kann die Liste der \texttt{targets} unübersichtlich lang werden.\\ + Diese \texttt{targets} werden außerdem in der Regel als \texttt{prerequisites} verwendet, + z.~B. für die \texttt{recipe} der Berichtdatei → Die Liste befindet sich sogar zweimal im \texttt{Makefile} + + \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} + \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} + \end{center} \end{frame} From b3d722d6b56e989fefe3185621be2fee405173f4 Mon Sep 17 00:00:00 2001 From: Christian Beckmann Date: Fri, 20 Sep 2024 17:25:15 +0200 Subject: [PATCH 3/4] append advanced make slides with second variable list definition, fix & mistakes --- make/content/advanced.tex | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/make/content/advanced.tex b/make/content/advanced.tex index 7999deca..0fb7a4f9 100644 --- a/make/content/advanced.tex +++ b/make/content/advanced.tex @@ -54,7 +54,7 @@ report.txt: plot1.pdf plot2.pdf touch report.txt - plot2.pdf plot1.pdf &: plot.py data.txt # das &: definiert die targets als group + plot2.pdf plot1.pdf &: plot.py data.txt # das &: definiert die targets als group python plot.py \end{minted} @@ -75,7 +75,7 @@ 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 + 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} \end{center} @@ -85,13 +85,34 @@ \begin{minted}{make} all: report.txt - script_targets = plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf #Variablen Definition + script_targets = plot1.pdf plot2.pdf plot3.pdf plot4.pdf plot5.pdf # Variablen Definition - report.txt: $(script_targets) #Variablen Verwendung + report.txt: $(script_targets) # Variablen Verwendung touch report.txt - $(script_targets): plot.py data.txt #Variablen Verwendung + $(script_targets) & : plot.py data.txt # Variablen Verwendung python plot.py \end{minted} \end{center} \end{frame} + +\begin{frame}[fragile]{Expert} + Die Variablenliste kann auch weiter bearbeitet werden. + Mit \texttt{addprefix build/} wird in diesem Beispiel der \texttt{build} Ordner + an den Anfang jedes Dateipfades geschrieben. + \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} + \end{center} +\end{frame} \ No newline at end of file From 5a1cec3e81d7a60e34806623fe984e3876dcd2f4 Mon Sep 17 00:00:00 2001 From: chrbeckm Date: Sat, 21 Sep 2024 21:04:33 +0200 Subject: [PATCH 4/4] place all example Make scripts into separate Makefiles and add them via minted to the slides --- make/content/advanced.tex | 80 +++----------------------- make/content/build.tex | 23 +------- make/content/latexmk.tex | 16 +----- make/content/simple_start.tex | 23 +------- make/example-files/Advanced-0 | 7 +++ make/example-files/Advanced-1 | 7 +++ make/example-files/Advanced-2 | 7 +++ make/example-files/Advanced-3 | 9 +++ make/example-files/Advanced-4 | 9 +++ make/example-files/Basic-block | 2 + make/example-files/Basic-block-example | 2 + make/example-files/Cake | 20 +++++++ make/example-files/First-build-dir | 15 +++++ make/example-files/First-report | 9 +++ make/example-files/Latexmk | 13 +++++ make/example-files/Simple-clean | 2 + 16 files changed, 115 insertions(+), 129 deletions(-) create mode 100644 make/example-files/Advanced-0 create mode 100644 make/example-files/Advanced-1 create mode 100644 make/example-files/Advanced-2 create mode 100644 make/example-files/Advanced-3 create mode 100644 make/example-files/Advanced-4 create mode 100644 make/example-files/Basic-block create mode 100644 make/example-files/Basic-block-example create mode 100644 make/example-files/Cake create mode 100644 make/example-files/First-build-dir create mode 100644 make/example-files/First-report create mode 100644 make/example-files/Latexmk create mode 100644 make/example-files/Simple-clean diff --git a/make/content/advanced.tex b/make/content/advanced.tex index 0fb7a4f9..b278a16a 100644 --- a/make/content/advanced.tex +++ b/make/content/advanced.tex @@ -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} @@ -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} @@ -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} @@ -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} \ No newline at end of file +\end{frame} diff --git a/make/content/build.tex b/make/content/build.tex index 9d280177..ade1493e 100644 --- a/make/content/build.tex +++ b/make/content/build.tex @@ -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}. @@ -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} diff --git a/make/content/latexmk.tex b/make/content/latexmk.tex index 4e77335a..35dbac07 100644 --- a/make/content/latexmk.tex +++ b/make/content/latexmk.tex @@ -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} diff --git a/make/content/simple_start.tex b/make/content/simple_start.tex index f896f3e0..2123de5a 100644 --- a/make/content/simple_start.tex +++ b/make/content/simple_start.tex @@ -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 @@ -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}) @@ -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} diff --git a/make/example-files/Advanced-0 b/make/example-files/Advanced-0 new file mode 100644 index 00000000..202645d4 --- /dev/null +++ b/make/example-files/Advanced-0 @@ -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 diff --git a/make/example-files/Advanced-1 b/make/example-files/Advanced-1 new file mode 100644 index 00000000..793a2635 --- /dev/null +++ b/make/example-files/Advanced-1 @@ -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 diff --git a/make/example-files/Advanced-2 b/make/example-files/Advanced-2 new file mode 100644 index 00000000..659ab96f --- /dev/null +++ b/make/example-files/Advanced-2 @@ -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 diff --git a/make/example-files/Advanced-3 b/make/example-files/Advanced-3 new file mode 100644 index 00000000..5e2b5ac3 --- /dev/null +++ b/make/example-files/Advanced-3 @@ -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 diff --git a/make/example-files/Advanced-4 b/make/example-files/Advanced-4 new file mode 100644 index 00000000..49ae755f --- /dev/null +++ b/make/example-files/Advanced-4 @@ -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 diff --git a/make/example-files/Basic-block b/make/example-files/Basic-block new file mode 100644 index 00000000..74c4201f --- /dev/null +++ b/make/example-files/Basic-block @@ -0,0 +1,2 @@ +target: prerequisites + recipe diff --git a/make/example-files/Basic-block-example b/make/example-files/Basic-block-example new file mode 100644 index 00000000..a8d86105 --- /dev/null +++ b/make/example-files/Basic-block-example @@ -0,0 +1,2 @@ +plot.pdf: plot.py data.txt + python plot.py diff --git a/make/example-files/Cake b/make/example-files/Cake new file mode 100644 index 00000000..b17180ca --- /dev/null +++ b/make/example-files/Cake @@ -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 diff --git a/make/example-files/First-build-dir b/make/example-files/First-build-dir new file mode 100644 index 00000000..66616766 --- /dev/null +++ b/make/example-files/First-build-dir @@ -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 diff --git a/make/example-files/First-report b/make/example-files/First-report new file mode 100644 index 00000000..ce8ad1ff --- /dev/null +++ b/make/example-files/First-report @@ -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 diff --git a/make/example-files/Latexmk b/make/example-files/Latexmk new file mode 100644 index 00000000..42c5702e --- /dev/null +++ b/make/example-files/Latexmk @@ -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 diff --git a/make/example-files/Simple-clean b/make/example-files/Simple-clean new file mode 100644 index 00000000..c2acfbda --- /dev/null +++ b/make/example-files/Simple-clean @@ -0,0 +1,2 @@ +clean: + rm plot.pdf report.pdf