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
.PHONYvariable at the top ofMakefilecalledoutputsthat generates bothisles.datandabyss.dat.Add more commands for generating
last.datandsierra.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
cleancommand that removes all the.datfiles.
[Extra] Variables and functions#
All this exercises can be found in the Variables and Functions chapters.
Update
Makefileso that the%.datrule references the variablesCOUNT_SRCandCOUNT_EXE. Then do the same for thetestzipf.pyscript and theresults.txtrule, usingZIPF_SRCandZIPF_EXEas variable names.Move the varaible declaration to a new file
config.mkthat you import intoMakefiles. What happens when you touchconfig.mkand thenmakeagain? Why? Try changingLANGUAGE=pythontoLANGUAGE=python3to 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 functionwildcardandpatsubst. If you feel adventurous, you can add more books tobooksand test Zipf’s Law.Explore how to add documentation to the makefiles.