#############################################################
#
# live555-lib
#
#############################################################
LIVE555_LIB_VER:=2009.02.23
LIVE555_LIB_SOURCE:=live.$(LIVE555_LIB_VER).tar.gz
LIVE555_LIB_SITE:=http://www.live555.com/liveMedia/public/
LIVE555_LIB_CAT:=zcat
LIVE555_LIB_DIR:=$(BUILD_DIR)/live

LIVE555_LIB_STATIC_LIBS:=	liveMedia/libliveMedia.a groupsock/libgroupsock.a BasicUsageEnvironment/libBasicUsageEnvironment.a \
				UsageEnvironment/libUsageEnvironment.a
LIVE555_LIB_DYNAMIC_LIBS:=	libliveMedia.so libgroupsock.so libBasicUsageEnvironment.so libUsageEnvironment.so
LIVE555_LIB_TESTPROGS:= 	openRTSP playSIP sapWatch testAMRAudioStreamer testMP3Receiver testMP3Streamer testMPEG1or2AudioVideoStreamer \
				testMPEG1or2AudioVideoToDarwin testMPEG1or2ProgramToTransportStream testMPEG1or2Splitter testMPEG1or2VideoReceiver \
				testMPEG1or2VideoStreamer testMPEG2TransportReceiver testMPEG2TransportStreamer testMPEG4VideoStreamer \
				testMPEG4VideoToDarwin testOnDemandRTSPServer testRelay testWAVAudioStreamer vobStreamer

$(DL_DIR)/$(LIVE555_LIB_SOURCE):
	 $(WGET) -P $(DL_DIR) $(LIVE555_LIB_SITE)/$(LIVE555_LIB_SOURCE)

live555-lib-source: $(DL_DIR)/$(LIVE555_LIB_SOURCE)

$(LIVE555_LIB_DIR)/.unpacked: $(DL_DIR)/$(LIVE555_LIB_SOURCE)
	$(LIVE555_LIB_CAT) $(DL_DIR)/$(LIVE555_LIB_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	toolchain/patch-kernel.sh $(LIVE555_LIB_DIR) local/live555-lib/patches/ '*'
	cp -dfpr local/live555-lib/overlay/* $(LIVE555_LIB_DIR)
	touch $(LIVE555_LIB_DIR)/.unpacked

$(LIVE555_LIB_DIR)/.make: $(LIVE555_LIB_DIR)/.unpacked
	cd $(LIVE555_LIB_DIR) && ./genMakefiles mips-linux && \
	make
	cd $(LIVE555_LIB_DIR)/liveMedia && \
	   $(TARGET_CC) -shared -o ../libliveMedia.so libliveMedia.a
	cd $(LIVE555_LIB_DIR)/groupsock && \
	   $(TARGET_CC) -shared -o ../libgroupsock.so libgroupsock.a
	cd $(LIVE555_LIB_DIR)/UsageEnvironment && \
	   $(TARGET_CC) -shared -o ../libUsageEnvironment.so libUsageEnvironment.a
	cd $(LIVE555_LIB_DIR)/BasicUsageEnvironment && \
	   $(TARGET_CC) -shared -o ../libBasicUsageEnvironment.so libBasicUsageEnvironment.a
	touch $(LIVE555_LIB_DIR)/.make

$(LIVE555_LIB_DIR)/.testProgs: $(LIVE555_LIB_DIR)/.make
	cd $(LIVE555_LIB_DIR)/testProgs && \
	cp ${LIVE555_LIB_TESTPROGS} $(STAGINGDIR)$(_TMTGTPREFIX)/bin

$(LIVE555_LIB_DIR)/.includes: $(LIVE555_LIB_DIR)/.testProgs
	cd $(LIVE555_LIB_DIR) && \
	cp liveMedia/*.h groupsock/include/*.h $(STAGINGDIR)$(_TMTGTPREFIX)/include && \
        cp liveMedia/*.hh liveMedia/include/*.hh WindowsAudioInputDevice/*.hh groupsock/include/*.hh \
	   BasicUsageEnvironment/include/*.hh UsageEnvironment/include/*.hh testProgs/*.hh $(STAGINGDIR)$(_TMTGTPREFIX)/include

$(LIVE555_LIB_DIR)/.libs: $(LIVE555_LIB_DIR)/.includes
	cd $(LIVE555_LIB_DIR) && \
	cp ${LIVE555_LIB_DYNAMIC_LIBS} $(STAGINGDIR)$(_TMTGTPREFIX)/lib && \
	cp ${LIVE555_LIB_STATIC_LIBS} $(STAGINGDIR)$(_TMTGTPREFIX)/lib

$(LIVE555_LIB_DIR)/.install: $(LIVE555_LIB_DIR)/.libs
	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(STAGING_DIR)$(_TMTGTPREFIX)/lib/libliveMedia.so -o $(ROOTFS)$(_TMTGTPREFIX)/lib/libliveMedia.so
	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(STAGING_DIR)$(_TMTGTPREFIX)/lib/libgroupsock.so -o $(ROOTFS)$(_TMTGTPREFIX)/lib/libgroupsock.so
	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(STAGING_DIR)$(_TMTGTPREFIX)/lib/libBasicUsageEnvironment.so -o $(ROOTFS)$(_TMTGTPREFIX)/lib/libBasicUsageEnvironment.so
	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(STAGING_DIR)$(_TMTGTPREFIX)/lib/libUsageEnvironment.so -o $(ROOTFS)$(_TMTGTPREFIX)/lib/libUsageEnvironment.so
	cd $(STAGING_DIR)/opt/nxp/bin/ && \
	cp $(LIVE555_LIB_TESTPROGS) $(ROOTFS)/opt/nxp/bin;
	touch $(LIVE555_LIB_DIR)/.install

live555-lib: $(LIVE555_LIB_DIR)/.install

live555-lib-clean:
	-make -C $(LIVE555_LIB_DIR) clean

live555-lib-dirclean:
	rm -rf $(LIVE555_LIB_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_LIVE555_LIB)),y)
TARGETS+=live555-lib
endif

