1
import os, sys
2
from os.path import join, basename
3
4
EnsureSConsVersion(1, 0)
5
6
# FIXME: sometimes it would be good to build for a different python
7
# version than the one running scons. (But how to find all paths then?)
8
python = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
9
print 'Building for', python
10
11
try: 
12
    import numpy
13
except ImportError:
14
    print 'You need to have numpy installed.'
15
    print
16
    raise
17
18
SConsignFile() # no .scsonsign into $PREFIX please
19
20
if sys.platform == "darwin":
21
    default_prefix = '/opt/local/'
22
else:
23
    default_prefix = '/usr/local/'
24
25
opts = Variables()
26
opts.Add(PathVariable('prefix', 'autotools-style installation prefix', default_prefix, validator=PathVariable.PathIsDirCreate))
27
28
opts.Add(BoolVariable('debug', 'enable HEAVY_DEBUG and disable optimizations', False))
29
env = Environment(ENV=os.environ, options=opts)
30
if sys.platform == "win32":
31
    env = Environment(tools=['mingw'], ENV=os.environ, options=opts)
32
opts.Update(env)
33
34
env.ParseConfig('pkg-config --cflags --libs glib-2.0')
35
36
env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
37
38
# Get the numpy include path (for numpy/arrayobject.h).
39
numpy_path = numpy.get_include()
40
env.Append(CPPPATH=numpy_path)
41
42
43
if sys.platform == "win32":
44
    env.ParseConfig('pkg-config --cflags --libs python25') # These two '.pc' files you probably have to make for yourself.
45
    env.ParseConfig('pkg-config --cflags --libs numpy')    # Place them among the other '.pc' files ( where the 'glib-2.0.pc' is located .. probably )
46
elif sys.platform == "darwin":
47
    env.ParseConfig('python-config --cflags')
48
    env.ParseConfig('python-config --ldflags')
49
else:
50
    # some distros use python2.5-config, others python-config2.5
51
    try:
52
        env.ParseConfig(python + '-config --cflags --ldflags')
53
    except OSError:
54
        print 'going to try python-config instead'
55
        env.ParseConfig('python-config --ldflags')
56
        env.ParseConfig('python-config --cflags')
57
58
if env.get('CPPDEFINES'):
59
    # make sure assertions are enabled
60
    env['CPPDEFINES'].remove('NDEBUG')
61
62
if env['debug']:
63
    env.Append(CPPDEFINES='HEAVY_DEBUG')
64
    env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
65
66
Export('env')
67
module = SConscript('lib/SConscript')
68
SConscript('brushlib/SConscript')
69
languages = SConscript('po/SConscript')
70
71
# Build mypaint.exe for running on windows
72
if sys.platform == "win32":
73
    env2 = Environment(tools=['mingw'], ENV=os.environ)
74
    env2.ParseConfig('pkg-config --cflags --libs python25')
75
    env2.Program('mypaint', ['mypaint_exe.c'])
76
77
def burn_python_version(target, source, env):
78
    # make sure we run the python version that we built the extension modules for
79
    s =  '#!/usr/bin/env ' + python + '\n'
80
    s += 5*'#\n'
81
    s += '# DO NOT EDIT - edit %s instead\n' % source[0]
82
    s += 5*'#\n'
83
    s += open(str(source[0])).read()
84
    f = open(str(target[0]), 'w')
85
    f.write(s)
86
    f.close()
87
88
env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
89
90
env.Clean('.', Glob('*.pyc'))
91
env.Clean('.', Glob('gui/*.pyc'))
92
env.Clean('.', Glob('lib/*.pyc'))
93
94
env.Alias('install', env['prefix'])
95
def install(dst, pattern):
96
    env.Install(join(env['prefix'], dst), Glob(pattern))
97
install('bin', 'mypaint')
98
install('share/mypaint/brushes', 'brushes/*')
99
install('share/mypaint/backgrounds', 'backgrounds/*')
100
install('share/mypaint/pixmaps', 'pixmaps/*')
101
102
install('share', 'desktop/icons')
103
install('share/applications', 'desktop/mypaint.desktop')
104
105
# location for achitecture-dependent modules
106
env.Install(join(env['prefix'], 'lib/mypaint'), module)
107
install('share/mypaint/lib', 'lib/*.py')
108
install('share/mypaint/gui', 'gui/*.py')
109
install('share/mypaint/gui', 'gui/menu.xml')
110
install('share/mypaint/brushlib', 'brushlib/*.py')
111
112
# translations
113
for lang in languages:
114
    install('share/locale/%s/LC_MESSAGES' % lang, 'po/%s/LC_MESSAGES/mypaint.mo' % lang)