Lab Session 6: Automation and Make
Contents
Lab Session 6: Automation and Make¶
Statistics 159/259, Spring 2022
Prof. F. Pérez and GSI F. Sapienza, Department of Statistics, UC Berkeley.
03/14/2022
Useful links:
Acknowledgment: The contents we are following for this course is based on the amazing tutorial about Automation and Make created by The Carpentries
Make is called a build tool: it builds files, plots, papers, etc. Today we are going to do everything from the the shell. If you haven’t done the setup for the tutorial during last lecture, please follow the setup page in order to start working with the contents of the tutorial.
We will start from the following version of our Makefile
created inside the folder make-lesson
provided in the tutorial.
from IPython import display
display.Code('Makefile')
# Generate summary table.
results.txt : testzipf.py isles.dat abyss.dat last.dat
python $< *.dat > $@
# Count words.
.PHONY : dats
dats : isles.dat abyss.dat last.dat
isles.dat : books/isles.txt countwords.py
python countwords.py $< $@
abyss.dat : books/abyss.txt countwords.py
python countwords.py $< $@
last.dat : books/last.txt countwords.py
python countwords.py $< $@
.PHONY : clean
clean :
rm -f *.dat
rm -f results.txt
Before continuing, be sure to know the answer to the following questions.
What is a phony target? When and how to use them?
What does
$^
,$<
and$@
designate?What happen is we modify the Python script we used to generate dat?
What does it means to do a dry run of your make file?
How do you execute a make file? Does the name of the file needs to be
Makefile
?Try to make a schematic plot of the tree of dependencies of this makefiles.
Part 1: Recap¶
Add to your
Makefile
the command to create a plot for the different books.Replace the repeated commands by using a pattern rule.
What does
%
designates?What does
$*
do and how to use it?When can and cannot use or the other?
Part 2: Variables and functions¶
All this exercises can be found in the Variables and Functions chapters.
Update
Makefile
so that the%.dat
rule references the variablesCOUNT_SRC
andCOUNT_EXE
. Then do the same for thetestzipf.py
script and theresults.txt
rule, usingZIPF_SRC
andZIPF_EXE
as variable names.Move the varaible declaration to a new file
config.mk
that you import intoMakefiles
. What happens when you touchconfig.mk
and thenmake
again? Why? Try changingLANGUAGE=python
toLANGUAGE=python3
to see if there is any difference.Follow the functions tutorial to simplify all the unnecessary explicit syntax in
Makefile
. This includes the use of both functionwildcard
andpatsubst
. If you feel adventurous, you can add more books tobooks
and test Zipf’s Law.Explore how to add documentation to the makefiles.
Part 3: Make graduation¶
The tutorial we follow has a final exercises for you to try. Test how much have you learned about makefiles and try to do it! You can use as an starting point the end of the previous tutorial.