Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each...
Transcript of Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each...
![Page 1: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/1.jpg)
Introduction to Makefile
Ray Song
February 25, 2012
Ray Song Introduction to Makefile
![Page 2: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/2.jpg)
Motivation
I Small programs -> single file -> manual compilationI “not so small” programs
I many filesI multiple componentsI more than one programmers
Ray Song Introduction to Makefile
![Page 3: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/3.jpg)
Motivation
I Small programs -> single file -> manual compilationI “not so small” programs
I many filesI multiple componentsI more than one programmers
Ray Song Introduction to Makefile
![Page 4: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/4.jpg)
Motivation
I Small programs -> single file -> manual compilationI “not so small” programs
I many filesI multiple componentsI more than one programmers
Ray Song Introduction to Makefile
![Page 5: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/5.jpg)
Motivation
I Small programs -> single file -> manual compilationI “not so small” programs
I many filesI multiple componentsI more than one programmers
Ray Song Introduction to Makefile
![Page 6: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/6.jpg)
Motivation
I Small programs -> single file -> manual compilationI “not so small” programs
I many filesI multiple componentsI more than one programmers
Ray Song Introduction to Makefile
![Page 7: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/7.jpg)
Motivation - cont.
I ProblemsI harder to manageI every change require long compilationI division to components is desired
Ray Song Introduction to Makefile
![Page 8: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/8.jpg)
Motivation - cont.
I ProblemsI harder to manageI every change require long compilationI division to components is desired
Ray Song Introduction to Makefile
![Page 9: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/9.jpg)
Motivation - cont.
I ProblemsI harder to manageI every change require long compilationI division to components is desired
Ray Song Introduction to Makefile
![Page 10: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/10.jpg)
Motivation - cont.
I ProblemsI harder to manageI every change require long compilationI division to components is desired
Ray Song Introduction to Makefile
![Page 11: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/11.jpg)
Motivation - cont.
I Solution - Makefile
Ray Song Introduction to Makefile
![Page 12: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/12.jpg)
Makefile
I Makefile describesI project structureI instructions for files creation
I A makefile consists of many rules.
Ray Song Introduction to Makefile
![Page 13: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/13.jpg)
Makefile
I Makefile describesI project structureI instructions for files creation
I A makefile consists of many rules.
Ray Song Introduction to Makefile
![Page 14: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/14.jpg)
Makefile
I Makefile describesI project structureI instructions for files creation
I A makefile consists of many rules.
Ray Song Introduction to Makefile
![Page 15: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/15.jpg)
Makefile
I Makefile describesI project structureI instructions for files creation
I A makefile consists of many rules.
Ray Song Introduction to Makefile
![Page 16: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/16.jpg)
Rule syntax
TARGETS: PREREQUISITES
RECIPE
I In short, each rule describe instructions (RECIPE) to createfiles (TARGETS) with PREREQUISITES.
I PREREQUISITES are targets must be created prior toTARGETS.
I A target is considered old if its modification timestamp issmaller than one of its dependencies’s.
Ray Song Introduction to Makefile
![Page 17: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/17.jpg)
Rule syntax
TARGETS: PREREQUISITES
RECIPE
I In short, each rule describe instructions (RECIPE) to createfiles (TARGETS) with PREREQUISITES.
I PREREQUISITES are targets must be created prior toTARGETS.
I A target is considered old if its modification timestamp issmaller than one of its dependencies’s.
Ray Song Introduction to Makefile
![Page 18: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/18.jpg)
Rule syntax
TARGETS: PREREQUISITES
RECIPE
I In short, each rule describe instructions (RECIPE) to createfiles (TARGETS) with PREREQUISITES.
I PREREQUISITES are targets must be created prior toTARGETS.
I A target is considered old if its modification timestamp issmaller than one of its dependencies’s.
Ray Song Introduction to Makefile
![Page 19: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/19.jpg)
Makefile – cont.
I TARGETS and PREREQUISITES are file names separatedby spaces.
I Usually there is only one target per rule.
I TARGETS and PREREQUISITES may contain wildcards,e.g. %.c.
I Each line of RECIPE starts with a TAB.
I The first rule indicates the default target (not countingtargets that contain wildcards).
Ray Song Introduction to Makefile
![Page 20: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/20.jpg)
Makefile – cont.
I TARGETS and PREREQUISITES are file names separatedby spaces.
I Usually there is only one target per rule.
I TARGETS and PREREQUISITES may contain wildcards,e.g. %.c.
I Each line of RECIPE starts with a TAB.
I The first rule indicates the default target (not countingtargets that contain wildcards).
Ray Song Introduction to Makefile
![Page 21: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/21.jpg)
Makefile – cont.
I TARGETS and PREREQUISITES are file names separatedby spaces.
I Usually there is only one target per rule.
I TARGETS and PREREQUISITES may contain wildcards,e.g. %.c.
I Each line of RECIPE starts with a TAB.
I The first rule indicates the default target (not countingtargets that contain wildcards).
Ray Song Introduction to Makefile
![Page 22: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/22.jpg)
Makefile – cont.
I TARGETS and PREREQUISITES are file names separatedby spaces.
I Usually there is only one target per rule.
I TARGETS and PREREQUISITES may contain wildcards,e.g. %.c.
I Each line of RECIPE starts with a TAB.
I The first rule indicates the default target (not countingtargets that contain wildcards).
Ray Song Introduction to Makefile
![Page 23: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/23.jpg)
Makefile – cont.
I TARGETS and PREREQUISITES are file names separatedby spaces.
I Usually there is only one target per rule.
I TARGETS and PREREQUISITES may contain wildcards,e.g. %.c.
I Each line of RECIPE starts with a TAB.
I The first rule indicates the default target (not countingtargets that contain wildcards).
Ray Song Introduction to Makefile
![Page 24: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/24.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 25: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/25.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 26: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/26.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 27: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/27.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 28: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/28.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 29: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/29.jpg)
make’s mechanism
I make command reads a makefile and records these rules intoits data base.
I GNU Make defaults to search GNUmakefile, makefile,Makefile in order, use the first of these which exists.
I The first goal (terminology used to refer to the list of targetsyou specified on the command line) should be created.
I Prerequisites which appeared in the target must be processedfirst.
I This is a recursive process (depth first search).
I After updating the dependencies , make decides whether it isnecessary to recreated the target. This is the case when it isolder than one of its dependencies. In the case we recreatethe target, execute the associated recipe.
Ray Song Introduction to Makefile
![Page 30: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/30.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 31: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/31.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 32: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/32.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 33: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/33.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 34: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/34.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 35: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/35.jpg)
make’s mechanism - cont.
I make virtually construct a dependency DAG (directed acyclicgraph).
I make ensures minimum compilation as long as the projectstructure is written properly.
I Do not write something like:
prog: main.c sum1.c sum2.c
gcc –o prog main.c sum1.c sum2.c
which requires compilation of all project when something ischanged
Ray Song Introduction to Makefile
![Page 36: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/36.jpg)
Automatic variables
I $@
I $ˆ
I $<
I others including $, $?, $+, $|, $%, $(%D), %(F), . . .
Ray Song Introduction to Makefile
![Page 37: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/37.jpg)
Automatic variables
I $@
I $ˆ
I $<
I others including $, $?, $+, $|, $%, $(%D), %(F), . . .
Ray Song Introduction to Makefile
![Page 38: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/38.jpg)
Automatic variables
I $@
I $ˆ
I $<
I others including $, $?, $+, $|, $%, $(%D), %(F), . . .
Ray Song Introduction to Makefile
![Page 39: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/39.jpg)
Automatic variables
I $@
I $ˆ
I $<
I others including $, $?, $+, $|, $%, $(%D), %(F), . . .
Ray Song Introduction to Makefile
![Page 40: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/40.jpg)
Example
convert: cmdline.o convert.o
g++ $ˆ -o $@
convert.o: convert.cpp convert.h
g++ -c $<
cmdline.o: cmdline.cpp cmdline.h convert.h
g++ -c $<
Ray Song Introduction to Makefile
![Page 41: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/41.jpg)
Equivalent (implicit rules)
I make can dedude appropriate recipes according to suffixes
convert: cmdline.o convert.o
convert.o: convert.cpp convert.h
cmdline.o: cmdline.cpp cmdline.h convert.h
Ray Song Introduction to Makefile
![Page 42: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/42.jpg)
Equivalent (implicit rules) - cont.
convert: cmdline.o
convert.o: convert.h
cmdline.o: cmdline.h convert.h
Ray Song Introduction to Makefile
![Page 43: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/43.jpg)
Another example
%.o: %.c
gcc -c $<
Ray Song Introduction to Makefile
![Page 44: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/44.jpg)
Passing parameters
test: FORCE
echo $(VAR)
FORCE:
I make VAR=hello
I make VAR=world
Ray Song Introduction to Makefile
![Page 45: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/45.jpg)
Passing parameters
test: FORCE
echo $(VAR)
FORCE:
I make VAR=hello
I make VAR=world
Ray Song Introduction to Makefile
![Page 46: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/46.jpg)
Force targets
I Targets without recipes or prerequisites
Ray Song Introduction to Makefile
![Page 47: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/47.jpg)
Phony targets
I They do not correspond to real file.
I Provide some utility, e.g. cleaning intermediate files, archivingthe whole project, creating TAGS file for some editors
I Forced to run its recipe upon executing.
Ray Song Introduction to Makefile
![Page 48: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/48.jpg)
Phony targets
I They do not correspond to real file.
I Provide some utility, e.g. cleaning intermediate files, archivingthe whole project, creating TAGS file for some editors
I Forced to run its recipe upon executing.
Ray Song Introduction to Makefile
![Page 49: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/49.jpg)
Phony targets
I They do not correspond to real file.
I Provide some utility, e.g. cleaning intermediate files, archivingthe whole project, creating TAGS file for some editors
I Forced to run its recipe upon executing.
Ray Song Introduction to Makefile
![Page 50: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/50.jpg)
Example
all : prog1 prog2 prog3
.PHONY : all
prog1 : prog1.o utils.o
cc -o prog1 prog1.o utils.o
prog2 : prog2.o
cc -o prog2 prog2.o
prog3 : prog3.o sort.o utils.o
cc -o prog3 prog3.o sort.o utils.o
Ray Song Introduction to Makefile
![Page 51: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/51.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 52: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/52.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 53: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/53.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 54: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/54.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 55: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/55.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 56: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/56.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 57: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/57.jpg)
Practical options of make
I -n, print the commands to be run but do not execute them
I -t, touch files instead of running the recipes
I -B, unconditionally make all targets (overide timestamps)
I -W file, pretend file has been just modified
I -p, print the data base that results from reading the makefiles
I -d, debug mode
I others, RTFM
Ray Song Introduction to Makefile
![Page 58: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/58.jpg)
Other usage
I Makefile’s mechanism is not limited to programsI LaTeX sourcesI website deploymentI describe any task where some files need updating as a result of
changes of other files
Ray Song Introduction to Makefile
![Page 59: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/59.jpg)
Other usage
I Makefile’s mechanism is not limited to programsI LaTeX sourcesI website deploymentI describe any task where some files need updating as a result of
changes of other files
Ray Song Introduction to Makefile
![Page 60: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/60.jpg)
Other usage
I Makefile’s mechanism is not limited to programsI LaTeX sourcesI website deploymentI describe any task where some files need updating as a result of
changes of other files
Ray Song Introduction to Makefile
![Page 61: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/61.jpg)
Other usage
I Makefile’s mechanism is not limited to programsI LaTeX sourcesI website deploymentI describe any task where some files need updating as a result of
changes of other files
Ray Song Introduction to Makefile
![Page 62: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/62.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 63: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/63.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 64: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/64.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 65: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/65.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 66: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/66.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 67: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/67.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 68: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/68.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 69: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/69.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 70: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/70.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 71: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/71.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 72: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/72.jpg)
Additional features
I Variables (two flavors: simple and recursive, the latter is alsocalled macros)
I Functions including string substitution, file namemanipulation, foreach, even the the root of evil – eval
I VPATH
I Ability to manipulate archives(.a)
I Including other makefiles
I Conditionals
I Secondary expansion
I Order-only prerequisites
I Static patterns
I Double-colon rules
I Target/pattern-specific variable values
Ray Song Introduction to Makefile
![Page 73: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/73.jpg)
Acknowledgements
I This slide incorporate some stuff from Roded Sharan’shttp://www.cs.tau.ac.il/~roded/courses/softp-b06/
Makefile.ppt
I Markdownhttp://daringfireball.net/projects/markdown/ inwhich this slide source is written.
I Pandoc http://johnmacfarlane.net/pandoc/ by whichthis slide is generated.
I Haskell http://www.haskell.org/ in which Pandoc isimplemented.
Ray Song Introduction to Makefile
![Page 74: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/74.jpg)
Acknowledgements
I This slide incorporate some stuff from Roded Sharan’shttp://www.cs.tau.ac.il/~roded/courses/softp-b06/
Makefile.ppt
I Markdownhttp://daringfireball.net/projects/markdown/ inwhich this slide source is written.
I Pandoc http://johnmacfarlane.net/pandoc/ by whichthis slide is generated.
I Haskell http://www.haskell.org/ in which Pandoc isimplemented.
Ray Song Introduction to Makefile
![Page 75: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/75.jpg)
Acknowledgements
I This slide incorporate some stuff from Roded Sharan’shttp://www.cs.tau.ac.il/~roded/courses/softp-b06/
Makefile.ppt
I Markdownhttp://daringfireball.net/projects/markdown/ inwhich this slide source is written.
I Pandoc http://johnmacfarlane.net/pandoc/ by whichthis slide is generated.
I Haskell http://www.haskell.org/ in which Pandoc isimplemented.
Ray Song Introduction to Makefile
![Page 76: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/76.jpg)
Acknowledgements
I This slide incorporate some stuff from Roded Sharan’shttp://www.cs.tau.ac.il/~roded/courses/softp-b06/
Makefile.ppt
I Markdownhttp://daringfireball.net/projects/markdown/ inwhich this slide source is written.
I Pandoc http://johnmacfarlane.net/pandoc/ by whichthis slide is generated.
I Haskell http://www.haskell.org/ in which Pandoc isimplemented.
Ray Song Introduction to Makefile
![Page 77: Introduction to Makefile - MaskRay · Rule syntax TARGETS: PREREQUISITES RECIPE I In short, each rule describe instructions (RECIPE) to create les (TARGETS) with PREREQUISITES. I](https://reader033.fdocuments.in/reader033/viewer/2022052002/60154feede7b3736e8265a35/html5/thumbnails/77.jpg)
References
I GNU Make Manualhttp://www.gnu.org/software/make/manual/
Ray Song Introduction to Makefile