Open LuckyJosh opened 1 month ago
And a small addition to that: Combined with a variable to list all the targets the Makefile looks very clean:
# Makefile
all: result.txt
targets = a.txt b.txt c.txt d.txt
$(targets) &:
touch a.txt b.txt c.txt d.txt
result.txt: $(targets)
touch result.txt
Another thing I found working on the lab report:
The context:
For the most extensive solution (exporting every value from the python script into a tex file) I added the manual synchronization from the last `make` -slide: ```make build/parameter-g_ball.tex: build/plot_ball_g.pdf build/parameter-t0-g_ball.tex: build/parameter-g_ball.tex build/plot-g_cylinder.pdf: build/parameter-t0-g_ball.tex build/parameter-g_cylinder.tex: build/plot_cylinder_g.pdf build/parameter-t0-g_cylinder.tex: build/parameter-g_cylinder.tex build/plot-I_ball.pdf: build/parameter-g_cylinder.tex build/parameter-I_ball.tex: build/plot_ball_I.pdf build/parameter-t0-I_ball.tex: build/parameter-I_ball.tex build/plot-I_cylinder.pdf: build/parameter-t0-I_ball.tex build/parameter-I_cylinder.tex: build/plot_cylinder_I.pdf build/parameter-t0-I_cylinder.tex: build/parameter-I_cylinder.tex build/table_all-measurements.tex: build/parameter-t0-I_cylinder.tex build/table_averaged-measurements.tex: build/table_all-measurements.tex build/tracklength.tex: build/table_averaged-measurements.tex build/framerate.tex: build/tracklength.tex build/mass_ball.tex: build/framerate.tex build/radius_ball.tex: build/mass_ball.tex build/theoretical-I_ball.tex: build/radius_ball.tex build/mass_cylinder.tex: build/theoretical-I_ball.tex build/radius-inner_cylinder.tex: build/mass_cylinder.tex build/radius-outer_cylinder.tex: build/radius-inner_cylinder.tex build/theoretical-I_cylinder.tex: build/radius-outer_cylinder.tex ``` does not look very nice in my opinion ... and it is also somewhat tedious to write ... though come to think of it, might be a prime example for multiline editing :thinking:I found a relatively recent addition to Make (4.3), so called 'grouped targets' docs
grouped targets are all created by just on execution of the specific rule. So the manual changing for parallel processing is not necessary.
Example
```make # Makefile all: result.txt a.txt b.txt c.txt d.txt: touch a.txt b.txt c.txt d.txt result.txt: a.txt b.txt c.txt d.txt touch result.txt ``` results in ```shell > make -j4 touch a.txt b.txt c.txt d.txt touch a.txt b.txt c.txt d.txt touch a.txt b.txt c.txt d.txt touch a.txt b.txt c.txt d.txt touch result.txt ``` ```make # Makefile with grouped targets all: result.txt # ↓ This & is all to add a.txt b.txt c.txt d.txt &: touch a.txt b.txt c.txt d.txt result.txt: a.txt b.txt c.txt d.txt touch result.txt ``` ```shell > make -j4 touch a.txt b.txt c.txt d.txt touch result.txt ```