In makefile, ${CC} -o myfile myfile.c
and $(CC) -o myfile myfile.c
both work fine even without definition of CC. My question is:
$(..)
and ${..}
?{}
or ()
to lowercase if that string is not defined?$${dir}
need two $$
infor dir in ${DIR}; do (cd $${dir}; ${MAKE}); done
${}
and $()
?And in your scenario, $MAKE is used in commands part (recipe) of makefile. It means whenever there is a change in dependency, make executes the command make --no-print-directory post-build in whichever directory you are on.
$(CC) -o executablename fileA.o fileB.o fileC.o -lm. This is a dependency and it means that the target "myprogram" should invoke the compiler whenever fileA.o, fileB.o, or fileC.o change. In particular, it invokes the compiler referred to in the variable "CC" and creates an executable called "executablename".
$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.
$(patsubst PATTERN,REPLACEMENT,TEXT) Finds whitespace-separated words in TEXT that match PATTERN and replaces them with REPLACEMENT. Here PATTERN may contain a % which acts as a wildcard, matching any number of any characters within a word.
There is no difference between ()
and {}
for Make.
If you use $$
in a recipe, then $
is "escaped" and passed to the shell. The shell may then make a difference between $()
or ${}
. But that is entirely up to the shell, and has nothing to do with Make or makefiles.
In the recipe command that you quote
for dir in ${DIR}; do (cd $${dir}; ${MAKE}); done
Make does this:
DIR
, for ${DIR}
, and that could just as well have been $(DIR)
$$
with $
("escaping", so that $
could be passed to the shell)MAKE
for ${MAKE}
, again this could have been $(MAKE)
. The value of MAKE
is automatically setup by Make, to the make executable that is being used.${}
the way it wants.CC
, similarly to MAKE
is one of those variables that are by default pre-defined by Make, that's why it "works" even if you don't set it yourself.
By the way, a better way to write this recipe for "target" is
.PHONY: $(DIR) target: $(DIR) $(DIR): $(MAKE) -C $@
Please consult the manual for explanation of things that are unclear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With