Professional Documents
Culture Documents
Makefile
1 78
2005 10 14
Makefile
...............................................................................................................................6
...............................................................................................6
Makefile ............................................................................................................7
Makefile ..............................................................................................................7
...........................................................................................................................8
make........................................................................................................9
makefile....................................................................................................10
make..........................................................................................................11
makefile....................................................................................................12
.....................................................................................................13
Makefile ..........................................................................................................13
Makefile ....................................................................................................13
1 ..............................................................................................................14
2 ..............................................................................................................14
3 ..........................................................................................................14
4 ..............................................................................................................14
5 ......................................................................................................................14
Makefile ........................................................................................................15
Makefile ....................................................................................................15
MAKEFILES................................................................................................16
make..........................................................................................................16
.....................................................................................................................17
.........................................................................................................................17
.....................................................................................................................17
.....................................................................................................18
.........................................................................................................................19
.............................................................................................................................20
.............................................................................................................................22
.........................................................................................................................22
.............................................................................................................24
.......................................................................................................................25
.........................................................................................................................26
.........................................................................................................................26
.........................................................................................................................27
make..............................................................................................................28
.....................................................................................................................30
.......................................................................................................................30
.....................................................................................................................31
.................................................................................................................32
.................................................................................................................34
.....................................................................................................................37
override ..........................................................................................................37
.........................................................................................................................38
2 78
2005 10 14
Makefile
.........................................................................................................................38
.........................................................................................................................39
.........................................................................................................................40
...............................................................................................................40
.................................................................................................................................40
.................................................................................................................................42
.......................................................................................................................43
.............................................................................................................44
.............................................................................................................44
1subst .......................................................................................................................44
2patsubst.................................................................................................................45
3strip .........................................................................................................................45
4findstring ...............................................................................................................46
5filter.........................................................................................................................46
6filter-out.................................................................................................................46
7sort ..........................................................................................................................47
8word ........................................................................................................................47
9wordlist ..................................................................................................................47
10words....................................................................................................................47
11firstword..............................................................................................................48
12....................................................................................................48
.............................................................................................................48
1dir.............................................................................................................................48
2notdir ......................................................................................................................48
3suffix .......................................................................................................................49
4basename..............................................................................................................49
5addsuffix................................................................................................................49
6addprefix ...............................................................................................................49
7join...........................................................................................................................50
foreach ................................................................................................................50
if ............................................................................................................................50
call ..........................................................................................................................51
origin .....................................................................................................................51
undefined .................................................................................................................52
default .......................................................................................................................52
file ...............................................................................................................................52
command line.........................................................................................................52
override ....................................................................................................................52
automatic .................................................................................................................52
shell .......................................................................................................................53
make..........................................................................................................53
1error ........................................................................................................................53
2warning ..................................................................................................................54
make ..............................................................................................................54
3 78
2005 10 14
Makefile
make..............................................................................................................54
Makefile ................................................................................................................54
.........................................................................................................................55
all ................................................................................................................................56
clean ..........................................................................................................................56
install .........................................................................................................................56
print ...........................................................................................................................56
tar ...............................................................................................................................56
dist..............................................................................................................................56
TAGS ..........................................................................................................................56
checktest ..........................................................................................................56
.........................................................................................................................57
make..................................................................................................................57
...................................................................................................................61
.................................................................................................................61
.................................................................................................................62
1C ...........................................................................................63
2C++ .....................................................................................63
3Pascal..................................................................................63
4Fortran/Ratfor..................................................................63
5Fortran/Ratfor..............................................................63
6Modula-2 ...........................................................................63
7 ..............................................................................64
8Object .................................................................................64
9Yacc C .....................................................................................64
10Lex C.....................................................................................64
11Lex Ratfor ...........................................................................65
12CYaccLexLint ..................................65
.....................................................................................................65
1 ..................................................................................................65
2 ..............................................................................................66
.....................................................................................................................67
.................................................................................................................68
1 ..........................................................................................................68
2 ..........................................................................................................69
3 ..............................................................................................................70
4 ..............................................................................................................72
5 ..................................................................................................72
"" .................................................................................................73
.........................................................................................................74
make....................................................................................75
.........................................................................................................75
.................................................................................................75
.................................................................................................76
4 78
2005 10 14
Makefile
.........................................................................................................................76
...........................................................................................................................77
5 78
2005 10 14
Makefile
UNIX GCC CC
CC++ pas
Windows .obj UNIX .o
Object Filecompile Object File
link
C/C++
O OBJ
O OBJ
Object File
6 78
2005 10 14
Makefile
Makefile
make Makefile make
Makefile
GNU make 8 C 3
Makefile make
1 C
2 C C
3 C
Makefile make
make
Makefile
Makefile Makefile
target ... : prerequisites ...
command
7 78
2005 10 14
Makefile
...
...
target Object File
Label
prerequisites target
command make
Shell
target
prerequisites command prerequisites
target command
Makefile Makefile
Makefile
Makefile Makefile
3 8 C
Makefile
edit : main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
main.o : main.c defs.h
cc -c main.c
kbd.o : kbd.c defs.h command.h
cc -c kbd.c
command.o : command.c defs.h command.h
cc -c command.c
display.o : display.c defs.h buffer.h
cc -c display.c
insert.o : insert.c defs.h buffer.h
cc -c insert.c
search.o : search.c defs.h buffer.h
cc -c search.c
files.o : files.c defs.h buffer.h command.h
cc -c files.c
8 78
2005 10 14
Makefile
prerequisites .c .h .o
.o edit
Tab make
make targets prerequisites prerequisites
targets target make
clean C
lable make
make
lable makefile
make
make
1make Makefilemakefile
2target
edit
3 edit
edit .o edit
edit
4 edit .o make .o
.o
5 C H make .o .o
make edit
make make
9 78
2005 10 14
Makefile
make make
make
clean
make
make clean
file.c file.o
file.o file.o
edit edit edit
command.hkdb.ocommand.o files.o
edit
makefile
edit
edit : main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
[.o][.o]
clean
makefile makefile
makefile
makefile makefile C
10 78
2005 10 14
Makefile
.o objects
make
GNU make
[.o] make
11 78
2005 10 14
Makefile
makefile
make [.o][.h]
[.h] make
makefile
objects = main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
edit : $(objects)
cc -o edit $(objects)
$(objects) : defs.h
kbd.o command.o files.o : command.h
display.o insert.o search.o files.o : buffer.h
.PHONY : clean
clean :
rm edit $(objects)
12 78
2005 10 14
Makefile
makefile
.o
Makefile .o
clean:
rm edit $(objects)
.PHONY : clean
clean :
-rm edit $(objects)
.PHONY clean
rm
clean
make
clean
Makefile
Makefile
13 78
2005 10 14
Makefile
Makefile
1
Makefile
2
make
Makefile make
3
Makefile C
Makefile
4
Makefile Makefile C
include Makefile C
#if
5
Makefile UNIX Shell #
C/C++// Makefile #
\#
Makefile [Tab]
14 78
2005 10 14
Makefile
Makefile
make GNUmakefile
makefileMakefile
Makefile
GNUmakefile GNU make make
makefile make makefile
Makefile
Makefile Make.Linux
Make.SolarisMake.AIX Makefile make
-f--filemake -f Make.Linux make --file Make.AIX
Makefile
Makefile include Makefile C
#includeinclude
include <filename>
filename Shell include
[Tab]include <filename>
Makefilea.mkb.mkc.mk
foo.make$(bar) e.mk f.mk
include foo.make *.mk $(bar)
2<prefix>/include/usr/local/bin /usr/include
make make
makefile make
make make
include -
15 78
2005 10 14
Makefile
-include <filename>
include make
sinclude
MAKEFILES
MAKEFILESmake
include Makefile include
Makefile
make
make Makefile
Makefile
make
GNU make
make
1 Makefile
2 include Makefile
3
4
5
6
7
1-5 6-7
make make make
make
16 78
2005 10 14
Makefile
Makefile Makefile
make
Makefile
make
targets : prerequisites
command
...
17 78
2005 10 14
Makefile
targets
command target:prerequisites[Tab
] prerequisites
prerequisites
\make
make
make UNIX Shell/bin/sh
make
*?[...] Unix B-Shell ~
~/test$HOME
test ~hchen/test hchen test
clean:
rm -f *.o
Shell
print: *.c
lpr -p $?
touch print
print [.c]
$?
objects = *.o
[*.o]objects
*.oMakefile C/C++
objects [.o]
18 78
2005 10 14
Makefile
make
make make
Makefile VPATH
make make
VPATH = src:../headers
src../headersmake
make vpath
make VPATH
vapth <pattern>%%
%.h.h<pattern>
<directories><pattern>
vpath %.h ../headers
make ../headers.h
19 78
2005 10 14
Makefile
vpath vpath
<pattern><pattern>make vpath
clean
clean:
rm *.o temp
clean
make clean
clean
make
.PHONY
make
.PHONY : clean
cleancleanmake
clean
20 78
2005 10 14
Makefile
.PHONY: clean
clean:
rm *.o temp
Makefile
make
Makefile
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
Makefile all
all
.PHONY : allall
2005 10 14
Makefile
Makefile
$@
bigoutput : text.g
generate text.g -big > bigoutput
littleoutput : text.g
generate text.g -little > littleoutput
-$(subst output,,$@)$ Makefile subst
$@
$@
22 78
2005 10 14
Makefile
<target-parrtern>%.o<target>.o
<prereq-parrterns>%.c<target-parrtern>
<target-parrtern>%[.o]
[.c]
%
%\%
$object %.o.o
foo.o bar.o$object %.c
%.o%foo bar.c
foo.c bar.c$<$@$<
foo.c bar.c$@foo.o bar.o
foo.o
$(CC)
bar.o
$(CC)
: foo.c
-c $(CFLAGS) foo.c -o foo.o
: bar.c
-c $(CFLAGS) bar.c -o bar.o
%.o
23 78
2005 10 14
Makefile
Makefile main.c
#include "defs.h"
main.o : main.c defs.h
C
Makefile
C/C++
C/C++-M
cc -M main.c
GNU C/C++
-MM-M
gcc -M main.c
main.o: main.c defs.h /usr/include/stdio.h /usr/include/features.h \
/usr/include/sys/cdefs.h /usr/include/gnu/stubs.h \
/usr/lib/gcc-lib/i486-suse-linux/2.95.3/include/stddef.h \
/usr/include/bits/types.h /usr/include/bits/pthreadtypes.h \
/usr/include/bits/sched.h /usr/include/libio.h \
/usr/include/_G_config.h /usr/include/wchar.h \
/usr/include/bits/wchar.h /usr/include/gconv.h \
/usr/lib/gcc-lib/i486-suse-linux/2.95.3/include/stdarg.h \
/usr/include/bits/stdio_lim.h
2005 10 14
Makefile
name.c
name.d Makefile [.d][.c]
[.c][.d] make [.d]
Makefile
[.d]
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
[.d][.c]rm -f $@
[.d]$<[.c]
$@%.d C name.c%
name$$$$name.d.12345
sed sed
[.d]
25 78
2005 10 14
Makefile
Shell make
[Tab]
Tab
make
UNIX Shell make
/bin/shUNIX Shell Shell
Makefile # C/C++//
make @
make
make -s--slient
make
cd cd
exec:
cd /home/hchen
pwd
26 78
2005 10 14
Makefile
exec:
cd /home/hchen; pwd
make exec cd pwd
Makefile cd pwd /home/hchenmake
SHELL Shell UNIX
Shell/bin/sh MS-DOS MS-DOS SHELL
UNIX make SHELL
PATH MS-DOS
.exe.com.bat.sh
make make
make
mkdir
mkdir
mkdir mkdir
Makefile -
Tab
clean:
-rm -f *.o
make -i--ignore-errors
Makefile .IGNORE
make -k--keep-going
27 78
2005 10 14
Makefile
make
Makefile Makefile
Makefile
Makefile
subdir Makefile
Makefile
subsystem:
cd subdir && $(MAKE)
subsystem:
$(MAKE) -C subdir
$(MAKE) make
subdir make
Makefile Makefile Makefile
Makefile
Makefile
-e
Makefile
export <variable ...>
Makefile
unexport <variable ...>
variable = value
export variable
28 78
2005 10 14
Makefile
variable := value
export variable
variable += value
export variable
export
SHELL MAKEFLAGS
export Makefile MAKEFILES make
Makefile make Makefile
MAKEFILES Makefile
make -C,-f,-h-o
-W Makefile
subsystem:
cd subdir && $(MAKE) MAKEFLAGS=
MAKEFLAGS
-t,-n,-q
-w--print-directory
make make
/home/hchen/gnu/makemake -w
29 78
2005 10 14
Makefile
Makefile
defineendef
define run-yacc
yacc $(firstword $^)
mv y.tab.c $@
endef
run-yacc Makefile
defineendef Yacc
Yacc y.tab.c
foo.c : foo.y
$(run-yacc)
run-yacc$^foo.y$@foo.c$
make
Makefile C/C++
Makefile C/C++
Makefile Makefile
Makefile
:
30 78
2005 10 14
Makefile
#=fooFooFOO
Makefile
MakeFlags
$<$@
$
{}$
$$
prog.o : prog.c
cc -c prog.c
Makefile Makefile
31 78
2005 10 14
Makefile
Makefile
==
foo = $(bar)
bar = $(ugh)
ugh = Huh?
all:
echo $(foo)
make all$(foo)Huh? $(foo)$(bar)
$(bar)$(ugh)$(ugh)Huh?
CFLAGS = $(include_dirs) -O
include_dirs = -Ifoo -Ibar
CFLAGS-Ifoo -Ibar -O
CFLAGS = $(CFLAGS) -O
A = $(B)
B = $(A)
make make
make
make wildcardshell
make
:=
32 78
2005 10 14
Makefile
x := foo
y := $(x) bar
x := later
y := foo bar
x := later
y := $(x) bar
x := foo
y barfoo bar
make
MAKELEVEL
ifeq (0,${MAKELEVEL})
cur-dir := $(shell pwd)
whoami := $(shell whoami)
host-type := $(shell arch)
MAKE := ${MAKE} host-type=${host-type} whoami=${whoami}
endif
MAKELEVEL
make make
Makefile
nullstring :=
space := $(nullstring) # end of the line
nullstring Empty space
Empty
#
##
33 78
2005 10 14
Makefile
$(var:a=b)${var:a=b}var
aab
34 78
2005 10 14
Makefile
x = y
y = z
a := $($(x))
$(x)y$($(x))$(y)$(a)z
x=yx=$(y)
x
y
z
a
= y
= z
= u
:= $($($(x)))
$(a)u
x
y
z
a
= $(y)
= z
= Hello
:= $($(x))
$($(x))$($(y))$(y)za:=$(z)
Hello
x = variable1
variable2 := Hello
y = $(subst 1,2,$(x))
z = y
a := $($($(z)))
$($($(z))) $($(y)) $($(subst
1,2,$(x)))$(x)variable1subst variable11
2variable1variable2
$(a)$(variable2)Hello
first_second = Hello
a = first
35 78
2005 10 14
Makefile
b = second
all = $($a_$b)
$a_$bfirst_second$(all)Hello
ifdef do_sort
func := sort
else
func := strip
endif
bar := a d b g q c
foo := $($(func) $(bar))
do_sortfoo := $(sort a d b g q c)$(foo)
a b c d g qdo_sortfoo := $(sort a d bg q
c) strip
dir = foo
$(dir)_sources := $(wildcard $(dir)/*.c)
define $(dir)_print
lpr $($(dir)_sources)
endef
dirfoo_sourcesfoo_print
36 78
2005 10 14
Makefile
+=
objects = main.o foo.o bar.o utils.o
objects += another.o
$(objects)main.o foo.o bar.o utils.o another.oanother.o
+=
objects = main.o foo.o bar.o utils.o
objects := $(objects) another.o
+=
+==+=
:=+=:=
variable := value
variable += more
variable := value
variable := $(variable) more
variable = value
variable += more
=+==
make
override
make Makefile
37 78
2005 10 14
Makefile
Makefile override
define define
define endef
=
[Tab] define [Tab]
make
define
define two-lines
echo foo
echo $(bar)
endef
2005 10 14
Makefile
Makefile make
make -e Makefile
CFLAGS
Makefile
Makefile CFLAGS Makefile
make Makefile
Makefile
Makefile
exprot
Makefile
Makefile
$<
Target-specific Variable
prog : CFLAGS = -g
prog : prog.o foo.o bar.o
$(CC) $(CFLAGS) prog.o foo.o bar.o
prog.o : prog.c
$(CC) $(CFLAGS) prog.c
39 78
2005 10 14
Makefile
foo.o : foo.c
$(CC) $(CFLAGS) foo.c
bar.o : bar.c
$(CC) $(CFLAGS) bar.c
$(CFLAGS) prog
prog.o foo.o bar.o
$(CFLAGS)-g
make %
[.o]
%.o : CFLAGS = -O
make
$(CC)gcc GNU
40 78
2005 10 14
Makefile
libs_for_gcc = -lgnu
normal_libs =
foo: $(objects)
ifeq ($(CC),gcc)
$(CC) -o foo $(objects) $(libs_for_gcc)
else
$(CC) -o foo $(objects) $(normal_libs)
endif
foo$(CC)
ifeqelse endififeq
else endif
endif
$(CC)gcc foo
foo: $(objects)
$(CC) -o foo $(objects) $(libs_for_gcc)
$(CC)gcccc foo
foo: $(objects)
$(CC) -o foo $(objects) $(normal_libs)
libs_for_gcc = -lgnu
normal_libs =
ifeq ($(CC),gcc)
libs=$(libs_for_gcc)
else
libs=$(normal_libs)
endif
foo: $(objects)
$(CC) -o foo $(objects) $(libs)
41 78
2005 10 14
Makefile
<conditional-directive>
<text-if-true>
endif
<conditional-directive>
<text-if-true>
else
<text-if-false>
endif
<conditional-directive>ifeq
ifeq
ifeq
ifeq
ifeq
ifeq
ifeq
(<arg1>,
'<arg1>'
"<arg1>"
"<arg1>"
'<arg1>'
<arg2>)
'<arg2>'
"<arg2>"
'<arg2>'
"<arg2>"
arg1arg2 make
(<arg1>,
'<arg1>'
"<arg1>"
"<arg1>"
'<arg1>'
<arg2>)
'<arg2>'
"<arg2>"
'<arg2>'
"<arg2>"
42 78
2005 10 14
Makefile
arg1arg2ifeq
ifdef
ifdef <variable-name>
<variable-name>
<variable-name>ifdef
bar =
foo = $(bar)
ifdef foo
frobozz = yes
else
frobozz = no
endif
foo =
ifdef foo
frobozz = yes
else
frobozz = no
endif
$(frobozz)yesno
ifndef
ifndef <variable-name>
ifdef
<conditional-directive>[Tab]
#elseendif
[Tab]
make Makefile
$@
make
43 78
2005 10 14
Makefile
Makefile
make
$
$(<function> <arguments>)
${<function> <arguments>}
<function>make <arguments>
,$
$(subst a,b,$(x))
$(subst a,b,${x})
comma:= ,
empty:=
space:= $(empty) $(empty)
foo:= a b c
bar:= $(subst $(space),$(comma),$(foo))
$(comma)$(space)$(empty)$(foo)
a b c$(bar)subst
$(foo)$(bar)a,b,c
1subst
$(subst <from>,<to>,<text>)
subst
<text><from><to>
44 78
2005 10 14
Makefile
2patsubst
$(patsubst <pattern>,<replacement>,<text>)
patsubst
<text>Tab
<pattern><replacement><pattern>
%<replacement>%<replacement>
%<pattern>%
\\%
%
$(var:<pattern>=<replacement>)
$(patsubst <pattern>,<replacement>,$(var))
$(var: <suffix>=<replacement>)
$(patsubst %<suffix>,%<replacement>,$(var))
objects = foo.o bar.o baz.o
$(objects:.o=.c)$(patsubst %.o,%.c,$(objects))
3strip
$(strip <string>)
strip
<string>
45 78
2005 10 14
Makefile
$(strip a b c )
a b c a b c
4findstring
$(findstring <find>,<in>)
findstring
<in><find>
<find>
$(findstring a,a b c)
$(findstring a,b c)
a
5filter
$(filter <pattern...>,<text>)
filter
<pattern><text><pattern>
<pattern>
6filter-out
$(filter-out <pattern...>,<text>)
filter-out
<pattern><text><pattern>
<pattern>
46 78
2005 10 14
Makefile
7sort
$(sort <list>)
sort
<list>
8word
$(word <n>,<text>)
word
<text><n>
<text><n><n><text>
9wordlist
$(wordlist <s>,<e>,<text>)
wordlist
<text><s><e><s><e>
<text><s><e><s><text>
<e><text><s><text>
10words
$(words <text>)
words
<text>
<text>
$(words, foo bar baz)3
<text>$(word $(words <te
xt>),<text>)
47 78
2005 10 14
Makefile
11firstword
$(firstword <text>)
firstword
<text>
<text>
$(firstword foo bar)foo
word $(word 1,<text>)
12
make VPATH
CFLAGS
1dir
$(dir <names...>)
dir
<names>/
./
<names>
$(dir src/foo.c hacks)src/ ./
2notdir
$(notdir <names...>)
48 78
2005 10 14
Makefile
notdir
<names> /
<names>
$(notdir src/foo.c hacks)foo.c hacks
3suffix
$(suffix <names...>)
suffix
<names>
<names>
$(suffix src/foo.c src-1.0/bar.c hacks).c .c
4basename
$(basename <names...>)
basename
<names>
<names>
$(basename src/foo.c src-1.0/bar.c hacks)src/foo src-1.0/b
ar hacks
5addsuffix
$(addsuffix <suffix>,<names...>)
addsuffix
<suffix><names>
6addprefix
$(addprefix <prefix>,<names...>)
addprefix
<prefix><names>
49 78
2005 10 14
Makefile
7join
$(join <list1>,<list2>)
join
<list2><list1><list1>
<list2><list1><list2>
<list1><list2><list2>
foreach
foreach Makefile
foreach Unix Shell/bin/sh for C-Shell
/bin/csh foreach
$(foreach <var>,<list>,<text>)
<list><var>
<text><text><text>
<text>
foreach
<var><list><text><var>
<list>
names := a b c d
files := $(foreach n,$(names),$(n).o)
$(name)n$(n).o
$(n) foreach
$(files)a.o b.o c.o d.o
foreach <var>foreach
<var> foreach
if
if GNU make ifeq
if
$(if <condition>,<then-part>)
50 78
2005 10 14
Makefile
$(if <condition>,<then-part>,<else-part>)
if else if
<condition> if
<then-part><else-part>
if <condition>
<then-part>
<condition><else-part>
<else-part>
<then-part><else-part>
call
call
call
$(call <expression>,<parm1>,<parm2>,<parm3>...)
make <expression>$(1)$(2)$(3)
<parm1><parm2><parm3><expression> call
origin
origin
$(origin <variable>)
<variable><variable>
$Origin origin
:
51 78
2005 10 14
Makefile
undefined
<variable>origin undefined
default
<variable>CC
environment <variable> Makefile -e
file
<variable> Makefile
command line
<variable>
override
<variable> override
automatic
<variable>
Makefile Makefile
Make.def Make.def bletch
bletch
Make.def
Makefile
ifdef bletch
ifeq "$(origin bletch)" "environment"
bletch = barf, gag, etc.
endif
endif
override
override override
52 78
2005 10 14
Makefile
shell
shell Shell
`shell
awksed
make
make make Makefile
make
1error
$(error <text ...>)
<text ...>error
ifdef ERROR_001
$(error error is $(ERROR_001))
endif
2005 10 14
Makefile
2warning
$(warning <text ...>)
error make ma
ke
make
make make
makefile make
make
make
make
0 -
1 - make 1
2 - make -q make 2
Make
Makefile
GNU make Makefile
GNUmakefilemakefileMakefile
make Makefile
make -f--file--makefile
makefile hchen.mk make
make f hchen.mk
54 78
2005 10 14
Makefile
make -f makefile
make
make makefile
make makefile
make
make make clean
makefile -
=
make make
make MAKECMDGOALS
.PHONY: all
all: prog1 prog2 prog3 prog4
makefile prog1
prog2 prog3 prog4make all
all makemake prog2
prog2
make makefile
makefile Unix
GNU makefile
makefile
55 78
2005 10 14
Makefile
all
clean
make
install
tar
tar
dist
tar Z gz
TAGS
checktest
makefile
makefile GNU
GNU UNIX
makefile makefile
56 78
2005 10 14
Makefile
makefile
make
-n
--just-print
--dry-run
--recon
makefile
-t
--touch
make
-q
--question
-W <file>
--what-if=<file>
--assume-new=<file>
--new-file=<file>
Make
-n
-p-v makefile
make
GNU make 3.80 make
make
-b
-m
make
57 78
2005 10 14
Makefile
-B
--always-make
-C <dir>
--directory=<dir>
makefile -Cmake
make C ~hchen/test C prog
make C ~hchen/test/prog
debug[=<options>]
make
<options>
a all
b basic
v verbose b makefile
i implicit
j jobs PID
m makefile make makefile makefile makefile
-d
--debug=a
-e
--environment-overrides
makefile
-f=<file>
--file=<file>
--makefile=<file>
makefile
-h
--help
-i
--ignore-errors
-I <dir>
58 78
2005 10 14
Makefile
--include-dir=<dir>
makefile -I
-j [<jobsnum>]
--jobs[=<jobsnum>]
make
-j-j
MS-DOS
-k
--keep-going
-l <load>
--load-average[=<load]
max-load[=<load>]
make
-n
--just-print
--dry-run
--recon
-o <file>
--old-file=<file>
--assume-old=<file>
<file>
-p
--print-data-base
makefile makefile
makefilemake -qp
makefile make p f
/dev/null makefile
makefile
-q
--question
0
2
-r
--no-builtin-rules
59 78
2005 10 14
Makefile
make
-R
--no-builtin-variabes
make
-s
--silent
--quiet
-S
--no-keep-going
--stop
-kmake MAKEFLAGS
-k
-t
--touch
UNIX touch
-v
--version
make make
-w
--print-directory
makefile make
--no-print-directory
-w
-W <file>
--what-if=<file>
--new-file=<file>
--assume-file=<file>
<file>-n
-n UNIX touch<file>
--warn-undefined-variables
make
60 78
2005 10 14
Makefile
Makefile
C/C++Unix [.o]Windows [.obj]
Makefile
make
Makefile [.c][.o]
make [.o]
CFLAGS
Makefile
Makefile
make make
make
Makefile
foo : foo.o bar.o
cc o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
Makefile foo.o bar.o
make
make
make [.o]
61 78
2005 10 14
Makefile
foo.o : foo.c
cc c foo.c $(CFLAGS)
bar.o : bar.c
cc c bar.c $(CFLAGS)
make C cc[.o]
[.o] make
make
make
foo.o : foo.p
foo.pPascal
foo.cfoo.c C
foo.o Pascal C make
foo.o C
make
make make
-r--no-builtin-rules
-r
.SUFFIXES
.out,.a, .ln, .o, .c, .cc, .C, .p, .f, .F, .r, .y, .l, .s, .S, .mod, .sym,
.def, .h, .info, .dvi, .tex, .texinfo, .texi, .txinfo, .w, .ch .web, .sh, .elc, .el
62 78
2005 10 14
Makefile
1 C
<n>.o<n>.c$(CC) c
$(CPPFLAGS) $(CFLAGS)
2 C++
<n>.o<n>.cc<n>.C
$(CXX) c $(CPPFLAGS) $(CFLAGS)
.cc C++
.C
3 Pascal
<n>.o<n>.p$(PC) c $
(PFLAGS)
4 Fortran/Ratfor
<n>.o<n>.r<n>.F<n>.f
:
.f $(FC) c $(FFLAGS)
.F $(FC) c $(FFLAGS) $(CPPFLAGS)
.f $(FC) c $(FFLAGS) $(RFLAGS)
5 Fortran/Ratfor
<n>.f<n>.r<n>.F
Ratfor Fortran Fortran
.F $(FC) F $(CPPFLAGS) $(FFLAGS)
.r $(FC) F $(FFLAGS) $(RFLAGS)
6 Modula-2
<n>.sym <n>.def
$(M2C)$(M2FLAGS) $(DEFFLAGS) <n.o>
63 78
2005 10 14
Makefile
7
<n>.o <n>.sas
$(AS) $(ASFLAGS) <n>.s
<n>.S C cpp$(AS) $(ASFLAGS)
8 Object
<n><n>.o C
ld$(CC) $(LDFLAGS) <n>.o $(LOADLIBES) $(LDLIBS)
Object
x : y.o z.o
x.cy.cz.c
cc -c x.c -o x.o
cc -c y.c -o y.o
cc -c z.c -o z.o
cc x.o y.o z.o -o x
rm -f x.o
rm -f y.o
rm -f z.o
x.c x
9Yacc C
<n>.cn.yYacc
$(YACC) $(YFALGS)
Yacc
10Lex C
<n>.cn.lLex $(LEX)
$(LFALGS)Lex
64 78
2005 10 14
Makefile
11Lex Ratfor
<n>.rn.lLex $(LEX)
$(LFALGS)
makefile make
make -R--nobuiltin-variables
C $(CC) c $(CFLAGS)
$(CPPFLAGS)Make cc$(CC)gcc
$(CFLAGS)-ggcc c -g
$(CPPFLAGS)
CC
CFLAGS
1
AR
ar
AS
as
65 78
2005 10 14
Makefile
CC
C cc
CXX
C++g++
CO
RCS co
CPP
C $(CC) E
FC
Fortran Ratfor f77
GET
SCCS get
LEX
Lex C Ratforlex
PC
Pascal pc
YACC
Yacc C yacc
YACCR
Yacc Ratfor yacc r
MAKEINFO
Texinfo .texi Info makeinfo
TEX
TeX TeX DVI tex
TEXI2DVI
Texinfo TeX DVI texi2dvi
WEAVE
Web TeX weave
CWEAVE
C Web TeX cweave
TANGLE
Web Pascal tangle
CTANGLE
C Web Cctangle
RM
rm f
66 78
2005 10 14
Makefile
ARFLAGS
AR rv
ASFLAGS
.s.S
CFLAGS
C
CXXFLAGS
C++
COFLAGS
RCS
CPPFLAGS
C C Fortran
FFLAGS
Fortran
GFLAGS
SCCS get
LDFLAGS
ld
LFLAGS
Lex
PFLAGS
Pascal
RFLAGS
Ratfor Fortran
YFLAGS
Yacc
[.o]
Yacc [.y][.c] C
[.c] C
[.c][.y] Yacc [.c]
C [.c][.o]
[.c]make
makefile
67 78
2005 10 14
Makefile
rm -f
makefile
.INTERMEDIATE
.INTERMEDIATE mid
make
.SECONDARY.SECONDARY : sec
%.o.PRECIOUS
make
Make foo.c
foomake foo.ofoo
cccc o foo foo.c
"%""%"
"%""%"
"%"
make Makefile "%"
1
"%"
"%""%""%.c"".c"
3
"s.%.c""s."".c"
5
"%""%""%"
68 78
2005 10 14
Makefile
"%""%"
%.o : %.c ; <command ......>
[.c][.o]
"a.o b.o""%c""a.c b.c"
"%"make
make
make make
2
,[.c][.o].
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
"$@""$<"
""
69 78
2005 10 14
Makefile
$@
"$@"
$%
"foo.a
(bar.o)""$%""bar.o""$@""foo.a"Unix
[.a]Windows [.lib]
$<
"%""$<"
$?
$^
$+
"$^"
$*
"%""dir/a.foo.b"
"a.%.b""$*""dir/a.foo"
"$*"
make "$*""foo.c"
".c" make "$*""foo" GNU make
70 78
2005 10 14
Makefile
make"$*"
make "$*"
"$?"
"lib" object object
Makefile
lib : foo.o bar.o lose.o win.o
ar r lib $?
$@$<$%$*
$(@F)
"$@""$@""dir/foo.o""$(@F)""foo.o""$(@F)"
"$(notdir $@)"
"$(*D)"
"$(*F)"
"$(*D)"
"dir""$(*F)""foo"
"$(%D)"
"$(%F)"
"archive(member)"
"member"
"$(<D)"
"$(<F)"
"$(^D)"
"$(^F)"
71 78
2005 10 14
Makefile
"$(+D)"
"$(+F)"
"$(?D)"
"$(?F)"
"$<"$
"$(<)""$<"
"""
"""
4
"%"
"%""%""%"
"""%.c""test.c""test"""
"%"""""
""
"e%t""src/eat""src/a"
""
"c%r""src/car"""
%.o : %.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) -D$(date)
%.o : %.s
72 78
2005 10 14
Makefile
""
.c.o: foo.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
".c.o""foo.h"
%.o: %.c foo.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
make ".SUFFIXES"
73 78
2005 10 14
Makefile
.SUFFIXES: #
.SUFFIXES: .c .o .h #
make "-r""-no-builtin-rules"
"SUFFIXE"".SUFFIXES"
"SUFFIXE"
T T
Makefile
"archive(member)"
T"member" T
1 T D N
T "src/foo.o"
D "src/"N "foo.o"
2 T N
3"%"
4
5
1""SS T N "%"
2"%"""S
D
3
""
4
6 5
1
2 5
3
4
74 78
2005 10 14
Makefile
7".DEFAULT"".DEFAULT"
T
make
Object Unix
"ar"
archive(member)
"ar"
foolib(hack.o) : hack.o
ar cr foolib hack.o
member
foolib(hack.o kludge.o)
foolib(hack.o) foolib(kludge.o)
Shell
foolib(*.o)
make "a(m)"
75 78
2005 10 14
Makefile
"(m)""%.o"
"make foo.a(bar.o)" Makefile "bar.o"
bar.o make bar.c bar.o
make
cc -c bar.c -o bar.o
ar r foo.a bar.o
rm -f bar.o
"$%"
""
""""
.c.a:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
$(AR) r $@ $*.o
$(RM) $*.o
(%.o)
$(CC)
$(AR)
$(RM)
: %.c
$(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
r $@ $*.o
$*.o
make "-j"
ar
make
"-j"
76 78
2005 10 14
Makefile
GNU make Makefile
make make
80% make"
" make make
GNU make VC nmakeBCB make UNIX
make Unix
make SCO Unix IBM AIX LinuxSolarisHP-UXAIX Alpha
Linux Solaris Unix make
Richard Stallman make cc/gcc
GNU make UNIX GNU GNU
GNU GNU
GNU Unix Windows""
make make
make Shell
Unix Makefile
tarawkmailsedcvscompresslsrmyaccrpmftp
"""""""""""
"
"@@@N###N"
make awk
sed"@@@N###N" C
" C" C "EXEC SQL" SQL
cc/gcc " C" cpre C
make
Unix
Makefile vi
"!make" vi Makefile
Makefile
Makefile
UNIX 400 200
Makefile
Makefile
77 78
2005 10 14
Makefile
GNU Makefile
Unix
/
P2PWeb ServiceJ2EE
MSNhaoel@hotmail.com
QQ753640
MSNhotmail
78 78
2005 10 14