# Copyright (C) 2007 FON Wireless Ltd.
# All rights reserved.
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$
#
include $(TOPDIR)/rules.mk

PKG_NAME:=fonbase
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install

include $(INCLUDE_DIR)/package.mk

define Package/fonbase
  SECTION:=base
  CATEGORY:=Base system
  TITLE:=FON Base System
  DESCRIPTION:=FON Base System
  DEPENDS:=+coova +libpthread
  URL:=http://www.fon.com
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./fonstate/* $(PKG_BUILD_DIR)/
endef

define Build/Configure
	(cd $(PKG_BUILD_DIR); \
		rm -rf config.{cache,status} ; \
		CFLAGS="$(TARGET_CFLAGS)" \
		LDFLAGS="-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib" \
		$(TARGET_CONFIGURE_OPTS) \
		./configure --host=$(GNU_TARGET_NAME) \
	);
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		$(TARGET_CONFIGURE_OPTS)
endef

define Package/fonbase/install
	$(CP) ./files/* $(1)/
	mkdir $(1)/.ssh/
	ln -sf /etc/dropbear/known_hosts $(1)/.ssh/
	chmod 755 $(1)/etc/init.d/forwardports
	ln -sf ../rc1.d/S95greenstatus $(1)/etc/rc2.d/K10greenstatus
	install -m0755 $(PKG_BUILD_DIR)/src/fonstate $(1)/sbin/
	install -m0755 $(PKG_BUILD_DIR)/src/fs $(1)/sbin/
endef

$(eval $(call BuildPackage,fonbase))

