LICENSE   := AGPLv3
VERSION   := git
DOWNLOADS := linphone-sdk.git bctoolbox.git belle-sip.git belr.git \
             bzrtp.git external-decaf.git external-libxml2.git \
             external-mbedtls.git external-opus.git external-speex.git \
             external-sqlite3.git external-srtp.git external-zlib.git \
             liblinphone.git mediastreamer2.git mswebrtc.git webrtc.git \
             ortp.git

DEPTH := 10000

URL(linphone-sdk) := https://gitlab.linphone.org/BC/public/linphone-sdk.git
REV(linphone-sdk) := 5bbd9ec01dfb725a3dfaaab4d8b08fc2cefcc4d7
DIR(linphone-sdk) := src

URL(bctoolbox) := https://gitlab.linphone.org/BC/public/bctoolbox.git --depth $(DEPTH)
REV(bctoolbox) := 6a403eed726e29cd86a8e737ef625316d0ba73b1
DIR(bctoolbox) := src/bctoolbox

URL(belle-sip) := https://gitlab.linphone.org/BC/public/belle-sip.git --depth $(DEPTH)
REV(belle-sip) := 6b1c87130649e82ef7971d3737f5c31c7ab6983e
DIR(belle-sip) := src/belle-sip

URL(belr) := https://gitlab.linphone.org/BC/public/belr.git --depth $(DEPTH)
REV(belr) := e28ed5b96dd36cfd233faff23e3cb3688892bb11
DIR(belr) := src/belr

URL(bzrtp) := https://gitlab.linphone.org/BC/public/bzrtp.git --depth $(DEPTH)
REV(bzrtp) := 922bd8a4f14e37c8a7702ecbc4e4d78d360081dd
DIR(bzrtp) := src/bzrtp

URL(external-decaf) := https://gitlab.linphone.org/BC/public/external/decaf.git
REV(external-decaf) := 4d7bafff3a69c9d02b8addbb78f301a6a74e59ea
DIR(external-decaf) := src/external/decaf

URL(external-libxml2) := https://gitlab.linphone.org/BC/public/external/libxml2.git --depth $(DEPTH)
REV(external-libxml2) := 0c3727603137d62b09648ce20d819f27d35e913e
DIR(external-libxml2) := src/external/libxml2

URL(external-mbedtls) := https://gitlab.linphone.org/BC/public/external/mbedtls.git
REV(external-mbedtls) := 2acc0f26e6e97c82ff9981c1ec32b497d4ea9426
DIR(external-mbedtls) := src/external/mbedtls

URL(external-opus) := https://gitlab.linphone.org/BC/public/external/opus.git --depth $(DEPTH)
REV(external-opus) := de9442fbf3fe6f97b53ee91070f0aa80fe312ac8
DIR(external-opus) := src/external/opus

URL(external-speex) := https://gitlab.linphone.org/BC/public/external/speex.git --depth $(DEPTH)
REV(external-speex) := d7a3c1731d5ec1688776a65b4e72ce8d32112c8e
DIR(external-speex) := src/external/speex

URL(external-sqlite3) := https://gitlab.linphone.org/BC/public/external/sqlite3.git --depth $(DEPTH)
REV(external-sqlite3) := 2ad0736620e82b47ee9ac5810f8e55abb6d46df9
DIR(external-sqlite3) := src/external/sqlite3

URL(external-srtp) := https://gitlab.linphone.org/BC/public/external/srtp.git
REV(external-srtp) := c136e9462551add57ad29844822e1f5dece4e4d7
DIR(external-srtp) := src/external/srtp

URL(external-zlib) := https://gitlab.linphone.org/BC/public/external/zlib.git --depth $(DEPTH)
REV(external-zlib) := 3c5c87046a6d94df354e0e0ca7fc3c981fbdf61e
DIR(external-zlib) := src/external/zlib

URL(liblinphone) := https://gitlab.linphone.org/BC/public/liblinphone.git --depth $(DEPTH)
REV(liblinphone) := 46c26da3d4134971f1203dc7e4ddab40ff6af876
DIR(liblinphone) := src/liblinphone

URL(mediastreamer2) := https://gitlab.linphone.org/BC/public/mediastreamer2.git --depth $(DEPTH)
REV(mediastreamer2) := d1bff7e66998e2175ee7be23a2e778210e7209ff
DIR(mediastreamer2) := src/mediastreamer2

URL(mswebrtc) := https://gitlab.linphone.org/BC/public/mswebrtc.git --depth $(DEPTH)
REV(mswebrtc) := 7cd041c884cad5a137556b845496c283c1e1c660
DIR(mswebrtc) := src/mswebrtc

URL(webrtc) := https://gitlab.linphone.org/BC/public/external/webrtc.git --depth $(DEPTH)
REV(webrtc) := 583acd27665cfadef8ab03eb85a768d308bd29dd
DIR(webrtc) := src/mswebrtc/webrtc

URL(ortp) := https://gitlab.linphone.org/BC/public/ortp.git --depth $(DEPTH)
REV(ortp) := b82c7f7327090b9b1ee72ebd3532fb4389da208c
DIR(ortp) := src/ortp

PATCHES := $(addprefix patches/,bctoolbox.patch \
                                bzrtp.patch \
                                ecstate_realpath.patch \
                                liblinphone.patch \
                                libxml2.patch \
                                mbedtls.patch \
                                mediastreamer2.patch \
                                ortp.patch \
                                oss.patch \
                                webrtc.patch)

PATCH_OPT(patches/bctoolbox.patch)        := -p1 -dsrc/bctoolbox
PATCH_OPT(patches/bzrtp.patch)            := -p1 -dsrc/bzrtp
PATCH_OPT(patches/ecstate_realpath.patch) := -p1 -dsrc/liblinphone
PATCH_OPT(patches/liblinphone.patch)      := -p1 -dsrc/liblinphone
PATCH_OPT(patches/libxml2.patch)          := -p1 -dsrc/external/libxml2
PATCH_OPT(patches/mbedtls.patch)          := -p1 -dsrc/external/mbedtls
PATCH_OPT(patches/mediastreamer2.patch)   := -p1 -dsrc/mediastreamer2
PATCH_OPT(patches/ortp.patch)             := -p1 -dsrc/ortp
PATCH_OPT(patches/oss.patch)              := -p1 -dsrc/mediastreamer2
PATCH_OPT(patches/webrtc.patch)           := -p1 -dsrc/mswebrtc/webrtc


#
# The rules below orchestrate the cloning of the various
# git modules referenced by the linphone-sdk.
#
# The 'clone_git_module' function generates the required
# target rules and establishes the order in which modules have
# to be cloned. To disarm the src directory check in the goa import
# tool we have to remove already existing directories from any
# git repository.
#

define clone_git_module
remove_$1 : $2
	$(VERBOSE)rmdir ${DIR($1)}
$1.git : remove_$1
endef

#
# like clone_git_module but removes broken symlinks in src
#
define clone_git_module_and_clean
remove_$1 : $2
	$(VERBOSE)rmdir ${DIR($1)}
	$(VEROBSE)find ${DIR(linphone.sdk)} -xtype l -delete
$1.git : remove_$1
endef

#
# Filter out linphone-sdk.git as it is the main dependency while
# webrtc.git depends on mswebrtc.git.
#
FILTER_DOWNLOADS := linphone-sdk webrtc ortp
MOD_LIST         := $(filter-out $(FILTER_DOWNLOADS),$(DOWNLOADS:%.git=%))
$(foreach MOD,$(MOD_LIST),$(eval $(call clone_git_module,$(MOD),linphone-sdk.git)))

$(eval $(call clone_git_module,webrtc,mswebrtc.git))
$(eval $(call clone_git_module_and_clean,ortp,linphone-sdk.git))
