]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
* lily/include/slur-scoring.hh (struct Slur_score_state): new file
[lilypond.git] / buildscripts / builder.py
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         LILYPOND_BIN = 'lilypond-bin',
73         LILYOND_BOOK = 'lilypond-book',
74
75         #ugr
76         #LILYPOND_BOOK_FORMAT = 'texi',
77         LILYPOND_BOOK_FORMAT = '',
78         LILYPOND_BOOK_FLAGS = ['--format=$LILYPOND_BOOK_FORMAT'],
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
89         TEXI2DVI_FLAGS = [],
90         _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
91         )
92
93 TXT =\
94     Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS\
95     --no-split --no-headers $SOURCE',
96                suffix = '.txt', src_suffix = '.texi')
97 env.Append (BUILDERS = {'TXT': TXT})
98
99 INFO =\
100      Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
101               suffix = '.info', src_suffix = '.texi')
102 env.Append (BUILDERS = {'INFO': INFO})
103
104 HTML =\
105      Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCLUDES\
106      --html --no-split --no-headers $MAKEINFO_FLAGS $SOURCE',
107 suffix = '.html', src_suffix = '.texi')
108 env.Append (BUILDERS = {'HTML': HTML})
109
110 TEXI =\
111      Builder (action =
112               '$LILYPOND_BOOK --output=${TARGET.dir} \
113               --include=${TARGET.dir} $LILYPOND_INCFLAGS \
114               --process="$LILYPOND_BIN $LILYPOND_INCFLAGS" \
115               $LILYPOND_BOOK_FLAGS \
116               $SOURCE',
117               suffix = '.texi', src_suffix = '.tely')
118 env.Append (BUILDERS = {'TEXI': TEXI})
119
120 TEXIDVI =\
121         Builder (action = 'cd ${TARGET.dir} && \
122         texi2dvi --batch $_TEXI2DVI_FLAGS ${SOURCE.file}',
123                  suffix = '.dvi', src_suffix = '.texi')
124 env.Append (BUILDERS = {'TEXIDVI': TEXIDVI})
125
126 DVIPS =\
127       Builder (action = 'dvips -o $TARGET $DVIPS_FLAGS $SOURCE',
128                suffix = '.ps', src_suffix = '.dvi')
129 env.Append (BUILDERS = {'DVIPS': DVIPS})
130
131 DVIPDF =\
132       Builder (action = 'dvips -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
133                suffix = '.pdfps', src_suffix = '.dvi')
134 env.Append (BUILDERS = {'DVIPDF': DVIPDF})
135
136 PSPDF =\
137       Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
138                suffix = '.pdf', src_suffix = '.pdfps')
139 env.Append (BUILDERS = {'PSPDF': PSPDF})
140
141 PNG2EPS =\
142         Builder (action = 'convert $SOURCE $TARGET',
143                  suffix = '.eps', src_suffix = '.png')
144 env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
145
146
147
148
149
150 # FIXME: cleanup, see above
151
152
153 env.Append (
154
155         #urg
156         BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
157         BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
158 )
159
160
161 def add_ps_target (target, source, env):
162         base = os.path.splitext (str (target[0]))[0]
163         return (target + [base + '.ps'], source)
164
165 # TODO: 
166 # FIXME: INCLUDES, FLAGS, use LILYPOND_BIN for building ? 
167 lilypond =\
168          Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
169                   suffix = '.pdf', src_suffix = '.ly')
170 ##                  emitter = add_ps_target)
171 env.Append (BUILDERS = {'LilyPond': lilypond})
172
173 ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
174                suffix = '.ly', src_suffix = '.abc')
175 env.Append (BUILDERS = {'ABC': ABC})
176
177 def add_log_target (target, source, env):
178         base = os.path.splitext (str (target[0]))[0]
179         return (target + [base + '.log'], source)
180
181 def add_enc_ly_tex_target (target, source, env):
182         base = os.path.splitext (str (target[0]))[0]
183         return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
184                 source)
185 a = 'cd ${TARGET.dir} && \
186 MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
187 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
188 | grep -v "@\|>>"'
189 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
190 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
191                emitter = add_log_target)
192 env.Append (BUILDERS = {'TFM': tfm})
193
194 a = '$PYTHON $MF_TO_TABLE_PY \
195 --outdir=${TARGET.dir} \
196 --afm=${TARGET.base}.afm \
197 --enc=${TARGET.base}.enc \
198 --tex=${TARGET.base}.tex \
199 --ly=${TARGET.base}list.ly \
200 ${TARGET.base}.log'
201 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
202                emitter = add_enc_ly_tex_target)
203 env.Append (BUILDERS = {'AFM': afm})
204
205 def add_enc_src (target, source, env):
206         base = os.path.splitext (str (target[0]))[0]
207         return (target, source + [base + '.enc'])
208
209 # UGH, should fix --output option for mftrace
210 # mftrace --verbose is too verbose
211 a = 'cd ${TARGET.dir} && \
212 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
213 MFINPUTS=$srcdir/mf:.: \
214 mftrace --pfa --simplify --keep-trying $$encoding $TOO__verbose \
215 --include=${TARGET.dir} \
216 ${SOURCE.file}'
217
218 pfa = Builder (action = a,
219                suffix = '.pfa',
220                src_suffix = '.mf',
221                emitter = add_enc_src)
222 env.Append (BUILDERS = {'PFA': pfa})
223
224 # Specific builders
225
226 # experiment: switch off for speed.
227 if 0:
228         env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
229         a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
230         patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
231         env.Append (BUILDERS = {'PATCH': patch})
232
233 atvars = [
234 'BASH',
235 'DATE',
236 'sharedstatedir',
237 'GUILE',
238 'bindir',
239 'date',
240 'datadir',
241 'lilypond_datadir',
242 'lilypond_libdir',
243 'local_lilypond_datadir',
244 'local_lilypond_libdir',
245 'localedir',
246 'PACKAGE',
247 'package',
248 'PATHSEP',
249 'PERL',
250 'prefix',
251 'program_prefix',
252 'program_suffix',
253 'PYTHON',
254 'SHELL',
255 'TOPLEVEL_VERSION',
256 'step-bindir',
257 ]
258
259 # naming
260 def at_copy (target, source, env):
261     s = open (str (source[0])).read ()
262     for i in atvars:
263             if env.has_key (i):
264                     s = string.replace (s, '@%s@'% i, env[i])
265     t = str (target[0])
266     open (t, 'w').write (s)
267     # wugh
268     if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
269             os.chmod (t, 0755)
270
271 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
272 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
273
274 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
275               suffix = '.mo', src_suffix = '.po')
276 env.Append (BUILDERS = {'MO': MO})
277
278 # ' '; ?
279 ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po ; '
280 a = ugh + 'xgettext --default-domain=lilypond --join \
281 --output-dir=${TARGET.dir} --add-comments \
282 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
283 PO = Builder (action = a, suffix = '.pot',
284               src_suffix = ['.cc', '.hh', '.py'], multi = 1)
285 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
286                                 'lilypond.pot')
287 env['pocommand'] = a
288
289 ugh = '; mv ${TARGET} ${SOURCE}'
290 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
291 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
292 env.Append (BUILDERS = {'POMERGE': POMERGE})
293
294 #UGRr
295 a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
296 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
297 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
298
299 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
300 --name=${TARGET.base} --title="$TITLE" $SOURCES'
301 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
302 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
303
304
305 def mutopia (ly = None, abc = None):
306
307         # FIXME: ugr, huh?  The values from ../SConstruct get appended
308         # to the predefined values from this builder context:
309
310         # abc2ly/usr/bin/python ..../abc2.py
311
312         # Override them again to fix web build...
313
314         
315         BUILD_ABC2LY = '${set__x}$PYTHON $srcdir/scripts/abc2ly.py'
316         BUILD_LILYPOND = '${set__x}$PYTHON $srcdir/scripts/lilypond.py${__verbose}'
317         e = env.Copy (
318                 LILYPOND = BUILD_LILYPOND,
319                 ABC2LY = BUILD_ABC2LY,
320         )
321         
322         if not abc:
323                 abc = base_glob ('*.abc')
324         if not ly:
325                 ly = base_glob ('*.ly') + map (e.ABC, abc)
326         pdf = map (e.LilyPond, ly)
327         
328         # We need lily and mf to build these.
329         env.Depends (pdf, ['#/lily', '#/mf'])
330         env.Alias ('doc', pdf)
331
332 Export ('mutopia')
333
334
335 def collate (title = 'collated files'):
336         ly = base_glob ('*.ly')
337         
338         e = env.Copy (
339                 TITLE = title,
340                 LILYPOND_BOOK_FLAGS = '''--process="lilypond-bin --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'"''',
341                                                                                                             __verbose = ' --verbose',
342                                                                                                             )
343         #               
344         tely = e.LYS2TELY ('collated-files', ly)
345         texi = e.TEXI (tely)
346         # We need lily and mf to build these.
347         env.Depends (texi, ['#/lily', '#/mf'])
348         dvi = e.TEXIDVI (texi)
349         pspdf = e.DVIPDF (dvi)
350         pdf = e.PSPDF (pspdf)
351         html = e.HTML (texi)
352
353         env.Alias ('doc', pdf)
354         env.Alias ('doc', html)
355
356 Export ('collate')
357
358 Export ('env')