Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / vpath
index ec24165..7c034b5 100644 (file)
@@ -1,65 +1,34 @@
 #                                                                     -*-perl-*-
 
-$description = "The following test creates a makefile to test the \n"
-              ."vpath directive which allows you to specify a search \n"
-              ."path for a particular class of filenames, those that\n"
-              ."match a particular pattern.";
-
-$details = "This tests the vpath directive by specifying search directories\n"
-         ."for one class of filenames with the form: vpath pattern directories"
-         ."\nIn this test, we specify the working directory for all files\n"
-         ."that end in c or h.  We also test the variables $@ (which gives\n"
-         ."target name) and $^ (which is a list of all dependencies \n"
-         ."including the directories in which they were found).  It also\n"
-         ."uses the function firstword used to extract just the first\n"
-         ."dependency from the entire list.";
-
-open(MAKEFILE,"> $makefile");
-
-# The Contents of the MAKEFILE ...
-
-print MAKEFILE "vpath %.c foo\n";
-print MAKEFILE "vpath %.c $workdir\n";
-print MAKEFILE "vpath %.h $workdir\n";
-print MAKEFILE "objects = main.o kbd.o commands.o display.o insert.o\n";
-print MAKEFILE "edit:  \$(objects)\n";
-print MAKEFILE "\t\@echo cc -o \$@ \$^\n";
-print MAKEFILE "main.o : main.c defs.h\n";
-print MAKEFILE "\t\@echo cc -c \$(firstword \$^)\n";
-print MAKEFILE "kbd.o : kbd.c defs.h command.h\n";
-print MAKEFILE "\t\@echo cc -c kbd.c\n";
-print MAKEFILE "commands.o : command.c defs.h command.h\n";
-print MAKEFILE "\t\@echo cc -c commands.c\n";
-print MAKEFILE "display.o : display.c defs.h buffer.h\n";
-print MAKEFILE "\t\@echo cc -c display.c\n";
-print MAKEFILE "insert.o : insert.c defs.h buffer.h\n";
-print MAKEFILE "\t\@echo cc -c insert.c\n";
-
-# END of Contents of MAKEFILE
-
-close(MAKEFILE);
+$description = "Test vpath for particular classes of filenames.";
 
+$details = "";
 
 @files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
-               "$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
-               "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
-               "$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
-              "$workdir${pathsep}command.c");
+                   "$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
+                   "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
+                   "$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
+                   "$workdir${pathsep}command.c");
 
 &touch(@files_to_touch);
 
-&run_make_with_options($makefile,"",&get_logfile);
-
-# Create the answer to what should be produced by this Makefile
-$answer = "cc -c $workdir${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
-         ."cc -c display.c\n"
-         ."cc -c insert.c\ncc -o edit main.o kbd.o commands.o display.o "
-         ."insert.o\n";
+run_make_test(q!
+vpath %.c foo
+vpath %.c #WORK#
+vpath %.h #WORK#
+objects = main.o kbd.o commands.o display.o insert.o
+edit: $(objects) ; @echo cc -o $@ $^
+main.o : main.c defs.h ; @echo cc -c $(firstword $^)
+kbd.o : kbd.c defs.h command.h ; @echo cc -c kbd.c
+commands.o : command.c defs.h command.h ; @echo cc -c commands.c
+display.o : display.c defs.h buffer.h ; @echo cc -c display.c
+insert.o : insert.c defs.h buffer.h ; @echo cc -c insert.c
+!,
+    '', "cc -c $workdir${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
+        ."cc -c display.c\ncc -c insert.c\n"
+        ."cc -o edit main.o kbd.o commands.o display.o insert.o\n");
 
-if (&compare_output($answer,&get_logfile(1)))
-{
-  unlink @files_to_touch;
-}
+unlink(@files_to_touch);
 
 # TEST 2: after vpath lookup ensure we don't get incorrect circular dependency
 # warnings due to change of struct file ptr.  Savannah bug #13529.
@@ -78,4 +47,68 @@ vpath-d/fail.te:
 
 rmdir('vpath-d');
 
+# Test VPATH vs vpath
+
+run_make_test(q!
+VPATH = #WORK#:#PWD#
+vpath %.c foo
+vpath %.c #WORK#
+vpath %.c #PWD#
+vpath %.h #WORK#
+vpath %.c
+vpath
+all: ; @echo ALL IS WELL
+!,
+              '', "ALL IS WELL\n");
+
+# Test interaction of -lfoo and vpath
+
+my @dirs_to_make = qw(a1 b1 a2 b2 b3);
+for my $d (@dirs_to_make) {
+    mkdir($d, 0777);
+}
+
+my @files_to_touch = ("a1${pathsep}lib1.a",
+                      "a1${pathsep}libc.a",
+                      "b1${pathsep}lib1.so",
+                      "a2${pathsep}lib2.a",
+                      "b2${pathsep}lib2.so",
+                      "lib3.a",
+                      "b3${pathsep}lib3.so");
+&touch(@files_to_touch);
+
+my $answer = "a1${pathsep}lib1.a a1${pathsep}libc.a " .
+             "a2${pathsep}lib2.a lib3.a\n";
+if ($port_type eq 'VMS-DCL') {
+    $answer =~ s/ /,/g;
+}
+
+run_make_test('
+vpath %.h b3
+vpath %.a a1
+vpath %.so b1
+vpath % a2 b2
+vpath % b3
+all: -l1 -lc -l2 -l3; @echo $^
+',
+              '', $answer);
+
+unlink(@files_to_touch);
+for my $d (@dirs_to_make) {
+    rmdir($d);
+}
+
+# Check that if we find find files with VPATH, we don't do pattern search
+
+mkdir("vpa");
+
+run_make_test(q!
+VPATH = vpa
+%.x: ; @echo pattern $@
+vpa/foo.x: ; @echo vpath $@
+!,
+              'foo.x', "vpath vpa/foo.x\n");
+
+rmdir("vpa");
+
 1;