automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix `distdir' to use relative paths only.


From: Ralf Wildenhues
Subject: Fix `distdir' to use relative paths only.
Date: Sat, 24 Nov 2007 09:27:12 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Hello,

Here's a suggestion for how to fix `distdir' to not depend on absolute
paths (so that users can build in a pwd that contains spaces).  It
reuses an algorithm from gnulib-tool's func_relativize (thanks, Bruno!)
to allow to compute a correct relative path even in the presence of
something like this in an inner Makefile.am:
  SUBDIRS = ../subdir2

(yes, there is a test like this in the Automake testsuite).

Does anybody see problems with it?

Cheers,
Ralf

    Fix the distdir target to cope with spaces in absolute file names.
    
    * lib/am/distdir.am: Quote all instances of $(distdir) and
    $(top_distdir).  They could contain white space, coming from
    a toplevel package bootstrapped with an older Automake version.
    (am__relativize): New macro, taken from gnulib code, written by
    Bruno Haible.
    (distdir): Use it to compute relative paths to distdir and
    top_distdir for enclosed subpackages.
    Also, quote $(distuninstallcheck_dir).
    * lib/am/texinfos.am: Likewise, quote $(distdir).

diff --git a/lib/am/distdir.am b/lib/am/distdir.am
index ce547fd..fdafa9d 100644
--- a/lib/am/distdir.am
+++ b/lib/am/distdir.am
@@ -1,5 +1,5 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006  Free Software
+## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007  Free Software
 ## Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
@@ -25,11 +25,46 @@ 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); }; }
+  { test ! -d "$(distdir)" \
+    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+         && rm -fr "$(distdir)"; }; }
+
 endif %?TOPDIR_P%
 
+if %?SUBDIRS%
+## computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2.
+## Input:
+## - DIR1            relative pathname, relative to the current directory
+## - DIR2            relative pathname, relative to the current directory
+## Output:
+## - reldir          relative pathname of DIR2, relative to DIR1
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+endif %?SUBDIRS%
+
 .PHONY: distdir
 distdir: $(DISTFILES)
 ##
@@ -51,7 +86,7 @@ endif %?TOPDIR_P%
 ##
 if %?TOPDIR_P%
        $(am__remove_distdir)
-       test -d $(distdir) || mkdir $(distdir)
+       test -d "$(distdir)" || mkdir "$(distdir)"
 endif %?TOPDIR_P%
 ##
 ##
@@ -140,15 +175,15 @@ endif %?TOPDIR_P%
 ## as Tru64) will magically create an empty directory in `.'
            dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
            if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
-             cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+             cp -pR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
            fi; \
-           cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+           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 \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
            || exit 1; \
          fi; \
        done
@@ -161,18 +196,26 @@ endif %?TOPDIR_P%
 ## directory, then we use `distdir' instead of `top_distdir'; this lets
 ## us work correctly with an enclosing package.
 ##
+## Note that in the computation of the relative subdir, we make one
+## crucial assumption: that we never leave the outermost distdir,
+## and that there is never a trailing `..' in $subdir.  Some sanity
+## has to be expected from the user.
 if %?SUBDIRS%
        list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
            test -d "$(distdir)/$$subdir" \
            || $(MKDIR_P) "$(distdir)/$$subdir" \
            || exit 1; \
-           distdir=`$(am__cd) $(distdir) && pwd`; \
-           top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
+           dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+           $(am__relativize); \
+           new_distdir=$$reldir; \
+           dir1=$$subdir; dir2="$(top_distdir)"; \
+           $(am__relativize); \
+           new_top_distdir=$$reldir; \
            (cd $$subdir && \
              $(MAKE) $(AM_MAKEFLAGS) \
-               top_distdir="$$top_distdir" \
-               distdir="$$distdir/$$subdir" \
+               top_distdir="$$new_top_distdir" \
+               distdir="$$new_distdir" \
 ## Disable am__remove_distdir so that sub-packages do not clear a
 ## directory we have already cleared and might even have populated
 ## (e.g. shared AUX dir in the sub-package).
@@ -213,13 +256,13 @@ endif %?DIST-TARGETS%
 ## the file in place in the source tree.
 ##
 if %?TOPDIR_P%
-       -find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+       -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 $(install_sh) -c -m a+r {} {} \; \
-       || chmod -R a+r $(distdir)
+       || chmod -R a+r "$(distdir)"
 if %?FILENAME_FILTER%
-       @if test -z "$(am__skip_length_check)" && find $(distdir) -type f 
-print | \
+       @if test -z "$(am__skip_length_check)" && find "$(distdir)" -type f 
-print | \
          grep '^%FILENAME_FILTER%' 1>&2; then \
          echo 'error: the above filenames are too long' 1>&2; \
          exit 1; \
@@ -403,7 +446,7 @@ 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) \
+       @cd '$(distuninstallcheck_dir)' \
        && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
           || { echo "ERROR: files left after uninstall:" ; \
                if test -n "$(DESTDIR)"; then \
diff --git a/lib/am/texinfos.am b/lib/am/texinfos.am
index c905aab..0a9b821 100644
--- a/lib/am/texinfos.am
+++ b/lib/am/texinfos.am
@@ -1,7 +1,7 @@
 ## automake - create Makefile.in from Makefile.am
 
 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-## 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+## 2003, 2004, 2005, 2006, 2007 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
@@ -349,8 +349,8 @@ dist-info: $(INFO_DEPS)
            if test -f $$file; then \
 ## Strip leading '$$d/'.
              relfile=`expr "$$file" : "$$d/\(.*\)"`; \
-             test -f $(distdir)/$$relfile || \
-               cp -p $$file $(distdir)/$$relfile; \
+             test -f "$(distdir)/$$relfile" || \
+               cp -p $$file "$(distdir)/$$relfile"; \
            else :; fi; \
          done; \
        done




reply via email to

[Prev in Thread] Current Thread [Next in Thread]