forked from mypaint/libmypaint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConscript
211 lines (162 loc) · 7.5 KB
/
SConscript
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
Import('env', 'install_perms')
import os, sys
import subprocess
brushlib_version = '1.1'
def add_gobject_introspection(env, gi_name, version,
func_prefix, type_prefix,
sources, includepaths, library,
pkgs, includes):
pkgs = ' '.join('--pkg=%s' % dep for dep in pkgs)
library = library[0] # there should be only one Node in the list
# Strip the library path to get the library name
libname = os.path.basename(library.get_path())
libname = os.path.splitext(libname)[0]
if libname.startswith('lib'):
libname = libname[3:]
includeflags = ' '.join(['-I%s' % s for s in includepaths])
gi_includes = ' '.join(['--include=%s' % s for s in includes])
scanner_cmd = """LD_LIBRARY_PATH=./ g-ir-scanner -o $TARGET --warn-all \
--namespace=%(gi_name)s --nsversion=%(version)s --add-include-path=./ \
--identifier-prefix=%(type_prefix)s --symbol-prefix=%(func_prefix)s \
%(pkgs)s %(includeflags)s %(gi_includes)s \
--library=%(libname)s $SOURCES""" % locals()
gir_file = env.Command("%s-%s.gir" % (gi_name, version), sources, scanner_cmd)
env.Depends(gir_file, library)
typelib_file = env.Command("%s-%s.typelib" % (gi_name, version), gir_file,
"g-ir-compiler --includedir=./ -o $TARGET $SOURCE")
return (gir_file, typelib_file)
# Generate a @pkgconfig_name.pc and a @pkgconfig_name-uninstalled.pc
def create_pkgconfig_files(env, pkgconfig_name, version, description,
libname, deps, libs=[], linkflags=[], cflags=[]):
pkg_info = {
'@LIBNAME@': libname,
'@REQUIRES@': ' '.join(deps),
'@DESCRIPTION@': description,
'@VERSION@': version,
'@LIBS@': ' '.join('-l'+lib for lib in libs),
'@LINKFLAGS@': ' '.join(linkflags),
'@PREFIX@': env['prefix'],
'@LIBDIR@': os.path.join(env['prefix'], 'lib'),
'@INCLUDEDIR@': os.path.join(env['prefix'], 'include'),
}
pc_file = env.Substfile('%s.pc' % pkgconfig_name,
"pkgconfig.pc.in", SUBST_DICT=pkg_info)
install_perms(env, '$prefix/lib/pkgconfig', pc_file)
return pc_file
# Helper for ParseConfig
def parse_pkg_config(env, libname):
extras = ""
if sys.platform == "msys" and os.environ.get("MSYSTEM") != "MSYS":
# Building on e.g. MINGW32 using MSYS scons.
# Paths will have drive letters & mess up scons's os.path.join()s
# unless we do this:
extras += " --dont-define-prefix"
cmd = "pkg-config --cflags --libs {libname} {extras}".format(
libname = libname,
extras = extras,
)
env.ParseConfig(cmd)
# NOTE: We use a copy of the environment, to be able to both inherit common options,
# and also add our own specifics ones without affecting the other builds
top_env = env
env = env.Clone()
if env['enable_introspection']:
if not env['use_glib']:
print "Enabling glib because of enable_introspection=true"
if not env['use_sharedlib']:
print "Building a shared lib instead of a static lib because of enable_introspection=true"
env['use_glib'] = True
env['use_sharedlib'] = True
Export('env')
if env['enable_docs']:
doc = SConscript('doc/SConscript')
env.Append(CPPPATH='./')
env.Append(CPPDEFINES='HAVE_JSON_C')
json_pkgconfig = 'json-c'
if subprocess.call(["pkg-config", json_pkgconfig]):
print "Could not find 'json-c' pkg-config, trying legacy 'json' instead"
json_pkgconfig = 'json'
pkg_deps = [json_pkgconfig]
libs = ['m']
linkflags = []
if env['enable_openmp']:
env.Append(CFLAGS='-fopenmp')
linkflags += ['-fopenmp']
if env['enable_i18n']:
env.Append(CPPDEFINES='HAVE_GETTEXT')
if sys.platform == "darwin":
libs += ['intl']
config_defines = ''
if env['use_glib']:
pkg_deps += ['gobject-2.0']
config_defines += '#define MYPAINT_CONFIG_USE_GLIB 1\n'
else:
config_defines += '#define MYPAINT_CONFIG_USE_GLIB 0\n'
config_file = env.Substfile("mypaint-config.h", "mypaint-config.h.in",
SUBST_DICT={'@DEFINES@': config_defines})
def generate_cheaders(env, target, source):
cmd = ' '.join([
env['python_binary'],
str(source[0]),
str(target[0]),
str(target[1]),
])
env.Execute(cmd)
env.Command(['mypaint-brush-settings-gen.h', 'brushsettings-gen.h'],
['generate.py', 'brushsettings.py', 'brushsettings.json'],
generate_cheaders)
env.Clean('.', Glob('*-gen.h'))
env.Clean('.', Glob('*.pyc'))
env.Clean('.', Glob('*.o'))
env.Append(LINKFLAGS=linkflags)
env.Append(LIBS=libs)
for pkg in pkg_deps:
parse_pkg_config(env, pkg)
lib_builder = env.SharedLibrary if env['use_sharedlib'] else env.StaticPicLibrary
sources = Glob("*.c")
sources = [n for n in sources if not n.name == "libmypaint.c"]
brushlib = lib_builder('./mypaint', sources)
create_pkgconfig_files(env, 'libmypaint', brushlib_version, 'MyPaint brush engine library',
libname='mypaint', deps=pkg_deps, libs=libs, linkflags=linkflags)
if env['enable_introspection']:
gir, typelib = add_gobject_introspection(env, "MyPaint", brushlib_version,
"mypaint_", "MyPaint",
Glob("*.c") + Glob("mypaint-*.h") +
Glob("glib/mypaint-[!gegl]*.c") + Glob("glib/mypaint-[!gegl]*.h"),
['./'], brushlib, ['glib-2.0'], [])
install_perms(env, '$prefix/share/gir-1.0', gir)
install_perms(env, '$prefix/lib/girepository-1.0', typelib)
install_perms(env, '$prefix/lib/', brushlib)
install_perms(env, '$prefix/include/libmypaint', Glob("./mypaint-*.h"))
install_perms(env, '$prefix/include/libmypaint/glib', Glob("./glib/mypaint-*.h"))
install_perms(env, "$prefix/share/libmypaint", Glob("./*.py"))
install_perms(env, "$prefix/share/libmypaint", "./brushsettings.json")
if env['enable_i18n']:
languages = SConscript('po/SConscript')
# Optional: GEGL library
gegl_env = env.Clone()
if env['enable_gegl']:
deps = ['gegl-%s' % env['GEGL_VERSION']]
for d in deps:
parse_pkg_config(gegl_env, d)
gegl_env.Append(LIBPATH=['.'], LIBS=['mypaint'])
lib_builder = gegl_env.SharedLibrary if env['use_sharedlib'] else gegl_env.StaticPicLibrary
brushlib_gegl = lib_builder('./mypaint-gegl', Glob("./gegl/*.c"))
install_perms(env, '$prefix/lib/', brushlib_gegl)
install_perms(env, '$prefix/include/libmypaint-gegl', Glob("./gegl/mypaint-gegl-*.h"))
create_pkgconfig_files(env, 'libmypaint-gegl', brushlib_version, 'MyPaint brush engine library, with GEGL integration',
libname='mypaint-gegl', deps=deps + ['libmypaint'])
if gegl_env['enable_introspection']:
gir, typelib = add_gobject_introspection(gegl_env, "MyPaintGegl", brushlib_version,
"mypaint_gegl", "MyPaintGegl",
Glob("gegl/*.c") + Glob("gegl/mypaint-gegl-*.h") +
Glob("glib/mypaint-gegl*"),
['./', './gegl'], brushlib_gegl,
['glib-2.0', 'gegl-%s' % env['GEGL_VERSION']],
['Gegl-%s' % env['GEGL_VERSION'], 'MyPaint-%s' % brushlib_version])
install_perms(env, '$prefix/share/gir-1.0', gir)
install_perms(env, '$prefix/lib/girepository-1.0', typelib)
Export('gegl_env', 'env', 'parse_pkg_config')
tests = SConscript('tests/SConscript')
Return('brushlib')
# vim:syntax=python