Attached program finds dependencies in lilypond files.
  E.g.:

$ grep include Sliv.ly global.ly
Sliv.ly:\include "global.ly"
Sliv.ly:\include "Mliv.ly"
Sliv.ly:\include "score.ly"
global.ly:\include "choirbook.ly"
global.ly:\include "../common/global.ly"
$ depend_ly ps Sliv.ly 
Sliv.ps:        Sliv.ly ../common/global.ly Mliv.ly choirbook.ly global.ly 
score.ly

  So you can have:

%.ps:   %.ly
        lilypond --ps $<

dep depend.mk:
        depend_ly ps  S*.ly  >  depend.mk

-include depend.mk

  in your makefile.

Regards,
/Karl

#!/usr/bin/perl -w

use strict;

my %inc;
my @Inc = (".");

sub Usage() {
  print "Usage:
        depend_ly [-I<dir>[:<dir>]...] ext ly-file(s)
Where
        <dir> is where to find included ly-files

        ext is the file extension which your lilypond run should generate
        e.g.: pdf, ps, eps
";
  exit 1;
}

sub file_exist($) {
  my $file = shift;
  my $inc;

  foreach (@Inc) {
    if ($_ eq ".") {
      $inc = $file;
    } else {
      $inc = "$_/$file";
    }
    if (stat $inc ) {
      return $inc;
    }
  }
  return 0;
}

sub ly_inc($) {
  my $file = shift;
  my $fh;
  my %lst = (); # which files to recursively check

  # no file no dependancies
  open($fh, "<", $file) || return;
  while(<$fh>) {
    s/%.*$//;

    # this breaks for multiple \include per line
    m/\\include[ \t]+\"([^\"]+)\"/ || next; #"
    my $inc_file = $1;

    # consider only existing files as dependancies
    $inc_file = file_exist $inc_file || next;


    # only add this file to %lst if we have not checked it for dependancies
    if (!$inc{$inc_file}) { $lst{$inc_file} = 1; }

    # add this as an dependancy
    $inc{$inc_file} = 1;
  }

  foreach (keys(%lst)) {
    &ly_inc($_);
  }
}

if (@ARGV < 2) { Usage(); }

my $ext = shift @ARGV;
if ($ext =~ m/^-I(.*)$/) {
  push @Inc, split(/:/, $1);
  $ext = shift @ARGV;
}

my $file;
foreach $file (@ARGV) {
  # reset found dependancies for each new file to check
  %inc = ();
  &ly_inc($file);

  my $stem = $file;
  $stem =~ s/\.ly$//;
  my $prefix = "$stem.$ext";
  if ($ext eq "eps") {
    # more than one file is generated for the eps backend
    $prefix .= " $stem-systems.tex";
  }
  my $lst = join(" ", sort(keys(%inc)));
  print "$prefix:\t$file ", $lst, "\n";
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to