forked from mypaint/mypaint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
241 lines (194 loc) · 8.88 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import os, sys
from os.path import join, basename
from SCons.Script.SConscript import SConsEnvironment
import SCons.Util
EnsureSConsVersion(2, 1)
default_python_binary = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
default_python_config = 'python%d.%d-config' % (sys.version_info[0], sys.version_info[1])
if sys.platform == "win32":
# Usually no versioned binaries on native Windows.
default_python_binary = 'python'
default_python_config = 'python-config'
elif sys.platform == "msys" and os.environ.get("MSYSTEM") != "MSYS":
# Building from MINGW32 or MINGW64 shell using MSYS2 python+scons.
# Defaults above will work fine.
pass
elif os.path.exists('/etc/gentoo-release'):
print 'Gentoo: /etc/gentoo-release exists. Must be on a Gentoo based system.'
default_python_config = 'python-config-%d.%d' % (sys.version_info[0],sys.version_info[1])
SConsignFile() # no .scsonsign into $PREFIX please
default_prefix = '/usr/local/'
default_openmp = True
if sys.platform == "darwin":
default_openmp = False
def isabs(key, dirname, env):
assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
opts = Variables()
opts.Add(
'prefix', 'autotools-style installation prefix',
default=default_prefix,
validator=isabs,
)
opts.Add(BoolVariable('debug', 'enable HEAVY_DEBUG and disable optimizations', False))
opts.Add(BoolVariable('enable_profiling', 'enable debug symbols for profiling purposes', True))
opts.Add(BoolVariable('enable_gegl', 'enable GEGL based code in build', False))
opts.Add(BoolVariable('enable_introspection', 'enable GObject introspection support', False))
opts.Add(BoolVariable('use_sharedlib', 'build a shared library instead of a static library (forced on by introspection)', False))
opts.Add(BoolVariable('use_glib', 'enable glib (forced on by introspection)', False))
opts.Add(BoolVariable('enable_docs', 'enable documentation build', False))
opts.Add(BoolVariable('enable_gperftools', 'enable gperftools in build, for profiling', False))
opts.Add(BoolVariable('enable_openmp', 'enable OpenMP for multithreaded processing', default_openmp))
opts.Add('python_binary', 'python executable to build for', default_python_binary)
opts.Add('python_config', 'python-config to use', default_python_config)
opts.Add('numpy_include', 'override include dir for NumPy (where numpy/arrayobject.h lives)', None)
tools = ['default', 'textfile']
if sys.platform == "msys" and os.environ.get("MSYSTEM") != "MSYS":
# Building from MINGW32 or MINGW64 shell using MSYS2 python+scons.
# MSYS2 ship their own SCons.Tool.mingw_w64
# https://github.com/Alexpux/MSYS2-packages/blob/master/scons
tools.append("mingw_w64")
elif sys.platform == "win32":
# Assume MinGW.org. This is untested outside of MSYS2.
# You're welcome to try MSVC instead: if it works, please submit a
# patch with a suitable options switch.
tools.append("mingw")
env = Environment(ENV=os.environ, options=opts, tools=tools)
Help(opts.GenerateHelpText(env))
if not env.GetOption("help"):
print('building for %r (use scons python_binary=xxx to change)'
% env['python_binary'])
print('using %r (use scons python_config=xxx to change)'
% env['python_config'])
# Respect some standard build environment stuff
# See http://cgit.freedesktop.org/mesa/mesa/tree/scons/gallium.py
# See https://wiki.gentoo.org/wiki/SCons#Missing_CC.2C_CFLAGS.2C_LDFLAGS
if os.environ.has_key('CC'):
env['CC'] = os.environ['CC']
if os.environ.has_key('CFLAGS'):
env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
if os.environ.has_key('CXX'):
env['CXX'] = os.environ['CXX']
if os.environ.has_key('CXXFLAGS'):
env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
if os.environ.has_key('CPPFLAGS'):
env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CPPFLAGS'])
env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CPPFLAGS'])
if os.environ.has_key('LDFLAGS'):
# LDFLAGS is omitted in SHLINKFLAGS, which is derived from LINKFLAGS
env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
if "$CCFLAGS" in env['CXXCOM']:
env['CXXCOM'] = env['CXXCOM'].replace("$CCFLAGS","")
opts.Update(env)
env.Append(CXXFLAGS=' -Wall -Wno-sign-compare -Wno-write-strings')
env.Append(CCFLAGS='-Wall')
env.Append(CFLAGS='-std=c99')
env['GEGL_VERSION'] = 0.3
# Define strdup() in string.h under glibc >= 2.10 (POSIX.1-2008)
env.Append(CFLAGS='-D_POSIX_C_SOURCE=200809L')
if env.get('CPPDEFINES'):
# make sure assertions are enabled
env['CPPDEFINES'].remove('NDEBUG')
if env['debug']:
env.Append(CPPDEFINES='HEAVY_DEBUG')
env.Append(CCFLAGS='-O0', LINKFLAGS='-O0')
else:
# Overridable defaults
env.Prepend(CCFLAGS='-O3', LINKFLAGS='-O3')
if env['enable_profiling'] or env['debug']:
env.Append(CCFLAGS='-g')
#env.Append(CCFLAGS='-fno-inline', LINKFLAGS='-fno-inline')
if sys.platform == "darwin":
pass
elif sys.platform == "win32":
pass
elif sys.platform == "msys" and os.environ.get("MSYSTEM") != "MSYS":
# Building from MINGW32 or MINGW64 shell using MSYS2 python+scons.
pass
else: # Assume Linux.
# Look up libraries dependencies relative to the library.
env.Append(LINKFLAGS='-Wl,-z,origin')
env.Append(RPATH = env.Literal(os.path.join('\\$$ORIGIN')))
# remove libraries produced by earlier versions, which are actually
# being used if they keep lying around, leading to mysterious bugs
env.Execute(Delete([
'libmypaint-tests.so',
'libmypaint-tests.so',
'libmypaint.so',
'libmypaintlib.so',
'libmypaint.a',
'libmypaint-tests.a',
'lib/_mypaintlib.so',
]))
set_dir_postaction = {}
def install_perms(env, target, sources, perms=0644, dirperms=0755):
"""As a normal env.Install, but with Chmod postactions.
The `target` parameter must be a string starting with ``$prefix``.
The permissions in `perms` will be assigned to each file which was
installed from `sources` in a post-install action.
The `dirperms` permissions will be assigned to each created
directory component which does not exist (at the time of calling
this function). Each set of permission bits is assigned in its own
postaction.
"""
assert target.startswith('$prefix')
install_targs = env.Install(target, sources)
# Set file permissions, and defer directory permission setting
for targ in install_targs:
env.AddPostAction(targ, Chmod(targ, perms))
d = os.path.dirname(os.path.normpath(targ.get_abspath()))
d_prev = None
while d != d_prev and not os.path.exists(d):
if not d in set_dir_postaction:
env.AddPostAction(targ, Chmod(d, dirperms))
set_dir_postaction[d] = True
d_prev = d
d = os.path.dirname(d)
# Return like Install()
return install_targs
def install_tree(env, 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(env, target_dir, filepaths, perms=perms, dirperms=dirperms)
def createStaticPicLibraryBuilder(env):
"""This is a utility function that creates the StaticExtLibrary Builder in
an Environment if it is not there already.
If it is already there, we return the existing one."""
import SCons.Action
try:
static_extlib = env['BUILDERS']['StaticPicLibrary']
except KeyError:
action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
if env.Detect('ranlib'):
ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
action_list.append(ranlib_action)
static_extlib = SCons.Builder.Builder(action = action_list,
emitter = '$LIBEMITTER',
prefix = '$LIBPREFIX',
suffix = '$LIBSUFFIX',
src_suffix = '$OBJSUFFIX',
src_builder = 'SharedObject')
env['BUILDERS']['StaticPicLibrary'] = static_extlib
return static_extlib
createStaticPicLibraryBuilder(env)
# Common
install_tree(env, '$prefix/share/mypaint', 'brushes')
# 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')
Export('env', 'install_tree', 'install_perms')
if not env.GetOption("help"):
print "Enabling i18n for brushlib in full application build"
env['enable_i18n'] = True
# Brushlib
brushlib = SConscript('./brushlib/SConscript')
Export('brushlib')
# App and its library
SConscript('./SConscript')
# vim:syntax=python