OSDN Git Service

more 'scons install' and desktop stuff; shebang the correct python version
[mypaint-anime/master.git] / SConstruct
1 import os, sys
2
3 python = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
4 print 'Building for', python
5
6 try: 
7     Glob
8 except:
9     # compatibility with SCons version 0.97
10     from glob import glob as Glob
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 # Does option parsing really screw up the win32 build? if no, remove comment
21 #if sys.platform == "win32":
22 #    env = Environment(ENV=os.environ)
23 #else:
24
25 # Warn the user about saved build options.
26 if os.path.exists('options.cache'):
27     optfile = file('options.cache')
28     print "Saved options:", optfile.read().replace("\n", ", ")[:-2]
29     optfile.close()
30 opts = Options('options.cache', ARGUMENTS)
31 opts.Add(PathOption('prefix', 'autotools-style installation prefix', '/usr/local', PathOption.PathAccept))
32 env = Environment(ENV=os.environ, options=opts)
33 opts.Update(env)
34 opts.Save('options.cache', env)
35
36 env.ParseConfig('pkg-config --cflags --libs glib-2.0')
37
38 env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
39 #env.Append(CXXFLAGS=' -O0', LINKFLAGS=' -O0')
40 #env.Append(CXXFLAGS=' -O3', LINKFLAGS=' -O3')
41
42 # Get the numpy include path (for numpy/arrayobject.h).
43 numpy_path = numpy.get_include()
44 env.Append(CPPPATH=numpy_path)
45
46
47 if sys.platform == "win32":
48     env.ParseConfig('pkg-config --cflags --libs python25') # These two '.pc' files you probably have to make for yourself.
49     env.ParseConfig('pkg-config --cflags --libs numpy')    # Place them among the other '.pc' files ( where the 'glib-2.0.pc' is located .. probably )
50 else:
51     env.ParseConfig('python%d.%d-config --cflags --ldflags' % (sys.version_info[0], sys.version_info[1]))
52
53 if env.get('CPPDEFINES'):
54     # make sure assertions are enabled
55     env['CPPDEFINES'].remove('NDEBUG')
56
57 module = SConscript('lib/SConscript', 'env')
58 SConscript('brushlib/SConscript', 'env')
59
60 # Build mypaint.exe for running on windows
61 if sys.platform == "win32":
62     env2 = Environment(ENV=os.environ)
63     env2.ParseConfig('pkg-config --cflags --libs python25')
64     env2.Program('mypaint', ['mypaint_exe.c'])
65
66 def burn_python_version(target, source, env):
67     # make sure we run the python version that we built the extension modules for
68     s =  '#!/usr/bin/env ' + python + '\n'
69     s += '#\n'
70     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
71     s += '#\n'
72     s += open(str(source[0])).read()
73     f = open(str(target[0]), 'w')
74     f.write(s)
75     f.close()
76
77 env.Command('mypaint', 'mypaint.in', [burn_python_version, Chmod('$TARGET', 0755)])
78
79 env.Alias('install', env['prefix'])
80 def install(dst, pattern):
81     env.Install(os.path.join(env['prefix'], dst), Glob(pattern))
82 install('bin', 'mypaint')
83 install('share/mypaint/brushes', 'brushes/*')
84 install('share/mypaint/backgrounds', 'backgrounds/*')
85
86 #install('share/mypaint/desktop', 'desktop/*')
87 # scons could recurse with Glob(), but it adds .svn directories when doing so
88 for dirpath, dirnames, filenames in os.walk('desktop'):
89     if '.svn' in dirnames:
90         dirnames.remove('.svn')
91     env.Install(os.path.join(env['prefix'], 'share/mypaint', dirpath), [os.path.join(dirpath, s) for s in filenames])
92
93 # mypaint.desktop goes into /usr/share/applications (debian-only or standard?)
94 install('share/applications', 'desktop/mypaint.desktop')
95
96 # location for achitecture-dependent modules
97 env.Install(os.path.join(env['prefix'], 'lib/mypaint'), module)
98 install('share/mypaint/lib', 'lib/*.py')
99 install('share/mypaint/gui', 'gui/*.py')
100 install('share/mypaint/brushlib', 'brushlib/*.py')
101
102 # debian python policy:
103 # "Private modules are installed in a directory such as /usr/share/packagename or /usr/lib/packagename."
104 # in general /usr/lib is for architecture-dependent stuff (compiled binaries or modules)
105 # and        /usr/share for independent
106
107
108 # normal python library:
109 # .deb on gettdeb.net:  /usr/share/mypaint/python
110
111 # autotools before:     /usr/lib/python2.5/site-packages/mypaint/mydrawwidget.so
112 # .deb on gettdeb.net:  /usr/lib/python2.5/site-packages/mypaint/mydrawwidget.so
113 # with foresight linux: /usr/lib64/python2.4/site-packages/mypaint/mydrawwidget.so
114 # (both of them probably just mirror autotools)
115