Keita Keita - 1 year ago 73
C Question

Makefile syntax: what is $(RM)?

I saw the following Makefile online (here):


$(RM) hello

When there is a hello.c file in the same directory with the Makefile,
command in Terminal builds
executable. When
make clean
is run,
executable is removed by
rm -f hello
instead. So,
$(RM) hello
rm -f hello

  • What does $(FOO) mean? Is it a special syntax of Makefile, or something bash command?

  • Can I run other commands as well as $(RM), like $(PWD)?

Answer Source

It's a Makefile variable. There're explicit variable (which is defined inside Makefile) or implicit variable (defined by make, can be override by you).

The list of implicit variables can be found by:

make -p

some of the most common variables can be found at: 10.3 Variables Used by Implicit Rules

You can expand variable by $(NAME) or ${NAME}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download