513b50bcf19d5cd0c55456a9e0fc6f391c0db950
[platform/upstream/automake.git] / lib / am / distdir.am
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 2001, 2002, 2003  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?      $(mkinstalldirs) %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 will rewrite `foo' as
68 ## `$(srcdir)/foo'.  An attempt to install the file with
69 ##    cp $file $(distdir)/$file
70 ## will thus install $(srcdir)/foo as $(distdir)/$(srcdir)/foo
71 ## instead of $(distdir)/foo.
72 ##
73 ## So let's strip this leading $(srcdir)/ when it exists.  (As far we
74 ## know, only SUN make adds it.)  Searching whether the file is to be
75 ## found in the source or build directory will be done latter.
76 ##
77 ## In case we are _not_ using SUN make, how can we be sure we are
78 ## not stripping a legitimate filename that starts with the same
79 ## pattern as $(srcdir)?
80 ## Well, it can't happen without the Makefile author distributing
81 ## something out of the distribution (which is bad).   As an example,
82 ## consider `EXTRA_DIST = ../bar'.  This is an issue if $srcdir is `..',
83 ## however getting this value for srcdir is impossible: `EXTRA_DIST = ../bar'
84 ## implies we are in a subdirectory (so `../bar' is within the package),
85 ## hence `$srcdir' is something like `../../subdir'.
86 ##
87           case $$file in \
88             $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
89 ## Also rewrite $(top_srcdir) (which sometimes appears in DISTFILES, and can
90 ## be absolute) by $(top_builddir) (which is always relative).  $(srcdir) will
91 ## be prepended latter.
92             $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
93           esac; \
94 ##
95 ## Always look for the file in the build directory first.  That way
96 ## for something like yacc output we will correctly pick up the latest
97 ## version.  Also check for directories in the build directory first,
98 ## so one can ship generated directories.
99 ##
100           if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
101 ##
102 ## Make the subdirectory for the file.  This is going to make `dist'
103 ## really crawl, but it seems like the only way to do it, given that
104 ## files in subdirectories can be specified for `dist' conditionally.
105 ##
106           dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
107           if test "$$dir" != "$$file" && test "$$dir" != "."; then \
108             dir="/$$dir"; \
109             $(mkinstalldirs) "$(distdir)$$dir"; \
110           else \
111             dir=''; \
112           fi; \
113 ##
114 ## Use cp, not ln.  There are situations in which "ln" can fail.  For
115 ## instance a file to distribute could actually be a cross-filesystem
116 ## symlink -- this can easily happen if "gettextize" was run on the
117 ## distribution.
118 ##
119           if test -d $$d/$$file; then \
120 ## Don't mention $$file in destination argument, since this fails if
121 ## destination directory already exists.  Also, use `-R' and not `-r'.
122 ## `-r' is almost always incorrect.
123 ##
124 ## If a directory exists both in `.' and $(srcdir), then
125 ## We copy the files from $(srcdir) first and then install those from
126 ## `.'.  This can help people who distribute directories made of
127 ## source files _and_ generated files.  It is also important when the
128 ## directory exists only in $(srcdir), because some vendor Make (such
129 ## as Tru64) will magically create an empty directory in `.'
130             if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
131               cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
132             fi; \
133             cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
134           else \
135 ## Test for file existence because sometimes a file gets included in
136 ## DISTFILES twice.  For example this happens when a single source
137 ## file is used in building more than one program.
138             test -f $(distdir)/$$file \
139             || cp -p $$d/$$file $(distdir)/$$file \
140             || exit 1; \
141           fi; \
142         done
143 ##
144 ## Test for directory existence here because previous automake
145 ## invocation might have created some directories.  Note that we
146 ## explicitly set distdir for the subdir make; that lets us mix-n-match
147 ## many automake-using packages into one large package, and have "dist"
148 ## at the top level do the right thing.  If we're in the topmost
149 ## directory, then we use `distdir' instead of `top_distdir'; this lets
150 ## us work correctly with an enclosing package.
151 ##
152 if %?SUBDIRS%
153         list='$(%DIST_SUBDIR_NAME%)'; for subdir in $$list; do \
154           if test "$$subdir" = .; then :; else \
155             test -d "$(distdir)/$$subdir" \
156             || mkdir "$(distdir)/$$subdir" \
157             || exit 1; \
158             (cd $$subdir && \
159               $(MAKE) $(AM_MAKEFLAGS) \
160                 top_distdir="../$(top_distdir)" \
161                 distdir="../$(distdir)/$$subdir" \
162                 distdir) \
163               || exit 1; \
164           fi; \
165         done
166 endif %?SUBDIRS%
167 ##
168 ## We might have to perform some last second updates, such as updating
169 ## info files.
170 ## We must explicitly set distdir and top_distdir for these sub-makes.
171 ##
172 if %?DIST-TARGETS%
173         $(MAKE) $(AM_MAKEFLAGS) \
174           top_distdir="$(top_distdir)" distdir="$(distdir)" \
175           %DIST-TARGETS%
176 endif %?DIST-TARGETS%
177 ##
178 ## This complex find command will try to avoid changing the modes of
179 ## links into the source tree, in case they're hard-linked.  It will
180 ## also make directories writable by everybody, because some
181 ## brain-dead tar implementations change ownership and permissions of
182 ## a directory before extracting the files, thus becoming unable to
183 ## extract them.
184 ##
185 ## Ignore return result from chmod, because it might give an error
186 ## if we chmod a symlink.
187 ##
188 ## Another nastiness: if the file is unreadable by us, we make it
189 ## readable regardless of the number of links to it.  This only
190 ## happens in perverse cases.
191 ##
192 ## We use $(install_sh) because that is a known-portable way to modify
193 ## the file in place in the source tree.
194 ##
195 if %?TOPDIR_P%
196         -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
197           ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
198           ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
199           ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
200         || chmod -R a+r $(distdir)
201 endif %?TOPDIR_P%
202
203
204
205
206 ## --------------------------------------- ##
207 ## Building various distribution flavors.  ##
208 ## --------------------------------------- ##
209
210 ## Note that we don't use GNU tar's `-z' option.  One reason (but not
211 ## the only reason) is that some versions of tar (e.g., OSF1)
212 ## interpret `-z' differently.
213
214 if %?TOPDIR_P%
215
216 ?GZIP?DIST_ARCHIVES += $(distdir).tar.gz
217 GZIP_ENV = --best
218 .PHONY: dist-gzip
219 dist-gzip: distdir
220         $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
221         $(am__remove_distdir)
222
223 ?BZIP2?DIST_ARCHIVES += $(distdir).tar.bz2
224 .PHONY: dist-bzip2
225 dist-bzip2: distdir
226         $(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
227         $(am__remove_distdir)
228
229 ?COMPRESS?DIST_ARCHIVES += $(distdir).tar.Z
230 .PHONY: dist-tarZ
231 dist-tarZ: distdir
232         $(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
233         $(am__remove_distdir)
234
235 ?SHAR?DIST_ARCHIVES += $(distdir).shar.gz
236 .PHONY: dist-shar
237 dist-shar: distdir
238         shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
239         $(am__remove_distdir)
240
241 ?ZIP?DIST_ARCHIVES += $(distdir).zip
242 .PHONY: dist-zip
243 dist-zip: distdir
244         -rm -f $(distdir).zip
245         zip -rq $(distdir).zip $(distdir)
246         $(am__remove_distdir)
247
248 endif %?TOPDIR_P%
249
250
251
252 ## ------------------------------------------------- ##
253 ## Building all the requested distribution flavors.  ##
254 ## ------------------------------------------------- ##
255
256 ## Currently we cannot use if/endif inside a rule.  The file_contents
257 ## parser needs work.
258
259 if %?TOPDIR_P%
260
261 .PHONY: dist dist-all
262 dist dist-all: distdir
263 ?GZIP?  $(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
264 ?BZIP2? $(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
265 ?COMPRESS?      $(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
266 ?SHAR?  shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
267 ?ZIP?   -rm -f $(distdir).zip
268 ?ZIP?   zip -rq $(distdir).zip $(distdir)
269         $(am__remove_distdir)
270
271 endif %?TOPDIR_P%
272
273
274 ## ------------------------- ##
275 ## Checking a distribution.  ##
276 ## ------------------------- ##
277
278
279 if %?TOPDIR_P%
280 # This target untars the dist file and tries a VPATH configuration.  Then
281 # it guarantees that the distribution is self-contained by making another
282 # tarfile.
283 .PHONY: distcheck
284 distcheck: dist
285         case '$(DIST_ARCHIVES)' in \
286         *.tar.gz*) \
287           GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf - ;;\
288         *.tar.bz2*) \
289           bunzip2 -c $(distdir).tar.bz2 | $(AMTAR) xf - ;;\
290         *.tar.Z*) \
291           uncompress -c $(distdir).tar.Z | $(AMTAR) xf - ;;\
292         *.shar.gz*) \
293           GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | unshar ;;\
294         *.zip*) \
295           unzip $(distdir).zip ;;\
296         esac
297 ## Make the new source tree read-only.  Distributions ought to work in
298 ## this case.  However, make the top-level directory writable so we
299 ## can make our new subdirs.
300         chmod -R a-w $(distdir); chmod a+w $(distdir)
301         mkdir $(distdir)/_build
302         mkdir $(distdir)/_inst
303 ## Undo the write access.
304         chmod a-w $(distdir)
305 ## Compute the absolute path of `_inst'.  Strip any leading DOS drive
306 ## to allow DESTDIR installations.  Otherwise $(DESTDIR)$(prefix) would
307 ## expand to c:/temp/am-dc-5668/c:/src/package/package-1.0/_inst.
308         dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
309 ## We will attemp a DESTDIR install in $dc_destdir.  We don't
310 ## create this directory under $dc_install_base, because it would
311 ## create very long directory names.
312           && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
313 ?DISTCHECK-HOOK?          && $(MAKE) $(AM_MAKEFLAGS) distcheck-hook \
314           && cd $(distdir)/_build \
315           && ../configure --srcdir=.. --prefix="$$dc_install_base" \
316 ?GETTEXT?           --with-included-gettext \
317 ## Additional flags for configure.  Keep this last in the configure
318 ## invocation so the user can override previous options.
319             $(DISTCHECK_CONFIGURE_FLAGS) \
320           && $(MAKE) $(AM_MAKEFLAGS) \
321           && $(MAKE) $(AM_MAKEFLAGS) dvi \
322           && $(MAKE) $(AM_MAKEFLAGS) check \
323           && $(MAKE) $(AM_MAKEFLAGS) install \
324           && $(MAKE) $(AM_MAKEFLAGS) installcheck \
325           && $(MAKE) $(AM_MAKEFLAGS) uninstall \
326           && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
327                 distuninstallcheck \
328 ## Make sure the package has proper DESTDIR support (we could not test this
329 ## in the previous install/installcheck/uninstall test, because it's reasonable
330 ## for installcheck to fail in a DESTDIR install).
331 ## We make the `$dc_install_base' read-only because this is where files
332 ## with missing DESTDIR support are likely to be installed.
333           && chmod -R a-w "$$dc_install_base" \
334 ## The logic here is quite convoluted because we must clean $dc_destdir
335 ## whatever happens (it won't be erased by the next run of distcheck like
336 ## $(distdir) is).
337           && ({ \
338 ## Build the directory, so we can cd into it even if `make install'
339 ## didn't create it.
340                (cd ../.. && $(mkinstalldirs) "$$dc_destdir") \
341                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
342                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
343                && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
344                     distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
345               } || { rm -rf "$$dc_destdir"; exit 1; }) \
346           && rm -rf "$$dc_destdir" \
347           && $(MAKE) $(AM_MAKEFLAGS) dist \
348 ## Make sure to remove the dists we created in the test build directory.
349           && rm -rf $(DIST_ARCHIVES) \
350           && $(MAKE) $(AM_MAKEFLAGS) distcleancheck
351         $(am__remove_distdir)
352         @(echo "$(distdir) archives ready for distribution: "; \
353           list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
354           sed -e '1{h;s/./=/g;p;x}' -e '$${p;x}'
355
356 ## Define distuninstallcheck_listfiles and distuninstallcheck separately
357 ## from distcheck, so that they can be overridden by the user.
358 .PHONY: distuninstallcheck
359 distuninstallcheck_listfiles = find . -type f -print
360 distuninstallcheck:
361 ## We use -le 1 because the `dir' file (created by install-info)
362 ## might still exist after uninstall.
363         @cd $(distuninstallcheck_dir) \
364         && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
365            || { echo "ERROR: files left after uninstall:" ; \
366                 if test -n "$(DESTDIR)"; then \
367                   echo "  (check DESTDIR support)"; \
368                 fi ; \
369                 $(distuninstallcheck_listfiles) ; \
370                 exit 1; } >&2
371
372 ## Define distcleancheck_listfiles and distcleancheck separately
373 ## from distcheck, so that they can be overridden by the user.
374 .PHONY: distcleancheck
375 distcleancheck_listfiles = find . -type f -print
376 distcleancheck: distclean
377         @if test '$(srcdir)' = . ; then \
378           echo "ERROR: distcleancheck can only run from a VPATH build" ; \
379           exit 1 ; \
380         fi
381         @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
382           || { echo "ERROR: files left in build directory after distclean:" ; \
383                $(distcleancheck_listfiles) ; \
384                exit 1; } >&2
385 endif %?TOPDIR_P%