OSDN Git Service

version bump
[mypaint-anime/master.git] / SConstruct
index 4d1ceb3..1b626b1 100644 (file)
@@ -1,5 +1,6 @@
 import os, sys
 from os.path import join, basename
+from SCons.Script.SConscript import SConsEnvironment
 
 EnsureSConsVersion(1, 0)
 
@@ -11,7 +12,7 @@ print 'Building for', python
 if sys.platform == "win32":
     python = 'python' # usually no versioned binaries on Windows
 
-try: 
+try:
     import numpy
 except ImportError:
     print 'You need to have numpy installed.'
@@ -31,6 +32,7 @@ opts.Add(PathVariable('prefix', 'autotools-style installation prefix', default_p
 opts.Add(BoolVariable('debug', 'enable HEAVY_DEBUG and disable optimizations', False))
 env = Environment(ENV=os.environ, options=opts)
 if sys.platform == "win32":
+    # remove this mingw if trying VisualStudio
     env = Environment(tools=['mingw'], ENV=os.environ, options=opts)
 opts.Update(env)
 
@@ -45,8 +47,10 @@ env.Append(CPPPATH=numpy_path)
 
 
 if sys.platform == "win32":
-    env.ParseConfig('pkg-config --cflags --libs python25') # These two '.pc' files you probably have to make for yourself.
-    env.ParseConfig('pkg-config --cflags --libs numpy')    # Place them among the other '.pc' files ( where the 'glib-2.0.pc' is located .. probably )
+    # official python shipped with no pc file on windows so get from current python
+    from distutils import sysconfig
+    pre,inc = sysconfig.get_config_vars('exec_prefix', 'INCLUDEPY')
+    env.Append(CPPPATH=inc, LIBPATH=pre+'\libs', LIBS='python'+sys.version[0]+sys.version[2])
 elif sys.platform == "darwin":
     env.ParseConfig('python-config --cflags')
     env.ParseConfig('python-config --ldflags')
@@ -68,17 +72,13 @@ if env['debug']:
     env.Append(CPPDEFINES='HEAVY_DEBUG')
     env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
 
+#env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
+
 Export('env', 'python')
 module = SConscript('lib/SConscript')
 SConscript('brushlib/SConscript')
 languages = SConscript('po/SConscript')
 
-# Build mypaint.exe for running on windows
-if sys.platform == "win32":
-    env2 = Environment(tools=['mingw'], ENV=os.environ)
-    env2.ParseConfig('pkg-config --cflags --libs python25')
-    env2.Program('mypaint', ['mypaint_exe.c'])
-
 def burn_python_version(target, source, env):
     # make sure we run the python version that we built the extension modules for
     s =  '#!/usr/bin/env ' + python + '\n'
@@ -90,32 +90,98 @@ def burn_python_version(target, source, env):
     f.write(s)
     f.close()
 
+try:
+    new_umask = 022
+    old_umask = os.umask(new_umask)
+    print "set umask to 0%03o (was 0%03o)" % (new_umask, old_umask)
+except OSError:
+    # Systems like Win32...
+    pass
+
 env.Command('mypaint', 'mypaint.py', [burn_python_version, Chmod('$TARGET', 0755)])
 
 env.Clean('.', Glob('*.pyc'))
 env.Clean('.', Glob('gui/*.pyc'))
 env.Clean('.', Glob('lib/*.pyc'))
 
-env.Alias('install', env['prefix'])
-def install(dst, pattern):
-    files = Glob(pattern)
-    assert files, "Glob expression did not match any files"
-    env.Install(join(env['prefix'], dst), files)
-install('bin', 'mypaint')
-install('share/mypaint/brushes', 'brushes/*')
-install('share/mypaint/backgrounds', 'backgrounds/*')
-install('share/mypaint/pixmaps', 'pixmaps/*')
 
-install('share', 'desktop/icons')
-install('share/applications', 'desktop/mypaint.desktop')
+set_dir_postaction = {}
+def install_perms(target, sources, perms=0644, dirperms=0755):
+    """As a normal env.Install, but with Chmod postactions.
+
+    The `target` parameter must be a string which starts with ``$prefix``.
+    Unless this is a sandbox install, the permission bits `dirperms` will be
+    set on every directory back to ``$prefix``, but not including it. `perms`
+    will always be set on each installed file from `sources`.
+    """
+    assert target.startswith('$prefix')
+    install_targs = env.Install(target, sources)
+    sandboxed = False
+    final_prefix = os.path.normpath(env["prefix"])
+
+    # Set file permissions.
+    for targ in install_targs:
+        env.AddPostAction(targ, Chmod(targ, perms))
+        targ_path = os.path.normpath(targ.get_path())
+        if not targ_path.startswith(final_prefix):
+            sandboxed = True
+
+    if not sandboxed:
+        # Set permissions on superdirs, back to $prefix (but not including it)
+        # Not sure if this is necessary with the umask forcing. It might help
+        # fix some broken installs.
+        for file_targ in install_targs:
+            d = os.path.normpath(target)
+            d_prev = None
+            while d != d_prev and d != '$prefix':
+                d_prev = d
+                if not set_dir_postaction.has_key(d):
+                    env.AddPostAction(file_targ, Chmod(d, dirperms))
+                    set_dir_postaction[d] = True
+                d = os.path.dirname(d)
+
+    return install_targs
+
+
+def install_tree(dest, path, perms=0644, dirperms=0755):
+    assert os.path.isdir(path)
+    target_root = join(dest, os.path.basename(path))
+    for dirpath, dirnames, filenames in os.walk(path):
+        reltarg = os.path.relpath(dirpath, path)
+        target_dir = join(target_root, reltarg)
+        target_dir = os.path.normpath(target_dir)
+        filepaths = [join(dirpath, basename) for basename in filenames]
+        install_perms(target_dir, filepaths, perms=perms, dirperms=dirperms)
+
+
+# Painting resources
+install_tree('$prefix/share/mypaint', 'brushes')
+install_tree('$prefix/share/mypaint', 'backgrounds')
+install_tree('$prefix/share/mypaint', 'pixmaps')
+
+# Desktop resources and themeable internal icons
+install_tree('$prefix/share', 'desktop/icons')
+install_perms('$prefix/share/applications', 'desktop/mypaint.desktop')
 
 # location for achitecture-dependent modules
-env.Install(join(env['prefix'], 'lib/mypaint'), module)
-install('share/mypaint/lib', 'lib/*.py')
-install('share/mypaint/gui', 'gui/*.py')
-install('share/mypaint/gui', 'gui/menu.xml')
-install('share/mypaint/brushlib', 'brushlib/*.py')
+install_perms('$prefix/lib/mypaint', module)
+
+# Program and supporting UI XML
+install_perms('$prefix/bin', 'mypaint', perms=0755)
+install_perms('$prefix/share/mypaint/gui', Glob('gui/*.xml'))
+install_perms("$prefix/share/mypaint/lib",      Glob("lib/*.py"))
+install_perms("$prefix/share/mypaint/brushlib", Glob("brushlib/*.py"))
+install_perms("$prefix/share/mypaint/gui",      Glob("gui/*.py"))
 
 # translations
 for lang in languages:
-    install('share/locale/%s/LC_MESSAGES' % lang, 'po/%s/LC_MESSAGES/mypaint.mo' % lang)
+    install_perms('$prefix/share/locale/%s/LC_MESSAGES' % lang,
+                 'po/%s/LC_MESSAGES/mypaint.mo' % lang)
+
+# These hierarchies belong entirely to us, so unmake if asked.
+env.Clean('$prefix', '$prefix/lib/mypaint')
+env.Clean('$prefix', '$prefix/share/mypaint')
+
+# Convenience alias for installing to $prefix
+env.Alias('install', '$prefix')
+