From ec862d472fca676cc04ce71b640e880ecefdd477 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Fri, 13 Aug 2021 08:48:02 +0200
Subject: [PATCH 26/27] lua-lzlib: backport package

Signed-off-by: John Crispin <john@phrozen.org>
---
 package/libs/lua-lzlib/Makefile               | 64 +++++++++++++++++++
 .../patches/001-allow_optim_flags.patch       | 12 ++++
 2 files changed, 76 insertions(+)
 create mode 100644 package/libs/lua-lzlib/Makefile
 create mode 100644 package/libs/lua-lzlib/patches/001-allow_optim_flags.patch

diff --git a/package/libs/lua-lzlib/Makefile b/package/libs/lua-lzlib/Makefile
new file mode 100644
index 0000000000..5e0a16b135
--- /dev/null
+++ b/package/libs/lua-lzlib/Makefile
@@ -0,0 +1,64 @@
+#
+# 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:=lua-lzlib
+PKG_VERSION:=0.4.3
+PKG_RELEASE:=1
+PKG_MAINTAINER:=Dirk Chang <dirk@kooiot.com>
+PKG_LICENSE:=MIT
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_MIRROR_HASH:=b6ef5e3f04b7f2137b39931a175ee802489a2486e70537770919bcccca10e723
+PKG_SOURCE_URL:=https://github.com/LuaDist/lzlib.git
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=79329a07d8f79c19eadd7ea2752b4c4e1574b015
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+
+HOST_BUILD_DEPENDS:=lua/host
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/host-build.mk
+
+define Package/lua-lzlib
+  SUBMENU:=Lua
+  SECTION:=lang
+  CATEGORY:=Languages
+  TITLE:=Lua zlib binding
+  URL:=http://github.com/LuaDist/lzlib
+  DEPENDS:= +lua +zlib
+endef
+
+define Package/lua-lzlib/description
+	A library to access zlib library functions and also to read/write gzip files using an interface similar to the base io package. 
+endef
+
+MAKE_FLAGS += \
+	LUA="$(STAGING_DIR)/usr" \
+	OFLAGS="$(TARGET_CFLAGS)" \
+
+HOST_MAKE_FLAGS += \
+	LUA="$(STAGING_DIR_HOSTPKG)" \
+	OFLAGS="$(HOST_CFLAGS)" \
+
+define Package/lua-lzlib/install
+	$(INSTALL_DIR) $(1)/usr/lib/lua
+	$(INSTALL_BIN) $(PKG_BUILD_DIR)/zlib.so $(1)/usr/lib/lua/
+
+	$(INSTALL_DATA) $(PKG_BUILD_DIR)/gzip.lua $(1)/usr/lib/lua/
+endef
+
+define Host/Install
+	$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/lib/lua/5.1
+	$(INSTALL_BIN) $(HOST_BUILD_DIR)/zlib.so $(STAGING_DIR_HOSTPKG)/lib/lua/5.1
+
+	$(INSTALL_DATA) $(HOST_BUILD_DIR)/gzip.lua $(STAGING_DIR_HOSTPKG)/lib/lua/5.1
+endef
+
+$(eval $(call BuildPackage,lua-lzlib))
+$(eval $(call HostBuild))
diff --git a/package/libs/lua-lzlib/patches/001-allow_optim_flags.patch b/package/libs/lua-lzlib/patches/001-allow_optim_flags.patch
new file mode 100644
index 0000000000..78f981d237
--- /dev/null
+++ b/package/libs/lua-lzlib/patches/001-allow_optim_flags.patch
@@ -0,0 +1,12 @@
+--- a/Makefile
++++ b/Makefile
+@@ -14,7 +14,8 @@ LUABIN= $(LUA)/bin
+ ZLIB=../zlib-1.2.3
+ 
+ # no need to change anything below here
+-CFLAGS= $(INCS) $(DEFS) $(WARN) -O0 -fPIC
++CFLAGS= $(INCS) $(DEFS) $(WARN) $(OFLAGS) -fPIC
++OFLAGS= -O0
+ WARN= -g -Werror -Wall -pedantic #-ansi
+ INCS= -I$(LUAINC) -I$(ZLIB)
+ LIBS= -L$(ZLIB) -lz -L$(LUALIB) -L$(LUABIN) #-llua51
-- 
2.25.1

