OSDN Git Service

move layer: fix to prevent tiledict overgrowth
[mypaint-anime/master.git] / SConstruct
1 import os, sys
2 from os.path import join, basename
3 from SCons.Script.SConscript import SConsEnvironment
4
5 EnsureSConsVersion(1, 0)
6
7 # FIXME: sometimes it would be good to build for a different python
8 # version than the one running scons. (But how to find all paths then?)
9 python = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
10 print 'Building for', python
11
12 if sys.platform == "win32":
13     python = 'python' # usually no versioned binaries on Windows
14
15 try:
16     import numpy
17 except ImportError:
18     print 'You need to have numpy installed.'
19     print
20     raise
21
22 SConsignFile() # no .scsonsign into $PREFIX please
23
24 if sys.platform == "darwin":
25     default_prefix = '/opt/local/'
26 else:
27     default_prefix = '/usr/local/'
28
29 opts = Variables()
30 opts.Add(PathVariable('prefix', 'autotools-style installation prefix', default_prefix, validator=PathVariable.PathIsDirCreate))
31
32 opts.Add(BoolVariable('debug', 'enable HEAVY_DEBUG and disable optimizations', False))
33 env = Environment(ENV=os.environ, options=opts)
34 if sys.platform == "win32":
35     # remove this mingw if trying VisualStudio
36     env = Environment(tools=['mingw'], ENV=os.environ, options=opts)
37 opts.Update(env)
38
39 env.ParseConfig('pkg-config --cflags --libs glib-2.0')
40 env.ParseConfig('pkg-config --cflags --libs libpng')
41
42 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
43
44 # Get the numpy include path (for numpy/arrayobject.h).
45 numpy_path = numpy.get_include()
46 env.Append(CPPPATH=numpy_path)
47
48
49 if sys.platform == "win32":
50     # official python shipped with no pc file on windows so get from current python
51     from distutils import sysconfig
52     pre,inc = sysconfig.get_config_vars('exec_prefix', 'INCLUDEPY')
53     env.Append(CPPPATH=inc, LIBPATH=pre+'\libs', LIBS='python'+sys.version[0]+sys.version[2])
54 elif sys.platform == "darwin":
55     env.ParseConfig(python + '-config --cflags')
56     ldflags = env.backtick(python + '-config --ldflags').split()
57     # scons does not seem to parse '-u' correctly
58     # put all options after -u in LINKFLAGS
59     if '-u' in ldflags:
60         idx = ldflags.index('-u')
61         env.Append(LINKFLAGS=ldflags[idx:])
62         del ldflags[idx:]
63     env.MergeFlags(' '.join(ldflags))
64 else:
65     # some distros use python2.5-config, others python-config2.5
66     try:
67         env.ParseConfig(python + '-config --cflags')
68         env.ParseConfig(python + '-config --ldflags')
69     except OSError:
70         print 'going to try python-config instead'
71         env.ParseConfig('python-config --ldflags')
72         env.ParseConfig('python-config --cflags')
73
74 if env.get('CPPDEFINES'):
75     # make sure assertions are enabled
76     env['CPPDEFINES'].remove('NDEBUG')
77
78 if env['debug']:
79     env.Append(CPPDEFINES='HEAVY_DEBUG')
80     env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
81
82 #env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
83
84 Export('env', 'python')
85 module = SConscript('lib/SConscript')
86 SConscript('brushlib/SConscript')
87 languages = SConscript('po/SConscript')
88
89 def burn_python_version(target, source, env):
90     # make sure we run the python version that we built the extension modules for
91     s =  '#!/usr/bin/env ' + python + '\n'
92     s += 5*'#\n'
93     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
94     s += 5*'#\n'
95     s += open(str(source[0])).read()
96     f = open(str(target[0]), 'w')
97     f.write(s)
98     f.close()
99
100 try:
101     new_umask = 022
102     old_umask = os.umask(new_umask)
103     print "set umask to 0%03o (was 0%03o)" % (new_umask, old_umask)
104 except OSError:
105     # Systems like Win32...
106     pass
107
108 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
109
110 env.Clean('.', Glob('*.pyc'))
111 env.Clean('.', Glob('gui/*.pyc'))
112 env.Clean('.', Glob('lib/*.pyc'))
113
114
115 set_dir_postaction = {}
116 def install_perms(target, sources, perms=0644, dirperms=0755):
117     """As a normal env.Install, but with Chmod postactions.
118
119     The `target` parameter must be a string which starts with ``$prefix``.
120     Unless this is a sandbox install, the permission bits `dirperms` will be
121     set on every directory back to ``$prefix``, but not including it. `perms`
122     will always be set on each installed file from `sources`.
123     """
124     assert target.startswith('$prefix')
125     install_targs = env.Install(target, sources)
126     sandboxed = False
127     final_prefix = os.path.normpath(env["prefix"])
128
129     # Set file permissions.
130     for targ in install_targs:
131         env.AddPostAction(targ, Chmod(targ, perms))
132         targ_path = os.path.normpath(targ.get_path())
133         if not targ_path.startswith(final_prefix):
134             sandboxed = True
135
136     if not sandboxed:
137         # Set permissions on superdirs, back to $prefix (but not including it)
138         # Not sure if this is necessary with the umask forcing. It might help
139         # fix some broken installs.
140         for file_targ in install_targs:
141             d = os.path.normpath(target)
142             d_prev = None
143             while d != d_prev and d != '$prefix':
144                 d_prev = d
145                 if not set_dir_postaction.has_key(d):
146                     env.AddPostAction(file_targ, Chmod(d, dirperms))
147                     set_dir_postaction[d] = True
148                 d = os.path.dirname(d)
149
150     return install_targs
151
152
153 def install_tree(dest, path, perms=0644, dirperms=0755):
154     assert os.path.isdir(path)
155     target_root = join(dest, os.path.basename(path))
156     for dirpath, dirnames, filenames in os.walk(path):
157         reltarg = os.path.relpath(dirpath, path)
158         target_dir = join(target_root, reltarg)
159         target_dir = os.path.normpath(target_dir)
160         filepaths = [join(dirpath, basename) for basename in filenames]
161         install_perms(target_dir, filepaths, perms=perms, dirperms=dirperms)
162
163
164 # Painting resources
165 install_tree('$prefix/share/mypaint', 'brushes')
166 install_tree('$prefix/share/mypaint', 'backgrounds')
167 install_tree('$prefix/share/mypaint', 'pixmaps')
168
169 # Desktop resources and themeable internal icons
170 install_tree('$prefix/share', 'desktop/icons')
171 install_perms('$prefix/share/applications', 'desktop/mypaint.desktop')
172
173 # location for achitecture-dependent modules
174 install_perms('$prefix/lib/mypaint', module)
175
176 # Program and supporting UI XML
177 install_perms('$prefix/bin', 'mypaint', perms=0755)
178 install_perms('$prefix/share/mypaint/gui', Glob('gui/*.xml'))
179 install_perms("$prefix/share/mypaint/lib",      Glob("lib/*.py"))
180 install_perms("$prefix/share/mypaint/brushlib", Glob("brushlib/*.py"))
181 install_perms("$prefix/share/mypaint/gui",      Glob("gui/*.py"))
182
183 # translations
184 for lang in languages:
185     install_perms('$prefix/share/locale/%s/LC_MESSAGES' % lang,
186                  'po/%s/LC_MESSAGES/mypaint.mo' % lang)
187
188 # These hierarchies belong entirely to us, so unmake if asked.
189 env.Clean('$prefix', '$prefix/lib/mypaint')
190 env.Clean('$prefix', '$prefix/share/mypaint')
191
192 # Convenience alias for installing to $prefix
193 env.Alias('install', '$prefix')
194