]> git.donarmstrong.com Git - lilypond.git/blob - buildscripts/builder.py
* SConstruct: Configure only pristine build tree or on user
[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=#/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' : '{' + env['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 = ['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 TELY = Builder (action = a, suffix = '.texi', src_suffix = '.tely')
68 env.Append (BUILDERS = {'TELY': TELY})
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 debug = 'echo "PATH=$$PATH";'
92 a = debug + 'LILYPONDPREFIX=$LILYPONDPREFIX \
93 $PYTHON $LILYPOND_PY $__verbose \
94 --include=${TARGET.dir} \
95 --output=${TARGET.base}  $SOURCE'
96 lilypond = Builder (action = a, suffix = '.pdf', src_suffix = '.ly')
97 ##                  emitter = add_ps_target)
98 env.Append (BUILDERS = {'LilyPond': lilypond})
99
100 #verbose = verbose_opt (env, ' --verbose')
101 verbose = ''
102 a = debug + 'LILYPONDPREFIX=$LILYPONDPREFIX $PYTHON $ABC2LY_PY \
103 --strict --output=${TARGET.base} $SOURCE'
104 ABC = Builder (action = a, suffix = '.ly', src_suffix = '.abc')
105 env.Append (BUILDERS = {'ABC': ABC})
106
107 def add_log_target (target, source, env):
108         base = os.path.splitext (str (target[0]))[0]
109         return (target + [base + '.log'], source)
110
111 def add_enc_ly_tex_target (target, source, env):
112         base = os.path.splitext (str (target[0]))[0]
113         return (target + [base + '.enc', base + '.tex', base + 'list.ly'],
114                 source)
115
116 def add_suffixes (target, source, env, target_suffixes, src_suffixes):
117         base = os.path.splitext (str (target[0]))[0]
118         return (target + map (lambda x: base + x, target_suffixes),
119                 source + map (lambda x: base + x, src_suffixes))
120
121 a = 'cd ${TARGET.dir} && \
122 MFINPUTS=.:${SOURCE.dir}:$srcdir/${SOURCE.dir} \
123 mf "\\mode:=$MFMODE; nonstopmode; input ${SOURCE.filebase};" \
124 | grep -v "@\|>>"'
125 tfm = Builder (action = a, suffix = '.tfm', src_suffix = '.mf',
126 #              emitter = lambda t, s, e: add_suffixes (t, s, e, ['.log'], []))
127                emitter = add_log_target)
128 env.Append (BUILDERS = {'TFM': tfm})
129
130 a = '$PYTHON $MF_TO_TABLE_PY \
131 --outdir=${TARGET.dir} \
132 --afm=${TARGET.base}.afm \
133 --enc=${TARGET.base}.enc \
134 --tex=${TARGET.base}.tex \
135 --ly=${TARGET.base}list.ly \
136 ${TARGET.base}.log'
137 afm = Builder (action = a, suffix = '.afm', src_suffix = '.log',
138                emitter = add_enc_ly_tex_target)
139 env.Append (BUILDERS = {'AFM': afm})
140
141 def add_enc_src (target, source, env):
142         base = os.path.splitext (str (target[0]))[0]
143         return (target, source + [base + '.enc'])
144
145 # UGH, should fix --output option for mftrace
146 a = 'cd ${TARGET.dir} && \
147 if test -e ${SOURCE.filebase}.enc; then encoding="--encoding=${SOURCE.filebase}.enc"; fi; \
148 MFINPUTS=$srcdir/mf:.: \
149 mftrace --pfa --simplify --keep-trying $$encoding $__verbose \
150 --include=${TARGET.dir} \
151 ${SOURCE.file}'
152
153 pfa = Builder (action = a,
154                suffix = '.pfa',
155                src_suffix = '.mf',
156                emitter = add_enc_src)
157 env.Append (BUILDERS = {'PFA': pfa})
158
159 env['DIFF_PY'] = os.path.join (srcdir, 'stepmake/bin/package-diff.py')
160 a = '$PYTHON $DIFF_PY $__verbose --outdir=${TARGET.dir}'
161 patch = Builder (action = a, suffix = '.diff', src_suffix = '.tar.gz')
162 env.Append (BUILDERS = {'PATCH': patch})
163
164 def src_glob (env, s):
165         here = os.getcwd ()
166         os.chdir (env.Dir ('.').srcnode ().abspath)
167         result = glob.glob (s)
168         os.chdir (here)
169         return result
170 env['src_glob'] = src_glob
171
172 def base_glob (env, s):
173         return map (lambda x: os.path.splitext (x)[0], src_glob (env, s))
174 env['base_glob'] = src_glob
175
176 atvars = [
177 'BASH',
178 'DATE',
179 'sharedstatedir',
180 'GUILE',
181 'bindir',
182 'date',
183 'datadir',
184 'lilypond_datadir',
185 'lilypond_libdir',
186 'local_lilypond_datadir',
187 'local_lilypond_libdir',
188 'localedir',
189 'PACKAGE',
190 'package',
191 'PATHSEP',
192 'PERL',
193 'prefix',
194 'program_prefix',
195 'program_suffix',
196 'PYTHON',
197 'SHELL',
198 'TOPLEVEL_VERSION',
199 'step-bindir',
200 ]
201
202 # naming
203 def at_copy (target, source, env):
204     s = open (str (source[0])).read ()
205     for i in atvars:
206             if env.has_key (i):
207                     s = string.replace (s, '@%s@'% i, env[i])
208     t = str (target[0])
209     open (t, 'w').write (s)
210     # wugh
211     if os.basename (os.dirname (str (target[0]))) == 'bin':
212             os.chmod (t, 0755)
213
214 AT_COPY = Builder (action = at_copy)
215 env.Append (BUILDERS = {'AT_COPY': AT_COPY})
216