4 Helpers to extract symbols from Unix libs and auto-generate
5 Windows definition files from them. Depends on nm(1). Tested
6 on Linux and Solaris only (-p option to nm is for Solaris only).
8 By Marc-Andre Lemburg, Aug 1998.
10 Additional notes: the output of nm is supposed to look like this:
13 000001fd T PyGrammar_AddAccelerators
15 00000237 T PyGrammar_RemoveAccelerators
24 00000000 T PyGrammar_FindDFA
25 00000034 T PyGrammar_LabelRepr
26 U _PyParser_TokenNames
33 Even if this isn't the default output of your nm, there is generally an
34 option to produce this format (since it is the original v7 Unix format).
39 PYTHONLIB
= 'libpython'+sys
.version
[:3]+'.a'
40 PC_PYTHONLIB
= 'Python'+sys
.version
[0]+sys
.version
[2]+'.dll'
41 NM
= 'nm -p -g %s' # For Linux, use "nm -g %s"
43 def symbols(lib
=PYTHONLIB
,types
=('T','C','D')):
45 lines
= os
.popen(NM
% lib
).readlines()
46 lines
= [s
.strip() for s
in lines
]
49 if len(line
) == 0 or ':' in line
:
54 address
, type, name
= items
57 symbols
[name
] = address
,type
60 def export_list(symbols
):
64 for name
,(addr
,type) in symbols
.items():
66 data
.append('\t'+name
)
68 code
.append('\t'+name
)
72 return ' DATA\n'.join(data
)+'\n'+'\n'.join(code
)
74 # Definition file template
80 # Special symbols that have to be included even though they don't
85 def filter_Python(symbols
,specials
=SPECIALS
):
87 for name
in symbols
.keys():
88 if name
[:2] == 'Py' or name
[:3] == '_Py':
90 elif name
not in specials
:
95 s
= symbols(PYTHONLIB
)
97 exports
= export_list(s
)
98 f
= sys
.stdout
# open('PC/python_nt.def','w')
99 f
.write(DEF_TEMPLATE
% (exports
))
102 if __name__
== '__main__':