From 3dd12104d9c021a10ba92680896edb777ae852d3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 10 Feb 2014 21:25:22 +0100 Subject: 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. --- old-makefile | 2 +- player/core.h | 1 + player/main.c | 11 +---------- player/main_fn.c | 15 +++++++++++++++ wscript | 7 +++++++ wscript_build.py | 19 ++++++++++++++++++- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 player/main_fn.c diff --git a/old-makefile b/old-makefile index 5ea5122f7e..0614829e6f 100644 --- a/old-makefile +++ b/old-makefile @@ -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) diff --git a/player/core.h b/player/core.h index 10c2f1886d..b772f862f7 100644 --- a/player/core.h +++ b/player/core.h @@ -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); diff --git a/player/main.c b/player/main.c index 4493d8aeb5..99ba0becd2 100644 --- a/player/main.c +++ b/player/main.c @@ -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 -} diff --git a/player/main_fn.c b/player/main_fn.c new file mode 100644 index 0000000000..87e1681987 --- /dev/null +++ b/player/main_fn.c @@ -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 +} diff --git a/wscript b/wscript index 3c9373e295..5a1526656d 100644 --- a/wscript +++ b/wscript @@ -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'), diff --git a/wscript_build.py b/wscript_build.py index 164fc553d6..83d1444a9c 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -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", -- cgit v1.2.3