maint.mk 62 KB

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