From: Stefano Lattarini Date: Mon, 18 Jun 2012 14:17:17 +0000 (+0200) Subject: [ng] general: simpler workaround for CDPATH issues X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d02bf85a2b851f7519d96dafaa6e9b1f1588bad;p=thirdparty%2Fautomake.git [ng] general: simpler workaround for CDPATH issues With this change, we also get rid of the $(am__cd) make variable. * lib/am/header-vars.am (am__cd): Remove. To ensure a CDPATH exported in the environment doesn't interfere with our scripts and recipes, we can simply un-export it here (using the GNU make "unexport" directive), rather than having to rely on $(am__cd) ... * Makefile.am, automake.in, lib/am/configure.am, lib/am/distdir.am, lib/am/header-vars.am, lib/am/inst-vars.am, lib/am/remake-hdr.am, lib/am/tags.am, lib/am/texibuild.am, t/ax/distcheck-hook-m4.am: ... in several places of these files. * GNUmakefile, HACKING: Adjust. * syntax-checks.mk (sc_cd_in_backquotes, sc_cd_relative_dir): Remove, superseded by ... (sc_no_am_cd): ... this new target, which has contrary semantics, and looks *against* the use of the now-obsolete $(am__cd). (syntax_check_rules): Adjust. Signed-off-by: Stefano Lattarini --- diff --git a/GNUmakefile b/GNUmakefile index d814dfe41..5890be6ec 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -34,8 +34,8 @@ endif # To allow bootstrapping also in an unconfigured tree. srcdir ?= . -am__cd ?= CDPATH=. && unset CDPATH && cd V ?= 0 +unexport CDPATH ifeq ($(V),0) AM_V_BOOTSTRAP = @echo " BOOTSTRAP"; @@ -50,7 +50,7 @@ endif # Must be phony, not to be confused with the 'bootstrap' script. .PHONY: bootstrap bootstrap: - $(AM_V_BOOTSTRAP)$(am__cd) $(srcdir) && ./bootstrap.sh + $(AM_V_BOOTSTRAP)cd $(srcdir) && ./bootstrap.sh $(AM_V_CONFIGURE)set -e; \ am__bootstrap_configure () { \ $(srcdir)/configure $${1+"$$@"} $(BOOTSTRAP_CONFIGURE_FLAGS); \ diff --git a/HACKING b/HACKING index 696638447..c15718f55 100644 --- a/HACKING +++ b/HACKING @@ -64,12 +64,6 @@ * Never use basename or dirname. Instead use sed. -* 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 "important" command it runs. The printed commands should be preceded diff --git a/Makefile.am b/Makefile.am index 532a5fdfa..59aa1f60a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -503,7 +503,7 @@ $(srcdir)/doc/amhello-1.0.tar.gz: $(amhello_sources) $(srcdir)/configure.ac $(AM_V_GEN): \ && PATH="$(abs_top_builddir)/t/wrap$(PATH_SEPARATOR)$$PATH" \ && export PATH \ - && $(am__cd) $(srcdir)/doc/amhello \ + && cd $(srcdir)/doc/amhello \ && ACLOCAL=aclocal-$(APIVERSION) && export ACLOCAL \ && AUTOMAKE=automake-$(APIVERSION) && export AUTOMAKE \ && AUTOCONF='$(am_AUTOCONF)' && export AUTOCONF \ @@ -591,7 +591,7 @@ ChangeLog: # Ensure tests are world-executable. # FIXME: this should be turned into a maintainer check... dist-hook: - $(am__cd) $(distdir)/t && chmod a+rx *.sh *.tap + cd $(distdir)/t && chmod a+rx *.sh *.tap ## --------------------------- ## @@ -712,14 +712,14 @@ autodiffs: rev=$$1 dir=$$2 \ && echo "$@: will get files from revision $$rev" \ && $(GIT) clone -q --depth 1 "$$am_gitdir" tmp \ - && $(am__cd) tmp \ + && cd tmp \ && $(GIT) checkout -q "$$rev" \ && echo "$@: bootstrapping $$rev" \ && $(SHELL) ./bootstrap.sh \ && echo "$@: copying files from $$rev" \ && makefile_ins=`find . -name Makefile.in` \ && (tar cf - configure aclocal.m4 $$makefile_ins) | \ - (cd .. && $(am__cd) "$$dir" && tar xf -) \ + (cd .. && cd "$$dir" && tar xf -) \ && cd .. \ && rm -rf tmp; \ }; \ @@ -729,7 +729,7 @@ autodiffs: && $(GIT) --git-dir="$$am_gitdir" describe $$NEW_COMMIT >/dev/null \ && rm -rf $$outdir \ && mkdir $$outdir \ - && $(am__cd) $$outdir \ + && cd $$outdir \ && mkdir new old \ && get_autofiles_from_rev $$OLD_COMMIT old \ && get_autofiles_from_rev $$NEW_COMMIT new \ @@ -796,7 +796,7 @@ fetch: rm -rf Fetchdir > /dev/null 2>&1 mkdir Fetchdir ## If a get fails then that is a problem. - ($(am__cd) Fetchdir && \ + (cd Fetchdir && \ $(WGET_SV_GIT_CF)config.guess -O config.guess && \ $(WGET_SV_GIT_CF)config.sub -O config.sub && \ $(WGET_SV_CVS)texinfo/texinfo/doc/texinfo.tex -O texinfo.tex && \ diff --git a/automake.in b/automake.in index 63de0273e..b518ffa77 100644 --- a/automake.in +++ b/automake.in @@ -3302,7 +3302,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\" = . || (\$(am__cd) \$\$subdir" + . "\t test \"\$\$subdir\" = . || (cd \$\$subdir" . " && \$(MAKE) tags); \\\n" . "\tdone\n"); push (@tag_deps, 'tags-recursive'); @@ -3312,7 +3312,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\" = . || (\$(am__cd) \$\$subdir" + . "\t test \"\$\$subdir\" = . || (cd \$\$subdir" . " && \$(MAKE) ctags); \\\n" . "\tdone\n"); push (@ctag_deps, 'ctags-recursive'); @@ -3322,7 +3322,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\" = . || (\$(am__cd) \$\$subdir" + . "\t test \"\$\$subdir\" = . || (cd \$\$subdir" . " && \$(MAKE) cscopelist); \\\n" . "\tdone\n"); push (@cscope_deps, 'cscopelist-recursive'); @@ -5037,7 +5037,7 @@ sub lang_vala_finish_target ($$) # Thus we need to create the stamp file *before* invoking valac, and to # move it to its final location only after valac has been invoked. "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n". - "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n". + "\t${verbose}cd \$(srcdir) && $compile @vala_sources\n". "\t${silent}mv -f \$\@-t \$\@\n"; push_dist_common ($stampfile); diff --git a/lib/am/configure.am b/lib/am/configure.am index ac816c460..f9d604a30 100644 --- a/lib/am/configure.am +++ b/lib/am/configure.am @@ -38,7 +38,7 @@ endif %?TOPDIR_P% case '$(am__configure_deps)' in \ *$$dep*) \ ?TOPDIR_P? echo ' cd $(srcdir) && $(AUTOMAKE) %AUTOMAKE-OPTIONS%'; \ -?TOPDIR_P? $(am__cd) $(srcdir) && $(AUTOMAKE) %AUTOMAKE-OPTIONS% \ +?TOPDIR_P? cd $(srcdir) && $(AUTOMAKE) %AUTOMAKE-OPTIONS% \ ?TOPDIR_P? && exit 0; \ ?!TOPDIR_P? ( cd $(top_builddir) && $(MAKE) am--refresh ) \ ## If on the other hand, subdir/Makefile.in has been removed, then toplevel @@ -51,7 +51,7 @@ endif %?TOPDIR_P% done; \ ## Otherwise, rebuild only this file. echo ' cd $(top_srcdir) && $(AUTOMAKE) %AUTOMAKE-OPTIONS% %MAKEFILE-AM-SOURCES%'; \ - $(am__cd) $(top_srcdir) && \ + cd $(top_srcdir) && \ $(AUTOMAKE) %AUTOMAKE-OPTIONS% %MAKEFILE-AM-SOURCES% ## Ensure that GNU make doesn't remove Makefile if ./config.status (below) @@ -101,7 +101,7 @@ $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENC ?!TOPDIR_P? cd $(top_builddir) && $(MAKE) am--refresh $(top_srcdir)/configure: %MAINTAINER-MODE% $(am__configure_deps) -?TOPDIR_P? $(am__cd) $(srcdir) && $(AUTOCONF) +?TOPDIR_P? cd $(srcdir) && $(AUTOCONF) ?!TOPDIR_P? cd $(top_builddir) && $(MAKE) am--refresh @@ -118,7 +118,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? $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +?TOPDIR_P? cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) ?!TOPDIR_P? cd $(top_builddir) && $(MAKE) am--refresh ## Avoid the "deleted header file" problem for the dependencies. diff --git a/lib/am/distdir.am b/lib/am/distdir.am index 1e5f9022e..51cd80a0a 100644 --- a/lib/am/distdir.am +++ b/lib/am/distdir.am @@ -238,7 +238,7 @@ if %?SUBDIRS% new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ - ($(am__cd) $$subdir && \ + (cd $$subdir && \ $(MAKE) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ @@ -448,13 +448,13 @@ distcheck: dist ## 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,^[^:\\/]:[\\/],/,'` \ + dc_install_base=`cd $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ ## We will attempt 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) distcheck-hook \ - && $(am__cd) $(distdir)/_build \ + && cd $(distdir)/_build \ && ../configure --srcdir=.. --prefix="$$dc_install_base" \ ?GETTEXT? --with-included-gettext \ ## Additional flags for configure. Keep this last in the configure @@ -515,7 +515,7 @@ distuninstallcheck: '$$(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ - $(am__cd) '$(distuninstallcheck_dir)' || { \ + cd '$(distuninstallcheck_dir)' || { \ echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am index 636713b9b..eccfec58c 100644 --- a/lib/am/header-vars.am +++ b/lib/am/header-vars.am @@ -60,6 +60,13 @@ ifdef SUBDIRS endif endif +# CDPATH is only useful in interactive usage, and should never be exported +# in the environment; doing so could cause our recipes and scripts to chdir +# to unexpected places, causing all sort of hard to reproduce mayhem. +# Still, but some people nonetheless export CDPATH (or did so in the past), +# so to be extra safe we have to neutralize it. +unexport CDPATH + # Be verbose by deafault. Yes, we really want $(V) to be overridable # from the environment, both for simplicity and for consistency with # mainline Automake. @@ -242,7 +249,6 @@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c diff --git a/lib/am/inst-vars.am b/lib/am/inst-vars.am index 3096f0a1e..f1b319be1 100644 --- a/lib/am/inst-vars.am +++ b/lib/am/inst-vars.am @@ -67,7 +67,7 @@ am__uninstall_files_from_dir = { \ ## is indeed desired and welcome (better to fail loudly thasn silently). || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ - $(am__cd) "$$dir" && rm -f $$files; }; \ + cd "$$dir" && rm -f $$files; }; \ } endif %?FIRST% diff --git a/lib/am/remake-hdr.am b/lib/am/remake-hdr.am index e4928e806..2bcf2df79 100644 --- a/lib/am/remake-hdr.am +++ b/lib/am/remake-hdr.am @@ -28,7 +28,7 @@ ## by autoheader. if %?FIRST% %CONFIG_HIN%: %MAINTAINER-MODE% $(am__configure_deps) - $(am__cd) $(top_srcdir) && $(AUTOHEADER) + 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/tags.am b/lib/am/tags.am index eadb9c01a..11a786f03 100644 --- a/lib/am/tags.am +++ b/lib/am/tags.am @@ -124,8 +124,8 @@ CTAGS: %CTAGSDIRS% $(TAGS_DEPENDENCIES) $(am__tagged_files) .PHONY: GTAGS GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ + here=`cd $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" diff --git a/lib/am/texibuild.am b/lib/am/texibuild.am index fd6a4b6bd..fcd40cff7 100644 --- a/lib/am/texibuild.am +++ b/lib/am/texibuild.am @@ -47,7 +47,7 @@ define am__texibuild_info ## to fail, the info files are not removed. (They are needed by the ## developer while he writes documentation.) $(AM_V_MAKEINFO)restore=: && backupdir=.am$$$$ && \ - $(if $1,am__cwd=`pwd` && $(am__cd) $(srcdir) &&) \ + $(if $1,am__cwd=`pwd` && 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. @@ -61,11 +61,11 @@ define am__texibuild_info -I $(@D) -I $(srcdir)/$(@D) -o $@ $<; \ then \ rc=0; \ - $(if $(am__info_insrc),$(am__cd) $(srcdir);) \ + $(if $(am__info_insrc),cd $(srcdir);) \ else \ rc=$$?; \ ## Beware that backup info files might come from a subdirectory. - $(if $(am__info_insrc),$(am__cd) $(srcdir) &&) \ + $(if $(am__info_insrc),cd $(srcdir) &&) \ $$restore $$backupdir/* $(@D); \ fi; \ rm -rf $$backupdir; exit $$rc diff --git a/syntax-checks.mk b/syntax-checks.mk index c71f1c48f..4c2135e38 100644 --- a/syntax-checks.mk +++ b/syntax-checks.mk @@ -51,8 +51,7 @@ sc_mkinstalldirs \ sc_pre_normal_post_install_uninstall \ sc_perl_no_undef \ sc_perl_no_split_regex_space \ -sc_cd_in_backquotes \ -sc_cd_relative_dir \ +sc_no_am_cd \ sc_perl_at_uscore_in_scalar_context \ sc_perl_local \ sc_AMDEP_TRUE_in_automake_in \ @@ -187,27 +186,19 @@ sc_perl_no_split_regex_space: exit 1; \ fi -## Look for cd within backquotes -sc_cd_in_backquotes: - @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \ - 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. -sc_cd_relative_dir: - @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \ - 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; \ +sc_no_am_cd: + @files="\ + $(xtests) \ + $(pms) \ + $(ams) \ + $(srcdir)/automake.in \ + $(srcdir)/doc/*.texi \ + "; \ + if grep -F 'am__cd' $$files; then \ + echo "Found uses of 'am__cd', which is obsolete" 1>&2; \ + echo "Using a simple 'cd' should be enough" 1>&2; \ exit 1; \ - fi + else :; fi ## Using @_ in a scalar context is most probably a programming error. sc_perl_at_uscore_in_scalar_context: diff --git a/t/ax/distcheck-hook-m4.am b/t/ax/distcheck-hook-m4.am index 5d36102c6..30b8760be 100644 --- a/t/ax/distcheck-hook-m4.am +++ b/t/ax/distcheck-hook-m4.am @@ -17,7 +17,7 @@ distcheck-hook: @fatal () { echo "$@: $$*" >&2; exit 1; }; \ - $(am__cd) $(distdir) && chmod u+w . && mkdir _m4 \ + cd $(distdir) && chmod u+w . && mkdir _m4 \ || fatal "cannot setup distdir"; \ $(ACLOCAL) -I _m4 $(ACLOCAL_AMFLAGS) --install --output=_am.m4 \ || fatal "cannot regenerate aclocal.m4"; \