]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
3811bc7969cd7c9999c8eea262a1d46901e013e5
[lilypond.git] / buildscripts / builder.py
1 # -*-python-*-
2
3 import glob
4 import os
5 import string
6
7 Import ('env')
8
9 # junkme
10 srcdir = env['srcdir']
11
12 def join_path (path, infix=os.pathsep, prefix = ''):
13         def dir (x):
14                 if x and x[0] == '#':
15                         return srcdir + x[1:]
16                 return x
17         return string.join (map (lambda x: prefix + dir (x), path), infix)
18
19 env['join_path'] = join_path
20
21 env['MAKEINFO_INCLUDES'] = join_path (env['MAKEINFO_PATH'], '', ' -I')
22 a = '$MAKEINFO $__verbose $MAKEINFO_INCLUDES --no-split --no-headers \
23 --output=$TARGET $SOURCE'
24 TXT = Builder (action = a, suffix = '.txt', src_suffix = '.texi')
25 env.Append (BUILDERS = {'TXT': TXT})
26
27 a = '$MAKEINFO $__verbose $MAKEINFO_INCLUDES --output=$TARGET $SOURCE'
28 INFO = Builder (action = a, suffix = '.info', src_suffix = '.texi')
29 env.Append (BUILDERS = {'INFO': INFO})
30
31 a = '$MAKEINFO $__verbose $MAKEINFO_INCLUDES  --html --no-split --no-headers \
32 --css-include=$srcdir/Documentation/texinfo.css --output=$TARGET $SOURCE'
33 HTML = Builder (action = a, suffix = '.html', src_suffix = '.texi')
34 env.Append (BUILDERS = {'HTML': HTML})
35
36
37 env['LILYPOND_BOOK_INCLUDES'] = join_path (env['LILYPOND_BOOK_PATH'], '',
38                                            ' --include=')
39
40 # UGHR, lilypond.py uses lilypond-bin from PATH
41 env.PrependENVPath ('PATH',
42                     os.path.join (env['absbuild'], env['out'], 'usr/bin'))
43
44 if os.environ.has_key ('TEXMF'):
45         env.Append (ENV = {'TEXMF' : os.environ['TEXMF']})
46 env.Append (ENV = {'TEXMF' : '{$LILYPONDPREFIX,' \
47                    + os.popen ('kpsexpand \$TEXMF').read ()[:-1] + '}' })
48
49 #if os.environ.has_key ('GS_LIB'):
50 #       env.Append (ENV = {'GS_LIB' : os.environ['GS_LIB'] })
51 #
52 #env.PrependENVPath ('GS_LIB', ['$run_prefix/share/lilyond/ps',
53 #                              '$run_prefix/share/lilypond/fonts/type1/'])
54
55 if os.environ.has_key ('LD_LIBRARY_PATH'):
56         env.Append (ENV = {'LD_LIBRARY_PATH' : os.environ['LD_LIBRARY_PATH']})
57 if os.environ.has_key ('GUILE_LOAD_PATH'):
58         env.Append (ENV = {'GUILE_LOAD_PATH' : os.environ['GUILE_LOAD_PATH']})
59
60 env.Append (PYTHONPATH = [os.path.join (env['absbuild'], env['out'],
61                                         'usr/lib/python'),
62                           os.path.join (srcdir, 'buildscripts'),
63                           os.path.join (srcdir, 'python')])
64 env.Append (ENV = { 'PYTHONPATH' : string.join (env['PYTHONPATH'],
65                                                 os.pathsep) } )
66
67 a = ['${__set_x}rm -f $$(grep -LF "\lilypondend" ${TARGET.dir}/lily-*.tex 2>/dev/null);',
68      'LILYPONDPREFIX=$LILYPONDPREFIX \
69      $PYTHON $LILYPOND_BOOK $__verbose \
70      --include=${TARGET.dir} $LILYPOND_BOOK_INCLUDES \
71      --process="$LILYPOND_BIN $LILYPOND_BOOK_INCLUDES" \
72      --output=${TARGET.dir} --format=$LILYPOND_BOOK_FORMAT \
73      $LILYPOND_BOOK_FLAGS \
74      $SOURCE']
75 TEXI = Builder (action = a, suffix = '.texi', src_suffix = '.tely')
76 env.Append (BUILDERS = {'TEXI': TEXI})
77
78 a = 'cd ${TARGET.dir} \
79 && texi2dvi --batch $TEXINFO_PAPERSIZE_OPTION ${SOURCE.file}'
80 texi2dvi = Builder (action = a, suffix = '.dvi', src_suffix = '.texi')
81 env.Append (BUILDERS = {'Texi2dvi': texi2dvi})
82
83 env.Append (DVIPSFLAGS = '-Ppdf -u+lilypond.map -u+ec-mftrace.map')
84
85 env ['DVIPS_PAPERSIZE'] = 'a4'
86 a = ['dvips $DVIPSFLAGS -o ${TARGET}.pdfps -t $DVIPS_PAPERSIZE $SOURCE',
87      'ps2pdf -sPAPERSIZE=$DVIPS_PAPERSIZE ${TARGET}.pdfps $TARGET']
88 dvi2pdf = Builder (action = a, suffix = '.pdf', src_suffix = '.dvi')
89 env.Append (BUILDERS = {'Dvi2pdf': dvi2pdf})
90
91 a = 'convert $SOURCE $TARGET'
92 png2eps = Builder (action = a, suffix = '.eps', src_suffix = '.png')
93 env.Append (BUILDERS = {'Png2eps': png2eps})
94
95 def add_ps_target (target, source, env):
96         base = os.path.splitext (str (target[0]))[0]
97         return (target + [base + '.ps'], source)
98
99 a = '${set__x}LILYPONDPREFIX=$LILYPONDPREFIX \
100 $PYTHON $LILYPOND_PY${__verbose} \
101 --include=${TARGET.dir} \
102 --output=${TARGET.base} $SOURCE'
103 lilypond = Builder (action = a, suffix = '.pdf', src_suffix = '.ly')
104 ##                  emitter = add_ps_target)
105 env.Append (BUILDERS = {'LilyPond': lilypond})
106
107 a = '${set__x}LILYPONDPREFIX=$LILYPONDPREFIX $PYTHON $ABC2LY_PY \
108 --strict --output=${TARGET} $SOURCE'
109 ABC = Builder (action = a, suffix = '.ly', src_suffix = '.abc')
110 env.Append (BUILDERS = {'ABC': ABC})
111
112 def add_log_target (target, source, env):
113         base = os.path.splitext (str (target[0]))[0]
114         return (target + [base + '.log'], source)
115
116 def add_enc_ly_tex_target (target, source, env):
117         base = os.path.splitext (str (target[0]))[0]
118         return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
119                 source)
120
121 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
122         base = os.path.splitext (str (target[0]))[0]
123         return (target + map (lambda x: base + x, target_suffixes),
124                 source + map (lambda x: base + x, src_suffixes))
125
126 a = 'cd ${TARGET.dir} && \
127 MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir} \
128 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
129 | grep -v "@\|>>"'
130 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
131 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
132                emitter = add_log_target)
133 env.Append (BUILDERS = {'TFM': tfm})
134
135 a = '$PYTHON $MF_TO_TABLE_PY \
136 --outdir=${TARGET.dir} \
137 --afm=${TARGET.base}.afm \
138 --enc=${TARGET.base}.enc \
139 --tex=${TARGET.base}.tex \
140 --ly=${TARGET.base}list.ly \
141 ${TARGET.base}.log'
142 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
143                emitter = add_enc_ly_tex_target)
144 env.Append (BUILDERS = {'AFM': afm})
145
146 def add_enc_src (target, source, env):
147         base = os.path.splitext (str (target[0]))[0]
148         return (target, source + [base + '.enc'])
149
150 # UGH, should fix --output option for mftrace
151 # mftrace --verbose is too verbose
152 a = 'cd ${TARGET.dir} && \
153 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
154 MFINPUTS=$srcdir/mf:.: \
155 mftrace --pfa --simplify --keep-trying $$encoding $TOO__verbose \
156 --include=${TARGET.dir} \
157 ${SOURCE.file}'
158
159 pfa = Builder (action = a,
160                suffix = '.pfa',
161                src_suffix = '.mf',
162                emitter = add_enc_src)
163 env.Append (BUILDERS = {'PFA': pfa})
164
165 env['DIFF_PY'] = os.path.join (srcdir, 'stepmake/bin/package-diff.py')
166 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
167 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
168 env.Append (BUILDERS = {'PATCH': patch})
169
170 def src_glob (env, s):
171         here = os.getcwd ()
172         os.chdir (env.Dir ('.').srcnode ().abspath)
173         result = glob.glob (s)
174         os.chdir (here)
175         return result
176 env['src_glob'] = src_glob
177
178 def base_glob (env, s):
179         return map (lambda x: os.path.splitext (x)[0], src_glob (env, s))
180 env['glob'] = base_glob
181
182 atvars = [
183 'BASH',
184 'DATE',
185 'sharedstatedir',
186 'GUILE',
187 'bindir',
188 'date',
189 'datadir',
190 'lilypond_datadir',
191 'lilypond_libdir',
192 'local_lilypond_datadir',
193 'local_lilypond_libdir',
194 'localedir',
195 'PACKAGE',
196 'package',
197 'PATHSEP',
198 'PERL',
199 'prefix',
200 'program_prefix',
201 'program_suffix',
202 'PYTHON',
203 'SHELL',
204 'TOPLEVEL_VERSION',
205 'step-bindir',
206 ]
207
208 # naming
209 def at_copy (target, source, env):
210     s = open (str (source[0])).read ()
211     for i in atvars:
212             if env.has_key (i):
213                     s = string.replace (s, '@%s@'% i, env[i])
214     t = str (target[0])
215     open (t, 'w').write (s)
216     # wugh
217     if os.path.basename (os.path.dirname (str (target[0]))) == 'bin':
218             os.chmod (t, 0755)
219
220 AT_COPY = Builder (action = at_copy, src_suffix = ['.in', '.py', '.sh',])
221 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
222
223 MO = Builder (action = 'msgfmt -o $TARGET $SOURCE',
224               suffix = '.mo', src_suffix = '.po')
225 env.Append (BUILDERS = {'MO': MO})
226
227 ugh =  'ln -f po/lilypond.pot ${TARGET.dir}/lilypond.po; '
228 a = ugh + 'xgettext --default-domain=lilypond --join \
229 --output-dir=${TARGET.dir} --add-comments \
230 --keyword=_ --keyword=_f --keyword=_i $SOURCES'
231 PO = Builder (action = a, suffix = '.pot',
232               src_suffix = ['.cc', '.hh', '.py'], multi = 1)
233 ##env.Append (BUILDERS = {'PO': PO})
234 ##env.Command(env['absbuild'] + '/po/' + env['out'] + '/lilypond.pot',
235 env['potarget'] = os.path.join (env['absbuild'], 'po', env['out'],
236                                 'lilypond.pot')
237 env['pocommand'] = a
238
239 ugh = '; mv ${TARGET} ${SOURCE}'
240 a = 'msgmerge ${SOURCE} ${SOURCE.dir}/lilypond.pot -o ${TARGET}' + ugh
241 POMERGE = Builder (action = a, suffix = '.pom', src_suffix = '.po')
242 env.Append (BUILDERS = {'POMERGE': POMERGE})
243
244 a = '$PYTHON $srcdir/buildscripts/bib2html.py -o $TARGET $SOURCE'
245 BIB2HTML = Builder (action = a, suffix = '.html', src_suffix = '.bib')
246 env.Append (BUILDERS = {'BIB2HTML': BIB2HTML})
247
248 a = '$PYTHON $srcdir/buildscripts/lys-to-tely.py \
249 --name=${TARGET.base} --title="$TITLE" $SOURCES'
250 LYS2TELY = Builder (action = a, suffix = '.tely', src_suffix = '.ly')
251 env.Append (BUILDERS = {'LYS2TELY': LYS2TELY})
252
253
254 def mutopia (ly = None, abc = None):
255         if not abc:
256                 abc = env['glob'] (env, '*.abc')
257         if not ly:
258                 ly = env['glob'] (env, '*.ly') + map (env.ABC, abc)
259         pdf = map (env.LilyPond, ly)
260         # We need lily and mf to build these.
261         env.Depends (pdf, ['#/lily', '#/mf'])
262         env.Alias ('doc', pdf)
263
264 env['mutopia'] = mutopia
265
266
267 def collate (title = 'collated files'):
268         ly = env['glob'] (env, '*.ly')
269         e = env.Copy (
270                 TITLE = title,
271                 LILYPOND_BOOK_FLAGS = '''--process="lilypond-bin --header=texidoc -I$srcdir/input/test -e '(ly:set-option (quote internal-type-checking) #t)'"''',
272                                                                                                             __verbose = ' --verbose',
273                                                                                                             )
274         #               
275         tely = e.LYS2TELY ('collated-files', ly)
276         texi = e.TEXI (tely)
277         # We need lily and mf to build these.
278         env.Depends (texi, ['#/lily', '#/mf'])
279         dvi = e.Texi2dvi (texi)
280         pdf = e.Dvi2pdf (dvi)
281         html = e.HTML (texi)
282
283         env.Alias ('doc', pdf)
284         env.Alias ('doc', html)
285
286 env['collate'] = collate