]> git.sesse.net Git - vlc/blob - bindings/python/setup.py
python bindings: begin to complete the libvlc API bindings. Cf TODO for what is left...
[vlc] / bindings / python / setup.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 # Determine the extra link args. Normally, vlc-config should take care
17 # of this and return the right path values, from a development tree or
18 # an installed version.
19 libtool=False
20 linkargs=[]
21 d=os.path.join(top_builddir, 'src', '.libs')
22 if os.path.exists(d):
23     # We are in a development tree, which was compiled with libtool
24     libtool=True
25     linkargs=[ '-L' + d ]
26 else:
27     d=os.path.join(top_builddir, 'src')
28     # We are in a development tree, which was compiled without libtool
29     if os.path.exists(d):
30         linkargs=[ '-L' + d ]
31
32 # For out-of-tree compilations
33 try:
34     srcdir=os.environ['srcdir']
35 except KeyError:
36     # Note: same as above
37     srcdir=None
38 if not srcdir:
39     srcdir = '.'
40
41 def get_vlcconfig():
42     vlcconfig=None
43     for n in ( 'vlc-config',
44                os.path.join( top_builddir, 'vlc-config' )):
45         if os.path.exists(n):
46             vlcconfig=n
47             break
48     if vlcconfig is None:
49         print "*** Warning *** Cannot find vlc-config"
50     elif os.sys.platform == 'win32':
51         # Win32 does not know how to invoke the shell itself.
52         vlcconfig="sh %s" % vlcconfig
53     return vlcconfig
54
55 def get_vlc_version():
56     vlcconfig=get_vlcconfig()
57     if vlcconfig is None:
58         return ""
59     else:
60         version=os.popen('%s --version' % vlcconfig, 'r').readline().strip()
61         return version
62     
63 def get_cflags():
64     vlcconfig=get_vlcconfig()
65     if vlcconfig is None:
66         return []
67     else:
68         cflags=os.popen('%s --cflags vlc' % vlcconfig, 'r').readline().rstrip().split()
69         return cflags
70
71 def get_ldflags():
72     vlcconfig=get_vlcconfig()
73     if vlcconfig is None:
74         return []
75     else:
76         ldflags = []
77         if os.sys.platform == 'darwin':
78             ldflags = "-read_only_relocs warning".split()
79         ldflags.extend(os.popen('%s --libs external' % vlcconfig,
80                                 'r').readline().rstrip().split())
81         if os.sys.platform == 'darwin':
82             ldflags.append('-lstdc++')
83         if not libtool:
84             # vlc-config is broken and gives a -lvlc-control which
85             # does not exist if libtool is disabled.
86             ldflags.remove('-lvlc-control')
87         return ldflags
88
89 #source_files = [ 'vlc_module.c', 'vlc_mediacontrol.c',
90 #                 'vlc_position.c', 'vlc_instance.c', 'vlc_input.c' ]
91 source_files = [ 'vlc_module.c' ]
92
93 # To compile in a local vlc tree
94 vlclocal = Extension('vlc',
95                      sources = [ os.path.join( srcdir, f ) for f in source_files ],
96                      include_dirs = [ top_builddir,
97                                       os.path.join( srcdir, '..', '..', 'include' ),
98                                       srcdir,
99                                       '/usr/win32/include' ],
100                 extra_objects = [ ],
101                 extra_compile_args = get_cflags(),
102                 extra_link_args = linkargs + get_ldflags(),
103                 )
104
105 setup (name = 'VLC Bindings',
106        version = get_vlc_version(),
107        #scripts = [ os.path.join( srcdir, 'vlcwrapper.py') ],
108        keywords = [ 'vlc', 'video' ],
109        license = "GPL", 
110        description = """VLC bindings for python.
111
112 This module provides bindings for the native libvlc API of the VLC
113 video player. Documentation can be found on the VLC wiki : 
114 http://wiki.videolan.org/index.php/ExternalAPI
115
116 This module also provides a MediaControl object, which implements an
117 API inspired from the OMG Audio/Video Stream 1.0 specification.
118 Documentation can be found on the VLC wiki :
119 http://wiki.videolan.org/index.php/PythonBinding
120
121 Example session:
122
123 import vlc
124 mc=vlc.MediaControl(['--verbose', '1'])
125 mc.playlist_add_item('movie.mpg')
126
127 # Start the movie at 2000ms
128 p=vlc.Position()
129 p.origin=vlc.RelativePosition
130 p.key=vlc.MediaTime
131 p.value=2000
132 mc.start(p)
133 # which could be abbreviated as
134 # mc.start(2000)
135 # for the default conversion from int is to make a RelativePosition in MediaTime
136
137 # Display some text during 2000ms
138 mc.display_text('Some useless information', 0, 2000)
139
140 # Pause the video
141 mc.pause(0)
142
143 # Get status information
144 mc.get_stream_information()
145        """,
146        ext_modules = [ vlclocal ])