#############################################################
#
# dvbsnoop
#
#############################################################
DVBSNOOP_VER:=1.4.50
DVBSNOOP_SOURCE:=dvbsnoop-$(DVBSNOOP_VER).tar.gz
DVBSNOOP_SITE:=http://$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/dvbsnoop
DVBSNOOP_CAT:=$(ZCAT)
DVBSNOOP_DIR:=$(BUILD_DIR)/dvbsnoop-$(DVBSNOOP_VER)

$(DL_DIR)/$(DVBSNOOP_SOURCE):
	 $(WGET) -P $(DL_DIR) $(DVBSNOOP_SITE)/$(DVBSNOOP_SOURCE)

dvbsnoop-source: $(DL_DIR)/$(DVBSNOOP_SOURCE)

$(DVBSNOOP_DIR)/.unpacked: $(DL_DIR)/$(DVBSNOOP_SOURCE)
	$(DVBSNOOP_CAT) $(DL_DIR)/$(DVBSNOOP_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	toolchain/patch-kernel.sh $(DVBSNOOP_DIR) local/dvbsnoop/ '*.patch'
	touch $@

$(DVBSNOOP_DIR)/.configured: $(DVBSNOOP_DIR)/.unpacked
	(cd $(DVBSNOOP_DIR); rm -rf config.cache; \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS) $(BR2_DVBSNOOP_CFLAGS)" \
		LDFLAGS="$(TARGET_LDFLAGS)" \
		ac_cv_func_malloc_0_nonnull=yes \
		./configure \
		--target=$(GNU_TARGET_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--build=$(GNU_HOST_NAME) \
		--prefix=/usr \ \
	);
	touch $@

$(DVBSNOOP_DIR)/src/dvbsnoop: $(DVBSNOOP_DIR)/.configured
	$(MAKE) CC=$(TARGET_CC) CC_FOR_BUILD="$(HOSTCC)" -C $(DVBSNOOP_DIR)

$(TARGET_DIR)/usr/bin/dvbsnoop: $(DVBSNOOP_DIR)/src/dvbsnoop
	cp -af $(DVBSNOOP_DIR)/src/dvbsnoop $(TARGET_DIR)/usr/bin/dvbsnoop
	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(TARGET_DIR)/usr/bin/dvbsnoop

dvbsnoop: $(TARGET_DIR)/usr/bin/dvbsnoop

dvbsnoop-clean:
	rm -f $(DVBSNOOP_DIR)/src/dvbsnoop
	rm -f $(TARGET_DIR)/usr/bin/dvbsnoop
	-$(MAKE) -C $(DVBSNOOP_DIR) clean

dvbsnoop-dirclean:
	rm -rf $(DVBSNOOP_DIR)

#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_DVBSNOOP)),y)
TARGETS+=dvbsnoop
endif
