build: add option to build a library

This library will export the client API functions.

Note that this doesn't allow compiling the command line player to link
against this library yet. The reason is that there's lots of weird stuff
required to setup the execution environment (mostly Windows and OSX
specifics), as well as things which are out of scope of the client API
and every application has to do on its own. However, since the mpv
command line player basically reuses functions from the mpv core to
implement these things, it's not very easy to separate the command
line player form the mpv core.
This commit is contained in:
wm4 2014-02-10 21:25:22 +01:00
parent 238c9b1d8d
commit 3dd12104d9
6 changed files with 43 additions and 12 deletions

View File

@ -396,7 +396,7 @@ all: $(ALL_TARGETS)
%-rc.o: %.rc
$(WINDRES) -I. $< $@
mpv$(EXESUF): $(OBJECTS)
mpv$(EXESUF): $(OBJECTS) player/main_fn.o
mpv$(EXESUF):
$(CC) -o $@ $^ $(EXTRALIBS)

View File

@ -388,6 +388,7 @@ void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
void mp_play_files(struct MPContext *mpctx);
// main.c
int mpv_main(int argc, char *argv[]);
int mp_initialize(struct MPContext *mpctx);
struct MPContext *mp_create(void);
void mp_destroy(struct MPContext *mpctx);

View File

@ -444,7 +444,7 @@ int mp_initialize(struct MPContext *mpctx)
return 0;
}
static int mpv_main(int argc, char *argv[])
int mpv_main(int argc, char *argv[])
{
osdep_preinit(&argc, &argv);
@ -519,12 +519,3 @@ static int mpv_main(int argc, char *argv[])
return 1;
}
int main(int argc, char *argv[])
{
#if HAVE_COCOA
return cocoa_main(mpv_main, argc, argv);
#else
return mpv_main(argc, argv);
#endif
}

15
player/main_fn.c Normal file
View File

@ -0,0 +1,15 @@
#include "config.h"
#include "core.h"
#if HAVE_COCOA
#include "osdep/macosx_application.h"
#endif
int main(int argc, char *argv[])
{
#if HAVE_COCOA
return cocoa_main(mpv_main, argc, argv);
#else
return mpv_main(argc, argv);
#endif
}

View File

@ -10,6 +10,11 @@ from waftools.checks.custom import *
build_options = [
{
'name': '--shared',
'desc': 'enable shared library',
'default': 'disable',
'func': check_true
}, {
'name': '--static-build',
'desc': 'static build',
'default': 'disable',
@ -739,6 +744,8 @@ _INSTALL_DIRS_LIST = [
('libdir', '${PREFIX}/lib', 'library files'),
('confdir', '${PREFIX}/etc/mpv', 'configuration files'),
('incdir', '${PREFIX}/include', 'include files'),
('datadir', '${PREFIX}/share', 'data files'),
('mandir', '${DATADIR}/man', 'man pages '),
('docdir', '${DATADIR}/doc/mpv', 'documentation files'),

View File

@ -426,7 +426,7 @@ def build(ctx):
ctx(
target = "mpv",
source = ctx.filtered_sources(sources),
source = ctx.filtered_sources(sources) + ["player/main_fn.c"],
use = ctx.dependencies_use(),
includes = [ctx.bldnode.abspath(), ctx.srcnode.abspath()] + \
ctx.dependencies_includes(),
@ -435,6 +435,23 @@ def build(ctx):
**cprog_kwargs
)
if ctx.dependency_satisfied('shared'):
ctx.load("syms")
ctx(
target = "mpv",
source = ctx.filtered_sources(sources),
use = ctx.dependencies_use(),
includes = [ctx.bldnode.abspath(), ctx.srcnode.abspath()] + \
ctx.dependencies_includes(),
features = "c cshlib syms",
export_symbols_regex = 'mpv_.*',
install_path = ctx.env.LIBDIR,
)
headers = ["client.h"]
for f in headers:
ctx.install_as(ctx.env.INCDIR + '/libmpv/' + f, 'libmpv/' + f)
if ctx.env.DEST_OS == 'win32':
wrapctx = ctx(
target = "mpv",