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