midl.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. # Issue 1185 ultrix gmail com
  3. """
  4. Microsoft Interface Definition Language support. Given ComObject.idl, this tool
  5. will generate ComObject.tlb ComObject_i.h ComObject_i.c ComObject_p.c and dlldata.c
  6. To declare targets using midl::
  7. def configure(conf):
  8. conf.load('msvc')
  9. conf.load('midl')
  10. def build(bld):
  11. bld(
  12. features='c cshlib',
  13. # Note: ComObject_i.c is generated from ComObject.idl
  14. source = 'main.c ComObject.idl ComObject_i.c',
  15. target = 'ComObject.dll')
  16. """
  17. from waflib import Task, Utils
  18. from waflib.TaskGen import feature, before_method
  19. import os
  20. def configure(conf):
  21. conf.find_program(['midl'], var='MIDL')
  22. conf.env.MIDLFLAGS = [
  23. '/nologo',
  24. '/D',
  25. '_DEBUG',
  26. '/W1',
  27. '/char',
  28. 'signed',
  29. '/Oicf',
  30. ]
  31. @feature('c', 'cxx')
  32. @before_method('process_source')
  33. def idl_file(self):
  34. # Do this before process_source so that the generated header can be resolved
  35. # when scanning source dependencies.
  36. idl_nodes = []
  37. src_nodes = []
  38. for node in Utils.to_list(self.source):
  39. if str(node).endswith('.idl'):
  40. idl_nodes.append(node)
  41. else:
  42. src_nodes.append(node)
  43. for node in self.to_nodes(idl_nodes):
  44. t = node.change_ext('.tlb')
  45. h = node.change_ext('_i.h')
  46. c = node.change_ext('_i.c')
  47. p = node.change_ext('_p.c')
  48. d = node.parent.find_or_declare('dlldata.c')
  49. self.create_task('midl', node, [t, h, c, p, d])
  50. self.source = src_nodes
  51. class midl(Task.Task):
  52. """
  53. Compile idl files
  54. """
  55. color = 'YELLOW'
  56. run_str = '${MIDL} ${MIDLFLAGS} ${CPPPATH_ST:INCLUDES} /tlb ${TGT[0].bldpath()} /header ${TGT[1].bldpath()} /iid ${TGT[2].bldpath()} /proxy ${TGT[3].bldpath()} /dlldata ${TGT[4].bldpath()} ${SRC}'
  57. before = ['winrc']