maint.mk 62 KB

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