Akim Demaille wrote: > Le 21 sept. 2012 à 16:44, Jim Meyering a écrit : > > Hi! > >>> diff --git a/top/maint.mk b/top/maint.mk >>> index 87bbde9..e8ea768 100644 >>> --- a/top/maint.mk >>> +++ b/top/maint.mk >>> @@ -91,13 +91,22 @@ my_distdir = $(PACKAGE)-$(VERSION) >>> # Old releases are stored here. >>> release_archive_dir ?= ../release >>> >>> +# Validate and return $(RELEASE_TYPE), or die. >>> +GET_RELEASE_TYPE = \ >>> + $(if $(RELEASE_TYPE), \ >>> + $(or $(shell case '$(RELEASE_TYPE)' in \ >>> + (alpha|beta|stable) echo $(RELEASE_TYPE);; \ >>> + esac), \ >>> + $(error invalid RELEASE_TYPE: $(RELEASE_TYPE))), \ >>> + $(error RELEASE_TYPE undefined)) >> >> This looks like a fine improvement. >> However, can't you do it without the cost of a $(shell ...)? >> How about using $(findstring ...) instead? >> Would be nice, but not required. > > I tried to do it in pure GNU Make, but I couldn't find a > means to do it. For instance findstring finds alpha in > alphabet. Could find a means to use filter or filter-out > either to make sure there is just one string, and one > I want.
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))) > I find it surprising that there is nothing available to > compare strings (but ifeq etc. which does not apply here: > I want the code to be run when the variable is read, not > when it is defined). ... Yeah, GNU make functions do take some getting used to.