Blame maint.mk

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