| 1 | # -*-perl-*-
|
|---|
| 2 |
|
|---|
| 3 | $description = "The following test creates a makefile to test the \n"
|
|---|
| 4 | ."vpath directive which allows you to specify a search \n"
|
|---|
| 5 | ."path for a particular class of filenames, those that\n"
|
|---|
| 6 | ."match a particular pattern.";
|
|---|
| 7 |
|
|---|
| 8 | $details = "This tests the vpath directive by specifying search directories\n"
|
|---|
| 9 | ."for one class of filenames with the form: vpath pattern directories"
|
|---|
| 10 | ."\nIn this test, we specify the working directory for all files\n"
|
|---|
| 11 | ."that end in c or h. We also test the variables $@ (which gives\n"
|
|---|
| 12 | ."target name) and $^ (which is a list of all dependencies \n"
|
|---|
| 13 | ."including the directories in which they were found). It also\n"
|
|---|
| 14 | ."uses the function firstword used to extract just the first\n"
|
|---|
| 15 | ."dependency from the entire list.";
|
|---|
| 16 |
|
|---|
| 17 | open(MAKEFILE,"> $makefile");
|
|---|
| 18 |
|
|---|
| 19 | # The Contents of the MAKEFILE ...
|
|---|
| 20 |
|
|---|
| 21 | print MAKEFILE "vpath %.c foo\n";
|
|---|
| 22 | print MAKEFILE "vpath %.c $workdir\n";
|
|---|
| 23 | print MAKEFILE "vpath %.h $workdir\n";
|
|---|
| 24 | print MAKEFILE "objects = main.o kbd.o commands.o display.o insert.o\n";
|
|---|
| 25 | print MAKEFILE "edit: \$(objects)\n";
|
|---|
| 26 | print MAKEFILE "\t\@echo cc -o \$@ \$^\n";
|
|---|
| 27 | print MAKEFILE "main.o : main.c defs.h\n";
|
|---|
| 28 | print MAKEFILE "\t\@echo cc -c \$(firstword \$^)\n";
|
|---|
| 29 | print MAKEFILE "kbd.o : kbd.c defs.h command.h\n";
|
|---|
| 30 | print MAKEFILE "\t\@echo cc -c kbd.c\n";
|
|---|
| 31 | print MAKEFILE "commands.o : command.c defs.h command.h\n";
|
|---|
| 32 | print MAKEFILE "\t\@echo cc -c commands.c\n";
|
|---|
| 33 | print MAKEFILE "display.o : display.c defs.h buffer.h\n";
|
|---|
| 34 | print MAKEFILE "\t\@echo cc -c display.c\n";
|
|---|
| 35 | print MAKEFILE "insert.o : insert.c defs.h buffer.h\n";
|
|---|
| 36 | print MAKEFILE "\t\@echo cc -c insert.c\n";
|
|---|
| 37 |
|
|---|
| 38 | # END of Contents of MAKEFILE
|
|---|
| 39 |
|
|---|
| 40 | close(MAKEFILE);
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 | @files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
|
|---|
| 44 | "$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
|
|---|
| 45 | "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
|
|---|
| 46 | "$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
|
|---|
| 47 | "$workdir${pathsep}command.c");
|
|---|
| 48 |
|
|---|
| 49 | &touch(@files_to_touch);
|
|---|
| 50 |
|
|---|
| 51 | # kmk: this requires -j1 because of ordering.
|
|---|
| 52 | &run_make_with_options($makefile,"-j1",&get_logfile);
|
|---|
| 53 |
|
|---|
| 54 | # Create the answer to what should be produced by this Makefile
|
|---|
| 55 | $answer = "cc -c $workdir${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
|
|---|
| 56 | ."cc -c display.c\n"
|
|---|
| 57 | ."cc -c insert.c\ncc -o edit main.o kbd.o commands.o display.o "
|
|---|
| 58 | ."insert.o\n";
|
|---|
| 59 |
|
|---|
| 60 | if (&compare_output($answer,&get_logfile(1)))
|
|---|
| 61 | {
|
|---|
| 62 | unlink @files_to_touch;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | # TEST 2: after vpath lookup ensure we don't get incorrect circular dependency
|
|---|
| 66 | # warnings due to change of struct file ptr. Savannah bug #13529.
|
|---|
| 67 |
|
|---|
| 68 | mkdir('vpath-d', 0777);
|
|---|
| 69 |
|
|---|
| 70 | run_make_test(q!
|
|---|
| 71 | vpath %.te vpath-d/
|
|---|
| 72 | .SECONDARY:
|
|---|
| 73 | default: vpath-d/a vpath-d/b
|
|---|
| 74 | vpath-d/a: fail.te
|
|---|
| 75 | vpath-d/b : fail.te
|
|---|
| 76 | vpath-d/fail.te:
|
|---|
| 77 | !,
|
|---|
| 78 | '', "#MAKE#: Nothing to be done for 'default'.\n");
|
|---|
| 79 |
|
|---|
| 80 | rmdir('vpath-d');
|
|---|
| 81 |
|
|---|
| 82 | 1;
|
|---|