#!/bin/bash if [ -x "`which gmake`" ]; then MAKE=gmake else MAKE=make fi for v in OBJDIR CPATH EXTRA_LIBS HAVE_LADSPA \ HAVE_ALSA HAVE_DVB HAVE_ESOUND HAVE_FIREWIRE HAVE_DV \ HAVE_OSS HAVE_XFT HAVE_VIDEO4LINUX HAVE_VIDEO4LINUX2 ; do eval export "$v=\"`$MAKE -s val-$v`\"" done if [ "$1" = "static" ]; then STATIC_LIBRARIES="y" elif [ "$1" = "shared" ]; then STATIC_LIBRARIES="n" elif [ "$1" = "cv" ]; then STATIC_LIBRARIES="n" libs="libogg libtheora libvorbis openexr libdv libjpeg tiff x264 mjpegtools a52dec lame libsndfile faac faad2" forced_libs="mjpegtools x264" else echo "usage: $0 " exit 1 fi #thirdparty libraries echo "configuring thirdparty library build" echo "" echo "required libraries:" append() { var=$1 shift eval "$var+=\" $*\"" } is_in() { value=$1 shift for var in $*; do [ $var = $value ] && return 0 done return 1 } add_library() { local lib=$1 shift 1 append LIBS $lib sta_lib=sta_$lib append $sta_lib $@ } inc_a52dec="include" add_library a52dec \ liba52/.libs/liba52.a inc_audiofile="libaudiofile" add_library audiofile \ libaudiofile/.libs/libaudiofile.a \ libaudiofile/modules/.libs/libmodules.a \ libaudiofile/alac/.libs/libalac.a inc_encore="." add_library encore \ $OBJDIR/libencore.a if [ "$HAVE_ESOUND" = "y" ]; then inc_esound="." add_library esound \ .libs/libesd.a \ .libs/libesddsp.a fi inc_faac="include" add_library faac \ libfaac/.libs/libfaac.a \ common/mp4v2/libmp4v2.a inc_faad2="include" add_library faad2 \ libfaad/.libs/libfaad.a \ common/mp4ff/libmp4ff.a # fdk replaces faac/faad2, but is experimental... inc_fdk="libAACdec/include libAACenc/include libSYS/include" add_library fdk \ .libs/libfdk-aac.a inc_festival="src" add_library festival \ src/lib/libFestival.a inc_ffmpeg="." add_library ffmpeg \ libavutil/libavutil.a \ libavcodec/libavcodec.a \ libpostproc/libpostproc.a \ libavdevice/libavdevice.a \ libavformat/libavformat.a \ libswscale/libswscale.a \ libavfilter/libavfilter.a \ libswresample/libswresample.a inc_fftw="api" add_library fftw \ .libs/libfftw3.a \ libbench2/libbench2.a \ rdft/scalar/r2cb/.libs/librdft_scalar_r2cb.a \ rdft/scalar/r2r/.libs/librdft_scalar_r2r.a \ rdft/scalar/.libs/librdft_scalar.a \ rdft/scalar/r2cf/.libs/librdft_scalar_r2cf.a \ rdft/.libs/librdft.a \ api/.libs/libapi.a \ reodft/.libs/libreodft.a \ dft/scalar/codelets/.libs/libdft_scalar_codelets.a \ dft/scalar/.libs/libdft_scalar.a \ dft/.libs/libdft.a \ kernel/.libs/libkernel.a \ simd-support/.libs/libsimd_support.a \ simd-support/.libs/libsimd_sse2_nonportable.a inc_flac="include" add_library flac \ src/libFLAC/.libs/libFLAC.a \ src/libFLAC++/.libs/libFLAC++.a \ src/share/utf8/.libs/libutf8.a \ src/share/replaygain_analysis/.libs/libreplaygain_analysis.a \ src/share/replaygain_synthesis/.libs/libreplaygain_synthesis.a \ src/share/grabbag/.libs/libgrabbag.a \ src/test_libs_common/.libs/libtest_libs_common.a inc_giflib="lib" add_library giflib \ lib/.libs/libgif.a \ util/libgetarg.a inc_ilmbase="Iex Half Imath config IlmThread" add_library ilmbase \ Iex/.libs/libIex.a \ IexMath/.libs/libIexMath.a \ Half/.libs/libHalf.a \ Imath/.libs/libImath.a \ IlmThread/.libs/libIlmThread.a if [ "$HAVE_LADSPA" = "y" ]; then inc_ladspa="" add_library ladspa fi inc_lame="include" add_library lame \ libmp3lame/.libs/libmp3lame.a \ mpglib/.libs/libmpgdecoder.a if [ "$HAVE_FIREWIRE" = "y" ]; then inc_libavc1394="." add_library libavc1394 \ libavc1394/.libs/libavc1394.a \ librom1394/.libs/librom1394.a \ common/.libs/libraw1394util.a inc_libraw1394="." add_library libraw1394 \ src/.libs/libraw1394.a inc_libiec61883="src" add_library libiec61883 \ src/.libs/libiec61883.a fi if [ "$HAVE_DV" = "y" ]; then inc_libdv="." add_library libdv \ libdv/.libs/libdv.a fi inc_libjpeg="." add_library libjpeg \ .libs/libjpeg.a \ .libs/libturbojpeg.a \ simd/.libs/libsimd.a inc_openjpeg="src/lib/openjp2" add_library openjpeg \ bin/libopenjp2.a inc_libogg="include" add_library libogg \ src/.libs/libogg.a inc_libsndfile="." add_library libsndfile \ src/.libs/libsndfile.a \ src/.libs/libcommon.a \ src/G72x/.libs/libg72x.a \ src/GSM610/.libs/libgsm.a inc_libtheora="." add_library libtheora \ lib/.libs/libtheora.a \ lib/.libs/libtheoradec.a \ lib/.libs/libtheoraenc.a inc_libuuid="." add_library libuuid \ .libs/libuuid.a inc_libvorbis="include ." add_library libvorbis \ lib/.libs/libvorbis.a \ lib/.libs/libvorbisenc.a \ lib/.libs/libvorbisfile.a inc_mjpegtools=". lavtools utils" add_library mjpegtools \ utils/mmxsse/.libs/libmmxsse.a \ utils/.libs/libmjpegutils.a \ lavtools/.libs/liblavfile.a \ lavtools/.libs/liblavjpeg.a \ yuvfilters/.libs/libyuvfilters.a \ mpeg2enc/.libs/libmpeg2encpp.a \ mplex/.libs/libmplex2.a inc_openexr="IlmImf config" add_library openexr \ IlmImf/.libs/libIlmImf.a \ IlmImfUtil/.libs/libIlmImfUtil.a inc_speech_tools="." add_library speech_tools \ lib/libestools.a \ lib/libeststring.a \ lib/libestbase.a inc_tiff="." add_library tiff \ libtiff/.libs/libtiff.a \ libtiff/.libs/libtiffxx.a \ port/.libs/libport.a inc_twolame="libtwolame" add_library twolame \ libtwolame/.libs/libtwolame.a inc_x264="." add_library x264 \ libx264.a inc_x265=". source" add_library x265 \ libx265.a inc_libvpx="." add_library libvpx \ libvpx.a \ echo "" if [ -n "$libs" ]; then LIBS="$libs" fi n=0 for lib in $LIBS; do echo -n " $lib" if [ $(((n+=1) % 8)) = 0 ]; then echo ""; fi done if [ $((n % 8)) != 0 ]; then echo ""; fi echo "" # dynamic library paths probe() { if ! `echo $LIBS | grep -qw $1`; then return 0; fi local name="$1" if [ -n "${!name}" ]; then return 0; fi local headers="$2" local func="$3" shift 3 : ${TMPDIR:=$TEMPDIR} : ${TMPDIR:=$TMP} : ${TMPDIR:=/tmp} local exe=$(mktemp -u "${TMPDIR}/cine-${name}.XXXXXXXX") trap "rm -f -- ${exe}" EXIT { for hdr in $headers; do test "${hdr%.h}" = "${hdr}" && echo "#include $hdr" || echo "#include <$hdr>" done for func in $func; do echo "long check_$func(void) { return (long) $func; }" done echo "int main(void) { return 0; }" } | cc -x c - -o $exe $@ $EXTRA_LIBS >& /dev/null ret=$? rm -f "${exe}" if [ $ret = 0 ]; then eval $name=\"shared $*\" echo "exists shared $name" return 0 fi local sta_libs=sta_$name eval $name=\"static ${!sta_libs}\" echo "build static $name" return 1 } # test for shared libs/header files probe a52dec "a52.h" a52_init -la52 probe audiofile "audiofile.h" afOpenFile -laudiofile probe faac "stdint.h faac.h" faacEncGetVersion -lfaac probe faad2 "faad.h" NeAACDecInit -lfaad # dont build festival in shared build if [ "$STATIC_LIBRARIES" = "n" ]; then festival="shared"; fi if [ "$STATIC_LIBRARIES" = "n" ]; then speech_tools="shared"; fi probe fftw "fftw3.h" fftw_execute -lfftw3 probe flac "FLAC/stream_decoder.h" FLAC__stream_decoder_new -lFLAC probe lame "lame/lame.h" hip_decode_init -lmp3lame probe libavc1394 "libavc1394/avc1394.h librom1394/rom1394.h" avc1394_init_target -lavc1394 probe libdv "libdv/dv.h" dv_init -ldv probe libiec61883 "libiec61883/iec61883.h" iec61883_mpeg2_recv_init -liec61883 probe libjpeg "stdio.h unistd.h jpeglib.h" jpeg_start_decompress -ljpeg probe libogg "ogg/ogg.h" ogg_stream_init -logg probe openjpeg "openjpeg.h" opj_version -lopenjp2 -DOPJ_STATIC || \ probe openjpeg "openjpeg-1.5/openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC || \ probe openjpeg "openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC probe libraw1394 "libraw1394/raw1394.h" raw1394_iso_recv_init -lraw1394 probe libsndfile "sndfile.h" sf_open -lsndfile probe ilmbase "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex probe openexr "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex probe libtheora "theora/theoraenc.h" th_info_init -ltheora -ltheoraenc -ltheoradec -logg probe libvorbis "vorbis/vorbisenc.h" vorbis_info_init -lvorbisenc -lvorbis -lvorbisfile -logg probe libvpx "vpx/vpx_decoder.h" vpx_codec_decode -lvpx probe tiff "tiff.h tiffio.h" TIFFOpen -ltiff probe twolame "twolame.h" twolame_encode_buffer_float32_interleaved -ltwolame probe x264 "stdint.h x264.h" x264_encoder_encode -lx264 probe x265 "x265.h" x265_encoder_encode -lx265 forced_libs="$forced_libs a52dec encore ffmpeg giflib libuuid openjpeg" # for ffmpeg link/broken disto libs for name in $LIBS; do if is_in $name $forced_libs; then set - ${!name} typ="$1" shift 1 if [ "$typ" = "shared" ]; then echo "warn: $name forced static" sta_libs=sta_$name eval $name=\"static ${!sta_libs}\" fi fi done # add dependencies (order matters) for dep in \ ffmpeg/faac ffmpeg/faad2 ffmpeg/twolame ffmpeg/lame ffmpeg/openjpeg \ ffmpeg/libvorbis ffmpeg/libtheora ffmpeg/x264 ffmpeg/fdk \ libiec61883/libraw1394 libavc1394/librom1394 \ openexr/ilmbase ilmbase/libogg \ libtheora/libogg libtheora/libvorbis ; do lib="${dep%%/*}" needs="${dep##*/}" if is_in $lib $shared; then if is_in $needs $shared; then continue; fi if is_in $needs $static; then echo warn: shared $lib using static $needs continue fi append shared $needs fi if is_in $lib $static; then if is_in $needs $static; then continue; fi if is_in $needs $shared; then echo warn: static $lib using shared $needs continue fi append static $needs fi done echo "" # check for static libs which may conflicting header files if [ "$STATIC_LIBRARIES" = "y" ]; then for name in $LIBS; do set - ${!name} typ="$1" shift 1 if [ "$typ" = "shared" ]; then echo "warn: $name is shared and static" fi sta_libs=sta_$name eval $name=\"static ${!sta_libs}\" done fi # any unknowns are static for name in $LIBS; do if [ -z "${!name}" ]; then sta_libs=sta_$name eval $name=\"static ${!sta_libs}\" fi done # dont build festival festival="shared" speech_tools="shared" shared="" static="" for lib in $LIBS; do set - ${!lib} typ="$1" append $typ $lib done echo "thirdparty :=$LIBS" > config.mak echo "shared_libs :=$shared" >> config.mak echo "static_libs :=$static" >> config.mak for lib in $LIBS; do echo "$lib := ${!lib}" inc_lib=inc_$lib echo "inc_$lib := ${!inc_lib}" done >> config.mak echo >> config.mak ' # translate config.mak into libs/incs pkg_path=$(lastword $(wildcard $(THIRDPARTY)/$(1)*)) lib_static=$(call pkg_path,$(1))/$(2) lib_shared=$(2) inc_static=-I$(1)/$(2) inc_shared= lib_typ=$(firstword $(1)) lib_refs=$(wordlist 2,$(words $(1)),$(1)) $(foreach lib,$(thirdparty), \ $(eval pkg_$(lib) := $(call pkg_path,$(lib))) \ $(eval typ_$(lib) := $(call lib_typ,$($(lib)))) \ $(eval lib_$(lib) := \ $(foreach ref, $(call lib_refs,$($(lib))), \ $(call lib_$(typ_$(lib)),$(lib),$(ref)))) \ $(eval inc_$(lib) := \ $(foreach inc, $(inc_$(lib)), \ $(call inc_$(typ_$(lib)),$(pkg_$(lib)),$(inc))))) #list libs/incs ifeq ($(MAKECMDGOALS),list) $(foreach lib,$(thirdparty),$(info $(lib) := $(typ_$(lib)) $(pkg_$(lib))) \ $(foreach ref,$(lib_$(lib)), $(info == $(ref))) \ $(foreach ref,$(inc_$(lib)), $(info -- $(ref)))) .PHONY: list list: endif static_includes := $(foreach lib,$(static_libs), $(inc_$(lib))) static_libraries := $(foreach lib,$(static_libs),$(lib_$(lib))) shared_libraries := $(foreach lib,$(shared_libs),$(lib_$(lib))) thirdparty_libraries := $(static_libraries) $(shared_libraries) '