1# -*-Makefile-*- 2# This Makefile fragment tries to be general-purpose enough to be 3# used by many projects via the gnulib maintainer-makefile module. 4 5## Copyright (C) 2001-2021 Free Software Foundation, Inc. 6## 7## This program is free software: you can redistribute it and/or modify 8## it under the terms of the GNU General Public License as published by 9## the Free Software Foundation, either version 3 of the License, or 10## (at your option) any later version. 11## 12## This program is distributed in the hope that it will be useful, 13## but WITHOUT ANY WARRANTY; without even the implied warranty of 14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15## GNU General Public License for more details. 16## 17## You should have received a copy of the GNU General Public License 18## along with this program. If not, see <https://www.gnu.org/licenses/>. 19 20# This is reported not to work with make-3.79.1 21# ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) 22ME := maint.mk 23 24# These variables ought to be defined through the configure.ac section 25# of the module description. But some packages import this file directly, 26# ignoring the module description. 27AWK ?= awk 28GREP ?= grep 29SED ?= sed 30 31# Helper variables. 32_empty = 33_sp = $(_empty) $(_empty) 34 35# _equal,S1,S2 36# ------------ 37# If S1 == S2, return S1, otherwise the empty string. 38_equal = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) 39 40# member-check,VARIABLE,VALID-VALUES 41# ---------------------------------- 42# Check that $(VARIABLE) is in the space-separated list of VALID-VALUES, and 43# return it. Die otherwise. 44member-check = \ 45 $(strip \ 46 $(if $($(1)), \ 47 $(if $(findstring $(_sp),$($(1))), \ 48 $(error invalid $(1): '$($(1))', expected $(2)), \ 49 $(or $(findstring $(_sp)$($(1))$(_sp),$(_sp)$(2)$(_sp)), \ 50 $(error invalid $(1): '$($(1))', expected $(2)))), \ 51 $(error $(1) undefined))) 52 53# Do not save the original name or timestamp in the .tar.gz file. 54# Use --rsyncable if available. 55gzip_rsyncable := \ 56 $(shell gzip --help 2>/dev/null|$(GREP) rsyncable >/dev/null \ 57 && printf %s --rsyncable) 58GZIP_ENV = '--no-name --best $(gzip_rsyncable)' 59 60GIT = git 61VC = $(GIT) 62 63VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir) 64 65# You can override this variable in cfg.mk if your gnulib submodule lives 66# in a different location. 67gnulib_dir ?= $(shell if test -d $(srcdir)/gnulib; then \ 68 echo $(srcdir)/gnulib; \ 69 else \ 70 echo ${GNULIB_SRCDIR}; \ 71 fi) 72 73# You can override this variable in cfg.mk to set your own regexp 74# matching files to ignore. 75VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$ 76 77# This is to preprocess robustly the output of $(VC_LIST), so that even 78# when $(srcdir) is a pathological name like "....", the leading sed command 79# removes only the intended prefix. 80_dot_escaped_srcdir = $(subst .,\.,$(srcdir)) 81 82# Post-process $(VC_LIST) output, prepending $(srcdir)/, but only 83# when $(srcdir) is not ".". 84ifeq ($(srcdir),.) 85 _prepend_srcdir_prefix = 86else 87 _prepend_srcdir_prefix = | $(SED) 's|^|$(srcdir)/|' 88endif 89 90# In order to be able to consistently filter "."-relative names, 91# (i.e., with no $(srcdir) prefix), this definition is careful to 92# remove any $(srcdir) prefix, and to restore what it removes. 93_sc_excl = \ 94 $(or $(exclude_file_name_regexp--$@),^$$) 95VC_LIST_EXCEPT = \ 96 $(VC_LIST) | $(SED) 's|^$(_dot_escaped_srcdir)/||' \ 97 | if test -f $(srcdir)/.x-$@; then $(GREP) -vEf $(srcdir)/.x-$@; \ 98 else $(GREP) -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \ 99 | $(GREP) -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \ 100 $(_prepend_srcdir_prefix) 101 102ifeq ($(origin prev_version_file), undefined) 103 prev_version_file = $(srcdir)/.prev-version 104endif 105 106PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null) 107VERSION_REGEXP = $(subst .,\.,$(VERSION)) 108PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION)) 109 110ifeq ($(VC),$(GIT)) 111 this-vc-tag = v$(VERSION) 112 this-vc-tag-regexp = v$(VERSION_REGEXP) 113else 114 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]') 115 tag-this-version = $(subst .,_,$(VERSION)) 116 this-vc-tag = $(tag-package)-$(tag-this-version) 117 this-vc-tag-regexp = $(this-vc-tag) 118endif 119my_distdir = $(PACKAGE)-$(VERSION) 120 121# Old releases are stored here. 122release_archive_dir ?= ../release 123 124# If RELEASE_TYPE is undefined, but RELEASE is, use its second word. 125# But overwrite VERSION. 126ifdef RELEASE 127 VERSION := $(word 1, $(RELEASE)) 128 RELEASE_TYPE ?= $(word 2, $(RELEASE)) 129endif 130 131# Validate and return $(RELEASE_TYPE), or die. 132RELEASE_TYPES = alpha beta stable 133release-type = $(call member-check,RELEASE_TYPE,$(RELEASE_TYPES)) 134 135# Override gnu_rel_host and url_dir_list in cfg.mk if these are not right. 136# Use alpha.gnu.org for alpha and beta releases. 137# Use ftp.gnu.org for stable releases. 138gnu_ftp_host-alpha = alpha.gnu.org 139gnu_ftp_host-beta = alpha.gnu.org 140gnu_ftp_host-stable = ftp.gnu.org 141gnu_rel_host ?= $(gnu_ftp_host-$(release-type)) 142 143url_dir_list ?= $(if $(call _equal,$(gnu_rel_host),ftp.gnu.org), \ 144 https://ftpmirror.gnu.org/$(PACKAGE), \ 145 https://$(gnu_rel_host)/gnu/$(PACKAGE)) 146 147# Override this in cfg.mk if you are using a different format in your 148# NEWS file. 149today = $(shell date +%Y-%m-%d) 150 151# Select which lines of NEWS are searched for $(news-check-regexp). 152# This is a sed line number spec. The default says that we search 153# lines 1..10 of NEWS for $(news-check-regexp). 154# If you want to search only line 3 or only lines 20-22, use "3" or "20,22". 155news-check-lines-spec ?= 1,10 156news-check-regexp ?= '^\*.* $(VERSION_REGEXP) \($(today)\)' 157 158# Prevent programs like 'sort' from considering distinct strings to be equal. 159# Doing it here saves us from having to set LC_ALL elsewhere in this file. 160export LC_ALL = C 161 162## --------------- ## 163## Sanity checks. ## 164## --------------- ## 165 166ifneq ($(_gl-Makefile),) 167_cfg_mk := $(wildcard $(srcdir)/cfg.mk) 168 169# Collect the names of rules starting with 'sc_'. 170syntax-check-rules := $(sort $(shell env LC_ALL=C $(SED) -n \ 171 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(srcdir)/$(ME) $(_cfg_mk))) 172.PHONY: $(syntax-check-rules) 173 174ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0) 175 local-checks-available += $(syntax-check-rules) 176else 177 local-checks-available += no-vc-detected 178no-vc-detected: 179 @echo "No version control files detected; skipping syntax check" 180endif 181.PHONY: $(local-checks-available) 182 183# Arrange to print the name of each syntax-checking rule just before running it. 184$(syntax-check-rules): %: %.m 185sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules)) 186.PHONY: $(sc_m_rules_) 187$(sc_m_rules_): 188 @echo $(patsubst sc_%.m, %, $@) 189 @date +%s.%N > .sc-start-$(basename $@) 190 191# Compute and print the elapsed time for each syntax-check rule. 192sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules)) 193.PHONY: $(sc_z_rules_) 194$(sc_z_rules_): %.z: % 195 @end=$$(date +%s.%N); \ 196 start=$$(cat .sc-start-$*); \ 197 rm -f .sc-start-$*; \ 198 $(AWK) -v s=$$start -v e=$$end \ 199 'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null 200 201# The patsubst here is to replace each sc_% rule with its sc_%.z wrapper 202# that computes and prints elapsed time. 203local-check := \ 204 $(patsubst sc_%, sc_%.z, \ 205 $(filter-out $(local-checks-to-skip), $(local-checks-available))) 206 207syntax-check: $(local-check) 208endif 209 210# _sc_search_regexp 211# 212# This macro searches for a given construct in the selected files and 213# then takes some action. 214# 215# Parameters (shell variables): 216# 217# prohibit | require 218# 219# Regular expression (ERE) denoting either a forbidden construct 220# or a required construct. Those arguments are exclusive. 221# 222# exclude 223# 224# Regular expression (ERE) denoting lines to ignore that matched 225# a prohibit construct. For example, this can be used to exclude 226# comments that mention why the nearby code uses an alternative 227# construct instead of the simpler prohibited construct. 228# 229# in_vc_files | in_files 230# 231# grep-E-style regexp selecting the files to check. For in_vc_files, 232# the regexp is used to select matching files from the list of all 233# version-controlled files; for in_files, it's from the names printed 234# by "find $(srcdir)". When neither is specified, use all files that 235# are under version control. 236# 237# containing | non_containing 238# 239# Select the files (non) containing strings matching this regexp. 240# If both arguments are specified then CONTAINING takes 241# precedence. 242# 243# with_grep_options 244# 245# Extra options for grep. 246# 247# ignore_case 248# 249# Ignore case. 250# 251# halt 252# 253# Message to display before to halting execution. 254# 255# Finally, you may exempt files based on an ERE matching file names. 256# For example, to exempt from the sc_space_tab check all files with the 257# .diff suffix, set this Make variable: 258# 259# exclude_file_name_regexp--sc_space_tab = \.diff$ 260# 261# Note that while this functionality is mostly inherited via VC_LIST_EXCEPT, 262# when filtering by name via in_files, we explicitly filter out matching 263# names here as well. 264 265# Initialize each, so that envvar settings cannot interfere. 266export require = 267export prohibit = 268export exclude = 269export in_vc_files = 270export in_files = 271export containing = 272export non_containing = 273export halt = 274export with_grep_options = 275 276# By default, _sc_search_regexp does not ignore case. 277export ignore_case = 278_ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :) 279 280define _sc_say_and_exit 281 dummy=; : so we do not need a semicolon before each use; \ 282 { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; }; 283endef 284 285define _sc_search_regexp 286 dummy=; : so we do not need a semicolon before each use; \ 287 \ 288 : Check arguments; \ 289 test -n "$$prohibit" && test -n "$$require" \ 290 && { msg='Cannot specify both prohibit and require' \ 291 $(_sc_say_and_exit) } || :; \ 292 test -z "$$prohibit" && test -z "$$require" \ 293 && { msg='Should specify either prohibit or require' \ 294 $(_sc_say_and_exit) } || :; \ 295 test -z "$$prohibit" && test -n "$$exclude" \ 296 && { msg='Use of exclude requires a prohibit pattern' \ 297 $(_sc_say_and_exit) } || :; \ 298 test -n "$$in_vc_files" && test -n "$$in_files" \ 299 && { msg='Cannot specify both in_vc_files and in_files' \ 300 $(_sc_say_and_exit) } || :; \ 301 test "x$$halt" != x \ 302 || { msg='halt not defined' $(_sc_say_and_exit) }; \ 303 \ 304 : Filter by file name; \ 305 if test -n "$$in_files"; then \ 306 files=$$(find $(srcdir) | $(GREP) -E "$$in_files" \ 307 | $(GREP) -Ev '$(_sc_excl)'); \ 308 else \ 309 files=$$($(VC_LIST_EXCEPT)); \ 310 if test -n "$$in_vc_files"; then \ 311 files=$$(echo "$$files" | $(GREP) -E "$$in_vc_files"); \ 312 fi; \ 313 fi; \ 314 \ 315 : Filter by content; \ 316 test -n "$$files" \ 317 && test -n "$$containing" \ 318 && { files=$$(echo "$$files" | xargs $(GREP) -l "$$containing"); } \ 319 || :; \ 320 test -n "$$files" \ 321 && test -n "$$non_containing" \ 322 && { files=$$(echo "$$files" | xargs $(GREP) -vl "$$non_containing"); } \ 323 || :; \ 324 \ 325 : Check for the construct; \ 326 if test -n "$$files"; then \ 327 if test -n "$$prohibit"; then \ 328 echo "$$files" \ 329 | xargs $(GREP) $$with_grep_options $(_ignore_case) -nE \ 330 "$$prohibit" /dev/null \ 331 | $(GREP) -vE "$${exclude:-^$$}" \ 332 && { msg="$$halt" $(_sc_say_and_exit) } \ 333 || :; \ 334 else \ 335 echo "$$files" \ 336 | xargs \ 337 $(GREP) $$with_grep_options $(_ignore_case) -LE "$$require" \ 338 | $(GREP) . \ 339 && { msg="$$halt" $(_sc_say_and_exit) } \ 340 || :; \ 341 fi \ 342 else :; \ 343 fi || :; 344endef 345 346sc_avoid_if_before_free: 347 @$(VC_LIST_EXCEPT) \ 348 | $(GREP) -v useless-if-before-free \ 349 | xargs \ 350 $(srcdir)/$(_build-aux)/useless-if-before-free \ 351 $(useless_free_options) \ 352 && { printf '$(ME): found useless "if"' \ 353 ' before "free" above\n' 1>&2; \ 354 exit 1; } \ 355 || : 356 357sc_cast_of_argument_to_free: 358 @prohibit='\<free *\( *\(' halt="don't cast free argument" \ 359 $(_sc_search_regexp) 360 361sc_cast_of_x_alloc_return_value: 362 @prohibit='\*\) *x(m|c|re)alloc\>' \ 363 halt="don't cast x*alloc return value" \ 364 $(_sc_search_regexp) 365 366sc_cast_of_alloca_return_value: 367 @prohibit='\*\) *alloca\>' \ 368 halt="don't cast alloca return value" \ 369 $(_sc_search_regexp) 370 371sc_space_tab: 372 @prohibit='[ ] ' \ 373 halt='found SPACE-TAB sequence; remove the SPACE' \ 374 $(_sc_search_regexp) 375 376# Don't use *scanf or the old ato* functions in "real" code. 377# They provide no error checking mechanism. 378# Instead, use strto* functions. 379sc_prohibit_atoi_atof: 380 @prohibit='\<([fs]?scanf|ato([filq]|ll)) *\(' \ 381 halt='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \ 382 $(_sc_search_regexp) 383 384# Use STREQ rather than comparing strcmp == 0, or != 0. 385sp_ = strcmp *\(.+\) 386sc_prohibit_strcmp: 387 @prohibit='! *strcmp *\(|\<$(sp_) *[!=]=|[!=]= *$(sp_)' \ 388 exclude='# *define STRN?EQ\(' \ 389 halt='replace strcmp calls above with STREQ/STRNEQ' \ 390 $(_sc_search_regexp) 391 392# Really. You don't want to use this function. 393# It may fail to NUL-terminate the destination, 394# and always NUL-pads out to the specified length. 395sc_prohibit_strncpy: 396 @prohibit='\<strncpy *\(' \ 397 halt='do not use strncpy, period' \ 398 $(_sc_search_regexp) 399 400# Pass EXIT_*, not number, to usage, exit, and error (when exiting) 401# Convert all uses automatically, via these two commands: 402# git grep -l '\<exit *(1)' \ 403# | grep -vEf .x-sc_prohibit_magic_number_exit \ 404# | xargs --no-run-if-empty \ 405# perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/' 406# git grep -l '\<exit *(0)' \ 407# | grep -vEf .x-sc_prohibit_magic_number_exit \ 408# | xargs --no-run-if-empty \ 409# perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/' 410sc_prohibit_magic_number_exit: 411 @prohibit='(^|[^.])\<(usage|exit|error) ?\(-?[0-9]+[,)]' \ 412 exclude='exit \(77\)|error ?\(((0|77),|[^,]*)' \ 413 halt='use EXIT_* values rather than magic number' \ 414 $(_sc_search_regexp) 415 416# Check that we don't use $< in non-implicit Makefile rules. 417# 418# To find the Makefiles, trace AC_CONFIG_FILES. Using VC_LIST would 419# miss the Makefiles that are not under VC control (e.g., symlinks 420# installed for gettext). "Parsing" (recursive) uses of SUBDIRS seems 421# too delicate. 422# 423# Use GNU Make's --print-data-base to normalize the rules into some 424# easy to parse format: they are separated by two \n. Look for the 425# "section" about non-pattern rules (marked with "# Files") inside 426# which there are still the POSIX Make like implicit rules (".c.o"). 427sc_prohibit_gnu_make_extensions_awk_ = \ 428 BEGIN { \ 429 RS = "\n\n"; \ 430 in_rules = 0; \ 431 } \ 432 /^\# Files/ { \ 433 in_rules = 1; \ 434 } \ 435 /\$$</ && in_rules && $$0 !~ /^(.*\n)*\.\w+(\.\w+)?:/ { \ 436 print "Error: " file ": $$< in a non implicit rule\n" $$0; \ 437 status = 1; \ 438 } \ 439 END { \ 440 exit status; \ 441 } 442sc_prohibit_gnu_make_extensions: 443 @if $(AWK) --version | grep GNU >/dev/null 2>&1; then \ 444 (cd $(srcdir) && autoconf --trace AC_CONFIG_FILES:'$$1') | \ 445 tr ' ' '\n' | \ 446 $(SED) -ne '/Makefile/{s/\.in$$//;p;}' | \ 447 while read m; do \ 448 $(MAKE) -qp -f $$m .DUMMY-TARGET 2>/dev/null | \ 449 $(AWK) -v file=$$m -e '$($@_awk_)' || exit 1; \ 450 done; \ 451 fi 452 453# Using EXIT_SUCCESS as the first argument to error is misleading, 454# since when that parameter is 0, error does not exit. Use '0' instead. 455sc_error_exit_success: 456 @prohibit='error *\(EXIT_SUCCESS,' \ 457 in_vc_files='\.[chly]$$' \ 458 halt='found error (EXIT_SUCCESS' \ 459 $(_sc_search_regexp) 460 461# "FATAL:" should be fully upper-cased in error messages 462# "WARNING:" should be fully upper-cased, or fully lower-cased 463sc_error_message_warn_fatal: 464 @$(VC_LIST_EXCEPT) \ 465 | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null \ 466 | $(GREP) -E '"Warning|"Fatal|"fatal' \ 467 && { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \ 468 exit 1; } \ 469 || : 470 471# Error messages should not start with a capital letter 472sc_error_message_uppercase: 473 @$(VC_LIST_EXCEPT) \ 474 | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null \ 475 | $(GREP) -E '"[A-Z]' \ 476 | $(GREP) -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX' \ 477 && { echo '$(ME): found capitalized error message' 1>&2; \ 478 exit 1; } \ 479 || : 480 481# Error messages should not end with a period 482sc_error_message_period: 483 @$(VC_LIST_EXCEPT) \ 484 | xargs $(GREP) -nEA2 '[^rp]error *\(' /dev/null \ 485 | $(GREP) -E '[^."]\."' \ 486 && { echo '$(ME): found error message ending in period' 1>&2; \ 487 exit 1; } \ 488 || : 489 490sc_file_system: 491 @prohibit=file''system \ 492 exclude='/proc/filesystems' \ 493 ignore_case=1 \ 494 halt='found use of "file''system"; spell it "file system"' \ 495 $(_sc_search_regexp) 496 497# Don't use cpp tests of this symbol. All code assumes config.h is included. 498sc_prohibit_have_config_h: 499 @prohibit='^# *if.*HAVE''_CONFIG_H' \ 500 halt='found use of HAVE''_CONFIG_H; remove' \ 501 $(_sc_search_regexp) 502 503# Nearly all .c files must include <config.h>. However, we also permit this 504# via inclusion of a package-specific header, if cfg.mk specified one. 505# config_h_header must be suitable for grep -E. 506config_h_header ?= <config\.h> 507sc_require_config_h: 508 @require='^# *include $(config_h_header)' \ 509 in_vc_files='\.c$$' \ 510 halt='the above files do not include <config.h>' \ 511 $(_sc_search_regexp) 512 513# Print each file name for which the first #include does not match 514# $(config_h_header). Like grep -m 1, this only looks at the first match. 515perl_config_h_first_ = \ 516 -e 'BEGIN {$$ret = 0}' \ 517 -e 'if (/^\# *include\b/) {' \ 518 -e ' if (not m{^\# *include $(config_h_header)}) {' \ 519 -e ' print "$$ARGV\n";' \ 520 -e ' $$ret = 1;' \ 521 -e ' }' \ 522 -e ' \# Move on to next file after first include' \ 523 -e ' close ARGV;' \ 524 -e '}' \ 525 -e 'END {exit $$ret}' 526 527# You must include <config.h> before including any other header file. 528# This can possibly be via a package-specific header, if given by cfg.mk. 529sc_require_config_h_first: 530 @if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \ 531 files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') && \ 532 perl -n $(perl_config_h_first_) $$files || \ 533 { echo '$(ME): the above files include some other header' \ 534 'before <config.h>' 1>&2; exit 1; } || :; \ 535 else :; \ 536 fi 537 538sc_prohibit_HAVE_MBRTOWC: 539 @prohibit='\bHAVE_MBRTOWC\b' \ 540 halt="do not use $$prohibit; it is always defined" \ 541 $(_sc_search_regexp) 542 543# To use this "command" macro, you must first define two shell variables: 544# h: the header name, with no enclosing <> or "" 545# re: a regular expression that matches IFF something provided by $h is used. 546define _sc_header_without_use 547 dummy=; : so we do not need a semicolon before each use; \ 548 h_esc=`echo '[<"]'"$$h"'[">]'|$(SED) 's/\./\\\\./g'`; \ 549 if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \ 550 files=$$($(GREP) -l '^# *include '"$$h_esc" \ 551 $$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$')) && \ 552 $(GREP) -LE "$$re" $$files | $(GREP) . && \ 553 { echo "$(ME): the above files include $$h but don't use it" \ 554 1>&2; exit 1; } || :; \ 555 else :; \ 556 fi 557endef 558 559# Prohibit the inclusion of assert.h without an actual use of assert. 560sc_prohibit_assert_without_use: 561 @h='assert.h' re='\<assert *\(' $(_sc_header_without_use) 562 563# Prohibit the inclusion of close-stream.h without an actual use. 564sc_prohibit_close_stream_without_use: 565 @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use) 566 567# Prohibit the inclusion of getopt.h without an actual use. 568sc_prohibit_getopt_without_use: 569 @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use) 570 571# Don't include quotearg.h unless you use one of its functions. 572sc_prohibit_quotearg_without_use: 573 @h='quotearg.h' re='\<quotearg(_[^ ]+)? *\(' $(_sc_header_without_use) 574 575# Don't include quote.h unless you use one of its functions. 576sc_prohibit_quote_without_use: 577 @h='quote.h' re='\<quote((_n)? *\(|_quoting_options\>)' \ 578 $(_sc_header_without_use) 579 580# Don't include this header unless you use one of its functions. 581sc_prohibit_long_options_without_use: 582 @h='long-options.h' re='\<parse_(long_options|gnu_standard_options_only) *\(' \ 583 $(_sc_header_without_use) 584 585# Don't include this header unless you use one of its functions. 586sc_prohibit_inttostr_without_use: 587 @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \ 588 $(_sc_header_without_use) 589 590# Don't include this header unless you use one of its functions. 591sc_prohibit_ignore_value_without_use: 592 @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \ 593 $(_sc_header_without_use) 594 595# Don't include this header unless you use one of its functions. 596sc_prohibit_error_without_use: 597 @h='error.h' \ 598 re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\ 599 $(_sc_header_without_use) 600 601# Don't include xalloc.h unless you use one of its functions. 602# Consider these symbols: 603# perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__'; 604# perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h 605# Divide into two sets on case, and filter each through this: 606# | sort | perl -MRegexp::Assemble -le \ 607# 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g' 608# Note this was produced by the above: 609# _xa1 = \ 610#x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup) 611# But we can do better, in at least two ways: 612# 1) take advantage of two "dup"-suffixed strings: 613# x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup) 614# 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable 615# "char|[cmz]" 616# x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup) 617_xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup) 618_xa2 = X([CZ]|N?M)ALLOC 619sc_prohibit_xalloc_without_use: 620 @h='xalloc.h' \ 621 re='\<($(_xa1)|$(_xa2)) *\('\ 622 $(_sc_header_without_use) 623 624# Extract function names: 625# perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/hash.h 626_hash_re = \ 627clear|delete|free|get_(first|next)|insert|lookup|print_statistics|reset_tuning 628_hash_fn = \<($(_hash_re)) *\( 629_hash_struct = (struct )?\<[Hh]ash_(table|tuning)\> 630sc_prohibit_hash_without_use: 631 @h='hash.h' \ 632 re='$(_hash_fn)|$(_hash_struct)'\ 633 $(_sc_header_without_use) 634 635sc_prohibit_cloexec_without_use: 636 @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \ 637 $(_sc_header_without_use) 638 639sc_prohibit_posixver_without_use: 640 @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use) 641 642sc_prohibit_same_without_use: 643 @h='same.h' re='\<same_name(at)? *\(' $(_sc_header_without_use) 644 645sc_prohibit_hash_pjw_without_use: 646 @h='hash-pjw.h' \ 647 re='\<hash_pjw\>' \ 648 $(_sc_header_without_use) 649 650sc_prohibit_safe_read_without_use: 651 @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \ 652 $(_sc_header_without_use) 653 654sc_prohibit_argmatch_without_use: 655 @h='argmatch.h' \ 656 re='(\<(ARGMATCH_DEFINE_GROUP|ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \ 657 $(_sc_header_without_use) 658 659sc_prohibit_canonicalize_without_use: 660 @h='canonicalize.h' \ 661 re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode|file_name)' \ 662 $(_sc_header_without_use) 663 664sc_prohibit_root_dev_ino_without_use: 665 @h='root-dev-ino.h' \ 666 re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \ 667 $(_sc_header_without_use) 668 669sc_prohibit_openat_without_use: 670 @h='openat.h' \ 671 re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat|(FCHMOD|FCHOWN|STAT)AT_INLINE)\>' \ 672 $(_sc_header_without_use) 673 674# Prohibit the inclusion of c-ctype.h without an actual use. 675ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\ 676|isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper 677sc_prohibit_c_ctype_without_use: 678 @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \ 679 $(_sc_header_without_use) 680 681# The following list was generated by running: 682# man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \ 683# | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt 684_sig_functions = \ 685 bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \ 686 sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \ 687 siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \ 688 sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo 689_sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions))) 690# The following were extracted from "man signal.h" manually. 691_sig_types_and_consts = \ 692 MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \ 693 SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \ 694 SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \ 695 SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \ 696 sigstack sigval stack_t ucontext_t 697# generated via this: 698# perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70 699_sig_names = \ 700 SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \ 701 SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \ 702 SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \ 703 SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \ 704 SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \ 705 SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \ 706 SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \ 707 SIGXCPU SIGXFSZ 708_sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts))) 709 710# Prohibit the inclusion of signal.h without an actual use. 711sc_prohibit_signal_without_use: 712 @h='signal.h' \ 713 re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \ 714 $(_sc_header_without_use) 715 716# Don't include stdio--.h unless you use one of its functions. 717sc_prohibit_stdio--_without_use: 718 @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\(' \ 719 $(_sc_header_without_use) 720 721# Don't include stdio-safer.h unless you use one of its functions. 722sc_prohibit_stdio-safer_without_use: 723 @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\(' \ 724 $(_sc_header_without_use) 725 726# Prohibit the inclusion of strings.h without a sensible use. 727# Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible. 728sc_prohibit_strings_without_use: 729 @h='strings.h' \ 730 re='\<(strn?casecmp|ffs(ll)?)\>' \ 731 $(_sc_header_without_use) 732 733# Extract the raw list of symbol names with this: 734gl_extract_define_simple = \ 735 /^\# *define ([A-Z]\w+)\(/ and print $$1 736# Filter out duplicates and convert to a space-separated list: 737_intprops_names = \ 738 $(shell f=$(gnulib_dir)/lib/intprops.h; \ 739 perl -lne '$(gl_extract_define_simple)' $$f | sort -u | tr '\n' ' ') 740# Remove trailing space and convert to a regular expression: 741_intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names))) 742# Prohibit the inclusion of intprops.h without an actual use. 743sc_prohibit_intprops_without_use: 744 @h='intprops.h' \ 745 re='\<($(_intprops_syms_re)) *\(' \ 746 $(_sc_header_without_use) 747 748_stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t 749# Prohibit the inclusion of stddef.h without an actual use. 750sc_prohibit_stddef_without_use: 751 @h='stddef.h' \ 752 re='\<($(_stddef_syms_re))\>' \ 753 $(_sc_header_without_use) 754 755_de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)? 756_de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)? 757_de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen 758_dirent_syms_re = $(_de1)|$(_de2)|$(_de3) 759# Prohibit the inclusion of dirent.h without an actual use. 760sc_prohibit_dirent_without_use: 761 @h='dirent.h' \ 762 re='\<($(_dirent_syms_re))\>' \ 763 $(_sc_header_without_use) 764 765# Prohibit the inclusion of verify.h without an actual use. 766sc_prohibit_verify_without_use: 767 @h='verify.h' \ 768 re='\<(verify(true|expr)?|assume|static_assert) *\(' \ 769 $(_sc_header_without_use) 770 771# Don't include xfreopen.h unless you use one of its functions. 772sc_prohibit_xfreopen_without_use: 773 @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use) 774 775sc_obsolete_symbols: 776 @prohibit='\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \ 777 halt='do not use HAVE''_FCNTL_H or O'_NDELAY \ 778 $(_sc_search_regexp) 779 780# FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ 781 782# Each nonempty ChangeLog line must start with a year number, or a TAB. 783sc_changelog: 784 @prohibit='^[^12 ]' \ 785 in_vc_files='^ChangeLog$$' \ 786 halt='found unexpected prefix in a ChangeLog' \ 787 $(_sc_search_regexp) 788 789# Ensure that each .c file containing a "main" function also 790# calls bindtextdomain. 791sc_bindtextdomain: 792 @require='bindtextdomain *\(' \ 793 in_vc_files='\.c$$' \ 794 containing='\<main *(' \ 795 halt='the above files do not call bindtextdomain' \ 796 $(_sc_search_regexp) 797 798# Require that the final line of each test-lib.sh-using test be this one: 799# Exit $fail 800# Note: this test requires GNU grep's --label= option. 801Exit_witness_file ?= tests/test-lib.sh 802Exit_base := $(notdir $(Exit_witness_file)) 803sc_require_test_exit_idiom: 804 @if test -f $(srcdir)/$(Exit_witness_file); then \ 805 die=0; \ 806 for i in $$($(GREP) -l -F 'srcdir/$(Exit_base)' \ 807 $$($(VC_LIST) tests)); do \ 808 tail -n1 $$i | $(GREP) '^Exit .' > /dev/null \ 809 && : || { die=1; echo $$i; } \ 810 done; \ 811 test $$die = 1 && \ 812 { echo 1>&2 '$(ME): the final line in each of the above is not:'; \ 813 echo 1>&2 'Exit something'; \ 814 exit 1; } || :; \ 815 fi 816 817sc_trailing_blank: 818 @prohibit='[ ]$$' \ 819 halt='found trailing blank(s)' \ 820 exclude='^Binary file .* matches$$' \ 821 $(_sc_search_regexp) 822 823# Match lines like the following, but where there is only one space 824# between the options and the description: 825# -D, --all-repeated[=delimit-method] print all duplicate lines\n 826longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)? 827sc_two_space_separator_in_usage: 828 @prohibit='^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \ 829 halt='help2man requires at least two spaces between an option and its description'\ 830 $(_sc_search_regexp) 831 832# A regexp matching function names like "error" that may be used 833# to emit translatable messages. 834_gl_translatable_diag_func_re ?= error 835 836# Look for diagnostics that aren't marked for translation. 837# This won't find any for which error's format string is on a separate line. 838sc_unmarked_diagnostics: 839 @prohibit='\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \ 840 exclude='(_|ngettext ?)\(' \ 841 halt='found unmarked diagnostic(s)' \ 842 $(_sc_search_regexp) 843 844# Avoid useless parentheses like those in this example: 845# #if defined (SYMBOL) || defined (SYM2) 846sc_useless_cpp_parens: 847 @prohibit='^# *if .*defined *\(' \ 848 halt='found useless parentheses in cpp directive' \ 849 $(_sc_search_regexp) 850 851# List headers for which HAVE_HEADER_H is always true, assuming you are 852# using the appropriate gnulib module. CAUTION: for each "unnecessary" 853# #if HAVE_HEADER_H that you remove, be sure that your project explicitly 854# requires the gnulib module that guarantees the usability of that header. 855gl_assured_headers_ = \ 856 cd $(gnulib_dir)/lib && echo *.in.h|$(SED) 's/\.in\.h//g' 857 858# Convert the list of names to upper case, and replace each space with "|". 859az_ = abcdefghijklmnopqrstuvwxyz 860AZ_ = ABCDEFGHIJKLMNOPQRSTUVWXYZ 861gl_header_upper_case_or_ = \ 862 $$($(gl_assured_headers_) \ 863 | tr $(az_)/.- $(AZ_)___ \ 864 | tr -s ' ' '|' \ 865 ) 866sc_prohibit_always_true_header_tests: 867 @or=$(gl_header_upper_case_or_); \ 868 re="HAVE_($$or)_H"; \ 869 prohibit='\<'"$$re"'\>' \ 870 halt=$$(printf '%s\n' \ 871 'do not test the above HAVE_<header>_H symbol(s);' \ 872 ' with the corresponding gnulib module, they are always true') \ 873 $(_sc_search_regexp) 874 875sc_prohibit_defined_have_decl_tests: 876 @prohibit='(#[ ]*ifn?def|\<defined)\>[ (]+HAVE_DECL_' \ 877 halt='HAVE_DECL macros are always defined' \ 878 $(_sc_search_regexp) 879 880# ================================================================== 881gl_other_headers_ ?= \ 882 intprops.h \ 883 openat.h \ 884 stat-macros.h 885 886# Perl -lne code to extract "significant" cpp-defined symbols from a 887# gnulib header file, eliminating a few common false-positives. 888# The exempted names below are defined only conditionally in gnulib, 889# and hence sometimes must/may be defined in application code. 890gl_extract_significant_defines_ = \ 891 /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\ 892 && $$2 !~ /(?:rpl_|_used_without_)/\ 893 && $$1 !~ /^(?:NSIG|ENODATA)$$/\ 894 && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\ 895 and print $$1 896 897# Create a list of regular expressions matching the names 898# of macros that are guaranteed to be defined by parts of gnulib. 899define def_sym_regex 900 gen_h=$(gl_generated_headers_); \ 901 (cd $(gnulib_dir)/lib; \ 902 for f in *.in.h $(gl_other_headers_); do \ 903 test -f $$f \ 904 && perl -lne '$(gl_extract_significant_defines_)' $$f; \ 905 done; \ 906 ) | sort -u \ 907 | $(SED) 's/^/^ *# *(define|undef) */;s/$$/\\>/' 908endef 909 910# Don't define macros that we already get from gnulib header files. 911sc_prohibit_always-defined_macros: 912 @if test -d $(gnulib_dir); then \ 913 case $$(echo all: | $(GREP) -l -f - Makefile) in Makefile);; *) \ 914 echo '$(ME): skipping $@: you lack GNU grep' 1>&2; exit 0;; \ 915 esac; \ 916 regex=$$($(def_sym_regex)); export regex; \ 917 $(VC_LIST_EXCEPT) \ 918 | xargs sh -c 'echo $$regex | $(GREP) -E -f - "$$@"' \ 919 dummy /dev/null \ 920 && { printf '$(ME): define the above' \ 921 ' via some gnulib .h file\n' 1>&2; \ 922 exit 1; } \ 923 || :; \ 924 fi 925# ================================================================== 926 927# Prohibit checked in backup files. 928sc_prohibit_backup_files: 929 @$(VC_LIST) | $(GREP) '~$$' && \ 930 { echo '$(ME): found version controlled backup file' 1>&2; \ 931 exit 1; } || : 932 933# Require the latest GPL. 934sc_GPL_version: 935 @prohibit='either ''version [^3]' \ 936 halt='GPL vN, N!=3' \ 937 $(_sc_search_regexp) 938 939# Require the latest GFDL. Two regexp, since some .texi files end up 940# line wrapping between 'Free Documentation License,' and 'Version'. 941_GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any) 942sc_GFDL_version: 943 @prohibit='$(_GFDL_regexp)' \ 944 halt='GFDL vN, N!=3' \ 945 $(_sc_search_regexp) 946 947# Don't use Texinfo's @acronym{}. 948# https://lists.gnu.org/r/bug-gnulib/2010-03/msg00321.html 949texinfo_suffix_re_ ?= \.(txi|texi(nfo)?)$$ 950sc_texinfo_acronym: 951 @prohibit='@acronym\{' \ 952 in_vc_files='$(texinfo_suffix_re_)' \ 953 halt='found use of Texinfo @acronym{}' \ 954 $(_sc_search_regexp) 955 956cvs_keywords = \ 957 Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State 958 959sc_prohibit_cvs_keyword: 960 @prohibit='\$$($(cvs_keywords))\$$' \ 961 halt='do not use CVS keyword expansion' \ 962 $(_sc_search_regexp) 963 964# This Perl code is slightly obfuscated. Not only is each "$" doubled 965# because it's in a Makefile, but the $$c's are comments; we cannot 966# use "#" due to the way the script ends up concatenated onto one line. 967# It would be much more concise, and would produce better output (including 968# counts) if written as: 969# perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ... 970# but that would be far less efficient, reading the entire contents 971# of each file, rather than just the last two bytes of each. 972# In addition, while the code below detects both blank lines and a missing 973# newline at EOF, the above detects only the former. 974# 975# This is a perl script that is expected to be the single-quoted argument 976# to a command-line "-le". The remaining arguments are file names. 977# Print the name of each file that does not end in exactly one newline byte. 978# I.e., warn if there are blank lines (2 or more newlines), or if the 979# last byte is not a newline. However, currently we don't complain 980# about any file that contains exactly one byte. 981# Exit nonzero if at least one such file is found, otherwise, exit 0. 982# Warn about, but otherwise ignore open failure. Ignore seek/read failure. 983# 984# Use this if you want to remove trailing empty lines from selected files: 985# perl -pi -0777 -e 's/\n\n+$/\n/' files... 986# 987require_exactly_one_NL_at_EOF_ = \ 988 foreach my $$f (@ARGV) \ 989 { \ 990 open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next; \ 991 my $$p = sysseek (F, -2, 2); \ 992 my $$c = "seek failure probably means file has < 2 bytes; ignore"; \ 993 my $$last_two_bytes; \ 994 defined $$p and $$p = sysread F, $$last_two_bytes, 2; \ 995 close F; \ 996 $$c = "ignore read failure"; \ 997 $$p && ($$last_two_bytes eq "\n\n" \ 998 || substr ($$last_two_bytes,1) ne "\n") \ 999 and (print $$f), $$fail=1; \ 1000 } \ 1001 END { exit defined $$fail } 1002sc_prohibit_empty_lines_at_EOF: 1003 @$(VC_LIST_EXCEPT) \ 1004 | xargs perl -le '$(require_exactly_one_NL_at_EOF_)' \ 1005 || { echo '$(ME): empty line(s) or no newline at EOF' 1>&2; \ 1006 exit 1; } \ 1007 || : 1008 1009# Make sure we don't use st_blocks. Use ST_NBLOCKS instead. 1010# This is a bit of a kludge, since it prevents use of the string 1011# even in comments, but for now it does the job with no false positives. 1012sc_prohibit_stat_st_blocks: 1013 @prohibit='[.>]st_blocks' \ 1014 halt='do not use st_blocks; use ST_NBLOCKS' \ 1015 $(_sc_search_regexp) 1016 1017# Make sure we don't define any S_IS* macros in src/*.c files. 1018# They're already defined via gnulib's sys/stat.h replacement. 1019sc_prohibit_S_IS_definition: 1020 @prohibit='^ *# *define *S_IS' \ 1021 halt='do not define S_IS* macros; include <sys/stat.h>' \ 1022 $(_sc_search_regexp) 1023 1024# Perl block to convert a match to FILE_NAME:LINENO:TEST, 1025# that is shared by two definitions below. 1026perl_filename_lineno_text_ = \ 1027 -e ' {' \ 1028 -e ' $$n = ($$` =~ tr/\n/\n/ + 1);' \ 1029 -e ' ($$v = $$&) =~ s/\n/\\n/g;' \ 1030 -e ' print "$$ARGV:$$n:$$v\n";' \ 1031 -e ' }' 1032 1033prohibit_doubled_words_ = \ 1034 the then in an on if is it but for or at and do to 1035# expand the regex before running the check to avoid using expensive captures 1036prohibit_doubled_word_expanded_ = \ 1037 $(join $(prohibit_doubled_words_),$(addprefix \s+,$(prohibit_doubled_words_))) 1038prohibit_doubled_word_RE_ ?= \ 1039 /\b(?:$(subst $(_sp),|,$(prohibit_doubled_word_expanded_)))\b/gims 1040prohibit_doubled_word_ = \ 1041 -e 'while ($(prohibit_doubled_word_RE_))' \ 1042 $(perl_filename_lineno_text_) 1043 1044# Define this to a regular expression that matches 1045# any filename:dd:match lines you want to ignore. 1046# The default is to ignore no matches. 1047ignore_doubled_word_match_RE_ ?= ^$$ 1048 1049sc_prohibit_doubled_word: 1050 @$(VC_LIST_EXCEPT) \ 1051 | xargs perl -n -0777 $(prohibit_doubled_word_) \ 1052 | $(GREP) -vE '$(ignore_doubled_word_match_RE_)' \ 1053 | $(GREP) . \ 1054 && { echo '$(ME): doubled words' 1>&2; exit 1; } \ 1055 || : 1056 1057# A regular expression matching undesirable combinations of words like 1058# "can not"; this matches them even when the two words appear on different 1059# lines, but not when there is an intervening delimiter like "#" or "*". 1060# Similarly undesirable, "See @xref{...}", since an @xref should start 1061# a sentence. Explicitly prohibit any prefix of "see" or "also". 1062# Also prohibit a prefix matching "\w+ +". 1063# @pxref gets the same see/also treatment and should be parenthesized; 1064# presume it must *not* start a sentence. 1065# POSIX spells it "timestamp" rather than "time\s+stamp", so we do, too. 1066bad_xref_re_ ?= (?:[\w,:;] +|(?:see|also)\s+)\@xref\{ 1067bad_pxref_re_ ?= (?:[.!?]|(?:see|also))\s+\@pxref\{ 1068prohibit_undesirable_word_seq_RE_ ?= \ 1069 /(?:\bcan\s+not\b|\btime\s+stamps?\b|$(bad_xref_re_)|$(bad_pxref_re_))/gims 1070prohibit_undesirable_word_seq_ = \ 1071 -e 'while ($(prohibit_undesirable_word_seq_RE_))' \ 1072 $(perl_filename_lineno_text_) 1073# Define this to a regular expression that matches 1074# any filename:dd:match lines you want to ignore. 1075# The default is to ignore no matches. 1076ignore_undesirable_word_sequence_RE_ ?= ^$$ 1077 1078sc_prohibit_undesirable_word_seq: 1079 @$(VC_LIST_EXCEPT) \ 1080 | xargs perl -n -0777 $(prohibit_undesirable_word_seq_) \ 1081 | $(GREP) -vE '$(ignore_undesirable_word_sequence_RE_)' \ 1082 | $(GREP) . \ 1083 && { echo '$(ME): undesirable word sequence' >&2; exit 1; } \ 1084 || : 1085 1086# Except for shell files and for loops, double semicolon is probably a mistake 1087sc_prohibit_double_semicolon: 1088 @prohibit='; *;[ {} \]*(/[/*]|$$)' \ 1089 in_vc_files='\.[chly]$$' \ 1090 exclude='\bfor *\(.*\)' \ 1091 halt="Double semicolon detected" \ 1092 $(_sc_search_regexp) 1093 1094_ptm1 = use "test C1 && test C2", not "test C1 -''a C2" 1095_ptm2 = use "test C1 || test C2", not "test C1 -''o C2" 1096# Using test's -a and -o operators is not portable. 1097# We prefer test over [, since the latter is spelled [[ in configure.ac. 1098sc_prohibit_test_minus_ao: 1099 @prohibit='(\<test| \[+) .+ -[ao] ' \ 1100 halt='$(_ptm1); $(_ptm2)' \ 1101 $(_sc_search_regexp) 1102 1103# Avoid a test bashism. 1104sc_prohibit_test_double_equal: 1105 @prohibit='(\<test| \[+) .+ == ' \ 1106 containing='#! */bin/[a-z]*sh' \ 1107 halt='use "test x = x", not "test x =''= x"' \ 1108 $(_sc_search_regexp) 1109 1110# Each program that uses proper_name_utf8 must link with one of the 1111# ICONV libraries. Otherwise, some ICONV library must appear in LDADD. 1112# The perl -0777 invocation below extracts the possibly-multi-line 1113# definition of LDADD from the appropriate Makefile.am and exits 0 1114# when it contains "ICONV". 1115sc_proper_name_utf8_requires_ICONV: 1116 @progs=$$($(VC_LIST_EXCEPT) \ 1117 | xargs $(GREP) -l 'proper_name_utf8 ''("'); \ 1118 if test "x$$progs" != x; then \ 1119 fail=0; \ 1120 for p in $$progs; do \ 1121 dir=$$(dirname "$$p"); \ 1122 perl -0777 \ 1123 -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)' \ 1124 $$dir/Makefile.am && continue; \ 1125 base=$$(basename "$$p" .c); \ 1126 $(GREP) "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \ 1127 || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \ 1128 done; \ 1129 test $$fail = 1 && \ 1130 { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \ 1131 exit 1; } || :; \ 1132 fi 1133 1134# Warn about "c0nst struct Foo const foo[]", 1135# but not about "char const *const foo" or "#define const const". 1136sc_redundant_const: 1137 @prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \ 1138 halt='redundant "const" in declarations' \ 1139 $(_sc_search_regexp) 1140 1141sc_const_long_option: 1142 @prohibit='^ *static.*struct option ' \ 1143 exclude='const struct option|struct option const' \ 1144 halt='add "const" to the above declarations' \ 1145 $(_sc_search_regexp) 1146 1147NEWS_hash = \ 1148 $$($(SED) -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \ 1149 $(srcdir)/NEWS \ 1150 | perl -0777 -pe \ 1151 's/^Copyright.+?Free\sSoftware\sFoundation,\sInc\.\n//ms' \ 1152 | md5sum - \ 1153 | $(SED) 's/ .*//') 1154 1155# Ensure that we don't accidentally insert an entry into an old NEWS block. 1156sc_immutable_NEWS: 1157 @if test -f $(srcdir)/NEWS; then \ 1158 test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \ 1159 { echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \ 1160 fi 1161 1162# Update the hash stored above. Do this after each release and 1163# for any corrections to old entries. 1164update-NEWS-hash: NEWS 1165 perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \ 1166 $(srcdir)/cfg.mk 1167 1168# Ensure that we use only the standard $(VAR) notation, 1169# not @...@ in Makefile.am, now that we can rely on automake 1170# to emit a definition for each substituted variable. 1171# However, there is still one case in which @VAR@ use is not just 1172# legitimate, but actually required: when augmenting an automake-defined 1173# variable with a prefix. For example, gettext uses this: 1174# MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@ 1175# otherwise, makeinfo would put German or French (current locale) 1176# navigation hints in the otherwise-English documentation. 1177# 1178# Allow the package to add exceptions via a hook in cfg.mk; 1179# for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by 1180# setting this to ' && !/PRAGMA_SYSTEM_HEADER/'. 1181_makefile_at_at_check_exceptions ?= 1182sc_makefile_at_at_check: 1183 @perl -ne '/\@\w+\@/' \ 1184 -e ' && !/(\w+)\s+=.*\@\1\@$$/' \ 1185 -e ''$(_makefile_at_at_check_exceptions) \ 1186 -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \ 1187 $$($(VC_LIST_EXCEPT) | $(GREP) -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \ 1188 && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || : 1189 1190news-check: NEWS 1191 $(AM_V_GEN)if $(SED) -n $(news-check-lines-spec)p $< \ 1192 | $(GREP) -E $(news-check-regexp) >/dev/null; then \ 1193 :; \ 1194 else \ 1195 echo 'NEWS: $$(news-check-regexp) failed to match' 1>&2; \ 1196 exit 1; \ 1197 fi 1198 1199sc_makefile_TAB_only_indentation: 1200 @prohibit='^ [ ]{8}' \ 1201 in_vc_files='akefile|\.mk$$' \ 1202 halt='found TAB-8-space indentation' \ 1203 $(_sc_search_regexp) 1204 1205sc_m4_quote_check: 1206 @prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \ 1207 in_vc_files='(^configure\.ac|\.m4)$$' \ 1208 halt='quote the first arg to AC_DEF*' \ 1209 $(_sc_search_regexp) 1210 1211fix_po_file_diag = \ 1212'you have changed the set of files with translatable diagnostics;\n\ 1213apply the above patch\n' 1214 1215# Generate a list of files in which to search for translatable strings. 1216perl_translatable_files_list_ = \ 1217 -e 'foreach $$file (@ARGV) {' \ 1218 -e ' \# Consider only file extensions with one or two letters' \ 1219 -e ' $$file =~ /\...?$$/ or next;' \ 1220 -e ' \# Ignore m4 and mk files' \ 1221 -e ' $$file =~ /\.m[4k]$$/ and next;' \ 1222 -e ' \# Ignore a .c or .h file with a corresponding .l or .y file' \ 1223 -e ' $$file =~ /(.+)\.[ch]$$/ && (-e "$${1}.l" || -e "$${1}.y")' \ 1224 -e ' and next;' \ 1225 -e ' \# Skip unreadable files' \ 1226 -e ' -r $$file or next;' \ 1227 -e ' print "$$file ";' \ 1228 -e '}' 1229 1230# Verify that all source files using _() (more specifically, files that 1231# match $(_gl_translatable_string_re)) are listed in po/POTFILES.in. 1232po_file ?= $(srcdir)/po/POTFILES.in 1233generated_files ?= $(srcdir)/lib/*.[ch] 1234_gl_translatable_string_re ?= \b(N?_|gettext *)\([^)"]*("|$$) 1235sc_po_check: 1236 @if test -f $(po_file); then \ 1237 $(GREP) -E -v '^(#|$$)' $(po_file) \ 1238 | $(GREP) -v '^src/false\.c$$' | sort > $@-1; \ 1239 { $(VC_LIST_EXCEPT); echo $(generated_files); } \ 1240 | xargs perl $(perl_translatable_files_list_) \ 1241 | xargs $(GREP) -E -l '$(_gl_translatable_string_re)' \ 1242 | $(SED) 's|^$(_dot_escaped_srcdir)/||' \ 1243 | sort -u > $@-2; \ 1244 diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \ 1245 || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \ 1246 rm -f $@-1 $@-2; \ 1247 fi 1248 1249# Sometimes it is useful to change the PATH environment variable 1250# in Makefiles. When doing so, it's better not to use the Unix-centric 1251# path separator of ':', but rather the automake-provided '$(PATH_SEPARATOR)'. 1252msg = 'Do not use ":" above; use $$(PATH_SEPARATOR) instead' 1253sc_makefile_path_separator_check: 1254 @prohibit='PATH[=].*:' \ 1255 in_vc_files='akefile|\.mk$$' \ 1256 halt=$(msg) \ 1257 $(_sc_search_regexp) 1258 1259# Check that 'make alpha' will not fail at the end of the process, 1260# i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release) 1261# and is read-only. 1262writable-files: 1263 $(AM_V_GEN)if test -d $(release_archive_dir); then \ 1264 for file in $(DIST_ARCHIVES); do \ 1265 for p in ./ $(release_archive_dir)/; do \ 1266 test -e $$p$$file || continue; \ 1267 test -w $$p$$file \ 1268 || { echo ERROR: $$p$$file is not writable; fail=1; }; \ 1269 done; \ 1270 done; \ 1271 test "$$fail" && exit 1 || : ; \ 1272 else :; \ 1273 fi 1274 1275v_etc_file = $(gnulib_dir)/lib/version-etc.c 1276sample-test = tests/sample-test 1277texi = doc/$(PACKAGE).texi 1278# Make sure that the copyright date in $(v_etc_file) is up to date. 1279# Do the same for the $(sample-test) and the main doc/.texi file. 1280sc_copyright_check: 1281 @require='enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' \ 1282 in_files=$(v_etc_file) \ 1283 halt='out of date copyright in $(v_etc_file); update it' \ 1284 $(_sc_search_regexp) 1285 @require='# Copyright \(C\) '$$(date +%Y)' Free' \ 1286 in_vc_files=$(sample-test) \ 1287 halt='out of date copyright in $(sample-test); update it' \ 1288 $(_sc_search_regexp) 1289 @require='Copyright @copyright\{\} .*'$$(date +%Y) \ 1290 in_vc_files=$(texi) \ 1291 halt='out of date copyright in $(texi); update it' \ 1292 $(_sc_search_regexp) 1293 1294# If tests/help-version exists and seems to be new enough, assume that its 1295# use of init.sh and path_prepend_ is correct, and ensure that every other 1296# use of init.sh is identical. 1297# This is useful because help-version cross-checks prog --version 1298# with $(VERSION), which verifies that its path_prepend_ invocation 1299# sets PATH correctly. This is an inexpensive way to ensure that 1300# the other init.sh-using tests also get it right. 1301_hv_file ?= $(srcdir)/tests/help-version 1302_hv_regex_weak ?= ^ *\. .*/init\.sh" 1303# Fix syntax-highlighters " 1304_hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh" 1305sc_cross_check_PATH_usage_in_tests: 1306 @if test -f $(_hv_file); then \ 1307 $(GREP) -l 'VERSION mismatch' $(_hv_file) >/dev/null \ 1308 || { echo "$@: skipped: no such file: $(_hv_file)" 1>&2; \ 1309 exit 0; }; \ 1310 $(GREP) -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null \ 1311 || { echo "$@: $(_hv_file) lacks conforming use of init.sh" 1>&2; \ 1312 exit 1; }; \ 1313 good=$$($(GREP) -E '$(_hv_regex_strong)' $(_hv_file)); \ 1314 $(VC_LIST_EXCEPT) \ 1315 | xargs $(GREP) -lE '$(_hv_regex_weak)' \ 1316 | xargs $(GREP) -LFx "$$good" \ 1317 | $(GREP) . \ 1318 && { printf "$(ME): the above files use" \ 1319 " path_prepend_ inconsistently\n" 1>&2; \ 1320 exit 1; } \ 1321 || :; \ 1322 fi 1323 1324# BRE regex of file contents to identify a test script. 1325_test_script_regex ?= \<init\.sh\> 1326 1327# In tests, use "compare expected actual", not the reverse. 1328sc_prohibit_reversed_compare_failure: 1329 @prohibit='\<compare [^ ]+ ([^ ]*exp|/dev/null)' \ 1330 containing='$(_test_script_regex)' \ 1331 halt='reversed compare arguments' \ 1332 $(_sc_search_regexp) 1333 1334# #if HAVE_... will evaluate to false for any non numeric string. 1335# That would be flagged by using -Wundef, however gnulib currently 1336# tests many undefined macros, and so we can't enable that option. 1337# So at least preclude common boolean strings as macro values. 1338sc_Wundef_boolean: 1339 @prohibit='^#define.*(yes|no|true|false)$$' \ 1340 in_files='$(CONFIG_INCLUDE)' \ 1341 halt='Use 0 or 1 for macro values' \ 1342 $(_sc_search_regexp) 1343 1344# Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might 1345# not be constant, or might overflow a stack. In general, use PATH_MAX as 1346# a limit, not an array or alloca size. 1347sc_prohibit_path_max_allocation: 1348 @prohibit='(\balloca *\([^)]*|\[[^]]*)\bPATH_MAX' \ 1349 halt='Avoid stack allocations of size PATH_MAX' \ 1350 $(_sc_search_regexp) 1351 1352sc_vulnerable_makefile_CVE-2009-4029: 1353 @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \ 1354 in_files='(^|/)Makefile\.in$$' \ 1355 halt=$$(printf '%s\n' \ 1356 'the above files are vulnerable; beware of running' \ 1357 ' "make dist*" rules, and upgrade to fixed automake' \ 1358 ' see https://bugzilla.redhat.com/show_bug.cgi?id=542609 for details') \ 1359 $(_sc_search_regexp) 1360 1361sc_vulnerable_makefile_CVE-2012-3386: 1362 @prohibit='chmod a\+w \$$\(distdir\)' \ 1363 in_files='(^|/)Makefile\.in$$' \ 1364 halt=$$(printf '%s\n' \ 1365 'the above files are vulnerable; beware of running' \ 1366 ' "make distcheck", and upgrade to fixed automake' \ 1367 ' see https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-3386 for details') \ 1368 $(_sc_search_regexp) 1369 1370vc-diff-check: 1371 $(AM_V_GEN)(unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || : 1372 $(AM_V_at)if test -s vc-diffs; then \ 1373 cat vc-diffs; \ 1374 echo "Some files are locally modified:" 1>&2; \ 1375 exit 1; \ 1376 else \ 1377 rm vc-diffs; \ 1378 fi 1379 1380rel-files = $(DIST_ARCHIVES) 1381 1382gnulib-version = $$(cd $(gnulib_dir) \ 1383 && { git describe || git rev-parse --short=10 HEAD; } ) 1384bootstrap-tools ?= autoconf,automake,gnulib 1385 1386gpgv = $$(gpgv2 --version >/dev/null && echo gpgv2 || echo gpgv) 1387# If it's not already specified, derive the GPG key ID from 1388# the signed tag we've just applied to mark this release. 1389gpg_key_ID ?= \ 1390 $$(cd $(srcdir) \ 1391 && git cat-file tag v$(VERSION) \ 1392 | $(gpgv) --status-fd 1 --keyring /dev/null - - 2>/dev/null \ 1393 | $(AWK) '/^\[GNUPG:\] ERRSIG / {print $$3; exit}') 1394 1395translation_project_ ?= coordinator@translationproject.org 1396 1397# Make info-gnu the default only for a stable release. 1398announcement_Cc_stable = $(translation_project_), $(PACKAGE_BUGREPORT) 1399announcement_mail_headers_stable = \ 1400 To: info-gnu@gnu.org \ 1401 Cc: $(announcement_Cc_) \ 1402 Mail-Followup-To: $(PACKAGE_BUGREPORT) 1403 1404announcement_Cc_alpha = $(translation_project_) 1405announcement_mail_headers_alpha = \ 1406 To: $(PACKAGE_BUGREPORT) \ 1407 Cc: $(announcement_Cc_) 1408 1409announcement_mail_Cc_beta = $(announcement_mail_Cc_alpha) 1410announcement_mail_headers_beta = $(announcement_mail_headers_alpha) 1411 1412announcement_mail_Cc_ ?= $(announcement_mail_Cc_$(release-type)) 1413announcement_mail_headers_ ?= $(announcement_mail_headers_$(release-type)) 1414announcement: NEWS ChangeLog $(rel-files) 1415# Not $(AM_V_GEN) since the output of this command serves as 1416# announcement message: it would start with " GEN announcement". 1417 $(AM_V_at)$(srcdir)/$(_build-aux)/announce-gen \ 1418 --mail-headers='$(announcement_mail_headers_)' \ 1419 --release-type=$(release-type) \ 1420 --package=$(PACKAGE) \ 1421 --prev=$(PREV_VERSION) \ 1422 --curr=$(VERSION) \ 1423 --gpg-key-id=$(gpg_key_ID) \ 1424 --srcdir=$(srcdir) \ 1425 --news=$(srcdir)/NEWS \ 1426 --bootstrap-tools=$(bootstrap-tools) \ 1427 $$(case ,$(bootstrap-tools), in (*,gnulib,*) \ 1428 echo --gnulib-version=$(gnulib-version);; esac) \ 1429 --no-print-checksums \ 1430 $(addprefix --url-dir=, $(url_dir_list)) 1431 1432.PHONY: release-commit 1433release-commit: 1434 $(AM_V_GEN)cd $(srcdir) \ 1435 && $(_build-aux)/do-release-commit-and-tag \ 1436 -C $(abs_builddir) $(RELEASE) 1437 1438## ---------------- ## 1439## Updating files. ## 1440## ---------------- ## 1441 1442ftp-gnu = https://ftp.gnu.org/gnu 1443www-gnu = https://www.gnu.org 1444 1445upload_dest_dir_ ?= $(PACKAGE) 1446upload_command = \ 1447 $(srcdir)/$(_build-aux)/gnupload $(GNUPLOADFLAGS) \ 1448 --to $(gnu_rel_host):$(upload_dest_dir_) \ 1449 $(rel-files) 1450emit_upload_commands: 1451 @echo ===================================== 1452 @echo ===================================== 1453 @echo '$(upload_command)' 1454 @echo '# send the ~/announce-$(my_distdir) e-mail' 1455 @echo ===================================== 1456 @echo ===================================== 1457 1458.PHONY: upload 1459upload: 1460 $(AM_V_GEN)$(upload_command) 1461 1462define emit-commit-log 1463 printf '%s\n' 'maint: post-release administrivia' '' \ 1464 '* NEWS: Add header line for next release.' \ 1465 '* .prev-version: Record previous version.' \ 1466 '* cfg.mk (old_NEWS_hash): Auto-update.' 1467endef 1468 1469.PHONY: no-submodule-changes 1470no-submodule-changes: 1471 $(AM_V_GEN)if test -d $(srcdir)/.git \ 1472 && git --version >/dev/null 2>&1; then \ 1473 diff=$$(cd $(srcdir) && git submodule -q foreach \ 1474 git diff-index --name-only HEAD) \ 1475 || exit 1; \ 1476 case $$diff in '') ;; \ 1477 *) echo '$(ME): submodule files are locally modified:'; \ 1478 echo "$$diff"; exit 1;; esac; \ 1479 else \ 1480 : ; \ 1481 fi 1482 1483submodule-checks ?= no-submodule-changes public-submodule-commit 1484 1485# Ensure that each sub-module commit we're using is public. 1486# Without this, it is too easy to tag and release code that 1487# cannot be built from a fresh clone. 1488.PHONY: public-submodule-commit 1489public-submodule-commit: 1490 $(AM_V_GEN)if test -d $(srcdir)/.git \ 1491 && git --version >/dev/null 2>&1; then \ 1492 cd $(srcdir) && \ 1493 git submodule --quiet foreach \ 1494 'test "$$(git rev-parse "$$sha1")" \ 1495 = "$$(git merge-base origin "$$sha1")"' \ 1496 || { echo '$(ME): found non-public submodule commit' >&2; \ 1497 exit 1; }; \ 1498 else \ 1499 : ; \ 1500 fi 1501# This rule has a high enough utility/cost ratio that it should be a 1502# dependent of "check" by default. However, some of us do occasionally 1503# commit a temporary change that deliberately points to a non-public 1504# submodule commit, and want to be able to use rules like "make check". 1505# In that case, run e.g., "make check gl_public_submodule_commit=" 1506# to disable this test. 1507gl_public_submodule_commit ?= public-submodule-commit 1508check: $(gl_public_submodule_commit) 1509 1510.PHONY: alpha beta stable release 1511ALL_RECURSIVE_TARGETS += alpha beta stable 1512alpha beta stable: $(local-check) writable-files $(submodule-checks) 1513 $(AM_V_GEN)test $@ = stable \ 1514 && { echo $(VERSION) | $(GREP) -E '^[0-9]+(\.[0-9]+)+$$' \ 1515 || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\ 1516 || : 1517 $(AM_V_at)$(MAKE) vc-diff-check 1518 $(AM_V_at)$(MAKE) news-check 1519 $(AM_V_at)$(MAKE) distcheck 1520 $(AM_V_at)$(MAKE) dist 1521 $(AM_V_at)$(MAKE) $(release-prep-hook) RELEASE_TYPE=$@ 1522 $(AM_V_at)$(MAKE) -s emit_upload_commands RELEASE_TYPE=$@ 1523 1524release: 1525 $(AM_V_GEN)$(MAKE) _version 1526 $(AM_V_GEN)$(MAKE) $(release-type) 1527 1528# Override this in cfg.mk if you follow different procedures. 1529release-prep-hook ?= release-prep 1530 1531gl_noteworthy_news_ = * Noteworthy changes in release ?.? (????-??-??) [?] 1532.PHONY: release-prep 1533release-prep: 1534 $(AM_V_GEN)$(MAKE) --no-print-directory -s announcement \ 1535 > ~/announce-$(my_distdir) 1536 $(AM_V_at)if test -d $(release_archive_dir); then \ 1537 ln $(rel-files) $(release_archive_dir); \ 1538 chmod a-w $(rel-files); \ 1539 fi 1540 $(AM_V_at)echo $(VERSION) > $(prev_version_file) 1541 $(AM_V_at)$(MAKE) update-NEWS-hash 1542 $(AM_V_at)perl -pi \ 1543 -e '$$. == 3 and print "$(gl_noteworthy_news_)\n\n\n"' \ 1544 $(srcdir)/NEWS 1545 $(AM_V_at)msg=$$($(emit-commit-log)) || exit 1; \ 1546 cd $(srcdir) && $(VC) commit -m "$$msg" -a 1547 1548# Override this with e.g., -s $(srcdir)/some_other_name.texi 1549# if the default $(PACKAGE)-derived name doesn't apply. 1550gendocs_options_ ?= 1551 1552.PHONY: web-manual 1553web-manual: 1554 $(AM_V_GEN)test -z "$(manual_title)" \ 1555 && { echo define manual_title in cfg.mk 1>&2; exit 1; } || : 1556 $(AM_V_at)cd '$(srcdir)/doc'; \ 1557 $(SHELL) ../$(_build-aux)/gendocs.sh $(gendocs_options_) \ 1558 -o '$(abs_builddir)/doc/manual' \ 1559 --email $(PACKAGE_BUGREPORT) $(PACKAGE) \ 1560 "$(PACKAGE_NAME) - $(manual_title)" 1561 $(AM_V_at)echo " *** Upload the doc/manual directory to web-cvs." 1562 1563.PHONY: web-manual-update 1564web-manual-update: 1565 $(AM_V_GEN)cd $(srcdir) \ 1566 && $(_build-aux)/gnu-web-doc-update -C $(abs_builddir) 1567 1568 1569# Code Coverage 1570 1571init-coverage: 1572 $(MAKE) $(AM_MAKEFLAGS) clean 1573 lcov --directory . --zerocounters 1574 1575COVERAGE_CCOPTS ?= "-g --coverage" 1576COVERAGE_OUT ?= doc/coverage 1577 1578build-coverage: 1579 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) 1580 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check 1581 mkdir -p $(COVERAGE_OUT) 1582 lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \ 1583 --capture 1584 1585gen-coverage: 1586 genhtml --output-directory $(COVERAGE_OUT) \ 1587 $(COVERAGE_OUT)/$(PACKAGE).info \ 1588 --highlight --frames --legend \ 1589 --title "$(PACKAGE_NAME)" 1590 1591coverage: 1592 $(MAKE) init-coverage 1593 $(MAKE) build-coverage 1594 $(MAKE) gen-coverage 1595 1596# Some projects carry local adjustments for gnulib modules via patches in 1597# a gnulib patch directory whose default name is gl/ (defined in bootstrap 1598# via local_gl_dir=gl). Those patches become stale as the originals evolve 1599# in gnulib. Use this rule to refresh any stale patches. It applies each 1600# patch to the original in $(gnulib_dir) and uses the temporary result to 1601# generate a fuzz-free .diff file. If you customize the name of your local 1602# gnulib patch directory via bootstrap.conf, this rule detects that name. 1603# Run this from a non-VPATH (i.e., srcdir) build directory. 1604.PHONY: refresh-gnulib-patches 1605refresh-gnulib-patches: 1606 gl=gl; \ 1607 if test -f bootstrap.conf; then \ 1608 t=$$(perl -lne '/^\s*local_gl_dir=(\S+)/ and $$d=$$1;' \ 1609 -e 'END{defined $$d and print $$d}' bootstrap.conf); \ 1610 test -n "$$t" && gl=$$t; \ 1611 fi; \ 1612 for diff in $$(cd $$gl; git ls-files | $(GREP) '\.diff$$'); do \ 1613 b=$$(printf %s "$$diff"|$(SED) 's/\.diff$$//'); \ 1614 VERSION_CONTROL=none \ 1615 patch "$(gnulib_dir)/$$b" "$$gl/$$diff" || exit 1; \ 1616 ( cd $(gnulib_dir) || exit 1; \ 1617 git diff "$$b" > "../$$gl/$$diff"; \ 1618 git checkout $$b ) || exit 1; \ 1619 done 1620 1621# Update gettext files. 1622PACKAGE ?= $(shell basename $(PWD)) 1623PO_DOMAIN ?= $(PACKAGE) 1624POURL = https://translationproject.org/latest/$(PO_DOMAIN)/ 1625PODIR ?= po 1626refresh-po: 1627 rm -f $(PODIR)/*.po && \ 1628 echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \ 1629 wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \ 1630 echo 'en@boldquot' > $(PODIR)/LINGUAS && \ 1631 echo 'en@quot' >> $(PODIR)/LINGUAS && \ 1632 ls $(PODIR)/*.po | $(SED) 's/\.po//;s,$(PODIR)/,,' | \ 1633 sort >> $(PODIR)/LINGUAS 1634 1635 # Running indent once is not idempotent, but running it twice is. 1636INDENT_SOURCES ?= $(C_SOURCES) 1637.PHONY: indent 1638indent: 1639 indent $(INDENT_SOURCES) 1640 indent $(INDENT_SOURCES) 1641 1642# If you want to set UPDATE_COPYRIGHT_* environment variables, 1643# put the assignments in this variable. 1644update-copyright-env ?= 1645 1646# Run this rule once per year (usually early in January) 1647# to update all FSF copyright year lists in your project. 1648# If you have an additional project-specific rule, 1649# add it in cfg.mk along with a line 'update-copyright: prereq'. 1650# By default, exclude all variants of COPYING; you can also 1651# add exemptions (such as ChangeLog..* for rotated change logs) 1652# in the file .x-update-copyright. 1653.PHONY: update-copyright 1654update-copyright: 1655 $(AM_V_GEN)$(GREP) -l -w Copyright \ 1656 $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \ 1657 | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@ 1658 1659# This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not 1660# overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS. 1661 1662# NOTE: to override any _gl_TS_* default value, you must 1663# define the variable(s) using "export" in cfg.mk. 1664_gl_TS_dir ?= src 1665 1666ALL_RECURSIVE_TARGETS += sc_tight_scope 1667sc_tight_scope: tight-scope.mk 1668 @fail=0; \ 1669 if ! $(GREP) '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk \ 1670 > /dev/null \ 1671 && ! $(GREP) -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \ 1672 > /dev/null 2>&1; then \ 1673 echo '$(ME): skipping $@'; \ 1674 else \ 1675 $(MAKE) -s -C $(_gl_TS_dir) \ 1676 -f Makefile \ 1677 -f $(abs_top_srcdir)/cfg.mk \ 1678 -f $(abs_top_builddir)/$< \ 1679 _gl_tight_scope \ 1680 || fail=1; \ 1681 fi; \ 1682 rm -f $<; \ 1683 exit $$fail 1684 1685tight-scope.mk: $(ME) 1686 @rm -f $@ $@-t 1687 @perl -ne '/^# TS-start/.../^# TS-end/ and print' $(srcdir)/$(ME) > $@-t 1688 @chmod a=r $@-t && mv $@-t $@ 1689 1690ifeq (a,b) 1691# TS-start 1692 1693# Most functions should have static scope. 1694# Any that don't must be marked with 'extern', but 'main' 1695# and 'usage' are exceptions: they're always extern, but 1696# do not need to be marked. Symbols matching '__.*' are 1697# reserved by the compiler, so are automatically excluded below. 1698_gl_TS_unmarked_extern_functions ?= main usage 1699_gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\w+) *\(/ 1700 1701# If your project uses a macro like "XTERN", then put 1702# the following in cfg.mk to override this default: 1703# export _gl_TS_extern = extern|XTERN 1704_gl_TS_extern ?= extern 1705 1706# The second nm|grep checks for file-scope variables with 'extern' scope. 1707# Without gnulib's progname module, you might put program_name here. 1708# Symbols matching '__.*' are reserved by the compiler, 1709# so are automatically excluded below. 1710_gl_TS_unmarked_extern_vars ?= 1711 1712# NOTE: the _match variables are perl expressions -- not mere regular 1713# expressions -- so that you can extend them to match other patterns 1714# and easily extract matched variable names. 1715# For example, if your project declares some global variables via 1716# a macro like this: GLOBAL(type, var_name, initializer), then you 1717# can override this definition to automatically extract those names: 1718# export _gl_TS_var_match = \ 1719# /^(?:$(_gl_TS_extern)) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/ 1720_gl_TS_var_match ?= /^(?:$(_gl_TS_extern)) .*?(\w+)(\[.*?\])?;/ 1721 1722# The names of object files in (or relative to) $(_gl_TS_dir). 1723_gl_TS_obj_files ?= *.$(OBJEXT) 1724 1725# Files in which to search for the one-line style extern declarations. 1726# $(_gl_TS_dir)-relative. 1727_gl_TS_headers ?= $(noinst_HEADERS) 1728_gl_TS_other_headers ?= *.h 1729 1730.PHONY: _gl_tight_scope 1731_gl_tight_scope: $(bin_PROGRAMS) 1732 sed_wrap='s/^/^_?/;s/$$/$$/'; \ 1733 t=exceptions-$$$$; \ 1734 trap 's=$$?; rm -f $$t; exit $$s' 0; \ 1735 for sig in 1 2 3 13 15; do \ 1736 eval "trap 'v=`expr $$sig + 128`; (exit $$v); exit $$v' $$sig"; \ 1737 done; \ 1738 src=`for f in $(SOURCES); do \ 1739 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \ 1740 hdr=`for f in $(_gl_TS_headers); do \ 1741 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \ 1742 ( printf '%s\n' '__.*' $(_gl_TS_unmarked_extern_functions); \ 1743 $(GREP) -h -A1 '^extern .*[^;]$$' $$src \ 1744 | $(GREP) -vE '^(extern |--|#)' | $(SED) 's/ .*//; /^$$/d'; \ 1745 perl -lne \ 1746 '$(_gl_TS_function_match) and print $$1' $$hdr; \ 1747 ) | sort -u | $(SED) "$$sed_wrap" > $$t; \ 1748 nm -g $(_gl_TS_obj_files)|$(SED) -n 's/.* T //p'|$(GREP) -Ev -f $$t \ 1749 && { echo the above functions should have static scope >&2; \ 1750 exit 1; } || : ; \ 1751 ( printf '%s\n' '__.*' main $(_gl_TS_unmarked_extern_vars); \ 1752 perl -lne '$(_gl_TS_var_match) and print $$1' \ 1753 $$hdr $(_gl_TS_other_headers) \ 1754 ) | sort -u | $(SED) "$$sed_wrap" > $$t; \ 1755 nm -g $(_gl_TS_obj_files) | $(SED) -n 's/.* [BCDGRS] //p' \ 1756 | sort -u | $(GREP) -Ev -f $$t \ 1757 && { echo the above variables should have static scope >&2; \ 1758 exit 1; } || : 1759# TS-end 1760endif 1761