3. Introduction
• Why do we need GUN Make?
• Source -> Object -> Executable
• Goal: The make program is intended to
automate the mundane aspects of
transforming source code into an executable.
• Base on timestamp.
8. Command Modifiers
• @ Do not echo the command. If you want to
apply this modifier to all, you can use the
--silent (or -s) option.
• - The dash prefix indicates that errors in the
command should be ignored by make.
You can use --ignore-errors (or -i) option.
• + The plus modifier tells make to execute the
command even if the --just-print (or -n)
command-line option is given to make.
9. Phony target
Goal: phony target is out of date.
Example:
clean:
rm –rf *.o
$touch clean
$make clean
make: `clean’ is up to date.
10. Phony target
• Remember! Make cannot distinguish the
different between target and phony target. So,
we need define following:
.PHONY: clean
clean:
rm –rf *.o
(2)
14. Variable name
• Run on Bash
hello:
@echo "Hello, $${USER}" #shell variable USER
@echo "Hello, ${USER}" #make variable USER
or
hello:
@echo "Hello, $$USER" #shell variable USER
@echo "Hello, $(USER)" #make variable USER
15. Automatic variable
• $@ target
• $% archive member,
Example: $@ is foo.a, $% is bar.o
foo.a(bar.o): bar.o
commands…
• $< the first prereq
• $? The names of all prerequisites that
are newer than the target
16. Automatic variable
• $^ The names of all the prerequisites. This list
has duplicate names removed.
• $+ Similar to $^, but it includes duplicates.
• $* The stem of the target filename.
Example: $* is hello
hello.o: hello.c
gcc hello.c –o hello.o
(3)
17. VPATH and vpath
• We can use VPATH or vpath to tell make where to
find the source code.
.
|-- inc
| `-- saydone.h
|-- log
|-- Makefile
`-- src
|-- hello.c
|-- saydone.c
18. VPATH and vpath
• Without VPATH or vpath, we make it and we
will get~
$make
make: *** No rule to make target `hello.c', needed by
`hello.o'. Stop.
• So, we need to tell make where to find source
code by VPATH or vpath.(4)
19. Pattern rule
For example:
hello: hello.o
hello.o: hello.c
$make
cc -c -o hello.o hello.c
cc hello.o -o hello
We need to key “make - -print-data-base” to
understand pattern rule.(5)
25. When Variables Are Expanded
• The righthand side of += is expanded
immediately if the lefthand side was originally
defined as a simple variable. Otherwise, its
evaluation is deferred.
• For rules, the targets and prerequisites are
always immediately expanded while the
commands are always deferred.
• (7.1)
28. Target- and Pattern-Specific Variables
Example:
gui.o: gui.h
$(COMPILE.c) -DUSE_NEW_MALLOC=1 $(OUTPUT_OPTION) $<
or you can do it same as following
gui.o: CPPFLAGS += -DUSE_NEW_MALLOC=1
gui.o: gui.h
#default pattern rule
Another example is libffmpeg.
29. Where Variables Come From
• Command line: (V)
– make CFLAGS=-g CPPFLAGS=‘-DBSD –DDEBUG’
• File:
– by include
• Environment:
– by export or unexport
31. include
• The include directive is used like this:
include definitions.mk
• Special characteristic.
(4)
• If any of the include files is updated by a rule,
make then clears its internal database and
rereads the entire makefile.
32. Standard make Variables
• MAKE_VERSION:
– This is the version number of GNU make.
• CURDIR:
– This variable contains the current working directory of the
executing make process.
• MAKECMDGOALS:
– It contains a list of all the targets specified on the
command line for the current execution of make.
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEPEND)
Endif
(v)