Index: branches/GNU/src/gmake/tests/scripts/features/include
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/include	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/include	(revision 284)
@@ -3,5 +3,6 @@
 $description = "Test various forms of the GNU make `include' command.";
 
-$details = "Test include, -include, sinclude and various regressions involving them.
+$details = "\
+Test include, -include, sinclude and various regressions involving them.
 Test extra whitespace at the end of the include, multiple -includes and
 sincludes (should not give an error) and make sure that errors are reported
@@ -16,5 +17,5 @@
 print MAKEFILE <<EOF;
 \#Extra space at the end of the following file name
-include $makefile2                  
+include $makefile2
 all: ; \@echo There should be no errors for this makefile.
 
@@ -47,4 +48,6 @@
 &compare_output($answer, &get_logfile(1));
 
+$makefile = undef;
+
 # Try to build the "error" target; this will fail since we don't know
 # how to create makeit.mk, but we should also get a message (even though
@@ -52,10 +55,38 @@
 # see one during the makefile run phase).
 
-# The fix to this caused more problems than the error, so I removed it.
-# pds -- 22 Jan 2000
+run_make_test
+  ('
+-include foo.mk
+error: foo.mk ; @echo $@
+',
+   '',
+   "#MAKE#: *** No rule to make target `foo.mk', needed by `error'.  Stop.\n",
+   512
+  );
 
-#&run_make_with_options($makefile, "error", &get_logfile, 512);
-#$answer = "$make_name: *** No rule to make target `makeit.mk', needed by `error'.\n";
-#&compare_output($answer, &get_logfile(1));
+# Make sure that target-specific variables don't impact things.  This could
+# happen because a file record is created when a target-specific variable is
+# set.
+
+run_make_test
+  ('
+bar.mk: foo := baz
+-include bar.mk
+hello: ; @echo hello
+',
+   '',
+   "hello\n"
+  );
+
+# Test inheritance of dontcare flag when rebuilding makefiles.
+#
+run_make_test('
+.PHONY: all
+all: ; @:
+
+-include foo
+
+foo: bar; @:
+', '', '');
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/features/order_only
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/order_only	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/order_only	(revision 284)
@@ -145,3 +145,14 @@
 unlink(qw(foo.w foo.x baz));
 
+# TEST #9 -- make sure that $< is set correctly in the face of order-only
+# prerequisites in pattern rules.
+
+run_make_test('
+%r: | baz ; @echo $< $^ $|
+bar: foo
+foo:;@:
+baz:;@:
+', '', "foo foo baz\n");
+
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/features/parallelism
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/parallelism	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/parallelism	(revision 284)
@@ -27,42 +27,22 @@
 }
 
-open(MAKEFILE,"> $makefile");
 
-print MAKEFILE <<"EOF";
+run_make_test("
 all : def_1 def_2 def_3
 def_1 : ; \@echo ONE; $sleep_command 3 ; echo TWO
 def_2 : ; \@$sleep_command 2 ; echo THREE
-def_3 : ; \@$sleep_command 1 ; echo FOUR
-EOF
-
-close(MAKEFILE);
-
-&run_make_with_options($makefile, "-j 4", &get_logfile);
-$answer = "ONE\nFOUR\nTHREE\nTWO\n";
-&compare_output($answer, &get_logfile(1));
-
+def_3 : ; \@$sleep_command 1 ; echo FOUR",
+              '-j4', "ONE\nFOUR\nTHREE\nTWO");
 
 # Test parallelism with included files.  Here we sleep/echo while
 # building the included files, to test that they are being built in
 # parallel.
-
-$makefile2 = &get_tmpfile;
-
-open(MAKEFILE,"> $makefile2");
-
-print MAKEFILE <<"EOF";
+run_make_test("
 all: 1 2; \@echo success
-
 -include 1.inc 2.inc
-
-1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@
-2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@
-EOF
-
-close(MAKEFILE);
-
-&run_make_with_options("$makefile2", "-j 4", &get_logfile);
-$answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n";
-&compare_output($answer, &get_logfile(1));
+1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
+2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
+              "-j4",
+              "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
 
 unlink('1.inc', '2.inc');
@@ -71,12 +51,6 @@
 # Test parallelism with included files--this time recurse first and make
 # sure the jobserver works.
-
-$makefile3 = &get_tmpfile;
-
-open(MAKEFILE,"> $makefile3");
-
-print MAKEFILE <<"EOF";
-recurse: ; \@\$(MAKE) --no-print-directory -f $makefile3 INC=yes all
-
+run_make_test("
+recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
 all: 1 2; \@echo success
 
@@ -86,15 +60,27 @@
 endif
 
-1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@
-2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@
-EOF
-
-close(MAKEFILE);
-
-&run_make_with_options("$makefile3", "-j 4", &get_logfile);
-$answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n";
-&compare_output($answer, &get_logfile(1));
+1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
+2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
+              "-j4",
+              "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
 
 unlink('1.inc', '2.inc');
 
+# Grant Taylor reports a problem where tokens can be lost (not written back
+# to the pipe when they should be): this happened when there is a $(shell ...)
+# function in an exported recursive variable.  I added some code to check
+# for this situation and print a message if it occurred.  This test used
+# to trigger this code when I added it but no longer does after the fix.
+
+run_make_test("
+export HI = \$(shell \$(\$\@.CMD))
+first.CMD = echo hi
+second.CMD = $sleep_command 4; echo hi
+
+.PHONY: all first second
+all: first second
+
+first second: ; \@echo \$\@; $sleep_command 1; echo \$\@",
+              '-j2', "first\nfirst\nsecond\nsecond");
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/features/patspecific_vars
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/patspecific_vars	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/patspecific_vars	(revision 284)
@@ -62,3 +62,63 @@
 &compare_output($answer,&get_logfile(1));
 
+# TEST #5 -- test pattern-specific exported variables
+#
+run_make_test('
+/%: export foo := foo
+
+/bar:
+	@test "$(foo)" = "$$foo"
+', '', '');
+
+
+# TEST #6 -- test expansion of pattern-specific simple variables
+#
+run_make_test('
+.PHONY: all
+
+all: inherit := good $$t
+all: bar baz
+
+b%: pattern := good $$t
+
+global := orginal $$t
+
+
+# normal target
+#
+ifdef rec
+bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
+else
+bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
+endif
+
+bar: ; @echo \'normal: $a;\'
+
+
+# pattern target
+#
+ifdef rec
+%z: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
+else
+%z: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
+endif
+
+%z: ; @echo \'pattrn: $a;\'
+
+
+global := new $$t
+',
+'',
+'normal: global: orginal $t pattern:  inherit: ;
+pattrn: global: orginal $t pattern:  inherit: ;');
+
+
+# TEST #7 -- test expansion of pattern-specific recursive variables
+#
+run_make_test(undef, # reuse previous makefile
+'rec=1',
+'normal: global: new $t pattern: good $t inherit: good $t;
+pattrn: global: new $t pattern: good $t inherit: good $t;');
+
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/features/recursion
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/recursion	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/recursion	(revision 284)
@@ -1,61 +1,55 @@
 #                                                                    -*-perl-*-
-$description = "The following test creates a makefile to ...\n";
+$description = "Test recursion.";
 
 $details = "DETAILS";
 
-open(MAKEFILE,"> $makefile");
+# Test some basic recursion.
+run_make_test('
+all:
+	$(MAKE) -f #MAKEFILE# foo
+foo:
+	@echo $(MAKE)
+	@echo MAKELEVEL = $(MAKELEVEL)
+	$(MAKE) -f #MAKEFILE# last
+last:
+	@echo $(MAKE)
+	@echo MAKELEVEL = $(MAKELEVEL)
+	@echo THE END
+',
+              ('CFLAGS=-O -w' . ($parallel_jobs ? '-j 2' : '')),
+              ($vos
+               ? "#MAKE#: Entering directory `#PWD#'
+make 'CFLAGS=-O' -f #MAKEFILE# foo
+make CFLAGS=-O
+MAKELEVEL = 0
+make 'CFLAGS=-O' -f #MAKEFILE# last
+make CFLAGS=-O
+MAKELEVEL = 0
+THE END
+#MAKE#: Leaving directory `#PWD#'"
+               : "#MAKE#: Entering directory `#PWD#'
+#MAKEPATH# -f #MAKEFILE# foo
+#MAKE#[1]: Entering directory `#PWD#'
+#MAKEPATH#
+MAKELEVEL = 1
+#MAKEPATH# -f #MAKEFILE# last
+#MAKE#[2]: Entering directory `#PWD#'
+#MAKEPATH#
+MAKELEVEL = 2
+THE END
+#MAKE#[2]: Leaving directory `#PWD#'
+#MAKE#[1]: Leaving directory `#PWD#'
+#MAKE#: Leaving directory `#PWD#'"));
 
-# The Contents of the MAKEFILE ...
 
-print MAKEFILE "all: \n"
-              ."\t\$(MAKE) -f $makefile foo \n"
-              ."foo: \n"
-              ."\t\@echo \$(MAKE) \n"
-              ."\t\@echo MAKELEVEL = \$(MAKELEVEL)\n"
-              ."\t\$(MAKE) -f $makefile last \n"
-              ."last: \n"
-              ."\t\@echo \$(MAKE) \n"
-              ."\t\@echo MAKELEVEL = \$(MAKELEVEL) \n"
-              ."\t\@echo THE END\n";
-
-# END of Contents of MAKEFILE
-
-close(MAKEFILE);
-
-if ($vos)
-{
-   $answer = "$make_name: Entering directory \`$pwd\'\n"
-            ."make 'CFLAGS=-O' -f $makefile foo \n"
-            ."make CFLAGS=-O\n"
-            ."MAKELEVEL = 0\n"
-            ."make 'CFLAGS=-O' -f $makefile last \n"
-            ."make CFLAGS=-O\n"
-            ."MAKELEVEL = 0\n"
-            ."THE END\n"
-            ."$make_name: Leaving directory `$pwd'\n";
-}
-else
-{
-   $answer = "$make_name: Entering directory `$pwd'\n"
-            ."$mkpath -f $makefile foo \n"
-            ."${make_name}[1]: Entering directory `$pwd'\n"
-            ."$mkpath\n"
-            ."MAKELEVEL = 1\n"
-            ."$mkpath -f $makefile last \n"
-            ."${make_name}[2]: Entering directory `$pwd'\n"
-            ."$mkpath\n"
-            ."MAKELEVEL = 2\n"
-            ."THE END\n"
-            ."${make_name}[2]: Leaving directory `$pwd'\n"
-            ."${make_name}[1]: Leaving directory `$pwd'\n"
-            ."$make_name: Leaving directory `$pwd'\n";
-}
-
-$mkoptions = "CFLAGS=-O -w";
-$mkoptions .= " -j 2" if ($parallel_jobs);
-
-&run_make_with_options($makefile,$mkoptions,&get_logfile,0);
-
-&compare_output($answer,&get_logfile(1));
+# Test command line overrides.
+run_make_test('
+recur: all ; @$(MAKE) --no-print-directory -f #MAKEFILE# a=AA all
+all: ; @echo "MAKEOVERRIDES = $(MAKEOVERRIDES)"
+',
+              'a=ZZ',
+              'MAKEOVERRIDES = a=ZZ
+MAKEOVERRIDES = a=AA
+');
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/features/statipattrules
===================================================================
--- branches/GNU/src/gmake/tests/scripts/features/statipattrules	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/features/statipattrules	(revision 284)
@@ -56,17 +56,21 @@
 $makefile2 = &get_tmpfile;
 open(MAKEFILE, "> $makefile2");
-print MAKEFILE "foo: foo%: % ; \@echo $@\n";
+print MAKEFILE "foo: foo%: % ; \@echo \$@\n";
 close(MAKEFILE);
 
-&run_make_with_options($makefile2, '', &get_logfile, 512);
-$answer = "$makefile2:1: *** target `foo' leaves prerequisite pattern empty.  Stop.\n";
+&run_make_with_options($makefile2, '', &get_logfile);
+$answer = "foo\n";
 &compare_output($answer, &get_logfile(1));
 
+# TEST #5 -- bug #12180: core dump on a stat pattern rule with an empty
+#                        prerequisite list.
+#
+run_make_test('
+foo.x bar.x: %.x : ; @echo $@
+
+',
+'',
+'foo.x
+');
 
 1;
-
-
-
-
-
-
Index: branches/GNU/src/gmake/tests/scripts/functions/eval
===================================================================
--- branches/GNU/src/gmake/tests/scripts/functions/eval	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/functions/eval	(revision 284)
@@ -135,3 +135,37 @@
 delete $ENV{EVAR};
 
+
+# Clean out previous information to allow new run_make_test() interface.
+# If we ever convert all the above to run_make_test() we can remove this line.
+$makefile = undef;
+
+# Test handling of backslashes in strings to be evaled.
+
+run_make_test('
+define FOO
+all: ; @echo hello \
+world
+endef
+$(eval $(FOO))
+', '', 'hello world');
+
+run_make_test('
+define FOO
+all: ; @echo he\llo
+	@echo world
+endef
+$(eval $(FOO))
+', '', 'hello
+world');
+
+
+# We don't allow new target/prerequisite relationships to be defined within a
+# command script, because these are evaluated after snap_deps() and that
+# causes lots of problems (like core dumps!)
+# See Savannah bug # 12124.
+
+run_make_test('deps: ; $(eval deps: foo)', '',
+              '#MAKEFILE#:1: *** prerequisites cannot be defined in command scripts.  Stop.',
+              512);
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/functions/substitution
===================================================================
--- branches/GNU/src/gmake/tests/scripts/functions/substitution	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/functions/substitution	(revision 284)
@@ -1,31 +1,32 @@
-$description = "The following test creates a makefile to ...";
+#                                                                    -*-perl-*-
+
+$description = "Test the subst and patsubst functions";
 
 $details = "";
 
-open(MAKEFILE,"> $makefile");
+# Generic patsubst test: test both the function and variable form.
 
-# The Contents of the MAKEFILE ...
+run_make_test('
+foo := a.o b.o c.o
+bar := $(foo:.o=.c)
+bar2:= $(foo:%.o=%.c)
+bar3:= $(patsubst %.c,%.o,x.c.c bar.c)
+all:;@echo $(bar); echo $(bar2); echo $(bar3)',
+'',
+'a.c b.c c.c
+a.c b.c c.c
+x.c.o bar.o');
 
-print MAKEFILE "foo := a.o b.o c.o\n"
-              ."bar := \$(foo:.o=.c)\n"
-	      ."bar2:= \$(foo:%.o=%.c)\n"
-              ."bar3:= \$(patsubst %.c,%.o,x.c.c bar.c)\n"
-              ."all:\n"
-              ."\t\@echo \$(bar)\n"
-              ."\t\@echo \$(bar2)\n"
-              ."\t\@echo \$(bar3)\n";
+# Patsubst without '%'--shouldn't match because the whole word has to match
+# in patsubst.  Based on a bug report by Markus Mauhart <qwe123@chello.at>
 
-# END of Contents of MAKEFILE
+run_make_test('all:;@echo $(patsubst Foo,Repl,FooFoo)', '', 'FooFoo');
 
-close(MAKEFILE);
+# Variable subst where a pattern matches multiple times in a single word.
+# Based on a bug report by Markus Mauhart <qwe123@chello.at>
 
-&run_make_with_options($makefile,"",&get_logfile);
-
-# Create the answer to what should be produced by this Makefile
-$answer = "a.c b.c c.c\n"
-         ."a.c b.c c.c\n"
-         ."x.c.o bar.o\n";
-
-&compare_output($answer,&get_logfile(1));
+run_make_test('
+A := fooBARfooBARfoo
+all:;@echo $(A:fooBARfoo=REPL)', '', 'fooBARREPL');
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/functions/wildcard
===================================================================
--- branches/GNU/src/gmake/tests/scripts/functions/wildcard	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/functions/wildcard	(revision 284)
@@ -86,10 +86,9 @@
 &run_make_with_options($makefile,"clean",&get_logfile);
 
-&compare_output($answer,&get_logfile(1));
-
-if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for"))
-{
+if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for")) {
    $test_passed = 0;
 }
+
+&compare_output($answer,&get_logfile(1));
 
 
Index: branches/GNU/src/gmake/tests/scripts/functions/word
===================================================================
--- branches/GNU/src/gmake/tests/scripts/functions/word	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/functions/word	(revision 284)
@@ -1,4 +1,5 @@
 #                                                                    -*-perl-*-
-$description = "Test the word, words, and wordlist functions.\n";
+$description = "\
+Test the word, words, wordlist, firstword, and lastword functions.\n";
 
 $details = "\
@@ -88,4 +89,40 @@
 &compare_output($answer, &get_logfile(1));
 
+
+# TEST #8 -- test $(firstword )
+#
+run_make_test('
+void :=
+list := $(void) foo bar baz #
+
+a := $(word 1,$(list))
+b := $(firstword $(list))
+
+.PHONY: all
+
+all:
+	@test "$a" = "$b" && echo $a
+',
+'',
+'foo');
+
+
+# TEST #9 -- test $(lastword )
+#
+run_make_test('
+void :=
+list := $(void) foo bar baz #
+
+a := $(word $(words $(list)),$(list))
+b := $(lastword $(list))
+
+.PHONY: all
+
+all:
+	@test "$a" = "$b" && echo $a
+',
+'',
+'baz');
+
 # This tells the test driver that the perl test script executed properly.
 1;
Index: branches/GNU/src/gmake/tests/scripts/misc/general4
===================================================================
--- branches/GNU/src/gmake/tests/scripts/misc/general4	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/misc/general4	(revision 284)
@@ -7,7 +7,4 @@
 
 open(MAKEFILE,"> $makefile");
-
-# The contents of the Makefile ...
-
 print MAKEFILE <<'EOF';
 # Make sure that subdirectories built as prerequisites are actually handled
@@ -22,5 +19,4 @@
 dir/subdir/%.a: dir/subdir/%.b ; @echo cp $< $@
 EOF
-
 close(MAKEFILE);
 
@@ -29,3 +25,26 @@
 &compare_output($answer,&get_logfile(1));
 
+# Test implicit rules
+
+&touch('foo.c');
+run_make_test('foo: foo.o',
+              'CC="@echo cc" OUTPUT_OPTION=',
+              'cc -c foo.c
+cc foo.o -o foo');
+unlink('foo.c');
+
+
+# Test other implicit rule searching
+
+&touch('bar');
+run_make_test('
+test.foo:
+%.foo : baz ; @echo done $<
+%.foo : bar ; @echo done $<
+fox: baz
+',
+              '',
+              'done bar');
+unlink('bar');
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/options/dash-B
===================================================================
--- branches/GNU/src/gmake/tests/scripts/options/dash-B	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/options/dash-B	(revision 284)
@@ -9,7 +9,7 @@
 is built again.";
 
-open(MAKEFILE,"> $makefile");
+&touch('bar.x');
 
-print MAKEFILE <<'EOF';
+run_make_test('
 .SUFFIXES:
 
@@ -20,24 +20,20 @@
 	@echo cp $< $@
 	@echo "" > $@
-EOF
+',
+              '', 'cp bar.x foo');
 
-close(MAKEFILE);
+run_make_test(undef, '', "#MAKE#: Nothing to be done for `all'.");
+run_make_test(undef, '-B', 'cp bar.x foo');
+
+# Put the timestamp for foo into the future; it should still be remade.
+
+utouch(1000, 'foo');
+run_make_test(undef, '', "#MAKE#: Nothing to be done for `all'.");
+run_make_test(undef, '-B', 'cp bar.x foo');
 
 
-&touch('bar.x');
+# Clean up
 
-&run_make_with_options($makefile, '', &get_logfile);
-$answer = "cp bar.x foo\n";
-&compare_output($answer, &get_logfile(1));
-
-&run_make_with_options($makefile, '', &get_logfile);
-$answer = "$make_name: Nothing to be done for `all'.\n";
-&compare_output($answer, &get_logfile(1));
-
-&run_make_with_options($makefile, '-B', &get_logfile);
-$answer = "cp bar.x foo\n";
-&compare_output($answer, &get_logfile(1));
-
-unlink('bar.x', 'foo') unless $keep;
+rmfiles('bar.x', 'foo');
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/options/dash-C
===================================================================
--- branches/GNU/src/gmake/tests/scripts/options/dash-C	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/options/dash-C	(revision 284)
@@ -1,27 +1,23 @@
-$description = "The following test creates a makefile to test the -C dir \n"
-              ."option in make.  This option tells make to change to \n"
-              ."directory dir before reading the makefile.";
+#                                                                    -*-perl-*-
 
-$details = "This test is similar to the clean test except that this test\n"
-          ."creates the file to delete in the work directory instead of\n"
-          ."the current directory.  Make is called from another directory\n"
-          ."using the -C workdir option so that it can both find the \n"
-          ."makefile and the file to delete in the work directory. ";
+$description = "Test the -C option to GNU make.";
 
-$example = $workdir . $pathsep . "EXAMPLE_FILE";
+$details = "\
+This test is similar to the clean test except that this test creates the file
+to delete in the work directory instead of the current directory.  Make is
+called from another directory using the -C workdir option so that it can both
+find the makefile and the file to delete in the work directory.";
+
+$example = $workdir . $pathsep . "EXAMPLE";
 
 open(MAKEFILE,"> $makefile");
-
-# The Contents of the MAKEFILE ...
-
-print MAKEFILE "all: \n";
-print MAKEFILE "\t\@echo This makefile did not clean the dir ... good\n";
-print MAKEFILE "clean: \n";
-print MAKEFILE "\t$delete_command EXAMPLE_FILE\n";
-
-# END of Contents of MAKEFILE
-
+print MAKEFILE <<EOF;
+all: ; \@echo This makefile did not clean the dir ... good
+clean: ; $delete_command EXAMPLE\$(ext)
+EOF
 close(MAKEFILE);
 
+# TEST #1
+# -------
 &touch($example);
 
@@ -34,15 +30,42 @@
 chdir $pwd;
 
+if (-f $example) {
+  $test_passed = 0;
+}
+
 # Create the answer to what should be produced by this Makefile
 $answer = "$make_name: Entering directory `$wpath'\n"
-        . "$delete_command EXAMPLE_FILE\n"
+        . "$delete_command EXAMPLE\n"
         . "$make_name: Leaving directory `$wpath'\n";
 
 &compare_output($answer,&get_logfile(1));
 
-if (-f $example)
-{
-   $test_passed = 0;
+
+# TEST #2
+# -------
+# Do it again with trailing "/"; this should work the same
+
+$example .= "slash";
+
+&touch($example);
+
+&run_make_with_options("${testname}.mk",
+	               "-C $workdir/ clean ext=slash",
+		       &get_logfile);
+
+chdir $workdir;
+$wpath = &get_this_pwd;
+chdir $pwd;
+
+if (-f $example) {
+  $test_passed = 0;
 }
 
+# Create the answer to what should be produced by this Makefile
+$answer = "$make_name: Entering directory `$wpath'\n"
+        . "$delete_command EXAMPLEslash\n"
+        . "$make_name: Leaving directory `$wpath'\n";
+
+&compare_output($answer,&get_logfile(1));
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/options/dash-k
===================================================================
--- branches/GNU/src/gmake/tests/scripts/options/dash-k	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/options/dash-k	(revision 284)
@@ -98,3 +98,17 @@
 &compare_output($answer, &get_logfile(1));
 
+# TEST -- make sure we keep the error code if we can't create an included
+# makefile.
+
+run_make_test('all: ; @echo hi
+include ifile
+ifile: no-such-file; @false
+',
+              '-k',
+              "#MAKEFILE#:2: ifile: No such file or directory
+#MAKE#: *** No rule to make target `no-such-file', needed by `ifile'.
+#MAKE#: Failed to remake makefile `ifile'.
+hi\n",
+              512);
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/options/dash-q
===================================================================
--- branches/GNU/src/gmake/tests/scripts/options/dash-q	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/options/dash-q	(revision 284)
@@ -4,9 +4,7 @@
 $details = "Try various uses of -q and ensure they all give the correct results.\n";
 
-open(MAKEFILE, "> $makefile");
+# TEST 0
 
-# The Contents of the MAKEFILE ...
-
-print MAKEFILE <<'EOMAKE';
+run_make_test('
 one:
 two: ;
@@ -22,49 +20,38 @@
 	: foo
 	$(.XY)
-EOMAKE
-
-close(MAKEFILE);
-
-# TEST 0
-
-&run_make_with_options($makefile, "-q one", &get_logfile);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+',
+              '-q one', '');
 
 # TEST 1
 
-&run_make_with_options($makefile, "-q two", &get_logfile);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q two', '');
 
 # TEST 2
 
-&run_make_with_options($makefile, "-q three", &get_logfile, 256);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q three', '', 256);
 
 # TEST 3
 
-&run_make_with_options($makefile, "-q four", &get_logfile);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q four', '');
 
 # TEST 4
 
-&run_make_with_options($makefile, "-q five", &get_logfile);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q five', '');
 
 # TEST 5
 
-&run_make_with_options($makefile, "-q six", &get_logfile);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q six', '');
 
 # TEST 6
 
-&run_make_with_options($makefile, "-q seven", &get_logfile, 256);
-$answer = "";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, '-q seven', '', 256);
+
+# TEST 7 : Savannah bug # 7144
+
+run_make_test('
+one:: ; @echo one
+one:: ; @echo two
+',
+              '-q', '', 256);
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/targets/FORCE
===================================================================
--- branches/GNU/src/gmake/tests/scripts/targets/FORCE	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/targets/FORCE	(revision 284)
@@ -1,3 +1,3 @@
-$description = "The following tests rules without Commands or Dependencies."; 
+$description = "The following tests rules without Commands or Dependencies.";
 
 $details = "If the rule ...\n";
@@ -18,5 +18,5 @@
 print MAKEFILE ".IGNORE :\n";
 print MAKEFILE "clean: FORCE\n";
-print MAKEFILE "\t$delete_command clean\n"; 
+print MAKEFILE "\t$delete_command clean\n";
 print MAKEFILE "FORCE:\n";
 
@@ -27,5 +27,5 @@
 
 # Create a file named "clean".  This is the same name as the target clean
-# and tricks the target into thinking that it is up to date.  (Unless you 
+# and tricks the target into thinking that it is up to date.  (Unless you
 # use the .PHONY target.
 &touch("clean");
@@ -34,11 +34,6 @@
 &run_make_with_options($makefile,"clean",&get_logfile);
 
-&compare_output($answer,&get_logfile(1)); 
+&compare_output($answer,&get_logfile(1));
 
-if (-f $example)
-{
-   $test_passed = 0;
-}
- 
 1;
 
Index: branches/GNU/src/gmake/tests/scripts/targets/PHONY
===================================================================
--- branches/GNU/src/gmake/tests/scripts/targets/PHONY	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/targets/PHONY	(revision 284)
@@ -28,5 +28,5 @@
 print MAKEFILE "\t\@echo This makefile did not clean the dir ... good\n";
 print MAKEFILE "clean: \n";
-print MAKEFILE "\t$delete_command $example clean\n"; 
+print MAKEFILE "\t$delete_command $example clean\n";
 
 # END of Contents of MAKEFILE
@@ -37,5 +37,5 @@
 
 # Create a file named "clean".  This is the same name as the target clean
-# and tricks the target into thinking that it is up to date.  (Unless you 
+# and tricks the target into thinking that it is up to date.  (Unless you
 # use the .PHONY target.
 &touch("clean");
@@ -44,11 +44,10 @@
 &run_make_with_options($makefile,"clean",&get_logfile);
 
-&compare_output($answer,&get_logfile(1)); 
+if (-f $example) {
+  $test_passed = 0;
+}
 
-if (-f $example)
-{
-   $test_passed = 0;
-}
- 
+&compare_output($answer,&get_logfile(1));
+
 1;
 
Index: branches/GNU/src/gmake/tests/scripts/targets/SECONDARY
===================================================================
--- branches/GNU/src/gmake/tests/scripts/targets/SECONDARY	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/targets/SECONDARY	(revision 284)
@@ -109,4 +109,17 @@
 unlink('source', 'final', 'intermediate');
 
+
+# TEST #8 -- test the "global" .SECONDARY, with .PHONY.
+
+touch('version2');
+run_make_test('
+.PHONY: version
+.SECONDARY:
+version2: version ; @echo GOOD
+all: version2',
+              'all', 'GOOD');
+
+unlink('version2');
+
 # This tells the test driver that the perl test script executed properly.
 1;
Index: branches/GNU/src/gmake/tests/scripts/targets/SILENT
===================================================================
--- branches/GNU/src/gmake/tests/scripts/targets/SILENT	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/targets/SILENT	(revision 284)
@@ -23,5 +23,5 @@
 print MAKEFILE ".SILENT : clean\n";
 print MAKEFILE "clean: \n";
-print MAKEFILE "\t$delete_command EXAMPLE_FILE\n"; 
+print MAKEFILE "\t$delete_command EXAMPLE_FILE\n";
 
 # END of Contents of MAKEFILE
@@ -33,11 +33,9 @@
 $answer = "";
 &run_make_with_options($makefile,"clean",&get_logfile,0);
+if (-f $example) {
+  $test_passed = 0;
+}
+&compare_output($answer,&get_logfile(1));
 
-&compare_output($answer,&get_logfile(1)); 
-if (-f $example)
-{
-   $test_passed = 0;
-}
- 
 1;
 
Index: branches/GNU/src/gmake/tests/scripts/targets/clean
===================================================================
--- branches/GNU/src/gmake/tests/scripts/targets/clean	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/targets/clean	(revision 284)
@@ -34,9 +34,8 @@
 $answer = "$delete_command $example\n";
 &run_make_with_options($makefile,"clean",&get_logfile,0);
-
+if (-f $example) {
+  $test_passed = 0;
+}
 &compare_output($answer,&get_logfile(1)) || &error ("abort");
-if (-f $example) {
-   $test_passed = 0;
-}
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/variables/MAKE
===================================================================
--- branches/GNU/src/gmake/tests/scripts/variables/MAKE	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/variables/MAKE	(revision 284)
@@ -1,2 +1,4 @@
+#								     -*-perl-*-
+
 $description = "The following test creates a makefile to test MAKE \n"
               ."(very generic)";
@@ -27,5 +29,5 @@
 &run_make_with_options($makefile,"",&get_logfile,0);
 
-&delete("foo");
+&rmfiles("foo");
 # COMPARE RESULTS
 &compare_output($answer,&get_logfile(1));
Index: branches/GNU/src/gmake/tests/scripts/variables/MAKELEVEL
===================================================================
--- branches/GNU/src/gmake/tests/scripts/variables/MAKELEVEL	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/variables/MAKELEVEL	(revision 284)
@@ -1,3 +1,3 @@
-#                                                               -*-perl-mode-*-
+#                                                                    -*-perl-*-
 
 $description = "The following test creates a makefile to test
@@ -10,5 +10,4 @@
 
 print MAKEFILE <<EOF;
-SHELL = /bin/sh
 all:
 \t\@echo MAKELEVEL is \$(MAKELEVEL)
Index: branches/GNU/src/gmake/tests/scripts/variables/automatic
===================================================================
--- branches/GNU/src/gmake/tests/scripts/variables/automatic	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/variables/automatic	(revision 284)
@@ -68,9 +68,9 @@
 
 &run_make_with_options($makefile2, "$dir/foo $dir/bar", &get_logfile);
-$answer = ".x\n$dir/foo.x\n\$.x\n\$@.x\n$dir.x\nfoo.x\n$dir/bar.x\nbar.x\n";
+$answer = ".x\n$dir/foo.x\nx\n\$@.x\n$dir.x\nfoo.x\n$dir/bar.x\nbar.x\n";
 &compare_output($answer, &get_logfile(1));
 
 &run_make_with_options($makefile2, "$dir/x.z $dir/y.z", &get_logfile);
-$answer = ".x\n$dir/x.z.x\n\$.x\n\$@.x\n$dir.x\nx.z.x\n.y\n$dir/y.z.y\n\$.y\n\$@.y\n$dir.y\ny.z.y\n";
+$answer = ".x\n$dir/x.z.x\nx\n\$@.x\n$dir.x\nx.z.x\n.y\n$dir/y.z.y\n\y\n\$@.y\n$dir.y\ny.z.y\n";
 &compare_output($answer, &get_logfile(1));
 
@@ -79,3 +79,18 @@
 &compare_output($answer, &get_logfile(1));
 
+# TEST #3 -- test for Savannah bug #12320.
+#
+run_make_test('
+.SUFFIXES: .b .src
+
+mbr.b: mbr.src
+	@echo $*
+
+mbr.src: ; @:
+
+',
+'',
+'mbr
+');
+
 1;
Index: branches/GNU/src/gmake/tests/scripts/variables/flavors
===================================================================
--- branches/GNU/src/gmake/tests/scripts/variables/flavors	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/variables/flavors	(revision 284)
@@ -72,5 +72,5 @@
 
 &run_make_with_options($makefile, "BOGUS=true", &get_logfile, 512);
-$answer = "$makefile:23: *** empty variable name.  Stop.\n";
+$answer = "$makefile:24: *** empty variable name.  Stop.\n";
 &compare_output($answer, &get_logfile(1));
 
@@ -82,4 +82,102 @@
 &compare_output($answer, &get_logfile(1));
 
+# Clean up from "old style" testing.  If all the above tests are converted to
+# run_make_test() syntax than this line can be removed.
+$makefile = undef;
+
+# -------------------------
+# Make sure that prefix characters apply properly to define/endef values.
+#
+# There's a bit of oddness here if you try to use a variable to hold the
+# prefix character for a define.  Even though something like this:
+#
+#       define foo
+#       echo bar
+#       endef
+#
+#       all: ; $(V)$(foo)
+#
+# (where V=@) can be seen by the user to be obviously different than this:
+#
+#       define foo
+#       $(V)echo bar
+#       endef
+#
+#       all: ; $(foo)
+#
+# and the user thinks it should behave the same as when the "@" is literal
+# instead of in a variable, that can't happen because by the time make
+# expands the variables for the command line and sees it begins with a "@" it
+# can't know anymore whether the prefix character came before the variable
+# reference or was included in the first line of the variable reference.
+
+# TEST #5
+# -------
+
+run_make_test('
+define FOO
+$(V1)echo hello
+$(V2)echo world
+endef
+all: ; @$(FOO)
+', '', 'hello
+world');
+
+# TEST #6
+# -------
+
+run_make_test(undef, 'V1=@ V2=@', 'hello
+world');
+
+# TEST #7
+# -------
+
+run_make_test('
+define FOO
+$(V1)echo hello
+$(V2)echo world
+endef
+all: ; $(FOO)
+', 'V1=@', 'hello
+echo world
+world');
+
+# TEST #8
+# -------
+
+run_make_test(undef, 'V2=@', 'echo hello
+hello
+world');
+
+# TEST #9
+# -------
+
+run_make_test(undef, 'V1=@ V2=@', 'hello
+world');
+
+# TEST #10
+# -------
+# Test the basics; a "@" internally to the variable applies to only one line.
+# A "@" before the variable applies to the entire variable.
+
+run_make_test('
+define FOO
+@echo hello
+echo world
+endef
+define BAR
+echo hello
+echo world
+endef
+
+all: foo bar
+foo: ; $(FOO)
+bar: ; @$(BAR)
+', '', 'hello
+echo world
+world
+hello
+world
+');
 
 1;
Index: branches/GNU/src/gmake/tests/scripts/variables/special
===================================================================
--- branches/GNU/src/gmake/tests/scripts/variables/special	(revision 283)
+++ branches/GNU/src/gmake/tests/scripts/variables/special	(revision 284)
@@ -5,10 +5,5 @@
 $details = "";
 
-$makefile2 = &get_tmpfile;
-
-
-open(MAKEFILE, "> $makefile");
-
-print MAKEFILE <<'EOF';
+&run_make_test('
 
 X1 := $(sort $(filter FOO BAR,$(.VARIABLES)))
@@ -24,19 +19,10 @@
 	@echo X2 = $(X2)
 	@echo LAST = $(sort $(filter FOO BAR,$(.VARIABLES)))
-
-EOF
-
-close(MAKEFILE);
-
-# TEST #1
-# -------
-
-&run_make_with_options($makefile, "", &get_logfile);
-$answer = "X1 =\nX2 = FOO\nLAST = BAR FOO\n";
-&compare_output($answer, &get_logfile(1));
+',
+               '', "X1 =\nX2 = FOO\nLAST = BAR FOO\n");
 
 
 
-
+# $makefile2 = &get_tmpfile;
 # open(MAKEFILE, "> $makefile2");
 
Index: branches/GNU/src/gmake/w32/include/sub_proc.h
===================================================================
--- branches/GNU/src/gmake/w32/include/sub_proc.h	(revision 283)
+++ branches/GNU/src/gmake/w32/include/sub_proc.h	(revision 284)
@@ -3,16 +3,14 @@
 
 /*
- * Component Name: 
+ * Component Name:
  *
- * $Date: 1997/08/27 20:34:23 $
+ * $Date: 2005/02/10 00:10:58 $
  *
  * $Source: /cvsroot/make/make/w32/include/sub_proc.h,v $
  *
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
  */
 
-/* $Id: sub_proc.h,v 1.4 1997/08/27 20:34:23 psmith Exp $ */
-
-#ifdef WINDOWS32
+/* $Id: sub_proc.h,v 1.5 2005/02/10 00:10:58 psmith Exp $ */
 
 #define EXTERN_DECL(entry, args) extern entry args
@@ -24,5 +22,5 @@
 EXTERN_DECL(long process_begin, (HANDLE proc, char **argv, char **envp,
 	char *exec_path, char *as_user));
-EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data, 
+EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data,
 	int stdin_data_len));
 EXTERN_DECL(long process_file_io, (HANDLE proc));
@@ -45,3 +43,2 @@
 
 #endif
-#endif
Index: branches/GNU/src/gmake/w32/subproc/NMakefile
===================================================================
--- branches/GNU/src/gmake/w32/subproc/NMakefile	(revision 283)
+++ branches/GNU/src/gmake/w32/subproc/NMakefile	(revision 284)
@@ -24,4 +24,5 @@
 LIB = lib
 CC = cl
+MAKE = nmake
 
 OUTDIR=.
Index: branches/GNU/src/gmake/w32/subproc/sub_proc.c
===================================================================
--- branches/GNU/src/gmake/w32/subproc/sub_proc.c	(revision 283)
+++ branches/GNU/src/gmake/w32/subproc/sub_proc.c	(revision 284)
@@ -665,11 +665,11 @@
 	HANDLE ready_hand;
 	bool_t child_dead = FALSE;
-
+	BOOL GetExitCodeResult;
 
 	/*
 	 *  Create stdin thread, if needed
 	 */
-    pproc->inp = stdin_data;
-    pproc->incnt = stdin_data_len;
+	pproc->inp = stdin_data;
+	pproc->incnt = stdin_data_len;
 	if (!pproc->inp) {
 		stdin_eof = TRUE;
@@ -763,5 +763,6 @@
 		} else if (ready_hand == childhand) {
 
-			if (GetExitCodeProcess(childhand, &pproc->exit_code) == FALSE) {
+			GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code);
+			if (GetExitCodeResult == FALSE) {
 				pproc->last_err = GetLastError();
 				pproc->lerrno = E_SCALL;
@@ -810,4 +811,5 @@
 	HANDLE childhand;
 	DWORD wait_return;
+	BOOL GetExitCodeResult;
 
 	if (proc == NULL)
@@ -853,5 +855,6 @@
 	}
 
-	if (GetExitCodeProcess(childhand, &pproc->exit_code) == FALSE) {
+	GetExitCodeResult = GetExitCodeProcess(childhand, (DWORD*)&pproc->exit_code);
+	if (GetExitCodeResult == FALSE) {
 		pproc->last_err = GetLastError();
 		pproc->lerrno = E_SCALL;
Index: branches/GNU/src/gmake/w32/subproc/w32err.c
===================================================================
--- branches/GNU/src/gmake/w32/subproc/w32err.c	(revision 283)
+++ branches/GNU/src/gmake/w32/subproc/w32err.c	(revision 284)
@@ -12,7 +12,10 @@
 char *
 map_windows32_error_to_string (DWORD ercode) {
-/* __declspec (thread) necessary if you will use multiple threads */
+/* __declspec (thread) necessary if you will use multiple threads on MSVC */
+#ifdef _MSC_VER
 __declspec (thread) static char szMessageBuffer[128];
-
+#else
+static char szMessageBuffer[128];
+#endif
 	/* Fill message buffer with a default message in
 	 * case FormatMessage fails
