~tweenk/inkscape/waf-build

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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/usr/bin/env python
# encoding: utf-8

top = '.'
out = 'build'
appname = 'inkscape'
tarball_version = '0.48+devel'

import waflib, re, os
from waflib import Configure, Build, Task, TaskGen, Utils, Logs, Tools
from waflib.Build import BuildContext
from inkwaf import ConfigHelpers
from waflib.Tools import ccroot, compiler_c, compiler_cxx
from waflib.TaskGen import feature, after_method

# enable autoconf-like automatic reconfiguration if a wscript is modified
Configure.autoconfig = True
# On Windows, we prefer MinGW
compiler_c.c_compiler['win32'] = ['gcc', 'clang']
compiler_cxx.cxx_compiler['win32'] = ['g++', 'clang++']

is_windows = Utils.is_win32
is_linux = Utils.unversioned_sys_platform() == 'linux'

def options(ctx):
    ctx.load('compiler_cxx')
    ctx.load('compiler_c')
    ctx.load('gnu_dirs')
    ctx.load('glib2')
    ctx.load('intltool')

    copt = ctx.parser.get_option_group('--out')
    copt.add_option('--with-gtk3', action='store_true', help='Use GTK+ 3.x')
    copt.add_option('--with-dbus', action='store_true', help='Enable DBus API')
    copt.add_option('--with-ext-gdl', action='store_true', help='Use external GDL')

def configure(ctx):
    ctx.env.PACKAGE = appname
    ctx.load('compiler_cxx')
    ctx.load('compiler_c')
    ctx.load('gnu_dirs')
    ctx.load('glib2', funs='find_glib_genmarshal')
    if is_linux:
        ctx.load('intltool')
    else:
        ctx.load('intltool', funs='find_msgfmt')
        ctx.check_cc(header_name='locale.h')

    # for revision reporting
    ctx.find_program('bzr', mandatory=False)

    ctx.check_cc(cppflags='-Wall', uselib_store='COMMON', msg='Enabling default compiler warnings')
    ctx.check_cc(cppflags='-Werror=format-security', uselib_store='COMMON', msg='Enabling format security errors', mandatory=False)
    ctx.check_cc(cppflags='-O2', uselib_store='COMMON', msg='Enabling some optimizations')
    ctx.check_cc(cppflags='-g', uselib_store='COMMON', msg='Enabling debug info')
    ctx.env.append_unique('DEFINES', 'HAVE_CONFIG_H')
    if not ctx.check_cc(header_name='stdint.h', mandatory=False):
        ctx.check_cc(header_name='inttypes.h')
    ctx.check_cc(header_name='ieeefp.h', mandatory=False)
    ctx.check_cc(header_name='ieeefp.h', function_name='fpsetmask', mandatory=False)
    ctx.check_cc(header_name='unistd.h', mandatory=False)
    ctx.check_cc(header_name='sys/param.h', mandatory=False)
    ctx.check_cc(header_name='dirent.h', mandatory=False)
    ctx.check_cc(header_name='fcntl.h', mandatory=False)
    ctx.check_cc(header_name='zlib.h', lib='z', uselib_store='Z', mandatory=False)
    ctx.check_cc(header_name='gc/gc.h', lib='gc', uselib_store='GC')
    ctx.check_cc(header_name='jpeglib.h', function_name='jpeg_CreateDecompress', lib='jpeg', uselib_store='JPEG', define_name='HAVE_JPEG', msg='Checking for libjpeg', mandatory=False)
    ctx.check_cc(header_name='aspell.h', function_name='new_aspell_config', lib='aspell', define_name='HAVE_ASPELL', uselib_store='ASPELL', mandatory=False)

    # mallinfo checking
    ctx.check_cc(header_name='malloc.h', mandatory=False)
    ctx.check_cc(header_name='malloc.h', function_name='mallinfo', mandatory=False)
    ctx.check_cc(header_name='malloc.h', type_name='struct mallinfo', field_name='usmblks', mandatory=False)
    ctx.check_cc(header_name='malloc.h', type_name='struct mallinfo', field_name='fsmblks', mandatory=False)
    ctx.check_cc(header_name='malloc.h', type_name='struct mallinfo', field_name='uordblks', mandatory=False)
    ctx.check_cc(header_name='malloc.h', type_name='struct mallinfo', field_name='fordblks', mandatory=False)
    ctx.check_cc(header_name='malloc.h', type_name='struct mallinfo', field_name='hblkhd', mandatory=False)

    # more complex checks, defined in inkwaf/ConfigHelpers.py
    ctx.check_openmp(uselib_store='COMMON', mandatory=False)
    ctx.check_boost_optional_strict_aliasing()
    ctx.check_unordered_set()

    # check pkg-config packages
    ctx.check_package('GLIB', 'glib-2.0', '2.32')
    ctx.check_package('GLIBMM', 'glibmm-2.4', '2.32')
    ctx.check_package('GIO', 'gio-2.0', '2.32')
    ctx.check_package('GIOMM', 'giomm-2.4', '2.32')
    ctx.check_cxx(header_name='glibmm/threads.h', use='GLIBMM')

    if ctx.options.with_gtk3:
        ctx.check_package('GTK', 'gtk+-3.0', '3.0')
        ctx.check_package('GTK', 'gtkspell-3.0', define_name='WITH_GTKSPELL')
        ctx.check_package('GTKMM', 'gtkmm-3.0', '3.0', define_name='WITH_GTKMM_3_0')
        ctx.check_package('GDKMM', 'gdkmm-3.0')
        ctx.define('WITH_GTKMM_3_0', 1)
    else:
        ctx.check_package('GTK', 'gtk+-2.0', '2.24')
        ctx.check_package('GTK', 'gtkspell-2.0', define_name='WITH_GTKSPELL')
        ctx.check_package('GTKMM', 'gtkmm-2.4', '2.24')
        ctx.check_package('GDKMM', 'gdkmm-2.4')

    if ctx.options.with_ext_gdl:
        ctx.check_package('GDL', 'gdl-3.0')
        ctx.check_package('GDL', 'gdl-3.0', '3.6', define_name='WITH_GDL_3_6', mandatory=False)
        ctx.define('WITH_EXT_GDL', 1)

    ctx.check_package('XML2', 'libxml-2.0', '2.6.11')
    ctx.check_package('XSLT', 'libxslt', '1.0')
    ctx.check_package('PNG', 'libpng', '1.2')
    ctx.check_package('EXIF', 'libexif')
    ctx.check_package('GSL', 'gsl')
    ctx.check_package('CAIRO', 'cairo', '1.12')
    ctx.check_package('FREETYPE', 'freetype2', '0.22')
    ctx.check_package('POPT', 'popt')

    if not ctx.check_package('LCMS', 'lcms2', '2.0', define_name='HAVE_LIBLCMS2', mandatory=False):
        ctx.check_package('LCMS', 'lcms', '1.13', define_name='HAVE_LIBLCMS1', mandatory=False)
    ctx.check_package('PANGOFT2', 'pangoft2', mandatory=False)
    ctx.check_poppler('POPPLER') # defined in inkwaf/ConfigHelpers.py
    ctx.check_package('CAIRO_PDF', 'cairo-pdf')
    wpg2 = ctx.check_package('WPG', 'libwpg-0.2', define_name='WITH_LIBWPG02', mandatory=False)
    wpg1 = ctx.check_package('WPG', 'libwpg-0.1 libwpg-stream-0.1', define_name='WITH_LIBWPG01', mandatory=False)
    ctx.check_package('CDR', 'libcdr-0.0', define_name='WITH_LIBCDR', mandatory=False)
    ctx.check_package('VISIO', 'libvisio-0.0', '0.0.20', define_name='WITH_LIBVISIO', mandatory=False)
    ctx.check_package('IMAGEMAGICK', 'ImageMagick++', define_name='WITH_IMAGE_MAGICK', mandatory=False)

    if wpg1 or wpg2:
        ctx.define('WITH_LIBWPG', 1)

    # library feature checks
    ctx.check_cc(header_name='libintl.h', function_name='bind_textdomain_codeset', use='GTK', mandatory=False)
    ctx.check_cc(header_name='gtk/gtk.h', function_name='gtk_window_set_default_icon_from_file', use='GTK', mandatory=False)
    ctx.check_cc(header_name='gtk/gtk.h', function_name='gtk_window_fullscreen', use='GTK', mandatory=False)

    # some fixed defines
    ctx.define('PACKAGE_TARNAME', appname)
    ctx.define('PACKAGE_STRING', appname)
    ctx.define('GETTEXT_PACKAGE', appname)
    ctx.define('VERSION', tarball_version)
    ctx.define('INKSCAPE_DATADIR', ctx.env.DATADIR)
    ctx.define('PACKAGE_LOCALE_DIR', ctx.env.LOCALEDIR)
    ctx.define('HAVE_THREADS', 1)
    ctx.define('_FORTIFY_SOURCE', 2)
    ctx.define('G_DISABLE_SINGLE_INCLUDES', 1)
    ctx.define('GSEAL_ENABLE', 1)
    ctx.undefine('DATADIR')
    ctx.write_config_header('config.h')

def build(ctx):
    ilib_paths = []
    def build_internal_lib(lib, srcpath, **kw):
        realuse = 'COMMON cshlib cxxshlib' # generate code which can be linked into dynamic libs
        if 'use' in kw:
            realuse = kw['use'] + ' ' + realuse
            del kw['use']
        ctx(features = 'c cxx cxxstlib',
            source = ctx.path.ant_glob(srcpath),
            target = lib,
            name = lib,
            includes = ['src', '#'],
            use = realuse,
            **kw)
        ilib_paths.append(srcpath)

    revno = ''
    if ctx.env.BZR:
        revno = int(ctx.cmd_and_log('%s revno --tree' % ctx.env.BZR[0], quiet=waflib.Context.BOTH))

    # version information file
    ctx(features = 'subst',
        source = 'src/inkscape-version.cpp.in',
        target = 'inkscape-version.cpp',
        VERSION = tarball_version,
        REVNO = revno,
        always = True)

    ctx.stlib(
        source = 'inkscape-version.cpp',
        target = 'inkversion',
        name = 'inkversion')

    build_internal_lib(
        '2geom', 'src/2geom/**/*.cpp',
        use = 'GSL GLIB')
    build_internal_lib(
        'avoid', 'src/libavoid/*.cpp')
    build_internal_lib(
        'cola', 'src/libcola/*.cpp')
    build_internal_lib(
        'croco', 'src/libcroco/*.c',
        use = 'XML2 GLIB')
    build_internal_lib(
        'depixelize', 'src/libdepixelize/*.cpp',
        use = 'GDKMM GLIBMM')
    build_internal_lib(
        'livarot', 'src/livarot/*.cpp',
        use = '2geom GTK GLIBMM XML2')
    build_internal_lib(
        'uemf', 'src/libuemf/*.c')
    build_internal_lib(
        'vpsc', 'src/libvpsc/**/*.cpp',
        use = 'GLIB')
    if not ctx.env.LIB_GDL:
        build_internal_lib(
            'GDL', 'src/libgdl/*.c',
            use = 'GTK GLIB')

    excluded_files = ['src/main.cpp', 'src/inkview.cpp', 'src/io/streamtest.cpp']

    #print ilib_paths + main_files
    #print ctx.path.ant_glob(incl=['src/**/*.cpp', 'src/**/*.c'], excl = ilib_paths + main_files)

    shared_sources = ['src/**/*.cpp', 'src/**/*.c']

    inklib = ctx.shlib(
        source = ctx.path.ant_glob(['src/**/*.cpp', 'src/**/*.c'], excl = ilib_paths + excluded_files),
        target = 'inklib',
        name = 'inklib',
        includes = ['src', '#'],
        use = 'depixelize livarot avoid cola vpsc uemf GDL croco inkversion ' +
              'GTKMM GLIBMM GIOMM FREETYPE CDR WPG VISIO POPPLER_CAIRO POPPLER CAIRO ' +
              'IMAGEMAGICK LCMS XML2 XSLT PNG JPEG EXIF ASPELL POPT GC Z COMMON')
    inklib.add_marshal_file('src/helper/sp-marshal.list', 'sp_marshal')

    ctx.program(
        source = 'src/main.cpp',
        target = 'inkscape',
        includes = ['src', '#'],
        use = 'inklib')
    ctx.program(
        source = 'src/inkview.cpp',
        target = 'inkview',
        includes = ['src', '#'],
        use = 'inklib')

    ctx(features = 'intltool_po',
        appname = appname,
        podir = 'po',
        install_path = "${LOCALEDIR}")
    if is_linux:
        ctx(features = 'intltool_in',
            podir = 'po',
            flags = ['--desktop-style', '-q', '-u', '-c'],
            source = 'inkscape.desktop.in',
            install_path = '${DATADIR}/applications')

    ctx.install_files(
        '${DATADIR}/inkscape',
        ctx.path.ant_glob('share/**/*', excl=['share/icons/application/**/*', 'share/icons/hicolor/*']))

    ctx.install_as(
        '${DATADIR}/icons/hicolor/scalable/applications/inkscape.svg',
        'share/branding/inkscape.svg')
    ctx.install_as(
        '${DATADIR}/icons/hicolor/scalable/mimetypes/image-svg+xml.svg',
        'share/icons/inkscape.file.svg')
    ctx.install_as(
        '${DATADIR}/icons/hicolor/32x32/mimetypes/image-svg+xml.svg',
        'share/icons/inkscape.file.png')

    for appicon in ctx.path.ant_glob('share/icons/application/inkscape_*.png'):
        name = os.path.basename(appicon.abspath())
        size = re.search(r'_([0-9]+)', name).group(1)
        ctx.install_as(
            '${DATADIR}/icons/hicolor/%sx%s/applications/inkscape.png' % (size, size),
            appicon)

# deduplicate flags
@feature('c', 'cxx', 'uselib')
@after_method('propagate_uselib_vars')
def prune_flags(self):
    for v in ['LIB', 'STLIB', 'LIBPATH', 'STLIBPATH', 'INCLUDES', 'CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'DEFINES']:
        uniqued = []
        seen = set()
        for a in reversed(self.env[v]):
            if a not in seen:
                seen.add(a)
                uniqued.append(a)
        self.env[v] = list(reversed(uniqued))

# nicer task display
def display(task):
    dstr = ' '.join([a.nice_path() for a in (task.outputs or task.inputs)])
    tasktype = task.__class__.__name__.replace('_task', '').upper()
    if tasktype == 'C' or tasktype == 'CXX':
        dstr = dstr.replace(out + '/', '')
    return '%-5s %s\n' % (tasktype, dstr)
Task.Task.__str__ = display

# vim: filetype=python:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :