B output.def libname.lib defaults to python.lib and output.def defaults to stdout Author: Robert Kern Last Update: April 30, 1999 z0.1az%d%dznm -CszrLIBRARY python%s.dll ;CODE PRELOAD MOVEABLE DISCARDABLE ;DATA PRELOAD SINGLE EXPORTS z^(.*) in python%s\.dllz^_imp__(.*) in python%s\.dllcCsttjdkrtjddddkrNtjddddkrNtjdd\}}nPtjddddkrtjddddkrtjdd\}}ntdtd njttjdkrtjddddkrtjd}d t}n$tjddddkrd}tjd}n d t}d}||fS) zBParses the command-line arguments. libfile, deffile = parse_cmd()Nz.librz.defz4I'm assuming that your first argument is the libraryzand the second is the DEF file.z python%s.lib)lensysargvprintpy_ver)libfiledeffilerJ/opt/alt/python37/lib64/python3.7/site-packages/numpy/distutils/lib2def.py parse_cmd)s",,    rZnmz-Csz python%s.libcCs,tj|dtjdd}|j}|j|S)zVReturns the output of nm_cmd via a pipe. nm_output = getnam(nm_cmd = 'nm -Cs py_lib')T)shellstdoutZuniversal_newlines) subprocessPopenPIPErreadclose)nm_cmdf nm_outputrrrgetnmAs  rcCst|}t|}g}xN|D]F}||kr|dddksZ|dddksZ|dddkr||qWg}x>|D]6}||krr|dddks|dddkrr||qrW||||fS)zReturns a tuple of lists: dlist for the list of data symbols and flist for the list of function symbols. dlist, flist = parse_nm(nm_output)NrZPyrZ_PyZinit)DATA_REfindallFUNC_REappendsort)rdatafuncflistZsymdlistrrrparse_nmJs   8 (r(cCsJx|D]}|d|}qW|d}x|D]}|d|}q(W||dS)zoOutputs the final DEF file to a file defaulting to stdout. output_def(dlist, flist, header, file = sys.stdout)z %s DATA  z %s N)write)r'r&headerfileZdata_symZfunc_symrrr output_def`s   r-__main__w)!Z __future__rrrrer osr__doc__ __version__tuple version_infor Z DEFAULT_NMZ DEF_HEADERcompile MULTILINEr!rrrr(rr-__name__rropenstrrrr'r&rrrrs0