summaryrefslogtreecommitdiffstats
path: root/SOURCES/dll2a
blob: 851ed10d32fb56137cab6e9f3b3da5c19802855f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python 
import sys
import os, os.path
import commands
import tempfile
from optparse import OptionParser

usage = "usage: %prog [options] arg"
op = OptionParser(usage)
op.add_option('-l', '--libdir', dest="libdir")
opts, args = op.parse_args()

if len(args) != 1:
	sys.exit("dll2a: Invalid argument(s)")

if not os.path.isfile(args[0]):
	sys.exit("dll2a: File %r doen't exists" % args[0])

if not opts.libdir == None and not os.path.isdir(opts.libdir):
	sys.exit("dll2a: Output directoy %r doesn't exists" % opts.libdir)

if opts.libdir == None:
	opts.libdir = os.path.dirname(args[0])

appdir = os.path.abspath(os.path.dirname(__file__))
basename = os.path.basename(__file__)

dllfile = args[0]

_t = basename.split("-dll2a")
if not _t[0].strip() == "":
	prefix=_t[0]+"-"
else:
	prefix=""

gendef_bin  = os.path.join(appdir, "%sgendef"%prefix)
dlltool_bin = os.path.join(appdir, "%sdlltool"%prefix)
ranlib_bin  = os.path.join(appdir, "%sranlib"%prefix)

dlldir = os.path.dirname(dllfile)
basedllname = os.path.basename(dllfile)[:-4]

deffile = basedllname+".def"
deffile = os.path.join(opts.libdir, deffile)

libfile = "lib"+basedllname+".a"
libfile = os.path.join(opts.libdir, libfile)

cmd = '''%s - %s > %s''' % (gendef_bin, dllfile, deffile)
ret, out = commands.getstatusoutput(cmd)

if os.path.isfile(deffile):
    ret, out = commands.getstatusoutput('''%s -d %s -l %s''' % (dlltool_bin, deffile, libfile))
	
if os.path.isfile(libfile):
    ret, out = commands.getstatusoutput('''%s %s''' % (ranlib_bin, libfile))

os.remove(deffile)

print "dll2a: %s: DLL import library %s generated" % (dllfile, libfile)
sys.exit(0)