Lab Session 8: Automation and Make#
Statistics 159/259, Spring 2022
Prof. F. Pérez and GSI F. Sapienza, Department of Statistics, UC Berkeley.
04/07/2023
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.
0. Setup#
Download the files form the setup page in the Carpentries tutorial.
We will start from the following version of our Makefile
created inside the folder make-lesson
provided in the tutorial.) you will find the data and scripts for this exercise. Add the corresponding files to your JupyterHub session.
We will start working from the following template Makefile
:
from IPython import display
display.Code('make-lesson/Makefile')
# Count words.
isles.dat : books/isles.txt
python countwords.py books/isles.txt isles.dat
abyss.dat : books/abyss.txt
python countwords.py books/abyss.txt abyss.dat
.PHONY : clean
clean :
rm -f *.dat
1. Recap#
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 data?
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.
2. Growing our Makefile#
Add a new
.PHONY
variable at the top ofMakefile
calledoutputs
that generates bothisles.dat
andabyss.dat
.Add more commands for generating
last.dat
andsierra.dat
.Replace the name of target and dependencies files using the special characters
$<
,$@
.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?
Add a
clean
command that removes all the.dat
files.
[Extra] 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.