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.

129 lines
2.9KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2005-2010 (ita)
  4. "base for all c/c++ programs and libraries"
  5. import os, sys, re
  6. from waflib import Utils, Build
  7. from waflib.Configure import conf
  8. def get_extensions(lst):
  9. """
  10. :param lst: files to process
  11. :list lst: list of string or :py:class:`waflib.Node.Node`
  12. :return: list of file extensions
  13. :rtype: list of string
  14. """
  15. ret = []
  16. for x in Utils.to_list(lst):
  17. try:
  18. if not isinstance(x, str):
  19. x = x.name
  20. ret.append(x[x.rfind('.') + 1:])
  21. except Exception:
  22. pass
  23. return ret
  24. def sniff_features(**kw):
  25. """
  26. Look at the source files and return the features for a task generator (mainly cc and cxx)::
  27. snif_features(source=['foo.c', 'foo.cxx'], type='shlib')
  28. # returns ['cxx', 'c', 'cxxshlib', 'cshlib']
  29. :param source: source files to process
  30. :type source: list of string or :py:class:`waflib.Node.Node`
  31. :param type: object type in *program*, *shlib* or *stlib*
  32. :type type: string
  33. :return: the list of features for a task generator processing the source files
  34. :rtype: list of string
  35. """
  36. exts = get_extensions(kw['source'])
  37. type = kw['_type']
  38. feats = []
  39. # watch the order, cxx will have the precedence
  40. if 'cxx' in exts or 'cpp' in exts or 'c++' in exts or 'cc' in exts or 'C' in exts:
  41. feats.append('cxx')
  42. if 'c' in exts or 'vala' in exts:
  43. feats.append('c')
  44. if 'd' in exts:
  45. feats.append('d')
  46. if 'java' in exts:
  47. feats.append('java')
  48. if 'java' in exts:
  49. return 'java'
  50. if type in ('program', 'shlib', 'stlib'):
  51. for x in feats:
  52. if x in ('cxx', 'd', 'c'):
  53. feats.append(x + type)
  54. return feats
  55. def set_features(kw, _type):
  56. kw['_type'] = _type
  57. kw['features'] = Utils.to_list(kw.get('features', [])) + Utils.to_list(sniff_features(**kw))
  58. @conf
  59. def program(bld, *k, **kw):
  60. """
  61. Alias for creating programs by looking at the file extensions::
  62. def build(bld):
  63. bld.program(source='foo.c', target='app')
  64. # equivalent to:
  65. # bld(features='c cprogram', source='foo.c', target='app')
  66. """
  67. set_features(kw, 'program')
  68. return bld(*k, **kw)
  69. @conf
  70. def shlib(bld, *k, **kw):
  71. """
  72. Alias for creating shared libraries by looking at the file extensions::
  73. def build(bld):
  74. bld.shlib(source='foo.c', target='app')
  75. # equivalent to:
  76. # bld(features='c cshlib', source='foo.c', target='app')
  77. """
  78. set_features(kw, 'shlib')
  79. return bld(*k, **kw)
  80. @conf
  81. def stlib(bld, *k, **kw):
  82. """
  83. Alias for creating static libraries by looking at the file extensions::
  84. def build(bld):
  85. bld.stlib(source='foo.cpp', target='app')
  86. # equivalent to:
  87. # bld(features='cxx cxxstlib', source='foo.cpp', target='app')
  88. """
  89. set_features(kw, 'stlib')
  90. return bld(*k, **kw)
  91. @conf
  92. def objects(bld, *k, **kw):
  93. """
  94. Alias for creating object files by looking at the file extensions::
  95. def build(bld):
  96. bld.objects(source='foo.c', target='app')
  97. # equivalent to:
  98. # bld(features='c', source='foo.c', target='app')
  99. """
  100. set_features(kw, 'objects')
  101. return bld(*k, **kw)