maint.mk 66 KB

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