2 from os.path import join, basename
3 from SCons.Script.SConscript import SConsEnvironment
5 EnsureSConsVersion(1, 0)
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
12 if sys.platform == "win32":
13 python = 'python' # usually no versioned binaries on Windows
18 print 'You need to have numpy installed.'
22 SConsignFile() # no .scsonsign into $PREFIX please
24 if sys.platform == "darwin":
25 default_prefix = '/opt/local/'
27 default_prefix = '/usr/local/'
30 opts.Add(PathVariable('prefix', 'autotools-style installation prefix', default_prefix, validator=PathVariable.PathIsDirCreate))
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)
39 env.ParseConfig('pkg-config --cflags --libs glib-2.0')
40 env.ParseConfig('pkg-config --cflags --libs libpng')
42 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
44 # Get the numpy include path (for numpy/arrayobject.h).
45 numpy_path = numpy.get_include()
46 env.Append(CPPPATH=numpy_path)
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')
58 # some distros use python2.5-config, others python-config2.5
60 env.ParseConfig(python + '-config --cflags')
61 env.ParseConfig(python + '-config --ldflags')
63 print 'going to try python-config instead'
64 env.ParseConfig('python-config --ldflags')
65 env.ParseConfig('python-config --cflags')
67 if env.get('CPPDEFINES'):
68 # make sure assertions are enabled
69 env['CPPDEFINES'].remove('NDEBUG')
72 env.Append(CPPDEFINES='HEAVY_DEBUG')
73 env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
75 #env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
77 Export('env', 'python')
78 module = SConscript('lib/SConscript')
79 SConscript('brushlib/SConscript')
80 languages = SConscript('po/SConscript')
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'
86 s += '# DO NOT EDIT - edit %s instead\n' % source[0]
88 s += open(str(source[0])).read()
89 f = open(str(target[0]), 'w')
95 old_umask = os.umask(new_umask)
96 print "set umask to 0%03o (was 0%03o)" % (new_umask, old_umask)
98 # Systems like Win32...
101 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
103 env.Clean('.', Glob('*.pyc'))
104 env.Clean('.', Glob('gui/*.pyc'))
105 env.Clean('.', Glob('lib/*.pyc'))
108 set_dir_postaction = {}
109 def install_perms(target, sources, perms=0644, dirperms=0755):
110 """As a normal env.Install, but with Chmod postactions.
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`.
117 assert target.startswith('$prefix')
118 install_targs = env.Install(target, sources)
120 final_prefix = os.path.normpath(env["prefix"])
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):
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)
136 while d != d_prev and d != '$prefix':
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)
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)
158 install_tree('$prefix/share/mypaint', 'brushes')
159 install_tree('$prefix/share/mypaint', 'backgrounds')
160 install_tree('$prefix/share/mypaint', 'pixmaps')
162 # Desktop resources and themeable internal icons
163 install_tree('$prefix/share', 'desktop/icons')
164 install_perms('$prefix/share/applications', 'desktop/mypaint.desktop')
166 # location for achitecture-dependent modules
167 install_perms('$prefix/lib/mypaint', module)
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"))
177 for lang in languages:
178 install_perms('$prefix/share/locale/%s/LC_MESSAGES' % lang,
179 'po/%s/LC_MESSAGES/mypaint.mo' % lang)
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')
185 # Convenience alias for installing to $prefix
186 env.Alias('install', '$prefix')