makefile martial arts - chapter 1. the morning of creation

21
broadlinux 7.2016 by quyenlv

Upload: quyen-le-van

Post on 12-Apr-2017

114 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Makefile Martial Arts - Chapter 1. The morning of creation

broadlinux

7.2016 by quyenlv

Page 2: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things 2

Chapter 1

Page 3: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things

Everything was born for a reason

A primitive notion

3

Page 4: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 5: Makefile Martial Arts - Chapter 1. The morning of creation

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 files depend on which others

the exact sequence of operations needed to build program

which files have been modified 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 unplugthe whole car?

Page 6: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things

The morning of creation

A primitive notion

6

Page 7: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 8: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 9: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 10: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 11: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 12: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 13: Makefile Martial Arts - Chapter 1. The morning of creation

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

make1

2

$ com1

$ com2 $ com3

Rule syntax

Page 14: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things

New cycle of program development

14

think — edit — make — test

Page 15: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things 15

You don’t get everything right at the first time

<tab>

Page 16: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 17: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things

The creativity in work

The lesson from make

17

Page 18: Makefile Martial Arts - Chapter 1. The morning of creation

Stuart FeldmanGoogle Vice President of Engineering

Bell Lab, 1977

Page 19: Makefile Martial Arts - Chapter 1. The morning of creation

Copyright© 2014 DASAN Networks, Inc.

”It became possible to go home in the evening while

leaving behind long runcoms executing overnight.”

LOUIS POUZIN

1931, France

Page 20: Makefile Martial Arts - Chapter 1. The morning of creation

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

Page 21: Makefile Martial Arts - Chapter 1. The morning of creation

Broadlinux | Linux of Things 21

Thank you!