maint.mk 57 KB

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