Update automake to version 1.10
[msysgit.git] / share / automake-1.10 / am / distdir.am
blob908a88287aaa8994f0beb8b585ad6760a64ffac9
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006  Free Software
3 ## Foundation, Inc.
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
20 ## DIST_COMMON comes first so that README can be the very first file.
21 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
23 if %?TOPDIR_P%
24 distdir = $(PACKAGE)-$(VERSION)
25 top_distdir = $(distdir)
27 am__remove_distdir = \
28   { test ! -d $(distdir) \
29     || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
30          && rm -fr $(distdir); }; }
31 endif %?TOPDIR_P%
33 .PHONY: distdir
34 distdir: $(DISTFILES)
36 ## For Gnits users, this is pretty handy.  Look at 15 lines
37 ## in case some explanatory text is desirable.
39 if %?TOPDIR_P%
40 if  %?CK-NEWS%
41         @case `sed 15q $(srcdir)/NEWS` in \
42         *"$(VERSION)"*) : ;; \
43         *) \
44           echo "NEWS not updated; not releasing" 1>&2; \
45           exit 1;; \
46         esac
47 endif  %?CK-NEWS%
48 endif %?TOPDIR_P%
50 ## Only for the top dir.
52 if %?TOPDIR_P%
53         $(am__remove_distdir)
54         test -d $(distdir) || mkdir $(distdir)
55 endif %?TOPDIR_P%
58         @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
59         topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
61 ## Yet another hack to support SUN make.
63 ## Let's assume `foo' appears in DISTFILES and is not a built file.
64 ## When building with VPATH=$(srcdir), SUN make and OSF1/Tru64 will
65 ## rewrite `foo' as `$(srcdir)/foo'.  An attempt to install the file
66 ## with
67 ##    cp $file $(distdir)/$file
68 ## will thus install $(srcdir)/foo as $(distdir)/$(srcdir)/foo
69 ## instead of $(distdir)/foo.
71 ## So let's strip this leading $(srcdir)/ when it exists.  (As far we
72 ## know, only SUN make and OSF1/Tru64 make add it.)  Searching whether
73 ## the file is to be found in the source or build directory will be
74 ## done later.
76 ## In case we are _not_ using SUN or OSF1/Tru64 make, how can we be sure
77 ## we are not stripping a legitimate filename that starts with the
78 ## same pattern as $(srcdir)?
79 ## Well, it can't happen without the Makefile author distributing
80 ## something out of the distribution (which is bad).   As an example,
81 ## consider `EXTRA_DIST = ../bar'.  This is an issue if $srcdir is `..',
82 ## however getting this value for srcdir is impossible: `EXTRA_DIST = ../bar'
83 ## implies we are in a subdirectory (so `../bar' is within the package),
84 ## hence `$srcdir' is something like `../../subdir'.
86 ## There is more to say about files which are above the current directory,
87 ## like `../bar' in the previous example.  The OSF1/Tru64 make
88 ## implementation can simplify filenames resulting from a VPATH lookup.
89 ## For instance if `VPATH = ../../subdir' and `../bar' is found in that
90 ## VPATH directory, then occurrences of `../bar' will be replaced by
91 ## `../../bar' (instead of `../../subdir/../bar').  This obviously defeats
92 ## any attempt to strip a leading $srcdir.  Presently we have no workaround
93 ## for this.  We avoid this issue by writing `EXTRA_DIST = $(srcdir)/../bar'
94 ## instead of `EXTRA_DIST = ../bar'.  This prefixing is needed only for files
95 ## above the current directory.  Fortunately, apart from auxdir files which
96 ## can be located in .. or ../.., this situation hardly occurs in practice.
98 ## Also rewrite $(top_srcdir) (which sometimes appears in DISTFILES, and can
99 ## be absolute) by $(top_builddir) (which is always relative).  $(srcdir) will
100 ## be prepended later.
101         list='$(DISTFILES)'; \
102           dist_files=`for file in $$list; do echo $$file; done | \
103           sed -e "s|^$$srcdirstrip/||;t" \
104               -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
105 ## (The second `t' command clears the flag for the next round.)
107 ## Make the subdirectories for the files.
109         case $$dist_files in \
110           */*) $(MKDIR_P) `echo "$$dist_files" | \
111                            sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
112                            sort -u` ;; \
113         esac; \
116         for file in $$dist_files; do \
118 ## Always look for the file in the build directory first.  That way
119 ## for something like yacc output we will correctly pick up the latest
120 ## version.  Also check for directories in the build directory first,
121 ## so one can ship generated directories.
123           if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
125 ## Use cp, not ln.  There are situations in which "ln" can fail.  For
126 ## instance a file to distribute could actually be a cross-filesystem
127 ## symlink -- this can easily happen if "gettextize" was run on the
128 ## distribution.
130           if test -d $$d/$$file; then \
131 ## Don't mention $$file in the destination argument, since this fails if
132 ## the destination directory already exists.  Also, use `-R' and not `-r'.
133 ## `-r' is almost always incorrect.
135 ## If a directory exists both in `.' and $(srcdir), then
136 ## We copy the files from $(srcdir) first and then install those from
137 ## `.'.  This can help people who distribute directories made of
138 ## source files _and_ generated files.  It is also important when the
139 ## directory exists only in $(srcdir), because some vendor Make (such
140 ## as Tru64) will magically create an empty directory in `.'
141             dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
142             if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
143               cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
144             fi; \
145             cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
146           else \
147 ## Test for file existence because sometimes a file gets included in
148 ## DISTFILES twice.  For example this happens when a single source
149 ## file is used in building more than one program.
150             test -f $(distdir)/$$file \
151             || cp -p $$d/$$file $(distdir)/$$file \
152             || exit 1; \
153           fi; \
154         done
156 ## Test for directory existence here because previous automake
157 ## invocation might have created some directories.  Note that we
158 ## explicitly set distdir for the subdir make; that lets us mix-n-match
159 ## many automake-using packages into one large package, and have "dist"
160 ## at the top level do the right thing.  If we're in the topmost
161 ## directory, then we use `distdir' instead of `top_distdir'; this lets
162 ## us work correctly with an enclosing package.
164 if %?SUBDIRS%
165         list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
166           if test "$$subdir" = .; then :; else \
167             test -d "$(distdir)/$$subdir" \
168             || $(MKDIR_P) "$(distdir)/$$subdir" \
169             || exit 1; \
170             distdir=`$(am__cd) $(distdir) && pwd`; \
171             top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
172             (cd $$subdir && \
173               $(MAKE) $(AM_MAKEFLAGS) \
174                 top_distdir="$$top_distdir" \
175                 distdir="$$distdir/$$subdir" \
176 ## Disable am__remove_distdir so that sub-packages do not clear a
177 ## directory we have already cleared and might even have populated
178 ## (e.g. shared AUX dir in the sub-package).
179                 am__remove_distdir=: \
180 ## Disable filename length check:
181                 am__skip_length_check=: \
182                 distdir) \
183               || exit 1; \
184           fi; \
185         done
186 endif %?SUBDIRS%
188 ## We might have to perform some last second updates, such as updating
189 ## info files.
190 ## We must explicitly set distdir and top_distdir for these sub-makes.
192 if %?DIST-TARGETS%
193         $(MAKE) $(AM_MAKEFLAGS) \
194           top_distdir="$(top_distdir)" distdir="$(distdir)" \
195           %DIST-TARGETS%
196 endif %?DIST-TARGETS%
198 ## This complex find command will try to avoid changing the modes of
199 ## links into the source tree, in case they're hard-linked.  It will
200 ## also make directories writable by everybody, because some
201 ## brain-dead tar implementations change ownership and permissions of
202 ## a directory before extracting the files, thus becoming unable to
203 ## extract them.
205 ## Ignore return result from chmod, because it might give an error
206 ## if we chmod a symlink.
208 ## Another nastiness: if the file is unreadable by us, we make it
209 ## readable regardless of the number of links to it.  This only
210 ## happens in perverse cases.
212 ## We use $(install_sh) because that is a known-portable way to modify
213 ## the file in place in the source tree.
215 if %?TOPDIR_P%
216         -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
217           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
218           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
219           ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
220         || chmod -R a+r $(distdir)
221 if %?FILENAME_FILTER%
222         @if test -z "$(am__skip_length_check)" && find $(distdir) -type f -print | \
223           grep '^%FILENAME_FILTER%' 1>&2; then \
224           echo 'error: the above filenames are too long' 1>&2; \
225           exit 1; \
226         else :; fi
227 endif %?FILENAME_FILTER%
228 endif %?TOPDIR_P%
232 ## --------------------------------------- ##
233 ## Building various distribution flavors.  ##
234 ## --------------------------------------- ##
236 ## Note that we don't use GNU tar's `-z' option.  One reason (but not
237 ## the only reason) is that some versions of tar (e.g., OSF1)
238 ## interpret `-z' differently.
240 ## The -o option of GNU tar used to exclude empty directories.  This
241 ## behavior was fixed in tar 1.12 (released on 1997-04-25).  But older
242 ## versions of tar are still used (for instance NetBSD 1.6.1 ships
243 ## with tar 1.11.2).  We do not do anything specific w.r.t. this
244 ## incompatibility since packages where empty directories need to be
245 ## present in the archive are really unusual.
247 if %?TOPDIR_P%
249 ?GZIP?DIST_ARCHIVES += $(distdir).tar.gz
250 GZIP_ENV = --best
251 .PHONY: dist-gzip
252 dist-gzip: distdir
253         tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
254         $(am__remove_distdir)
256 ?BZIP2?DIST_ARCHIVES += $(distdir).tar.bz2
257 .PHONY: dist-bzip2
258 dist-bzip2: distdir
259         tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
260         $(am__remove_distdir)
262 ?COMPRESS?DIST_ARCHIVES += $(distdir).tar.Z
263 .PHONY: dist-tarZ
264 dist-tarZ: distdir
265         tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
266         $(am__remove_distdir)
268 ?SHAR?DIST_ARCHIVES += $(distdir).shar.gz
269 .PHONY: dist-shar
270 dist-shar: distdir
271         shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
272         $(am__remove_distdir)
274 ?ZIP?DIST_ARCHIVES += $(distdir).zip
275 .PHONY: dist-zip
276 dist-zip: distdir
277         -rm -f $(distdir).zip
278         zip -rq $(distdir).zip $(distdir)
279         $(am__remove_distdir)
281 endif %?TOPDIR_P%
285 ## ------------------------------------------------- ##
286 ## Building all the requested distribution flavors.  ##
287 ## ------------------------------------------------- ##
289 ## Currently we cannot use if/endif inside a rule.  The file_contents
290 ## parser needs work.
292 if %?TOPDIR_P%
294 .PHONY: dist dist-all
295 dist dist-all: distdir
296 ?GZIP?  tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
297 ?BZIP2? tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
298 ?COMPRESS?      tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
299 ?SHAR?  shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
300 ?ZIP?   -rm -f $(distdir).zip
301 ?ZIP?   zip -rq $(distdir).zip $(distdir)
302         $(am__remove_distdir)
304 endif %?TOPDIR_P%
307 ## ------------------------- ##
308 ## Checking a distribution.  ##
309 ## ------------------------- ##
312 if %?TOPDIR_P%
313 # This target untars the dist file and tries a VPATH configuration.  Then
314 # it guarantees that the distribution is self-contained by making another
315 # tarfile.
316 .PHONY: distcheck
317 distcheck: dist
318         case '$(DIST_ARCHIVES)' in \
319         *.tar.gz*) \
320           GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(am__untar) ;;\
321         *.tar.bz2*) \
322           bunzip2 -c $(distdir).tar.bz2 | $(am__untar) ;;\
323         *.tar.Z*) \
324           uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
325         *.shar.gz*) \
326           GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
327         *.zip*) \
328           unzip $(distdir).zip ;;\
329         esac
330 ## Make the new source tree read-only.  Distributions ought to work in
331 ## this case.  However, make the top-level directory writable so we
332 ## can make our new subdirs.
333         chmod -R a-w $(distdir); chmod a+w $(distdir)
334         mkdir $(distdir)/_build
335         mkdir $(distdir)/_inst
336 ## Undo the write access.
337         chmod a-w $(distdir)
338 ## Compute the absolute path of `_inst'.  Strip any leading DOS drive
339 ## to allow DESTDIR installations.  Otherwise "$(DESTDIR)$(prefix)" would
340 ## expand to "c:/temp/am-dc-5668/c:/src/package/package-1.0/_inst".
341         dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
342 ## We will attemp a DESTDIR install in $dc_destdir.  We don't
343 ## create this directory under $dc_install_base, because it would
344 ## create very long directory names.
345           && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
346 ?DISTCHECK-HOOK?          && $(MAKE) $(AM_MAKEFLAGS) distcheck-hook \
347           && cd $(distdir)/_build \
348           && ../configure --srcdir=.. --prefix="$$dc_install_base" \
349 ?GETTEXT?           --with-included-gettext \
350 ## Additional flags for configure.  Keep this last in the configure
351 ## invocation so the user can override previous options.
352             $(DISTCHECK_CONFIGURE_FLAGS) \
353           && $(MAKE) $(AM_MAKEFLAGS) \
354           && $(MAKE) $(AM_MAKEFLAGS) dvi \
355           && $(MAKE) $(AM_MAKEFLAGS) check \
356           && $(MAKE) $(AM_MAKEFLAGS) install \
357           && $(MAKE) $(AM_MAKEFLAGS) installcheck \
358           && $(MAKE) $(AM_MAKEFLAGS) uninstall \
359           && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
360                 distuninstallcheck \
361 ## Make sure the package has proper DESTDIR support (we could not test this
362 ## in the previous install/installcheck/uninstall test, because it's reasonable
363 ## for installcheck to fail in a DESTDIR install).
364 ## We make the `$dc_install_base' read-only because this is where files
365 ## with missing DESTDIR support are likely to be installed.
366           && chmod -R a-w "$$dc_install_base" \
367 ## The logic here is quite convoluted because we must clean $dc_destdir
368 ## whatever happens (it won't be erased by the next run of distcheck like
369 ## $(distdir) is).
370           && ({ \
371 ## Build the directory, so we can cd into it even if `make install'
372 ## didn't create it.  Use mkdir, not $(MKDIR_P) because we want to
373 ## fail if the directory already exists (PR/413).
374                (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
375                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
376                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
377                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
378                     distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
379               } || { rm -rf "$$dc_destdir"; exit 1; }) \
380           && rm -rf "$$dc_destdir" \
381           && $(MAKE) $(AM_MAKEFLAGS) dist \
382 ## Make sure to remove the dists we created in the test build directory.
383           && rm -rf $(DIST_ARCHIVES) \
384           && $(MAKE) $(AM_MAKEFLAGS) distcleancheck
385         $(am__remove_distdir)
386         @(echo "$(distdir) archives ready for distribution: "; \
387           list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
388           sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
390 ## Define distuninstallcheck_listfiles and distuninstallcheck separately
391 ## from distcheck, so that they can be overridden by the user.
392 .PHONY: distuninstallcheck
393 distuninstallcheck_listfiles = find . -type f -print
394 distuninstallcheck:
395 ## We use -le 1 because the `dir' file (created by install-info)
396 ## might still exist after uninstall.
397         @cd $(distuninstallcheck_dir) \
398         && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
399            || { echo "ERROR: files left after uninstall:" ; \
400                 if test -n "$(DESTDIR)"; then \
401                   echo "  (check DESTDIR support)"; \
402                 fi ; \
403                 $(distuninstallcheck_listfiles) ; \
404                 exit 1; } >&2
406 ## Define distcleancheck_listfiles and distcleancheck separately
407 ## from distcheck, so that they can be overridden by the user.
408 .PHONY: distcleancheck
409 distcleancheck_listfiles = find . -type f -print
410 distcleancheck: distclean
411         @if test '$(srcdir)' = . ; then \
412           echo "ERROR: distcleancheck can only run from a VPATH build" ; \
413           exit 1 ; \
414         fi
415         @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
416           || { echo "ERROR: files left in build directory after distclean:" ; \
417                $(distcleancheck_listfiles) ; \
418                exit 1; } >&2
419 endif %?TOPDIR_P%