Skip to content

Commit

Permalink
linux: link ffmpeg statically
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Feb 1, 2014
1 parent e211654 commit 974a3c0
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 15 deletions.
11 changes: 11 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ ifeq ($(findstring freebsd,@ARCH@),freebsd)
DYNOBJSXBMC+= xbmc/freebsd/freebsd.a
endif

ifeq (@USE_STATIC_FFMPEG@,1)
DYNOBJSXBMC += lib/ffmpeg/libavcodec/libavcodec.a \
lib/ffmpeg/libavfilter/libavfilter.a \
lib/ffmpeg/libswresample/libswresample.a \
lib/ffmpeg/libavformat/libavformat.a \
lib/ffmpeg/libavutil/libavutil.a \
lib/ffmpeg/libpostproc/libpostproc.a \
lib/ffmpeg/libswscale/libswscale.a
LIBS+= @GNUTLS_ALL_LIBS@ @VORBISENC_ALL_LIBS@
endif

OBJSXBMC:=$(filter-out $(DYNOBJSXBMC), $(OBJSXBMC))

MAINOBJS=xbmc/xbmc.o
Expand Down
19 changes: 18 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ MAKE="${MAKE:-make}"
OBJDUMP="${OBJDUMP:-objdump}"

use_external_ffmpeg=no
use_static_ffmpeg=no

# ffmpeg needs the output of uname -s (e.x. linux, darwin) for the target_os
# there is no autoconf variable which will give
Expand Down Expand Up @@ -627,13 +628,17 @@ case $host in
if test "$use_cpu" = "no" -a "$cross_compiling" = "yes"; then
use_arch="x86"
use_cpu="i686"
else
target_platform=target_linux
fi
;;
x86_64-*-linux-gnu*|x86_64-*-linux-uclibc*)
ARCH="x86_64-linux"
if test "$use_cpu" = "no" -a "$cross_compiling" = "yes"; then
use_arch="x86_64"
use_cpu="x86_64"
else
target_platform=target_linux
fi
;;
i386-*-freebsd*)
Expand Down Expand Up @@ -867,6 +872,15 @@ elif test "$use_arch" = "arm"; then
fi
fi
fi
if test "$target_platform" = "target_linux"; then

This comment has been minimized.

Copy link
@Fneufneu

Fneufneu Feb 4, 2014

Member

this stuff is not target linux specific, it's needed for ffmpeg static building.
so it's better to have:

if [ "$use_static_ffmpeg" = "yes" ]; then

and i think i'll add use_static_ffmpeg=yes for FreeBSD all well.

This comment has been minimized.

Copy link
@wsnipex

wsnipex Feb 4, 2014

Member

indeed. The current state probably also breaks libxbmc.so on linux

This comment has been minimized.

Copy link
@FernetMenta

FernetMenta Feb 4, 2014

Author Contributor

use_static_ffmeg is set some lines down from here and can't be used for comparison here.

This comment has been minimized.

Copy link
@wsnipex

wsnipex Feb 4, 2014

Member

this should work:
set use_static_ffmeg instead of target_platform=target_linux on lines 632 and 641, then here test this instead:
if test "$use_static_ffmpeg" = "yes" -a "$use_shared_lib" != "yes";

This comment has been minimized.

Copy link
@sraue

sraue Feb 5, 2014

Member

added in #4154 (partly, which means i dont have tested with libxbmc.so and dont enabled static building on platformas other then i*86, x86_64, arm)

USE_STATIC_FFMPEG=1
use_static_ffmpeg=yes
AC_DEFINE([USE_STATIC_FFMPEG], [1], [link ffmpeg statically])
# ffmpeg may depend on gnutls and vorbisenc, we add those libs at the end of linker
# command in order to resolve any missing symbols
GNUTLS_ALL_LIBS=`${PKG_CONFIG} --static --libs-only-l --silence-errors gnutls`
VORBISENC_ALL_LIBS=`${PKG_CONFIG} --static --libs-only-l --silence-errors vorbisenc`
fi

# Checks for library functions.
AC_FUNC_ALLOCA
Expand Down Expand Up @@ -2601,6 +2615,7 @@ AC_SUBST(DISABLE_FISHBMC)
AC_SUBST(DISABLE_PROJECTM)
AC_SUBST(USE_SKIN_TOUCHED)
AC_SUBST(USE_EXTERNAL_FFMPEG)
AC_SUBST(USE_STATIC_FFMPEG)
AC_SUBST(USE_LIBAV_HACKS)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(OUTPUT_FILES)
Expand Down Expand Up @@ -2645,6 +2660,8 @@ AC_SUBST(USE_ANDROID)
AC_SUBST(GTEST_CONFIGURED)
AC_SUBST(USE_DOXYGEN)
AC_SUBST(USE_PVR_ADDONS)
AC_SUBST(GNUTLS_ALL_LIBS)
AC_SUBST(VORBISENC_ALL_LIBS)

# pushd and popd are not available in other shells besides bash, so implement
# our own pushd/popd functions
Expand Down Expand Up @@ -2802,7 +2819,7 @@ XB_CONFIG_MODULE([lib/ffmpeg], [
--disable-ffserver \
--disable-ffmpeg \
--disable-crystalhd \
--enable-shared \
`if test "$use_static_ffmpeg" = "yes"; then echo --enable-static; else echo --enable-shared; fi` \
--disable-doc \
--enable-postproc \
--enable-gpl \
Expand Down
4 changes: 2 additions & 2 deletions lib/DllAvCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DllAvCodecInterface
virtual AVDictionary* av_frame_get_metadata(const AVFrame* frame)=0;
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)

// Use direct layer
class DllAvCodec : public DllDynamic, DllAvCodecInterface
Expand Down Expand Up @@ -166,7 +166,7 @@ class DllAvCodec : public DllDynamic, DllAvCodecInterface
// DLL faking.
virtual bool ResolveExports() { return true; }
virtual bool Load() {
#if !defined(TARGET_DARWIN)
#if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
CLog::Log(LOGDEBUG, "DllAvCodec: Using libavcodec system library");
#endif
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/DllAvFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DllAvFilterInterface
#endif
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
// Use direct mapping
class DllAvFilter : public DllDynamic, DllAvFilterInterface
{
Expand Down
8 changes: 4 additions & 4 deletions lib/DllAvFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
void xbmc_read_frame_flush(AVFormatContext *s);
#else
#include "libavformat/avformat.h"
#if defined(TARGET_DARWIN)
#if defined(TARGET_DARWIN) || defined(USE_STATIC_FFMPEG)
void ff_read_frame_flush(AVFormatContext *s); // internal replacement
#define xbmc_read_frame_flush ff_read_frame_flush
#endif
Expand Down Expand Up @@ -73,7 +73,7 @@ class DllAvFormatInterface
virtual int av_read_play(AVFormatContext *s)=0;
virtual int av_read_pause(AVFormatContext *s)=0;
virtual int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)=0;
#if (!defined USE_EXTERNAL_FFMPEG) && (!defined TARGET_DARWIN)
#if (!defined USE_EXTERNAL_FFMPEG) && (!defined TARGET_DARWIN) && (!defined USE_STATIC_FFMPEG)
virtual int avformat_find_stream_info_dont_call(AVFormatContext *ic, AVDictionary **options)=0;
#endif
virtual int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)=0;
Expand Down Expand Up @@ -108,7 +108,7 @@ class DllAvFormatInterface
#endif
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)

// Use direct mapping
class DllAvFormat : public DllDynamic, DllAvFormatInterface
Expand Down Expand Up @@ -170,7 +170,7 @@ class DllAvFormat : public DllDynamic, DllAvFormatInterface
// DLL faking.
virtual bool ResolveExports() { return true; }
virtual bool Load() {
#if !defined(TARGET_DARWIN)
#if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
CLog::Log(LOGDEBUG, "DllAvFormat: Using libavformat system library");
#endif
CSingleLock lock(DllAvCodec::m_critSection);
Expand Down
4 changes: 2 additions & 2 deletions lib/DllAvUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DllAvUtilInterface
#endif
};

#if defined (USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if defined (USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)
// Use direct layer
class DllAvUtilBase : public DllDynamic, DllAvUtilInterface
{
Expand Down Expand Up @@ -174,7 +174,7 @@ class DllAvUtilBase : public DllDynamic, DllAvUtilInterface
// DLL faking.
virtual bool ResolveExports() { return true; }
virtual bool Load() {
#if !defined(TARGET_DARWIN)
#if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
CLog::Log(LOGDEBUG, "DllAvUtilBase: Using libavutil system library");
#endif
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/DllPostProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DllPostProcInterface
virtual void pp_free_context(pp_context *ppContext)=0;
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)

// We call directly.
class DllPostProc : public DllDynamic, DllPostProcInterface
Expand Down
4 changes: 2 additions & 2 deletions lib/DllSwResample.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DllSwResampleInterface
virtual int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance) = 0;
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)

// Use direct mapping
class DllSwResample : public DllDynamic, DllSwResampleInterface
Expand All @@ -71,7 +71,7 @@ class DllSwResample : public DllDynamic, DllSwResampleInterface
// DLL faking.
virtual bool ResolveExports() { return true; }
virtual bool Load() {
#if !defined(TARGET_DARWIN)
#if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
CLog::Log(LOGDEBUG, "DllAvFormat: Using libswresample system library");
#endif
return true;
Expand Down
4 changes: 2 additions & 2 deletions lib/DllSwScale.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DllSwScaleInterface
virtual void sws_freeContext(struct SwsContext *context)=0;
};

#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) || (defined USE_STATIC_FFMPEG)

// We call into this library directly.
class DllSwScale : public DllDynamic, public DllSwScaleInterface
Expand All @@ -111,7 +111,7 @@ class DllSwScale : public DllDynamic, public DllSwScaleInterface
// DLL faking.
virtual bool ResolveExports() { return true; }
virtual bool Load() {
#if !defined(TARGET_DARWIN)
#if !defined(TARGET_DARWIN) && !defined(USE_STATIC_FFMPEG)
CLog::Log(LOGDEBUG, "DllSwScale: Using libswscale system library");
#endif
return true;
Expand Down
14 changes: 14 additions & 0 deletions lib/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif

LIBS=
ifneq (@USE_EXTERNAL_FFMPEG@,1)
ifneq (@USE_STATIC_FFMPEG@,1)
LIBS+=$(AVUTIL_SO) \
$(AVCODEC_SO) \
$(AVFORMAT_SO) \
Expand All @@ -35,10 +36,12 @@ ifneq (@USE_EXTERNAL_FFMPEG@,1)
$(SWSCALE_SO) \
$(SWRESAMPLE_SO)
endif
endif

.PHONY: $(DIRS) codecs

ifneq ($(findstring osx,$(ARCH)), osx)
ifneq (@USE_STATIC_FFMPEG@,1)

codecs: $(addprefix $(SYSDIR)/, $(LIBS));

Expand Down Expand Up @@ -71,6 +74,17 @@ ffmpeg/libswscale/libswscale.so : ffmpeg;
ffmpeg/libpostproc/libpostproc.so : ffmpeg;
ffmpeg/libswresample/libswresample.so : ffmpeg;
endif
endif

ifeq (@USE_STATIC_FFMPEG@,1)
ffmpeg/libavutil/libavutil.a : ffmpeg;
ffmpeg/libavcodec/libavcodec.a : ffmpeg;
ffmpeg/libavformat/libavformat.a : ffmpeg;
ffmpeg/libavfilter/libavfilter.a : ffmpeg;
ffmpeg/libswscale/libswscale.a : ffmpeg;
ffmpeg/libpostproc/libpostproc.a : ffmpeg;
ffmpeg/libswresample/libswresample.a : ffmpeg;
endif

ffmpeg:
$(MAKE) -C $@
Expand Down

0 comments on commit 974a3c0

Please sign in to comment.