#############################################################
#
# conntrack
#
#############################################################
# Copyright (C) 2001-2003 by Erik Andersen <andersen@codepoet.org>
# Copyright (C) 2002 by Tim Riker <Tim@Rikers.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA

CONNTRACK_VER:=1.00beta2
CONNTRACK_DIR:=$(BUILD_DIR)/conntrack-$(CONNTRACK_VER)
CONNTRACK_SITE:=http://www.netfilter.org/projects/conntrack/files
CONNTRACK_SOURCE:=conntrack-$(CONNTRACK_VER).tar.bz2
CONNTRACK_CAT:=bzcat

$(DL_DIR)/$(CONNTRACK_SOURCE):
	 $(WGET) -P $(DL_DIR) $(CONNTRACK_SITE)/$(CONNTRACK_SOURCE)

conntrack-source: $(DL_DIR)/$(CONNTRACK_SOURCE)

$(CONNTRACK_DIR)/.unpacked: $(DL_DIR)/$(CONNTRACK_SOURCE)
	$(CONNTRACK_CAT) $(DL_DIR)/$(CONNTRACK_SOURCE) | tar -C $(BUILD_DIR) $(TAR_OPTIONS) -
	patch -p1 -d $(CONNTRACK_DIR) < package/conntrack/ooma_conntrack_delete_mod.patch
	touch $(CONNTRACK_DIR)/.unpacked

$(CONNTRACK_DIR)/.configured: $(CONNTRACK_DIR)/.unpacked
	( \
		cd $(CONNTRACK_DIR) ; \
		rm -rf config.cache; \
		LDFLAGS=-L$(STAGING_DIR)/usr/lib\ -lnfnetlink\ $(LDFLAGS) \
		CFLAGS=-I$(STAGING_DIR)/include\ $(CFLAGS) \
		$(TARGET_CONFIGURE_OPTS) \
                ./configure \
                --target=$(GNU_TARGET_NAME) \
                --host=$(GNU_TARGET_NAME) \
                --build=$(GNU_HOST_NAME) \
                --prefix=/usr \
                --exec-prefix=/usr \
                --bindir=/bin \
                --sbindir=/sbin \
                --localstatedir=/var \
		--libdir=/lib \
                --mandir=/usr/man \
	)
	touch $(CONNTRACK_DIR)/.configured

$(CONNTRACK_DIR)/.compiled: $(CONNTRACK_DIR)/.configured
	$(MAKE) -C $(CONNTRACK_DIR)
	touch $(CONNTRACK_DIR)/.compiled

$(STAGING_DIR)/bin/mips-linux-conntrack: $(CONNTRACK_DIR)/.compiled
	$(MAKE) \
		-C $(CONNTRACK_DIR) \
		prefix=$(STAGING_DIR) \
		exec_prefix=$(STAGING_DIR) \
		bindir=$(STAGING_DIR)/bin \
		datadir=$(STAGING_DIR)/share \
		sbindir=$(STAGING_DIR)/bin \
		mandir=$(STAGING_DIR)/man \
		libdir=$(STAGING_DIR)/lib \
		install
	touch -c $(STAGING_DIR)/bin/mips-linux-conntrack

$(TARGET_DIR)/bin/conntrack: $(STAGING_DIR)/bin/mips-linux-conntrack
	cp -dpf $(STAGING_DIR)/bin/mips-linux-conntrack $(TARGET_DIR)/bin/conntrack
	cp -dpf $(STAGING_DIR)/lib/conntrack/ct*so $(TARGET_DIR)/lib
	-$(STRIP) --strip-unneeded $(TARGET_DIR)/bin/conntrack

conntrack: uclibc libnfnetlink libnetfilter_conntrack $(TARGET_DIR)/bin/conntrack

conntrack-clean:
	-$(MAKE) -C $(CONNTRACK_DIR) clean
#############################################################
#
# Toplevel Makefile options
#
#############################################################
ifeq ($(strip $(BR2_PACKAGE_CONNTRACK)),y)
TARGETS+=conntrack
endif
