summaryrefslogtreecommitdiff
path: root/lib/am/distdir.am
blob: 71ee7769292f3489a6f4553aa3106ec53136cb9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
## automake - create Makefile.in from Makefile.am
## Copyright (C) 2001, 2002, 2003, 2004  Free Software Foundation, Inc.

## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.

## DIST_COMMON comes first so that README can be the very first file.
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)

if %?TOPDIR_P%
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)

am__remove_distdir = \
  { test ! -d $(distdir) \
    || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
         && rm -fr $(distdir); }; }
endif %?TOPDIR_P%

.PHONY: distdir
distdir: $(DISTFILES)
##
## For Gnits users, this is pretty handy.  Look at 15 lines
## in case some explanatory text is desirable.
##
if %?TOPDIR_P%
if  %?CK-NEWS%
	@case `sed 15q $(srcdir)/NEWS` in \
	*"$(VERSION)"*) : ;; \
	*) \
	  echo "NEWS not updated; not releasing" 1>&2; \
	  exit 1;; \
	esac
endif  %?CK-NEWS%
endif %?TOPDIR_P%
##
## Only for the top dir.
##
if %?TOPDIR_P%
	$(am__remove_distdir)
	mkdir $(distdir)
endif %?TOPDIR_P%
##
##
?DISTDIRS?	$(mkdir_p) %DISTDIRS%
##
##
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
##
## Yet another hack to support SUN make.
##
## Let's assume `foo' appears in DISTFILES and is not a built file.
## When building with VPATH=$(srcdir), SUN make and OSF1/Tru64 will
## rewrite `foo' as `$(srcdir)/foo'.  An attempt to install the file
## with
##    cp $file $(distdir)/$file
## will thus install $(srcdir)/foo as $(distdir)/$(srcdir)/foo
## instead of $(distdir)/foo.
##
## So let's strip this leading $(srcdir)/ when it exists.  (As far we
## know, only SUN make and OSF1/Tru64 make add it.)  Searching whether
## the file is to be found in the source or build directory will be
## done latter.
##
## In case we are _not_ using SUN or OSF1/Tru64 make, how can we be sure
## we are not stripping a legitimate filename that starts with the
## same pattern as $(srcdir)?
## Well, it can't happen without the Makefile author distributing
## something out of the distribution (which is bad).   As an example,
## consider `EXTRA_DIST = ../bar'.  This is an issue if $srcdir is `..',
## however getting this value for srcdir is impossible: `EXTRA_DIST = ../bar'
## implies we are in a subdirectory (so `../bar' is within the package),
## hence `$srcdir' is something like `../../subdir'.
##
## There is more to say about files which are above the current directory,
## like `../bar' in the previous example.  The OSF1/Tru64 make
## implementation can simplify filenames resulting from a VPATH lookup.
## For instance if `VPATH = ../../subdir' and `../bar' is found in that
## VPATH directory, then occurrences of `../bar' will be replaced by
## `../../bar' (instead of `../../subdir/../bar').  This obviously defeats
## any attempt to strip a leading $srcdir.  Presently we have no workaround
## for this.  We avoid this issue by writing `EXTRA_DIST = $(srcdir)/../bar'
## instead of `EXTRA_DIST = ../bar'.  This prefixing is needed only for files
## above the current directory.  Fortunately, apart from auxdir files which
## can be located in .. or ../.., this situation hardly occurs in practice.
##
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
## Also rewrite $(top_srcdir) (which sometimes appears in DISTFILES, and can
## be absolute) by $(top_builddir) (which is always relative).  $(srcdir) will
## be prepended latter.
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
##
## Always look for the file in the build directory first.  That way
## for something like yacc output we will correctly pick up the latest
## version.  Also check for directories in the build directory first,
## so one can ship generated directories.
##
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
##
## Make the subdirectory for the file.  This is going to make `dist'
## really crawl, but it seems like the only way to do it, given that
## files in subdirectories can be specified for `dist' conditionally.
##
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkdir_p) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
##
## Use cp, not ln.  There are situations in which "ln" can fail.  For
## instance a file to distribute could actually be a cross-filesystem
## symlink -- this can easily happen if "gettextize" was run on the
## distribution.
##
	  if test -d $$d/$$file; then \
## Don't mention $$file in destination argument, since this fails if
## destination directory already exists.  Also, use `-R' and not `-r'.
## `-r' is almost always incorrect.
##
## If a directory exists both in `.' and $(srcdir), then
## We copy the files from $(srcdir) first and then install those from
## `.'.  This can help people who distribute directories made of
## source files _and_ generated files.  It is also important when the
## directory exists only in $(srcdir), because some vendor Make (such
## as Tru64) will magically create an empty directory in `.'
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
## Test for file existence because sometimes a file gets included in
## DISTFILES twice.  For example this happens when a single source
## file is used in building more than one program.
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
##
## Test for directory existence here because previous automake
## invocation might have created some directories.  Note that we
## explicitly set distdir for the subdir make; that lets us mix-n-match
## many automake-using packages into one large package, and have "dist"
## at the top level do the right thing.  If we're in the topmost
## directory, then we use `distdir' instead of `top_distdir'; this lets
## us work correctly with an enclosing package.
##
if %?SUBDIRS%
	list='$(%DIST_SUBDIR_NAME%)'; for subdir in $$list; do \
	  if test "$$subdir" = .; then :; else \
	    test -d "$(distdir)/$$subdir" \
	    || mkdir "$(distdir)/$$subdir" \
	    || exit 1; \
	    (cd $$subdir && \
	      $(MAKE) $(AM_MAKEFLAGS) \
	        top_distdir="../$(top_distdir)" \
	        distdir="../$(distdir)/$$subdir" \
	        distdir) \
	      || exit 1; \
	  fi; \
	done
endif %?SUBDIRS%
##
## We might have to perform some last second updates, such as updating
## info files.
## We must explicitly set distdir and top_distdir for these sub-makes.
##
if %?DIST-TARGETS%
	$(MAKE) $(AM_MAKEFLAGS) \
	  top_distdir="$(top_distdir)" distdir="$(distdir)" \
	  %DIST-TARGETS%
endif %?DIST-TARGETS%
##
## This complex find command will try to avoid changing the modes of
## links into the source tree, in case they're hard-linked.  It will
## also make directories writable by everybody, because some
## brain-dead tar implementations change ownership and permissions of
## a directory before extracting the files, thus becoming unable to
## extract them.
##
## Ignore return result from chmod, because it might give an error
## if we chmod a symlink.
##
## Another nastiness: if the file is unreadable by us, we make it
## readable regardless of the number of links to it.  This only
## happens in perverse cases.
##
## We use $(install_sh) because that is a known-portable way to modify
## the file in place in the source tree.
##
if %?TOPDIR_P%
	-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
	  ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
	|| chmod -R a+r $(distdir)
endif %?TOPDIR_P%




## --------------------------------------- ##
## Building various distribution flavors.  ##
## --------------------------------------- ##

## Note that we don't use GNU tar's `-z' option.  One reason (but not
## the only reason) is that some versions of tar (e.g., OSF1)
## interpret `-z' differently.
##
## The -o option of GNU tar used to exclude empty directories.  This
## behavior was fixed in tar 1.12 (released on 1997-04-25).  But older
## versions of tar are still used (for instance NetBSD 1.6.1 ships
## with tar 1.11.2).  We do not do anything specific w.r.t. this
## incompatibility since packages where empty directories need to be
## present in the archive are really unusual.

if %?TOPDIR_P%

?GZIP?DIST_ARCHIVES += $(distdir).tar.gz
GZIP_ENV = --best
.PHONY: dist-gzip
dist-gzip: distdir
	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
	$(am__remove_distdir)

?BZIP2?DIST_ARCHIVES += $(distdir).tar.bz2
.PHONY: dist-bzip2
dist-bzip2: distdir
	$(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
	$(am__remove_distdir)

?COMPRESS?DIST_ARCHIVES += $(distdir).tar.Z
.PHONY: dist-tarZ
dist-tarZ: distdir
	$(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
	$(am__remove_distdir)

?SHAR?DIST_ARCHIVES += $(distdir).shar.gz
.PHONY: dist-shar
dist-shar: distdir
	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
	$(am__remove_distdir)

?ZIP?DIST_ARCHIVES += $(distdir).zip
.PHONY: dist-zip
dist-zip: distdir
	-rm -f $(distdir).zip
	zip -rq $(distdir).zip $(distdir)
	$(am__remove_distdir)

endif %?TOPDIR_P%



## ------------------------------------------------- ##
## Building all the requested distribution flavors.  ##
## ------------------------------------------------- ##

## Currently we cannot use if/endif inside a rule.  The file_contents
## parser needs work.

if %?TOPDIR_P%

.PHONY: dist dist-all
dist dist-all: distdir
?GZIP?	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
?BZIP2?	$(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
?COMPRESS?	$(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
?SHAR?	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
?ZIP?	-rm -f $(distdir).zip
?ZIP?	zip -rq $(distdir).zip $(distdir)
	$(am__remove_distdir)

endif %?TOPDIR_P%


## ------------------------- ##
## Checking a distribution.  ##
## ------------------------- ##


if %?TOPDIR_P%
# This target untars the dist file and tries a VPATH configuration.  Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
.PHONY: distcheck
distcheck: dist
	case '$(DIST_ARCHIVES)' in \
	*.tar.gz*) \
	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf - ;;\
	*.tar.bz2*) \
	  bunzip2 -c $(distdir).tar.bz2 | $(AMTAR) xf - ;;\
	*.tar.Z*) \
	  uncompress -c $(distdir).tar.Z | $(AMTAR) xf - ;;\
	*.shar.gz*) \
	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | unshar ;;\
	*.zip*) \
	  unzip $(distdir).zip ;;\
	esac
## Make the new source tree read-only.  Distributions ought to work in
## this case.  However, make the top-level directory writable so we
## can make our new subdirs.
	chmod -R a-w $(distdir); chmod a+w $(distdir)
	mkdir $(distdir)/_build
	mkdir $(distdir)/_inst
## Undo the write access.
	chmod a-w $(distdir)
## Compute the absolute path of `_inst'.  Strip any leading DOS drive
## to allow DESTDIR installations.  Otherwise "$(DESTDIR)$(prefix)" would
## expand to "c:/temp/am-dc-5668/c:/src/package/package-1.0/_inst".
	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
## We will attemp a DESTDIR install in $dc_destdir.  We don't
## create this directory under $dc_install_base, because it would
## create very long directory names.
	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
?DISTCHECK-HOOK?	  && $(MAKE) $(AM_MAKEFLAGS) distcheck-hook \
	  && cd $(distdir)/_build \
	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
?GETTEXT?	    --with-included-gettext \
## Additional flags for configure.  Keep this last in the configure
## invocation so the user can override previous options.
	    $(DISTCHECK_CONFIGURE_FLAGS) \
	  && $(MAKE) $(AM_MAKEFLAGS) \
	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
	  && $(MAKE) $(AM_MAKEFLAGS) check \
	  && $(MAKE) $(AM_MAKEFLAGS) install \
	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
	        distuninstallcheck \
## Make sure the package has proper DESTDIR support (we could not test this
## in the previous install/installcheck/uninstall test, because it's reasonable
## for installcheck to fail in a DESTDIR install).
## We make the `$dc_install_base' read-only because this is where files
## with missing DESTDIR support are likely to be installed.
	  && chmod -R a-w "$$dc_install_base" \
## The logic here is quite convoluted because we must clean $dc_destdir
## whatever happens (it won't be erased by the next run of distcheck like
## $(distdir) is).
	  && ({ \
## Build the directory, so we can cd into it even if `make install'
## didn't create it.
	       (cd ../.. && $(mkdir_p) "$$dc_destdir") \
	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
	  && rm -rf "$$dc_destdir" \
	  && $(MAKE) $(AM_MAKEFLAGS) dist \
## Make sure to remove the dists we created in the test build directory.
	  && rm -rf $(DIST_ARCHIVES) \
	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck
	$(am__remove_distdir)
	@(echo "$(distdir) archives ready for distribution: "; \
	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
	  sed -e '1{h;s/./=/g;p;x;}' -e '$${p;x;}'

## Define distuninstallcheck_listfiles and distuninstallcheck separately
## from distcheck, so that they can be overridden by the user.
.PHONY: distuninstallcheck
distuninstallcheck_listfiles = find . -type f -print
distuninstallcheck:
## We use -le 1 because the `dir' file (created by install-info)
## might still exist after uninstall.
	@cd $(distuninstallcheck_dir) \
	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
	   || { echo "ERROR: files left after uninstall:" ; \
	        if test -n "$(DESTDIR)"; then \
	          echo "  (check DESTDIR support)"; \
	        fi ; \
	        $(distuninstallcheck_listfiles) ; \
	        exit 1; } >&2

## Define distcleancheck_listfiles and distcleancheck separately
## from distcheck, so that they can be overridden by the user.
.PHONY: distcleancheck
distcleancheck_listfiles = find . -type f -print
distcleancheck: distclean
	@if test '$(srcdir)' = . ; then \
	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
	  exit 1 ; \
	fi
	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
	  || { echo "ERROR: files left in build directory after distclean:" ; \
	       $(distcleancheck_listfiles) ; \
	       exit 1; } >&2
endif %?TOPDIR_P%