Can I make a makefile abort outside of a rule?

前端 未结 1 1212
离开以前
离开以前 2021-01-15 04:27

At the top of my Makefile, before any of the rules, I have the following:

ifeq ($(ENVIRONMENT),LOCAL)
    TARGET := local_target
else
    TARGET := hello
end         


        
相关标签:
1条回答
  • 2021-01-15 04:46

    exit is a shell command, so you could use the shell assignment operator (i.e.: !=) inside the Makefile to call exit:

    TARGET != exit -1
    

    This would be actually equivalent to:

    TARGET := $(shell exit -1)
    

    Note again that this calls a shell that in turns runs the shell's exit built-in, i.e.: it does not exit make. The typical approach for exiting while processing a makefile is to call GNU Make's error built-in function instead:

    $(error Error-message-here)
    

    Putting everything together:

    ifeq ($(ENVIRONMENT),LOCAL)
     TARGET := local_target
    else # indent with spaces, not a tab
     $(error ENVIRONMENT not set to LOCAL)
    endif
    
    0 讨论(0)
提交回复
热议问题