]> git.sesse.net Git - vlc/blob - bindings/python/setup-internal.py
mkv: Remove an unneeded test.
[vlc] / bindings / python / setup-internal.py
1 from distutils.core import setup, Extension
2 import os
3
4 # Get build variables (buildir, srcdir)
5 try:
6     top_builddir=os.environ['top_builddir']
7 except KeyError:
8     # Note: do not initialize here, so that we get
9     # a correct default value if the env. var is
10     # defined but empty
11     top_builddir=None
12 if not top_builddir:
13     top_builddir = os.path.join( '..', '..' )
14     os.environ['top_builddir'] = top_builddir
15
16 try:
17     srcdir=os.environ['srcdir']
18 except KeyError:
19     # Note: same as above
20     srcdir=None
21 if not srcdir:
22     srcdir = '.'
23
24 def get_vlcconfig():
25     vlcconfig=None
26     for n in ( 'vlc-config',
27                os.path.join( top_builddir, 'vlc-config' )):
28         if os.path.exists(n):
29             vlcconfig=n
30             break
31     if vlcconfig is None:
32         print "*** Warning *** Cannot find vlc-config"
33     elif os.sys.platform == 'win32':
34         # Win32 does not know how to invoke the shell itself.
35         vlcconfig="sh %s" % vlcconfig
36     return vlcconfig
37
38 def get_vlc_version():
39     vlcconfig=get_vlcconfig()
40     if vlcconfig is None:
41         return ""
42     else:
43         version=os.popen('%s --version' % vlcconfig, 'r').readline().strip()
44         return version
45     
46 def get_cflags():
47     vlcconfig=get_vlcconfig()
48     if vlcconfig is None:
49         return []
50     else:
51         cflags=os.popen('%s --cflags vlc' % vlcconfig, 'r').readline().rstrip().split()
52         return cflags
53
54 def get_ldflags():
55     vlcconfig=get_vlcconfig()
56     if vlcconfig is None:
57         return []
58     else:
59         ldflags = []
60         if os.sys.platform == 'darwin':
61             ldflags = "-read_only_relocs warning".split()
62         ldflags.extend(os.popen('%s --libs vlc external' % vlcconfig,
63                                 'r').readline().rstrip().split())
64         if os.sys.platform == 'darwin':
65             ldflags.append('-lstdc++')
66         return ldflags
67
68 #source_files = [ 'vlc_module.c', 'vlc_object.c', 'vlc_mediacontrol.c',
69 #                 'vlc_position.c', 'vlc_instance.c', 'vlc_input.c' ]
70 source_files = [ 'vlc_internal.c' ]
71
72 # To compile in a local vlc tree
73 vlclocal = Extension('vlcinternal',
74                      sources = [ os.path.join( srcdir, f ) for f in source_files ],
75                      include_dirs = [ top_builddir,
76                                       os.path.join( srcdir, '..', '..', 'include' ),
77                                       srcdir,
78                                       '/usr/win32/include' ],
79                 extra_objects = [ ],
80                 extra_compile_args = get_cflags(),
81                 extra_link_args = [ '-L' + os.path.join(top_builddir, 'src', '.libs') ]  + get_ldflags(),
82                 )
83
84 setup (name = 'VLC Internal Bindings',
85        version = get_vlc_version(),
86        #scripts = [ os.path.join( srcdir, 'vlcwrapper.py') ],
87        keywords = [ 'vlc', 'video' ],
88        license = "GPL", 
89        description = """VLC internal bindings for python.
90
91 This module provides an Object type, which gives a low-level access to
92 the vlc objects and their variables.
93
94 Example session:
95
96 import vlcinternal
97
98 # Access lowlevel objets
99 o=vlcinternal.Object(1)
100 o.info()
101 i=o.find_object('input')
102 i.list()
103 i.get('time')
104        """,
105        ext_modules = [ vlclocal ])