CSC 282.01, Class 06: Automating work with Make
Overview
- Preliminaries
- Notes and news
- Upcoming work
- Questions
- Background - Why Make?
- Key Make issues
- Rules
- Variables
- Automatic variables
- Default targets
- Practice
News / Etc.
- No class next week. Use the time to work on the homework.
- I will try to mix lecture, discussion, recitation, and work today. We’ll see how it goes.
Upcoming work
- Build an arbitrary-precision-integer library and associated files. (Details in today’s class)
Good things to do
- CS extras
- CS table
- Rosenfield symposium on techology and stuff
- Q&A on new gender inclusive housing March 13 12-1 or 7-8pm in JRC 101.
- March 9-12 Playboy of the Western World, 7:30 Thu-Sat, 2:00 Sunday. Watch ST wish that she could hit lots of people with sticks.
Questions
Background - Why Make?
- We type long and complex incantations to create our programs, particularly when we have large projects.
- We should document those incantations.
- Once you’ve put incantations in a file, there’s no reason for you to type them ever again (or even copy and paste them). (Up arrow or bang history may help.)
- When you inherit / download someone else’s project, there’s an overhead in figuring out which incantations are important
- Make was designed to address these and similar issues
- Also helps us avoid rebuilding unnecessary things
Key Make issues
- Target: Thing you want to build or do.
- Thing: I want to build my application
- Action: Get rid of the cruft
- Dependencies: What I need to have built already to build my application.
To build gimp, I need gimplib.a built already.
- Dependencies can be chained. To build gimplib.a, I need gimp-tools.o and gimp-image-format.o and …
- Actions: The incantations
- We put Targets, Dependencies, and Actions together into Rules
- We benefit from Variables
- We benefit from Generic rules
- Some variables can be provided for us (such as “Upon what do I depend?”)
- It’s good to have customs, particularly default targets.
Rules
Three parts: Targets, Dependencies, and Actions
target: dependencies
action1
action2
action3
foo: foo.c
gcc -o foo -g -Wall foo.c
bar: bar.c
gcc -o bar -g -Wall bar.c
Variables
CFLAGS = -g -Wall
foo: foo.c
gcc -o foo $(CFLAGS) foo.c
bar: bar.c
gcc -o bar $(CFLAGS) bar.c
Automatic variables
Let’s avoid repetition by referring to things by their role.
$@the target$^the dependencies$<the first dependency
CFLAGS = -g -Wall
foo: foo.c
gcc -o $@ $(CFLAGS) $<
bar: bar.c
gcc -o $@ $(CFLAGS) $<
Generic rules
Use % for “Something”
CFLAGS = -g -Wall
%: %.c
gcc -o $@ $(CFLAGS) $<
Standard targets
all, appears first, what your goals are. When you just typemake, make attempts to make the target of the first specific rule.check, run your test programsinstall, installs your program / you may not writeclean, remove cruftdistclean, remove cruft and anything you builtdist, make a Tarball