TOPDIR=..
include $(TOPDIR)/Makefiles/Repo-defines.mk

DIRECTORIES_CODECS_STATIC_LIB= \
	amr \
	amr_wb \
	evs \
	evrc_b \
	evrc \
	evrc_nw \
	g7xxcommon \
	g722code \
	g723code \
	g726code \
	g729code \
	gsmfr \
	iSAC \
	iLBC \
	opus \
	qcelp \
	silk \
	speex

DIRECTORIES_CODECS_SHARED_LIB= \
	gsmefr \
	gsmhr \

DIRECTORIES= \
	$(DIRECTORIES_CODECS_STATIC_LIB) \
	$(DIRECTORIES_CODECS_SHARED_LIB)

all::
	@echo "=== Applying Empirix patches to RTP-CODECS"
	patch -p0 --forward < amr_memory_leak_fix.patch || true

-include ${EMPIRIX_PIPELINE_FRAMEWORK_MAKEFILE_SUPPORT_DIR}/Recursive-targets.mk

# to build precompiled binaries faster, set here a number equal to the cores of your machine:
NUM_PROCS=40

HAS_ONLY_RELEASE_MODE_PRECOMPILED=1


# NOTE: the "clean" target in third-party-cpp-libs should NOT clean up the shared/static libraries
clean_build_intermediate_artifacts:
	find -name Build | xargs rm -rf

clean_build_outputs: 
	rm -rf $(BUILDID)

clean:: clean_build_intermediate_artifacts clean_build_outputs

#
# Strip target
#
strip:
	# after stripping it's important to run ranlib to make sure the static library is usable and linkable
	@if [ -d $(PRECOMPILED_DIR) ] ; then \
		for libfile in $(PRECOMPILED_DIR)/*.a ; do  \
			if [ ! -h $$libfile ] ; then \
				echo "Stripping static RTP codec library $$libfile" ; \
				strip --strip-debug $$libfile ; \
				ranlib $$libfile ; \
			fi ; \
		done ; \
	fi

# NOTE: regardless of the value of CFG=debug/release, we always install only the release version
install_libs:
ifndef DESTDIR
	@echo "*** ERROR: please call this makefile supplying explicitly the DESTDIR variable"
	@exit 1
endif
	$(MKDIR) $(DESTDIR)
	#@$(foreach dir, $(filter-out opus,$(DIRECTORIES_CODECS_STATIC_LIB)), cp -av $(dir)/Lib/$(PRECOMPILED_DIR)/*.a $(DESTDIR); )
	#@$(foreach dir, $(DIRECTORIES_CODECS_SHARED_LIB), cp -av $(dir)/Bin/$(PRECOMPILED_DIR)/*.so* $(DESTDIR); )
	#@cp -av opus/*/Lib/$(PRECOMPILED_DIR)/*.a $(DESTDIR)
	@cp -avf $(PRECOMPILED_DIR)/*.a $(DESTDIR)

install_headers::
ifndef DESTDIR
	@echo "*** ERROR: please call this makefile supplying explicitly the DESTDIR variable"
	@exit 1
endif
	@mkdir -p $(DESTDIR)/rtp-codecs
	@cp --parents */*.h $(DESTDIR)/rtp-codecs 
	@cp --parents */*/*.h $(DESTDIR)/rtp-codecs 
