Le 22 sept. 2012 à 17:02, Jim Meyering a écrit : > How about something like this? > > release-type = > \ > $(subst :, , \ > $(if $(RELEASE_TYPE), \ > $(or $(findstring :$(RELEASE_TYPE):,:alpha:beta:stable:), > \ > $(error invalid RELEASE_TYPE: $(RELEASE_TYPE))), \ > $(error RELEASE_TYPE undefined))) > > That's not quite right because it fails to reject RELEASE_TYPE=alpha:beta. > Adding one more "if" just for that case should do the job: > > release-type = > \ > $(subst :, , \ > $(if $(RELEASE_TYPE), \ > $(if $(findstring :,$(RELEASE_TYPE)), \ > $(error invalid RELEASE_TYPE: $(RELEASE_TYPE)), \ > $(or $(findstring :$(RELEASE_TYPE):,:alpha:beta:stable:), \ > $(error invalid RELEASE_TYPE: $(RELEASE_TYPE)))), \ > $(error RELEASE_TYPE undefined)))
Nice! Further improvement: use " " instead of ":" as separator, as it is a more natural separator in Make, which removes the need to add and strip these ":", and you get something which is more generic: _null := # Null character. _sp := $(_null) # White space. RELEASE_TYPES = alpha beta stable # member-check VARIABLE,VALID-VALUES member-check = \ $(if $($(1)), \ $(if $(findstring $(_sp),$($(1))), \ $(error invalid $(1): '$($(1))', expected $(2)), \ $(or $(findstring $(_sp)$($(1))$(_sp),$(_sp)$(2)(_sp)), \ $(error invalid $(1): '$($(1))', expected $(2)))), \ $(error $(1) undefined)) $(call member-check,RELEASE_TYPE,$(RELEASE_TYPES)) I also realized that is-equal is findstring $(1),$(2) && findstring $(2),$(1). I couldn't find a means to factor elegantly the checks to have a single $(error invalid $(1)).