OSDN Git Service

Build: Fail when not finding files to install
[mypaint-anime/master.git] / SConstruct
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 env.ParseConfig('pkg-config --cflags --libs libpng')
36
37 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
38
39 # Get the numpy include path (for numpy/arrayobject.h).
40 numpy_path = numpy.get_include()
41 env.Append(CPPPATH=numpy_path)
42
43
44 if sys.platform == "win32":
45     env.ParseConfig('pkg-config --cflags --libs python25') # These two '.pc' files you probably have to make for yourself.
46     env.ParseConfig('pkg-config --cflags --libs numpy')    # Place them among the other '.pc' files ( where the 'glib-2.0.pc' is located .. probably )
47 elif sys.platform == "darwin":
48     env.ParseConfig('python-config --cflags')
49     env.ParseConfig('python-config --ldflags')
50 else:
51     # some distros use python2.5-config, others python-config2.5
52     try:
53         env.ParseConfig(python + '-config --cflags')
54         env.ParseConfig(python + '-config --ldflags')
55     except OSError:
56         print 'going to try python-config instead'
57         env.ParseConfig('python-config --ldflags')
58         env.ParseConfig('python-config --cflags')
59
60 if env.get('CPPDEFINES'):
61     # make sure assertions are enabled
62     env['CPPDEFINES'].remove('NDEBUG')
63
64 if env['debug']:
65     env.Append(CPPDEFINES='HEAVY_DEBUG')
66     env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
67
68 Export('env')
69 module = SConscript('lib/SConscript')
70 SConscript('brushlib/SConscript')
71 languages = SConscript('po/SConscript')
72
73 # Build mypaint.exe for running on windows
74 if sys.platform == "win32":
75     env2 = Environment(tools=['mingw'], ENV=os.environ)
76     env2.ParseConfig('pkg-config --cflags --libs python25')
77     env2.Program('mypaint', ['mypaint_exe.c'])
78
79 def burn_python_version(target, source, env):
80     # make sure we run the python version that we built the extension modules for
81     s =  '#!/usr/bin/env ' + python + '\n'
82     s += 5*'#\n'
83     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
84     s += 5*'#\n'
85     s += open(str(source[0])).read()
86     f = open(str(target[0]), 'w')
87     f.write(s)
88     f.close()
89
90 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
91
92 env.Clean('.', Glob('*.pyc'))
93 env.Clean('.', Glob('gui/*.pyc'))
94 env.Clean('.', Glob('lib/*.pyc'))
95
96 env.Alias('install', env['prefix'])
97 def install(dst, pattern):
98     files = Glob(pattern)
99     assert files, "Glob expression did not match any files"
100     env.Install(join(env['prefix'], dst), files)
101 install('bin', 'mypaint')
102 install('share/mypaint/brushes', 'brushes/*')
103 install('share/mypaint/backgrounds', 'backgrounds/*')
104 install('share/mypaint/pixmaps', 'pixmaps/*')
105
106 install('share', 'desktop/icons')
107 install('share/applications', 'desktop/mypaint.desktop')
108
109 # location for achitecture-dependent modules
110 env.Install(join(env['prefix'], 'lib/mypaint'), module)
111 install('share/mypaint/lib', 'lib/*.py')
112 install('share/mypaint/gui', 'gui/*.py')
113 install('share/mypaint/gui', 'gui/menu.xml')
114 install('share/mypaint/brushlib', 'brushlib/*.py')
115
116 # translations
117 for lang in languages:
118     install('share/locale/%s/LC_MESSAGES' % lang, 'po/%s/LC_MESSAGES/mypaint.mo' % lang)