1

I've make file with target that needs some variable (token) as pre-requisite

e.g.

token = 

deploy:
   http://api.run.cf.com $(token)

I need that the user enter the token (to the file) before he run the make deploy

If not provide some error, how can I do it ?

I've tried to add

ifndef token @echo Warning: token isn\'t defined\; abort

However not sure how to integrate it to the ` deploy target.

NSS
  • 755
  • 1
  • 11
  • 30
  • Is it possible to read the token from a file? This has the benefit to be able to run without interaction should you ever want to move the process to a build server. make likes files. make hates console. Really. – Vroomfondel Apr 27 '20 at 07:46

1 Answers1

1

User can add variables on the fly when running make

Example:

$ VAR1=44 OPTIONFORMKE=true make

This will set:

VAR1=44
&
OPTIONFORMAKE=true

as if they were provided as input parameters.

and in Makefile you can check

if [ "$OPTIONFORMAKE" == "true" ];then echo doing something here; fi

same for VAR1 or any other on-the-fly variable you want to pass

Ron
  • 5,900
  • 2
  • 20
  • 30
  • Thanks, not sure that I got the complete flow, how the if statement related to the target which i need to run , as I dont want to allow to run it if token is missing... – NSS Apr 27 '20 at 06:12
  • with the if statement you can check if the required token/variable is missing, and if it is echo a warning and `exit 1` – Ron Apr 27 '20 at 06:44