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 ldflags = env.backtick(python + '-config --ldflags').split()
57 # scons does not seem to parse '-u' correctly
58 # put all options after -u in LINKFLAGS
60 idx = ldflags.index('-u')
61 env.Append(LINKFLAGS=ldflags[idx:])
63 env.MergeFlags(' '.join(ldflags))
65 # some distros use python2.5-config, others python-config2.5
67 env.ParseConfig(python + '-config --cflags')
68 env.ParseConfig(python + '-config --ldflags')
70 print 'going to try python-config instead'
71 env.ParseConfig('python-config --ldflags')
72 env.ParseConfig('python-config --cflags')
74 if env.get('CPPDEFINES'):
75 # make sure assertions are enabled
76 env['CPPDEFINES'].remove('NDEBUG')
79 env.Append(CPPDEFINES='HEAVY_DEBUG')
80 env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
82 #env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
84 Export('env', 'python')
85 module = SConscript('lib/SConscript')
86 SConscript('brushlib/SConscript')
87 languages = SConscript('po/SConscript')
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'
93 s += '# DO NOT EDIT - edit %s instead\n' % source[0]
95 s += open(str(source[0])).read()
96 f = open(str(target[0]), 'w')
102 old_umask = os.umask(new_umask)
103 print "set umask to 0%03o (was 0%03o)" % (new_umask, old_umask)
105 # Systems like Win32...
108 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
110 env.Clean('.', Glob('*.pyc'))
111 env.Clean('.', Glob('gui/*.pyc'))
112 env.Clean('.', Glob('lib/*.pyc'))
115 set_dir_postaction = {}
116 def install_perms(target, sources, perms=0644, dirperms=0755):
117 """As a normal env.Install, but with Chmod postactions.
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`.
124 assert target.startswith('$prefix')
125 install_targs = env.Install(target, sources)
127 final_prefix = os.path.normpath(env["prefix"])
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):
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)
143 while d != d_prev and d != '$prefix':
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)
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)
165 install_tree('$prefix/share/mypaint', 'brushes')
166 install_tree('$prefix/share/mypaint', 'backgrounds')
167 install_tree('$prefix/share/mypaint', 'pixmaps')
169 # Desktop resources and themeable internal icons
170 install_tree('$prefix/share', 'desktop/icons')
171 install_perms('$prefix/share/applications', 'desktop/mypaint.desktop')
173 # location for achitecture-dependent modules
174 install_perms('$prefix/lib/mypaint', module)
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"))
184 for lang in languages:
185 install_perms('$prefix/share/locale/%s/LC_MESSAGES' % lang,
186 'po/%s/LC_MESSAGES/mypaint.mo' % lang)
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')
192 # Convenience alias for installing to $prefix
193 env.Alias('install', '$prefix')