moz.configure 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. include('build/moz.configure/init.configure')
  6. # Note:
  7. # - Gecko-specific options and rules should go in toolkit/moz.configure.
  8. # - Firefox-specific options and rules should go in browser/moz.configure.
  9. # - Fennec-specific options and rules should go in
  10. # mobile/android/moz.configure.
  11. # - Spidermonkey-specific options and rules should go in js/moz.configure.
  12. # - etc.
  13. option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',
  14. help='Download and use prebuilt binary artifacts.')
  15. @depends('--enable-artifact-builds')
  16. def artifact_builds(value):
  17. if value:
  18. return True
  19. set_config('MOZ_ARTIFACT_BUILDS', artifact_builds)
  20. imply_option('--enable-artifact-build-symbols',
  21. depends(artifact_builds)(lambda v: False if v is None else None),
  22. reason='--disable-artifact-builds')
  23. option('--enable-artifact-build-symbols',
  24. help='Download symbols when artifact builds are enabled.')
  25. set_config('MOZ_ARTIFACT_BUILD_SYMBOLS',
  26. depends_if('--enable-artifact-build-symbols')(lambda _: True))
  27. @depends('--enable-artifact-builds')
  28. def imply_disable_compile_environment(value):
  29. if value:
  30. return False
  31. imply_option('--enable-compile-environment', imply_disable_compile_environment)
  32. option('--disable-compile-environment',
  33. help='Disable compiler/library checks')
  34. @depends('--disable-compile-environment')
  35. def compile_environment(compile_env):
  36. if compile_env:
  37. return True
  38. set_config('COMPILE_ENVIRONMENT', compile_environment)
  39. add_old_configure_assignment('COMPILE_ENVIRONMENT', compile_environment)
  40. js_option('--enable-debug',
  41. nargs='?',
  42. help='Enable building with developer debug info '
  43. '(using the given compiler flags).')
  44. add_old_configure_assignment('MOZ_DEBUG',
  45. depends('--enable-debug')(lambda v: bool(v)))
  46. include('build/moz.configure/pkg.configure')
  47. # Make this assignment here rather than in pkg.configure to avoid
  48. # requiring this file in unit tests.
  49. add_old_configure_assignment('PKG_CONFIG', pkg_config)
  50. include('build/moz.configure/toolchain.configure',
  51. when='--enable-compile-environment')
  52. include('build/moz.configure/memory.configure',
  53. when='--enable-compile-environment')
  54. include('build/moz.configure/headers.configure',
  55. when='--enable-compile-environment')
  56. include('build/moz.configure/warnings.configure',
  57. when='--enable-compile-environment')
  58. include(include_project_configure)
  59. @depends('--help')
  60. @imports(_from='mozbuild.backend', _import='backends')
  61. def build_backends_choices(_):
  62. return tuple(backends)
  63. @deprecated_option('--enable-build-backend', nargs='+',
  64. choices=build_backends_choices)
  65. def build_backend(backends):
  66. if backends:
  67. return tuple('+%s' % b for b in backends)
  68. imply_option('--build-backends', build_backend)
  69. @depends('--enable-artifact-builds', '--disable-compile-environment', '--help')
  70. @imports('sys')
  71. def build_backend_defaults(artifact_builds, compile_environment, _):
  72. if artifact_builds:
  73. all_backends = ['FasterMake+RecursiveMake']
  74. else:
  75. all_backends = ['RecursiveMake', 'FasterMake']
  76. # Normally, we'd use target.os == 'WINNT', but a dependency on target
  77. # would require target to depend on --help, as well as host and shell,
  78. # and this is not a can of worms we can open at the moment.
  79. if sys.platform == 'win32' and compile_environment:
  80. all_backends.append('VisualStudio')
  81. return tuple(all_backends)
  82. option('--build-backends', nargs='+', default=build_backend_defaults,
  83. choices=build_backends_choices, help='Build backends to generate')
  84. @depends('--build-backends')
  85. def build_backends(backends):
  86. return backends
  87. set_config('BUILD_BACKENDS', build_backends)
  88. # Awk detection
  89. # ==============================================================
  90. awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
  91. # Until the AWK variable is not necessary in old-configure
  92. @depends(awk)
  93. def awk_for_old_configure(value):
  94. return value
  95. add_old_configure_assignment('AWK', awk_for_old_configure)
  96. # Perl detection
  97. # ==============================================================
  98. perl = check_prog('PERL', ('perl5', 'perl'))
  99. # Until the PERL variable is not necessary in old-configure
  100. @depends(perl)
  101. def perl_for_old_configure(value):
  102. return value
  103. add_old_configure_assignment('PERL', perl_for_old_configure)
  104. @template
  105. def perl_version_check(min_version):
  106. @depends(perl)
  107. @checking('for minimum required perl version >= %s' % min_version)
  108. def get_perl_version(perl):
  109. return Version(check_cmd_output(
  110. perl, '-e', 'print $]',
  111. onerror=lambda: die('Failed to get perl version.')
  112. ))
  113. @depends(get_perl_version)
  114. def check_perl_version(version):
  115. if version < min_version:
  116. die('Perl %s or higher is required.', min_version)
  117. @depends(perl)
  118. @checking('for full perl installation')
  119. @imports('subprocess')
  120. def has_full_perl_installation(perl):
  121. ret = subprocess.call(
  122. [perl, '-e', 'use Config; exit(!-d $Config{archlib})'])
  123. return ret == 0
  124. @depends(has_full_perl_installation)
  125. def require_full_perl_installation(has_full_perl_installation):
  126. if not has_full_perl_installation:
  127. die('Cannot find Config.pm or $Config{archlib}. '
  128. 'A full perl installation is required.')
  129. perl_version_check('5.006')
  130. # GNU make detection
  131. # ==============================================================
  132. option(env='MAKE', nargs=1, help='Path to GNU make')
  133. @depends('MAKE', host)
  134. def possible_makes(make, host):
  135. candidates = []
  136. if host.kernel == 'WINNT':
  137. candidates.append('mingw32-make')
  138. if make:
  139. candidates.append(make[0])
  140. if host.kernel == 'WINNT':
  141. candidates.extend(('make', 'gmake'))
  142. else:
  143. candidates.extend(('gmake', 'make'))
  144. return candidates
  145. check_prog('GMAKE', possible_makes)
  146. # tup detection
  147. # ==============================================================
  148. @depends(build_backends)
  149. def tup_progs(build_backends):
  150. for backend in build_backends:
  151. if 'Tup' in backend:
  152. return ['tup']
  153. return None
  154. tup = check_prog('TUP', tup_progs)
  155. # Miscellaneous programs
  156. # ==============================================================
  157. check_prog('DOXYGEN', ('doxygen',), allow_missing=True)
  158. check_prog('XARGS', ('xargs',))
  159. @depends(target)
  160. def extra_programs(target):
  161. if target.kernel == 'Darwin':
  162. return namespace(
  163. DSYMUTIL=('dsymutil', 'llvm-dsymutil'),
  164. GENISOIMAGE=('genisoimage',),
  165. )
  166. if target.os == 'GNU' and target.kernel == 'Linux':
  167. return namespace(RPMBUILD=('rpmbuild',))
  168. check_prog('DSYMUTIL', delayed_getattr(extra_programs, 'DSYMUTIL'),
  169. allow_missing=True)
  170. check_prog('GENISOIMAGE', delayed_getattr(extra_programs, 'GENISOIMAGE'),
  171. allow_missing=True)
  172. check_prog('RPMBUILD', delayed_getattr(extra_programs, 'RPMBUILD'),
  173. allow_missing=True)
  174. option('--enable-system-hunspell',
  175. help="Use system hunspell (located with pkgconfig)")
  176. @depends('--enable-system-hunspell', compile_environment)
  177. def check_for_hunspell(value, compile_env):
  178. return value and compile_env
  179. system_hunspell = pkg_check_modules('MOZ_HUNSPELL', 'hunspell',
  180. when=check_for_hunspell)
  181. set_config('MOZ_SYSTEM_HUNSPELL', depends_if(system_hunspell)(lambda _: True))
  182. @depends(target)
  183. @imports('os')
  184. def makensis_progs(target):
  185. if target.kernel != 'WINNT':
  186. return
  187. candidates = [
  188. 'makensis-3.01.exe',
  189. 'makensis-3.0b3.exe',
  190. 'makensis-3.0b1.exe',
  191. 'makensis.exe',
  192. 'makensis',
  193. ]
  194. # Look for nsis installed by msys environment. But only the 32-bit version.
  195. # We use an absolute path and insert as the first entry so it is preferred
  196. # over a 64-bit exe that may be in PATH.
  197. if 'MSYSTEM_PREFIX' in os.environ:
  198. prefix = os.path.dirname(os.environ['MSYSTEM_PREFIX'])
  199. candidates.insert(0, os.path.join(prefix, 'mingw32', 'bin', 'makensis.exe'))
  200. return tuple(candidates)
  201. nsis = check_prog('MAKENSISU', makensis_progs)
  202. # Make sure the version of makensis is up to date.
  203. @depends_if(nsis)
  204. @checking('for NSIS version')
  205. @imports('re')
  206. def nsis_version(nsis):
  207. nsis_min_version = '3.0b1'
  208. out = check_cmd_output(nsis, '-version',
  209. onerror=lambda: die('Failed to get nsis version.'))
  210. m = re.search(r'(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?', out)
  211. if not m:
  212. raise FatalCheckError('Unknown version of makensis')
  213. ver = Version(m.group(0))
  214. # Versions comparisons don't quite work well with beta versions, so ensure
  215. # it works for the non-beta version.
  216. if ver < nsis_min_version and (ver >= '3.0a' or ver < '3'):
  217. raise FatalCheckError('To build the installer you must have NSIS'
  218. ' version %s or greater in your path'
  219. % nsis_min_version)
  220. return ver
  221. # And that makensis is 32-bit.
  222. @depends_if(nsis)
  223. @checking('for 32-bit NSIS')
  224. def nsis_binary_type(nsis):
  225. bin_type = windows_binary_type(nsis)
  226. if bin_type != 'win32':
  227. raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
  228. return 'yes'
  229. # Fallthrough to autoconf-based configure
  230. include('build/moz.configure/old.configure')
  231. # Please do not add anything after the include of old.configure.