maint.mk 56 KB

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