lesson material is available on:
these slides on:
You need make
and python
available
Options
ssh NETID@rice.stanford.edu
Bitly to curl in the files:
curl -L bit.ly/36SQ1TI > make-lesson.zip
man make
Make is an automation tool for *NIX systems.
Originally written to facilitate compiling software.
Organizes and executes complex compilation in a flexible and readable way
Other tools are more powerful for pipelines, why use make
?
I use makefile to launch more complex tools.
make
Github for bwa
, check out the Makefile
Testing things is the best way to learn! Ask questions if you can think of something it should be able to do, maybe we can find out how to do it.
make-lesson.zip
contains a directory structure. Unzipped, books
contains text of books.
The directory also has three python scripts that do a couple of things.
python countwords.py books/sierra.txt sierra.dat
python testzipf.py sierra.dat
#!/bin/bash
python countwords.py books/sierra.txt sierra.dat
python countwords.py books/last.txt last.dat
python testzipf.py sierra.dat last.dat
Make a text file called exactly Makefile
a_file:
date > a_file
Run it like so
make a_file
make
make a_file -nd | less
rules
define how to make targets
from dependencies
using actions
TABs are critical
a_file:
date > a_file
another_file: a_file
cat a_file > another_file
date >> another_file
cat a_file >> another_file
Run with
make another_file
make another_file -dn | less
sierra.dat : books/sierra.txt
python countwords.py books/sierra.txt sierra.dat
last.dat : books/last.txt
python countwords.py books/last.txt last.dat
results.txt : sierra.dat
python testzipf.py sierra.dat > results.txt
disp_results:
less results.txt
make disp_results
mkdir disp_results
make disp_results
touch empty_file
creates an empty file, or updates modification time
.PHONY: all
all: results.txt
By default make runs the first thing, but will parse for running all.
Another good one is:
.PHONY: all clean
clean:
rm *dat
all: results.txt
#
is comments, @
means don’t echo it
Automatic variables are handy
https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
$@ $^ $<
n
booksRewrite with some of these automatic variables
sierra.dat : books/sierra.txt
python countwords.py $^ $@
results.txt : sierra.dat
python testzipf.py $^ > $@
make a_file -d | less
sierra.dat : books/sierra.txt countwords.py
python countwords.py $< $@
Functions are called by doing something like $(functionName arugments,here)
sierra.dat : books/sierra.txt countwords.py whatever
@echo $(word 1,$^)
https://www.gnu.org/software/make/manual/html_node/Functions.html
%
is a wildcard that gets substituted for %
in dependencies
%.dat : books/%.txt countwords.py
python countwords.py $< $@
results.txt : sierra.dat last.dat abyss.dat
python testzipf.py $^ > $@
$*
is special automatic variable available in the action
ALL_THE_DAT = sierra.dat last.dat abyss.dat last.dat
%.dat : books/%.txt countwords.py
python countwords.py $< $@
results.txt : ${ALL_THE_DAT}
python testzipf.py $^ > $@
Shell variables require $$ to work!
Can we define ALL_THE_DAT
using a function?
ALL_THE_DAT=$(patsubst books/%.txt,%.dat,$(wildcard books/*.txt))
Slightly awkward - remember make
is a pull paradigm pipeline, not push
Project Gutenberg
UTF-8
bwa
Makefile again