~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to buildscripts/builder.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-python-*-
 
2
 
 
3
import glob
 
4
import os
 
5
import string
 
6
 
 
7
Import ('env')
 
8
 
 
9
# utility
 
10
 
 
11
def add_suffixes (target, source, env, target_suffixes, src_suffixes):
 
12
        base = os.path.splitext (str (target[0]))[0]
 
13
        return (target + map (lambda x: base + x, target_suffixes),
 
14
                source + map (lambda x: base + x, src_suffixes))
 
15
 
 
16
# junkme; see _concat
 
17
def join_path (path, infix=os.pathsep, prefix = ''):
 
18
        def dir (x):
 
19
                if x and x[0] == '#':
 
20
                        return env['srcdir'] + x[1:]
 
21
                return x
 
22
        return string.join (map (lambda x: prefix + dir (x), path), infix)
 
23
 
 
24
 
 
25
def src_glob (s):
 
26
        here = os.getcwd ()
 
27
        os.chdir (env.Dir ('.').srcnode ().abspath)
 
28
        result = glob.glob (s)
 
29
        os.chdir (here)
 
30
        return result
 
31
 
 
32
Export ('src_glob')
 
33
 
 
34
def base_glob (s):
 
35
        return map (lambda x: os.path.splitext (x)[0], src_glob (s))
 
36
 
 
37
Export ('base_glob')
 
38
 
 
39
def install (target, dir):
 
40
        dest = env['DESTDIR'] + dir
 
41
        if type (target) == type ([]):
 
42
                map (lambda x: env.Install (dir, x), target)
 
43
        else:
 
44
                env.Install (dir, target)
 
45
        env.Alias ('install', dir)
 
46
 
 
47
Export ('install')
 
48
 
 
49
def _fixme (s):
 
50
        x = string.replace (s, '#', env['srcdir'])
 
51
        x = string.replace (x, '@', env['absbuild'])
 
52
        return x
 
53
 
 
54
# Clean separation between generic action + flags and actual
 
55
# configuration and flags in environment for this build.
 
56
 
 
57
# Generic builders could/should be part of SCons.
 
58
 
 
59
 
 
60
HH = Builder (action = 'bison -d -o ${TARGET.base}.cc $SOURCE',
 
61
              suffix = '.hh', src_suffix = '.yy')
 
62
env.Append (BUILDERS = {'HH' : HH})
 
63
 
 
64
 
 
65
# Setup LilyPond environment.  For the LilyPond build, we override
 
66
# some of these commands in the ENVironment.
 
67
 
 
68
env.Append (
 
69
        _fixme = _fixme,
 
70
        ##ABC2LY = 'abc2ly',
 
71
        ##LILYPOND = 'lilypond',
 
72
        LILYOND_BOOK = 'lilypond-book',
 
73
 
 
74
        #ugr
 
75
        #LILYPOND_BOOK_FORMAT = 'texi',
 
76
        LILYPOND_BOOK_FORMAT = '',
 
77
        #LILYPOND_BOOK_FLAGS = ['--format=$LILYPOND_BOOK_FORMAT'],
 
78
        LILYPOND_BOOK_FLAGS = '''--format=$LILYPOND_BOOK_FORMAT --process="lilypond --backend=eps --formats=ps,png --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'" ''',
 
79
 
 
80
        LILYPOND_PATH = [],
 
81
        # The SCons way around FOO_PATH:
 
82
        ##LILYPOND_INCFLAGS = '$( ${_concat(INCPREFIX, LILYPOND_PATH, INCSUFFIX, __env__, RDirs)} $)',
 
83
        LILYPOND_INCFLAGS = '$( ${_concat(INCPREFIX, LILYPOND_PATH, INCSUFFIX, __env__)} $)',
 
84
 
 
85
        MAKEINFO_PATH = [],
 
86
        MAKEINFO_FLAGS = [],
 
87
        MAKEINFO_INCFLAGS = '$( ${_concat(INCPREFIX, MAKEINFO_PATH, INCSUFFIX, __env__, RDirs)} $)',
 
88
        # should not be necessary
 
89
        # PYTHONPATH = ['$absbuild/python/$out'],
 
90
        TEXI2DVI_FLAGS = [],
 
91
        _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
 
92
        )
 
93
 
 
94
TXT =\
 
95
    Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS\
 
96
    --no-split --no-headers $SOURCE',
 
97
               suffix = '.txt', src_suffix = '.texi')
 
98
env.Append (BUILDERS = {'TXT': TXT})
 
99
 
 
100
INFO =\
 
101
     Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
 
102
              suffix = '.info', src_suffix = '.texi')
 
103
env.Append (BUILDERS = {'INFO': INFO})
 
104
 
 
105
HTML =\
 
106
     Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCLUDES\
 
107
     --html --no-split --no-headers $MAKEINFO_FLAGS $SOURCE',
 
108
suffix = '.html', src_suffix = '.texi')
 
109
env.Append (BUILDERS = {'HTML': HTML})
 
110
 
 
111
TEXI =\
 
112
     Builder (action =
 
113
              '$LILYPOND_BOOK --output=${TARGET.dir} \
 
114
              --include=${TARGET.dir} $LILYPOND_INCFLAGS \
 
115
              --process="$LILYPOND $LILYPOND_INCFLAGS" \
 
116
              $LILYPOND_BOOK_FLAGS \
 
117
              $SOURCE',
 
118
              suffix = '.texi', src_suffix = '.tely')
 
119
env.Append (BUILDERS = {'TEXI': TEXI})
 
120
 
 
121
TEXIDVI =\
 
122
        Builder (action = 'cd ${TARGET.dir} && \
 
123
        texi2dvi --batch $_TEXI2DVI_FLAGS ${SOURCE.file}',
 
124
                 suffix = '.dvi', src_suffix = '.texi')
 
125
env.Append (BUILDERS = {'TEXIDVI': TEXIDVI})
 
126
 
 
127
DVIPS =\
 
128
      Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET $DVIPS_FLAGS $SOURCE',
 
129
               suffix = '.ps', src_suffix = '.dvi')
 
130
env.Append (BUILDERS = {'DVIPS': DVIPS})
 
131
 
 
132
DVIPDF =\
 
133
      Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
 
134
               suffix = '.pdfps', src_suffix = '.dvi')
 
135
env.Append (BUILDERS = {'DVIPDF': DVIPDF})
 
136
 
 
137
PSPDF =\
 
138
      Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
 
139
               suffix = '.pdf', src_suffix = '.pdfps')
 
140
env.Append (BUILDERS = {'PSPDF': PSPDF})
 
141
 
 
142
PNG2EPS =\
 
143
        Builder (action = 'convert $SOURCE $TARGET',
 
144
                 suffix = '.eps', src_suffix = '.png')
 
145
env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
 
146
 
 
147
 
 
148
 
 
149
# FIXME: cleanup, see above
 
150
 
 
151
 
 
152
env.Append (
 
153
 
 
154
        #urg
 
155
        BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
 
156
        BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
 
157
)
 
158
 
 
159
 
 
160
def add_ps_target (target, source, env):
 
161
        base = os.path.splitext (str (target[0]))[0]
 
162
        return (target + [base + '.ps'], source)
 
163
 
 
164
lilypond =\
 
165
         Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
 
166
                  suffix = '.pdf', src_suffix = '.ly')
 
167
##                  emitter = add_ps_target)
 
168
env.Append (BUILDERS = {'LilyPond': lilypond})
 
169
 
 
170
ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
 
171
               suffix = '.ly', src_suffix = '.abc')
 
172
env.Append (BUILDERS = {'ABC': ABC})
 
173
 
 
174
def add_log_target (target, source, env):
 
175
        base = os.path.splitext (str (target[0]))[0]
 
176
        return (target + [base + '.log'], source)
 
177
 
 
178
def add_tfm_target (target, source, env):
 
179
        base = os.path.splitext (str (target[0]))[0]
 
180
        return (target + [base + '.tfm'], source)
 
181
 
 
182
def add_lisp_enc_tex_ly_target (target, source, env):
 
183
        base = os.path.splitext (str (target[0]))[0]
 
184
        return (target + [base + '.lisp', base + '.enc', base + '.tex',
 
185
                          base + 'list.ly'],
 
186
                source)
 
187
 
 
188
def add_cff_cffps_svg (target, source, env):
 
189
        base = os.path.splitext (str (target[0]))[0]
 
190
        return (target + [base + '.cff', base + '.cff.ps', base + '.svg'],
 
191
                source)
 
192
 
 
193
a = 'cd ${TARGET.dir} \
 
194
&& MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
 
195
$MF "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
 
196
| grep -v "@\|>>\|w:\|h:";'
 
197
tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
 
198
#              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
 
199
               emitter = add_log_target)
 
200
env.Append (BUILDERS = {'TFM': tfm})
 
201
 
 
202
a = '$PYTHON $MF_TO_TABLE_PY \
 
203
--outdir=${TARGET.dir} \
 
204
--global-lisp=${TARGET.base}.otf-gtable \
 
205
--lisp=${TARGET.base}.lisp \
 
206
--enc=${TARGET.base}.enc \
 
207
--tex=${TARGET.base}.tex \
 
208
--ly=${TARGET.base}list.ly \
 
209
${TARGET.base}.log'
 
210
gtable = Builder (action = a, suffix = '.otf-gtable', src_suffix = '.log',
 
211
                  emitter = add_lisp_enc_tex_ly_target)
 
212
env.Append (BUILDERS = {'GTABLE': gtable})
 
213
 
 
214
def add_enc_src (target, source, env):
 
215
        base = os.path.splitext (str (target[0]))[0]
 
216
        return (target, source + [base + '.enc'])
 
217
 
 
218
# FIXME UGH, should fix --output option for mftrace
 
219
a = 'cd ${TARGET.dir} && \
 
220
if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
 
221
MFINPUTS=$srcdir/mf:.: \
 
222
$MFTRACE --formats=pfa --simplify --keep-trying --no-afm \
 
223
$$encoding $__verbose \
 
224
--include=${TARGET.dir} \
 
225
${SOURCE.file}'
 
226
 
 
227
pfa = Builder (action = a,
 
228
               suffix = '.pfa',
 
229
               src_suffix = '.mf',
 
230
               emitter = add_enc_src)
 
231
env.Append (BUILDERS = {'PFA': pfa})
 
232
 
 
233
a = ['(cd ${TARGET.dir} && $FONTFORGE -script ${SOURCE.file})',
 
234
#     '$PYTHON $srcdir/buildscripts/ps-embed-cff.py ${SOURCE.base}.cff $$(cat ${SOURCE.base}.fontname) ${SOURCE.base}.cff.ps',
 
235
     'rm -f ${TARGET.dir}/*.scale.pfa']
 
236
otf = Builder (action = a,
 
237
               suffix = '.otf',
 
238
               src_suffix = '.pe',
 
239
#              emitter = add_cff_cffps_svg
 
240
               )
 
241
env.Append (BUILDERS = {'OTF': otf})
 
242
 
 
243
 
 
244
# Specific builders
 
245
 
 
246
env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
 
247
a = '$PYTHON $DIFF_PY $NO__verbose --outdir=${TARGET.dir}'
 
248
patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
 
249
env.Append (BUILDERS = {'PATCH': patch})
 
250
 
 
251
atvars = [
 
252
'BASH',
 
253
'DATE',
 
254
'sharedstatedir',
 
255
'GUILE',
 
256
'bindir',
 
257
'date',
 
258
'datadir',
 
259
'lilypond_datadir',
 
260
'lilypond_libdir',
 
261
'local_lilypond_datadir',
 
262
'local_lilypond_libdir',
 
263
'localedir',
 
264
'PACKAGE',
 
265
'package',
 
266
'PATHSEP',
 
267
'PERL',
 
268
'prefix',
 
269
'program_prefix',
 
270
'program_suffix',
 
271
'PYTHON',
 
272
'SHELL',
 
273
'TOPLEVEL_VERSION',
 
274
'step-bindir',
 
275
]
 
276
 
 
277
# naming
 
278
def at_copy (target, source, env):
 
279
    n = str (source[0])
 
280
    s = open (n).read ()
 
281
    for i in atvars:
 
282
            if env.has_key (i):
 
283
                    s = string.replace (s, '@%s@'% i, env[i])
 
284
    t = str (target[0])
 
285
    open (t, 'w').write (s)
 
286
    # wugh
 
287
    if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
 
288
            os.chmod (t, 0755)
 
289
 
 
290
AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
 
291
env.Append (BUILDERS = {'AT_COPY': AT_COPY})
 
292
 
 
293
# naming
 
294
def at_copy_ext (target, source, env):
 
295
    n = str (source[0])
 
296
    s = open (n).read ()
 
297
    for i in atvars:
 
298
            if env.has_key (i):
 
299
                    s = string.replace (s, '@%s@'% i, env[i])
 
300
    # whugh
 
301
    e = os.path.splitext (n)[1]
 
302
    t = str (target[0]) + e
 
303
    open (t, 'w').write (s)
 
304
 
 
305
AT_COPY_EXT = Builder (action = at_copy_ext, src_suffix = ['.py', '.sh',])
 
306
env.Append (BUILDERS = {'AT_COPY_EXT': AT_COPY_EXT})
 
307
 
 
308
 
 
309
MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
 
310
              suffix = '.mo', src_suffix = '.po')
 
311
env.Append (BUILDERS = {'MO': MO})
 
312
 
 
313
# ' '; ?
 
314
ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po ; '
 
315
a = ugh + 'xgettext --default-domain=lilypond --join \
 
316
--output-dir=${TARGET.dir} --add-comments \
 
317
--keyword=_ --keyword=_f --keyword=_i $SOURCES'
 
318
PO = Builder (action = a, suffix = '.pot',
 
319
              src_suffix = ['.cc', '.hh', '.py'], multi = 1)
 
320
env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
 
321
                                'lilypond.pot')
 
322
env['pocommand'] = a
 
323
 
 
324
ugh = '; mv ${TARGET} ${SOURCE}'
 
325
a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
 
326
POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
 
327
env.Append (BUILDERS = {'POMERGE': POMERGE})
 
328
 
 
329
#UGRr
 
330
a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
 
331
BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
 
332
env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
 
333
 
 
334
a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
 
335
--name=${TARGET.base} --title="$TITLE" $SOURCES'
 
336
LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
 
337
env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
 
338
 
 
339
 
 
340
def mutopia (ly = None, abc = None):
 
341
 
 
342
        # FIXME: ugr, huh?  The values from ../SConstruct get appended
 
343
        # to the predefined values from this builder context:
 
344
 
 
345
        # abc2ly/usr/bin/python ..../abc2.py
 
346
 
 
347
        # Override them again to fix web build...
 
348
 
 
349
        
 
350
        #BUILD_ABC2LY = '${set__x}$PYTHON $srcdir/scripts/abc2ly.py'
 
351
        #BUILD_LILYPOND = '$absbuild/$out/lilypond ${__verbose}'
 
352
        e = env.Copy (
 
353
                #LILYPOND = BUILD_LILYPOND,
 
354
                #ABC2LY = BUILD_ABC2LY,
 
355
        )
 
356
        
 
357
        if not abc:
 
358
                abc = base_glob ('*.abc')
 
359
        if not ly:
 
360
                ly = base_glob ('*.ly') + map (e.ABC, abc)
 
361
        pdf = map (e.LilyPond, ly)
 
362
        
 
363
        # We need lily and mf to build these.
 
364
        env.Depends (pdf, ['#/lily', '#/mf'])
 
365
        env.Alias ('doc', pdf)
 
366
 
 
367
Export ('mutopia')
 
368
 
 
369
 
 
370
def collate (title = 'collated files'):
 
371
        ly = base_glob ('*.ly')
 
372
        
 
373
        e = env.Copy (
 
374
                TITLE = title,
 
375
                LILYPOND_BOOK_FLAGS = '''--process="lilypond --backend=eps --formats=ps,png --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'" ''',
 
376
                                                                                                                                       __verbose = ' --verbose',
 
377
                                                                                                                                       )
 
378
        #
 
379
        tely = e.LYS2TELY ('collated-files', ly)
 
380
        texi = e.TEXI (tely)
 
381
        # We need lily and mf to build these.
 
382
        env.Depends (texi, ['#/lily', '#/mf'])
 
383
        dvi = e.TEXIDVI (texi)
 
384
        pspdf = e.DVIPDF (dvi)
 
385
        pdf = e.PSPDF (pspdf)
 
386
        html = e.HTML (texi)
 
387
 
 
388
        env.Alias ('doc', pdf)
 
389
        env.Alias ('doc', html)
 
390
 
 
391
Export ('collate')
 
392
 
 
393
Export ('env')