OSDN Git Service

more tolerant search for python*-config; comment cleanups
[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     # some distros use python2.5-config, others python-config2.5
52     try:
53         env.ParseConfig(python + '-config --cflags --ldflags')
54     except OSError:
55         print 'going to try python-config instead'
56         env.ParseConfig('python-config --cflags --ldflags')
57
58 if env.get('CPPDEFINES'):
59     # make sure assertions are enabled
60     env['CPPDEFINES'].remove('NDEBUG')
61
62 module = SConscript('lib/SConscript', 'env')
63 SConscript('brushlib/SConscript', 'env')
64
65 # Build mypaint.exe for running on windows
66 if sys.platform == "win32":
67     env2 = Environment(ENV=os.environ)
68     env2.ParseConfig('pkg-config --cflags --libs python25')
69     env2.Program('mypaint', ['mypaint_exe.c'])
70
71 def burn_python_version(target, source, env):
72     # make sure we run the python version that we built the extension modules for
73     s =  '#!/usr/bin/env ' + python + '\n'
74     s += '#\n'
75     s += '# DO NOT EDIT - edit %s instead\n' % source[0]
76     s += '#\n'
77     s += open(str(source[0])).read()
78     f = open(str(target[0]), 'w')
79     f.write(s)
80     f.close()
81
82 env.Command('mypaint', 'mypaint.in.py', [burn_python_version, Chmod('$TARGET', 0755)])
83
84 env.Alias('install', env['prefix'])
85 def install(dst, pattern):
86     env.Install(os.path.join(env['prefix'], dst), Glob(pattern))
87 install('bin', 'mypaint')
88 install('share/mypaint/brushes', 'brushes/*')
89 install('share/mypaint/backgrounds', 'backgrounds/*')
90
91 #install('share/mypaint/desktop', 'desktop/*')
92 # scons could recurse with Glob(), but it adds .svn directories when doing so
93 for dirpath, dirnames, filenames in os.walk('desktop'):
94     if '.svn' in dirnames:
95         dirnames.remove('.svn')
96     env.Install(os.path.join(env['prefix'], 'share/mypaint', dirpath), [os.path.join(dirpath, s) for s in filenames])
97
98 # mypaint.desktop goes into /usr/share/applications (debian-only or standard?)
99 install('share/applications', 'desktop/mypaint.desktop')
100
101 # location for achitecture-dependent modules
102 env.Install(os.path.join(env['prefix'], 'lib/mypaint'), module)
103 install('share/mypaint/lib', 'lib/*.py')
104 install('share/mypaint/gui', 'gui/*.py')
105 install('share/mypaint/brushlib', 'brushlib/*.py')
106
107 # debian python policy:
108 # "Private modules are installed in a directory such as /usr/share/packagename or /usr/lib/packagename."
109 # in general /usr/lib is for architecture-dependent stuff (compiled binaries or modules)
110 # and        /usr/share for independent
111
112
113 # normal python library:
114 # .deb on gettdeb.net:  /usr/share/mypaint/python
115
116 # autotools before:     /usr/lib/python2.5/site-packages/mypaint/mydrawwidget.so
117 # .deb on gettdeb.net:  /usr/lib/python2.5/site-packages/mypaint/mydrawwidget.so
118 # with foresight linux: /usr/lib64/python2.4/site-packages/mypaint/mydrawwidget.so
119 # (both of them probably just mirror autotools)
120