GriMel
GriMel

Reputation: 2320

Stop make if argument not passed

I have a makefile

PATH = "MyFolder_"{ver}

compile:
    [list_of_commands] $PATH

And run it like this

make ver="1.1" compile

How do I stop compiling in case if no ver specified?
I want something like this

#input
make compile

And then output

No version specified. Compilation terminated.

Upvotes: 1

Views: 993

Answers (1)

MadScientist
MadScientist

Reputation: 101111

There are many ways to do it. Partly it depends on which version of make you're using, and which operating system you're running it on (which shell make invokes).

Note you should NOT use a variable PATH in your makefile; that's the system's PATH variable and resetting it will break all your recipes.

Also it's usually a bad idea to include quotes in the variable like that. If you want it quoted then add the quotes in the recipe.

If you have GNU make you can do this:

ifeq ($(ver),)
$(error No version specified.)
endif

If you don't have GNU make but you're using a UNIX system or Windows with a UNIX shell, you can do this:

MYPATH = MyFolder_$(ver)
compile:
        [ -n "$(ver)" ] || { echo "No version specified."; exit 1; }
        [list_of_commands] "$(MYPATH)"

If you're using Windows with Windows command.com then you can do something similar but I'm not sure of the details.

Upvotes: 2

Related Questions