]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
*** empty log message ***
[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 texi2txt = Builder (action = a, suffix = '.txt', src_suffix = '.texi')
23 env.Append (BUILDERS = {'Texi2txt': texi2txt})
24
25 env['LILYPOND_BOOK_INCLUDES'] = join_path (env['LILYPOND_BOOK_PATH'], '',
26                                            ' --include=')
27
28 # UGHR, lilypond.py uses lilypond-bin from PATH
29 #env.Append (ENV = {'PATH' : os.environ['PATH']})
30 env.PrependENVPath ('PATH',
31                     os.path.join (env['absbuild'], env['out'], 'usr/bin'))
32
33 if os.environ.has_key ('TEXMF'):
34         env.Append (ENV = {'TEXMF' : os.environ['TEXMF']})
35 env.Append (ENV = {'TEXMF' : '{' + env['LILYPONDPREFIX'] + ',' \
36                    + os.popen ('kpsexpand \$TEXMF').read ()[:-1] + '}' })
37
38 if os.environ.has_key ('LD_LIBRARY_PATH'):
39         env.Append (ENV = {'LD_LIBRARY_PATH' : os.environ['LD_LIBRARY_PATH']})
40 if os.environ.has_key ('GUILE_LOAD_PATH'):
41         env.Append (ENV = {'GUILE_LOAD_PATH' : os.environ['GUILE_LOAD_PATH']})
42
43 env.Append (PYTHONPATH = [os.path.join (env['absbuild'], env['out'],
44                                         'usr/lib/python'),
45                           os.path.join (srcdir, 'buildscripts'),
46                           os.path.join (srcdir, 'python')])
47 env.Append (ENV = { 'PYTHONPATH' : string.join (env['PYTHONPATH'],
48                                                 os.pathsep) } )
49
50 a = ['rm -f $$(grep -LF "\lilypondend" ${TARGET.dir}/lily-*.tex 2>/dev/null);',
51      'LILYPONDPREFIX=$LILYPONDPREFIX \
52      $PYTHON $LILYPOND_BOOK $__verbose \
53      --include=${TARGET.dir} $LILYPOND_BOOK_INCLUDES \
54      --process="$LILYPOND_BIN $LILYPOND_BOOK_INCLUDES" \
55      --output=${TARGET.dir} --format=$LILYPOND_BOOK_FORMAT \
56      $LILYPOND_BOOK_FLAGS \
57      $SOURCE']
58 tely2texi = Builder (action = a, suffix = '.texi', src_suffix = '.tely')
59 env.Append (BUILDERS = {'Tely2texi': tely2texi})
60
61 a = 'cd ${TARGET.dir} \
62 && texi2dvi --batch $TEXINFO_PAPERSIZE_OPTION ${SOURCE.file}'
63 texi2dvi = Builder (action = a, suffix = '.dvi', src_suffix = '.texi')
64 env.Append (BUILDERS = {'Texi2dvi': texi2dvi})
65
66 env.Append (DVIPSFLAGS = '-Ppdf -u+lilypond.map -u+ec-mftrace.map')
67
68 env ['DVIPS_PAPERSIZE'] = 'a4'
69 a = ['dvips $DVIPSFLAGS -o ${TARGET}.pdfps -t $DVIPS_PAPERSIZE $SOURCE',
70      'ps2pdf -sPAPERSIZE=$DVIPS_PAPERSIZE ${TARGET}.pdfps $TARGET']
71 dvi2pdf = Builder (action = a, suffix = '.pdf', src_suffix = '.dvi')
72 env.Append (BUILDERS = {'Dvi2pdf': dvi2pdf})
73
74 a = 'convert $SOURCE $TARGET'
75 png2eps = Builder (action = a, suffix = '.eps', src_suffix = '.png')
76 env.Append (BUILDERS = {'Png2eps': png2eps})
77
78 def add_ps_target (target, source, env):
79         base = os.path.splitext (str (target[0]))[0]
80         return (target + [base + '.ps'], source)
81
82 a = ' LILYPONDPREFIX=$LILYPONDPREFIX \
83 $PYTHON $LILYPOND_PY $__verbose \
84 --include=${TARGET.dir} \
85 --output=${TARGET.base}  $SOURCE'
86 lilypond = Builder (action = a, suffix = '.pdf', src_suffix = '.ly')
87 ##                  emitter = add_ps_target)
88 env.Append (BUILDERS = {'LilyPond': lilypond})
89
90 #verbose = verbose_opt (env, ' --verbose')
91 verbose = ''
92 a = 'LILYPONDPREFIX=$LILYPONDPREFIX $PYTHON $ABC2LY_PY \
93 --strict --output=${TARGET.base} $SOURCE'
94 abc2ly = Builder (action = a, suffix = '.ly', src_suffix = '.abc')
95 env.Append (BUILDERS = {'Abc2ly': abc2ly})
96
97 def add_log_target (target, source, env):
98         base = os.path.splitext (str (target[0]))[0]
99         return (target + [base + '.log'], source)
100
101 def add_enc_ly_tex_target (target, source, env):
102         base = os.path.splitext (str (target[0]))[0]
103         return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
104                 source)
105
106 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
107         base = os.path.splitext (str (target[0]))[0]
108         return (target + map (lambda x: base + x, target_suffixes),
109                 source + map (lambda x: base + x, src_suffixes))
110
111 a = 'cd ${TARGET.dir} && \
112 MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir} \
113 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
114 | grep -v "@\|>>"'
115 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
116 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
117                emitter = add_log_target)
118 env.Append (BUILDERS = {'TFM': tfm})
119
120 a = '$PYTHON $MF_TO_TABLE_PY \
121 --outdir=${TARGET.dir} \
122 --afm=${TARGET.base}.afm \
123 --enc=${TARGET.base}.enc \
124 --tex=${TARGET.base}.tex \
125 --ly=${TARGET.base}list.ly \
126 ${TARGET.base}.log'
127 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
128                emitter = add_enc_ly_tex_target)
129 env.Append (BUILDERS = {'AFM': afm})
130
131 def add_enc_src (target, source, env):
132         base = os.path.splitext (str (target[0]))[0]
133         return (target, source + [base + '.enc'])
134
135 # UGH, should fix --output option for mftrace
136 a = 'cd ${TARGET.dir} && \
137 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
138 MFINPUTS=$srcdir/mf:.: \
139 mftrace --pfa --simplify --keep-trying $$encoding $__verbose \
140 --include=${TARGET.dir} \
141 ${SOURCE.file}'
142
143 pfa = Builder (action = a,
144                suffix = '.pfa',
145                src_suffix = '.mf',
146                emitter = add_enc_src)
147 env.Append (BUILDERS = {'PFA': pfa})
148
149 env['DIFF_PY'] = os.path.join (srcdir, 'stepmake/bin/package-diff.py')
150 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
151 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
152 env.Append (BUILDERS = {'PATCH': patch})
153
154 def src_glob (env, s):
155         here = os.getcwd ()
156         os.chdir (env.Dir ('.').srcnode ().abspath)
157         result = glob.glob (s)
158         os.chdir (here)
159         return result
160 env['src_glob'] = src_glob
161
162 atvars = [
163 'BASH',
164 'DATE',
165 'sharedstatedir',
166 'GUILE',
167 'bindir',
168 'date',
169 'datadir',
170 'lilypond_datadir',
171 'lilypond_libdir',
172 'local_lilypond_datadir',
173 'local_lilypond_libdir',
174 'localedir',
175 'PACKAGE',
176 'package',
177 'PATHSEP',
178 'PERL',
179 'prefix',
180 'program_prefix',
181 'program_suffix',
182 'PYTHON',
183 'SHELL',
184 'TOPLEVEL_VERSION',
185 'step-bindir',
186 ]
187
188 #compat
189 env['lilypond_datadir'] = env['sharedir_package']
190 env['local_lilypond_datadir'] = env['sharedir_package_version']
191 env['TOPLEVEL_VERSION'] = env['version']
192 env['SHELL'] = '/bin/sh'
193 env['BASH'] = '/bin/bash'
194
195 def at (target, source, env):
196     s = open (str (source[0])).read ()
197     for i in atvars:
198             if env.has_key (i):
199                     s = string.replace (s, '@%s@'% i, env[i])
200     t = str (target[0])
201     open (t, 'w').write (s)
202     # ugh
203     os.chmod (t, 0755)
204
205 at = Builder (action = at)
206 env.Append (BUILDERS = {'AT': at})
207