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