]> git.donarmstrong.com Git - lilypond.git/blob - SConstruct
New file.
[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 -DSTRING_UTILS_INLINED')
82 if env['warnings']:
83         env.Append (CFLAGS = '-W -Wall')
84         env.Append (CXXFLAGS = '-W -Wall -Wconversion')
85
86 env['MFMODE'] = 'ljfour'
87
88 conf = Configure (env)
89
90 #ugh -- hardcode territory
91 defines = {
92    '0DIRSEP' : "'/'",
93    '1PATHSEP' : "':'",
94
95    '2PACKAGE': '"lilypond"',
96    '3TOPLEVEL_VERSION' : '"2.3.6"',
97    '4DATADIR' : '"' + os.getcwd () + '/share"',
98    '5PACKAGE_DATADIR': 'DATADIR "/" PACKAGE',
99    '6LILYPOND_DATADIR' : 'PACKAGE_DATADIR',
100    '7LOCAL_PACKAGE_DATADIR' : 'PACKAGE_DATADIR "/" TOPLEVEL_VERSION',
101    '8LOCAL_LILYPOND_DATADIR' : 'LOCAL_PACKAGE_DATADIR',
102    '9LOCALEDIR' : '"' + os.getcwd () + '/share/locale"',
103 }
104
105 headers = ('sys/stat.h', 'assert.h', 'kpathsea/kpathsea.h')
106 for i in headers:
107         if conf.CheckCHeader (i):
108                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
109                 defines[key] = '1'
110
111 ccheaders = ('sstream',)
112 for i in ccheaders:
113         if conf.CheckCXXHeader (i):
114                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
115                 defines[key] = '1'
116
117 functions = ('gettext', 'isinf', 'memmem', 'snprintf', 'vsnprintf')
118 for i in functions:
119         if 0 or conf.CheckFunc (i):
120                 key = re.sub ('[./]', '_', 'zHAVE_' + string.upper (i))
121                 defines[key] = '1'
122
123 if conf.CheckLib ('dl'):
124         pass
125
126 if conf.CheckLib ('kpathsea'):
127         defines['KPATHSEA'] = '1'
128
129 env = conf.Finish ()
130
131 Export ('env')
132
133 #this could happen after flower...
134 env.ParseConfig ('guile-config compile')
135
136 build = env['build']
137 out = env['out']
138 ##reldir = str (Dir ('.').srcnode ())
139 reldir = os.getcwd ()
140 outdir = os.path.join (env['build'], reldir, env['out'])
141 if not os.path.exists (outdir):
142         os.mkdir (outdir)
143
144 config = open (os.path.join (outdir, 'config.h'), 'w')
145 sort_helper = defines.keys ()
146 sort_helper.sort ()
147 for i in sort_helper:
148         config.write ('#define %s %s\n' % (i[1:], defines[i]))
149 config.close ()
150
151 os.system (sys.executable \
152            + ' ./stepmake/bin/make-version.py VERSION > '\
153            + os.path.join (build, 'version.hh'))
154
155 if os.path.exists ('parser'):
156         env.Append (LIBPATH = ['#/flower', '#/lily', '#/parser', '#/gui',],
157                     CPPPATH = [outdir, '#',])
158 else:   
159         env.Append (LIBPATH = ['#/flower/' + out,],
160                     CPPPATH = [outdir, '#',])
161
162 subdirs = ('flower', 'lily', 'mf')
163 #subdirs = ('mf',)
164 #subdirs = ('flower', 'lily', 'parser', 'gui', 'main',)
165 for d in subdirs:
166         b = os.path.join (build, d, out)
167         # Support clean sourctree build (srcdir build)
168         # and outdir build.
169         # TODO: figure out SConscript (dir, builddir, duplicate)) feature
170         if (build and build != '.') \
171            or (out and out != '.'):
172                 env.BuildDir (b, d, duplicate=0)
173         SConscript (os.path.join (b, 'SConscript'))
174