3 #Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
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
30 def exportForwardsForLibrary(library):
31 dumpBin = subprocess.Popen("dumpbin /directives " + library, stdout=subprocess.PIPE, universal_newlines=True)
33 output = dumpBin.communicate()[0]
36 libraries = sys.argv[1 : -1]
37 outputFileName = sys.argv[-1]
39 exportedSymbolRegexp = re.compile("\s*(?P<symbol>/EXPORT:.+)")
43 for line in exportForwardsForLibrary(lib).splitlines():
44 match = exportedSymbolRegexp.match(line)
46 symbols.add(match.group("symbol"))
48 print "Forwarding %s symbols from %s" % (len(symbols), " ".join(libraries))
50 exportFile = open(outputFileName, "w")
51 for symbol in symbols:
52 exportFile.write("#pragma comment(linker, \"%s\")\n" % symbol);