maint.mk 44 KB

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