]> git.donarmstrong.com Git - lilypond.git/blob - SConstruct
* mf/SConscript: Update multiple target rules.
[lilypond.git] / SConstruct
1 # -*-python-*-
2
3 '''
4 Experimental scons (www.scons.org) building:
5
6 Usage:
7     scons
8     scons install
9     scons -c              # clean
10     scons -h              # help
11
12     scons build=DIR       # scrdir build, write to new tree =build
13     scons out=DIR         # write output to deeper dir DIR
14
15 Optionally, make a custom.py.  I have
16
17 import os
18 out='out-scons'
19 optimising=0
20 debugging=1
21 prefix=os.getcwd ()
22
23
24 '''
25
26
27 # TODO:
28 #   * mf: pfa
29 #   *, Documentation, ly etc.
30
31
32 import re
33 import glob
34 import os
35 import sys
36 import string
37
38 env = Environment ()
39
40 # put your favourite stuff in custom.py
41 opts = Options ('custom.py', ARGUMENTS)
42 opts.Add ('prefix', 'Install prefix', '/usr/')
43 opts.Add ('out', 'Output directory', 'out-scons')
44 opts.Add ('build', 'Build directory', '.')
45 opts.AddOptions (
46         BoolOption ('warnings', 'compile with -Wall and similiar',
47                    1),
48         BoolOption ('debugging', 'compile with debugging symbols',
49                     0),
50         BoolOption ('optimising', 'compile with optimising',
51                     1),
52         BoolOption ('shared', 'build shared libraries',
53                     0),
54         BoolOption ('static', 'build static libraries',
55                     1),
56         )
57
58 Help (opts.GenerateHelpText (env))
59
60 env = Environment (options = opts)
61
62 env.CacheDir (os.path.join (env['build'], '=build-cache'))
63
64 #ugh
65 sys.path.append (os.path.join ('.', 'stepmake', 'bin'))
66 import packagepython
67 package = packagepython.Package ('.')
68
69 env['version'] = packagepython.version_tuple_to_str (package.version)
70 env['bindir'] = os.path.join (env['prefix'], 'bin')
71 env['sharedir'] = os.path.join (env['prefix'], 'share')
72 env['libdir'] = os.path.join (env['prefix'], 'lib')
73 env['lilypondprefix'] = os.path.join (env['sharedir'], 'lilypond',
74                                       env['version'])
75
76 if env['debugging']:
77         env.Append (CFLAGS = '-g')
78         env.Append (CXXFLAGS = '-g')
79 if env['optimising']:
80         env.Append (CFLAGS = '-O2')
81         env.Append (CXXFLAGS = '-O2')
82         env.Append (CXXFLAGS = '-DSTRING_UTILS_INLINED')
83 if env['warnings']:
84         env.Append (CFLAGS = '-W ')
85         env.Append (CFLAGS = '-Wall')
86         env.Append (CXXFLAGS = '-W')
87         env.Append (CXXFLAGS = '-Wall')
88         env.Append (CXXFLAGS = '-Wconversion')
89
90 env['MFMODE'] = 'ljfour'
91
92 conf = Configure (env)
93
94 #ugh -- hardcode territory
95 defines = {
96    '0DIRSEP' : "'/'",
97    '1PATHSEP' : "':'",
98
99    '2PACKAGE': '"lilypond"',
100    '3TOPLEVEL_VERSION' : '"2.3.6"',
101    '4DATADIR' : '"' + os.getcwd () + '/share"',
102    '5PACKAGE_DATADIR': 'DATADIR "/" PACKAGE',
103    '6LILYPOND_DATADIR' : 'PACKAGE_DATADIR',
104    '7LOCAL_PACKAGE_DATADIR' : 'PACKAGE_DATADIR "/" TOPLEVEL_VERSION',
105    '8LOCAL_LILYPOND_DATADIR' : 'LOCAL_PACKAGE_DATADIR',
106    '9LOCALEDIR' : '"' + os.getcwd () + '/share/locale"',
107 }
108
109 headers = ('sys/stat.h', 'assert.h', 'kpathsea/kpathsea.h')
110 for i in headers:
111         if conf.CheckCHeader (i):
112                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
113                 defines[key] = '1'
114
115 ccheaders = ('sstream',)
116 for i in ccheaders:
117         if conf.CheckCXXHeader (i):
118                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
119                 defines[key] = '1'
120
121 functions = ('gettext', 'isinf', 'memmem', 'snprintf', 'vsnprintf')
122 for i in functions:
123         if 0 or conf.CheckFunc (i):
124                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
125                 defines[key] = '1'
126
127
128 key = 'HAVE_FLEXLEXER_YY_CURRENT_BUFFER'
129 defines[key] = conf.TryCompile("""using namespace std;
130 #include <FlexLexer.h>
131 class yy_flex_lexer: public yyFlexLexer
132 {
133   public:
134     yy_flex_lexer ()
135     {
136       yy_current_buffer = 0;
137     }
138 };""", 'cc')
139
140 if conf.CheckLib ('dl'):
141         pass
142
143 if conf.CheckLib ('kpathsea'):
144         defines['KPATHSEA'] = '1'
145
146 # huh? 
147 if conf.CheckLib ('kpathsea', 'kpse_find_file'):
148         defines['HAVE_KPSE_FIND_FILE'] = '1'
149
150 env = conf.Finish ()
151
152 Export ('env')
153
154 #this could happen after flower...
155 env.ParseConfig ('guile-config compile')
156
157 build = env['build']
158 out = env['out']
159 ##reldir = str (Dir ('.').srcnode ())
160 reldir = os.getcwd ()
161 outdir = os.path.join (env['build'], reldir, env['out'])
162 if not os.path.exists (outdir):
163         os.mkdir (outdir)
164
165 config = open (os.path.join (outdir, 'config.h'), 'w')
166 sort_helper = defines.keys ()
167 sort_helper.sort ()
168 for i in sort_helper:
169         config.write ('#define %s %s\n' % (i[1:], defines[i]))
170 config.close ()
171
172 os.system (sys.executable \
173            + ' ./stepmake/bin/make-version.py VERSION > '\
174            + os.path.join (build, 'version.hh'))
175
176 if os.path.exists ('parser'):
177         env.Append (LIBPATH = ['#/flower', '#/lily', '#/parser', '#/gui',],
178                     CPPPATH = [outdir, '#',])
179 else:   
180         env.Append (LIBPATH = ['#/flower/' + out,],
181                     CPPPATH = [outdir, '#',])
182
183 def get_version (program):
184         command = '(%(program)s --version || %(program)s -V) 2>&1' % vars ()
185         output = os.popen (command).readline ()[:-1]
186         v = re.sub ('^.*[^-.0-9]([0-9][0-9]*\.[0-9][.0-9]*).*$', '\\1', output)
187         return string.split (v, '.')
188
189 def assert_version (program, minimal, description, package):
190         global required
191         sys.stdout.write ('Checking %s version... ' % program)
192         actual = get_version (program)
193         sys.stdout.write (string.join (actual, '.'))
194         sys.stdout.write ('\n')
195         if actual < string.split (minimal, '.'):
196                 required.append ((description, package,
197                                   string.join (minimal, '.'),
198                                   program,
199                                   string.join (actual, '.')))
200
201 required = []
202 assert_version ('gcc', '3.0.5', 'GNU C compiler', 'gcc')
203 assert_version ('makeinfo', '4.7, 'Makeinfo tool', 'texinfo')
204
205 if required:
206         print
207         print '********************************'
208         print 'Please install required packages'
209 for i in required:
210         print '%s:      %s-%s or newer (found: %s-%s)' % i
211
212 sys.exit (1)
213         
214
215 subdirs = ('mf',)
216 #subdirs = ('flower', 'lily', 'parser', 'gui', 'main',)
217 #subdirs = ('flower', 'lily', 'mf')
218 for d in subdirs:
219         b = os.path.join (build, d, out)
220         # Support clean sourctree build (srcdir build)
221         # and outdir build.
222         # TODO: figure out SConscript (dir, builddir, duplicate)) feature
223         if (build and build != '.') \
224            or (out and out != '.'):
225                 env.BuildDir (b, d, duplicate=0)
226         SConscript (os.path.join (b, 'SConscript'))
227