Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | |
michael@0 | 3 | import os |
michael@0 | 4 | |
michael@0 | 5 | import locale |
michael@0 | 6 | locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') |
michael@0 | 7 | |
michael@0 | 8 | header = """ |
michael@0 | 9 | # Please note this file is autogenerated from generate_mozbuild.py, so do not modify it directly |
michael@0 | 10 | |
michael@0 | 11 | """ |
michael@0 | 12 | |
michael@0 | 13 | footer = """ |
michael@0 | 14 | |
michael@0 | 15 | # left out of UNIFIED_SOURCES for now; that's not C++ anyway, nothing else to unify it with |
michael@0 | 16 | if not CONFIG['INTEL_ARCHITECTURE'] and CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC']: |
michael@0 | 17 | SOURCES += [ |
michael@0 | 18 | 'trunk/src/opts/memset.arm.S', |
michael@0 | 19 | ] |
michael@0 | 20 | if CONFIG['BUILD_ARM_NEON']: |
michael@0 | 21 | SOURCES += [ |
michael@0 | 22 | 'trunk/src/opts/memset16_neon.S', |
michael@0 | 23 | 'trunk/src/opts/memset32_neon.S', |
michael@0 | 24 | ] |
michael@0 | 25 | |
michael@0 | 26 | MSVC_ENABLE_PGO = True |
michael@0 | 27 | |
michael@0 | 28 | FINAL_LIBRARY = 'gkmedias' |
michael@0 | 29 | LOCAL_INCLUDES += [ |
michael@0 | 30 | 'trunk/include/config', |
michael@0 | 31 | 'trunk/include/core', |
michael@0 | 32 | 'trunk/include/effects', |
michael@0 | 33 | 'trunk/include/gpu', |
michael@0 | 34 | 'trunk/include/images', |
michael@0 | 35 | 'trunk/include/lazy', |
michael@0 | 36 | 'trunk/include/pathops', |
michael@0 | 37 | 'trunk/include/pipe', |
michael@0 | 38 | 'trunk/include/ports', |
michael@0 | 39 | 'trunk/include/utils', |
michael@0 | 40 | 'trunk/include/utils/mac', |
michael@0 | 41 | 'trunk/include/utils/win', |
michael@0 | 42 | 'trunk/include/views', |
michael@0 | 43 | 'trunk/src/core', |
michael@0 | 44 | 'trunk/src/gpu', |
michael@0 | 45 | 'trunk/src/gpu/effects', |
michael@0 | 46 | 'trunk/src/gpu/gl', |
michael@0 | 47 | 'trunk/src/image', |
michael@0 | 48 | 'trunk/src/lazy', |
michael@0 | 49 | 'trunk/src/opts', |
michael@0 | 50 | 'trunk/src/sfnt', |
michael@0 | 51 | 'trunk/src/utils', |
michael@0 | 52 | 'trunk/src/utils/android', |
michael@0 | 53 | 'trunk/src/utils/mac', |
michael@0 | 54 | 'trunk/src/utils/win', |
michael@0 | 55 | ] |
michael@0 | 56 | |
michael@0 | 57 | DEFINES['SK_A32_SHIFT'] = 24 |
michael@0 | 58 | DEFINES['SK_R32_SHIFT'] = 16 |
michael@0 | 59 | DEFINES['SK_G32_SHIFT'] = 8 |
michael@0 | 60 | DEFINES['SK_B32_SHIFT'] = 0 |
michael@0 | 61 | |
michael@0 | 62 | if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3', 'qt', 'gonk', 'cocoa'): |
michael@0 | 63 | DEFINES['SK_USE_POSIX_THREADS'] = 1 |
michael@0 | 64 | |
michael@0 | 65 | if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['HAVE_TOOLCHAIN_SUPPORT_MSSSE3']: |
michael@0 | 66 | DEFINES['SK_BUILD_SSSE3'] = 1 |
michael@0 | 67 | |
michael@0 | 68 | if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'): |
michael@0 | 69 | DEFINES['SK_FONTHOST_CAIRO_STANDALONE'] = 0 |
michael@0 | 70 | |
michael@0 | 71 | if (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android') or \ |
michael@0 | 72 | (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa') or \ |
michael@0 | 73 | (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk') or \ |
michael@0 | 74 | (CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt') or \ |
michael@0 | 75 | CONFIG['MOZ_WIDGET_GTK']: |
michael@0 | 76 | DEFINES['SK_FONTHOST_DOES_NOT_USE_FONTMGR'] = 1 |
michael@0 | 77 | |
michael@0 | 78 | if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': |
michael@0 | 79 | DEFINES['SKIA_DLL'] = 1 |
michael@0 | 80 | DEFINES['GR_DLL'] = 1 |
michael@0 | 81 | |
michael@0 | 82 | if CONFIG['INTEL_ARCHITECTURE'] and CONFIG['GNU_CC']: |
michael@0 | 83 | SOURCES['trunk/src/opts/SkBitmapFilter_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 84 | SOURCES['trunk/src/opts/SkBitmapProcState_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 85 | SOURCES['trunk/src/opts/SkBitmapProcState_opts_SSSE3.cpp'].flags += ['-mssse3'] |
michael@0 | 86 | SOURCES['trunk/src/opts/SkBlitRect_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 87 | SOURCES['trunk/src/opts/SkBlitRow_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 88 | SOURCES['trunk/src/opts/SkBlurImage_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 89 | SOURCES['trunk/src/opts/SkMorphology_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 90 | SOURCES['trunk/src/opts/SkUtils_opts_SSE2.cpp'].flags += CONFIG['SSE2_FLAGS'] |
michael@0 | 91 | elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC'] and CONFIG['BUILD_ARM_NEON']: |
michael@0 | 92 | DEFINES['__ARM_HAVE_OPTIONAL_NEON_SUPPORT'] = 1 |
michael@0 | 93 | DEFINES['USE_ANDROID_NDK_CPU_FEATURES'] = 0 |
michael@0 | 94 | |
michael@0 | 95 | DEFINES['SKIA_IMPLEMENTATION'] = 1 |
michael@0 | 96 | DEFINES['GR_IMPLEMENTATION'] = 1 |
michael@0 | 97 | |
michael@0 | 98 | if CONFIG['GNU_CXX']: |
michael@0 | 99 | CXXFLAGS += [ |
michael@0 | 100 | '-Wno-overloaded-virtual', |
michael@0 | 101 | '-Wno-unused-function', |
michael@0 | 102 | ] |
michael@0 | 103 | if not CONFIG['CLANG_CXX']: |
michael@0 | 104 | CXXFLAGS += ['-Wno-logical-op'] |
michael@0 | 105 | """ |
michael@0 | 106 | |
michael@0 | 107 | import json |
michael@0 | 108 | |
michael@0 | 109 | platforms = ['linux', 'mac', 'android', 'win'] |
michael@0 | 110 | |
michael@0 | 111 | custom_includes = { |
michael@0 | 112 | 'trunk/src/ports/SkAtomics_android.h': True, |
michael@0 | 113 | 'trunk/src/ports/SkAtomics_sync.h': True, |
michael@0 | 114 | 'trunk/src/ports/SkAtomics_win.h': True, |
michael@0 | 115 | 'trunk/src/ports/SkMutex_pthread.h': True, |
michael@0 | 116 | 'trunk/src/ports/SkMutex_win.h': True |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | def generate_includes(): |
michael@0 | 120 | includes = {} |
michael@0 | 121 | for root, dirs, files in os.walk('trunk/include'): |
michael@0 | 122 | for name in files: |
michael@0 | 123 | if name.endswith('.h'): |
michael@0 | 124 | includes[os.path.join(root, name)] = True |
michael@0 | 125 | |
michael@0 | 126 | return dict(includes.items() + custom_includes.items()) |
michael@0 | 127 | |
michael@0 | 128 | def generate_opt_sources(): |
michael@0 | 129 | opt_sources = {'opts': {''}} |
michael@0 | 130 | for root, dirs, files in os.walk('trunk/src/opts'): |
michael@0 | 131 | for name in files: |
michael@0 | 132 | if name.endswith('.cpp'): |
michael@0 | 133 | opt_sources['opts'].add(os.path.join(root, name)) |
michael@0 | 134 | |
michael@0 | 135 | return opt_sources |
michael@0 | 136 | |
michael@0 | 137 | def generate_platform_sources(): |
michael@0 | 138 | sources = {} |
michael@0 | 139 | |
michael@0 | 140 | for plat in platforms: |
michael@0 | 141 | if os.system("cd trunk && GYP_GENERATORS=dump_mozbuild ./gyp_skia -D OS=%s gyp/skia_lib.gyp" % plat) != 0: |
michael@0 | 142 | print 'Failed to generate sources for ' + plat |
michael@0 | 143 | continue |
michael@0 | 144 | |
michael@0 | 145 | |
michael@0 | 146 | f = open('trunk/sources.json'); |
michael@0 | 147 | sources[plat] = set(json.load(f)); |
michael@0 | 148 | f.close() |
michael@0 | 149 | |
michael@0 | 150 | return dict(sources.items() + generate_opt_sources().items()) |
michael@0 | 151 | |
michael@0 | 152 | |
michael@0 | 153 | def generate_separated_sources(platform_sources): |
michael@0 | 154 | blacklist = [ |
michael@0 | 155 | 'ChromeUtils', |
michael@0 | 156 | 'SkImageDecoder_', |
michael@0 | 157 | '_gif', |
michael@0 | 158 | 'SkFontConfigParser_android', |
michael@0 | 159 | 'SkJpeg', |
michael@0 | 160 | 'SkXML', |
michael@0 | 161 | 'SkCity', |
michael@0 | 162 | 'GrGLCreateNativeInterface', |
michael@0 | 163 | 'fontconfig', |
michael@0 | 164 | 'SkThreadUtils_pthread_', |
michael@0 | 165 | 'SkImage_Codec', |
michael@0 | 166 | 'SkBitmapChecksummer', |
michael@0 | 167 | 'SkNativeGLContext', |
michael@0 | 168 | 'SkFontConfig', |
michael@0 | 169 | 'SkFontHost_win_dw', |
michael@0 | 170 | 'SkForceLinking', |
michael@0 | 171 | 'SkMovie', |
michael@0 | 172 | 'SkImageDecoder', |
michael@0 | 173 | 'SkImageEncoder', |
michael@0 | 174 | 'SkBitmapHasher', |
michael@0 | 175 | 'SkWGL', |
michael@0 | 176 | 'SkImages', |
michael@0 | 177 | 'SkDiscardableMemory_ashmem', |
michael@0 | 178 | 'SkMemory_malloc' |
michael@0 | 179 | ] |
michael@0 | 180 | |
michael@0 | 181 | def isblacklisted(value): |
michael@0 | 182 | for item in blacklist: |
michael@0 | 183 | if value.find(item) >= 0: |
michael@0 | 184 | return True |
michael@0 | 185 | |
michael@0 | 186 | return False |
michael@0 | 187 | |
michael@0 | 188 | separated = { |
michael@0 | 189 | 'common': { |
michael@0 | 190 | #'trunk/src/effects/gradients/SkGradientTileProc.cpp', |
michael@0 | 191 | 'trunk/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', |
michael@0 | 192 | 'trunk/src/ports/SkDiscardableMemory_none.cpp', |
michael@0 | 193 | 'trunk/src/ports/SkImageDecoder_empty.cpp', |
michael@0 | 194 | 'trunk/src/ports/SkMemory_mozalloc.cpp', |
michael@0 | 195 | # 'trunk/src/images/SkImages.cpp', |
michael@0 | 196 | # 'trunk/src/images/SkImageRef.cpp', |
michael@0 | 197 | # 'trunk/src/images/SkImageRef_GlobalPool.cpp', |
michael@0 | 198 | # 'trunk/src/images/SkImageRefPool.cpp', |
michael@0 | 199 | # 'trunk/src/images/SkImageDecoder.cpp', |
michael@0 | 200 | # 'trunk/src/images/SkImageDecoder_Factory.cpp', |
michael@0 | 201 | }, |
michael@0 | 202 | 'android': { |
michael@0 | 203 | # 'trunk/src/ports/SkDebug_android.cpp', |
michael@0 | 204 | 'trunk/src/ports/SkFontHost_android_old.cpp', |
michael@0 | 205 | 'trunk/src/ports/SkFontHost_cairo.cpp', |
michael@0 | 206 | # 'trunk/src/ports/SkFontHost_FreeType.cpp', |
michael@0 | 207 | # 'trunk/src/ports/SkFontHost_FreeType_common.cpp', |
michael@0 | 208 | # 'trunk/src/ports/SkThread_pthread.cpp', |
michael@0 | 209 | # 'trunk/src/ports/SkPurgeableMemoryBlock_android.cpp', |
michael@0 | 210 | # 'trunk/src/ports/SkTime_Unix.cpp', |
michael@0 | 211 | # 'trunk/src/utils/SkThreadUtils_pthread.cpp', |
michael@0 | 212 | # 'trunk/src/images/SkImageRef_ashmem.cpp', |
michael@0 | 213 | # 'trunk/src/utils/android/ashmem.cpp', |
michael@0 | 214 | }, |
michael@0 | 215 | 'linux': { |
michael@0 | 216 | 'trunk/src/ports/SkFontHost_cairo.cpp', |
michael@0 | 217 | }, |
michael@0 | 218 | 'intel': { |
michael@0 | 219 | 'trunk/src/opts/SkXfermode_opts_none.cpp', |
michael@0 | 220 | }, |
michael@0 | 221 | 'arm': { |
michael@0 | 222 | 'trunk/src/opts/SkUtils_opts_arm.cpp', |
michael@0 | 223 | 'trunk/src/core/SkUtilsArm.cpp', |
michael@0 | 224 | }, |
michael@0 | 225 | 'neon': { |
michael@0 | 226 | 'trunk/src/opts/SkBitmapProcState_arm_neon.cpp', |
michael@0 | 227 | }, |
michael@0 | 228 | 'none': { |
michael@0 | 229 | 'trunk/src/opts/SkUtils_opts_none.cpp', |
michael@0 | 230 | } |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | for plat in platform_sources.keys(): |
michael@0 | 234 | if not separated.has_key(plat): |
michael@0 | 235 | separated[plat] = set() |
michael@0 | 236 | |
michael@0 | 237 | for value in platform_sources[plat]: |
michael@0 | 238 | if isblacklisted(value): |
michael@0 | 239 | continue |
michael@0 | 240 | |
michael@0 | 241 | if value.find('_SSE') > 0 or value.find('_SSSE') > 0: #lol |
michael@0 | 242 | separated['intel'].add(value) |
michael@0 | 243 | continue |
michael@0 | 244 | |
michael@0 | 245 | if value.find('_neon') > 0: |
michael@0 | 246 | separated['neon'].add(value) |
michael@0 | 247 | continue |
michael@0 | 248 | |
michael@0 | 249 | if value.find('_arm') > 0: |
michael@0 | 250 | separated['arm'].add(value) |
michael@0 | 251 | continue |
michael@0 | 252 | |
michael@0 | 253 | if value.find('_none') > 0: |
michael@0 | 254 | separated['none'].add(value) |
michael@0 | 255 | continue |
michael@0 | 256 | |
michael@0 | 257 | found = True |
michael@0 | 258 | for other in platforms: |
michael@0 | 259 | if other == plat or not platform_sources.has_key(other): |
michael@0 | 260 | continue |
michael@0 | 261 | |
michael@0 | 262 | if not value in platform_sources[other]: |
michael@0 | 263 | found = False |
michael@0 | 264 | break; |
michael@0 | 265 | |
michael@0 | 266 | if found: |
michael@0 | 267 | separated['common'].add(value) |
michael@0 | 268 | else: |
michael@0 | 269 | separated[plat].add(value) |
michael@0 | 270 | |
michael@0 | 271 | return separated |
michael@0 | 272 | |
michael@0 | 273 | def uniq(seq): |
michael@0 | 274 | seen = set() |
michael@0 | 275 | seen_add = seen.add |
michael@0 | 276 | return [ x for x in seq if x not in seen and not seen_add(x)] |
michael@0 | 277 | |
michael@0 | 278 | def write_cflags(f, values, subsearch, cflag, indent): |
michael@0 | 279 | def write_indent(indent): |
michael@0 | 280 | for _ in range(indent): |
michael@0 | 281 | f.write(' ') |
michael@0 | 282 | |
michael@0 | 283 | val_list = uniq(sorted(map(lambda val: val.replace('../', 'trunk/'), values), key=lambda x: x.lower())) |
michael@0 | 284 | |
michael@0 | 285 | if len(val_list) == 0: |
michael@0 | 286 | return |
michael@0 | 287 | |
michael@0 | 288 | for val in val_list: |
michael@0 | 289 | if val.find(subsearch) > 0: |
michael@0 | 290 | write_indent(indent) |
michael@0 | 291 | f.write("SOURCES[\'" + val + "\'].flags += [\'" + cflag + "\']\n") |
michael@0 | 292 | |
michael@0 | 293 | |
michael@0 | 294 | def write_list(f, name, values, indent): |
michael@0 | 295 | def write_indent(indent): |
michael@0 | 296 | for _ in range(indent): |
michael@0 | 297 | f.write(' ') |
michael@0 | 298 | |
michael@0 | 299 | val_list = uniq(sorted(map(lambda val: val.replace('../', 'trunk/'), values), key=lambda x: x.lower())) |
michael@0 | 300 | |
michael@0 | 301 | if len(val_list) == 0: |
michael@0 | 302 | return |
michael@0 | 303 | |
michael@0 | 304 | write_indent(indent) |
michael@0 | 305 | f.write(name + ' += [\n') |
michael@0 | 306 | for val in val_list: |
michael@0 | 307 | write_indent(indent + 4) |
michael@0 | 308 | f.write('\'' + val + '\',\n') |
michael@0 | 309 | |
michael@0 | 310 | write_indent(indent) |
michael@0 | 311 | f.write(']\n') |
michael@0 | 312 | |
michael@0 | 313 | def write_mozbuild(includes, sources): |
michael@0 | 314 | filename = 'moz.build' |
michael@0 | 315 | f = open(filename, 'w') |
michael@0 | 316 | |
michael@0 | 317 | f.write(header) |
michael@0 | 318 | |
michael@0 | 319 | write_list(f, 'EXPORTS.skia', includes, 0) |
michael@0 | 320 | |
michael@0 | 321 | write_list(f, 'SOURCES', sources['common'], 0) |
michael@0 | 322 | |
michael@0 | 323 | f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gonk'):\n") |
michael@0 | 324 | write_list(f, 'SOURCES', sources['android'], 4) |
michael@0 | 325 | |
michael@0 | 326 | f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':\n") |
michael@0 | 327 | write_list(f, 'SOURCES', sources['mac'], 4) |
michael@0 | 328 | |
michael@0 | 329 | f.write("if CONFIG['MOZ_WIDGET_GTK']:\n") |
michael@0 | 330 | write_list(f, 'SOURCES', sources['linux'], 4) |
michael@0 | 331 | |
michael@0 | 332 | f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':\n") |
michael@0 | 333 | write_list(f, 'SOURCES', sources['linux'], 4) |
michael@0 | 334 | |
michael@0 | 335 | f.write("if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':\n") |
michael@0 | 336 | write_list(f, 'SOURCES', sources['win'], 4) |
michael@0 | 337 | |
michael@0 | 338 | f.write("\n\n") |
michael@0 | 339 | f.write("if CONFIG['INTEL_ARCHITECTURE']:\n") |
michael@0 | 340 | write_list(f, 'SOURCES', sources['intel'], 4) |
michael@0 | 341 | |
michael@0 | 342 | f.write("elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC']:\n") |
michael@0 | 343 | write_list(f, 'SOURCES', sources['arm'], 4) |
michael@0 | 344 | |
michael@0 | 345 | f.write(" if CONFIG['BUILD_ARM_NEON']:\n") |
michael@0 | 346 | write_list(f, 'SOURCES', sources['neon'], 8) |
michael@0 | 347 | write_cflags(f, sources['neon'], 'neon', '-mfpu=neon', 8) |
michael@0 | 348 | |
michael@0 | 349 | f.write("else:\n") |
michael@0 | 350 | write_list(f, 'SOURCES', sources['none'], 4) |
michael@0 | 351 | |
michael@0 | 352 | f.write(footer) |
michael@0 | 353 | |
michael@0 | 354 | f.close() |
michael@0 | 355 | |
michael@0 | 356 | print 'Wrote ' + filename |
michael@0 | 357 | |
michael@0 | 358 | def main(): |
michael@0 | 359 | includes = generate_includes() |
michael@0 | 360 | platform_sources = generate_platform_sources() |
michael@0 | 361 | separated_sources = generate_separated_sources(platform_sources) |
michael@0 | 362 | write_mozbuild(includes, separated_sources) |
michael@0 | 363 | |
michael@0 | 364 | |
michael@0 | 365 | if __name__ == '__main__': |
michael@0 | 366 | main() |