Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile syntax: what is $(RM)?

I saw the following Makefile online (here):

hello:

clean:
    $(RM) hello

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

  • 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)?
like image 475
Keita Avatar asked Dec 01 '16 09:12

Keita


People also ask

What is $( make in makefile?

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.

What does $< in makefile mean?

The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file. For example: hello.o: hello.c hello.h gcc -c $< -o $@ Here, hello.o is the output file.

What is $$ in makefile?

$$ means be interpreted as a $ by the shell. the $(UNZIP_PATH) gets expanded by make before being interpreted by the shell.

What is makefile target?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).


1 Answers

It's a Makefile variable. There are explicit variables (which are defined inside a Makefile) and implicit variables (defined by make, can be overriden by you).

You can see a list of implicit variables with this flag:

make -p

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

You can expand a variable with the syntax $(NAME) or ${NAME}

like image 191
Danh Avatar answered Sep 30 '22 00:09

Danh