vpath 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. $description = "The following test creates a makefile to test the \n"
  2. ."vpath directive which allows you to specify a search \n"
  3. ."path for a particular class of filenames, those that\n"
  4. ."match a particular pattern.";
  5. $details = "This tests the vpath directive by specifying search directories\n"
  6. ."for one class of filenames with the form: vpath pattern directories"
  7. ."\nIn this test, we specify the working directory for all files\n"
  8. ."that end in c or h. We also test the variables $@ (which gives\n"
  9. ."target name) and $^ (which is a list of all dependencies \n"
  10. ."including the directories in which they were found). It also\n"
  11. ."uses the function firstword used to extract just the first\n"
  12. ."dependency from the entire list.";
  13. open(MAKEFILE,"> $makefile");
  14. # The Contents of the MAKEFILE ...
  15. print MAKEFILE "vpath %.c foo\n";
  16. print MAKEFILE "vpath %.c $workdir\n";
  17. print MAKEFILE "vpath %.h $workdir\n";
  18. print MAKEFILE "objects = main.o kbd.o commands.o display.o insert.o\n";
  19. print MAKEFILE "edit: \$(objects)\n";
  20. print MAKEFILE "\t\@echo cc -o \$@ \$^\n";
  21. print MAKEFILE "main.o : main.c defs.h\n";
  22. print MAKEFILE "\t\@echo cc -c \$(firstword \$^)\n";
  23. print MAKEFILE "kbd.o : kbd.c defs.h command.h\n";
  24. print MAKEFILE "\t\@echo cc -c kbd.c\n";
  25. print MAKEFILE "commands.o : command.c defs.h command.h\n";
  26. print MAKEFILE "\t\@echo cc -c commands.c\n";
  27. print MAKEFILE "display.o : display.c defs.h buffer.h\n";
  28. print MAKEFILE "\t\@echo cc -c display.c\n";
  29. print MAKEFILE "insert.o : insert.c defs.h buffer.h\n";
  30. print MAKEFILE "\t\@echo cc -c insert.c\n";
  31. # END of Contents of MAKEFILE
  32. close(MAKEFILE);
  33. @files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
  34. "$workdir${pathsep}kbd.c","$workdir${pathsep}command.h",
  35. "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
  36. "$workdir${pathsep}buffer.h","$workdir${pathsep}insert.c",
  37. "$workdir${pathsep}command.c");
  38. &touch(@files_to_touch);
  39. &run_make_with_options($makefile,"",&get_logfile);
  40. # Create the answer to what should be produced by this Makefile
  41. $answer = "cc -c $workdir${pathsep}main.c\ncc -c kbd.c\ncc -c commands.c\n"
  42. ."cc -c display.c\n"
  43. ."cc -c insert.c\ncc -o edit main.o kbd.o commands.o display.o "
  44. ."insert.o\n";
  45. if (&compare_output($answer,&get_logfile(1)))
  46. {
  47. unlink @files_to_touch;
  48. }
  49. 1;