maint.mk 49 KB

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