# 
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: Makefile 6807 2007-04-01 19:07:59Z nbd $

include $(TOPDIR)/rules.mk
PKG_NAME:=owfs
PKG_VERSION:=2.7p5
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
PKG_MD5SUM:=x

include $(INCLUDE_DIR)/package.mk

# Add this for owperl-module
include $(TOPDIR)/package/perlmod.mk
PERL5LIB:=${PERL_LIB}
PERL5DIR:=${PERL_LIB}

define Package/owfs/Default
  TITLE:=OWFS
  DEPENDS:=
  DESCRIPTION:=\
	OWFS (one-wire filesystem)
  URL:=http://owfs.sourceforge.net/
endef

define Package/owlib
  $(call Package/owfs/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+libusb +libpthread
  TITLE+= (library)
  DESCRIPTION+=\\\
	\\\
	This package contains the OWFS shared library, needed by other programs.
endef

define Package/owshell
  $(call Package/owfs/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=
  TITLE+= (shell utilities)
  DESCRIPTION+=\\\
	\\\
	This package contains the OWFS shell utilities.
endef

define Package/owcapi
  $(call Package/owfs/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+owlib
  TITLE+= (C-API library)
  DESCRIPTION+=\\\
	\\\
	This package contains the OWFS C-API.
endef

define Package/owperl
  $(call Package/owfs/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+owlib +perlbase-autoloader +perlbase-config +perlbase-dynaloader +perlbase-essential +perlbase-io
  TITLE+= (owperl module)
  DESCRIPTION+=\\\
	\\\
	This package contains the OWFS perl-module.
endef

define Package/owfs
  $(call Package/owfs/Default)
  SECTION:=libs
  CATEGORY:=Libraries
  DEPENDS:=+owlib +kmod-fuse-2-4 +libfuse-2-4 +fuse-utils-2-4
  TITLE+= (apps)
  DESCRIPTION+=\\\
	\\\
	This package contains the OWFS binaries.
endef

PKG_CONFIGURE_OPTS:= \
		--enable-zero \
		--disable-parport \
		--disable-ownfsd \
		--disable-ownet \
		--disable-owpython


ifneq ($(CONFIG_PACKAGE_owperl),)
PKG_CONFIGURE_OPTS+= --enable-owperl
ENABLE_SWIG:=1
else
PKG_CONFIGURE_OPTS+= --disable-owperl
endif
ifneq ($(CONFIG_PACKAGE_owtcl),)
PKG_CONFIGURE_OPTS+= --enable-owtcl
ENABLE_SWIG:=1
else
PKG_CONFIGURE_OPTS+= --disable-owtcl
PKG_CONFIGURE_OPTS+= --disable-owside
endif
ifneq ($(CONFIG_PACKAGE_owphp),)
PKG_CONFIGURE_OPTS+= --enable-owphp
ENABLE_SWIG:=1
else
PKG_CONFIGURE_OPTS+= --disable-owphp
endif
ifneq ($(ENABLE_SWIG),)
PKG_CONFIGURE_OPTS+= --enable-swig
else
PKG_CONFIGURE_OPTS+= --disable-swig
endif

CONFIGURE_ARGS += \
	--prefix=/usr \
	--exec-prefix=/usr \
	--enable-owftpd \
	--enable-owserver \
	--enable-owhttpd \
	--enable-owfs \
	--with-perl5=$(STAGING_DIR)/usr/bin/perl \
	--with-fuseinclude="$(STAGING_DIR)/usr/include" \
	--with-fuselib="$(STAGING_DIR)/usr/lib" \
	$(PKG_CONFIGURE_OPTS) \
	--enable-shared \
	--disable-rpath

define Build/Configure
	(cd $(PKG_BUILD_DIR); \
		rm -rf config.{status,cache} ; \
		./bootstrap ; \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS) $(CFLAGS_LARGEFILE)" \
		CPPFLAGS="-I$(STAGING_DIR)/usr/include" \
		LDFLAGS="-L$(STAGING_DIR)/usr/lib" \
		lt_sys_lib_dlsearch_path_spec="$(STAGING_DIR)/lib $(STAGING_DIR)/usr/lib" \
		lt_sys_lib_search_path_spec="$(STAGING_DIR)/lib $(STAGING_DIR)/usr/lib" \
		shrext_cmds=".so" \
		PERL5LIB="${PERL_LIB}" \
		PERL5DIR="${PERL_LIB}" \
		./configure \
			$(CONFIGURE_ARGS) \
	);
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		DESTDIR="$(PKG_INSTALL_DIR)" \
		all install
endef

define Build/InstallDev
	mkdir -p $(STAGING_DIR)/usr/include
	$(CP)	$(PKG_INSTALL_DIR)/usr/include/{owcapi,owfs_config}.h $(STAGING_DIR)/usr/include/
	mkdir -p $(STAGING_DIR)/usr/lib
	$(CP)	$(PKG_INSTALL_DIR)/usr/lib/libow.{a,so} $(PKG_INSTALL_DIR)/usr/lib/libowcapi.{a,so} $(STAGING_DIR)/usr/lib/
	$(CP)	$(PKG_INSTALL_DIR)/usr/lib/libow-*.so.* $(PKG_INSTALL_DIR)/usr/lib/libowcapi-*.so.* $(STAGING_DIR)/usr/lib/
endef

define Build/UninstallDev
	rm -rf	$(STAGING_DIR)/usr/include/{owcapi,owfs_config}.h \
		$(STAGING_DIR)/usr/lib/libowcapi-*.so.* \
		$(STAGING_DIR)/usr/lib/libow-*.so.* \
		$(STAGING_DIR)/usr/lib/libowcapi.{a,so} \
		$(STAGING_DIR)/usr/lib/libow.{a,so}
endef

define Package/owfs/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owfs $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owserver $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owhttpd $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owftpd $(1)/usr/bin/
	$(CP) ./files/kill-owfs $(1)/usr/bin
	$(CP) ./files/run-owfs $(1)/usr/bin
	$(INSTALL_DIR) $(1)/etc/init.d
	$(CP) ./files/owfs.init $(1)/etc/init.d/owfs
	$(CP) ./files/owserver.init $(1)/etc/init.d/owserver
	$(CP) ./files/owhttpd.init $(1)/etc/init.d/owhttpd
	$(CP) ./files/owftpd.init $(1)/etc/init.d/owftpd
	$(LN) -s ../init.d/owserver $(1)/etc/rc.d/S70owserver
	$(LN) -s ../init.d/owfs $(1)/etc/rc.d/S80owfs
	$(LN) -s ../init.d/owhttpd $(1)/etc/rc.d/S80owhttpd
	$(LN) -s ../init.d/owftpd $(1)/etc/rc.d/S80owftpd
	$(INSTALL_DIR) $(1)/etc/config
	$(CP) ./files/owfs.default $(1)/etc/config/owfs
	$(CP) ./files/owserver.default $(1)/etc/config/owserver
	$(CP) ./files/owhttpd.default $(1)/etc/config/owhttpd
	$(CP) ./files/owftpd.default $(1)/etc/config/owftpd
endef

define Package/owshell/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owread $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owwrite $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owdir $(1)/usr/bin/
	$(CP) $(PKG_INSTALL_DIR)/usr/bin/owpresent $(1)/usr/bin/
endef

define Package/owlib/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libow-*.so.* $(1)/usr/lib/
endef

define Package/owcapi/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/lib/libowcapi-*.so.* $(1)/usr/lib/
	$(INSTALL_DIR) $(1)/usr/include
	$(CP) $(PKG_INSTALL_DIR)/usr/include/{owcapi,owfs_config}.h $(1)/usr/include/
endef

define Package/owperl/install
	install -d -m0755 $(1)/usr/lib/perl5
	cp -fpR $(PKG_INSTALL_DIR)/usr/lib/perl5/* $(1)/usr/lib/perl5
	-rm -f $(1)/usr/lib/perl5/*/perllocal.pod
endef

$(eval $(call BuildPackage,owshell))
$(eval $(call BuildPackage,owlib))
$(eval $(call BuildPackage,owfs))
$(eval $(call BuildPackage,owcapi))
$(eval $(call BuildPackage,owperl))
