Blame maint.mk

Packit aea12f
# -*-Makefile-*-
Packit aea12f
# This Makefile fragment tries to be general-purpose enough to be
Packit aea12f
# used by many projects via the gnulib maintainer-makefile module.
Packit aea12f
Packit Service 991b93
## Copyright (C) 2001-2020 Free Software Foundation, Inc.
Packit aea12f
##
Packit aea12f
## This program is free software: you can redistribute it and/or modify
Packit aea12f
## it under the terms of the GNU General Public License as published by
Packit aea12f
## the Free Software Foundation, either version 3 of the License, or
Packit aea12f
## (at your option) any later version.
Packit aea12f
##
Packit aea12f
## This program is distributed in the hope that it will be useful,
Packit aea12f
## but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
## GNU General Public License for more details.
Packit aea12f
##
Packit aea12f
## You should have received a copy of the GNU General Public License
Packit aea12f
## along with this program.  If not, see <https://www.gnu.org/licenses/>.
Packit aea12f
Packit aea12f
# This is reported not to work with make-3.79.1
Packit aea12f
# ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
Packit aea12f
ME := maint.mk
Packit aea12f
Packit aea12f
# These variables ought to be defined through the configure.ac section
Packit aea12f
# of the module description. But some packages import this file directly,
Packit aea12f
# ignoring the module description.
Packit Service 991b93
AWK ?= awk
Packit aea12f
GREP ?= grep
Packit aea12f
SED ?= sed
Packit aea12f
Packit aea12f
# Helper variables.
Packit aea12f
_empty =
Packit aea12f
_sp = $(_empty) $(_empty)
Packit aea12f
Packit aea12f
# _equal,S1,S2
Packit aea12f
# ------------
Packit aea12f
# If S1 == S2, return S1, otherwise the empty string.
Packit aea12f
_equal = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
Packit aea12f
Packit aea12f
# member-check,VARIABLE,VALID-VALUES
Packit aea12f
# ----------------------------------
Packit aea12f
# Check that $(VARIABLE) is in the space-separated list of VALID-VALUES, and
Packit aea12f
# return it.  Die otherwise.
Packit aea12f
member-check =								\
Packit aea12f
  $(strip								\
Packit aea12f
    $(if $($(1)),							\
Packit aea12f
      $(if $(findstring $(_sp),$($(1))),				\
Packit aea12f
          $(error invalid $(1): '$($(1))', expected $(2)),		\
Packit aea12f
          $(or $(findstring $(_sp)$($(1))$(_sp),$(_sp)$(2)$(_sp)),	\
Packit aea12f
            $(error invalid $(1): '$($(1))', expected $(2)))),		\
Packit aea12f
      $(error $(1) undefined)))
Packit aea12f
Packit aea12f
# Do not save the original name or timestamp in the .tar.gz file.
Packit aea12f
# Use --rsyncable if available.
Packit aea12f
gzip_rsyncable := \
Packit aea12f
  $(shell gzip --help 2>/dev/null|$(GREP) rsyncable >/dev/null \
Packit aea12f
    && printf %s --rsyncable)
Packit aea12f
GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
Packit aea12f
Packit aea12f
GIT = git
Packit aea12f
VC = $(GIT)
Packit aea12f
Packit aea12f
VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
Packit aea12f
Packit aea12f
# You can override this variable in cfg.mk if your gnulib submodule lives
Packit aea12f
# in a different location.
Packit aea12f
gnulib_dir ?= $(srcdir)/gnulib
Packit aea12f
Packit aea12f
# You can override this variable in cfg.mk to set your own regexp
Packit aea12f
# matching files to ignore.
Packit aea12f
VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
Packit aea12f
Packit aea12f
# This is to preprocess robustly the output of $(VC_LIST), so that even
Packit aea12f
# when $(srcdir) is a pathological name like "....", the leading sed command
Packit aea12f
# removes only the intended prefix.
Packit aea12f
_dot_escaped_srcdir = $(subst .,\.,$(srcdir))
Packit aea12f
Packit aea12f
# Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
Packit aea12f
# when $(srcdir) is not ".".
Packit aea12f
ifeq ($(srcdir),.)
Packit aea12f
  _prepend_srcdir_prefix =
Packit aea12f
else
Packit aea12f
  _prepend_srcdir_prefix = | $(SED) 's|^|$(srcdir)/|'
Packit aea12f
endif
Packit aea12f
Packit aea12f
# In order to be able to consistently filter "."-relative names,
Packit aea12f
# (i.e., with no $(srcdir) prefix), this definition is careful to
Packit aea12f
# remove any $(srcdir) prefix, and to restore what it removes.
Packit aea12f
_sc_excl = \
Packit aea12f
  $(or $(exclude_file_name_regexp--$@),^$$)
Packit aea12f
VC_LIST_EXCEPT = \
Packit aea12f
  $(VC_LIST) | $(SED) 's|^$(_dot_escaped_srcdir)/||' \
Packit aea12f
	| if test -f $(srcdir)/.x-$@; then $(GREP) -vEf $(srcdir)/.x-$@; \
Packit aea12f
	  else $(GREP) -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
Packit aea12f
	| $(GREP) -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
Packit aea12f
	$(_prepend_srcdir_prefix)
Packit aea12f
Packit aea12f
ifeq ($(origin prev_version_file), undefined)
Packit aea12f
  prev_version_file = $(srcdir)/.prev-version
Packit aea12f
endif
Packit aea12f
Packit aea12f
PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null)
Packit aea12f
VERSION_REGEXP = $(subst .,\.,$(VERSION))
Packit aea12f
PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION))
Packit aea12f
Packit aea12f
ifeq ($(VC),$(GIT))
Packit aea12f
  this-vc-tag = v$(VERSION)
Packit aea12f
  this-vc-tag-regexp = v$(VERSION_REGEXP)
Packit aea12f
else
Packit aea12f
  tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
Packit aea12f
  tag-this-version = $(subst .,_,$(VERSION))
Packit aea12f
  this-vc-tag = $(tag-package)-$(tag-this-version)
Packit aea12f
  this-vc-tag-regexp = $(this-vc-tag)
Packit aea12f
endif
Packit aea12f
my_distdir = $(PACKAGE)-$(VERSION)
Packit aea12f
Packit aea12f
# Old releases are stored here.
Packit aea12f
release_archive_dir ?= ../release
Packit aea12f
Packit aea12f
# If RELEASE_TYPE is undefined, but RELEASE is, use its second word.
Packit aea12f
# But overwrite VERSION.
Packit aea12f
ifdef RELEASE
Packit aea12f
  VERSION := $(word 1, $(RELEASE))
Packit aea12f
  RELEASE_TYPE ?= $(word 2, $(RELEASE))
Packit aea12f
endif
Packit aea12f
Packit aea12f
# Validate and return $(RELEASE_TYPE), or die.
Packit aea12f
RELEASE_TYPES = alpha beta stable
Packit aea12f
release-type = $(call member-check,RELEASE_TYPE,$(RELEASE_TYPES))
Packit aea12f
Packit aea12f
# Override gnu_rel_host and url_dir_list in cfg.mk if these are not right.
Packit aea12f
# Use alpha.gnu.org for alpha and beta releases.
Packit aea12f
# Use ftp.gnu.org for stable releases.
Packit aea12f
gnu_ftp_host-alpha = alpha.gnu.org
Packit aea12f
gnu_ftp_host-beta = alpha.gnu.org
Packit aea12f
gnu_ftp_host-stable = ftp.gnu.org
Packit aea12f
gnu_rel_host ?= $(gnu_ftp_host-$(release-type))
Packit aea12f
Packit aea12f
url_dir_list ?= $(if $(call _equal,$(gnu_rel_host),ftp.gnu.org),	\
Packit aea12f
                     https://ftpmirror.gnu.org/$(PACKAGE),		\
Packit aea12f
                     https://$(gnu_rel_host)/gnu/$(PACKAGE))
Packit aea12f
Packit aea12f
# Override this in cfg.mk if you are using a different format in your
Packit aea12f
# NEWS file.
Packit aea12f
today = $(shell date +%Y-%m-%d)
Packit aea12f
Packit aea12f
# Select which lines of NEWS are searched for $(news-check-regexp).
Packit aea12f
# This is a sed line number spec.  The default says that we search
Packit aea12f
# lines 1..10 of NEWS for $(news-check-regexp).
Packit aea12f
# If you want to search only line 3 or only lines 20-22, use "3" or "20,22".
Packit aea12f
news-check-lines-spec ?= 1,10
Packit aea12f
news-check-regexp ?= '^\*.* $(VERSION_REGEXP) \($(today)\)'
Packit aea12f
Packit aea12f
# Prevent programs like 'sort' from considering distinct strings to be equal.
Packit aea12f
# Doing it here saves us from having to set LC_ALL elsewhere in this file.
Packit aea12f
export LC_ALL = C
Packit aea12f
Packit aea12f
## --------------- ##
Packit aea12f
## Sanity checks.  ##
Packit aea12f
## --------------- ##
Packit aea12f
Packit aea12f
ifneq ($(_gl-Makefile),)
Packit aea12f
_cfg_mk := $(wildcard $(srcdir)/cfg.mk)
Packit aea12f
Packit aea12f
# Collect the names of rules starting with 'sc_'.
Packit aea12f
syntax-check-rules := $(sort $(shell $(SED) -n \
Packit aea12f
   's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(srcdir)/$(ME) $(_cfg_mk)))
Packit aea12f
.PHONY: $(syntax-check-rules)
Packit aea12f
Packit aea12f
ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
Packit aea12f
  local-checks-available += $(syntax-check-rules)
Packit aea12f
else
Packit aea12f
  local-checks-available += no-vc-detected
Packit aea12f
no-vc-detected:
Packit aea12f
	@echo "No version control files detected; skipping syntax check"
Packit aea12f
endif
Packit aea12f
.PHONY: $(local-checks-available)
Packit aea12f
Packit aea12f
# Arrange to print the name of each syntax-checking rule just before running it.
Packit aea12f
$(syntax-check-rules): %: %.m
Packit aea12f
sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules))
Packit aea12f
.PHONY: $(sc_m_rules_)
Packit aea12f
$(sc_m_rules_):
Packit aea12f
	@echo $(patsubst sc_%.m, %, $@)
Packit aea12f
	@date +%s.%N > .sc-start-$(basename $@)
Packit aea12f
Packit aea12f
# Compute and print the elapsed time for each syntax-check rule.
Packit aea12f
sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules))
Packit aea12f
.PHONY: $(sc_z_rules_)
Packit aea12f
$(sc_z_rules_): %.z: %
Packit aea12f
	@end=$$(date +%s.%N);						\
Packit aea12f
	start=$$(cat .sc-start-$*);					\
Packit aea12f
	rm -f .sc-start-$*;						\
Packit Service 991b93
	$(AWK) -v s=$$start -v e=$$end					\
Packit aea12f
	  'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null
Packit aea12f
Packit aea12f
# The patsubst here is to replace each sc_% rule with its sc_%.z wrapper
Packit aea12f
# that computes and prints elapsed time.
Packit aea12f
local-check :=								\
Packit aea12f
  $(patsubst sc_%, sc_%.z,						\
Packit aea12f
    $(filter-out $(local-checks-to-skip), $(local-checks-available)))
Packit aea12f
Packit aea12f
syntax-check: $(local-check)
Packit aea12f
endif
Packit aea12f
Packit aea12f
# _sc_search_regexp
Packit aea12f
#
Packit aea12f
# This macro searches for a given construct in the selected files and
Packit aea12f
# then takes some action.
Packit aea12f
#
Packit aea12f
# Parameters (shell variables):
Packit aea12f
#
Packit aea12f
#  prohibit | require
Packit aea12f
#
Packit aea12f
#     Regular expression (ERE) denoting either a forbidden construct
Packit aea12f
#     or a required construct.  Those arguments are exclusive.
Packit aea12f
#
Packit aea12f
#  exclude
Packit aea12f
#
Packit aea12f
#     Regular expression (ERE) denoting lines to ignore that matched
Packit aea12f
#     a prohibit construct.  For example, this can be used to exclude
Packit aea12f
#     comments that mention why the nearby code uses an alternative
Packit aea12f
#     construct instead of the simpler prohibited construct.
Packit aea12f
#
Packit aea12f
#  in_vc_files | in_files
Packit aea12f
#
Packit aea12f
#     grep-E-style regexp selecting the files to check.  For in_vc_files,
Packit aea12f
#     the regexp is used to select matching files from the list of all
Packit aea12f
#     version-controlled files; for in_files, it's from the names printed
Packit aea12f
#     by "find $(srcdir)".  When neither is specified, use all files that
Packit aea12f
#     are under version control.
Packit aea12f
#
Packit aea12f
#  containing | non_containing
Packit aea12f
#
Packit aea12f
#     Select the files (non) containing strings matching this regexp.
Packit aea12f
#     If both arguments are specified then CONTAINING takes
Packit aea12f
#     precedence.
Packit aea12f
#
Packit aea12f
#  with_grep_options
Packit aea12f
#
Packit aea12f
#     Extra options for grep.
Packit aea12f
#
Packit aea12f
#  ignore_case
Packit aea12f
#
Packit aea12f
#     Ignore case.
Packit aea12f
#
Packit aea12f
#  halt
Packit aea12f
#
Packit aea12f
#     Message to display before to halting execution.
Packit aea12f
#
Packit aea12f
# Finally, you may exempt files based on an ERE matching file names.
Packit aea12f
# For example, to exempt from the sc_space_tab check all files with the
Packit aea12f
# .diff suffix, set this Make variable:
Packit aea12f
#
Packit aea12f
# exclude_file_name_regexp--sc_space_tab = \.diff$
Packit aea12f
#
Packit aea12f
# Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
Packit aea12f
# when filtering by name via in_files, we explicitly filter out matching
Packit aea12f
# names here as well.
Packit aea12f
Packit aea12f
# Initialize each, so that envvar settings cannot interfere.
Packit aea12f
export require =
Packit aea12f
export prohibit =
Packit aea12f
export exclude =
Packit aea12f
export in_vc_files =
Packit aea12f
export in_files =
Packit aea12f
export containing =
Packit aea12f
export non_containing =
Packit aea12f
export halt =
Packit aea12f
export with_grep_options =
Packit aea12f
Packit aea12f
# By default, _sc_search_regexp does not ignore case.
Packit aea12f
export ignore_case =
Packit aea12f
_ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :)
Packit aea12f
Packit aea12f
define _sc_say_and_exit
Packit aea12f
   dummy=; : so we do not need a semicolon before each use;		\
Packit aea12f
   { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; };
Packit aea12f
endef
Packit aea12f
Packit aea12f
define _sc_search_regexp
Packit aea12f
   dummy=; : so we do not need a semicolon before each use;		\
Packit aea12f
									\
Packit aea12f
   : Check arguments;							\
Packit aea12f
   test -n "$$prohibit" && test -n "$$require"				\
Packit aea12f
     && { msg='Cannot specify both prohibit and require'		\
Packit aea12f
          $(_sc_say_and_exit) } || :;					\
Packit aea12f
   test -z "$$prohibit" && test -z "$$require"				\
Packit aea12f
     && { msg='Should specify either prohibit or require'		\
Packit aea12f
          $(_sc_say_and_exit) } || :;					\
Packit aea12f
   test -z "$$prohibit" && test -n "$$exclude"				\
Packit aea12f
     && { msg='Use of exclude requires a prohibit pattern'		\
Packit aea12f
          $(_sc_say_and_exit) } || :;					\
Packit aea12f
   test -n "$$in_vc_files" && test -n "$$in_files"			\
Packit aea12f
     && { msg='Cannot specify both in_vc_files and in_files'		\
Packit aea12f
          $(_sc_say_and_exit) } || :;					\
Packit aea12f
   test "x$$halt" != x							\
Packit aea12f
     || { msg='halt not defined' $(_sc_say_and_exit) };			\
Packit aea12f
									\
Packit aea12f
   : Filter by file name;						\
Packit aea12f
   if test -n "$$in_files"; then					\
Packit aea12f
     files=$$(find $(srcdir) | $(GREP) -E "$$in_files"			\
Packit aea12f
              | $(GREP) -Ev '$(_sc_excl)');				\
Packit aea12f
   else									\
Packit aea12f
     files=$$($(VC_LIST_EXCEPT));					\
Packit aea12f
     if test -n "$$in_vc_files"; then					\
Packit aea12f
       files=$$(echo "$$files" | $(GREP) -E "$$in_vc_files");		\
Packit aea12f
     fi;								\
Packit aea12f
   fi;									\
Packit aea12f
									\
Packit aea12f
   : Filter by content;							\
Packit aea12f
   test -n "$$files"							\
Packit aea12f
     && test -n "$$containing"						\
Packit aea12f
     && { files=$$(echo "$$files" | xargs $(GREP) -l "$$containing"); }	\
Packit aea12f
     || :;								\
Packit aea12f
   test -n "$$files"							\
Packit aea12f
     && test -n "$$non_containing"					\
Packit aea12f
     && { files=$$(echo "$$files" | xargs $(GREP) -vl "$$non_containing"); } \
Packit aea12f
     || :;								\
Packit aea12f
									\
Packit aea12f
   : Check for the construct;						\
Packit aea12f
   if test -n "$$files"; then						\
Packit aea12f
     if test -n "$$prohibit"; then					\
Packit aea12f
       echo "$$files"							\
Packit aea12f
         | xargs $(GREP) $$with_grep_options $(_ignore_case) -nE	\
Packit aea12f
		"$$prohibit" /dev/null					\
Packit aea12f
         | $(GREP) -vE "$${exclude:-^$$}"				\
Packit aea12f
         && { msg="$$halt" $(_sc_say_and_exit) }			\
Packit aea12f
         || :;								\
Packit aea12f
     else								\
Packit aea12f
       echo "$$files"							\
Packit aea12f
         | xargs							\
Packit aea12f
             $(GREP) $$with_grep_options $(_ignore_case) -LE "$$require" \
Packit aea12f
         | $(GREP) .							\
Packit aea12f
         && { msg="$$halt" $(_sc_say_and_exit) }			\
Packit aea12f
         || :;								\
Packit aea12f
     fi									\
Packit aea12f
   else :;								\
Packit aea12f
   fi || :;
Packit aea12f
endef
Packit aea12f
Packit aea12f
sc_avoid_if_before_free:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | $(GREP) -v useless-if-before-free				\
Packit aea12f
	  | xargs							\
Packit aea12f
	      $(srcdir)/$(_build-aux)/useless-if-before-free		\
Packit aea12f
	      $(useless_free_options)					\
Packit aea12f
	  && { printf '$(ME): found useless "if"'			\
Packit aea12f
		      ' before "free" above\n' 1>&2;			\
Packit aea12f
	       exit 1; }						\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
sc_cast_of_argument_to_free:
Packit aea12f
	@prohibit='\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_cast_of_x_alloc_return_value:
Packit aea12f
	@prohibit='\*\) *x(m|c|re)alloc\>'				\
Packit aea12f
	halt="don't cast x*alloc return value"				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_cast_of_alloca_return_value:
Packit aea12f
	@prohibit='\*\) *alloca\>'					\
Packit aea12f
	halt="don't cast alloca return value"				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_space_tab:
Packit aea12f
	@prohibit='[ ]	'						\
Packit aea12f
	halt='found SPACE-TAB sequence; remove the SPACE'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Don't use *scanf or the old ato* functions in "real" code.
Packit aea12f
# They provide no error checking mechanism.
Packit aea12f
# Instead, use strto* functions.
Packit aea12f
sc_prohibit_atoi_atof:
Packit aea12f
	@prohibit='\<([fs]?scanf|ato([filq]|ll)) *\('				\
Packit aea12f
	halt='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q'	\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Use STREQ rather than comparing strcmp == 0, or != 0.
Packit aea12f
sp_ = strcmp *\(.+\)
Packit aea12f
sc_prohibit_strcmp:
Packit aea12f
	@prohibit='! *strcmp *\(|\<$(sp_) *[!=]=|[!=]= *$(sp_)'		\
Packit aea12f
	exclude='# *define STRN?EQ\('					\
Packit aea12f
	halt='replace strcmp calls above with STREQ/STRNEQ'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Really.  You don't want to use this function.
Packit aea12f
# It may fail to NUL-terminate the destination,
Packit aea12f
# and always NUL-pads out to the specified length.
Packit aea12f
sc_prohibit_strncpy:
Packit aea12f
	@prohibit='\
Packit aea12f
	halt='do not use strncpy, period'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Pass EXIT_*, not number, to usage, exit, and error (when exiting)
Packit aea12f
# Convert all uses automatically, via these two commands:
Packit aea12f
# git grep -l '\
Packit aea12f
#  | grep -vEf .x-sc_prohibit_magic_number_exit \
Packit aea12f
#  | xargs --no-run-if-empty \
Packit aea12f
#      perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/'
Packit aea12f
# git grep -l '\
Packit aea12f
#  | grep -vEf .x-sc_prohibit_magic_number_exit \
Packit aea12f
#  | xargs --no-run-if-empty \
Packit aea12f
#      perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/'
Packit aea12f
sc_prohibit_magic_number_exit:
Packit aea12f
	@prohibit='(^|[^.])\<(usage|exit|error) ?\(-?[0-9]+[,)]'	\
Packit aea12f
	exclude='exit \(77\)|error ?\(((0|77),|[^,]*)'			\
Packit aea12f
	halt='use EXIT_* values rather than magic number'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit Service 991b93
# Check that we don't use $< in non-implicit Makefile rules.
Packit Service 991b93
#
Packit Service 991b93
# To find the Makefiles, trace AC_CONFIG_FILES.  Using VC_LIST would
Packit Service 991b93
# miss the Makefiles that are not under VC control (e.g., symlinks
Packit Service 991b93
# installed for gettext).  "Parsing" (recursive) uses of SUBDIRS seems
Packit Service 991b93
# too delicate.
Packit Service 991b93
#
Packit Service 991b93
# Use GNU Make's --print-data-base to normalize the rules into some
Packit Service 991b93
# easy to parse format: they are separated by two \n.  Look for the
Packit Service 991b93
# "section" about non-pattern rules (marked with "# Files") inside
Packit Service 991b93
# which there are still the POSIX Make like implicit rules (".c.o").
Packit Service 991b93
sc_prohibit_gnu_make_extensions_awk_ =					\
Packit Service 991b93
  BEGIN {								\
Packit Service 991b93
      RS = "\n\n";							\
Packit Service 991b93
      in_rules = 0;							\
Packit Service 991b93
  }									\
Packit Service 991b93
  /^\# Files/ {								\
Packit Service 991b93
      in_rules = 1;							\
Packit Service 991b93
  }									\
Packit Service 991b93
  /\$$</ && in_rules && $$0 !~ /^(.*\n)*\.\w+(\.\w+)?:/ {		\
Packit Service 991b93
      print "Error: " file ": $$< in a non implicit rule\n" $$0;	\
Packit Service 991b93
      status = 1;							\
Packit Service 991b93
  }									\
Packit Service 991b93
  END {									\
Packit Service 991b93
     exit status;							\
Packit Service 991b93
  }
Packit Service 991b93
sc_prohibit_gnu_make_extensions:
Packit Service 991b93
	@if $(AWK) --version | grep GNU >/dev/null 2>&1; then		\
Packit Service 991b93
	  (cd $(srcdir) && autoconf --trace AC_CONFIG_FILES:'$$1') |	\
Packit Service 991b93
	    tr ' ' '\n' |						\
Packit Service 991b93
	    $(SED) -ne '/Makefile/{s/\.in$$//;p;}' |			\
Packit Service 991b93
	    while read m; do						\
Packit Service 991b93
	      $(MAKE) -qp -f $$m .DUMMY-TARGET 2>/dev/null |		\
Packit Service 991b93
	        $(AWK) -v file=$$m -e '$($@_awk_)' || exit 1;		\
Packit Service 991b93
	    done;							\
Packit Service 991b93
	fi
Packit Service 991b93
Packit aea12f
# Using EXIT_SUCCESS as the first argument to error is misleading,
Packit aea12f
# since when that parameter is 0, error does not exit.  Use '0' instead.
Packit aea12f
sc_error_exit_success:
Packit aea12f
	@prohibit='error *\(EXIT_SUCCESS,'				\
Packit aea12f
	in_vc_files='\.[chly]$$'					\
Packit aea12f
	halt='found error (EXIT_SUCCESS'				\
Packit aea12f
	 $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# "FATAL:" should be fully upper-cased in error messages
Packit aea12f
# "WARNING:" should be fully upper-cased, or fully lower-cased
Packit aea12f
sc_error_message_warn_fatal:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
Packit aea12f
	  | $(GREP) -E '"Warning|"Fatal|"fatal'				\
Packit aea12f
	  && { echo '$(ME): use FATAL, WARNING or warning' 1>&2;	\
Packit aea12f
	       exit 1; }						\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
# Error messages should not start with a capital letter
Packit aea12f
sc_error_message_uppercase:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
Packit aea12f
	  | $(GREP) -E '"[A-Z]'						\
Packit aea12f
	  | $(GREP) -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX'		\
Packit aea12f
	  && { echo '$(ME): found capitalized error message' 1>&2;	\
Packit aea12f
	       exit 1; }						\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
# Error messages should not end with a period
Packit aea12f
sc_error_message_period:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null		\
Packit aea12f
	  | $(GREP) -E '[^."]\."'					\
Packit aea12f
	  && { echo '$(ME): found error message ending in period' 1>&2;	\
Packit aea12f
	       exit 1; }						\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
sc_file_system:
Packit aea12f
	@prohibit=file''system						\
Packit aea12f
	exclude='/proc/filesystems'					\
Packit aea12f
	ignore_case=1							\
Packit aea12f
	halt='found use of "file''system"; spell it "file system"'	\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Don't use cpp tests of this symbol.  All code assumes config.h is included.
Packit aea12f
sc_prohibit_have_config_h:
Packit aea12f
	@prohibit='^# *if.*HAVE''_CONFIG_H'				\
Packit aea12f
	halt='found use of HAVE''_CONFIG_H; remove'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Nearly all .c files must include <config.h>.  However, we also permit this
Packit aea12f
# via inclusion of a package-specific header, if cfg.mk specified one.
Packit aea12f
# config_h_header must be suitable for grep -E.
Packit aea12f
config_h_header ?= <config\.h>
Packit aea12f
sc_require_config_h:
Packit aea12f
	@require='^# *include $(config_h_header)'			\
Packit aea12f
	in_vc_files='\.c$$'						\
Packit aea12f
	halt='the above files do not include <config.h>'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Print each file name for which the first #include does not match
Packit aea12f
# $(config_h_header).  Like grep -m 1, this only looks at the first match.
Packit aea12f
perl_config_h_first_ =							\
Packit aea12f
  -e 'BEGIN {$$ret = 0}'						\
Packit aea12f
  -e 'if (/^\# *include\b/) {'						\
Packit aea12f
  -e '  if (not m{^\# *include $(config_h_header)}) {'			\
Packit aea12f
  -e '    print "$$ARGV\n";'						\
Packit aea12f
  -e '    $$ret = 1;'							\
Packit aea12f
  -e '  }'								\
Packit aea12f
  -e '  \# Move on to next file after first include'			\
Packit aea12f
  -e '  close ARGV;'							\
Packit aea12f
  -e '}'								\
Packit aea12f
  -e 'END {exit $$ret}'
Packit aea12f
Packit aea12f
# You must include <config.h> before including any other header file.
Packit aea12f
# This can possibly be via a package-specific header, if given by cfg.mk.
Packit aea12f
sc_require_config_h_first:
Packit aea12f
	@if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then	\
Packit aea12f
	  files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') &&		\
Packit aea12f
	  perl -n $(perl_config_h_first_) $$files ||			\
Packit aea12f
	    { echo '$(ME): the above files include some other header'	\
Packit aea12f
		'before <config.h>' 1>&2; exit 1; } || :;		\
Packit aea12f
	else :;								\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
sc_prohibit_HAVE_MBRTOWC:
Packit aea12f
	@prohibit='\bHAVE_MBRTOWC\b'					\
Packit aea12f
	halt="do not use $$prohibit; it is always defined"		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# To use this "command" macro, you must first define two shell variables:
Packit aea12f
# h: the header name, with no enclosing <> or ""
Packit aea12f
# re: a regular expression that matches IFF something provided by $h is used.
Packit aea12f
define _sc_header_without_use
Packit aea12f
  dummy=; : so we do not need a semicolon before each use;		\
Packit aea12f
  h_esc=`echo '[<"]'"$$h"'[">]'|$(SED) 's/\./\\\\./g'`;			\
Packit aea12f
  if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then		\
Packit aea12f
    files=$$($(GREP) -l '^# *include '"$$h_esc"				\
Packit aea12f
	     $$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$')) &&		\
Packit aea12f
    $(GREP) -LE "$$re" $$files | $(GREP) . &&				\
Packit aea12f
      { echo "$(ME): the above files include $$h but don't use it"	\
Packit aea12f
	1>&2; exit 1; } || :;						\
Packit aea12f
  else :;								\
Packit aea12f
  fi
Packit aea12f
endef
Packit aea12f
Packit aea12f
# Prohibit the inclusion of assert.h without an actual use of assert.
Packit aea12f
sc_prohibit_assert_without_use:
Packit aea12f
	@h='assert.h' re='\
Packit aea12f
Packit aea12f
# Prohibit the inclusion of close-stream.h without an actual use.
Packit aea12f
sc_prohibit_close_stream_without_use:
Packit aea12f
	@h='close-stream.h' re='\
Packit aea12f
Packit aea12f
# Prohibit the inclusion of getopt.h without an actual use.
Packit aea12f
sc_prohibit_getopt_without_use:
Packit aea12f
	@h='getopt.h' re='\
Packit aea12f
Packit aea12f
# Don't include quotearg.h unless you use one of its functions.
Packit aea12f
sc_prohibit_quotearg_without_use:
Packit aea12f
	@h='quotearg.h' re='\
Packit aea12f
Packit aea12f
# Don't include quote.h unless you use one of its functions.
Packit aea12f
sc_prohibit_quote_without_use:
Packit aea12f
	@h='quote.h' re='\<quote((_n)? *\(|_quoting_options\>)' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include this header unless you use one of its functions.
Packit aea12f
sc_prohibit_long_options_without_use:
Packit aea12f
	@h='long-options.h' re='\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include this header unless you use one of its functions.
Packit aea12f
sc_prohibit_inttostr_without_use:
Packit aea12f
	@h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include this header unless you use one of its functions.
Packit aea12f
sc_prohibit_ignore_value_without_use:
Packit aea12f
	@h='ignore-value.h' re='\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include this header unless you use one of its functions.
Packit aea12f
sc_prohibit_error_without_use:
Packit aea12f
	@h='error.h' \
Packit aea12f
	re='\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include xalloc.h unless you use one of its functions.
Packit aea12f
# Consider these symbols:
Packit aea12f
# perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
Packit aea12f
# perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h
Packit aea12f
# Divide into two sets on case, and filter each through this:
Packit aea12f
# | sort | perl -MRegexp::Assemble -le \
Packit aea12f
#  'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
Packit aea12f
# Note this was produced by the above:
Packit aea12f
# _xa1 = \
Packit aea12f
#x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup)
Packit aea12f
# But we can do better, in at least two ways:
Packit aea12f
# 1) take advantage of two "dup"-suffixed strings:
Packit aea12f
# x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup)
Packit aea12f
# 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable
Packit aea12f
# "char|[cmz]"
Packit aea12f
# x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
Packit aea12f
_xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
Packit aea12f
_xa2 = X([CZ]|N?M)ALLOC
Packit aea12f
sc_prohibit_xalloc_without_use:
Packit aea12f
	@h='xalloc.h' \
Packit aea12f
	re='\<($(_xa1)|$(_xa2)) *\('\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Extract function names:
Packit aea12f
# perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/hash.h
Packit aea12f
_hash_re = \
Packit aea12f
clear|delete|free|get_(first|next)|insert|lookup|print_statistics|reset_tuning
Packit aea12f
_hash_fn = \<($(_hash_re)) *\(
Packit aea12f
_hash_struct = (struct )?\<[Hh]ash_(table|tuning)\>
Packit aea12f
sc_prohibit_hash_without_use:
Packit aea12f
	@h='hash.h' \
Packit aea12f
	re='$(_hash_fn)|$(_hash_struct)'\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_cloexec_without_use:
Packit aea12f
	@h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_posixver_without_use:
Packit aea12f
	@h='posixver.h' re='\
Packit aea12f
Packit aea12f
sc_prohibit_same_without_use:
Packit aea12f
	@h='same.h' re='\
Packit aea12f
Packit aea12f
sc_prohibit_hash_pjw_without_use:
Packit aea12f
	@h='hash-pjw.h' \
Packit aea12f
	re='\<hash_pjw\>' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_safe_read_without_use:
Packit aea12f
	@h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_argmatch_without_use:
Packit aea12f
	@h='argmatch.h' \
Packit Service 991b93
	re='(\<(ARGMATCH_DEFINE_GROUP|ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_canonicalize_without_use:
Packit aea12f
	@h='canonicalize.h' \
Packit aea12f
	re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode|file_name)' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_root_dev_ino_without_use:
Packit aea12f
	@h='root-dev-ino.h' \
Packit aea12f
	re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
sc_prohibit_openat_without_use:
Packit aea12f
	@h='openat.h' \
Packit aea12f
	re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat|(FCHMOD|FCHOWN|STAT)AT_INLINE)\>' \
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Prohibit the inclusion of c-ctype.h without an actual use.
Packit aea12f
ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
Packit aea12f
|isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
Packit aea12f
sc_prohibit_c_ctype_without_use:
Packit aea12f
	@h='c-ctype.h' re='\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# The following list was generated by running:
Packit aea12f
# man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
Packit aea12f
#   | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
Packit aea12f
_sig_functions = \
Packit aea12f
  bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \
Packit aea12f
  sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \
Packit aea12f
  siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \
Packit aea12f
  sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo
Packit aea12f
_sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions)))
Packit aea12f
# The following were extracted from "man signal.h" manually.
Packit aea12f
_sig_types_and_consts =							\
Packit aea12f
  MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK		\
Packit aea12f
  SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL		\
Packit aea12f
  SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE	\
Packit aea12f
  SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t	\
Packit aea12f
  sigstack sigval stack_t ucontext_t
Packit aea12f
# generated via this:
Packit aea12f
# perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70
Packit aea12f
_sig_names =								\
Packit aea12f
  SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT	\
Packit aea12f
  SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL	\
Packit aea12f
  SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP	\
Packit aea12f
  SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR	\
Packit aea12f
  SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS	\
Packit aea12f
  SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1	\
Packit aea12f
  SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW	\
Packit aea12f
  SIGXCPU SIGXFSZ
Packit aea12f
_sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts)))
Packit aea12f
Packit aea12f
# Prohibit the inclusion of signal.h without an actual use.
Packit aea12f
sc_prohibit_signal_without_use:
Packit aea12f
	@h='signal.h'							\
Packit aea12f
	re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>'		\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include stdio--.h unless you use one of its functions.
Packit aea12f
sc_prohibit_stdio--_without_use:
Packit aea12f
	@h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\('		\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include stdio-safer.h unless you use one of its functions.
Packit aea12f
sc_prohibit_stdio-safer_without_use:
Packit aea12f
	@h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\('	\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Prohibit the inclusion of strings.h without a sensible use.
Packit aea12f
# Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
Packit aea12f
sc_prohibit_strings_without_use:
Packit aea12f
	@h='strings.h'							\
Packit aea12f
	re='\<(strn?casecmp|ffs(ll)?)\>'				\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Extract the raw list of symbol names with this:
Packit aea12f
gl_extract_define_simple = \
Packit aea12f
  /^\# *define ([A-Z]\w+)\(/ and print $$1
Packit aea12f
# Filter out duplicates and convert to a space-separated list:
Packit aea12f
_intprops_names = \
Packit aea12f
  $(shell f=$(gnulib_dir)/lib/intprops.h;				\
Packit aea12f
    perl -lne '$(gl_extract_define_simple)' $$f | sort -u | tr '\n' ' ')
Packit aea12f
# Remove trailing space and convert to a regular expression:
Packit aea12f
_intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
Packit aea12f
# Prohibit the inclusion of intprops.h without an actual use.
Packit aea12f
sc_prohibit_intprops_without_use:
Packit aea12f
	@h='intprops.h'							\
Packit aea12f
	re='\<($(_intprops_syms_re)) *\('				\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
_stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
Packit aea12f
# Prohibit the inclusion of stddef.h without an actual use.
Packit aea12f
sc_prohibit_stddef_without_use:
Packit aea12f
	@h='stddef.h'							\
Packit aea12f
	re='\<($(_stddef_syms_re))\>'					\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
_de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
Packit aea12f
_de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
Packit aea12f
_de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
Packit aea12f
_dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
Packit aea12f
# Prohibit the inclusion of dirent.h without an actual use.
Packit aea12f
sc_prohibit_dirent_without_use:
Packit aea12f
	@h='dirent.h'							\
Packit aea12f
	re='\<($(_dirent_syms_re))\>'					\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Prohibit the inclusion of verify.h without an actual use.
Packit aea12f
sc_prohibit_verify_without_use:
Packit aea12f
	@h='verify.h'							\
Packit aea12f
	re='\<(verify(true|expr)?|assume|static_assert) *\('		\
Packit aea12f
	  $(_sc_header_without_use)
Packit aea12f
Packit aea12f
# Don't include xfreopen.h unless you use one of its functions.
Packit aea12f
sc_prohibit_xfreopen_without_use:
Packit aea12f
	@h='xfreopen.h' re='\
Packit aea12f
Packit aea12f
sc_obsolete_symbols:
Packit aea12f
	@prohibit='\<(HAVE''_FCNTL_H|O''_NDELAY)\>'			\
Packit aea12f
	halt='do not use HAVE''_FCNTL_H or O'_NDELAY			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
Packit aea12f
Packit aea12f
# Each nonempty ChangeLog line must start with a year number, or a TAB.
Packit aea12f
sc_changelog:
Packit aea12f
	@prohibit='^[^12	]'					\
Packit aea12f
	in_vc_files='^ChangeLog$$'					\
Packit aea12f
	halt='found unexpected prefix in a ChangeLog'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Ensure that each .c file containing a "main" function also
Packit aea12f
# calls bindtextdomain.
Packit aea12f
sc_bindtextdomain:
Packit aea12f
	@require='bindtextdomain *\('					\
Packit aea12f
	in_vc_files='\.c$$'						\
Packit aea12f
	containing='\
Packit aea12f
	halt='the above files do not call bindtextdomain'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Require that the final line of each test-lib.sh-using test be this one:
Packit aea12f
# Exit $fail
Packit aea12f
# Note: this test requires GNU grep's --label= option.
Packit aea12f
Exit_witness_file ?= tests/test-lib.sh
Packit aea12f
Exit_base := $(notdir $(Exit_witness_file))
Packit aea12f
sc_require_test_exit_idiom:
Packit aea12f
	@if test -f $(srcdir)/$(Exit_witness_file); then		\
Packit aea12f
	  die=0;							\
Packit aea12f
	  for i in $$($(GREP) -l -F 'srcdir/$(Exit_base)'		\
Packit aea12f
		$$($(VC_LIST) tests)); do				\
Packit aea12f
	    tail -n1 $$i | $(GREP) '^Exit .' > /dev/null		\
Packit aea12f
	      && : || { die=1; echo $$i; }				\
Packit aea12f
	  done;								\
Packit aea12f
	  test $$die = 1 &&						\
Packit aea12f
	    { echo 1>&2 '$(ME): the final line in each of the above is not:'; \
Packit aea12f
	      echo 1>&2 'Exit something';				\
Packit aea12f
	      exit 1; } || :;						\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
sc_trailing_blank:
Packit aea12f
	@prohibit='[	 ]$$'						\
Packit aea12f
	halt='found trailing blank(s)'					\
Packit aea12f
	exclude='^Binary file .* matches$$'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Match lines like the following, but where there is only one space
Packit aea12f
# between the options and the description:
Packit aea12f
#   -D, --all-repeated[=delimit-method]  print all duplicate lines\n
Packit aea12f
longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
Packit aea12f
sc_two_space_separator_in_usage:
Packit aea12f
	@prohibit='^   *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$'		\
Packit aea12f
	halt='help2man requires at least two spaces between an option and its description'\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# A regexp matching function names like "error" that may be used
Packit aea12f
# to emit translatable messages.
Packit aea12f
_gl_translatable_diag_func_re ?= error
Packit aea12f
Packit aea12f
# Look for diagnostics that aren't marked for translation.
Packit aea12f
# This won't find any for which error's format string is on a separate line.
Packit aea12f
sc_unmarked_diagnostics:
Packit aea12f
	@prohibit='\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
Packit aea12f
	exclude='(_|ngettext ?)\('					\
Packit aea12f
	halt='found unmarked diagnostic(s)'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Avoid useless parentheses like those in this example:
Packit aea12f
# #if defined (SYMBOL) || defined (SYM2)
Packit aea12f
sc_useless_cpp_parens:
Packit aea12f
	@prohibit='^# *if .*defined *\('				\
Packit aea12f
	halt='found useless parentheses in cpp directive'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# List headers for which HAVE_HEADER_H is always true, assuming you are
Packit aea12f
# using the appropriate gnulib module.  CAUTION: for each "unnecessary"
Packit aea12f
# #if HAVE_HEADER_H that you remove, be sure that your project explicitly
Packit aea12f
# requires the gnulib module that guarantees the usability of that header.
Packit aea12f
gl_assured_headers_ = \
Packit aea12f
  cd $(gnulib_dir)/lib && echo *.in.h|$(SED) 's/\.in\.h//g'
Packit aea12f
Packit aea12f
# Convert the list of names to upper case, and replace each space with "|".
Packit aea12f
az_ = abcdefghijklmnopqrstuvwxyz
Packit aea12f
AZ_ = ABCDEFGHIJKLMNOPQRSTUVWXYZ
Packit aea12f
gl_header_upper_case_or_ =						\
Packit aea12f
  $$($(gl_assured_headers_)						\
Packit aea12f
    | tr $(az_)/.- $(AZ_)___						\
Packit aea12f
    | tr -s ' ' '|'							\
Packit aea12f
    )
Packit aea12f
sc_prohibit_always_true_header_tests:
Packit aea12f
	@or=$(gl_header_upper_case_or_);				\
Packit aea12f
	re="HAVE_($$or)_H";						\
Packit aea12f
	prohibit='\<'"$$re"'\>'						\
Packit aea12f
	halt=$$(printf '%s\n'						\
Packit aea12f
	'do not test the above HAVE_<header>_H symbol(s);'		\
Packit aea12f
	'  with the corresponding gnulib module, they are always true')	\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_prohibit_defined_have_decl_tests:
Packit aea12f
	@prohibit='(#[	 ]*ifn?def|\<defined)\>[	 (]+HAVE_DECL_'	\
Packit aea12f
	halt='HAVE_DECL macros are always defined'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# ==================================================================
Packit aea12f
gl_other_headers_ ?= \
Packit aea12f
  intprops.h	\
Packit aea12f
  openat.h	\
Packit aea12f
  stat-macros.h
Packit aea12f
Packit aea12f
# Perl -lne code to extract "significant" cpp-defined symbols from a
Packit aea12f
# gnulib header file, eliminating a few common false-positives.
Packit aea12f
# The exempted names below are defined only conditionally in gnulib,
Packit aea12f
# and hence sometimes must/may be defined in application code.
Packit aea12f
gl_extract_significant_defines_ = \
Packit aea12f
  /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\
Packit aea12f
    && $$2 !~ /(?:rpl_|_used_without_)/\
Packit aea12f
    && $$1 !~ /^(?:NSIG|ENODATA)$$/\
Packit aea12f
    && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\
Packit aea12f
    and print $$1
Packit aea12f
Packit aea12f
# Create a list of regular expressions matching the names
Packit aea12f
# of macros that are guaranteed to be defined by parts of gnulib.
Packit aea12f
define def_sym_regex
Packit aea12f
	gen_h=$(gl_generated_headers_);					\
Packit aea12f
	(cd $(gnulib_dir)/lib;						\
Packit aea12f
	  for f in *.in.h $(gl_other_headers_); do			\
Packit aea12f
	    test -f $$f							\
Packit aea12f
	      && perl -lne '$(gl_extract_significant_defines_)' $$f;	\
Packit aea12f
	  done;								\
Packit aea12f
	) | sort -u							\
Packit aea12f
	  | $(SED) 's/^/^ *# *(define|undef)  */;s/$$/\\>/'
Packit aea12f
endef
Packit aea12f
Packit aea12f
# Don't define macros that we already get from gnulib header files.
Packit aea12f
sc_prohibit_always-defined_macros:
Packit aea12f
	@if test -d $(gnulib_dir); then					\
Packit aea12f
	  case $$(echo all: | $(GREP) -l -f - Makefile) in Makefile);; *) \
Packit aea12f
	    echo '$(ME): skipping $@: you lack GNU grep' 1>&2; exit 0;;	\
Packit aea12f
	  esac;								\
Packit aea12f
	  regex=$$($(def_sym_regex)); export regex;			\
Packit aea12f
	  $(VC_LIST_EXCEPT)						\
Packit aea12f
	    | xargs sh -c 'echo $$regex | $(GREP) -E -f - "$$@"'	\
Packit aea12f
		dummy /dev/null						\
Packit aea12f
	    && { printf '$(ME): define the above'			\
Packit aea12f
			' via some gnulib .h file\n' 1>&2;		\
Packit aea12f
	         exit 1; }						\
Packit aea12f
	    || :;							\
Packit aea12f
	fi
Packit aea12f
# ==================================================================
Packit aea12f
Packit aea12f
# Prohibit checked in backup files.
Packit aea12f
sc_prohibit_backup_files:
Packit aea12f
	@$(VC_LIST) | $(GREP) '~$$' &&					\
Packit aea12f
	  { echo '$(ME): found version controlled backup file' 1>&2;	\
Packit aea12f
	    exit 1; } || :
Packit aea12f
Packit aea12f
# Require the latest GPL.
Packit aea12f
sc_GPL_version:
Packit aea12f
	@prohibit='either ''version [^3]'				\
Packit aea12f
	halt='GPL vN, N!=3'						\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Require the latest GFDL.  Two regexp, since some .texi files end up
Packit aea12f
# line wrapping between 'Free Documentation License,' and 'Version'.
Packit aea12f
_GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any)
Packit aea12f
sc_GFDL_version:
Packit aea12f
	@prohibit='$(_GFDL_regexp)'					\
Packit aea12f
	halt='GFDL vN, N!=3'						\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Don't use Texinfo's @acronym{}.
Packit aea12f
# https://lists.gnu.org/r/bug-gnulib/2010-03/msg00321.html
Packit aea12f
texinfo_suffix_re_ ?= \.(txi|texi(nfo)?)$$
Packit aea12f
sc_texinfo_acronym:
Packit aea12f
	@prohibit='@acronym\{'						\
Packit aea12f
	in_vc_files='$(texinfo_suffix_re_)'				\
Packit aea12f
	halt='found use of Texinfo @acronym{}'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
cvs_keywords = \
Packit aea12f
  Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State
Packit aea12f
Packit aea12f
sc_prohibit_cvs_keyword:
Packit aea12f
	@prohibit='\$$($(cvs_keywords))\$$'				\
Packit aea12f
	halt='do not use CVS keyword expansion'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# This Perl code is slightly obfuscated.  Not only is each "$" doubled
Packit aea12f
# because it's in a Makefile, but the $$c's are comments;  we cannot
Packit aea12f
# use "#" due to the way the script ends up concatenated onto one line.
Packit aea12f
# It would be much more concise, and would produce better output (including
Packit aea12f
# counts) if written as:
Packit aea12f
#   perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
Packit aea12f
# but that would be far less efficient, reading the entire contents
Packit aea12f
# of each file, rather than just the last two bytes of each.
Packit aea12f
# In addition, while the code below detects both blank lines and a missing
Packit aea12f
# newline at EOF, the above detects only the former.
Packit aea12f
#
Packit aea12f
# This is a perl script that is expected to be the single-quoted argument
Packit aea12f
# to a command-line "-le".  The remaining arguments are file names.
Packit aea12f
# Print the name of each file that does not end in exactly one newline byte.
Packit aea12f
# I.e., warn if there are blank lines (2 or more newlines), or if the
Packit aea12f
# last byte is not a newline.  However, currently we don't complain
Packit aea12f
# about any file that contains exactly one byte.
Packit aea12f
# Exit nonzero if at least one such file is found, otherwise, exit 0.
Packit aea12f
# Warn about, but otherwise ignore open failure.  Ignore seek/read failure.
Packit aea12f
#
Packit aea12f
# Use this if you want to remove trailing empty lines from selected files:
Packit aea12f
#   perl -pi -0777 -e 's/\n\n+$/\n/' files...
Packit aea12f
#
Packit aea12f
require_exactly_one_NL_at_EOF_ =					\
Packit aea12f
  foreach my $$f (@ARGV)						\
Packit aea12f
    {									\
Packit aea12f
      open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next;	\
Packit aea12f
      my $$p = sysseek (F, -2, 2);					\
Packit aea12f
      my $$c = "seek failure probably means file has < 2 bytes; ignore"; \
Packit aea12f
      my $$last_two_bytes;						\
Packit aea12f
      defined $$p and $$p = sysread F, $$last_two_bytes, 2;		\
Packit aea12f
      close F;								\
Packit aea12f
      $$c = "ignore read failure";					\
Packit aea12f
      $$p && ($$last_two_bytes eq "\n\n"				\
Packit aea12f
              || substr ($$last_two_bytes,1) ne "\n")			\
Packit aea12f
          and (print $$f), $$fail=1;					\
Packit aea12f
    }									\
Packit aea12f
  END { exit defined $$fail }
Packit aea12f
sc_prohibit_empty_lines_at_EOF:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs perl -le '$(require_exactly_one_NL_at_EOF_)'		\
Packit aea12f
	  || { echo '$(ME): empty line(s) or no newline at EOF' 1>&2;	\
Packit aea12f
	       exit 1; }						\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
# Make sure we don't use st_blocks.  Use ST_NBLOCKS instead.
Packit aea12f
# This is a bit of a kludge, since it prevents use of the string
Packit aea12f
# even in comments, but for now it does the job with no false positives.
Packit aea12f
sc_prohibit_stat_st_blocks:
Packit aea12f
	@prohibit='[.>]st_blocks'					\
Packit aea12f
	halt='do not use st_blocks; use ST_NBLOCKS'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Make sure we don't define any S_IS* macros in src/*.c files.
Packit aea12f
# They're already defined via gnulib's sys/stat.h replacement.
Packit aea12f
sc_prohibit_S_IS_definition:
Packit aea12f
	@prohibit='^ *# *define  *S_IS'					\
Packit aea12f
	halt='do not define S_IS* macros; include <sys/stat.h>'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Perl block to convert a match to FILE_NAME:LINENO:TEST,
Packit aea12f
# that is shared by two definitions below.
Packit aea12f
perl_filename_lineno_text_ =						\
Packit aea12f
    -e '  {'								\
Packit aea12f
    -e '    $$n = ($$` =~ tr/\n/\n/ + 1);'				\
Packit aea12f
    -e '    ($$v = $$&) =~ s/\n/\\n/g;'					\
Packit aea12f
    -e '    print "$$ARGV:$$n:$$v\n";'					\
Packit aea12f
    -e '  }'
Packit aea12f
Packit aea12f
prohibit_doubled_words_ = \
Packit aea12f
    the then in an on if is it but for or at and do to
Packit aea12f
# expand the regex before running the check to avoid using expensive captures
Packit aea12f
prohibit_doubled_word_expanded_ = \
Packit aea12f
    $(join $(prohibit_doubled_words_),$(addprefix \s+,$(prohibit_doubled_words_)))
Packit aea12f
prohibit_doubled_word_RE_ ?= \
Packit aea12f
    /\b(?:$(subst $(_sp),|,$(prohibit_doubled_word_expanded_)))\b/gims
Packit aea12f
prohibit_doubled_word_ =						\
Packit aea12f
    -e 'while ($(prohibit_doubled_word_RE_))'				\
Packit aea12f
    $(perl_filename_lineno_text_)
Packit aea12f
Packit aea12f
# Define this to a regular expression that matches
Packit aea12f
# any filename:dd:match lines you want to ignore.
Packit aea12f
# The default is to ignore no matches.
Packit aea12f
ignore_doubled_word_match_RE_ ?= ^$$
Packit aea12f
Packit aea12f
sc_prohibit_doubled_word:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs perl -n -0777 $(prohibit_doubled_word_)		\
Packit aea12f
	  | $(GREP) -vE '$(ignore_doubled_word_match_RE_)'		\
Packit aea12f
	  | $(GREP) .							\
Packit aea12f
	  && { echo '$(ME): doubled words' 1>&2; exit 1; }		\
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
# A regular expression matching undesirable combinations of words like
Packit aea12f
# "can not"; this matches them even when the two words appear on different
Packit aea12f
# lines, but not when there is an intervening delimiter like "#" or "*".
Packit aea12f
# Similarly undesirable, "See @xref{...}", since an @xref should start
Packit aea12f
# a sentence.  Explicitly prohibit any prefix of "see" or "also".
Packit aea12f
# Also prohibit a prefix matching "\w+ +".
Packit aea12f
# @pxref gets the same see/also treatment and should be parenthesized;
Packit aea12f
# presume it must *not* start a sentence.
Packit aea12f
# POSIX spells it "timestamp" rather than "time\s+stamp", so we do, too.
Packit aea12f
bad_xref_re_ ?= (?:[\w,:;] +|(?:see|also)\s+)\@xref\{
Packit aea12f
bad_pxref_re_ ?= (?:[.!?]|(?:see|also))\s+\@pxref\{
Packit aea12f
prohibit_undesirable_word_seq_RE_ ?=					\
Packit aea12f
  /(?:\bcan\s+not\b|\btime\s+stamps?\b|$(bad_xref_re_)|$(bad_pxref_re_))/gims
Packit aea12f
prohibit_undesirable_word_seq_ =					\
Packit aea12f
    -e 'while ($(prohibit_undesirable_word_seq_RE_))'			\
Packit aea12f
    $(perl_filename_lineno_text_)
Packit aea12f
# Define this to a regular expression that matches
Packit aea12f
# any filename:dd:match lines you want to ignore.
Packit aea12f
# The default is to ignore no matches.
Packit aea12f
ignore_undesirable_word_sequence_RE_ ?= ^$$
Packit aea12f
Packit aea12f
sc_prohibit_undesirable_word_seq:
Packit aea12f
	@$(VC_LIST_EXCEPT)						\
Packit aea12f
	  | xargs perl -n -0777 $(prohibit_undesirable_word_seq_)	\
Packit aea12f
	  | $(GREP) -vE '$(ignore_undesirable_word_sequence_RE_)'	\
Packit aea12f
	  | $(GREP) .							\
Packit aea12f
	  && { echo '$(ME): undesirable word sequence' >&2; exit 1; }   \
Packit aea12f
	  || :
Packit aea12f
Packit aea12f
# Except for shell files and for loops, double semicolon is probably a mistake
Packit aea12f
sc_prohibit_double_semicolon:
Packit aea12f
	@prohibit='; *;[	{} \]*(/[/*]|$$)'			\
Packit aea12f
	in_vc_files='\.[chly]$$'					\
Packit aea12f
	exclude='\bfor *\(.*\)'						\
Packit aea12f
	halt="Double semicolon detected"				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
_ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
Packit aea12f
_ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
Packit aea12f
# Using test's -a and -o operators is not portable.
Packit aea12f
# We prefer test over [, since the latter is spelled [[ in configure.ac.
Packit aea12f
sc_prohibit_test_minus_ao:
Packit aea12f
	@prohibit='(\
Packit aea12f
	halt='$(_ptm1); $(_ptm2)'					\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Avoid a test bashism.
Packit aea12f
sc_prohibit_test_double_equal:
Packit aea12f
	@prohibit='(\
Packit aea12f
	containing='#! */bin/[a-z]*sh'					\
Packit aea12f
	halt='use "test x = x", not "test x =''= x"'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Each program that uses proper_name_utf8 must link with one of the
Packit aea12f
# ICONV libraries.  Otherwise, some ICONV library must appear in LDADD.
Packit aea12f
# The perl -0777 invocation below extracts the possibly-multi-line
Packit aea12f
# definition of LDADD from the appropriate Makefile.am and exits 0
Packit aea12f
# when it contains "ICONV".
Packit aea12f
sc_proper_name_utf8_requires_ICONV:
Packit aea12f
	@progs=$$($(VC_LIST_EXCEPT)					\
Packit aea12f
		    | xargs $(GREP) -l 'proper_name_utf8 ''("');	\
Packit aea12f
	if test "x$$progs" != x; then					\
Packit aea12f
	  fail=0;							\
Packit aea12f
	  for p in $$progs; do						\
Packit aea12f
	    dir=$$(dirname "$$p");					\
Packit aea12f
	    perl -0777							\
Packit aea12f
	      -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)'	\
Packit aea12f
	      $$dir/Makefile.am && continue;				\
Packit aea12f
	    base=$$(basename "$$p" .c);					\
Packit aea12f
	    $(GREP) "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null	\
Packit aea12f
	      || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
Packit aea12f
	  done;								\
Packit aea12f
	  test $$fail = 1 &&						\
Packit aea12f
	    { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \
Packit aea12f
	      exit 1; } || :;						\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
# Warn about "c0nst struct Foo const foo[]",
Packit aea12f
# but not about "char const *const foo" or "#define const const".
Packit aea12f
sc_redundant_const:
Packit aea12f
	@prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b'		\
Packit aea12f
	halt='redundant "const" in declarations'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_const_long_option:
Packit aea12f
	@prohibit='^ *static.*struct option '				\
Packit aea12f
	exclude='const struct option|struct option const'		\
Packit aea12f
	halt='add "const" to the above declarations'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
NEWS_hash =								\
Packit aea12f
  $$($(SED) -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p'		\
Packit aea12f
       $(srcdir)/NEWS							\
Packit aea12f
     | perl -0777 -pe							\
Packit aea12f
	's/^Copyright.+?Free\sSoftware\sFoundation,\sInc\.\n//ms'	\
Packit aea12f
     | md5sum -								\
Packit aea12f
     | $(SED) 's/ .*//')
Packit aea12f
Packit aea12f
# Ensure that we don't accidentally insert an entry into an old NEWS block.
Packit aea12f
sc_immutable_NEWS:
Packit aea12f
	@if test -f $(srcdir)/NEWS; then				\
Packit aea12f
	  test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : ||		\
Packit aea12f
	    { echo '$(ME): you have modified old NEWS' 1>&2; exit 1; };	\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
# Update the hash stored above.  Do this after each release and
Packit aea12f
# for any corrections to old entries.
Packit aea12f
update-NEWS-hash: NEWS
Packit aea12f
	perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \
Packit aea12f
	  $(srcdir)/cfg.mk
Packit aea12f
Packit aea12f
# Ensure that we use only the standard $(VAR) notation,
Packit aea12f
# not @...@ in Makefile.am, now that we can rely on automake
Packit aea12f
# to emit a definition for each substituted variable.
Packit aea12f
# However, there is still one case in which @VAR@ use is not just
Packit aea12f
# legitimate, but actually required: when augmenting an automake-defined
Packit aea12f
# variable with a prefix.  For example, gettext uses this:
Packit aea12f
# MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
Packit aea12f
# otherwise, makeinfo would put German or French (current locale)
Packit aea12f
# navigation hints in the otherwise-English documentation.
Packit aea12f
#
Packit aea12f
# Allow the package to add exceptions via a hook in cfg.mk;
Packit aea12f
# for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
Packit aea12f
# setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
Packit aea12f
_makefile_at_at_check_exceptions ?=
Packit aea12f
sc_makefile_at_at_check:
Packit aea12f
	@perl -ne '/\@\w+\@/'						\
Packit aea12f
          -e ' && !/(\w+)\s+=.*\@\1\@$$/'				\
Packit aea12f
          -e ''$(_makefile_at_at_check_exceptions)			\
Packit aea12f
	  -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}'	\
Packit aea12f
	    $$($(VC_LIST_EXCEPT) | $(GREP) -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
Packit aea12f
	  && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
Packit aea12f
Packit aea12f
news-check: NEWS
Packit aea12f
	$(AM_V_GEN)if $(SED) -n $(news-check-lines-spec)p $<		\
Packit aea12f
	    | $(GREP) -E $(news-check-regexp) >/dev/null; then		\
Packit aea12f
	  :;								\
Packit aea12f
	else								\
Packit aea12f
	  echo 'NEWS: $$(news-check-regexp) failed to match' 1>&2;	\
Packit aea12f
	  exit 1;							\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
sc_makefile_TAB_only_indentation:
Packit aea12f
	@prohibit='^	[ ]{8}'						\
Packit aea12f
	in_vc_files='akefile|\.mk$$'					\
Packit aea12f
	halt='found TAB-8-space indentation'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_m4_quote_check:
Packit aea12f
	@prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]'		\
Packit aea12f
	in_vc_files='(^configure\.ac|\.m4)$$'				\
Packit aea12f
	halt='quote the first arg to AC_DEF*'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
fix_po_file_diag = \
Packit aea12f
'you have changed the set of files with translatable diagnostics;\n\
Packit aea12f
apply the above patch\n'
Packit aea12f
Packit aea12f
# Generate a list of files in which to search for translatable strings.
Packit aea12f
perl_translatable_files_list_ =						\
Packit aea12f
  -e 'foreach $$file (@ARGV) {'						\
Packit aea12f
  -e '	\# Consider only file extensions with one or two letters'	\
Packit aea12f
  -e '	$$file =~ /\...?$$/ or next;'					\
Packit aea12f
  -e '	\# Ignore m4 and mk files'					\
Packit aea12f
  -e '	$$file =~ /\.m[4k]$$/ and next;'				\
Packit aea12f
  -e '	\# Ignore a .c or .h file with a corresponding .l or .y file'	\
Packit aea12f
  -e '	$$file =~ /(.+)\.[ch]$$/ && (-e "$${1}.l" || -e "$${1}.y")'	\
Packit aea12f
  -e '	  and next;'							\
Packit aea12f
  -e '	\# Skip unreadable files'					\
Packit aea12f
  -e '	-r $$file or next;'						\
Packit aea12f
  -e '	print "$$file ";'						\
Packit aea12f
  -e '}'
Packit aea12f
Packit aea12f
# Verify that all source files using _() (more specifically, files that
Packit aea12f
# match $(_gl_translatable_string_re)) are listed in po/POTFILES.in.
Packit aea12f
po_file ?= $(srcdir)/po/POTFILES.in
Packit aea12f
generated_files ?= $(srcdir)/lib/*.[ch]
Packit aea12f
_gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$)
Packit aea12f
sc_po_check:
Packit aea12f
	@if test -f $(po_file); then					\
Packit aea12f
	  $(GREP) -E -v '^(#|$$)' $(po_file)				\
Packit aea12f
	    | $(GREP) -v '^src/false\.c$$' | sort > $@-1;		\
Packit aea12f
	  { $(VC_LIST_EXCEPT); echo $(generated_files); }		\
Packit aea12f
	    | xargs perl $(perl_translatable_files_list_)		\
Packit aea12f
	    | xargs $(GREP) -E -l '$(_gl_translatable_string_re)'	\
Packit aea12f
	    | $(SED) 's|^$(_dot_escaped_srcdir)/||'			\
Packit aea12f
	    | sort -u > $@-2;						\
Packit aea12f
	  diff -u -L $(po_file) -L $(po_file) $@-1 $@-2			\
Packit aea12f
	    || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; };	\
Packit aea12f
	  rm -f $@-1 $@-2;						\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
# Sometimes it is useful to change the PATH environment variable
Packit aea12f
# in Makefiles.  When doing so, it's better not to use the Unix-centric
Packit aea12f
# path separator of ':', but rather the automake-provided '$(PATH_SEPARATOR)'.
Packit aea12f
msg = 'Do not use ":" above; use $$(PATH_SEPARATOR) instead'
Packit aea12f
sc_makefile_path_separator_check:
Packit aea12f
	@prohibit='PATH[=].*:'						\
Packit aea12f
	in_vc_files='akefile|\.mk$$'					\
Packit aea12f
	halt=$(msg)							\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Check that 'make alpha' will not fail at the end of the process,
Packit aea12f
# i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release)
Packit aea12f
# and is read-only.
Packit aea12f
writable-files:
Packit aea12f
	$(AM_V_GEN)if test -d $(release_archive_dir); then		\
Packit aea12f
	  for file in $(DIST_ARCHIVES); do				\
Packit aea12f
	    for p in ./ $(release_archive_dir)/; do			\
Packit aea12f
	      test -e $$p$$file || continue;				\
Packit aea12f
	      test -w $$p$$file						\
Packit aea12f
		|| { echo ERROR: $$p$$file is not writable; fail=1; };	\
Packit aea12f
	    done;							\
Packit aea12f
	  done;								\
Packit aea12f
	  test "$$fail" && exit 1 || : ;				\
Packit aea12f
	else :;								\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
v_etc_file = $(gnulib_dir)/lib/version-etc.c
Packit aea12f
sample-test = tests/sample-test
Packit aea12f
texi = doc/$(PACKAGE).texi
Packit aea12f
# Make sure that the copyright date in $(v_etc_file) is up to date.
Packit aea12f
# Do the same for the $(sample-test) and the main doc/.texi file.
Packit aea12f
sc_copyright_check:
Packit aea12f
	@require='enum { COPYRIGHT_YEAR = '$$(date +%Y)' };'		\
Packit aea12f
	in_files=$(v_etc_file)						\
Packit aea12f
	halt='out of date copyright in $(v_etc_file); update it'	\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
	@require='# Copyright \(C\) '$$(date +%Y)' Free'		\
Packit aea12f
	in_vc_files=$(sample-test)					\
Packit aea12f
	halt='out of date copyright in $(sample-test); update it'	\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
	@require='Copyright @copyright\{\} .*'$$(date +%Y)		\
Packit aea12f
	in_vc_files=$(texi)						\
Packit aea12f
	halt='out of date copyright in $(texi); update it'		\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# If tests/help-version exists and seems to be new enough, assume that its
Packit aea12f
# use of init.sh and path_prepend_ is correct, and ensure that every other
Packit aea12f
# use of init.sh is identical.
Packit aea12f
# This is useful because help-version cross-checks prog --version
Packit aea12f
# with $(VERSION), which verifies that its path_prepend_ invocation
Packit aea12f
# sets PATH correctly.  This is an inexpensive way to ensure that
Packit aea12f
# the other init.sh-using tests also get it right.
Packit aea12f
_hv_file ?= $(srcdir)/tests/help-version
Packit aea12f
_hv_regex_weak ?= ^ *\. .*/init\.sh"
Packit aea12f
# Fix syntax-highlighters "
Packit aea12f
_hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh"
Packit aea12f
sc_cross_check_PATH_usage_in_tests:
Packit aea12f
	@if test -f $(_hv_file); then					\
Packit aea12f
	  $(GREP) -l 'VERSION mismatch' $(_hv_file) >/dev/null		\
Packit aea12f
	    || { echo "$@: skipped: no such file: $(_hv_file)" 1>&2;	\
Packit aea12f
		 exit 0; };						\
Packit aea12f
	  $(GREP) -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null	\
Packit aea12f
	    || { echo "$@: $(_hv_file) lacks conforming use of init.sh" 1>&2; \
Packit aea12f
		 exit 1; };						\
Packit aea12f
	  good=$$($(GREP) -E '$(_hv_regex_strong)' $(_hv_file));	\
Packit aea12f
	  $(VC_LIST_EXCEPT)						\
Packit aea12f
	    | xargs $(GREP) -lE '$(_hv_regex_weak)'			\
Packit aea12f
	    | xargs $(GREP) -LFx "$$good"				\
Packit aea12f
	    | $(GREP) .							\
Packit aea12f
	    && { printf "$(ME): the above files use"			\
Packit aea12f
			" path_prepend_ inconsistently\n" 1>&2;		\
Packit aea12f
		 exit 1; }						\
Packit aea12f
	    || :;							\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
# BRE regex of file contents to identify a test script.
Packit aea12f
_test_script_regex ?= \<init\.sh\>
Packit aea12f
Packit aea12f
# In tests, use "compare expected actual", not the reverse.
Packit aea12f
sc_prohibit_reversed_compare_failure:
Packit aea12f
	@prohibit='\
Packit aea12f
	containing='$(_test_script_regex)'				\
Packit aea12f
	halt='reversed compare arguments'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# #if HAVE_... will evaluate to false for any non numeric string.
Packit aea12f
# That would be flagged by using -Wundef, however gnulib currently
Packit aea12f
# tests many undefined macros, and so we can't enable that option.
Packit aea12f
# So at least preclude common boolean strings as macro values.
Packit aea12f
sc_Wundef_boolean:
Packit aea12f
	@prohibit='^#define.*(yes|no|true|false)$$'			\
Packit aea12f
	in_files='$(CONFIG_INCLUDE)'					\
Packit aea12f
	halt='Use 0 or 1 for macro values'				\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
# Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
Packit aea12f
# not be constant, or might overflow a stack.  In general, use PATH_MAX as
Packit aea12f
# a limit, not an array or alloca size.
Packit aea12f
sc_prohibit_path_max_allocation:
Packit aea12f
	@prohibit='(\balloca *\([^)]*|\[[^]]*)\bPATH_MAX'		\
Packit aea12f
	halt='Avoid stack allocations of size PATH_MAX'			\
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_vulnerable_makefile_CVE-2009-4029:
Packit aea12f
	@prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
Packit aea12f
	in_files='(^|/)Makefile\.in$$'					\
Packit aea12f
	halt=$$(printf '%s\n'						\
Packit aea12f
	  'the above files are vulnerable; beware of running'		\
Packit aea12f
	  '  "make dist*" rules, and upgrade to fixed automake'		\
Packit aea12f
	  '  see https://bugzilla.redhat.com/show_bug.cgi?id=542609 for details') \
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
sc_vulnerable_makefile_CVE-2012-3386:
Packit aea12f
	@prohibit='chmod a\+w \$$\(distdir\)'				\
Packit aea12f
	in_files='(^|/)Makefile\.in$$'					\
Packit aea12f
	halt=$$(printf '%s\n'						\
Packit aea12f
	  'the above files are vulnerable; beware of running'		\
Packit aea12f
	  '  "make distcheck", and upgrade to fixed automake'		\
Packit aea12f
	  '  see https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-3386 for details') \
Packit aea12f
	  $(_sc_search_regexp)
Packit aea12f
Packit aea12f
vc-diff-check:
Packit aea12f
	$(AM_V_GEN)(unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || :
Packit aea12f
	$(AM_V_at)if test -s vc-diffs; then			\
Packit aea12f
	  cat vc-diffs;						\
Packit aea12f
	  echo "Some files are locally modified:" 1>&2;		\
Packit aea12f
	  exit 1;						\
Packit aea12f
	else							\
Packit aea12f
	  rm vc-diffs;						\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
rel-files = $(DIST_ARCHIVES)
Packit aea12f
Packit aea12f
gnulib-version = $$(cd $(gnulib_dir)				\
Packit aea12f
                    && { git describe || git rev-parse --short=10 HEAD; } )
Packit aea12f
bootstrap-tools ?= autoconf,automake,gnulib
Packit aea12f
Packit aea12f
gpgv = $$(gpgv2 --version >/dev/null && echo gpgv2 || echo gpgv)
Packit aea12f
# If it's not already specified, derive the GPG key ID from
Packit aea12f
# the signed tag we've just applied to mark this release.
Packit aea12f
gpg_key_ID ?=								\
Packit aea12f
  $$(cd $(srcdir)							\
Packit aea12f
     && git cat-file tag v$(VERSION)					\
Packit aea12f
        | $(gpgv) --status-fd 1 --keyring /dev/null - - 2>/dev/null	\
Packit Service 991b93
        | $(AWK) '/^\[GNUPG:\] ERRSIG / {print $$3; exit}')
Packit aea12f
Packit aea12f
translation_project_ ?= coordinator@translationproject.org
Packit aea12f
Packit aea12f
# Make info-gnu the default only for a stable release.
Packit aea12f
announcement_Cc_stable = $(translation_project_), $(PACKAGE_BUGREPORT)
Packit aea12f
announcement_mail_headers_stable =		\
Packit aea12f
  To: info-gnu@gnu.org				\
Packit aea12f
  Cc: $(announcement_Cc_)			\
Packit aea12f
  Mail-Followup-To: $(PACKAGE_BUGREPORT)
Packit aea12f
Packit aea12f
announcement_Cc_alpha = $(translation_project_)
Packit aea12f
announcement_mail_headers_alpha =		\
Packit aea12f
  To: $(PACKAGE_BUGREPORT)			\
Packit aea12f
  Cc: $(announcement_Cc_)
Packit aea12f
Packit aea12f
announcement_mail_Cc_beta = $(announcement_mail_Cc_alpha)
Packit aea12f
announcement_mail_headers_beta = $(announcement_mail_headers_alpha)
Packit aea12f
Packit aea12f
announcement_mail_Cc_ ?= $(announcement_mail_Cc_$(release-type))
Packit aea12f
announcement_mail_headers_ ?= $(announcement_mail_headers_$(release-type))
Packit aea12f
announcement: NEWS ChangeLog $(rel-files)
Packit aea12f
# Not $(AM_V_GEN) since the output of this command serves as
Packit aea12f
# announcement message: it would start with " GEN announcement".
Packit aea12f
	$(AM_V_at)$(srcdir)/$(_build-aux)/announce-gen			\
Packit aea12f
	    --mail-headers='$(announcement_mail_headers_)'		\
Packit aea12f
	    --release-type=$(release-type)				\
Packit aea12f
	    --package=$(PACKAGE)					\
Packit aea12f
	    --prev=$(PREV_VERSION)					\
Packit aea12f
	    --curr=$(VERSION)						\
Packit aea12f
	    --gpg-key-id=$(gpg_key_ID)					\
Packit aea12f
	    --srcdir=$(srcdir)						\
Packit aea12f
	    --news=$(srcdir)/NEWS					\
Packit aea12f
	    --bootstrap-tools=$(bootstrap-tools)			\
Packit aea12f
	    $$(case ,$(bootstrap-tools), in (*,gnulib,*)		\
Packit aea12f
	       echo --gnulib-version=$(gnulib-version);; esac)		\
Packit aea12f
	    --no-print-checksums					\
Packit aea12f
	    $(addprefix --url-dir=, $(url_dir_list))
Packit aea12f
Packit aea12f
.PHONY: release-commit
Packit aea12f
release-commit:
Packit aea12f
	$(AM_V_GEN)cd $(srcdir)				\
Packit aea12f
	  && $(_build-aux)/do-release-commit-and-tag	\
Packit aea12f
	       -C $(abs_builddir) $(RELEASE)
Packit aea12f
Packit aea12f
## ---------------- ##
Packit aea12f
## Updating files.  ##
Packit aea12f
## ---------------- ##
Packit aea12f
Packit aea12f
ftp-gnu = https://ftp.gnu.org/gnu
Packit aea12f
www-gnu = https://www.gnu.org
Packit aea12f
Packit aea12f
upload_dest_dir_ ?= $(PACKAGE)
Packit aea12f
upload_command =						\
Packit aea12f
  $(srcdir)/$(_build-aux)/gnupload $(GNUPLOADFLAGS)		\
Packit aea12f
  --to $(gnu_rel_host):$(upload_dest_dir_)			\
Packit aea12f
  $(rel-files)
Packit aea12f
emit_upload_commands:
Packit aea12f
	@echo =====================================
Packit aea12f
	@echo =====================================
Packit aea12f
	@echo '$(upload_command)'
Packit aea12f
	@echo '# send the ~/announce-$(my_distdir) e-mail'
Packit aea12f
	@echo =====================================
Packit aea12f
	@echo =====================================
Packit aea12f
Packit aea12f
.PHONY: upload
Packit aea12f
upload:
Packit aea12f
	$(AM_V_GEN)$(upload_command)
Packit aea12f
Packit aea12f
define emit-commit-log
Packit aea12f
  printf '%s\n' 'maint: post-release administrivia' ''			\
Packit aea12f
    '* NEWS: Add header line for next release.'				\
Packit aea12f
    '* .prev-version: Record previous version.'				\
Packit aea12f
    '* cfg.mk (old_NEWS_hash): Auto-update.'
Packit aea12f
endef
Packit aea12f
Packit aea12f
.PHONY: no-submodule-changes
Packit aea12f
no-submodule-changes:
Packit aea12f
	$(AM_V_GEN)if test -d $(srcdir)/.git				\
Packit aea12f
		&& git --version >/dev/null 2>&1; then			\
Packit aea12f
	  diff=$$(cd $(srcdir) && git submodule -q foreach		\
Packit aea12f
		  git diff-index --name-only HEAD)			\
Packit aea12f
	    || exit 1;							\
Packit aea12f
	  case $$diff in '') ;;						\
Packit aea12f
	    *) echo '$(ME): submodule files are locally modified:';	\
Packit aea12f
		echo "$$diff"; exit 1;; esac;				\
Packit aea12f
	else								\
Packit aea12f
	  : ;								\
Packit aea12f
	fi
Packit aea12f
Packit aea12f
submodule-checks ?= no-submodule-changes public-submodule-commit
Packit aea12f
Packit aea12f
# Ensure that each sub-module commit we're using is public.
Packit aea12f
# Without this, it is too easy to tag and release code that
Packit aea12f
# cannot be built from a fresh clone.
Packit aea12f
.PHONY: public-submodule-commit
Packit aea12f
public-submodule-commit:
Packit aea12f
	$(AM_V_GEN)if test -d $(srcdir)/.git				\
Packit aea12f
		&& git --version >/dev/null 2>&1; then			\
Packit aea12f
	  cd $(srcdir) &&						\
Packit aea12f
	  git submodule --quiet foreach					\
Packit aea12f
	      'test "$$(git rev-parse "$$sha1")"			\
Packit aea12f
		  = "$$(git merge-base origin "$$sha1")"'		\
Packit aea12f
	    || { echo '$(ME): found non-public submodule commit' >&2;	\
Packit aea12f
		 exit 1; };						\
Packit aea12f
	else								\
Packit aea12f
	  : ;								\
Packit aea12f
	fi
Packit aea12f
# This rule has a high enough utility/cost ratio that it should be a
Packit aea12f
# dependent of "check" by default.  However, some of us do occasionally
Packit aea12f
# commit a temporary change that deliberately points to a non-public
Packit aea12f
# submodule commit, and want to be able to use rules like "make check".
Packit aea12f
# In that case, run e.g., "make check gl_public_submodule_commit="
Packit aea12f
# to disable this test.
Packit aea12f
gl_public_submodule_commit ?= public-submodule-commit
Packit aea12f
check: $(gl_public_submodule_commit)
Packit aea12f
Packit aea12f
.PHONY: alpha beta stable release
Packit aea12f
ALL_RECURSIVE_TARGETS += alpha beta stable
Packit aea12f
alpha beta stable: $(local-check) writable-files $(submodule-checks)
Packit aea12f
	$(AM_V_GEN)test $@ = stable					\
Packit aea12f
	  && { echo $(VERSION) | $(GREP) -E '^[0-9]+(\.[0-9]+)+$$'	\
Packit aea12f
	       || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
Packit aea12f
	  || :
Packit aea12f
	$(AM_V_at)$(MAKE) vc-diff-check
Packit aea12f
	$(AM_V_at)$(MAKE) news-check
Packit aea12f
	$(AM_V_at)$(MAKE) distcheck
Packit aea12f
	$(AM_V_at)$(MAKE) dist
Packit aea12f
	$(AM_V_at)$(MAKE) $(release-prep-hook) RELEASE_TYPE=$@
Packit aea12f
	$(AM_V_at)$(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
Packit aea12f
Packit aea12f
release:
Packit aea12f
	$(AM_V_GEN)$(MAKE) _version
Packit aea12f
	$(AM_V_GEN)$(MAKE) $(release-type)
Packit aea12f
Packit aea12f
# Override this in cfg.mk if you follow different procedures.
Packit aea12f
release-prep-hook ?= release-prep
Packit aea12f
Packit aea12f
gl_noteworthy_news_ = * Noteworthy changes in release ?.? (????-??-??) [?]
Packit aea12f
.PHONY: release-prep
Packit aea12f
release-prep:
Packit aea12f
	$(AM_V_GEN)$(MAKE) --no-print-directory -s announcement \
Packit aea12f
	  > ~/announce-$(my_distdir)
Packit aea12f
	$(AM_V_at)if test -d $(release_archive_dir); then	\
Packit aea12f
	  ln $(rel-files) $(release_archive_dir);		\
Packit aea12f
	  chmod a-w $(rel-files);				\
Packit aea12f
	fi
Packit aea12f
	$(AM_V_at)echo $(VERSION) > $(prev_version_file)
Packit aea12f
	$(AM_V_at)$(MAKE) update-NEWS-hash
Packit aea12f
	$(AM_V_at)perl -pi						\
Packit aea12f
	  -e '$$. == 3 and print "$(gl_noteworthy_news_)\n\n\n"'	\
Packit aea12f
	  $(srcdir)/NEWS
Packit aea12f
	$(AM_V_at)msg=$$($(emit-commit-log)) || exit 1;		\
Packit aea12f
	cd $(srcdir) && $(VC) commit -m "$$msg" -a
Packit aea12f
Packit aea12f
# Override this with e.g., -s $(srcdir)/some_other_name.texi
Packit aea12f
# if the default $(PACKAGE)-derived name doesn't apply.
Packit aea12f
gendocs_options_ ?=
Packit aea12f
Packit aea12f
.PHONY: web-manual
Packit aea12f
web-manual:
Packit aea12f
	$(AM_V_GEN)test -z "$(manual_title)" \
Packit aea12f
	  && { echo define manual_title in cfg.mk 1>&2; exit 1; } || :
Packit aea12f
	$(AM_V_at)cd '$(srcdir)/doc'; \
Packit aea12f
	  $(SHELL) ../$(_build-aux)/gendocs.sh $(gendocs_options_) \
Packit aea12f
	     -o '$(abs_builddir)/doc/manual' \
Packit aea12f
	     --email $(PACKAGE_BUGREPORT) $(PACKAGE) \
Packit aea12f
	    "$(PACKAGE_NAME) - $(manual_title)"
Packit aea12f
	$(AM_V_at)echo " *** Upload the doc/manual directory to web-cvs."
Packit aea12f
Packit aea12f
.PHONY: web-manual-update
Packit aea12f
web-manual-update:
Packit aea12f
	$(AM_V_GEN)cd $(srcdir) \
Packit aea12f
	  && $(_build-aux)/gnu-web-doc-update -C $(abs_builddir)
Packit aea12f
Packit aea12f
Packit aea12f
# Code Coverage
Packit aea12f
Packit aea12f
init-coverage:
Packit aea12f
	$(MAKE) $(AM_MAKEFLAGS) clean
Packit aea12f
	lcov --directory . --zerocounters
Packit aea12f
Packit aea12f
COVERAGE_CCOPTS ?= "-g --coverage"
Packit aea12f
COVERAGE_OUT ?= doc/coverage
Packit aea12f
Packit aea12f
build-coverage:
Packit aea12f
	$(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
Packit aea12f
	$(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
Packit aea12f
	mkdir -p $(COVERAGE_OUT)
Packit aea12f
	lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
Packit aea12f
		--capture
Packit aea12f
Packit aea12f
gen-coverage:
Packit aea12f
	genhtml --output-directory $(COVERAGE_OUT) \
Packit aea12f
		$(COVERAGE_OUT)/$(PACKAGE).info \
Packit aea12f
		--highlight --frames --legend \
Packit aea12f
		--title "$(PACKAGE_NAME)"
Packit aea12f
Packit aea12f
coverage:
Packit aea12f
	$(MAKE) init-coverage
Packit aea12f
	$(MAKE) build-coverage
Packit aea12f
	$(MAKE) gen-coverage
Packit aea12f
Packit aea12f
# Some projects carry local adjustments for gnulib modules via patches in
Packit aea12f
# a gnulib patch directory whose default name is gl/ (defined in bootstrap
Packit aea12f
# via local_gl_dir=gl).  Those patches become stale as the originals evolve
Packit aea12f
# in gnulib.  Use this rule to refresh any stale patches.  It applies each
Packit aea12f
# patch to the original in $(gnulib_dir) and uses the temporary result to
Packit aea12f
# generate a fuzz-free .diff file.  If you customize the name of your local
Packit aea12f
# gnulib patch directory via bootstrap.conf, this rule detects that name.
Packit aea12f
# Run this from a non-VPATH (i.e., srcdir) build directory.
Packit aea12f
.PHONY: refresh-gnulib-patches
Packit aea12f
refresh-gnulib-patches:
Packit aea12f
	gl=gl;								\
Packit aea12f
	if test -f bootstrap.conf; then					\
Packit aea12f
	  t=$$(perl -lne '/^\s*local_gl_dir=(\S+)/ and $$d=$$1;'	\
Packit aea12f
	       -e 'END{defined $$d and print $$d}' bootstrap.conf);	\
Packit aea12f
	  test -n "$$t" && gl=$$t;					\
Packit aea12f
	fi;								\
Packit aea12f
	for diff in $$(cd $$gl; git ls-files | $(GREP) '\.diff$$'); do	\
Packit aea12f
	  b=$$(printf %s "$$diff"|$(SED) 's/\.diff$$//');		\
Packit aea12f
	  VERSION_CONTROL=none						\
Packit aea12f
	    patch "$(gnulib_dir)/$$b" "$$gl/$$diff" || exit 1;		\
Packit aea12f
	  ( cd $(gnulib_dir) || exit 1;					\
Packit aea12f
	    git diff "$$b" > "../$$gl/$$diff";				\
Packit aea12f
	    git checkout $$b ) || exit 1;				\
Packit aea12f
	done
Packit aea12f
Packit aea12f
# Update gettext files.
Packit aea12f
PACKAGE ?= $(shell basename $(PWD))
Packit aea12f
PO_DOMAIN ?= $(PACKAGE)
Packit aea12f
POURL = https://translationproject.org/latest/$(PO_DOMAIN)/
Packit aea12f
PODIR ?= po
Packit aea12f
refresh-po:
Packit aea12f
	rm -f $(PODIR)/*.po && \
Packit aea12f
	echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
Packit aea12f
	wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
Packit aea12f
	echo 'en@boldquot' > $(PODIR)/LINGUAS && \
Packit aea12f
	echo 'en@quot' >> $(PODIR)/LINGUAS && \
Packit aea12f
	ls $(PODIR)/*.po | $(SED) 's/\.po//;s,$(PODIR)/,,' | \
Packit aea12f
	  sort >> $(PODIR)/LINGUAS
Packit aea12f
Packit aea12f
 # Running indent once is not idempotent, but running it twice is.
Packit aea12f
INDENT_SOURCES ?= $(C_SOURCES)
Packit aea12f
.PHONY: indent
Packit aea12f
indent:
Packit aea12f
	indent $(INDENT_SOURCES)
Packit aea12f
	indent $(INDENT_SOURCES)
Packit aea12f
Packit aea12f
# If you want to set UPDATE_COPYRIGHT_* environment variables,
Packit aea12f
# put the assignments in this variable.
Packit aea12f
update-copyright-env ?=
Packit aea12f
Packit aea12f
# Run this rule once per year (usually early in January)
Packit aea12f
# to update all FSF copyright year lists in your project.
Packit aea12f
# If you have an additional project-specific rule,
Packit aea12f
# add it in cfg.mk along with a line 'update-copyright: prereq'.
Packit aea12f
# By default, exclude all variants of COPYING; you can also
Packit aea12f
# add exemptions (such as ChangeLog..* for rotated change logs)
Packit aea12f
# in the file .x-update-copyright.
Packit aea12f
.PHONY: update-copyright
Packit aea12f
update-copyright:
Packit aea12f
	$(AM_V_GEN)$(GREP) -l -w Copyright                               \
Packit aea12f
	  $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
Packit aea12f
	  | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
Packit aea12f
Packit aea12f
# This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
Packit aea12f
# overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
Packit aea12f
Packit aea12f
# NOTE: to override any _gl_TS_* default value, you must
Packit aea12f
# define the variable(s) using "export" in cfg.mk.
Packit aea12f
_gl_TS_dir ?= src
Packit aea12f
Packit aea12f
ALL_RECURSIVE_TARGETS += sc_tight_scope
Packit aea12f
sc_tight_scope: tight-scope.mk
Packit aea12f
	@fail=0;							\
Packit aea12f
	if ! $(GREP) '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk	\
Packit aea12f
		> /dev/null						\
Packit aea12f
	   && ! $(GREP) -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
Packit aea12f
		> /dev/null 2>&1; then					\
Packit aea12f
	    echo '$(ME): skipping $@';					\
Packit aea12f
	else								\
Packit aea12f
	    $(MAKE) -s -C $(_gl_TS_dir)					\
Packit aea12f
		-f Makefile						\
Packit aea12f
		-f $(abs_top_srcdir)/cfg.mk				\
Packit aea12f
		-f $(abs_top_builddir)/$<				\
Packit aea12f
	      _gl_tight_scope						\
Packit aea12f
		|| fail=1;						\
Packit aea12f
	fi;								\
Packit aea12f
	rm -f $<;							\
Packit aea12f
	exit $$fail
Packit aea12f
Packit aea12f
tight-scope.mk: $(ME)
Packit aea12f
	@rm -f $@ $@-t
Packit aea12f
	@perl -ne '/^# TS-start/.../^# TS-end/ and print' $(srcdir)/$(ME) > $@-t
Packit aea12f
	@chmod a=r $@-t && mv $@-t $@
Packit aea12f
Packit aea12f
ifeq (a,b)
Packit aea12f
# TS-start
Packit aea12f
Packit aea12f
# Most functions should have static scope.
Packit aea12f
# Any that don't must be marked with 'extern', but 'main'
Packit aea12f
# and 'usage' are exceptions: they're always extern, but
Packit aea12f
# do not need to be marked.  Symbols matching '__.*' are
Packit aea12f
# reserved by the compiler, so are automatically excluded below.
Packit aea12f
_gl_TS_unmarked_extern_functions ?= main usage
Packit aea12f
_gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\w+) *\(/
Packit aea12f
Packit aea12f
# If your project uses a macro like "XTERN", then put
Packit aea12f
# the following in cfg.mk to override this default:
Packit aea12f
# export _gl_TS_extern = extern|XTERN
Packit aea12f
_gl_TS_extern ?= extern
Packit aea12f
Packit aea12f
# The second nm|grep checks for file-scope variables with 'extern' scope.
Packit aea12f
# Without gnulib's progname module, you might put program_name here.
Packit aea12f
# Symbols matching '__.*' are reserved by the compiler,
Packit aea12f
# so are automatically excluded below.
Packit aea12f
_gl_TS_unmarked_extern_vars ?=
Packit aea12f
Packit aea12f
# NOTE: the _match variables are perl expressions -- not mere regular
Packit aea12f
# expressions -- so that you can extend them to match other patterns
Packit aea12f
# and easily extract matched variable names.
Packit aea12f
# For example, if your project declares some global variables via
Packit aea12f
# a macro like this: GLOBAL(type, var_name, initializer), then you
Packit aea12f
# can override this definition to automatically extract those names:
Packit aea12f
# export _gl_TS_var_match = \
Packit aea12f
#   /^(?:$(_gl_TS_extern)) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
Packit aea12f
_gl_TS_var_match ?= /^(?:$(_gl_TS_extern)) .*?(\w+)(\[.*?\])?;/
Packit aea12f
Packit aea12f
# The names of object files in (or relative to) $(_gl_TS_dir).
Packit aea12f
_gl_TS_obj_files ?= *.$(OBJEXT)
Packit aea12f
Packit aea12f
# Files in which to search for the one-line style extern declarations.
Packit aea12f
# $(_gl_TS_dir)-relative.
Packit aea12f
_gl_TS_headers ?= $(noinst_HEADERS)
Packit aea12f
_gl_TS_other_headers ?= *.h
Packit aea12f
Packit aea12f
.PHONY: _gl_tight_scope
Packit aea12f
_gl_tight_scope: $(bin_PROGRAMS)
Packit aea12f
	sed_wrap='s/^/^_?/;s/$$/$$/';					\
Packit aea12f
	t=exceptions-$$$$;						\
Packit aea12f
	trap 's=$$?; rm -f $$t; exit $$s' 0;				\
Packit aea12f
	for sig in 1 2 3 13 15; do					\
Packit aea12f
	  eval "trap 'v=`expr $$sig + 128`; (exit $$v); exit $$v' $$sig"; \
Packit aea12f
	done;								\
Packit aea12f
	src=`for f in $(SOURCES); do					\
Packit aea12f
	       test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;	\
Packit aea12f
	hdr=`for f in $(_gl_TS_headers); do				\
Packit aea12f
	       test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`;	\
Packit aea12f
	( printf '%s\n' '__.*' $(_gl_TS_unmarked_extern_functions);	\
Packit aea12f
	  $(GREP) -h -A1 '^extern .*[^;]$$' $$src			\
Packit aea12f
	    | $(GREP) -vE '^(extern |--|#)' | $(SED) 's/ .*//; /^$$/d';	\
Packit aea12f
	  perl -lne							\
Packit aea12f
	     '$(_gl_TS_function_match) and print $$1' $$hdr;		\
Packit aea12f
	) | sort -u | $(SED) "$$sed_wrap" > $$t;			\
Packit aea12f
	nm -g $(_gl_TS_obj_files)|$(SED) -n 's/.* T //p'|$(GREP) -Ev -f $$t \
Packit aea12f
	  && { echo the above functions should have static scope >&2;	\
Packit aea12f
	       exit 1; } || : ;						\
Packit aea12f
	( printf '%s\n' '__.*' main $(_gl_TS_unmarked_extern_vars);	\
Packit aea12f
	  perl -lne '$(_gl_TS_var_match) and print $$1'			\
Packit aea12f
		$$hdr $(_gl_TS_other_headers)				\
Packit aea12f
	) | sort -u | $(SED) "$$sed_wrap" > $$t;			\
Packit aea12f
	nm -g $(_gl_TS_obj_files) | $(SED) -n 's/.* [BCDGRS] //p'	\
Packit aea12f
            | sort -u | $(GREP) -Ev -f $$t				\
Packit aea12f
	  && { echo the above variables should have static scope >&2;	\
Packit aea12f
	       exit 1; } || :
Packit aea12f
# TS-end
Packit aea12f
endif