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

include $(TOPDIR)/rules.mk

PKG_NAME:=luastruct
PKG_VERSION:=0.3
PKG_RELEASE:=1
PKG_MAINTAINER:=Dirk Chang <dirk@kooiot.com>
PKG_LICENSE:=MIT

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.inf.puc-rio.br/~roberto/struct/struct-0.3.tar.gz
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_HASH:=007a6fd5e42023c4add504cd541871e56d5eb245a7e6c23c582997eee9841b53

PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk

define Package/luastruct
  SUBMENU:=Lua
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=luastruct
  URL:=https://github.com/Kong/luastruct
  DEPENDS:=+lua
endef

define Package/luastruct/description
  pack binary parser/builder for Lua
endef

TARGET_CFLAGS += $(FPIC) -DUSE_GLOBALS

# add make variable overrides here
MAKE_FLAGS += -DUSE_GLOBALS

define Build/Configure
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		PREFIX="$(STAGING_DIR)/usr" \
		LUA_LIBDIR="$(STAGING_DIR)/usr/lib/lua" \
		LUA_INCDIR="$(STAGING_DIR)/usr/include" \
		LIB_OPTION="-shared" \
		CC="$(TARGET_CROSS)gcc" \
		CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
		struct.so
endef

define Build/Install
endef

define Package/luastruct/install
	$(INSTALL_DIR) $(1)/usr/lib/lua/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/struct.so $(1)/usr/lib/lua/struct.so
endef

$(eval $(call BuildPackage,luastruct))
