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.

115 lines
3.0KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Brant Young, 2007
  4. "Process *.rc* files for C/C++: X{.rc -> [.res|.rc.o]}"
  5. import re, traceback
  6. from waflib import Task, Logs, Utils
  7. from waflib.TaskGen import extension
  8. from waflib.Tools import c_preproc
  9. @extension('.rc')
  10. def rc_file(self, node):
  11. """
  12. Bind the .rc extension to a winrc task
  13. """
  14. obj_ext = '.rc.o'
  15. if self.env['WINRC_TGT_F'] == '/fo':
  16. obj_ext = '.res'
  17. rctask = self.create_task('winrc', node, node.change_ext(obj_ext))
  18. try:
  19. self.compiled_tasks.append(rctask)
  20. except AttributeError:
  21. self.compiled_tasks = [rctask]
  22. re_lines = re.compile(
  23. '(?:^[ \t]*(#|%:)[ \t]*(ifdef|ifndef|if|else|elif|endif|include|import|define|undef|pragma)[ \t]*(.*?)\s*$)|'\
  24. '(?:^\w+[ \t]*(ICON|BITMAP|CURSOR|HTML|FONT|MESSAGETABLE|TYPELIB|REGISTRY|D3DFX)[ \t]*(.*?)\s*$)',
  25. re.IGNORECASE | re.MULTILINE)
  26. class rc_parser(c_preproc.c_parser):
  27. def filter_comments(self, filepath):
  28. code = Utils.readf(filepath)
  29. if c_preproc.use_trigraphs:
  30. for (a, b) in c_preproc.trig_def: code = code.split(a).join(b)
  31. code = c_preproc.re_nl.sub('', code)
  32. code = c_preproc.re_cpp.sub(c_preproc.repl, code)
  33. ret = []
  34. for m in re.finditer(re_lines, code):
  35. if m.group(2):
  36. ret.append((m.group(2), m.group(3)))
  37. else:
  38. ret.append(('include', m.group(5)))
  39. return ret
  40. def addlines(self, node):
  41. self.currentnode_stack.append(node.parent)
  42. filepath = node.abspath()
  43. self.count_files += 1
  44. if self.count_files > c_preproc.recursion_limit:
  45. raise c_preproc.PreprocError("recursion limit exceeded")
  46. pc = self.parse_cache
  47. Logs.debug('preproc: reading file %r', filepath)
  48. try:
  49. lns = pc[filepath]
  50. except KeyError:
  51. pass
  52. else:
  53. self.lines.extend(lns)
  54. return
  55. try:
  56. lines = self.filter_comments(filepath)
  57. lines.append((c_preproc.POPFILE, ''))
  58. lines.reverse()
  59. pc[filepath] = lines
  60. self.lines.extend(lines)
  61. except IOError:
  62. raise c_preproc.PreprocError("could not read the file %s" % filepath)
  63. except Exception:
  64. if Logs.verbose > 0:
  65. Logs.error("parsing %s failed" % filepath)
  66. traceback.print_exc()
  67. class winrc(Task.Task):
  68. """
  69. Task for compiling resource files
  70. """
  71. run_str = '${WINRC} ${WINRCFLAGS} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${WINRC_TGT_F} ${TGT} ${WINRC_SRC_F} ${SRC}'
  72. color = 'BLUE'
  73. def scan(self):
  74. tmp = rc_parser(self.generator.includes_nodes)
  75. tmp.start(self.inputs[0], self.env)
  76. nodes = tmp.nodes
  77. names = tmp.names
  78. if Logs.verbose:
  79. Logs.debug('deps: deps for %s: %r; unresolved %r' % (str(self), nodes, names))
  80. return (nodes, names)
  81. def configure(conf):
  82. """
  83. Detect the programs RC or windres, depending on the C/C++ compiler in use
  84. """
  85. v = conf.env
  86. v['WINRC_TGT_F'] = '-o'
  87. v['WINRC_SRC_F'] = '-i'
  88. # find rc.exe
  89. if not conf.env.WINRC:
  90. if v.CC_NAME == 'msvc':
  91. conf.find_program('RC', var='WINRC', path_list = v['PATH'])
  92. v['WINRC_TGT_F'] = '/fo'
  93. v['WINRC_SRC_F'] = ''
  94. else:
  95. conf.find_program('windres', var='WINRC', path_list = v['PATH'])
  96. if not conf.env.WINRC:
  97. conf.fatal('winrc was not found!')
  98. v['WINRCFLAGS'] = []