]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
patch::: 1.3.132.jcn1
[lilypond.git] / scripts / lilypond-book.py
index ea8f9ce871a8d7240a75be47dd9ff4f50bcbb505..e395ca7d48c87d21d06f8246748cb9467c6039b2 100644 (file)
@@ -212,8 +212,10 @@ class LatexPaper:
                if not self.m_use_geometry:
                        return latex_linewidths[self.m_papersize][self.m_fontsize]
                else:
-                       geo_opts = (a == None, b == None, c == None)
-                       
+                       geo_opts = (self.m_geo_lmargin == None,
+                                   self.m_geo_width == None,
+                                   self.m_geo_rmargin == None)
+
                        if geo_opts == (1, 1, 1):
                                if self.m_geo_textwidth:
                                        return self.m_geo_textwidth
@@ -520,7 +522,8 @@ def compose_full_body (body, opts):
        optstring = string.join (opts, ' ')
        optstring = re.sub ('\n', ' ', optstring)
        body = r"""
-%% Generated by lilypond-book.py; options are %s  %%ughUGH not original options
+%% Generated automatically by: lilypond-book.py
+%% options are %s  %%ughUGH not original options
 \include "paper%d.ly"
 \paper  { linewidth = %f \pt; } 
 """ % (optstring, music_size, l) + body
@@ -802,7 +805,7 @@ def schedule_lilypond_block (chunk):
        (type, body, opts) = chunk
        assert type == 'lilypond'
        file_body = compose_full_body (body, opts)
-       basename = `abs(hash (file_body))`
+       basename = 'lily-' + `abs(hash (file_body))`
        for o in opts:
                m = re.search ('filename="(.*?)"', o)
                if m:
@@ -895,6 +898,7 @@ def system (cmd):
        return st
 
 def compile_all_files (chunks):
+       global foutn
        eps = []
        tex = []
        png = []
@@ -923,10 +927,25 @@ def compile_all_files (chunks):
                                x = os.path.join (g_here_dir, x)
                        return ' -I %s' % x
 
-               incs =  map (incl_opt, include_path)
+               incs = map (incl_opt, include_path)
                lilyopts = string.join (incs, ' ' )
+               if do_deps:
+                       lilyopts = lilyopts + ' --dependencies '
+                       if g_outdir:
+                               lilyopts = lilyopts + '--dep-prefix=' + g_outdir + '/'
                texfiles = string.join (tex, ' ')
                system ('lilypond --header=texidoc %s %s' % (lilyopts, texfiles))
+
+               #
+               # Ugh, fixing up dependencies for .tex generation
+               #
+               if do_deps:
+                       depfiles=map (lambda x: re.sub ('(.*)\.ly', '\\1.dep', x), tex)
+                       for i in depfiles:
+                               text=open (i).read ()
+                               text=re.sub ('\n([^:\n]*):', '\n' + foutn + ':', text)
+                               open (i, 'w').write (text)
+
        for e in eps:
                system(r"tex '\nonstopmode \input %s'" % e)
                system(r"dvips -E -o %s %s" % (e + '.eps', e))
@@ -934,8 +953,7 @@ def compile_all_files (chunks):
                cmd = r"""gs -sDEVICE=pgm  -dTextAlphaBits=4 -dGraphicsAlphaBits=4  -q -sOutputFile=- -r90 -dNOPAUSE %s -c quit | pnmcrop | pnmtopng > %s"""
                cmd = cmd % (g + '.eps', g + '.png')
                system (cmd)
-       if g_outdir:
-               os.chdir(d)
+       os.chdir (d)
 
 
 def update_file (body, name):
@@ -1032,15 +1050,34 @@ Han-Wen Nienhuys <hanwen@cs.uu.nl>
        sys.exit (0)
 
 
-def write_deps (fn, target):
-       sys.stdout.write('writing `%s\'\n' % os.path.join(g_outdir, fn))
+def write_deps (fn, target, chunks):
+       global read_files
+       sys.stdout.write('Writing `%s\'\n' % os.path.join(g_outdir, fn))
        f = open (os.path.join(g_outdir, fn), 'w')
        f.write ('%s%s: ' % (g_dep_prefix, target))
-       for d in __main__.read_files:
+       for d in read_files:
                f.write ('%s ' %  d)
+       basenames=[]
+        for c in chunks:
+               if c[0] == 'lilypond':
+                       (type, body, opts, todo, basename) = c;
+                       basenames.append (basename)
+       for d in basenames:
+               if g_outdir:
+                       d=g_outdir + '/' + d
+               if g_dep_prefix:
+                       #if not os.isfile (d): # thinko?
+                       if not re.search ('/', d):
+                               d = g_dep_prefix + d
+               f.write ('%s.tex ' %  d)
+       f.write ('\n')
+       #if len (basenames):
+       #       for d in basenames:
+       #               f.write ('%s.ly ' %  d)
+       #       f.write (' : %s' % target)
        f.write ('\n')
        f.close ()
-       __main__.read_files = []
+       read_files = []
 
 def identify():
        sys.stdout.write ('lilypond-book (GNU LilyPond) %s\n' % program_version)
@@ -1076,7 +1113,9 @@ def fix_epswidth (chunks):
        return newchunks
 
 
+foutn=""
 def do_file(input_filename):
+       global foutn
        file_settings = {}
        if outname:
                my_outname = outname
@@ -1097,6 +1136,8 @@ def do_file(input_filename):
        scan_preamble(chunks)
        chunks = process_lilypond_blocks(my_outname, chunks)
 
+       foutn = os.path.join (g_outdir, my_outname + '.' + format)
+
        # Do It.
        if __main__.g_run_lilypond:
                compile_all_files (chunks)
@@ -1107,7 +1148,6 @@ def do_file(input_filename):
 
        x = 0
        chunks = completize_preamble (chunks)
-       foutn = os.path.join(g_outdir, my_outname + '.' + format)
        sys.stderr.write ("Writing `%s'\n" % foutn)
        fout = open (foutn, 'w')
        for c in chunks:
@@ -1116,7 +1156,7 @@ def do_file(input_filename):
        # should chmod -w
 
        if do_deps:
-               write_deps (my_depname, foutn)
+               write_deps (my_depname, foutn, chunks)
 
 
 outname = ''