]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
Clean up buildscripts
[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 lilypond_book_flags = '''--format=$LILYPOND_BOOK_FORMAT --process="lilypond -I$srcdir -I$srcdir/input/test $__verbose --backend=eps --formats=ps,png --header=texidoc -dinternal-type-checking -ddump-signatures -danti-alias-factor=2" '''
69
70 env.Append (
71     BSTINPUTS = '${SOURCE.dir}:${TARGET.dir}:',
72     BIB2HTML = '$PYTHON $srcdir/buildscripts/bib2html.py',
73     LILYOND_BOOK = 'lilypond-book',
74     LILYPOND_BOOK_FORMAT = '',
75     LILYPOND_BOOK_FLAGS = lilypond_book_flags,
76     LILYPOND_PATH = [],
77     # The SCons way around FOO_PATH:
78     LILYPOND_INCFLAGS = '$( ${_concat(INCPREFIX, LILYPOND_PATH, INCSUFFIX, __env__)} $)',
79
80     MAKEINFO_PATH = [],
81     MAKEINFO_FLAGS = [],
82     MAKEINFO_INCFLAGS = '$( ${_concat(INCPREFIX, MAKEINFO_PATH, INCSUFFIX, __env__, RDirs)} $)',
83     #TEXI2DVI_FLAGS = [],
84     _TEXI2DVI_FLAGS = '$( ${_concat(" ", TEXI2DVI_FLAGS,)} $)',
85     )
86
87 TXT =\
88   Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS\
89   --no-split --no-headers $SOURCE',
90        suffix = '.txt', src_suffix = '.texi')
91 env.Append (BUILDERS = {'TXT': TXT})
92
93 INFO =\
94   Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCFLAGS $SOURCE',
95        suffix = '.info', src_suffix = '.texi')
96 env.Append (BUILDERS = {'INFO': INFO})
97
98 HTML =\
99   Builder (action = '$MAKEINFO --output=$TARGET $MAKEINFO_INCLUDES\
100   --html --no-split --no-headers $MAKEINFO_FLAGS $SOURCE',
101 suffix = '.html', src_suffix = '.texi')
102 env.Append (BUILDERS = {'HTML': HTML})
103
104 TEXI =\
105   Builder (action =
106        '$LILYPOND_BOOK --output=${TARGET.dir} \
107        --include=${TARGET.dir} $LILYPOND_INCFLAGS \
108        --process="$LILYPOND $LILYPOND_INCFLAGS" \
109        $LILYPOND_BOOK_FLAGS \
110        $SOURCE',
111        suffix = '.texi', src_suffix = '.tely')
112 env.Append (BUILDERS = {'TEXI': TEXI})
113
114 TEXIDVI =\
115     Builder (action = 'cd ${TARGET.dir} && \
116     texi2dvi --batch -I $srcdir/Documentation/user $_TEXI2DVI_FLAGS ${SOURCE.file}',
117         suffix = '.dvi', src_suffix = '.texi')
118 env.Append (BUILDERS = {'TEXIDVI': TEXIDVI})
119
120 DVIPS =\
121    Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET $DVIPS_FLAGS $SOURCE',
122        suffix = '.ps', src_suffix = '.dvi')
123 env.Append (BUILDERS = {'DVIPS': DVIPS})
124
125 DVIPDF =\
126    Builder (action = 'TEXINPUTS=${TARGET.dir}:$$TEXINPUTS $DVIPS -o $TARGET -Ppdf $DVIPS_FLAGS $SOURCE',
127        suffix = '.pdfps', src_suffix = '.dvi')
128 env.Append (BUILDERS = {'DVIPDF': DVIPDF})
129
130 PSPDF =\
131    Builder (action = 'ps2pdf $PSPDF_FLAGS $SOURCE $TARGET',
132        suffix = '.pdf', src_suffix = '.pdfps')
133 env.Append (BUILDERS = {'PSPDF': PSPDF})
134
135 PNG2EPS =\
136     Builder (action = 'convert $SOURCE $TARGET',
137         suffix = '.eps', src_suffix = '.png')
138 env.Append (BUILDERS = {'PNG2EPS': PNG2EPS})
139
140 EPS2PNG =\
141     Builder (action = 'convert $SOURCE $TARGET',
142         suffix = '.png', src_suffix = '.eps')
143 env.Append (BUILDERS = {'EPS2PNG': EPS2PNG})
144
145 def add_ps_target (target, source, env):
146     base = os.path.splitext (str (target[0]))[0]
147     return (target + [base + '.ps'], source)
148
149 lilypond =\
150     Builder (action = '$LILYPOND --output=${TARGET.base} --include=${TARGET.dir} $SOURCE',
151          suffix = '.pdf', src_suffix = '.ly')
152 ##                    emitter = add_ps_target)
153 env.Append (BUILDERS = {'LilyPond': lilypond})
154
155 ABC = Builder (action = '$ABC2LY --output=${TARGET} --strict $SOURCE',
156        suffix = '.ly', src_suffix = '.abc')
157 env.Append (BUILDERS = {'ABC': ABC})
158
159 def add_log_target (target, source, env):
160     base = os.path.splitext (str (target[0]))[0]
161     return (target + [base + '.log'], source)
162
163 def add_tfm_target (target, source, env):
164     base = os.path.splitext (str (target[0]))[0]
165     return (target + [base + '.tfm'], source)
166
167 def add_lisp_enc_target (target, source, env):
168     base = os.path.splitext (str (target[0]))[0]
169     return (target + [base + '.lisp', base + '.enc'],
170         source)
171
172 def add_cff_cffps_svg (target, source, env):
173     base = os.path.splitext (str (target[0]))[0]
174     return (target + [base + '.cff', base + '.cff.ps', base + '.svg'],
175         source)
176
177 a = 'cd ${TARGET.dir} \
178 && MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir}: \
179 $MF "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
180 | grep -v "@\|>>\|w:\|h:";'
181 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
182 #               emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
183        emitter = add_log_target)
184 env.Append (BUILDERS = {'TFM': tfm})
185
186 a = '$PYTHON $MF_TO_TABLE_PY \
187 --outdir=${TARGET.dir} \
188 --global-lisp=${TARGET.base}.otf-gtable \
189 --lisp=${TARGET.base}.lisp \
190 --enc=${TARGET.base}.enc \
191 ${TARGET.base}.log'
192 gtable = Builder (action = a, suffix = '.otf-gtable', src_suffix = '.log',
193          emitter = add_lisp_enc_target)
194 env.Append (BUILDERS = {'GTABLE': gtable})
195
196 def add_enc_src (target, source, env):
197     base = os.path.splitext (str (target[0]))[0]
198     #return (target, source + [base + '.enc'])
199     return (target + [base + '.pfb', base + '.svg'], source + [base + '.enc'])
200
201 def add_svg (target, source, env):
202     base = os.path.splitext (str (target[0]))[0]
203     return (target + [base + '.svg'], source)
204
205 # FIXME UGH, should fix --output option for mftrace
206 a = 'cd ${TARGET.dir} && \
207 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
208 MFINPUTS=$srcdir/mf:.: \
209 $MFTRACE --formats=pfa,pfb,svg --simplify --keep-trying --no-afm \
210 $$encoding $__verbose \
211 --include=${TARGET.dir} \
212 ${SOURCE.file}'
213
214 pfa = Builder (action = a,
215        suffix = '.pfa',
216        src_suffix = '.mf',
217        emitter = add_enc_src)
218 env.Append (BUILDERS = {'PFA': pfa})
219
220 a = ['(cd ${TARGET.dir} && $FONTFORGE -script ${SOURCE.file})',
221 #     '$PYTHON $srcdir/buildscripts/ps-embed-cff.py ${SOURCE.base}.cff $$(cat ${SOURCE.base}.fontname) ${SOURCE.base}.cff.ps',
222   'rm -f ${TARGET.dir}/*.scale.pfa']
223 otf = Builder (action = a,
224        suffix = '.otf',
225        src_suffix = '.pe',
226 #               emitter = add_cff_cffps_svg
227                emitter = add_svg
228        )
229 env.Append (BUILDERS = {'OTF': otf})
230
231
232 # Specific builders
233
234 env['DIFF_PY'] = '$srcdir/stepmake/bin/package-diff.py'
235 a = '$PYTHON $DIFF_PY $NO__verbose --outdir=${TARGET.dir}'
236 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
237 env.Append (BUILDERS = {'PATCH': patch})
238
239 atvars = [
240 'BASH',
241 'DATE',
242 'sharedstatedir',
243 'GUILE',
244 'bindir',
245 'date',
246 'datadir',
247 'lilypond_datadir',
248 'lilypond_libdir',
249 'local_lilypond_datadir',
250 'local_lilypond_libdir',
251 'localedir',
252 'PACKAGE',
253 'package',
254 'PATHSEP',
255 'PERL',
256 'prefix',
257 'program_prefix',
258 'program_suffix',
259 'PYTHON',
260 'SHELL',
261 'TOPLEVEL_VERSION',
262 'step-bindir',
263 ]
264
265 def at_copy (target, source, env):
266   n = str (source[0])
267   s = open (n).read ()
268   for i in atvars:
269       if env.has_key (i):
270           s = string.replace (s, '@%s@'% i, env[i])
271   t = str (target[0])
272   open (t, 'w').write (s)
273   # wugh
274   if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
275       os.chmod (t, 0755)
276
277 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
278 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
279
280 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
281        suffix = '.mo', src_suffix = '.po')
282 env.Append (BUILDERS = {'MO': MO})
283
284 ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po ; '
285 a = ugh + 'xgettext --default-domain=lilypond --join \
286 --output-dir=${TARGET.dir} --add-comments \
287 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
288 PO = Builder (action = a, suffix = '.pot',
289        src_suffix = ['.cc', '.hh', '.py'], multi = 1)
290 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
291                 'lilypond.pot')
292 env['pocommand'] = a
293
294 ugh = '; mv ${TARGET} ${SOURCE}'
295 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
296 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
297 env.Append (BUILDERS = {'POMERGE': POMERGE})
298
299 a = 'BSTINPUTS=$BSTINPUTS $BIB2HTML -o $TARGET $SOURCE'
300 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
301 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
302
303 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
304 --name=${TARGET.base} --title="$TITLE" $SOURCES'
305 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
306 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
307
308
309 def mutopia (ly=None, abc=None):
310     e = env.Copy (
311         LILYPOND_BOOK_FLAGS = lilypond_book_flags,
312         )
313     
314     if not abc:
315         abc = base_glob ('*.abc')
316     if not ly:
317         ly = base_glob ('*.ly') + map (e.ABC, abc)
318     pdf = map (e.LilyPond, ly)
319     env.Depends (pdf, ['#/lily', '#/mf'])
320     env.Alias ('doc', pdf)
321
322 Export ('mutopia')
323
324 def collate (title = 'collated files'):
325     ly = base_glob ('*.ly')
326     
327     e = env.Copy (
328         TITLE = title,
329         LILYPOND_BOOK_FLAGS = lilypond_book_flags,
330         # __verbose = ' --verbose',
331         )
332     tely = e.LYS2TELY ('collated-files', ly)
333     texi = e.TEXI (tely)
334     env.Depends (texi, ['#/lily', '#/mf'])
335     dvi = e.TEXIDVI (texi)
336     pspdf = e.DVIPDF (dvi)
337     pdf = e.PSPDF (pspdf)
338     html = e.HTML (texi)
339
340     env.Alias ('doc', pdf)
341     env.Alias ('doc', html)
342
343 Export ('collate')
344
345 Export ('env')