Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Makefile variable from console if not set

Tags:

shell

makefile

I'm updating a Makefile that accesses some resources from an external source, i.e. there is a rule of the form

$(External)/% : 
    cvs up $@

...which works as expected for unrestricted resources. Now, there has been a feature drift, and the external resources requires a more complex login, so the rule has changed to something not too different from this:

$(External)/% : 
    cvs -d :pserver:$(CVSUSER)@cvs-server up $@

...which makes the rule dependent on the variable CVSUSER. The quick and easy way to enforce this would be to abort with a helpful error message if it's undefined. But that's no fun, I'd like to read the variable CVSUSER from console if it's unset by the time it's needed. I naively tried

CVSUSER ?= $(shell read -p "User name: ")

but that obviously does not work :) How would you go about doing this?

like image 430
Christoffer Avatar asked Apr 07 '26 10:04

Christoffer


1 Answers

$(shell) grabs the output from the shell command. But read reads input in a variable (REPLY by default) and does not output it. Here's a quick fix:

CVSUSER ?= $(shell read -p "User name: ";echo $$REPLY)
like image 112
laalto Avatar answered Apr 10 '26 13:04

laalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!