automake-patches
[Top][All Lists]
Advanced

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

Avoid getting bitten by CDPATH


From: Ralf Wildenhues
Subject: Avoid getting bitten by CDPATH
Date: Sun, 31 Aug 2008 09:56:33 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

I'm not sure whether this patch is (at least partly) overkill,
so I'd be glad about some feedback on this; thanks.

When the user has CDPATH set, a 'cd $dir' may end up someplace
unwanted (plus produce extraneous output), iff $dir is a relative
directory not beginning with a dot.

Now, the part I'm sure should be fixed is all the $(SUBDIRS)
iterations.  As in: if the user has 'SUBDIRS = sub' but for
some reason $builddir/sub does not exist, we shouldn't wind
up anywhere else, but be sure to fail.

The not-so-sure part is about $(srcdir) and $(top_srcdir).
These usually are either absolute paths, or begin with a dot,
except for when the build tree is a super directory of the
source tree:
  sub/configure ...
  make

This is AFAIK a fairly unusual setup, but there is no particular
reason it shouldn't otherwise work fine.  Do you think we should
cater for this case?

FWIW, $(top_builddir) always begins with a dot, so it's safe.
FWIW2, $(DESTDIR) can be empty, but is typically followed by
an absolute directory name.

Since this is a rather minor issue, I intend this for master only.

Cheers,
Ralf

    For all possibly-relative subdirs, use $(am__cd).
    
    Up to now, $(am__cd) was only used within backquotes, to avoid
    extraneous output.  This patch also uses it for every `cd' to a
    relative subdir, to prevent CDPATH from entering an unwanted
    directory.
    
    * Makefile.am (maintainer-check): Fix current check for
    $(am__cd) within backquotes a bit.  Add new check for `cd' to a
    relative subdir.
    * automake.in (handle_tags, handle_configure):  Adjust rules.
    * lib/am/ansi2knr.am: Likewise.
    * lib/am/configure.am: Likewise.
    * lib/am/distdir.am: Likewise.
    * lib/am/remake-hdr.am: Likewise.
    * lib/am/subdirs.am: Likewise.
    * lib/am/tags.am: Likewise.
    * lib/am/texibuild.am: Likewise.
    
    Signed-off-by: Ralf Wildenhues <address@hidden>

diff --git a/HACKING b/HACKING
index 3be23bc..5e7191f 100644
--- a/HACKING
+++ b/HACKING
@@ -64,6 +64,9 @@
 
 * Do not use `cd' within back-quotes, use `$(am__cd)' instead.
   Otherwise the directory name may be printed, depending on CDPATH.
+  More generally, do not ever use plain `cd' together with a relative
+  directory that does not start with a dot, or you might end up in one
+  computed with CDPATH.
 
 * For install and uninstall rules, if a loop is required, it should be
   silent.  Then the body of the loop itself should print each
diff --git a/Makefile.am b/Makefile.am
index 7fc1fd9..2589adc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -164,7 +164,21 @@ maintainer-check: automake aclocal
 ## Look for cd within backquotes
        @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in \
              $(srcdir)/lib/am/*.am; then \
-         echo "Consider using $$$$(am__cd) in the line above." 1>&2; \
+         echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
+         exit 1; \
+       fi
+## Look for cd to a relative directory (may be influenced by CDPATH).
+## Skip some known directories that are OK.
+       @if grep -n '^[^#]*cd ' $(srcdir)/automake.in \
+             $(srcdir)/lib/am/*.am | \
+             grep -v 'echo.*cd ' | \
+             grep -v 'am__cd =' | \
+             grep -v '^[^#]*cd [./]' | \
+             grep -v '^[^#]*cd \$$(top_builddir)' | \
+             grep -v '^[^#]*cd "\$$\$$am__cwd' | \
+             grep -v '^[^#]*cd \$$(abs' | \
+             grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
+         echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
          exit 1; \
        fi
 ## Using @_ in a scalar context is most probably a programming error.
diff --git a/automake.in b/automake.in
index c49045f..baaac96 100755
--- a/automake.in
+++ b/automake.in
@@ -3521,7 +3521,7 @@ sub handle_tags
                          . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do 
\\\n"
                          # Never fail here if a subdir fails; it
                          # isn't important.
-                         . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
+                         . "\t  test \"\$\$subdir\" = . || (\$(am__cd) 
\$\$subdir"
                          . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
                          . "\tdone\n");
        push (@tag_deps, 'tags-recursive');
@@ -3531,7 +3531,7 @@ sub handle_tags
                          . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do 
\\\n"
                          # Never fail here if a subdir fails; it
                          # isn't important.
-                         . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
+                         . "\t  test \"\$\$subdir\" = . || (\$(am__cd) 
\$\$subdir"
                          . " && \$(MAKE) \$(AM_MAKEFLAGS) ctags); \\\n"
                          . "\tdone\n");
        push (@ctag_deps, 'ctags-recursive');
diff --git a/lib/am/ansi2knr.am b/lib/am/ansi2knr.am
index 7dafd1e..ee106c5 100644
--- a/lib/am/ansi2knr.am
+++ b/lib/am/ansi2knr.am
@@ -1,5 +1,5 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994, 1995, 1996, 1997, 2001, 2003
+## Copyright (C) 1994, 1995, 1996, 1997, 2001, 2003, 2008
 ## Free Software Foundation, Inc.
 
 ## This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,7 @@ if %?ANSI2KNR-DIR%
 
 ANSI2KNR = %ANSI2KNR-DIR%/ansi2knr
 %ANSI2KNR-DIR%/ansi2knr:
-       cd %ANSI2KNR-DIR% && $(MAKE) $(AM_MAKEFLAGS) ./ansi2knr
+       $(am__cd) %ANSI2KNR-DIR% && $(MAKE) $(AM_MAKEFLAGS) ./ansi2knr
 
 else !%?ANSI2KNR-DIR%
 
diff --git a/lib/am/configure.am b/lib/am/configure.am
index 4623f41..e24e9a6 100644
--- a/lib/am/configure.am
+++ b/lib/am/configure.am
@@ -40,7 +40,7 @@ endif %?TOPDIR_P%
          case '$(am__configure_deps)' in \
            *$$dep*) \
 ?TOPDIR_P?           echo ' cd $(srcdir) && $(AUTOMAKE) --%STRICTNESS% 
%USE-DEPS%'; \
-?TOPDIR_P?           cd $(srcdir) && $(AUTOMAKE) --%STRICTNESS% %USE-DEPS% \
+?TOPDIR_P?           $(am__cd) $(srcdir) && $(AUTOMAKE) --%STRICTNESS% 
%USE-DEPS% \
 ?TOPDIR_P?             && exit 0; \
 ?!TOPDIR_P?          ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) 
am--refresh ) \
 ## If on the other hand, subdir/Makefile.in has been removed, then toplevel
@@ -53,7 +53,7 @@ endif %?TOPDIR_P%
        done; \
 ## Otherwise, rebuild only this file.
        echo ' cd $(top_srcdir) && $(AUTOMAKE) --%STRICTNESS% %USE-DEPS% 
%MAKEFILE-AM-SOURCES%'; \
-       cd $(top_srcdir) && \
+       $(am__cd) $(top_srcdir) && \
          $(AUTOMAKE) --%STRICTNESS% %USE-DEPS% %MAKEFILE-AM-SOURCES%
 
 ## Ensure that GNU make doesn't remove Makefile if ./config.status (below)
@@ -102,7 +102,7 @@ $(top_builddir)/config.status: $(top_srcdir)/configure 
$(CONFIG_STATUS_DEPENDENC
 ?!TOPDIR_P?    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
 $(top_srcdir)/configure: %MAINTAINER-MODE% $(am__configure_deps)
-?TOPDIR_P?     cd $(srcdir) && $(AUTOCONF)
+?TOPDIR_P?     $(am__cd) $(srcdir) && $(AUTOCONF)
 ?!TOPDIR_P?    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
 
@@ -119,7 +119,7 @@ $(top_srcdir)/configure: %MAINTAINER-MODE% 
$(am__configure_deps)
 ## the $(am__configure_deps) dependency.
 if %?REGEN-ACLOCAL-M4%
 $(ACLOCAL_M4): %MAINTAINER-MODE% $(am__aclocal_m4_deps)
-?TOPDIR_P?     cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
+?TOPDIR_P?     $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
 ?!TOPDIR_P?    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
 ## Avoid the "deleted header file" problem for the dependencies.
diff --git a/lib/am/distdir.am b/lib/am/distdir.am
index 825b561..41e9b2b 100644
--- a/lib/am/distdir.am
+++ b/lib/am/distdir.am
@@ -1,6 +1,6 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007  Free Software
-## Foundation, Inc.
+## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008  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
@@ -206,7 +206,7 @@ if %?SUBDIRS%
            dir1=$$subdir; dir2="$(top_distdir)"; \
            $(am__relativize); \
            new_top_distdir=$$reldir; \
-           (cd $$subdir && \
+           ($(am__cd) $$subdir && \
              $(MAKE) $(AM_MAKEFLAGS) \
                top_distdir="$$new_top_distdir" \
                distdir="$$new_distdir" \
@@ -390,7 +390,7 @@ distcheck: dist
 ## create very long directory names.
          && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
 ?DISTCHECK-HOOK?         && $(MAKE) $(AM_MAKEFLAGS) distcheck-hook \
-         && cd $(distdir)/_build \
+         && $(am__cd) $(distdir)/_build \
          && ../configure --srcdir=.. --prefix="$$dc_install_base" \
 ?GETTEXT?          --with-included-gettext \
 ## Additional flags for configure.  Keep this last in the configure
@@ -440,7 +440,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)' \
+       @$(am__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/remake-hdr.am b/lib/am/remake-hdr.am
index 421a982..c1bc42f 100644
--- a/lib/am/remake-hdr.am
+++ b/lib/am/remake-hdr.am
@@ -35,7 +35,7 @@
 ## by autoheader.
 if %?FIRST%
 %CONFIG_HIN%: %MAINTAINER-MODE% $(am__configure_deps) %FILES%
-       cd $(top_srcdir) && $(AUTOHEADER)
+       $(am__cd) $(top_srcdir) && $(AUTOHEADER)
 ## Whenever $(AUTOHEADER) has run, we must make sure that
 ## ./config.status will rebuild config.h.  The dependency from %STAMP%
 ## on %CONFIG_H_DEPS% (which contains config.hin) is not enough to
diff --git a/lib/am/subdirs.am b/lib/am/subdirs.am
index 83ad257..1888042 100644
--- a/lib/am/subdirs.am
+++ b/lib/am/subdirs.am
@@ -1,6 +1,6 @@
 ## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004
-## Free Software Foundation, Inc.
+## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
+## 2004, 2008 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
@@ -49,7 +49,7 @@ $(RECURSIVE_TARGETS):
          else \
            local_target="$$target"; \
          fi; \
-         (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+         ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
          || eval $$failcom; \
        done; \
        if test "$$dot_seen" = "no"; then \
@@ -102,6 +102,6 @@ $(RECURSIVE_CLEAN_TARGETS):
          else \
            local_target="$$target"; \
          fi; \
-         (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+         ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
          || eval $$failcom; \
        done && test -z "$$fail"
diff --git a/lib/am/tags.am b/lib/am/tags.am
index 191274d..a654ec8 100644
--- a/lib/am/tags.am
+++ b/lib/am/tags.am
@@ -124,7 +124,7 @@ CTAGS: %CTAGSDIRS% $(HEADERS) $(SOURCES) %CONFIG% 
$(TAGS_DEPENDENCIES) \
 .PHONY: GTAGS
 GTAGS:
        here=`$(am__cd) $(top_builddir) && pwd` \
-         && cd $(top_srcdir) \
+         && $(am__cd) $(top_srcdir) \
          && gtags -i $(GTAGS_ARGS) "$$here"
 
 
diff --git a/lib/am/texibuild.am b/lib/am/texibuild.am
index ac49073..aafa081 100644
--- a/lib/am/texibuild.am
+++ b/lib/am/texibuild.am
@@ -1,6 +1,6 @@
 ## automake - create Makefile.in from Makefile.am
 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-##   2003, 2004, 2005  Free Software Foundation, Inc.
+##   2003, 2004, 2005, 2008  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
@@ -33,7 +33,7 @@
 ##    developer while he writes documentation.)
 ## *.iNN files are used on DJGPP.  See the comments in install-info-am
        restore=: && backupdir="$(am__leading_dot)am$$$$" && \
-?INSRC?        am__cwd=`pwd` && cd $(srcdir) && \
+?INSRC?        am__cwd=`pwd` && $(am__cd) $(srcdir) && \
        rm -rf $$backupdir && mkdir $$backupdir && \
 ## If makeinfo is not installed we must not backup the files so
 ##`missing' can do its job and touch $@ if it exists.
@@ -49,11 +49,11 @@
 ?INSRC??GENERIC_INFO?   -o $@ $<; \
        then \
          rc=0; \
-?INSRC?          cd $(srcdir); \
+?INSRC?          $(am__cd) $(srcdir); \
        else \
          rc=$$?; \
 ## Beware that backup info files might come from a subdirectory.
-?INSRC?          cd $(srcdir) && \
+?INSRC?          $(am__cd) $(srcdir) && \
          $$restore $$backupdir/* `echo "./$@" | sed 's|[^/]*$$||'`; \
        fi; \
        rm -rf $$backupdir; exit $$rc




reply via email to

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