Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read input variable in makefile and set variable upon it`s name

I have a makefile where I want to read module name from input and then make directory based on it`s name. here is my code:

build:       @read -p "Enter Module Name:" module;       module_dir=./modules/$$module       mkdir -p $$module_dir/build;   

But after setting module_dir, it contains only ./modules/ (with no module name concatenated).
What is wrong in my code?

thanks for your answers

like image 344
armezit Avatar asked Aug 29 '12 03:08

armezit


People also ask

How do I read user input in makefile?

If you want to get user input from within a Makefile, ensure you run the read command in one line. It turns out that each line is run in its own subshell. So if you read in user input, ensure you have semicolons and backslashes to ensure commands are run in the same subshell.

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.


1 Answers

Each command runs in its own subshell, so variables can't survive from one command to the next. Put them on the same line and they'll work:

build:       @read -p "Enter Module Name:" module; \       module_dir=./modules/$$module; \     mkdir -p $$module_dir/build 
like image 126
Beta Avatar answered Oct 08 '22 19:10

Beta