autoupdate
[gnulib.git] / top / maint.mk
index fc72d11..ed9c1aa 100644 (file)
@@ -1,6 +1,6 @@
 # -*-Makefile-*-
 # This Makefile fragment tries to be general-purpose enough to be
-# used by at least coreutils, idutils, CPPI, Bison, and Autoconf.
+# used by many projects via the gnulib maintainer-makefile module.
 
 ## Copyright (C) 2001-2009 Free Software Foundation, Inc.
 ##
 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
 ME := maint.mk
 
+# Override this in cfg.mk if you use a non-standard build-aux directory.
+build_aux ?= $(srcdir)/build-aux
+
 # Do not save the original name or timestamp in the .tar.gz file.
 # Use --rsyncable if available.
 gzip_rsyncable := \
   $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
 
+# cfg.mk must define the gpg_key_ID used by this package.
 GIT = git
 VC = $(GIT)
-VC-tag = git tag -s -m '$(VERSION)'
+VC-tag = git tag -s -m '$(VERSION)' -u '$(gpg_key_ID)'
 
-VC_LIST = $(srcdir)/build-aux/vc-list-files
+VC_LIST = $(build_aux)/vc-list-files -C $(srcdir)
 
 VC_LIST_EXCEPT = \
-  $(VC_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
+  $(VC_LIST) | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; else grep -v ChangeLog; fi
 
 ifeq ($(origin prev_version_file), undefined)
   prev_version_file = $(srcdir)/.prev-version
@@ -68,7 +72,7 @@ export LC_ALL = C
 
 # Collect the names of rules starting with `sc_'.
 syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
-                        $(srcdir)/$(ME) $(srcdir)/cfg.mk)
+                       $(srcdir)/$(ME) $(srcdir)/cfg.mk)
 .PHONY: $(syntax-check-rules)
 
 local-checks-available = \
@@ -110,9 +114,9 @@ define _prohibit_regexp
 endef
 
 sc_avoid_if_before_free:
-       @$(srcdir)/build-aux/useless-if-before-free                     \
+       @$(build_aux)/useless-if-before-free                            \
                $(useless_free_options)                                 \
-           $$($(VC_LIST_EXCEPT)) &&                                    \
+           $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) &&   \
          { echo '$(ME): found useless "if" before "free" above' 1>&2;  \
            exit 1; } || :
 
@@ -190,10 +194,13 @@ sc_prohibit_have_config_h:
          { echo '$(ME): found use of HAVE''_CONFIG_H; remove'          \
                1>&2; exit 1; } || :
 
-# Nearly all .c files must include <config.h>.
+# Nearly all .c files must include <config.h>.  However, we also permit this
+# via inclusion of a package-specific header, if cfg.mk specified one.
+# config_h_header must be suitable for grep -E.
+config_h_header ?= <config\.h>
 sc_require_config_h:
-       @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then               \
-         grep -L '^# *include <config\.h>'                             \
+       @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then       \
+         grep -EL '^# *include $(config_h_header)'                     \
                $$($(VC_LIST_EXCEPT) | grep '\.c$$')                    \
              | grep . &&                                               \
          { echo '$(ME): the above files do not include <config.h>'     \
@@ -202,12 +209,13 @@ sc_require_config_h:
        fi
 
 # You must include <config.h> before including any other header file.
+# This can possibly be via a package-specific header, if given by cfg.mk.
 sc_require_config_h_first:
        @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then       \
          fail=0;                                                       \
          for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do             \
            grep '^# *include\>' $$i | sed 1q                           \
-               | grep '^# *include <config\.h>' > /dev/null            \
+               | grep -E '^# *include $(config_h_header)' > /dev/null  \
              || { echo $$i; fail=1; };                                 \
          done;                                                         \
          test $$fail = 1 &&                                            \
@@ -495,7 +503,7 @@ sc_makefile_check:
 
 news-date-check: NEWS
        today=`date +%Y-%m-%d`;                                         \
-       if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')'       \
+       if head $(srcdir)/NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
            >/dev/null; then                                            \
          :;                                                            \
        else                                                            \
@@ -593,7 +601,7 @@ sc_copyright_check:
        fi
 
 vc-diff-check:
-       $(VC) diff > vc-diffs || :
+       (unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || :
        if test -s vc-diffs; then                               \
          cat vc-diffs;                                         \
          echo "Some files are locally modified:" 1>&2;         \
@@ -630,17 +638,19 @@ built_programs = $$(cd src && MAKEFLAGS= $(MAKE) -s built_programs.list)
 
 rel-files = $(DIST_ARCHIVES)
 
+gnulib_dir ?= $(srcdir)/gnulib
 gnulib-version = $$(cd $(gnulib_dir) && git describe)
+bootstrap-tools ?= autoconf,automake,gnulib
 
 announcement: NEWS ChangeLog $(rel-files)
-       @./build-aux/announce-gen                                       \
+       @$(build_aux)/announce-gen                                      \
            --release-type=$(RELEASE_TYPE)                              \
            --package=$(PACKAGE)                                        \
            --prev=$(PREV_VERSION)                                      \
            --curr=$(VERSION)                                           \
            --gpg-key-id=$(gpg_key_ID)                                  \
            --news=NEWS                                                 \
-           --bootstrap-tools=autoconf,automake,bison,gnulib            \
+           --bootstrap-tools=$(bootstrap-tools)                        \
            --gnulib-version=$(gnulib-version)                          \
            --no-print-checksums                                        \
            $(addprefix --url-dir=, $(url_dir_list))
@@ -652,13 +662,10 @@ announcement: NEWS ChangeLog $(rel-files)
 ftp-gnu = ftp://ftp.gnu.org/gnu
 www-gnu = http://www.gnu.org
 
-# Use mv, if you don't have/want move-if-change.
-move_if_change ?= move-if-change
-
 emit_upload_commands:
        @echo =====================================
        @echo =====================================
-       @echo "$(srcdir)/build-aux/gnupload $(GNUPLOADFLAGS) \\"
+       @echo "$(build_aux)/gnupload $(GNUPLOADFLAGS) \\"
        @echo "    --to $(gnu_rel_host):$(PACKAGE) \\"
        @echo "  $(rel-files)"
        @echo '# send the /tmp/announcement e-mail'
@@ -673,9 +680,22 @@ define emit-commit-log
     '* cfg.mk (old_NEWS_hash): Auto-update.'
 endef
 
+.PHONY: no-submodule-changes
+no-submodule-changes:
+       if test -d $(srcdir)/.git; then                                 \
+         diff=$$(cd $(srcdir) && git submodule -q foreach              \
+                 git diff-index --name-only HEAD)                      \
+           || exit 1;                                                  \
+         case $$diff in '') ;;                                         \
+           *) echo '$(ME): submodule files are locally modified:';     \
+               echo "$$diff"; exit 1;; esac;                           \
+       else                                                            \
+         : ;                                                           \
+       fi
+
 .PHONY: alpha beta major
 ALL_RECURSIVE_TARGETS += alpha beta major
-alpha beta major: $(local-check) writable-files
+alpha beta major: $(local-check) writable-files no-submodule-changes
        test $@ = major                                         \
          && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
               || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\