include $(TOPDIR)/rules.mk

PKG_NAME:=rathole-client
VERSION_YEAR=$(shell date +%Y)
VERSION_MAJOR=$(shell expr $(VERSION_YEAR) - 2018)
VERSION_MINOR=$(shell date +%V%u)
#VERSION_REVISION=$(shell date +%H%M)
VERSION_REVISION=0001
PKG_VERSION:=$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)


include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
	SECTION:=DYIOT
	CATEGORY:=DYIOT Software
	TITLE:=rathole reverse proxy client
	DEPENDS:=+libopenssl
endef

define Package/$(PKG_NAME)/description
	https://github.com/rapiz1/rathole
endef

define Package/$(PKG_NAME)/conffiles
	/app/config/rathole.toml
endef

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

define Build/Compile
	CC="$(TARGET_CC)" \
	CFLAGS="$(TARGET_CFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	$(MAKE) $(PKG_MFLAGS) -C $(PKG_BUILD_DIR) \
		$(TARGET_CONFIGURE_OPTS) all
endef

define Package/$(PKG_NAME)/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_DIR) $(1)/app/config/
	$(INSTALL_DIR) $(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/rathole $(1)/usr/bin/
	$(INSTALL_BIN) ./files/rathole.initd $(1)/etc/init.d/rathole
	$(INSTALL_DATA) $(PKG_BUILD_DIR)/rathole.toml $(1)/app/config/
endef

$(eval $(call BuildPackage,$(PKG_NAME)))
