2017-05-31 77 views
0

我在檢查我的ENVIRONMENT變量是否爲空,並且是developmentproductionMakefile - 如何檢查變量是否爲空並且是兩個值之一

ENVIRONMENT ?= development 

define ENV_CHECK 
     $(if $(or $(call seq,$(1),development),$(call seq,$(1),production)),true,false) 
endef 

.PHONY: test 
test: 
     @echo "$(ENVIRONMENT)" 
     $(call ENV_CHECK,$(ENVIRONMENT)) 

make test失敗,下面的錯誤

# make test 
development 
false 
make: *** [test] Error 1 

回答

2

這將是一個老生常談的某種解決方案:

的Makefile

ENVIRONMENT ?= development 
ifeq ($(filter $(ENVIRONMENT),development production),) 
$(error invalid `ENVIRONMENT` value) 
endif 

.PHONY: test 
test: 
    @echo "$(ENVIRONMENT)" 

8.2 Functions for String Substitution and Analysis