#
# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id:

include $(TOPDIR)/rules.mk

PKG_NAME:=xapian-core
PKG_VERSION:=1.0.7
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://oligarchy.co.uk/xapian/$(PKG_VERSION)
PKG_FIXUP:=libtool

include $(INCLUDE_DIR)/package.mk

PKG_INSTALL=1

EXTRA_LDFLAGS+= \
	-L$(STAGING_DIR)/usr/lib/libintl/lib \
	-L$(STAGING_DIR)/usr/lib/libiconv/lib \
	-L$(TOOLCHAIN_DIR)/lib

define Package/libxapian
  SECTION:=lib
  CATEGORY:=Libraries
  TITLE:=xapian
  URL:=http://xapian.org
  DEPENDS:=+libstdcpp
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/share/aclocal
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/usr/share/aclocal/* \
		$(1)/usr/share/aclocal

	$(INSTALL_DIR) $(1)/usr/include
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/usr/include/xapian.h \
		$(1)/usr/include
	$(INSTALL_DIR) $(1)/usr/include/xapian
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/usr/include/xapian/* \
		$(1)/usr/include/xapian

	$(INSTALL_DIR) $(1)/usr/lib/
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/usr/lib/*.{so*,la} \
		$(1)/usr/lib/
	$(INSTALL_DIR) $(2)/bin
	$(INSTALL_BIN) \
		$(PKG_INSTALL_DIR)/usr/bin/xapian-config \
		$(2)/bin
	$(SED) 's,prefix=",prefix="$(STAGING_DIR),g' $(2)/bin/xapian-config

	#FIXME: Libtool should handle this
	$(SED) \
		"s,$(STAGING_DIR)/usr/lib/libstdc++,$(TOOLCHAIN_DIR)/lib/libstdc++,g" \
		$(1)/usr/lib/libxapian.la
endef

define Package/libxapian/install
	$(INSTALL_DIR) $(1)/usr/lib/
	$(INSTALL_DATA) \
		$(PKG_INSTALL_DIR)/usr/lib/*.{so*,a} \
		$(1)/usr/lib
	$(INSTALL_DIR) $(1)/usr/bin/
	$(INSTALL_BIN) \
		$(PKG_INSTALL_DIR)/usr/bin/* \
		$(1)/usr/bin
endef

$(eval $(call BuildPackage,libxapian))


