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