nad87563
nad87563

Reputation: 4092

Makefile logical AND

How to perform a logical AND in makefile. if I run make test It works as expected it gives the output Both PARAMETERS are required. If one of the parameter is missing It should still give the same output but its not working that way for example if I run make test PARAM1=abc it should output Both PARAMETERS are required.How can I mandate both the parameters.

%/test:
    ifeq ($(PARAM1)$(PARAM2),)
        @echo "Both PARAMETERS are required"
        @exit 1
    endif
    @echo "Do Something $(PARAM1) $(PARAM2)"

I have tried the below code and it gives the error *** missing separator. Stop. I am not familiar with makefile any help is appreciated.

%/test: 
    @# $(or $(and $(PARAME1),$(PARAM2)),$(error Both PARAMETERS must be set))   
    @>&2 echo "Do Something $(PARAM1),$(PARAME2)"   

Upvotes: 1

Views: 297

Answers (1)

tripleee
tripleee

Reputation: 189638

Your test by its very nature checks that the concatenation of the two is the empty string. If that's not what you want to check, perform a different check. For example,

%/test:
    @# $(or $(and $(PARAM1),$(PARAM2)),$(error Both PARAMETERS must be set))

Various other variations; Makefile set if variable is empty

Upvotes: 2

Related Questions