summaryrefslogtreecommitdiff
path: root/build/gecko_templates.mozbuild
blob: 8eab9d327d8b325f5026a9f4adb3b329ae6b66be (plain)
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
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

@template
def GeckoBinary(linkage='dependent', msvcrt='dynamic', mozglue=None):
    '''Template for Gecko-related binaries.

    This template is meant to be used in other templates.

    `linkage` indicates the wanted xpcom linkage type. Valid values are
    'dependent', 'standalone' or None. 'dependent' is the default. It is
    used for e.g. XPCOM components and executables with direct dependencies
    on libxul. Most executables should use the 'standalone' linkage, which
    uses the standalone XPCOM glue to load libxul. None means no XPCOM glue
    or libxul linkage at all.

    `msvcrt` indicates which Microsoft Visual Studio CRT, for Windows build,
    ought to be linked: 'static' or 'dynamic'.

    `mozglue` indicates whether to link against the mozglue library, and if
    so, what linkage to apply. Valid values are None (mozglue not linked),
    'program' (mozglue linked to an executable program), or 'library' (mozglue
    linked to a shared library).
    '''
    if msvcrt == 'dynamic' or CONFIG['OS_ARCH'] != 'WINNT' or CONFIG['MOZ_ASAN']:
        xpcomglue = 'xpcomglue'
    elif msvcrt == 'static':
        USE_STATIC_LIBS = True
        xpcomglue = 'xpcomglue_staticruntime'
        if not CONFIG['GNU_CC']:
            mozglue = None
            if linkage == 'dependent':
                USE_LIBS += [
                    'mozalloc_staticruntime',
                ]
    else:
        error('msvcrt must be "dynamic" or "static"')

    if linkage == 'dependent':
        USE_LIBS += [
            'nspr',
            '%s_s' % xpcomglue,
            'xul',
        ]
    elif linkage == 'standalone':
        DEFINES['XPCOM_GLUE'] = True

        USE_LIBS += [
            xpcomglue,
        ]
    elif linkage != None:
        error('`linkage` must be "dependent", "standalone" or None')

    if mozglue:
        LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
        if mozglue == 'program':
            USE_LIBS += ['mozglue']
            DEFINES['MOZ_HAS_MOZGLUE'] = True
            if CONFIG['MOZ_GLUE_IN_PROGRAM']:
                if CONFIG['GNU_CC']:
                    LDFLAGS += ['-rdynamic']
                if CONFIG['MOZ_MEMORY']:
                    USE_LIBS += ['memory']
        elif mozglue == 'library':
            LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True
            if not CONFIG['MOZ_GLUE_IN_PROGRAM']:
                USE_LIBS += ['mozglue']
        else:
            error('`mozglue` must be "program" or "library"')

    if not CONFIG['JS_STANDALONE']:
        USE_LIBS += [
            'fallible',
        ]


@template
def GeckoProgram(name, linkage='standalone', **kwargs):
    '''Template for program executables related to Gecko.

    `name` identifies the executable base name.

    See the documentation for `GeckoBinary` for other possible arguments,
    with the notable difference that the default for `linkage` is 'standalone'.
    '''
    Program(name)

    kwargs.setdefault('mozglue', 'program')

    GeckoBinary(linkage=linkage, **kwargs)


@template
def GeckoSimplePrograms(names, **kwargs):
    '''Template for simple program executables related to Gecko.

    `names` identifies the executable base names for each executable.

    See the documentation for `GeckoBinary` for other possible arguments.
    '''
    SimplePrograms(names)

    kwargs.setdefault('mozglue', 'program')

    GeckoBinary(**kwargs)


@template
def GeckoCppUnitTests(names, **kwargs):
    '''Template for C++ unit tests related to Gecko.

    `names` identifies the executable base names for each executable.

    See the documentation for `GeckoBinary` for other possible arguments.
    '''
    CppUnitTests(names)

    kwargs.setdefault('mozglue', 'program')

    GeckoBinary(**kwargs)


@template
def GeckoSharedLibrary(name, **kwargs):
    '''Template for shared libraries related to Gecko.

    `name` identifies the library base name.
    See the documentation for `GeckoBinary` for other possible arguments.
    '''
    SharedLibrary(name)

    kwargs.setdefault('mozglue', 'library')

    GeckoBinary(**kwargs)


@template
def GeckoFramework(name, **kwargs):
    '''Template for OSX frameworks related to Gecko.

    `name` identifies the library base name.
    See the documentation for `GeckoBinary` for other possible arguments.
    '''
    Framework(name)

    kwargs.setdefault('mozglue', 'library')

    GeckoBinary(**kwargs)


@template
def XPCOMBinaryComponent(name):
    '''Template defining an XPCOM binary component for Gecko.

    `name` is the name of the component.
    '''
    GeckoSharedLibrary(name)

    IS_COMPONENT = True