3. Broadlinux | Linux of Things
Everything was born for a reason
A primitive notion
3
4. Broadlinux | Linux of Things
Motivation
ïŹ So small programs â single and short file
ïŹ âNot so smallâ programs :
ïŹ Many lines of code â long file, harder to manage
ïŹ Many programmers â canât modify the same file simultaneously
ïŹ Every change requires long compilation
ïŹ Solution: divide large programs into smaller, more manageable
pieces with multiple files
ïŹ Pros:
ïŹ Good division to components
ïŹ Easy maintenance of project structure, dependencies and creation
4
5. Broadlinux | Linux of Things
Original management approach
ïŹ Manual with care, must think of everything
ïŹ Compiling and linking by hand becomes tedious
ïŹ Use shell scripts to comment out some steps to save processing time
ïŹ Early automation used simple make.sh and install.sh scripts
ïŹ Easily lose track of:
ïŹ which ïŹles depend on which others
ïŹ the exact sequence of operations needed to build program
ïŹ which ïŹles have been modiïŹed recently
ïŹ Recompiling everything in sight just to be safe is very wasteful
ïŹ Minimum compilation when something is changed
5
Repair manual
Repair the
Wheel need
to unplug
the whole car?
6. Broadlinux | Linux of Things
The morning of creation
A primitive notion
6
7. Broadlinux | Linux of Things 7
Steve Johnson Stuart Feldman
I wasted a
morning
debugging a
program,
file hadn't been
compiled, cc *.o
was therefore
unaffected
Bell Labs
8. Broadlinux | Linux of Things 8
I met the same
disaster on a project I
was working on
Need a
tool to
solve it!
â„Makeâ„
1977
Bell Labs
9. Broadlinux | Linux of Things
make philosophy
9
dependency
relationship
target
commandstimestamp
make
Sequence of execution commands
final target
1. Automate the software building
2. Take minimum of effort
Mission
10. Broadlinux | Linux of Things
ïŹ A file describes how to generate a particular target file
ïŹ Consists a number of rules
ïŹ If (target out-of-date with dependencies) then
Execute commands to make target up-to-date
ïŹ âEverything is a fileâ
Makefile
10
dependency
relationship
target
commands
target: dependencies
<tab>commands rule
11. Broadlinux | Linux of Things
Makefile in Life
11
clothes: shoes wallet mobile t-shirt
look in the mirror
shoes: socks, trousers
make shoes clean
put on shoes
socks:
wash your foot
put on socks
trousers: underpants
put on trousers
underpants:
put on underpants
look in the mirror
wallet, mobile: trousers
put in trouser pockets
t-shirt:
put on t-shirt
walletshoes
trousers
socks underpants
mobile shirt
clothes
<>
$ make clothes
wash your foot
put on socks
put on underpants
look in the mirror
put on trousers
make shoes clean
put on shoes
put wallet in trouser pockets
put mobile in trouser pockets
put on t-shirt
12. Broadlinux | Linux of Things
Learn from Yacc and Lex
12
Lexical analyzer
Syntax analyzer
Lex
Yacc
a = b + c * d
id1
=
+
*id2
id3 id4
patterns
grammar
Source code
id1 = id2 + id3 * id4Tokens
Syntax tree
Code generator
load id3
mul id4
add id2
store id1
Generated code
ïŹ The basic building blocks of a compiler
13. Broadlinux | Linux of Things
make architecture
13
sum (exe)
sum.omain.o
sum.h sum.cmain.c
Makefile
make analyzer
Dependency
Graph
$ make sum
$ gcc âc main.c
$ gcc âc sum.c
$ gcc âo sum main.o sum.o
Build command
Shell commands
# target prerequisite command
# ------------------------------------------------
sum main.o, sum.o gcc âo sum main.o sum.o
main.o main.c, main.h gcc âc main.c
sum.o sum.c, sum.h gcc âc sum.c
Semantic graph
make processor
Makefile
make
1
2
$ com1
$ com2 $ com3
Rule syntax
14. Broadlinux | Linux of Things
New cycle of program development
14
think â edit â make â test
15. Broadlinux | Linux of Things 15
You donât get everything right at the first time
<tab>
16. Broadlinux | Linux of Things
The worst ever made
ïŹ What we see
ïŹ What it is
ïŹ The interpretation of a makefile can change drastically on the basis
of invisible differences in whitespace.
ïŹ âI had a user population of about a dozen, most of them friends, and
I didnât want to screw up my embedded base. The rest, sadly, is
history.â -- Stuart Feldman --
16
17. Broadlinux | Linux of Things
The creativity in work
The lesson from make
17
20. Broadlinux | Linux of Things
Reference
ïŹ Make a program for maintaining computer programs
https://www.researchgate.net/publication/220280049_Make-
A_Program_for_Maintaining_Computer_Programs
ïŹ The Art of Unix Programming by Eric Steven Raymond
ïŹ Whatâs Wrong With GNU make? http://www.conifersystems.com/whitepapers/gnu-
make/
ïŹ Make for data scientists http://blog.kaggle.com/2012/10/15/make-for-data-scientists/
ïŹ Introduction to making Makefiles
http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html
20