File: wscript_build

package info (click to toggle)
glmark2 2023.01%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,380 kB
  • sloc: cpp: 20,680; python: 13,052; ansic: 8,595; java: 1,246; xml: 383; makefile: 41; sh: 39
file content (298 lines) | stat: -rw-r--r-- 11,260 bytes parent folder | download | duplicates (3)
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
294
295
296
297
298
# Detect a Windows build.
is_win = 'WIN32' in ' '.join(bld.env.keys())

# Detect MSVC
is_msvc = bld.env.CXX_NAME == 'msvc'

all_sources = bld.path.ant_glob('*.cpp scene-ideas/*.cc scene-terrain/*.cpp')
common_sources = [f for f in all_sources if f.name.find('canvas-') == -1 and
                                            f.name.find('android') == -1 and
                                            f.name.find('native-state-') == -1 and
                                            f.name.find('gl-state-') == -1 and
                                            f.name.find('main.cpp') == -1]

common_defines = ['USE_EXCEPTIONS']

libmatrix_sources = [f for f in bld.path.ant_glob('libmatrix/*.cc')
                     if not f.name.endswith('test.cc')]

common_flavor_sources = ['main.cpp', 'canvas-generic.cpp']

libpng_local_sources = [f for f in bld.path.ant_glob('libpng/*.c')]
zlib_local_sources = [f for f in bld.path.ant_glob('zlib/*.c')]

# Some c sources in libjpeg-turbo are included like headers. So we cannot use globs.
libjpeg_local_sources = [
  'jcapimin', 'jcapistd', 'jccoefct', 'jccolor', 'jcdctmgr', 'jchuff', 'jcinit',
  'jcmainct', 'jcmarker', 'jcmaster', 'jcomapi', 'jcparam', 'jcphuff', 'jcprepct',
  'jcsample', 'jdapimin', 'jdapistd', 'jdatadst', 'jdatasrc', 'jdcoefct', 'jdcolor',
  'jddctmgr', 'jdhuff', 'jdinput', 'jdmainct', 'jdmarker', 'jdmaster', 'jdmerge',
  'jdphuff', 'jdpostct', 'jdsample', 'jerror', 'jfdctflt', 'jfdctfst', 'jfdctint',
  'jidctflt', 'jidctfst', 'jidctint', 'jidctred', 'jmemmgr', 'jmemnobs', 'jquant1',
  'jquant2', 'jsimd_none', 'jutils',
]

libjpeg_turbo_local_sources = ['libjpeg-turbo/%s.c' % f for f in libjpeg_local_sources]

platform_includes = []
platform_libs = []
platform_uselibs = []

if is_win:
  platform_uselibs += ['libpng-local', 'zlib-local', 'libjpeg-turbo-local']
  platform_libs = ['user32']

  # On windows include some overrides for posix headers.
  if is_msvc:
    platform_includes += ['include']
else:
  platform_uselibs += ['libpng']
  platform_libs = ['m', 'jpeg', 'dl']

if 'WAYLAND_SCANNER_wayland_scanner' in bld.env.keys():
    def wayland_scanner_cmd(arg, src):
        return '%s %s < %s > ${TGT}' % (bld.env['WAYLAND_SCANNER_wayland_scanner'], arg, src)

    def wayland_proto_src_path(proto, ver):
        wp_dir = bld.env['WAYLAND_PROTOCOLS_pkgdatadir']
        if ver == 'stable':
            return '%s/stable/%s/%s.xml' % (wp_dir, proto, proto)
        else:
            return '%s/unstable/%s/%s-unstable-%s.xml' % (wp_dir, proto, proto, ver)

    def wayland_client_protocol(proto, ver, dst_base):
        src_path = wayland_proto_src_path(proto, ver)
        out = '%s-client-protocol.h' % dst_base
        return bld(rule = wayland_scanner_cmd('client-header', src_path),
                   target = out,
                   name = out,
                   ext_out = ['.h'])

    def wayland_protocol_code(proto, ver, dst_base):
        src_path = wayland_proto_src_path(proto, ver)
        out = '%s-protocol.c' % dst_base
        return bld(rule = wayland_scanner_cmd('private-code', src_path),
                   target = out,
                   name = out)

    wayland_client_protocol('xdg-shell', 'stable', 'xdg-shell')
    wayland_protocol_code('xdg-shell', 'stable', 'xdg-shell')

flavor_sources = {
  'dispmanx-glesv2' : common_flavor_sources + ['native-state-dispmanx.cpp', 'gl-state-egl.cpp'],
  'drm-gl' : common_flavor_sources + ['native-state-drm.cpp', 'gl-state-egl.cpp'],
  'drm-glesv2' : common_flavor_sources + ['native-state-drm.cpp', 'gl-state-egl.cpp'],
  'wayland-gl' : common_flavor_sources + ['native-state-wayland.cpp', 'gl-state-egl.cpp'],
  'wayland-glesv2' : common_flavor_sources + ['native-state-wayland.cpp', 'gl-state-egl.cpp'],
  'win32-gl': common_flavor_sources + ['native-state-win32.cpp', 'gl-state-wgl.cpp'],
  'win32-glesv2': common_flavor_sources + ['native-state-win32.cpp', 'gl-state-egl.cpp'],
  'x11-gl' : common_flavor_sources + ['native-state-x11.cpp', 'gl-state-glx.cpp'],
  'x11-glesv2' : common_flavor_sources + ['native-state-x11.cpp', 'gl-state-egl.cpp'],
}
flavor_uselibs = {
  'dispmanx-glesv2' : ['glad-egl-dispmanx', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2',  'dispmanx'],
  'drm-gl' : ['drm', 'gbm', 'udev', 'glad-egl-drm', 'glad-gl', 'matrix-gl', 'common-gl'],
  'drm-glesv2' : ['drm', 'gbm', 'udev', 'glad-egl-drm', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
  'wayland-gl' : ['wayland-client', 'wayland-egl', 'wayland-cursor', 'glad-egl-wayland', 'glad-gl', 'matrix-gl', 'common-gl'],
  'wayland-glesv2' : ['wayland-client', 'wayland-egl', 'wayland-cursor', 'glad-egl-wayland', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
  'win32-gl': ['glad-gl', 'glad-wgl', 'matrix-gl', 'common-gl'],
  'win32-glesv2': ['glad-egl-win32', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
  'x11-gl' : ['x11', 'glad-gl', 'glad-glx', 'matrix-gl', 'common-gl'],
  'x11-glesv2' : ['x11', 'glad-egl-x11', 'glad-glesv2', 'matrix-glesv2', 'common-glesv2'],
}

flavor_defines = {
  'dispmanx-glesv2' : ['GLMARK2_USE_DISPMANX', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
  'drm-gl' : ['GLMARK2_USE_DRM', 'GLMARK2_USE_GL', 'GLMARK2_USE_EGL'],
  'drm-glesv2' : ['GLMARK2_USE_DRM', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
  'wayland-gl' : ['GLMARK2_USE_WAYLAND', 'GLMARK2_USE_GL', 'GLMARK2_USE_EGL'],
  'wayland-glesv2' : ['GLMARK2_USE_WAYLAND', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
  'win32-gl': ['GLMARK2_USE_WIN32', 'GLMARK2_USE_WGL', 'GLMARK2_USE_GL'],
  'win32-glesv2': ['GLMARK2_USE_WIN32', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
  'x11-gl' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GL', 'GLMARK2_USE_GLX'],
  'x11-glesv2' : ['GLMARK2_USE_X11', 'GLMARK2_USE_GLESv2', 'GLMARK2_USE_EGL'],
}
flavor_libs = {
  'dispmanx-glesv2' : [],
  'drm-gl' : [],
  'drm-glesv2' : [],
  'wayland-gl' : [],
  'wayland-glesv2' : [],
  'win32-gl': ['opengl32', 'gdi32'],
  'win32-glesv2' : [],
  'x11-gl' : [],
  'x11-glesv2' : [],
}
flavor_depends_on = {
  'dispmanx-glesv2' : [],
  'drm-gl' : [],
  'drm-glesv2' : [],
  'wayland-gl' : ['xdg-shell-client-protocol.h', 'xdg-shell-protocol.c'],
  'wayland-glesv2' : ['xdg-shell-client-protocol.h', 'xdg-shell-protocol.c'],
  'win32-gl': [],
  'win32-glesv2' : [],
  'x11-gl' : [],
  'x11-glesv2' : [],
}
flavor_sources_gen = {
  'dispmanx-glesv2' : [],
  'drm-gl' : [],
  'drm-glesv2' : [],
  'wayland-gl' : [bld.path.find_or_declare('xdg-shell-protocol.c')],
  'wayland-glesv2' : [bld.path.find_or_declare('xdg-shell-protocol.c')],
  'win32-gl': [],
  'win32-glesv2' : [],
  'x11-gl' : [],
  'x11-glesv2' : [],
}
egl_platform_defines = {
  'dispmanx' : ['MESA_EGL_NO_X11_HEADERS'],
  'drm' : ['__GBM__'],
  'wayland' : ['WL_EGL_PLATFORM'],
  'win32' : [],
  'x11' : [],
}

includes = ['.', 'scene-ideas', 'scene-terrain'] + platform_includes

all_uselibs = set()

for name in bld.env.keys():
    if name.startswith('FLAVOR_') and bld.env[name]:
        flavor = name.replace('FLAVOR_', '').lower().replace('_', '-')
        egl_platform = flavor.split('-')[0]
        target = bld.env[name]
        node = bld(
            features     = ['cxx', 'cprogram'],
            source       = flavor_sources[flavor],
            target       = target,
            use          = platform_uselibs + flavor_uselibs[flavor],
            lib          = platform_libs + flavor_libs[flavor],
            includes     = ['.'] + platform_includes,
            defines      = common_defines + flavor_defines[flavor] +
                           ['GLMARK2_EXECUTABLE="%s"' % target] +
                           egl_platform_defines[egl_platform],
            depends_on   = flavor_depends_on[flavor]
            )
        if flavor_sources_gen[flavor]:
            node.source.extend(flavor_sources_gen[flavor])
        all_uselibs |= set(flavor_uselibs[flavor] + platform_uselibs)

# Build glad-egl for all used EGL platforms
for egl_target in (v for v in all_uselibs if v.startswith('glad-egl')):
    egl_platform = egl_target.split('-')[2]
    bld(
        features = ['c'],
        source   = ['glad/src/egl.c'],
        target   = egl_target,
        includes = ['glad/include'],
        export_includes = 'glad/include',
        defines = egl_platform_defines[egl_platform]
        )

if 'glad-glx' in all_uselibs:
    bld(
        features = ['c'],
        source   = ['glad/src/glx.c'],
        target   = 'glad-glx',
        includes = ['glad/include'],
        export_includes = 'glad/include'
        )

if 'glad-gl' in all_uselibs:
    bld(
        features = ['c'],
        source   = ['glad/src/gl.c'],
        target   = 'glad-gl',
        includes = ['glad/include'],
        export_includes = 'glad/include'
        )

if 'glad-wgl' in all_uselibs:
    bld(
        features = ['c'],
        source   = ['glad/src/wgl.c'],
        target   = 'glad-wgl',
        includes = ['glad/include'],
        export_includes = 'glad/include'
        )

if 'glad-glesv2' in all_uselibs:
    bld(
        features = ['c'],
        source   = ['glad/src/gles2.c'],
        target   = 'glad-glesv2',
        includes = ['glad/include'],
        export_includes = 'glad/include'
        )
        
if 'matrix-gl' in all_uselibs:
    bld(
        features = ['cxx', 'cxxstlib'],
        source   = libmatrix_sources,
        target   = 'matrix-gl',
        use      = ['glad-gl'],
        lib      = ['m'],
        includes = ['.'] + platform_includes,
        export_includes = 'libmatrix',
        defines  = ['GLMARK2_USE_GL', 'USE_EXCEPTIONS']
        )

if 'matrix-glesv2' in all_uselibs:
    bld(
        features = ['cxx', 'cxxstlib'],
        source   = libmatrix_sources,
        target   = 'matrix-glesv2',
        use      = ['glad-glesv2'],
        lib      = ['m'],
        includes = ['.'] + platform_includes,
        export_includes = 'libmatrix',
        defines  = ['GLMARK2_USE_GLESv2', 'USE_EXCEPTIONS']
        )

if 'libpng-local' in all_uselibs:
    bld(
        features  = ['c'],
        source    = libpng_local_sources,
        target    = 'libpng-local',
        use       = ['zlib-local'],
        export_includes = 'libpng'
        )

if 'zlib-local' in all_uselibs:
    bld(
        features  = ['c'],
        source    = zlib_local_sources,
        target    = 'zlib-local',
        export_includes = 'zlib'
        )

if 'libjpeg-turbo-local' in all_uselibs:
    bld(
        features  = ['c'],
        source    = libjpeg_turbo_local_sources,
        target    = 'libjpeg-turbo-local',
        export_includes = 'libjpeg-turbo'
        )

if 'common-gl' in all_uselibs:
    bld(
        features = ['cxx', 'cxxstlib'],
        source   = common_sources,
        target   = 'common-gl',
        use      = platform_uselibs + ['glad-gl', 'matrix-gl'],
        lib      = ['m', 'jpeg', 'dl'],
        includes = includes,
        defines  = ['GLMARK2_USE_GL', 'USE_EXCEPTIONS']
        )

if 'common-glesv2' in all_uselibs:
    bld(
        features = ['cxx', 'cxxstlib'],
        source   = common_sources,
        target   = 'common-glesv2',
        use      = platform_uselibs + ['glad-glesv2', 'matrix-glesv2'],
        lib      = ['m', 'jpeg', 'dl'],
        includes = includes,
        defines  = ['GLMARK2_USE_GLESv2', 'USE_EXCEPTIONS']
        )