![Page 1: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/1.jpg)
/
Week 7
1 / 55
![Page 2: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/2.jpg)
/
AnnouncementsHW5, ADV5 due by 11:59 PM on Feb 26HW6, ADV6 due by 11:59 PM on Mar 4
Will release ADV6 tonight or Saturday: will be easy and not require going to o�icehours
2 / 55
![Page 3: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/3.jpg)
/
Lecture 7: Build Systemsgcc -I inc -o app $(find . -name *.c) -lsomelib
3 / 55
![Page 4: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/4.jpg)
/
OverviewBuild systemsmakeOther build systems
4 / 55
![Page 5: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/5.jpg)
/
Build systems
5 / 55
![Page 6: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/6.jpg)
/
Build systems
Q: Who has used a build system?
6 / 55
![Page 7: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/7.jpg)
/
What is a build system?
Typing out gcc -o myapp file1.c file2.c file3.c main.c every timeyou want to compile can be annoying...
7 / 55
![Page 8: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/8.jpg)
/
What is a build system?
Typing out gcc -o myapp file1.c file2.c file3.c main.c every timeyou want to compile can be annoying...Tool to automate building so�ware
CompilationPackagingTesting
8 / 55
![Page 9: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/9.jpg)
/
A simple build system
A throwback to HW2...
---build.sh---#!/usr/bin/env bashgcc -o myapp src/file1.c src/file2.c src/file3.c src/main.c
---build.sh---#!/usr/bin/env bashgcc -o myapp $(find src -name "*.c")
./build.sh
9 / 55
![Page 10: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/10.jpg)
/
Some issues
Can be a bit of work to custom write a script, especially with larger projectsWill blindly compile everything, every timeWhat if we made a small change to one file and didn't want to recompile all the code?
10 / 55
![Page 11: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/11.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)
11 / 55
![Page 12: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/12.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)Imagine if I had to recompile everything every time I made a small code change
12 / 55
![Page 13: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/13.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)Imagine if I had to recompile everything every time I made a small code changePut together independent bits instead of compiling/building everything every timeClassic model: C/C++ programs
Compile individual C/C++ files into object code (.o files)
13 / 55
![Page 14: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/14.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)Imagine if I had to recompile everything every time I made a small code changePut together independent bits instead of compiling/building everything every timeClassic model: C/C++ programs
Compile individual C/C++ files into object code (.o files)Link the object code files into the final output executable binary
14 / 55
![Page 15: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/15.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)Imagine if I had to recompile everything every time I made a small code changePut together independent bits instead of compiling/building everything every timeClassic model: C/C++ programs
Compile individual C/C++ files into object code (.o files)Link the object code files into the final output executable binaryChange only one C/C++ file? Just build the object code for that file, then link theobject code
15 / 55
![Page 16: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/16.jpg)
/
Aside: incremental building
It takes my lab computer about 30 minutes to do a clean build of LLVM and Clang whilemaxing out my CPU
(Hours if I restrict how many cores I give it...)Imagine if I had to recompile everything every time I made a small code changePut together independent bits instead of compiling/building everything every timeClassic model: C/C++ programs
Compile individual C/C++ files into object code (.o files)Link the object code files into the final output executable binaryChange only one C/C++ file? Just build the object code for that file, then link theobject code
...now a simple shell script doesn't seem to cut it
16 / 55
![Page 17: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/17.jpg)
/
Make(We'll be focusing on GNU Make as it's probably the most popular)
Classic tool that helps with build automation
17 / 55
![Page 18: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/18.jpg)
/
Make(We'll be focusing on GNU Make as it's probably the most popular)
Classic tool that helps with build automationProvides more abstractions over a plain shell script
18 / 55
![Page 19: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/19.jpg)
/
Make(We'll be focusing on GNU Make as it's probably the most popular)
Classic tool that helps with build automationProvides more abstractions over a plain shell scriptInvoke it by running make
19 / 55
![Page 20: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/20.jpg)
/
Make(We'll be focusing on GNU Make as it's probably the most popular)
Classic tool that helps with build automationProvides more abstractions over a plain shell scriptInvoke it by running makeWill look for a Makefile (or makefile) to run
(it's actually possible to run without a Makefile, but we won't really get intothat)
20 / 55
![Page 21: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/21.jpg)
/
Make(We'll be focusing on GNU Make as it's probably the most popular)
Classic tool that helps with build automationProvides more abstractions over a plain shell scriptInvoke it by running makeWill look for a Makefile (or makefile) to run
(it's actually possible to run without a Makefile, but we won't really get intothat)
The Makefile will specify rules that have prerequisites that have to be met/builtbefore running its recipe to build a target
target: prerequisites recipe # <- actual tab character, not spaces!
Make is able tell if the built target file is newer than prerequisite files to avoidunnecessarily performing the recipeThe recipe consists of shell commandsmake <target> will build a specific target
21 / 55
![Page 22: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/22.jpg)
/
Simple example
myapp: src/file1.c src/file2.c src/file3.c src/main.c gcc -o myapp src/file1.c src/file2.c src/file3.c src/main.c
22 / 55
![Page 23: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/23.jpg)
/
Simple example
myapp: src/file1.c src/file2.c src/file3.c src/main.c gcc -o myapp src/file1.c src/file2.c src/file3.c src/main.c
A bit more sophisticated
myapp: src/file1.c src/file2.c src/file3.c src/main.c gcc -o $@ $^
23 / 55
![Page 24: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/24.jpg)
/
Philosophy
Overall idea is to have rules that depend on other rules that build smaller bits of thesystem
e.g. building the final executable depends on compiling individual source codefiles into corresponding object code
24 / 55
![Page 25: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/25.jpg)
/
Philosophy
Overall idea is to have rules that depend on other rules that build smaller bits of thesystem
e.g. building the final executable depends on compiling individual source codefiles into corresponding object code
This composability means that we can incrementally build our projectInvaluable with enormous code bases: don't want to recompile every file of theLinux kernel if you made a single line change to one file
25 / 55
![Page 26: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/26.jpg)
/
Philosophy
Overall idea is to have rules that depend on other rules that build smaller bits of thesystem
e.g. building the final executable depends on compiling individual source codefiles into corresponding object code
This composability means that we can incrementally build our projectInvaluable with enormous code bases: don't want to recompile every file of theLinux kernel if you made a single line change to one file
Can have additional rules that run/test/debug the application and clean the directoryof build output
26 / 55
![Page 27: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/27.jpg)
/
Make concepts
Make gives us more abstractions to make our lives easier
It's a pretty deep tool; we're going to look at the basics
Targets and rules"Phony" targetsPowerful variable assignmentsFunctions and other expansionsAutomatic variablesPattern matching
27 / 55
![Page 28: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/28.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be run
28 / 55
![Page 29: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/29.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be runThe recipe consists of shell commands
29 / 55
![Page 30: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/30.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be runThe recipe consists of shell commandsmake <target> will build a specific target
30 / 55
![Page 31: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/31.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be runThe recipe consists of shell commandsmake <target> will build a specific targetThe target is assumed to be some actual file that gets produced
31 / 55
![Page 32: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/32.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be runThe recipe consists of shell commandsmake <target> will build a specific targetThe target is assumed to be some actual file that gets producedMake is able tell if the built target file is newer than prerequisite files to avoidunnecessarily performing the recipe
32 / 55
![Page 33: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/33.jpg)
/
Targets and rulestarget: prerequisites recipe # <- actual tab character, not spaces!
Prerequisite targets will be built before the target's recipe will be able to be runThe recipe consists of shell commandsmake <target> will build a specific targetThe target is assumed to be some actual file that gets producedMake is able tell if the built target file is newer than prerequisite files to avoidunnecessarily performing the recipeIf there are no prerequisites and the target file is present, the recipe won't be run again
33 / 55
![Page 34: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/34.jpg)
/
"Phony" targets
What if you have a target that you want to be a word/concept?e.g. clean, all, test
34 / 55
![Page 35: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/35.jpg)
/
"Phony" targets
What if you have a target that you want to be a word/concept?e.g. clean, all, test
If a file called clean or all is present, the target won't ever be run
35 / 55
![Page 36: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/36.jpg)
/
"Phony" targets
What if you have a target that you want to be a word/concept?e.g. clean, all, test
If a file called clean or all is present, the target won't ever be runThe .PHONY target can specify phony targets that don't have actual files
.PHONY: all clean test
36 / 55
![Page 37: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/37.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)
37 / 55
![Page 38: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/38.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.
38 / 55
![Page 39: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/39.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.To use Makefile variables and "expand" them, you use $(varname) or ${varname}
Parentheses are more common
39 / 55
![Page 40: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/40.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.To use Makefile variables and "expand" them, you use $(varname) or ${varname}
Parentheses are more common
Two flavors of variables
Define how they get assigned and how they get expanded
40 / 55
![Page 41: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/41.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.To use Makefile variables and "expand" them, you use $(varname) or ${varname}
Parentheses are more common
Two flavors of variables
Define how they get assigned and how they get expandedvarA = $(varB) recursively expands the right hand side whenever the variablegets expanded
If varB gets reassigned a�er this, an expanded varA will expand the currentvalue of varB
41 / 55
![Page 42: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/42.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.To use Makefile variables and "expand" them, you use $(varname) or ${varname}
Parentheses are more common
Two flavors of variables
Define how they get assigned and how they get expandedvarA = $(varB) recursively expands the right hand side whenever the variablegets expanded
If varB gets reassigned a�er this, an expanded varA will expand the currentvalue of varB
varA := $(varB) performs a simple expansion, taking on the value of the righthand side at assignment time
If varB gets reassigned a�er this, an expanded varA will expand to the value ofvarB when varA got assigned
42 / 55
![Page 43: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/43.jpg)
/
Variable assignments
You can define variables in Makefiles as well (you can put spaces around the '='!)O�en times are things like compilation flags, compiler selection, directories, files etc.To use Makefile variables and "expand" them, you use $(varname) or ${varname}
Parentheses are more common
Two flavors of variables
Define how they get assigned and how they get expandedvarA = $(varB) recursively expands the right hand side whenever the variablegets expanded
If varB gets reassigned a�er this, an expanded varA will expand the currentvalue of varB
varA := $(varB) performs a simple expansion, taking on the value of the righthand side at assignment time
If varB gets reassigned a�er this, an expanded varA will expand to the value ofvarB when varA got assigned
Another operator
varA ?= bar will assign variable varA if it hasn't been assigned before 43 / 55
![Page 44: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/44.jpg)
/
Functions and other expansions
There are some functions that can be expanded to help with text manipulation$(wildcard <pattern>) can expand to a file list for files that match the pattern
$(wildcard *.c)
44 / 55
![Page 45: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/45.jpg)
/
Functions and other expansions
There are some functions that can be expanded to help with text manipulation$(wildcard <pattern>) can expand to a file list for files that match the pattern
$(wildcard *.c)$(<var>:<pattern>=<replacement>), known as a substitution reference, canperform replacements
$(SOURCES:%.c=%.o)
45 / 55
![Page 46: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/46.jpg)
/
Functions and other expansions
There are some functions that can be expanded to help with text manipulation$(wildcard <pattern>) can expand to a file list for files that match the pattern
$(wildcard *.c)$(<var>:<pattern>=<replacement>), known as a substitution reference, canperform replacements
$(SOURCES:%.c=%.o)$(shell <commands>) can run a shell command and expand to the command'soutput
$(shell find . -name "*.c")
46 / 55
![Page 47: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/47.jpg)
/
Automatic variables
In a rule, Make has some automatically assigned variables$@: target's file name$<: First prerequisite$?: All prerequisites newer than the target$^: All prerequisites...and more
47 / 55
![Page 48: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/48.jpg)
/
Automatic variables
In a rule, Make has some automatically assigned variables$@: target's file name$<: First prerequisite$?: All prerequisites newer than the target$^: All prerequisites...and more
Using what we've learned so far...
CC := gccBIN := myappSRCS := $(shell find src -name *.c)$(BIN): $(SRCS) $(CC) -o $@ $^
48 / 55
![Page 49: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/49.jpg)
/
Pattern matching
Pattern rules
%.o : %.c $(CC) -c -o $@ $<
Uses % to match file namesThis example compiles .c files into .o filesNote that this is a general rule that applies to all .o files
This is known as an implicit rule
49 / 55
![Page 50: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/50.jpg)
/
Pattern matching
Pattern rules
%.o : %.c $(CC) -c -o $@ $<
Uses % to match file namesThis example compiles .c files into .o filesNote that this is a general rule that applies to all .o files
This is known as an implicit rule
Static pattern rules
OBJS := $(SRCS:src/%.c=obj/%.o)$(OBJS): obj/%.o : src/%.c $(CC) -c -o $@ $<
Can narrow down a pattern rule to a particular list of targets50 / 55
![Page 51: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/51.jpg)
/
Make
This is a brief overview of some of the features of MakeThis is by no means a comprehensive look at Make: refer to the manual for morefeatures and details
51 / 55
![Page 52: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/52.jpg)
/
Other build systemsMake is a fairly general build system, but other build systems have more abstractionsand may be tailored towards a particular language
52 / 55
![Page 53: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/53.jpg)
/
Other build systemsMake is a fairly general build system, but other build systems have more abstractionsand may be tailored towards a particular languageGeneral: Ninja, CMake (actually more of a Makefile generator)Java: Ant, Maven, GradleRuby: RakeContinuous integration: Jenkins, Travis CI
53 / 55
![Page 54: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/54.jpg)
/
Demo time
54 / 55
![Page 55: Week 7 - eecs.umich.edu · Week 7 1 / 55 / Announcements HW5, ADV5 due by 11:59 PM on Feb 26 HW6, ADV6 due by 11:59 PM on Mar 4 Will release ADV6 tonight or Saturday: will be easy](https://reader033.vdocuments.us/reader033/viewer/2022060508/5f2325eb0b1f151328044ae4/html5/thumbnails/55.jpg)
/
Questions
55 / 55