OSDN Git Service

enable assertions with "scons debug=true"
[mypaint-anime/master.git] / SConstruct
1 import os, sys
2 from os.path import join, basename
3
4 EnsureSConsVersion(1, 0)
5
6 python = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
7 print 'Building for', python
8
9 try: 
10     Glob
11 except:
12     # compatibility with SCons version 0.97
13     from glob import glob as Glob
14
15 from glob import glob
16
17 try: 
18     import numpy
19 except ImportError:
20     print 'You need to have numpy installed.'
21     print
22     raise
23
24 SConsignFile() # no .scsonsign into $PREFIX please
25
26 # Does option parsing really screw up the win32 build? if no, remove comment
27 #if sys.platform == "win32":
28 #    env = Environment(ENV=os.environ)
29 #else:
30
31 opts = Variables()
32 opts.Add(PathVariable('prefix', 'autotools-style installation prefix', '/usr/local', validator=PathVariable.PathIsDirCreate))
33 opts.Add(BoolVariable('debug', 'enable HEAVY_DEBUG and disable optimizations', False))
34 env = Environment(ENV=os.environ, options=opts)
35 opts.Update(env)
36
37 env.ParseConfig('pkg-config --cflags --libs glib-2.0')
38
39 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
40
41 # Get the numpy include path (for numpy/arrayobject.h).
42 numpy_path = numpy.get_include()
43 env.Append(CPPPATH=numpy_path)
44
45
46 if sys.platform == "win32":
47     env.ParseConfig('pkg-config --cflags --libs python25') # These two '.pc' files you probably have to make for yourself.
48     env.ParseConfig('pkg-config --cflags --libs numpy')    # Place them among the other '.pc' files ( where the 'glib-2.0.pc' is located .. probably )
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 --cflags --ldflags')
56
57 if env.get('CPPDEFINES'):
58     # make sure assertions are enabled
59     env['CPPDEFINES'].remove('NDEBUG')
60
61 if env['debug']:
62     env.Append(CPPDEFINES='HEAVY_DEBUG')
63     env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
64
65 Export('env')
66 module = SConscript('lib/SConscript')
67 SConscript('brushlib/SConscript')
68 languages = SConscript('po/SConscript')
69
70 # Build mypaint.exe for running on windows
71 if sys.platform == "win32":
72     env2 = Environment(ENV=os.environ)
73     env2.ParseConfig('pkg-config --cflags --libs python25')
74     env2.Program('mypaint', ['mypaint_exe.c'])
75
76 def burn_python_version(target, source, env):
77     # make sure we run the python version that we built the extension modules for
78     s =  '#!/usr/bin/env ' + python + '\n'
79     s += 5*'#\n'
80     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
81     s += 5*'#\n'
82     s += open(str(source[0])).read()
83     f = open(str(target[0]), 'w')
84     f.write(s)
85     f.close()
86
87 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
88
89 env.Alias('install', env['prefix'])
90 def install(dst, pattern):
91     env.Install(join(env['prefix'], dst), Glob(pattern))
92 install('bin', 'mypaint')
93 install('share/mypaint/brushes', 'brushes/*')
94 install('share/mypaint/backgrounds', 'backgrounds/*')
95 install('share/mypaint/pixmaps', 'pixmaps/*')
96
97 #install('share/mypaint/desktop', 'desktop/*')
98 # scons could recurse with Glob(), but it adds .svn directories when doing so
99 for dirpath, dirnames, filenames in os.walk('desktop'):
100     if '.svn' in dirnames:
101         dirnames.remove('.svn')
102     env.Install(join(env['prefix'], 'share/mypaint', dirpath), [join(dirpath, s) for s in filenames])
103
104 # mypaint.desktop goes into /usr/share/applications (debian-only or standard?)
105 install('share/applications', 'desktop/mypaint.desktop')
106
107 # location for achitecture-dependent modules
108 env.Install(join(env['prefix'], 'lib/mypaint'), module)
109 install('share/mypaint/lib', 'lib/*.py')
110 install('share/mypaint/gui', 'gui/*.py')
111 install('share/mypaint/brushlib', 'brushlib/*.py')
112
113 # translations
114 for lang in languages:
115     install('share/locale/%s/LC_MESSAGES' % lang, 'po/%s/LC_MESSAGES/mypaint.mo' % lang)