1.) What is the -g option of gcc?
Generate debugging info
2.) What are $* and $@
$*
is the stem of the rule. When you make rule like
%.ext: %.otherext
ext2otherext --input $? --output $@ --logfile $*.log
, and the rule tries to make file.ext
from file.otherext
, then to log goes to file.log
$@
is the target filename (file.ext
in the case above).
3.) How does it know to execute the last target?
This is a mystery.
$*
is used for intermediary files: like, when you try to make an %.so
out of %.c
, you'll need an intermediary %.o
which is neither target nor a source. You put:
%.so: %.c
gcc -fPIC -g -c -o $*.o $?
ld -shared -o $@ $*.o
In other words, in a %.extension
rule, $*
is everything but the .extension
.
As a target, $*
makes no sense.
Are you sure this rule is actually executed somewhere? When I try to reproduce it using your Makefile, it applies default rules (cc -o
) instead of gcc -g -o
Rule you need seems to be:
%: %.c
gcc -g -o $@ $?