package = "nixio"
version = "0.4-1"
source = {
   url = "https://github.com/openwrt/luci/archive/luci-0.10.zip",
   dir = "luci-luci-0.10/libs/nixio",
}
description = {
   summary = "System, Networking and I/O library for Lua",
   detailed = [[
      Nixio is a multi-platform library offering a wide variety
      of features such as IPv4, IPv6 and UNIX networking, large file I/O, file
      system operations, system and process control, POSIX user/group management,
      basic cryptographical hashing, hmac and TLS support, bit operations and
      binary conversion.
   ]],
   homepage = "https://github.com/openwrt/luci",
   license = "Apache 2.0",
   maintainer = "Steven Barth",
}
dependencies = {
   "lua >= 5.1"
}
external_dependencies = {
   OPENSSL = {
      header = "openssl/ssl.h",
   }
}
build = {
   type = "make",
   build_variables = {
      NIXIO_LDFLAGS = "-lcrypt -L$(OPENSSL_LIBDIR) -I$(OPENSSL_INCDIR)",
      LUA_CFLAGS = "$(CFLAGS) -I$(LUA_INCDIR)",
   },
   install_variables = {
      LUA_MODULEDIR = "$(LUADIR)",
      LUA_LIBRARYDIR = "$(LIBDIR)",
   },
   patches = {
      ["fix_linking.patch"] = [[
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ src/axtls-compat.o: src/libaxtls.a src/axtls-compat.c
 endif	
 
 compile: $(NIXIO_OBJ)
-	$(LINK) $(SHLIB_FLAGS) $(NIXIO_LDFLAGS) -o src/$(NIXIO_SO) $(NIXIO_OBJ) $(NIXIO_LDFLAGS_POST)
+	$(LINK) $(SHLIB_FLAGS) -o src/$(NIXIO_SO) $(NIXIO_OBJ) $(NIXIO_LDFLAGS) $(NIXIO_LDFLAGS_POST)
 	mkdir -p dist$(LUA_LIBRARYDIR)
 	cp src/$(NIXIO_SO) dist$(LUA_LIBRARYDIR)/$(NIXIO_SO)
 
      ]],
      ["gcc_werror_memcpy.patch"] = [[
--- a/src/bind.c
+++ b/src/bind.c
@@ -256,7 +256,7 @@ static int nixio_sock_accept(lua_State *L) {
 	luaL_getmetatable(L, NIXIO_META);
 	lua_setmetatable(L, -2);
 
-	memcpy(clsock, sock, sizeof(clsock));
+	memcpy(clsock, sock, sizeof(nixio_sock));
 	clsock->fd = newfd;
 
 	if (!nixio__addr_parse(&addr, (struct sockaddr *)&saddr)) {
      ]],
      ["fix_lua51plus.patch"] = [[
--- a/src/address.c	2020-02-24 09:30:39.528097040 +0100
+++ b/src/address.c	2020-02-24 09:31:47.064228133 +0100
@@ -495,7 +495,7 @@
 
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 #if defined(__linux__) || defined(BSD)
 	{"getifaddrs",	nixio_getifaddrs},
 #endif
@@ -505,7 +505,7 @@
 };
 
 /* object table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"getsockname",	nixio_sock_getsockname},
 	{"getpeername",	nixio_sock_getpeername},
 	{NULL,			NULL}
--- a/src/user.c	2020-02-24 09:33:08.252374721 +0100
+++ b/src/user.c	2020-02-24 09:33:28.356409535 +0100
@@ -238,7 +238,7 @@
 
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"crypt",		nixio_crypt},
 	{"getgr",		nixio_getgr},
 	{"getpw",		nixio_getpw},
@@ -252,7 +252,7 @@
 
 #else /* __WINNT__ */
 
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 		{NULL,			NULL}
 };
 
--- a/src/protoent.c	2020-02-24 09:34:47.272541696 +0100
+++ b/src/protoent.c	2020-02-24 09:35:01.816565378 +0100
@@ -91,7 +91,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
     {"getprotobyname",		nixio_getprotobyname},
     {"getprotobynumber",	nixio_getprotobynumber},
     {"getproto",			nixio_getproto},
--- a/src/socket.c	2020-02-24 09:36:57.164747520 +0100
+++ b/src/socket.c	2020-02-24 09:38:54.677386177 +0100
@@ -150,13 +150,13 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"socket",		nixio_socket},
 	{NULL,			NULL}
 };
 
 /* object table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"close",		nixio_sock_close},
 	{"shutdown",	nixio_sock_shutdown},
 	{"__gc",		nixio_sock__gc},
--- a/src/tls-crypto.c	2020-02-24 09:39:51.305730619 +0100
+++ b/src/tls-crypto.c	2020-02-24 09:40:08.493830295 +0100
@@ -154,14 +154,14 @@
 
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"hash",		nixio_crypto_hash},
 	{"hmac",		nixio_crypto_hmac},
 	{NULL,			NULL}
 };
 
 /* hash table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"update",		nixio_crypto_hash_update},
 	{"final",		nixio_crypto_hash_final},
 	{"__gc",		nixio_crypto_hash__gc},
--- a/src/tls-socket.c	2020-02-24 09:41:27.770263449 +0100
+++ b/src/tls-socket.c	2020-02-24 09:41:43.066342350 +0100
@@ -239,7 +239,7 @@
 
 
 /* ctx function table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"recv", 		nixio_tls_sock_recv},
 	{"send", 		nixio_tls_sock_send},
 	{"read", 		nixio_tls_sock_recv},
--- a/src/file.c	2020-02-24 09:42:25.202552551 +0100
+++ b/src/file.c	2020-02-24 09:42:48.406664055 +0100
@@ -347,7 +347,7 @@
 }
 
 /* method table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"write",		nixio_file_write},
 	{"read",		nixio_file_read},
 	{"tell",		nixio_file_tell},
@@ -362,7 +362,7 @@
 };
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"dup",			nixio_dup},
 	{"open",		nixio_open},
 	{"open_flags",	nixio_open_flags},
--- a/src/sockopt.c	2020-02-24 09:43:41.418908313 +0100
+++ b/src/sockopt.c	2020-02-24 09:43:55.262969836 +0100
@@ -366,7 +366,7 @@
 }
 
 /* module table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"setblocking", nixio_sock_setblocking},
 	{"getsockopt",	nixio_sock_getsockopt},
 	{"setsockopt",	nixio_sock_setsockopt},
--- a/src/syslog.c	2020-02-24 09:45:04.203263414 +0100
+++ b/src/syslog.c	2020-02-24 09:45:23.395341597 +0100
@@ -102,7 +102,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"openlog",		nixio_openlog},
 	{"syslog",		nixio_syslog},
 	{"setlogmask",	nixio_setlogmask},
--- a/src/io.c	2020-02-24 09:46:18.647558823 +0100
+++ b/src/io.c	2020-02-24 09:46:26.647589360 +0100
@@ -208,7 +208,7 @@
 
 
 /* module table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"send",	nixio_sock_send},
 	{"sendto",	nixio_sock_sendto},
 	{"recv",	nixio_sock_recv},
--- a/src/tls-context.c	2020-02-24 09:47:01.763720833 +0100
+++ b/src/tls-context.c	2020-02-24 09:47:12.147758937 +0100
@@ -203,13 +203,13 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"tls",		nixio_tls_ctx},
 	{NULL,			NULL}
 };
 
 /* ctx function table */
-static const luaL_reg CTX_M[] = {
+static const luaL_Reg CTX_M[] = {
 	{"set_cert",			nixio_tls_ctx_set_cert},
 	{"set_verify_locations",       nixio_tls_ctx_set_verify_locations},
 	{"set_key",				nixio_tls_ctx_set_key},
--- a/src/splice.c	2020-02-24 09:48:04.455945834 +0100
+++ b/src/splice.c	2020-02-24 09:48:13.991979042 +0100
@@ -161,7 +161,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 #ifdef _GNU_SOURCE
 #ifdef SPLICE_F_MOVE
 	{"splice",			nixio_splice},
--- a/src/process.c	2020-02-24 09:48:50.136102633 +0100
+++ b/src/process.c	2020-02-24 09:49:09.072166009 +0100
@@ -412,7 +412,7 @@
 
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 #ifdef __linux__
 	{"sysinfo",		nixio_sysinfo},
 #endif
--- a/src/fs.c	2020-02-24 09:50:06.716353517 +0100
+++ b/src/fs.c	2020-02-24 09:50:24.808410790 +0100
@@ -519,7 +519,7 @@
 
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 #ifndef __WINNT__
 	{"glob",		nixio_glob},
 	{"mkfifo",		nixio_mkfifo},
--- a/src/poll.c	2020-02-24 09:51:25.020596421 +0100
+++ b/src/poll.c	2020-02-24 09:51:45.956659287 +0100
@@ -197,7 +197,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"gettimeofday", nixio_gettimeofday},
 	{"nanosleep",	nixio_nanosleep},
 	{"poll",		nixio_poll},
--- a/src/binary.c	2020-02-24 09:52:26.304778182 +0100
+++ b/src/binary.c	2020-02-24 09:52:38.696814127 +0100
@@ -296,7 +296,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"hexlify",		nixio_bin_hexlify},
 	{"unhexlify",	nixio_bin_unhexlify},
 	{"crc32",		nixio_bin_crc32},
--- a/src/bit.c	2020-02-24 09:53:27.084952096 +0100
+++ b/src/bit.c	2020-02-24 09:53:35.108974622 +0100
@@ -120,7 +120,7 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"bor",			nixio_bit_or},
 	{"set",			nixio_bit_or},
 	{"band",		nixio_bit_and},
--- a/src/nixio.c	2020-02-24 09:54:22.557105906 +0100
+++ b/src/nixio.c	2020-02-24 09:54:30.853128537 +0100
@@ -102,7 +102,7 @@
 }
 
 /* object table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"errno",		nixio_errno},
 	{"strerror",	nixio_strerror},
 	{NULL,			NULL}
--- a/src/bind.c	2020-02-24 09:55:58.201361498 +0100
+++ b/src/bind.c	2020-02-24 09:57:04.837533334 +0100
@@ -269,14 +269,14 @@
 }
 
 /* module table */
-static const luaL_reg R[] = {
+static const luaL_Reg R[] = {
 	{"bind",		nixio_bind},
 	{"connect",		nixio_connect},
 	{NULL,			NULL}
 };
 
 /* object table */
-static const luaL_reg M[] = {
+static const luaL_Reg M[] = {
 	{"bind",		nixio_sock_bind},
 	{"connect",		nixio_sock_connect},
 	{"listen",		nixio_sock_listen},
--- a/src/nixio.h	2020-02-24 09:59:40.441918349 +0100
+++ b/src/nixio.h	2020-02-24 10:04:06.490537909 +0100
@@ -21,6 +21,10 @@
 #include <lauxlib.h>
 #include <luaconf.h>
 
+#if LUA_VERSION_NUM < 501
+#define luaL_Reg luaL_reg
+#endif
+
 #define NIXIO_BUFFERSIZE 8192
 
 typedef struct nixio_socket {
      ]],
   }
}
