[CherryPick] Input Method upversion
[framework/web/webkit-efl.git] / Tools / Scripts / generate-win32-export-forwards
1 #!/usr/bin/env python
2
3 #Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4
5 #This library is free software; you can redistribute it and/or
6 #modify it under the terms of the GNU Library General Public
7 #License as published by the Free Software Foundation; either
8 #version 2 of the License, or (at your option) any later version.
9
10 #This library is distributed in the hope that it will be useful,
11 #but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #Library General Public License for more details.
14
15 #You should have received a copy of the GNU Library General Public License
16 #along with this library; see the file COPYING.LIB.  If not, write to
17 #the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 #Boston, MA 02110-1301, USA.
19
20 # Extract /EXPORT: linker directives from static library and write it into a
21 # separate file as linker pragmas.
22 # Usage: generate-win32-export-forwards \path\to\static\library.lib outputfile.cpp
23 # Then compile outputfile.cpp into the final .dll and link the static library
24 # into the dll.
25
26 import subprocess
27 import sys
28 import re
29
30 def exportForwardsForLibrary(library):
31     dumpBin = subprocess.Popen("dumpbin /directives " + library, stdout=subprocess.PIPE, universal_newlines=True)
32
33     output = dumpBin.communicate()[0]
34     return output
35
36 libraries = sys.argv[1 : -1]
37 outputFileName = sys.argv[-1]
38
39 exportedSymbolRegexp = re.compile("\s*(?P<symbol>/EXPORT:.+)")
40 symbols = set()
41
42 for lib in libraries:
43     for line in exportForwardsForLibrary(lib).splitlines():
44         match = exportedSymbolRegexp.match(line)
45         if match:
46             symbols.add(match.group("symbol"))
47
48 print "Forwarding %s symbols from %s" % (len(symbols), " ".join(libraries))
49
50 exportFile = open(outputFileName, "w")
51 for symbol in symbols:
52     exportFile.write("#pragma comment(linker, \"%s\")\n" % symbol);
53 exportFile.close()