###############################################################################
# This file is part of the IPCop Firewall.                                    #
#                                                                             #
# IPCop is free software; you can redistribute it and/or modify               #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation; either version 2 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# IPCop is distributed in the hope that it will be useful,                    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with IPCop; if not, write to the Free Software                        #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    #
#                                                                             #
# Makefiles are based on LFSMake, which is                                    #
# Copyright (C) 2002 Rod Roard <rod@sunsetsystems.com>                        #
#                                                                             #
# Modifications by:                                                           #
# ??-12-2003 Mark Wormgoor < mark@wormgoor.com>                               #
#          - Modified Makefile for IPCop build                                #
#                                                                             #
# $Id: discover 2621 2009-03-22 12:43:10Z owes $
#                                                                             #
###############################################################################

###############################################################################
# Definitions
###############################################################################

include Config

PKG_NAME   = discover
VER        = 2.1.2
HOST_ARCH  = all
OTHER_SRC  = yes

THISAPP    = $(PKG_NAME)-$(VER)
DL_FILE    = $(PKG_NAME)_$(VER).orig.tar.gz
DL_FROM    = $(URL_DEBIAN)/d
DIR_APP    = $(DIR_SRC)/$(THISAPP)
TARGET     = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)

# PATCH1     = $(PKG_NAME)_$(VER)-2.diff.gz

DATA_VER   = 2008.06.25
DATAAPP    = $(PKG_NAME)-data-2.$(DATA_VER)
DATA_DL_FILE  = $(PKG_NAME)-data_2.$(DATA_VER).tar.gz
DATA_DIR   = $(DIR_APP)/trunk

###############################################################################
# Top-level Rules
###############################################################################

objects = $(DL_FILE) \
	$(DATA_DL_FILE)
# we don't need the diff patch actually, no patches on debian/patches to apply

$(DL_FILE)					= $(DL_FROM)/$(PKG_NAME)/$(DL_FILE)
# $(PATCH1)					= $(DL_FROM)/$(PKG_NAME)/$(PATCH1)
$(DATA_DL_FILE)					= $(DL_FROM)/$(PKG_NAME)-data/$(DATA_DL_FILE)

$(DL_FILE)_MD5					= af78b63cc8db31b11d7e25958423611e
# $(PATCH1)_MD5					= 598be78eb4b87efd96f720606e76941e
$(DATA_DL_FILE)_MD5				= c4d45317a2229b30859fdd1bb31bdb04

install : $(TARGET)

check : $(patsubst %,$(DIR_CHK)/%,$(objects))

download :$(patsubst %,$(DIR_DL)/%,$(objects))

md5 : $(subst %,%_MD5,$(objects))

###############################################################################
# Downloading, checking, md5sum
###############################################################################

$(patsubst %,$(DIR_CHK)/%,$(objects)) :
	@$(CHECK)

$(patsubst %,$(DIR_DL)/%,$(objects)) :
	@$(LOAD)

$(subst %,%_MD5,$(objects)) :
	@$(MD5)

###############################################################################
# Installation Details
###############################################################################

$(TARGET) : $(firstword $(MAKEFILE_LIST)) $(patsubst %,$(DIR_DL)/%,$(objects))
	@$(PREBUILD)
	@rm -rf $(DIR_APP)
	@cd $(DIR_SRC) && tar zxf $(DIR_DL)/$(DL_FILE)
	@cd $(DIR_APP) && tar zxf $(DIR_DL)/$(DATA_DL_FILE)

	# First install the xml data files (by default in /usr/share/discover)
	cd $(DATA_DIR) && make install

	# There is no patches actually in the diff, so the diff is useless
	# Now patch, compile and install discover
	# cd $(DIR_APP) && gzip -dc $(DIR_DL)/$(PATCH1) | patch -Np1
	# if there was debian/patches, we need to apply there like made in lfs/grub

	cd $(DIR_APP) && ./configure	--prefix=/usr \
					--disable-nls \
					--disable-curl \
					--datadir=/usr/share \
					--sysconfdir=/etc
	cd $(DIR_APP) && make
	cd $(DIR_APP) && make install

	# Fix some incorrect entries
	sed -i	-e "s,qlogicfc,qla2xxx,g" \
		-e "s,sym53c8xx_2,sym53c8xx,g" \
		-e "s,usb-uhci,uhci-hcd,g" \
		-e "s,usb-ohci,ohci-hcd,g" \
		-e "s,usb-ehci,ehci-hcd,g" \
		/usr/share/discover/pci-device.xml

	# Strip PCI devices we are not interested in to save ~ 200 kB compressed and 1800 kB uncompressed
	${DIR_SRC}/src/scripts/discover-data-shrink.pl	/usr/share/discover/pci-device.xml \
							/usr/share/discover/pci-device.xml
	# Save 4kB when compressed, 120kB uncompressed
	sed -i -e '/last-updated/d' /usr/share/discover/pci-device.xml

	@rm -rf $(DIR_APP)
	@$(POSTBUILD)
