Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$${HOME} or ${HOME} in Makefile?

$ cat Makefile 
all:
    echo VAR is ${HOME}
    echo VAR is $${HOME}

Gives

$ make
echo VAR is /home/abc
VAR is /home/abc
echo VAR is ${HOME}
VAR is /home/abc

Why does echo VAR is ${HOME} syntax work in Makefile? I thought, to use shell variables you have to use $${HOME}}

like image 753
Ankur Agarwal Avatar asked Jun 07 '18 22:06

Ankur Agarwal


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.

How can I get PWD in makefile?

You can use shell function: current_dir = $(shell pwd) . Or shell in combination with notdir , if you need not absolute path: current_dir = $(notdir $(shell pwd)) .

What is a makefile target?

A simple makefile consists of "rules" with the following shape: target ... : dependencies ... command ... ... A target is usually the name of a file that is generated by a program; examples of targets are executable or object files.


1 Answers

Yes and no. It is best to use $$ to be explicit. However, there is a special rule for environment variables:

Variables in make can come from the environment in which make is run. Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. But an explicit assignment in the makefile, or with a command argument, overrides the environment. (If the `-e' flag is specified, then values from the environment override assignments in the makefile. See section Summary of Options. But this is not recommended practice.)

like image 68
jeremysprofile Avatar answered Oct 12 '22 03:10

jeremysprofile