glib.recipe 13.3 KB
Newer Older
1
# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
2
import shlex
3
import shutil
4
5
from cerbero.tools.libtool import LibtoolLibrary
from cerbero.tools.libtool import get_libtool_versions
Andoni Morales Alastruey's avatar
Andoni Morales Alastruey committed
6

7
8
9
10
11
12
13
GLIB_CONFIG_UNVERSAL='''\
#ifdef __i386__
#include "i386/glibconfig.h"
#elif defined(__ppc__)
#include "ppc/glibconfig.h"
#elif defined(__x86_64__)
#include "x86_64/glibconfig.h"
14
15
#elif defined(__arm__)
#include "arm/glibconfig.h"
16
17
#elif defined(__arm64__)
#include "arm64/glibconfig.h"
18
19
20
21
22
#else
#error "Unsupported Architecture"
#endif
'''

Andoni Morales Alastruey's avatar
Andoni Morales Alastruey committed
23
24
class Recipe(recipe.Recipe):
    name = 'glib'
Nirbheek Chauhan's avatar
Nirbheek Chauhan committed
25
    version = '2.62.6'
26
    stype = SourceType.TARBALL
27
    url = 'gnome://'
Nirbheek Chauhan's avatar
Nirbheek Chauhan committed
28
    tarball_checksum = '104fa26fbefae8024ff898330c671ec23ad075c1c0bce45c325c6d5657d58b9c'
29
    licenses = [License.LGPLv2Plus]
30
    btype = BuildType.MESON
31
32
    meson_options = {'internal_pcre': 'true', 'libmount': 'false', 'dtrace': 'false',
                     'iconv': 'auto'}
33
    deps = ['libffi', 'zlib']
34

Nirbheek Chauhan's avatar
Nirbheek Chauhan committed
35
36
37
38
39
40
41
42
43
44
    patches = [
        'glib/0003-Add-support-for-loading-GIO-modules-from-the-distro-.patch',
        'glib/0004-Allow-for-a-second-distro-GIO-module-path-as-used-on.patch',
        'glib/0006-giomodule-do-not-try-to-load-modules-from-gio-module.patch',
        'glib/0008-Unhide-_g_io_modules_ensure_extension_points_registe.patch',
        'glib/0009-Implementation-of-Cocoa-event-loop-integration-in-GM.patch',
        # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1415,
        'glib/0001-meson-Don-t-use-assert-in-test-code.patch',
        # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1433
        'glib/0001-meson-fix-buildtype-args-and-vscrt-usage.patch',
45
46
47
48
        # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1512
        'glib/0001-meson-host_system-can-be-ios-when-cross-compiling.patch',
        'glib/0002-meson-Autodetect-when-building-for-iOS.patch',
        'glib/0003-meson-Only-look-for-_NSGetEnviron-when-building-for-.patch',
49
50
        # https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1522
        'glib/0001-meson-Fix-gnulib-printf-checks.patch',
Nirbheek Chauhan's avatar
Nirbheek Chauhan committed
51
    ]
52

53
54
55
    files_libs = [
        'libglib-2.0', 'libgio-2.0', 'libgmodule-2.0', 'libgobject-2.0',
        'libgthread-2.0']
Sebastian Dröge's avatar
Sebastian Dröge committed
56
    files_bins = ['gsettings', 'gdbus', 'gio-querymodules', 'glib-compile-schemas']
Andoni Morales Alastruey's avatar
Andoni Morales Alastruey committed
57
58
59
    platform_files_schemas = {
        Platform.WINDOWS: ['share/glib-2.0/schemas'],
        Platform.DARWIN: ['share/glib-2.0/schemas'],
Thibault Saunier's avatar
Thibault Saunier committed
60
        Platform.IOS: ['share/glib-2.0/schemas'],
Andoni Morales Alastruey's avatar
Andoni Morales Alastruey committed
61
    }
62
63
    #FIXME: Fill it when needed
    #files_gio = ['lib/gio/modules']
64
    files_devel = [
65
66
        'bin/glib-gettextize',
        'bin/glib-mkenums',
Sebastian Dröge's avatar
Sebastian Dröge committed
67
        'bin/glib-compile-resources%(bext)s',
68
        'bin/glib-genmarshal',
Sebastian Dröge's avatar
Sebastian Dröge committed
69
        'bin/gresource%(bext)s',
70
        'bin/gdbus-codegen',
71
        'lib/glib-2.0/include',
72
73
74
        'lib/pkgconfig/gio-2.0.pc',
        'lib/pkgconfig/glib-2.0.pc',
        'lib/pkgconfig/gmodule-2.0.pc',
75
76
        'lib/pkgconfig/gmodule-export-2.0.pc',
        'lib/pkgconfig/gmodule-no-export-2.0.pc',
77
78
        'lib/pkgconfig/gobject-2.0.pc',
        'lib/pkgconfig/gthread-2.0.pc',
79
        'include/glib-2.0',
80
        'share/aclocal/glib-2.0.m4',
81
        'share/aclocal/glib-gettext.m4'
82
    ]
83
    platform_files_devel = {
84
        Platform.WINDOWS: ['lib/pkgconfig/gio-windows-2.0.pc', 'include/gio-win32-2.0'],
85
        Platform.LINUX: ['lib/pkgconfig/gio-unix-2.0.pc', 'include/gio-unix-2.0'],
86
        Platform.ANDROID: ['lib/pkgconfig/gio-unix-2.0.pc', 'include/gio-unix-2.0'],
87
        Platform.DARWIN: ['lib/pkgconfig/gio-unix-2.0.pc', 'include/gio-unix-2.0'],
Thibault Saunier's avatar
Thibault Saunier committed
88
        Platform.IOS: ['lib/pkgconfig/gio-unix-2.0.pc', 'include/gio-unix-2.0'],
89
90
    }

91
    files_lang = ['glib20']
92

93
    def _set_gio_flags(self, path1=None, path2=None, use_old_uri_scheme=False):
94
        self.append_env('CFLAGS', *self._gio_flags(path1, path2, use_old_uri_scheme))
95

96
    def _gio_flags(self, path1=None, path2=None, use_old_uri_scheme=False):
97
        flags = []
98
        def escape(path):
99
100
101
102
103
            # We want the define the macro to a C string, then we quote it
            # because it is expanded inside cerbero to set c_args in the cross
            # file or to pass directly to meson using the env var for native
            # builds
            return shlex.quote('"{}"'.format(path))
104
        if path1 is not None:
105
            flags.append('-DGST_SDK_GLIB_GIO_DISTRO_GIO_MODULE_PATH=' + escape(path1))
106
        if path2 is not None:
107
            flags.append('-DGST_SDK_GLIB_GIO_DISTRO_GIO_MODULE_PATH2=' + escape(path2))
108
        if use_old_uri_scheme:
109
            flags.append('-DGST_SDK_GLIB_GIO_OLD_URI_SCHEME_HANDLERS=1')
110
        return flags
111

112
    def prepare(self):
113
114
        # Glib doesn't support static libraries on Windows yet
        if self.config.target_platform == Platform.WINDOWS:
115
            self.library_type = LibraryType.SHARED
116

117
        if self.config.target_platform != Platform.LINUX:
118
119
            # Disable valgrind code on non-Linux, in the best case it just
            # gives us compiler errors :)
120
            self.append_env('CFLAGS', '-DNVALGRIND=1')
121
122
123
            self.meson_options.update({'xattr': 'false'})
            self.deps.append('proxy-libintl')

124
        # Android only provides libiconv with API level >=28 (Pie and newer)
125
        if self.config.target_platform == Platform.ANDROID and DistroVersion.get_android_api_version(self.config.target_distro_version) < 28:
126
127
            self.deps.append('libiconv')

128
        if self.config.target_platform == Platform.WINDOWS:
129
130
            # Want secure versions of stdlib functions. Glib already defines
            # _WIN32_WINNT, so undefine it on the cmdline to avoid warnings
131
            self.append_env('CFLAGS', '-DMINGW_HAS_SECURE_API=1', '-U_WIN32_WINNT')
132
133
134
135
136
137
138
            # TODO: upstream
            if self.config.variants.uwp:
                # gdbus is completely disabled at present
                self.files_bins.remove('gdbus')
                self.files_bins_devel.remove('bin/gdbus.pdb')
                self.patches += [
                    # Ready to upstream
139
                    'glib/uwp/0001-glib-Never-use-MessageBox-on-UWP-apps.patch',
140
                    'glib/uwp/0001-gpoll-UWP-does-not-need-to-poll-a-msg_fd.patch',
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
                    'glib/uwp/0001-gio-Remove-broken-support-for-XP.patch',
                    'glib/uwp/0002-win_iconv-Use-LoadPackagedLibrary-when-building-UWP-.patch',
                    'glib/uwp/0003-glib-getpid-is-available-on-Win32-but-not-WinRT.patch',
                    'glib/uwp/0004-goption-Do-not-call-GetCommandlineW-on-UWP.patch',
                    'glib/uwp/0005-gmodule-Fix-some-more-WinRT-incompatibilities.patch',
                    'glib/uwp/0006-gutils-Can-t-fetch-the-username-on-UWP.patch',
                    'glib/uwp/0007-gutils-GetWindowsDirectory-is-not-available-on-WinRT.patch',
                    'glib/uwp/0008-glocalfile-File-user-info-is-not-supported-on-WinRT.patch',
                    'glib/uwp/0009-gwin32-Stub-out-all-version-checking-on-WinRT.patch',
                    'glib/uwp/0010-gutils-GetModuleHandle-is-not-available-on-WinRT.patch',
                    'glib/uwp/0011-gsocket-if_nametoindex-is-not-available-on-WinRT.patch',
                    'glib/uwp/0012-gio-ginetaddress-Fix-build-on-WinRT.patch',
                    # Need some more work
                    'glib/uwp/0013-WIP-UPSTREAM-glib-Specify-noreturn-prototype-for-MSV.patch',
                    'glib/uwp/0014-WIP-gspawn-Do-not-allow-spawning-or-making-pipes-on-.patch',
                    'glib/uwp/0015-WIP-glib-giowin32-Disallow-invalid-usage-of-GIOChann.patch',
                    'glib/uwp/0016-WIP-glocalfile-Trash-as-a-concept-does-not-exist-on-.patch',
                    'glib/uwp/0020-WIP-glib-Implement-get_special_folder-for-UWP-apps.patch',
                    'glib/uwp/0021-WIP-gtimezone-Partially-port-to-WinRT.patch',
                    # Need a lot more work
                    'glib/uwp/0017-TODO-gdate-gstdio-Abort-when-trying-to-use-unsupport.patch',
                    'glib/uwp/0018-gio-Disable-win32-API-and-modules-when-unavailable-o.patch',
                    'glib/uwp/0019-TODO-gdbus-Completely-disable-when-building-for-WinR.patch',
                    'glib/uwp/0022-TODO-gio-gcontenttype-Needs-porting-to-WinRT-model.patch',
                ]
Thibault Saunier's avatar
Thibault Saunier committed
166
        elif self.config.target_platform in [Platform.DARWIN, Platform.IOS]:
167
            self.files_devel.append(os.path.join('lib', 'glib-2.0', 'include', '*', 'glibconfig.h'))
168
169
170
            arch = self.config.target_arch
            if arch == Architecture.X86:
                arch = 'i386'
171
172
            elif arch == Architecture.ARM64:
                arch = 'arm64'
173
            elif Architecture.is_arm(arch):
174
                arch = 'arm'
175
            extra_flags = []
Thibault Saunier's avatar
Thibault Saunier committed
176
177
            if self.config.target_platform == Platform.IOS:
                # Disable mac OS X specifics
178
                extra_flags = ['-DGST_SDK_IOS=1']
179
180
                # XXX: Why did we disable these for iOS?
                #self.configure_options += ' --disable-carbon --disable-modular-tests --disable-cocoa'
181
            self.append_env('CFLAGS', *extra_flags)
182

183
        elif self.config.target_platform == Platform.LINUX:
184
185
186
            path1 = '/usr/lib/gio/modules'
            path2 = None
            use_old_uri_scheme = False
187
            self.meson_options.update({'selinux': 'disabled'})
188
189
190
191
192
            # Old Debian/Ubuntu
            if self.config.target_distro_version in [DistroVersion.DEBIAN_SQUEEZE,
                                                     DistroVersion.UBUNTU_LUCID,
                                                     DistroVersion.UBUNTU_MAVERICK]:
                use_old_uri_scheme = True
193
194
195
            # Ubuntu, cannot check self.config.target_distro here because it's
            # set to Distro.DEBIAN
            elif self.config.target_distro_version.startswith('ubuntu_'):
196
                if self.config.target_arch == Architecture.X86:
197
                    path2 = '/usr/lib/i386-linux-gnu/gio/modules'
198
                elif self.config.target_arch == Architecture.X86_64:
199
200
                    path2 = '/usr/lib/x86_64-linux-gnu/gio/modules'
            # Debian
201
            elif self.config.target_distro == Distro.DEBIAN:
202
                if self.config.target_arch == Architecture.X86:
203
                    path1 = '/usr/lib/i386-linux-gnu/gio/modules'
204
                elif self.config.target_arch == Architecture.X86_64:
205
206
                    path1 = '/usr/lib/x86_64-linux-gnu/gio/modules'
            # RedHat
207
208
209
            elif self.config.target_distro == Distro.REDHAT:
                if self.config.target_arch == Architecture.X86_64:
                    path1 = '/usr/lib64/gio/modules/'
210
            # Suse
211
            elif self.config.target_distro == Distro.SUSE:
212
213
                if self.config.target_arch == Architecture.X86_64:
                    path1 = '/usr/lib64/gio/modules/'
214
215
216
            # Arch
            elif self.config.target_distro == Distro.ARCH:
                path1 = '/usr/lib/gio/modules/'
217
218
219
            # Gentoo
            elif self.config.target_distro == Distro.GENTOO:
                path1 = '/usr/lib/gio/modules/'
220
221
            elif self.config.target_distro == Distro.NONE:
                if self.config.target_distro_version == DistroVersion.NONE_UCLIBC:
222
                    self.deps += ('proxy-libintl', 'libiconv')
223
224
            else:
                raise FatalError(_("Add specific for other Linux distributions here"))
Andoni Morales Alastruey's avatar
Andoni Morales Alastruey committed
225
            self._set_gio_flags(path1, path2, use_old_uri_scheme)
226
227

    def post_install(self):
228
        if self.config.target_platform in [Platform.IOS, Platform.DARWIN]:
229
            # For the universal build we need to ship glibconfig.h of both
230
            # architectures in a subfolder and include the correct one depending
231
232
233
234
            # on the compiler architecture
            arch = self.config.target_arch
            if arch == Architecture.X86:
                arch = 'i386'
235
236
237
            elif arch == Architecture.ARM64:
                arch = 'arm64'
            elif Architecture.is_arm(arch):
238
                arch = 'arm'
239
240
241
242
243

            arch_dir = os.path.join(self.config.prefix, 'lib', 'glib-2.0',
                                     'include', arch)
            if not os.path.exists(arch_dir):
                os.makedirs(arch_dir)
244
            shutil.copyfile(os.path.join(self.meson_dir, 'glib', 'glibconfig.h'),
245
246
247
248
                        os.path.join(arch_dir, 'glibconfig.h'))
            with open(os.path.join(self.config.prefix, 'lib', 'glib-2.0',
                                   'include', 'glibconfig.h'), 'w+') as f:
                f.write(GLIB_CONFIG_UNVERSAL)
249
250
251
252
253
254
255
256
257
258
        major, minor, micro = get_libtool_versions(self.version)
        # Meson does not generate la files
        LibtoolLibrary('glib-2.0', major, minor, micro,
                self.config.libdir, self.config.target_platform).save()
        LibtoolLibrary('gobject-2.0', major, minor, micro,
                self.config.libdir, self.config.target_platform,
                deps=['glib-2.0', 'ffi']).save()
        LibtoolLibrary('gmodule-2.0', major, minor, micro,
                self.config.libdir, self.config.target_platform,
                deps=['glib-2.0']).save()
259
260
261
        LibtoolLibrary('gthread-2.0', major, minor, micro,
                self.config.libdir, self.config.target_platform,
                deps=['glib-2.0']).save()
262
263
264
        LibtoolLibrary('gio-2.0', major, minor, micro,
                self.config.libdir, self.config.target_platform,
                deps=['gobject-2.0', 'gmodule-2.0', 'z']).save()
265
        super().post_install()