jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.4KB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # Tool to provide dedicated variables for cross-compilation
  4. __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
  5. __copyright__ = "Jérôme Carretero, 2014"
  6. """
  7. This tool allows to use environment variables to define cross-compilation things,
  8. mostly used when you use build variants.
  9. Usage:
  10. - In your build script::
  11. def configure(cfg):
  12. ...
  13. conf.load('c_cross_gnu')
  14. for variant in x_variants:
  15. conf.xcheck_host()
  16. conf.xcheck_host_var('POUET')
  17. ...
  18. ...
  19. - Then::
  20. CHOST=arm-hardfloat-linux-gnueabi waf configure
  21. env arm-hardfloat-linux-gnueabi-CC="clang -..." waf configure
  22. CFLAGS=... CHOST=arm-hardfloat-linux-gnueabi HOST_CFLAGS=-g waf configure
  23. HOST_CC="clang -..." waf configure
  24. """
  25. import os
  26. from waflib import Utils, Configure
  27. try:
  28. from shlex import quote
  29. except ImportError:
  30. from pipes import quote
  31. @Configure.conf
  32. def xcheck_prog(conf, var, tool, cross=False):
  33. value = os.environ.get(var, '')
  34. value = Utils.to_list(value)
  35. if not value:
  36. return
  37. conf.env[var] = value
  38. if cross:
  39. pretty = 'cross-compilation %s' % var
  40. else:
  41. pretty = var
  42. conf.msg('Will use %s' % pretty,
  43. " ".join(quote(x) for x in value))
  44. @Configure.conf
  45. def xcheck_envar(conf, name, wafname=None, cross=False):
  46. wafname = wafname or name
  47. value = os.environ.get(name, None)
  48. value = Utils.to_list(value)
  49. if not value:
  50. return
  51. conf.env[wafname] += value
  52. if cross:
  53. pretty = 'cross-compilation %s' % wafname
  54. else:
  55. pretty = wafname
  56. conf.msg('Will use %s' % pretty,
  57. " ".join(quote(x) for x in value))
  58. @Configure.conf
  59. def xcheck_host_prog(conf, name, tool, wafname=None):
  60. wafname = wafname or name
  61. host = conf.env.CHOST
  62. specific = None
  63. if host:
  64. specific = os.environ.get('%s-%s' % (host[0], name), None)
  65. if specific:
  66. value = Utils.to_list(specific)
  67. conf.env[wafname] += value
  68. conf.msg('Will use cross-compilation %s' % name,
  69. " ".join(quote(x) for x in value))
  70. return
  71. conf.xcheck_prog('HOST_%s' % name, tool, cross=True)
  72. if conf.env[wafname]:
  73. return
  74. value = None
  75. if host:
  76. value = '%s-%s' % (host[0], tool)
  77. if value:
  78. conf.env[wafname] = value
  79. conf.msg('Will use cross-compilation %s' % wafname, value)
  80. @Configure.conf
  81. def xcheck_host_envar(conf, name, wafname=None):
  82. wafname = wafname or name
  83. host = conf.env.CHOST
  84. specific = None
  85. if host:
  86. specific = os.environ.get('%s-%s' % (host[0], name), None)
  87. if specific:
  88. value = Utils.to_list(specific)
  89. conf.env[wafname] += value
  90. conf.msg('Will use cross-compilation %s' % name,
  91. " ".join(quote(x) for x in value))
  92. return
  93. conf.xcheck_envar('HOST_%s' % name, wafname, cross=True)
  94. @Configure.conf
  95. def xcheck_host(conf):
  96. conf.xcheck_envar('CHOST', cross=True)
  97. conf.xcheck_host_prog('CC', 'gcc')
  98. conf.xcheck_host_prog('CXX', 'g++')
  99. conf.xcheck_host_prog('LINK_CC', 'gcc')
  100. conf.xcheck_host_prog('LINK_CXX', 'g++')
  101. conf.xcheck_host_prog('AR', 'ar')
  102. conf.xcheck_host_prog('AS', 'as')
  103. conf.xcheck_host_prog('LD', 'ld')
  104. conf.xcheck_host_envar('CFLAGS')
  105. conf.xcheck_host_envar('CXXFLAGS')
  106. conf.xcheck_host_envar('LDFLAGS', 'LINKFLAGS')
  107. conf.xcheck_host_envar('LIB')
  108. conf.xcheck_host_envar('PKG_CONFIG_PATH')
  109. # TODO find a better solution than this ugliness
  110. if conf.env.PKG_CONFIG_PATH:
  111. conf.find_program('pkg-config', var='PKGCONFIG')
  112. conf.env.PKGCONFIG = [
  113. 'env', 'PKG_CONFIG_PATH=%s' % (conf.env.PKG_CONFIG_PATH[0])
  114. ] + conf.env.PKGCONFIG