gecko_templates.mozbuild 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. @template
  6. def GeckoBinary(linkage='dependent', msvcrt='dynamic', mozglue=None):
  7. '''Template for Gecko-related binaries.
  8. This template is meant to be used in other templates.
  9. `linkage` indicates the wanted xpcom linkage type. Valid values are
  10. 'dependent', 'standalone' or None. 'dependent' is the default. It is
  11. used for e.g. XPCOM components and executables with direct dependencies
  12. on libxul. Most executables should use the 'standalone' linkage, which
  13. uses the standalone XPCOM glue to load libxul. None means no XPCOM glue
  14. or libxul linkage at all.
  15. `msvcrt` indicates which Microsoft Visual Studio CRT, for Windows build,
  16. ought to be linked: 'static' or 'dynamic'.
  17. `mozglue` indicates whether to link against the mozglue library, and if
  18. so, what linkage to apply. Valid values are None (mozglue not linked),
  19. 'program' (mozglue linked to an executable program), or 'library' (mozglue
  20. linked to a shared library).
  21. '''
  22. if msvcrt == 'dynamic' or CONFIG['OS_ARCH'] != 'WINNT' or CONFIG['MOZ_ASAN']:
  23. xpcomglue = 'xpcomglue'
  24. elif msvcrt == 'static':
  25. USE_STATIC_LIBS = True
  26. xpcomglue = 'xpcomglue_staticruntime'
  27. if not CONFIG['GNU_CC']:
  28. mozglue = None
  29. if linkage == 'dependent':
  30. USE_LIBS += [
  31. 'mozalloc_staticruntime',
  32. ]
  33. else:
  34. error('msvcrt must be "dynamic" or "static"')
  35. if linkage == 'dependent':
  36. USE_LIBS += [
  37. 'nspr',
  38. '%s_s' % xpcomglue,
  39. 'xul',
  40. ]
  41. elif linkage == 'standalone':
  42. DEFINES['XPCOM_GLUE'] = True
  43. USE_LIBS += [
  44. xpcomglue,
  45. ]
  46. elif linkage != None:
  47. error('`linkage` must be "dependent", "standalone" or None')
  48. if mozglue:
  49. LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
  50. if mozglue == 'program':
  51. USE_LIBS += ['mozglue']
  52. DEFINES['MOZ_HAS_MOZGLUE'] = True
  53. if CONFIG['MOZ_GLUE_IN_PROGRAM']:
  54. if CONFIG['GNU_CC']:
  55. LDFLAGS += ['-rdynamic']
  56. if CONFIG['MOZ_MEMORY']:
  57. USE_LIBS += ['memory']
  58. if CONFIG['OS_ARCH'] == 'FreeBSD':
  59. # Make sure this function is linked in, so that it is
  60. # executed at executable load (it has the 'constructor'
  61. # flag).
  62. LDFLAGS += ['-u', 'jemalloc_FreeBSD_init']
  63. elif mozglue == 'library':
  64. LIBRARY_DEFINES['MOZ_HAS_MOZGLUE'] = True
  65. if not CONFIG['MOZ_GLUE_IN_PROGRAM']:
  66. USE_LIBS += ['mozglue']
  67. else:
  68. error('`mozglue` must be "program" or "library"')
  69. if not CONFIG['JS_STANDALONE']:
  70. USE_LIBS += [
  71. 'fallible',
  72. ]
  73. @template
  74. def GeckoProgram(name, linkage='standalone', **kwargs):
  75. '''Template for program executables related to Gecko.
  76. `name` identifies the executable base name.
  77. See the documentation for `GeckoBinary` for other possible arguments,
  78. with the notable difference that the default for `linkage` is 'standalone'.
  79. '''
  80. Program(name)
  81. kwargs.setdefault('mozglue', 'program')
  82. GeckoBinary(linkage=linkage, **kwargs)
  83. @template
  84. def GeckoSimplePrograms(names, **kwargs):
  85. '''Template for simple program executables related to Gecko.
  86. `names` identifies the executable base names for each executable.
  87. See the documentation for `GeckoBinary` for other possible arguments.
  88. '''
  89. SimplePrograms(names)
  90. kwargs.setdefault('mozglue', 'program')
  91. GeckoBinary(**kwargs)
  92. @template
  93. def GeckoCppUnitTests(names, **kwargs):
  94. '''Template for C++ unit tests related to Gecko.
  95. `names` identifies the executable base names for each executable.
  96. See the documentation for `GeckoBinary` for other possible arguments.
  97. '''
  98. CppUnitTests(names)
  99. kwargs.setdefault('mozglue', 'program')
  100. GeckoBinary(**kwargs)
  101. @template
  102. def GeckoSharedLibrary(name, **kwargs):
  103. '''Template for shared libraries related to Gecko.
  104. `name` identifies the library base name.
  105. See the documentation for `GeckoBinary` for other possible arguments.
  106. '''
  107. SharedLibrary(name)
  108. kwargs.setdefault('mozglue', 'library')
  109. GeckoBinary(**kwargs)
  110. @template
  111. def GeckoFramework(name, **kwargs):
  112. '''Template for OSX frameworks related to Gecko.
  113. `name` identifies the library base name.
  114. See the documentation for `GeckoBinary` for other possible arguments.
  115. '''
  116. Framework(name)
  117. kwargs.setdefault('mozglue', 'library')
  118. GeckoBinary(**kwargs)
  119. @template
  120. def XPCOMBinaryComponent(name):
  121. '''Template defining an XPCOM binary component for Gecko.
  122. `name` is the name of the component.
  123. '''
  124. GeckoSharedLibrary(name)
  125. IS_COMPONENT = True