2 # This Makefile fragment tries to be general-purpose enough to be
3 # used by at least coreutils, idutils, CPPI, Bison, and Autoconf.
5 ## Copyright (C) 2001-2008 Free Software Foundation, Inc.
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, either version 3 of the License, or
10 ## (at your option) any later version.
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # This is reported not to work with make-3.79.1
21 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
24 # Do not save the original name or timestamp in the .tar.gz file.
25 # Use --rsyncable if available.
27 $(shell gzip
--help
2>/dev
/null|grep rsyncable
>/dev
/null
&& echo
--rsyncable
)
28 GZIP_ENV
= '--no-name --best $(gzip_rsyncable)'
32 VC-tag
= git tag
-s
-m
'$(VERSION)'
34 VC_LIST
= $(srcdir)/build-aux
/vc-list-files
-C
$(srcdir)
37 $(VC_LIST
) | if
test -f
$(srcdir)/.x-
$@
; then \
38 grep
-vEf
$(srcdir)/.x-
$@
; \
43 ifeq ($(origin prev_version_file
), undefined
)
44 prev_version_file
= $(srcdir)/.prev-version
47 PREV_VERSION
:= $(shell cat
$(prev_version_file
))
48 VERSION_REGEXP
= $(subst .
,\.
,$(VERSION
))
50 this-vc-tag
= v
$(VERSION
)
51 this-vc-tag-regexp
= v
$(VERSION_REGEXP
)
52 my_distdir
= $(PACKAGE
)-$(VERSION
)
54 # Old releases are stored here.
55 # Used for diffs and xdeltas.
56 release_archive_dir ?
= ..
/release
58 # Prevent programs like 'sort' from considering distinct strings to be equal.
59 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
68 # Collect the names of rules starting with `sc_'.
69 syntax-check-rules
:= $(shell sed
-n
's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
71 .PHONY
: $(syntax-check-rules
)
73 local-checks-available
= \
74 po-check copyright-check writable-files m4-check author_mark_check \
75 changelog-check patch-check strftime-check
$(syntax-check-rules
) \
76 makefile_path_separator_check \
77 makefile-check check-AUTHORS
78 .PHONY
: $(local-checks-available
)
80 local-check
:= $(filter-out $(local-checks-to-skip
), $(local-checks-available
))
82 syntax-check
: $(local-check
)
83 # @shopt -s nullglob; \
84 # grep -nE '# *include <(limits|std(def|arg|bool))\.h>' \
85 # $$(find -type f -name '*.[chly]') /dev/null && \
86 # { echo '$(ME): found conditional include' 1>&2; \
89 # grep -nE '^# *include <(string|stdlib)\.h>' \
90 # $(srcdir)/{lib,src}/*.[chly] /dev/null && \
91 # { echo '$(ME): FIXME' 1>&2; \
93 # FIXME: don't allow `#include .strings\.h' anywhere
95 sc_cast_of_argument_to_free
:
97 grep
-nE
'\<free \(\(' \
98 $(srcdir)/{lib
,src
}/*.
[chly
] /dev
/null
&& \
99 { echo
'$(ME): don'\''t cast free argument' 1>&2; \
102 sc_cast_of_x_alloc_return_value
:
103 @shopt
-s nullglob
; \
104 grep
-nE
--exclude
=$(srcdir)/lib
/regex.c \
105 '\*\) *x(m|c|re)alloc\>' \
106 $(srcdir)/{lib
,src
}/*.
[chly
] /dev
/null
&& \
107 { echo
'$(ME): don'\''t cast x*alloc return value' 1>&2; \
110 sc_cast_of_alloca_return_value
:
111 @shopt
-s nullglob
; \
112 grep
-nE
'\*\) *alloca\>' \
113 $(srcdir)/src
/*.
[chly
] /dev
/null
&& \
114 { echo
'$(ME): don'\''t cast alloca return value' 1>&2; \
118 @grep
-n
'[ ] ' $$($(VC_LIST_EXCEPT
)) && \
119 { echo
'$(ME): found SPACE-TAB sequence; remove the SPACE' \
122 # Don't use *scanf or the old ato* functions in `real' code.
123 # They provide no error checking mechanism.
124 # Instead, use strto* functions.
125 sc_prohibit_atoi_atof
:
126 @grep
-nE
'\<([fs]?scanf|ato([filq]|ll))\>' $$($(VC_LIST_EXCEPT
)) && \
127 { echo
'$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf' \
130 # Using EXIT_SUCCESS as the first argument to error is misleading,
131 # since when that parameter is 0, error does not exit. Use `0' instead.
132 sc_error_exit_success
:
133 @grep
-nF
'error (EXIT_SUCCESS,' \
134 $$(find
-type f
-name
'*.[chly]') /dev
/null
&& \
135 { echo
'$(ME): found error (EXIT_SUCCESS' 1>&2; \
139 @grep
-ni
'file''system' $$($(VC_LIST_EXCEPT
)) \
140 | grep
-v
'File''system Hierarchy Standard' && \
141 { echo
'$(ME): found use of "file''system";' \
142 'rewrite to use "file system"' 1>&2; \
146 @grep
-n
'^# *if.*HAVE''_CONFIG_H' $$($(VC_LIST_EXCEPT
)) && \
147 { echo
'$(ME): found use of HAVE''_CONFIG_H; remove' \
150 # Nearly all .c files must include <config.h>.
152 @if
$(VC_LIST_EXCEPT
) | grep
'\.c$$' > /dev
/null
; then \
153 grep
-L
'^# *include <config\.h>' \
154 $$($(VC_LIST_EXCEPT
) | grep
'\.c$$') \
156 { echo
'$(ME): the above files do not include <config.h>' \
157 1>&2; exit
1; } ||
:; \
161 # To use this "command" macro, you must first define two shell variables:
162 # h: the header, enclosed in <> or ""
163 # re: a regular expression that matches IFF something provided by $h is used.
164 define _header_without_use
165 h_esc
=`echo "$$h"|sed 's/\./\\./'`; \
166 if
$(VC_LIST_EXCEPT
) | grep
'\.c$$' > /dev
/null
; then \
167 files
=$$(grep
-l
'^# *include '"$$h_esc" \
168 $$($(VC_LIST_EXCEPT
) | grep
'\.c$$')) && \
169 grep
-LE
"$$re" $$files | grep .
&& \
170 { echo
"$(ME): the above files include $$h but don't use it" \
171 1>&2; exit
1; } ||
:; \
176 # Prohibit the inclusion of assert.h without an actual use of assert.
177 sc_prohibit_assert_without_use
:
178 @h
='<assert.h>' re
='\<assert *\(' $(_header_without_use
)
180 # Prohibit the inclusion of getopt.h without an actual use.
181 sc_prohibit_getopt_without_use
:
182 @h
='<getopt.h>' re
='\<getopt(_long)? *\(' $(_header_without_use
)
184 # Don't include quotearg.h unless you use one of its functions.
185 sc_prohibit_quotearg_without_use
:
186 @h
='"quotearg.h"' re
='\<quotearg(_[^ ]+)? *\(' $(_header_without_use
)
188 # Don't include quote.h unless you use one of its functions.
189 sc_prohibit_quote_without_use
:
190 @h
='"quote.h"' re
='\<quote(_n)? *\(' $(_header_without_use
)
192 # Don't include this header unless you use one of its functions.
193 sc_prohibit_long_options_without_use
:
194 @h
='"long-options.h"' re
='\<parse_long_options *\(' \
195 $(_header_without_use
)
197 # Don't include this header unless you use one of its functions.
198 sc_prohibit_inttostr_without_use
:
199 @h
='"inttostr.h"' re
='\<(off|[iu]max|uint)tostr *\(' \
200 $(_header_without_use
)
202 # Don't include this header unless you use one of its functions.
203 sc_prohibit_error_without_use
:
205 re
='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
206 $(_header_without_use
)
208 sc_prohibit_safe_read_without_use
:
209 @h
='"safe-read.h"' re
='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
210 $(_header_without_use
)
212 sc_prohibit_argmatch_without_use
:
214 re
='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<argmatch(_exit_fn|_(in)?valid) *\()' \
215 $(_header_without_use
)
217 sc_prohibit_root_dev_ino_without_use
:
218 @h
='"root-dev-ino.h"' \
219 re
='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
220 $(_header_without_use
)
223 @grep
-nE
'\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
224 $$($(VC_LIST_EXCEPT
)) && \
225 { echo
'$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
228 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
230 # Each nonempty line must start with a year number, or a TAB.
232 @grep
-n
'^[^12 ]' $$(find
$(srcdir) -maxdepth
2 -name ChangeLog
) && \
233 { echo
'$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
236 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
237 # with the strings from the two affected variables.
238 dd_c
= $(srcdir)/src
/dd.c
239 sc_dd_max_sym_length
:
240 ifneq ($(wildcard $(dd_c
)),)
241 @len
=$$( (sed
-n
'/conversions\[\] =$$/,/^};/p' $(dd_c
);\
242 sed
-n
'/flags\[\] =$$/,/^};/p' $(dd_c
) ) \
243 |sed
-n
'/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
244 | wc
--max-line-length
); \
245 max
=$$(sed
-n
'/^#define LONGEST_SYMBOL /s///p' $(dd_c
) \
246 |tr
-d
'"' | wc
--max-line-length
); \
247 if
test "$$len" = "$$max"; then
:; else \
248 echo
'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
253 # Many m4 macros names once began with `jm_'.
254 # On 2004-04-13, they were all changed to start with gl_ instead.
255 # Make sure that none are inadvertently reintroduced.
256 sc_prohibit_jm_in_m4
:
257 @grep
-nE
'jm_[A-Z]' \
258 $$($(VC_LIST
) m4 |grep
'\.m4$$') && \
259 { echo
'$(ME): do not use jm_ in m4 macro names' \
263 @t1
=sc-root.expected
; t2
=sc-root.actual
; \
264 grep
-nl
'^PRIV_CHECK_ARG=require-root' \
265 $$($(VC_LIST
) tests
) |sed s
/tests
/.
/ |
sort > $$t1; \
266 sed
-n
's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
267 $(srcdir)/tests
/Makefile.am |
sort > $$t2; \
268 diff
-u
$$t1 $$t2 || diff
=1; \
271 && { echo
'tests/Makefile.am: missing check-root action'>&2; \
274 # Files in src/ should not include directly any of
275 # the headers already included via system.h.
277 @if
test -f
$(srcdir)/src
/system.h
; then \
279 sed
-n
'/^# *include /s///p' $(srcdir)/src
/system.h
/dev
/null \
280 | grep
-Ev
'sys/(param|file)\.h' \
281 | sed
's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
284 $$($(VC_LIST
) src | \
285 grep
-Ev
'((copy|system)\.h|parse-gram\.c)$$') \
286 && { echo
'$(ME): the above are already included via system.h'\
287 1>&2; exit
1; } ||
:; \
292 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
293 $$($(VC_LIST_EXCEPT
)) && \
294 { echo
'$(ME): found misuse of Sun OS version numbers' 1>&2; \
298 @grep
-ni
'\<the ''the\>' $$($(VC_LIST_EXCEPT
)) && \
299 { echo
'$(ME): found use of "the ''the";' 1>&2; \
303 test ! -d src ||
$(MAKE
) -C src
$@
306 @grep
-n
'[ ]$$' $$($(VC_LIST_EXCEPT
)) && \
307 { echo
'$(ME): found trailing blank(s)' \
310 # Match lines like the following, but where there is only one space
311 # between the options and the description:
312 # -D, --all-repeated[=delimit-method] print all duplicate lines\n
313 longopt_re
= --[a-z
][0-9A-Za-z-
]*(\
[?
=[0-9A-Za-z-
]*\
]?
)?
314 sc_two_space_separator_in_usage
:
315 @grep
-nE
'^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
316 $$($(VC_LIST_EXCEPT
)) && \
317 { echo
"$(ME): help2man requires at least two spaces between"; \
318 echo
"$(ME): an option and its description"; \
321 # Look for diagnostics that aren't marked for translation.
322 # This won't find any for which error's format string is on a separate line.
323 sc_unmarked_diagnostics
:
325 '\<error \([^"]*"[^"]*[a-z]{3}' $$($(VC_LIST_EXCEPT
)) \
326 | grep
-v
'_''(' && \
327 { echo
'$(ME): found unmarked diagnostic(s)' 1>&2; \
330 # Avoid useless parentheses like those in this example:
331 # #if defined (SYMBOL) || defined (SYM2)
332 sc_useless_cpp_parens
:
333 @grep
-n
'^# *if .*defined *(' $$($(VC_LIST_EXCEPT
)) && \
334 { echo
'$(ME): found useless parentheses in cpp directive' \
337 # Ensure that the c99-to-c89 patch applies cleanly.
339 if
test -f src
/c99-to-c89.diff
; then \
340 rm -rf src-c89
$@
.1 $@
.2 && \
341 cp
-a src src-c89
&& \
342 (cd src-c89
; patch
-V never
--fuzz
=0) < src
/c99-to-c89.diff \
344 { grep
-v
'^patching file ' $@
.1 > $@
.2 ||
:; } && \
346 rm -rf src-c89
$@
.1 $@
.2; \
349 # Ensure that date's --help output stays in sync with the info
350 # documentation for GNU strftime. The only exception is %N,
351 # which date accepts but GNU strftime does not.
352 extract_char
= sed
's/^[^%][^%]*%\(.\).*/\1/'
354 if
test -f
$(srcdir)/src
/date.c
; then \
355 grep
'^ %. ' $(srcdir)/src
/date.c |
sort \
356 |
$(extract_char
) > $@
-src
; \
358 info libc date calendar format | grep
'^ `%.'\' \
359 |
$(extract_char
); } |
sort > $@
-info; \
360 diff
-u
$@
-src
$@
-info || exit
1; \
361 rm -f
$@
-src
$@
-info; \
365 test ! -d src ||
$(MAKE
) -C src
$@
367 # Ensure that we use only the standard $(VAR) notation,
368 # not @...@ in Makefile.am, now that we can rely on automake
369 # to emit a definition for each substituted variable.
371 grep
-nE
'@[A-Z_0-9]+@' `find $(srcdir) -name Makefile.am` \
372 && { echo
'$(ME): use $$(...), not @...@' 1>&2; exit
1; } ||
:
374 news-date-check
: NEWS
375 today
=`date +%Y-%m-%d`; \
376 if head NEWS | grep
'^\*.* $(VERSION_REGEXP) ('$$today')' \
380 echo
"version or today's date is not in NEWS" 1>&2; \
385 if head ChangeLog | grep
'Version $(VERSION_REGEXP)\.$$' \
389 echo
"$(VERSION) not in ChangeLog" 1>&2; \
394 @shopt
-s nullglob
; \
395 grep
'AC_DEFUN([^[]' m4
/*.m4
/dev
/null \
396 && { echo
'$(ME): quote the first arg to AC_DEFUN' 1>&2; \
399 # Verify that all source files using _() are listed in po/POTFILES.in.
400 # FIXME: don't hard-code file names below; use a more general mechanism.
402 if
test -f po
/POTFILES.in
; then \
403 grep
-E
-v
'^(#|$$)' po
/POTFILES.in \
404 | grep
-v
'^src/false\.c$$' |
sort > $@
-1; \
406 for file in
$$($(VC_LIST_EXCEPT
)) lib
/*.
[ch
]; do \
408 djgpp
/* | man
/*) continue
;; \
409 */c99-to-c89.diff
) continue
;; \
413 base
=`expr " $$file" : ' \(.*\)\..'`; \
414 { test -f
$$base.l ||
test -f
$$base.y
; } && continue
;; \
416 files
="$$files $$file"; \
418 grep
-E
-l
'\b(N?_|gettext *)\([^)"]*("|$$)' $$files \
420 diff
-u
$@
-1 $@
-2 || exit
1; \
424 # In a definition of #define AUTHORS "... and ..." where the RHS contains
425 # the English word `and', the string must be marked with `N_ (...)' so that
426 # gettext recognizes it as a string requiring translation.
428 @shopt
-s nullglob
; \
429 grep
-n
'^# *define AUTHORS "[^"]* and ' src
/*.c
/dev
/null \
430 | grep
-v
' N_ (' && \
431 { echo
'$(ME): enclose the above strings in N_ (...)' 1>&2; \
434 # Sometimes it is useful to change the PATH environment variable
435 # in Makefiles. When doing so, it's better not to use the Unix-centric
436 # path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
437 # It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
438 # and there probably aren't many projects with so many Makefile.am files
439 # that we'd have to worry about limits on command line length.
440 msg
= '$(ME): Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
441 makefile_path_separator_check
:
442 @grep
-n
'PATH=.*:' `find $(srcdir) -name Makefile.am` \
443 && { echo
$(msg
) 1>&2; exit
1; } ||
:
445 # Check that `make alpha' will not fail at the end of the process.
447 if
test -d
$(release_archive_dir
); then
:; else \
448 mkdir
$(release_archive_dir
); \
450 for file in
$(distdir
).
tar.gz
$(xd-delta
) \
451 $(release_archive_dir
)/$(distdir
).
tar.gz \
452 $(release_archive_dir
)/$(xd-delta
); do \
453 test -e
$$file || continue
; \
455 ||
{ echo ERROR
: $$file is not writable
; fail
=1; }; \
457 test "$$fail" && exit
1 ||
:
459 v_etc_file
= lib
/version-etc.c
460 # Make sure that the copyright date in $(v_etc_file) is up to date.
462 @if
test -f
$(v_etc_file
); then \
463 grep
'enum { COPYRIGHT_YEAR = '$$(date
+%Y
)' };' $(v_etc_file
) \
465 ||
{ echo
'out of date copyright in $(v_etc_file); update it' 1>&2; \
470 (CDPATH
=; cd
$(srcdir) && $(VC
) diff
) > vc-diffs ||
:
471 if
test -s vc-diffs
; then \
473 echo
"Some files are locally modified:" 1>&2; \
479 cvs-check
: vc-diff-check
481 maintainer-distcheck
:
485 # Don't make a distribution if checks fail.
486 # Also, make sure the NEWS file is up-to-date.
487 vc-dist
: $(local-check
) cvs-check maintainer-distcheck
490 # Use this to make sure we don't run these programs when building
491 # from a virgin tgz file, below.
492 null_AM_MAKEFLAGS
= \
499 # Detect format-string/arg-list mismatches that would normally be obscured
500 # by the use of _(). The --disable-nls effectively defines away that macro,
501 # and building with CFLAGS='-Wformat -Werror' causes any format warning to be
502 # treated as a failure. Also, check for shadowing problems with -Wshadow,
503 # and for pointer arithmetic problems with -Wpointer-arith.
504 # These CFLAGS are pretty strict. If you build this target, you probably
505 # have to have a recent version of gcc and glibc headers.
507 t
=$(TMPDIR
)/$(PACKAGE
)/test
508 my-distcheck
: $(local-check
) $(release_archive_dir
)/$(prev-tgz
)
511 GZIP
=$(GZIP_ENV
) $(AMTAR
) -C
$(t
) -zxf
$(distdir
).
tar.gz
513 && .
/configure
--disable-nls \
514 && $(MAKE
) CFLAGS
='-Werror -Wall -Wformat -Wshadow -Wpointer-arith' \
515 AM_MAKEFLAGS
='$(null_AM_MAKEFLAGS)' \
519 (cd
$(t
) && mv
$(distdir
) $(distdir
).old \
520 && $(AMTAR
) -zxf
- ) < $(distdir
).
tar.gz
521 diff
-ur
$(t
)/$(distdir
).old
$(t
)/$(distdir
)
523 @echo
"========================"; \
524 echo
"$(distdir).tar.gz is ready for distribution"; \
525 echo
"========================"
527 prev-tgz
= $(PACKAGE
)-$(PREV_VERSION
).
tar.gz
528 xd-delta
= $(PACKAGE
)-$(PREV_VERSION
)-$(VERSION
).xdelta
530 rel-files
= $(xd-delta
) $(DIST_ARCHIVES
)
531 announcement
: NEWS ChangeLog
$(rel-files
)
533 --release-type
=$(RELEASE_TYPE
) \
534 --package
=$(PACKAGE
) \
535 --prev
=$(PREV_VERSION
) \
537 --gpg-key-id
=$(gpg_key_ID
) \
538 --news
=$(srcdir)/NEWS \
539 --bootstrap-tools
=automake \
540 $(addprefix --url-dir
=, $(url_dir_list
))
542 ## ---------------- ##
543 ## Updating files. ##
544 ## ---------------- ##
546 ftp-gnu
= ftp
://ftp.gnu.org
/gnu
547 www-gnu
= http
://www.gnu.org
549 # Use mv, if you don't have/want move-if-change.
550 move_if_change ?
= move-if-change
552 emit_upload_commands
:
553 @echo
=====================================
554 @echo
=====================================
555 @echo
"$(srcdir)/build-aux/gnupload $(GNUPLOADFLAGS) \\"
556 @echo
" --to $(gnu_rel_host):$(PACKAGE) \\"
557 @echo
" $(rel-files)"
558 @echo
'# send the /tmp/announcement e-mail'
559 @echo
=====================================
560 @echo
=====================================
562 $(xd-delta
): $(release_archive_dir
)/$(prev-tgz
) $(distdir
).
tar.gz
563 xdelta delta
-9 $^
$@ ||
:
565 .PHONY
: alpha beta major
566 alpha beta major
: news-date-check changelog-check
$(local-check
)
568 && { echo
$(VERSION
) | grep
-E
'^[0-9]+(\.[0-9]+)+$$' \
569 ||
{ echo
"invalid version string: $(VERSION)" 1>&2; exit
1;};}\
573 $(MAKE
) -s announcement RELEASE_TYPE
=$@
> /tmp
/announce-
$(my_distdir
)
574 ln
$(rel-files
) $(release_archive_dir
)
575 chmod a-w
$(rel-files
)
576 $(MAKE
) -s emit_upload_commands RELEASE_TYPE
=$@
577 echo
$(VERSION
) > $(prev_version_file
)
579 '$(prev_version_file): Record previous version: $(VERSION).' \