maint.mk 65 KB

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