1

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)"   
nad87563
  • 3,672
  • 7
  • 32
  • 54
  • You must indent your lines with literal TAB characters, not spaces. Make sure your editor is not converting TABs to spaces for you. – MadScientist Nov 19 '20 at 23:07

1 Answers1

2

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

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • The code actually has a tab but Stack Overflow renders it as four spaces so you can't blindly copy/paste from here. – tripleee Nov 20 '20 at 08:22
  • Bug report: https://meta.stackoverflow.com/questions/403016/literal-tab-in-code-block-renders-as-four-spaces – tripleee Nov 20 '20 at 08:44