Make is a popular tool for automating the building of software - compiling source code into executable programs.
Though Make is nearly 40 years old, and there are many other build tools available, its fundamental concepts are common across build tools.
Today, researchers working with legacy codes in C or FORTRAN, which are very common in high-performance computing, will, very likely encounter Make.
Researchers are also finding Make of use in implementing reproducible research workflows, automating data analysis and visualization (using Python or R) and combining tables and plots with text to produce reports and papers for publication.
The overall lesson can be done in 3.5 hours.
Solutions for challenges are used in subsequent topics.
A number of example Makefiles, including sample solutions to challenges,
are in subdirectories of
code for the corresponding episodes.
It can be useful to use two windows during the lesson, one with the terminal
where you run the
make commands, the other with the Makefile opened in a text
editor all the time. This makes it possible to refer to the Makefile while
explaining the output from the commandline, for example. Make sure, though,
that the text in both windows is readable from the back of the room.
Recommend instructors and students use
nano as the text editor for
this lesson because
Please point out to students during setup that they can and should use another text editor if they’re already familiar with it.
Instructors and students should use two shell windows: one for running nano, and one for running Make.
Check that all attendees have Make installed and that it runs correctly, before beginning the session.
Python scripts to be invoked by Make are in
Data files are in
You can either create a simple Git repository for students to clone which contains:
Or, ask students to download make-lesson.zip from this repository.
$ make make-lesson.zip
The single most commonly occurring problem will be students using spaces instead of TABs when indenting actions.
Some of these pages use images of Makefile dependencies, in the
To install GraphViz on Scientific Linux 6:
$ sudo yum install graphviz $ dot -V
dot - graphviz version 2.26.0 (20091210.2329)
To install GraphViz on Ubuntu:
$ sudo apt-get install graphviz $ dot -V
dot - graphviz version 2.38.0 (20140413.2041)
To download and build makefile2graph on Linux:
$ cd $ git clone https://github.com/lindenb/makefile2graph $ cd makefile2graph/ $ make $ export PATH=~/makefile2graph/:$PATH $ cd $ which makefile2graph
To create the image files for the lesson:
$ make diagrams
books/last.txt with Python 3 and vanilla shell environment on
Arch Linux the following error has appeared:
$ python wordcount.py books/last.txt last.dat
Traceback (most recent call last): File "wordcount.py", line 131, in <module> word_count(input_file, output_file, min_length) File "wordcount.py", line 118, in word_count lines = load_text(input_file) File "wordcount.py", line 14, in load_text lines = input_fd.read().splitlines() File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6862: ordinal not in range(128)
The workaround was to define encoding for the terminal session (this can be
either done at the command line or placed in the
.bashrc or equivalent):
$ export LC_ALL=en_US.UTF-8 $ export LANG=en_US.UTF-8 $ export LANGUAGE=en_US.UTF-8
The lesson is based on GNU Make. Although it is very rare, on some systems
(e.g. AIX) you might find
make not pointing to GNU Make and
gmake needs to
be used instead.