Currently, every decent non-GNU make program makes it possible to remake out-of-date autotools-generated files with a simple "make Makefile" issued from the top-level directory. And while having to run "make Makefile" by hand isn't as convenient as the GNU make feature of "automatic remake *and reloading* of out-of-date makefiles", it is usually good enough and definitely worth having.
Unfortunately, a silly limitation in the current implementation of remake rules prevents this idiom from working when it's used outside the top-level directory. Luckily, this limitation is easy to remove, and that's what this patch does. * lib/am/configure.am (am--refresh): Depend on `%MAKEFILE%'. * tests/defs.in (using_gmake): New function, backported from the `master' branch (and simplified). * tests/remake-subdir.test: New test. * tests/remake-subdir2.test: Likewise. * tests/remake-subdir-gnu.test: Likewise. * tests/remake-subdir-from-subdir.test: Likewise. * tests/Makefile.am (TESTS): Update. --- ChangeLog | 23 +++++++++ lib/am/configure.am | 2 +- tests/Makefile.am | 4 ++ tests/Makefile.in | 4 ++ tests/defs.in | 10 ++++ tests/remake-subdir-from-subdir.test | 56 +++++++++++++++++++++++ tests/remake-subdir-gnu.test | 80 +++++++++++++++++++++++++++++++++ tests/remake-subdir.test | 81 +++++++++++++++++++++++++++++++++ tests/remake-subdir2.test | 82 ++++++++++++++++++++++++++++++++++ 9 files changed, 341 insertions(+), 1 deletions(-) create mode 100755 tests/remake-subdir-from-subdir.test create mode 100755 tests/remake-subdir-gnu.test create mode 100755 tests/remake-subdir.test create mode 100755 tests/remake-subdir2.test diff --git a/ChangeLog b/ChangeLog index 3631129..40daff3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2011-05-29 Stefano Lattarini <stefano.lattar...@gmail.com> + + remake: behave better with non-GNU make in subdirectories + Currently, every decent non-GNU make program makes it possible + to remake out-of-date autotools-generated files with a simple + "make Makefile" issued from the top-level directory. And while + having to run "make Makefile" by hand isn't as convenient as + the GNU make feature of "automatic remake *and reloading* of + out-of-date makefiles", it is usually good enough and definitely + worth having. + Unfortunately, a silly limitation in the current implementation + of remake rules prevents this idiom from working when it's used + outside the top-level directory. Luckily, this limitation is + easy to remove, and that's what this patch does. + * lib/am/configure.am (am--refresh): Depend on `%MAKEFILE%'. + * tests/defs.in (using_gmake): New function, backported from the + `master' branch (and simplified). + * tests/remake-subdir.test: New test. + * tests/remake-subdir2.test: Likewise. + * tests/remake-subdir-gnu.test: Likewise. + * tests/remake-subdir-from-subdir.test: Likewise. + * tests/Makefile.am (TESTS): Update. + 2011-05-20 Stefano Lattarini <stefano.lattar...@gmail.com> testsuite: avoid re-running few tests with 'parallel-tests' option diff --git a/lib/am/configure.am b/lib/am/configure.am index e9299d6..d00846a 100644 --- a/lib/am/configure.am +++ b/lib/am/configure.am @@ -22,7 +22,7 @@ ## %MAKEFILE% is updated before considering the am--refresh target. if %?TOPDIR_P% .PHONY: am--refresh -am--refresh: +am--refresh: %MAKEFILE% @: endif %?TOPDIR_P% diff --git a/tests/Makefile.am b/tests/Makefile.am index 49d8942..33ae8bc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -654,6 +654,10 @@ remake4.test \ remake5.test \ remake6.test \ remake7.test \ +remake-subdir-from-subdir.test \ +remake-subdir-gnu.test \ +remake-subdir.test \ +remake-subdir2.test \ pr8365-remake-timing.test \ regex.test \ req.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 110d13b..ad45cff 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -922,6 +922,10 @@ remake4.test \ remake5.test \ remake6.test \ remake7.test \ +remake-subdir-from-subdir.test \ +remake-subdir-gnu.test \ +remake-subdir.test \ +remake-subdir2.test \ pr8365-remake-timing.test \ regex.test \ req.test \ diff --git a/tests/defs.in b/tests/defs.in index e020498..1a72391 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -513,6 +513,16 @@ is_newest () test -z "$is_newest_files" } +# using_gmake +# ----------- +# Return success if $MAKE is GNU make, return failure otherwise. +using_gmake () +{ + # Use --version AND -v, because SGI Make doesn't fail on --version. + # Also grep for GNU because newer versions of FreeBSD make do + # not complain about `--version' (they seem to silently ignore it). + $MAKE --version -v | grep GNU +} # AUTOMAKE_run status [options...] # -------------------------------- diff --git a/tests/remake-subdir-from-subdir.test b/tests/remake-subdir-from-subdir.test new file mode 100755 index 0000000..1e369f8 --- /dev/null +++ b/tests/remake-subdir-from-subdir.test @@ -0,0 +1,56 @@ +#! /bin/sh +# Copyright (C) 2009 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, see <http://www.gnu.org/licenses/>. + +# Check that remake rules works for adding a new subdirectory from a +# pre-existing subdirectory. + +. ./defs || Exit 1 + +set -e + +cat >> configure.in <<'END' +m4_include([subdirs.m4]) +AC_SUBST([MAGIC], [magic]) +AC_OUTPUT +END + +echo 'AC_CONFIG_FILES([sub/Makefile])' > subdirs.m4 +echo 'SUBDIRS = sub' > Makefile.am + +mkdir sub +: > sub/Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE + +cd sub +$sleep +echo 'AC_CONFIG_FILES([sub/subsub/Makefile])' >> ../subdirs.m4 +echo 'SUBDIRS = subsub' >> Makefile.am +mkdir subsub +cat > subsub/Makefile.am <<'END' +all-local: + : > ok-it-works +END +using_gmake || $MAKE Makefile +$MAKE +test -f subsub/ok-it-works + +: diff --git a/tests/remake-subdir-gnu.test b/tests/remake-subdir-gnu.test new file mode 100755 index 0000000..cc683f3 --- /dev/null +++ b/tests/remake-subdir-gnu.test @@ -0,0 +1,80 @@ +#! /bin/sh +# Copyright (C) 2011 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, see <http://www.gnu.org/licenses/>. + +# Check that remake rules works from subdirectories, even using +# `GNUmakefile' as makefiles name. This obviously requires GNU +# make. + +required=GNUmake +. ./defs || Exit 1 + +set -e + +magic1='::MagicString::One::' +magic2='__MagicString__Two__' + +debug_info () +{ + grep -i magic configure GNUmakefile.in GNUmakefile \ + sub/GNUmakefile.in sub/GNUmakefile +} + +cat > configure.in <<END +AC_INIT([$me], [1.0]) +AM_INIT_AUTOMAKE +AC_CONFIG_FILES([GNUmakefile sub/GNUmakefile]) +AC_SUBST([MAGIC], [magic]) +AC_OUTPUT +END + +cat > GNUmakefile.am <<'END' +SUBDIRS = sub +END + +mkdir sub +: > sub/GNUmakefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE +debug_info + +$sleep +sed "s|magic|$magic1|" configure.in > t +mv -f t configure.in +cd sub +$MAKE +cd .. +debug_info +$FGREP $magic1 configure +$FGREP $magic1 GNUmakefile +$FGREP $magic1 sub/GNUmakefile + +$sleep +cd sub +echo MAGIC = $magic2 >> GNUmakefile.am +$MAKE +cd .. +debug_info +$FGREP $magic2 sub/GNUmakefile +$FGREP $magic2 sub/GNUmakefile.in +$FGREP $magic1 sub/GNUmakefile sub/GNUmakefile.in && Exit 1 +$FGREP $magic2 GNUmakefile GNUmakefile.in && Exit 1 + +: diff --git a/tests/remake-subdir.test b/tests/remake-subdir.test new file mode 100755 index 0000000..5bbc345 --- /dev/null +++ b/tests/remake-subdir.test @@ -0,0 +1,81 @@ +#! /bin/sh +# Copyright (C) 2011 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, see <http://www.gnu.org/licenses/>. + +# Check that remake rules works from subdirectories, even with non-GNU +# make implementations. + +. ./defs || Exit 1 + +set -e + +if using_gmake; then + remake=$MAKE +else + remake="$MAKE Makefile" +fi + +magic1='::MagicString::One::' +magic2='__MagicString__Two__' + +debug_info () +{ + grep -i magic configure Makefile.in Makefile sub/Makefile.in sub/Makefile +} + +cat >> configure.in <<'END' +AC_CONFIG_FILES([sub/Makefile]) +AC_SUBST([MAGIC], [magic]) +AC_OUTPUT +END + +cat > Makefile.am <<'END' +SUBDIRS = sub +END + +mkdir sub +: > sub/Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE +debug_info + +$sleep +sed "s|magic|$magic1|" configure.in > t +mv -f t configure.in +cd sub +$remake +cd .. +debug_info +$FGREP $magic1 configure +$FGREP $magic1 Makefile +$FGREP $magic1 sub/Makefile + +$sleep +cd sub +echo MAGIC = $magic2 >> Makefile.am +$remake +cd .. +debug_info +$FGREP $magic2 sub/Makefile +$FGREP $magic2 sub/Makefile.in +$FGREP $magic1 sub/Makefile sub/Makefile.in && Exit 1 +$FGREP $magic2 Makefile Makefile.in && Exit 1 + +: diff --git a/tests/remake-subdir2.test b/tests/remake-subdir2.test new file mode 100755 index 0000000..52ed6ba --- /dev/null +++ b/tests/remake-subdir2.test @@ -0,0 +1,82 @@ +#! /bin/sh +# Copyright (C) 2011 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, see <http://www.gnu.org/licenses/>. + +# Check that remake rules works from subdirectories, even when makefiles +# are not named "Makefile". + +. ./defs || Exit 1 + +set -e + +magic1='::MagicString::One::' +magic2='__MagicString__Two__' + +debug_info () +{ + grep -i magic configure build.in build.mk sub/build.in sub/build.mk +} + +cat > configure.in <<END +AC_INIT([$me], [1.0]) +AM_INIT_AUTOMAKE +AC_CONFIG_FILES([build.mk:build.in]) +AC_CONFIG_FILES([sub/build.mk:sub/build.in]) +AC_SUBST([MAGIC], [magic]) +AC_OUTPUT +END + +cat > build.am <<'END' +AM_MAKEFLAGS = -f build.mk +SUBDIRS = sub +END + +mkdir sub +cat > sub/build.am <<'END' +AM_MAKEFLAGS = -f build.mk +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE +./configure +ls -l # For debugging. + +$MAKE -f build.mk +debug_info + +$sleep +sed "s|magic|$magic1|" configure.in > t +mv -f t configure.in +cd sub +$MAKE -f build.mk build.mk +cd .. +debug_info +$FGREP $magic1 configure +$FGREP $magic1 build.mk +$FGREP $magic1 sub/build.mk + +$sleep +cd sub +echo MAGIC = $magic2 >> build.am +$MAKE -f build.mk build.mk +cd .. +debug_info +$FGREP $magic2 sub/build.mk +$FGREP $magic2 sub/build.in +$FGREP $magic1 sub/build.in sub/build.mk && Exit 1 +$FGREP $magic2 build.in build.mk && Exit 1 + +: -- 1.7.2.3