maint.mk: factor the validation of RELEASE_TYPE
authorAkim Demaille <akim@lrde.epita.fr>
Fri, 21 Sep 2012 12:11:18 +0000 (14:11 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Tue, 25 Sep 2012 09:50:52 +0000 (11:50 +0200)
With help from Jim Meyering.
http://lists.gnu.org/archive/html/bug-gnulib/2012-09/msg00132.html

* top/maint.mk (_empty, _sp): Move their definition earlier.
(member-check, release-type): New.
Use the latter instead of $(RELEASE_TYPE).
Remove now useless local checks.

ChangeLog
top/maint.mk

index ba00e87..0c63b76 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-09-21  Akim Demaille  <akim@lrde.epita.fr>
+
+       maint.mk: factor the validation of RELEASE_TYPE
+       With help from Jim Meyering.
+       http://lists.gnu.org/archive/html/bug-gnulib/2012-09/msg00132.html
+       * top/maint.mk (_empty, _sp): Move their definition earlier.
+       (member-check, release-type): New.
+       Use the latter instead of $(RELEASE_TYPE).
+       Remove now useless local checks.
+
 2012-09-20  Akim Demaille  <akim@lrde.epita.fr>
 
        maint.mk: silent rules
index 87bbde9..1851815 100644 (file)
@@ -28,6 +28,22 @@ ifneq ($(build_aux),)
 set $$(_build-aux) relative to $$(srcdir) instead of $$(build_aux)")
 endif
 
+# Helper variables.
+_empty =
+_sp = $(_empty) $(_empty)
+
+# member-check VARIABLE,VALID-VALUES
+# ----------------------------------
+# Check that $(VARIABLE) is in the space-separated list of VALID-VALUES, and
+# return it.  Die otherwise.
+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))
+
 # Do not save the original name or timestamp in the .tar.gz file.
 # Use --rsyncable if available.
 gzip_rsyncable := \
@@ -91,13 +107,17 @@ my_distdir = $(PACKAGE)-$(VERSION)
 # Old releases are stored here.
 release_archive_dir ?= ../release
 
+# Validate and return $(RELEASE_TYPE), or die.
+RELEASE_TYPES = alpha beta stable
+release-type = $(call member-check,RELEASE_TYPE,$(RELEASE_TYPES))
+
 # Override gnu_rel_host and url_dir_list in cfg.mk if these are not right.
 # Use alpha.gnu.org for alpha and beta releases.
 # Use ftp.gnu.org for stable releases.
 gnu_ftp_host-alpha = alpha.gnu.org
 gnu_ftp_host-beta = alpha.gnu.org
 gnu_ftp_host-stable = ftp.gnu.org
-gnu_rel_host ?= $(gnu_ftp_host-$(RELEASE_TYPE))
+gnu_rel_host ?= $(gnu_ftp_host-$(release-type))
 
 ifeq ($(gnu_rel_host),ftp.gnu.org)
 url_dir_list ?= http://ftpmirror.gnu.org/$(PACKAGE)
@@ -570,8 +590,6 @@ sc_prohibit_c_ctype_without_use:
        @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
          $(_sc_header_without_use)
 
-_empty =
-_sp = $(_empty) $(_empty)
 # The following list was generated by running:
 # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
 #   | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
@@ -1266,7 +1284,7 @@ gpg_key_ID ?=                                                             \
 translation_project_ ?= coordinator@translationproject.org
 
 # Make info-gnu the default only for a stable release.
-ifeq ($(RELEASE_TYPE),stable)
+ifeq ($(release-type),stable)
   announcement_Cc_ ?= $(translation_project_), $(PACKAGE_BUGREPORT)
   announcement_mail_headers_ ?=                                                \
     To: info-gnu@gnu.org                                               \
@@ -1284,7 +1302,7 @@ announcement: NEWS ChangeLog $(rel-files)
 # annoucement message: it would start with " GEN announcement".
        $(AM_V_at)$(srcdir)/$(_build-aux)/announce-gen                  \
            --mail-headers='$(announcement_mail_headers_)'              \
-           --release-type=$(RELEASE_TYPE)                              \
+           --release-type=$(release-type)                              \
            --package=$(PACKAGE)                                        \
            --prev=$(PREV_VERSION)                                      \
            --curr=$(VERSION)                                           \
@@ -1386,9 +1404,7 @@ release-prep-hook ?= release-prep
 gl_noteworthy_news_ = * Noteworthy changes in release ?.? (????-??-??) [?]
 .PHONY: release-prep
 release-prep:
-       $(AM_V_GEN)case $$RELEASE_TYPE in alpha|beta|stable) ;; \
-         *) echo "invalid RELEASE_TYPE: $$RELEASE_TYPE" 1>&2; exit 1;; esac
-       $(AM_V_at)$(MAKE) --no-print-directory -s announcement \
+       $(AM_V_GEN)$(MAKE) --no-print-directory -s announcement \
          > ~/announce-$(my_distdir)
        $(AM_V_at)if test -d $(release_archive_dir); then       \
          ln $(rel-files) $(release_archive_dir);               \