~midori/midori/trunk

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
292
293
#! /usr/bin/env python
# WAF build script for midori
# This file is licensed under the terms of the expat license, see the file EXPAT.

import Params
import pproc as subprocess
import Common
import sys
import os
import UnitTest

APPNAME = 'midori'
VERSION = '0.1.0'

try:
    git = subprocess.Popen (['git', 'rev-parse', '--short', 'HEAD'],
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if not git.wait ():
        VERSION = (VERSION + '-' + git.stdout.read ()).strip ()
except:
    pass

srcdir = '.'
blddir = '_build_'

def configure (conf):
    conf.check_tool ('compiler_cc')

    if not Params.g_options.disable_docs:
        conf.find_program ('rst2html.py', var='RST2HTML')
        # debian renames the executable, check that as well :(
        if not conf.env['RST2HTML']:
            conf.find_program ('rst2html', var='RST2HTML')
        if conf.env['RST2HTML']:
            docs = 'yes'
        else:
            docs = 'not available'
    else:
        docs = 'no'
    conf.check_message_custom ('generate', 'user documentation', docs)

    if not Params.g_options.disable_nls:
        conf.check_tool ('intltool')
        if conf.env['INTLTOOL'] and conf.env['POCOM']:
            nls = 'yes'
            conf.define ('ENABLE_NLS', 1)
            conf.define ('MIDORI_LOCALEDIR', 'LOCALEDIR', 0)
        else:
            nls = 'not available'
    else:
        nls = 'no'
    conf.check_message_custom ('localization', 'support', nls)

    if Params.g_options.libdir == '':
        libdir = os.path.join (conf.env['PREFIX'], 'lib')
    else:
        libdir = Params.g_options.libdir
    conf.define ('LIBDIR', libdir)

    # We support building without intltool
    # Therefore datadir may not have been defined
    if not conf.is_defined ('DATADIR'):
        if Params.g_options.datadir != '':
            conf.define ('DATADIR', Params.g_options.datadir)
        else:
            conf.define ('DATADIR', os.path.join (conf.env['PREFIX'], 'share'))

    if Params.g_options.docdir == '':
        docdir =  "%s/doc" % conf.env['DATADIR']
    else:
        docdir = Params.g_options.docdir
    conf.define ('DOCDIR', docdir)

    if Params.g_options.enable_api_docs:
        conf.find_program ('gtkdoc-scan', var='GTKDOC_SCAN')
        conf.find_program ('gtkdoc-mktmpl', var='GTKDOC_MKTMPL')
        conf.find_program ('gtkdoc-mkdb', var='GTKDOC_MKDB')
        conf.find_program ('gtkdoc-mkhtml', var='GTKDOC_MKHTML')
        if conf.env['GTKDOC_SCAN'] and conf.env['GTKDOC_MKTMPL'] \
            and conf.env['GTKDOC_MKDB'] and conf.env['GTKDOC_MKHTML']:
            api_docs = 'yes'
        else:
            api_docs = 'not available'
    else:
        api_docs = 'no'
    conf.check_message_custom ('generate', 'API documentation', api_docs)

    if not Params.g_options.disable_unique:
        conf.check_pkg ('unique-1.0', destvar='UNIQUE', vnum='0.9', mandatory=False)
        single_instance = ['not available','yes'][conf.env['HAVE_UNIQUE'] == 1]
    else:
        single_instance = 'no'
    conf.check_message_custom ('single instance', 'support', single_instance)

    if not Params.g_options.disable_libsoup:
        conf.check_pkg ('libsoup-2.4', destvar='LIBSOUP', mandatory=False)
        libsoup = ['not available','yes'][conf.env['HAVE_LIBSOUP'] == 1]
    else:
        libsoup = 'no'
    conf.check_message_custom ('libsoup', 'support', libsoup)

    if not Params.g_options.disable_sqlite:
        conf.check_pkg ('sqlite3', destvar='SQLITE', vnum='3.0', mandatory=False)
        sqlite = ['not available','yes'][conf.env['HAVE_SQLITE'] == 1]
    else:
        sqlite = 'no'
    conf.check_message_custom ('history database', 'support', sqlite)

    conf.check_pkg ('gmodule-2.0', destvar='GMODULE', vnum='2.8.0', mandatory=False)
    conf.check_pkg ('gio-2.0', destvar='GIO', vnum='2.16.0', mandatory=False)
    conf.check_pkg ('gtk+-2.0', destvar='GTK', vnum='2.10.0', mandatory=True)
    conf.check_pkg ('webkit-1.0', destvar='WEBKIT', vnum='0.1', mandatory=True)
    conf.check_pkg ('libxml-2.0', destvar='LIBXML', vnum='2.6', mandatory=True)

    conf.check_header ('unistd.h', 'HAVE_UNISTD_H')
    if sys.platform == 'darwin':
        conf.define ('HAVE_OSX', 1)

    if conf.find_program ('rsvg-convert', var='RSVG_CONVERT'):
        icons = 'yes'
    else:
        icons = 'no'
    conf.check_message_custom ('icon optimization', 'support', icons)

    conf.define ('PACKAGE_VERSION', VERSION)
    conf.define ('PACKAGE_NAME', APPNAME)
    conf.define ('PACKAGE_BUGREPORT', 'http://www.twotoasts.de/bugs')
    conf.define ('GETTEXT_PACKAGE', APPNAME)

    conf.write_config_header ('config.h')
    conf.env.append_value ('CCFLAGS', '-DHAVE_CONFIG_H')

    print
    if single_instance == 'not available':
        print "Single instance support is unavailable in this build."
        print " Install libUnique and reconfigure to enable it."
        print
    if libsoup == 'not available':
        print "Icons, view source and Save as are unavailable in this build."
        print " Install libSoup and reconfigure to enable these features."
        print
    if sqlite == 'not available':
        print "History storage on disk is unavailable in this build."
        print " Install sqlite3 and reconfigure to enable it."
        print

def set_options (opt):
    opt.tool_options ('compiler_cc')
    opt.tool_options ('intltool')
    opt.add_option ('--docdir', type='string', default='',
        help='Documentation root', dest='docdir')
    opt.add_option ('--disable-docs', action='store_true', default=False,
        help='Disables user documentation', dest='disable_docs')

    opt.add_option ('--disable-nls', action='store_true', default=False,
        help='Disables native language support', dest='disable_nls')

    opt.add_option ('--disable-unique', action='store_true', default=False,
        help='Disables Unique support', dest='disable_unique')
    opt.add_option ('--disable-libsoup', action='store_true', default=False,
        help='Disables libsoup support', dest='disable_libsoup')
    opt.add_option ('--disable-sqlite', action='store_true', default=False,
        help='Disables sqlite support', dest='disable_sqlite')

    opt.add_option ('--enable-api-docs', action='store_true', default=False,
        help='Enables API documentation', dest='enable_api_docs')

    opt.add_option ('--update-po', action='store_true', default=False,
        help='Update localization files', dest='update_po')

    opt.add_option ('--libdir', type='string', default='',
        help='Library root', dest='libdir')
    opt.add_option ('--disable-extensions', action='store_true', default=False,
        help='Disables building of extensions', dest='disable_extensions')

def build (bld):
    def mkdir (path):
        if not os.access (path, os.F_OK):
            os.mkdir (path)

    def _install_files (folder, destination, source):
        try:
            install_files (folder, destination, source)
        except:
            pass

    bld.add_subdirs ('katze midori icons')

    if not Params.g_options.disable_extensions:
        bld.add_subdirs ('extensions')

    install_files ('DOCDIR', '/' + APPNAME + '/', \
        'AUTHORS ChangeLog COPYING EXPAT README TRANSLATE')

    if bld.env ()['RST2HTML']:
        # FIXME: Build only if needed
        if not os.access (blddir, os.F_OK):
            os.mkdir (blddir)
        if not os.access (blddir + '/docs', os.F_OK):
            os.mkdir (blddir + '/docs')
        if not os.access (blddir + '/docs/user', os.F_OK):
            os.mkdir (blddir + '/docs/user')
        os.chdir (blddir + '/docs/user')
        subprocess.call ([bld.env ()['RST2HTML'], '-stg',
            '--stylesheet=../../../docs/user/midori.css',
            '../../../docs/user/midori.txt',
            'midori.html',])
        os.chdir ('../../..')
        install_files ('DOCDIR', '/midori/user/', blddir + '/docs/user/midori.html')

    if bld.env ()['INTLTOOL']:
        obj = bld.create_obj ('intltool_po')
        obj.podir = 'po'
        obj.appname = APPNAME

    if bld.env ()['GTKDOC_SCAN'] and Params.g_commands['build']:
        bld.add_subdirs ('docs/api')

    if bld.env ()['INTLTOOL']:
        obj = bld.create_obj ('intltool_in')
        obj.source   = APPNAME + '.desktop.in'
        obj.inst_var = 'DATADIR'
        obj.inst_dir = 'applications'
        obj.flags    = '-d'
    else:
        # FIXME: process desktop.in without intltool
        Params.pprint ('BLUE', "File " + APPNAME + ".desktop not generated")
    if bld.env ()['INTLTOOL']:
        install_files ('DATADIR', 'applications', APPNAME + '.desktop')

    if bld.env ()['RSVG_CONVERT']:
        mkdir (blddir + '/data')
        convert = subprocess.Popen ([bld.env ()['RSVG_CONVERT'],
            '-o', blddir + '/data/logo-shade.png',
            srcdir + '/data/logo-shade.svg'],
            stderr=subprocess.PIPE)
        if not convert.wait ():
            _install_files ('DATADIR', APPNAME,
                            blddir + '/data/logo-shade.png')
        else:
            Params.pprint ('BLUE', "logo-shade could not be rasterized.")

    if Params.g_commands['check']:
        bld.add_subdirs ('tests')

def shutdown ():
    if Params.g_commands['install'] or Params.g_commands['uninstall']:
        dir = Common.path_install ('DATADIR', 'icons/hicolor')
        icon_cache_updated = False
        if not Params.g_options.destdir:
            # update the pixmap cache directory
            try:
                uic = subprocess.Popen (['gtk-update-icon-cache', '-q', '-f', '-t', dir],
                                  stderr=subprocess.PIPE)
                if not uic.wait ():
                    Params.pprint ('YELLOW', "Updated Gtk icon cache.")
                    icon_cache_updated = True
            except:
                Params.pprint ('RED', "Failed to update icon cache.")
        if not icon_cache_updated:
            Params.pprint ('YELLOW', "Icon cache not updated. After install, run this:")
            Params.pprint ('YELLOW', "gtk-update-icon-cache -q -f -t %s" % dir)

    elif Params.g_commands['check']:
        test = UnitTest.unit_test ()
        test.change_to_testfile_dir = True
        test.want_to_see_test_output = True
        test.want_to_see_test_error = True
        test.run ()
        test.print_results ()

    elif Params.g_options.update_po:
        os.chdir('./po')
        try:
            try:
                size_old = os.stat (APPNAME + '.pot').st_size
            except:
                size_old = 0
            subprocess.call (['intltool-update', '--pot'])
            size_new = os.stat (APPNAME + '.pot').st_size
            if size_new <> size_old:
                Params.pprint ('YELLOW', "Updated po template.")
                try:
                    intltool_update = subprocess.Popen (['intltool-update', '-r'],
                                                         stderr=subprocess.PIPE)
                    intltool_update.wait ()
                    Params.pprint ('YELLOW', "Updated translations.")
                except:
                    Params.pprint ('RED', "Failed to update translations.")
        except:
            Params.pprint ('RED', "Failed to generate po template.")
            Params.pprint ('RED', "Make sure intltool is installed.")
        os.chdir ('..')