mkltxdep 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/perl
  2. # 0 means don't include as dependencies, 1 means include only if it exists,
  3. # 2 means always include. Note that .bbl and .ind also trigger
  4. # bibtex or mkindex processing
  5. %handling=(
  6. '.bbl'=>0,
  7. '.cfg'=>1,
  8. '.clo'=>1,
  9. '.cls'=>1,
  10. '.def'=>1,
  11. '.fd'=>1,
  12. '.ind'=>0,
  13. '.out'=>0,
  14. '.pdf'=>2,
  15. '.sty'=>1,
  16. '.tex'=>1,
  17. );
  18. $outstem=shift;
  19. @prereqs=("$outstem.tex");
  20. $flag=0;
  21. $hasbib=0;
  22. $hasind=0;
  23. while (<>) {
  24. $flag=0 if /\*\*\*\*\*\*\*\*\*\*\*/;
  25. if ($flag) {
  26. next unless /^\s*([^ .]+)(\.\S+)?\s*/;
  27. if (($handling{$2}==2) || ($handling{$2}==1 && -r $1.$2)) {
  28. push(@prereqs,$1.$2);
  29. }
  30. if ($2 eq '.bbl') {
  31. $hasbib=1;
  32. }
  33. if ($2 eq '.ind') {
  34. $hasind=1;
  35. }
  36. }
  37. $flag=1 if /\*File List\*/;
  38. }
  39. if ($hasbib) {
  40. open(AUX,"$outstem.aux");
  41. @bibdata=();
  42. while (<AUX>) {
  43. @bibdata=split(/,/,$1) if /^\\bibdata\{(.*)\}/;
  44. }
  45. }
  46. print "$outstem.p1: ".join(' ',@prereqs)."\n\n";
  47. if ($hasbib || $hasind) {
  48. print "$outstem.pdf: $outstem.p2\n\n";
  49. print "$outstem.p2:".($hasbib?" $outstem.bbl":'')
  50. .($hasind?" $outstem.ind":'')."\n\n";
  51. print "$outstem.ind: $outstem.p1 $outstem.bbl\n\n" if $hasbib && $hasind;
  52. print "$outstem.bbl: ".join('.bib ',@bibdata).".bib\n\n" if $hasbib && @bibdata;
  53. } else {
  54. print "$outstem.pdf: $outstem.p1\n\n";
  55. }