Reading User Input in a Makefile Script
08:15 09 Sep 2018

I have a very simple Makefile (that just recursively calls another subdirectory make):

all:
    cd addons/godot-haskell-plugin && make && cd -
run:
    cd addons/godot-haskell-plugin && make run && cd -

What I'd like to do is

  1. Check if shell variable ENV_VAR is defined.
  2. If it is, then run the Makefile as usual (i.e., ENV_VAR=1 make all should do exactly as make all above).
  3. If it isn't, then prompt the user with a message "Warning: ENV_VAR isn't defined; continue? [Y/n]", where an input of "Y" passes make all and make run as usual, and an input of "n" simply echos a message and exits.

I know that to do this in bash you would use a combination of echo and read functions. But it's unclear how to do this in Make.

shell makefile