Abstract: Some Make topic
cc -M main.c
The result is main.o: main.c defs.h
For Sun forte 6, -xM -xM1
$@ the file names of the target of the rule
$% the target menber name, when the target is an archive member
$< the names of the first dependency
$? the names of all the dependencies that are newer than the target,with space between them
$^ the names of all the dependencies, whith spaces between them
The command is excuted by makeing a new subshell for eachline.
One line is One command
If you want to excute more than one commands in same shell, use ; to separate the commands in online.
For example, cd /usr/bin; ls
Or use \ to split shell command to multiple lines
For example,
cd /usr/bin; \
ls
clean:
-rm -f *.o
The canned commands is actually a variable, so the name must not confilict with other variable names.
define run-yacc
yacc $(firstword $ˆ)
mv y.tab.c $@
endef
The define directive does not expand.
To use the command sequences, substitute the vaiable into the commands of a rule.
foo.c : foo.y
$(run-yacc)
It has the form ‘$(var:a=b)’ (or ‘$’)
and its meaning is to take the value of the variable var, replace every a
at the end of a word with b in that value, and substitute the resulting
string.
foo := a.o b.o c.o
bar := $(foo:.o=.c)
sets ‘bar’ to ‘a.c b.c c.c’