OSDN Git Service

version bump
[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     env.ParseConfig('python-config --ldflags')
57 else:
58     # some distros use python2.5-config, others python-config2.5
59     try:
60         env.ParseConfig(python + '-config --cflags')
61         env.ParseConfig(python + '-config --ldflags')
62     except OSError:
63         print 'going to try python-config instead'
64         env.ParseConfig('python-config --ldflags')
65         env.ParseConfig('python-config --cflags')
66
67 if env.get('CPPDEFINES'):
68     # make sure assertions are enabled
69     env['CPPDEFINES'].remove('NDEBUG')
70
71 if env['debug']:
72     env.Append(CPPDEFINES='HEAVY_DEBUG')
73     env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
74
75 #env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
76
77 Export('env', 'python')
78 module = SConscript('lib/SConscript')
79 SConscript('brushlib/SConscript')
80 languages = SConscript('po/SConscript')
81
82 def burn_python_version(target, source, env):
83     # make sure we run the python version that we built the extension modules for
84     s =  '#!/usr/bin/env ' + python + '\n'
85     s += 5*'#\n'
86     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
87     s += 5*'#\n'
88     s += open(str(source[0])).read()
89     f = open(str(target[0]), 'w')
90     f.write(s)
91     f.close()
92
93 try:
94     new_umask = 022
95     old_umask = os.umask(new_umask)
96     print "set umask to 0%03o (was 0%03o)" % (new_umask, old_umask)
97 except OSError:
98     # Systems like Win32...
99     pass
100
101 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
102
103 env.Clean('.', Glob('*.pyc'))
104 env.Clean('.', Glob('gui/*.pyc'))
105 env.Clean('.', Glob('lib/*.pyc'))
106
107
108 set_dir_postaction = {}
109 def install_perms(target, sources, perms=0644, dirperms=0755):
110     """As a normal env.Install, but with Chmod postactions.
111
112     The `target` parameter must be a string which starts with ``$prefix``.
113     Unless this is a sandbox install, the permission bits `dirperms` will be
114     set on every directory back to ``$prefix``, but not including it. `perms`
115     will always be set on each installed file from `sources`.
116     """
117     assert target.startswith('$prefix')
118     install_targs = env.Install(target, sources)
119     sandboxed = False
120     final_prefix = os.path.normpath(env["prefix"])
121
122     # Set file permissions.
123     for targ in install_targs:
124         env.AddPostAction(targ, Chmod(targ, perms))
125         targ_path = os.path.normpath(targ.get_path())
126         if not targ_path.startswith(final_prefix):
127             sandboxed = True
128
129     if not sandboxed:
130         # Set permissions on superdirs, back to $prefix (but not including it)
131         # Not sure if this is necessary with the umask forcing. It might help
132         # fix some broken installs.
133         for file_targ in install_targs:
134             d = os.path.normpath(target)
135             d_prev = None
136             while d != d_prev and d != '$prefix':
137                 d_prev = d
138                 if not set_dir_postaction.has_key(d):
139                     env.AddPostAction(file_targ, Chmod(d, dirperms))
140                     set_dir_postaction[d] = True
141                 d = os.path.dirname(d)
142
143     return install_targs
144
145
146 def install_tree(dest, path, perms=0644, dirperms=0755):
147     assert os.path.isdir(path)
148     target_root = join(dest, os.path.basename(path))
149     for dirpath, dirnames, filenames in os.walk(path):
150         reltarg = os.path.relpath(dirpath, path)
151         target_dir = join(target_root, reltarg)
152         target_dir = os.path.normpath(target_dir)
153         filepaths = [join(dirpath, basename) for basename in filenames]
154         install_perms(target_dir, filepaths, perms=perms, dirperms=dirperms)
155
156
157 # Painting resources
158 install_tree('$prefix/share/mypaint', 'brushes')
159 install_tree('$prefix/share/mypaint', 'backgrounds')
160 install_tree('$prefix/share/mypaint', 'pixmaps')
161
162 # Desktop resources and themeable internal icons
163 install_tree('$prefix/share', 'desktop/icons')
164 install_perms('$prefix/share/applications', 'desktop/mypaint.desktop')
165
166 # location for achitecture-dependent modules
167 install_perms('$prefix/lib/mypaint', module)
168
169 # Program and supporting UI XML
170 install_perms('$prefix/bin', 'mypaint', perms=0755)
171 install_perms('$prefix/share/mypaint/gui', Glob('gui/*.xml'))
172 install_perms("$prefix/share/mypaint/lib",      Glob("lib/*.py"))
173 install_perms("$prefix/share/mypaint/brushlib", Glob("brushlib/*.py"))
174 install_perms("$prefix/share/mypaint/gui",      Glob("gui/*.py"))
175
176 # translations
177 for lang in languages:
178     install_perms('$prefix/share/locale/%s/LC_MESSAGES' % lang,
179                  'po/%s/LC_MESSAGES/mypaint.mo' % lang)
180
181 # These hierarchies belong entirely to us, so unmake if asked.
182 env.Clean('$prefix', '$prefix/lib/mypaint')
183 env.Clean('$prefix', '$prefix/share/mypaint')
184
185 # Convenience alias for installing to $prefix
186 env.Alias('install', '$prefix')
187