lua: fix build with MacOS's make

This commit is contained in:
lean 2020-03-25 13:42:28 +08:00
parent 334f365c2b
commit d29f9dbeb9
8 changed files with 254 additions and 36 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=lua
PKG_VERSION:=5.1.5
PKG_RELEASE:=1
PKG_RELEASE:=7
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
@ -46,6 +46,7 @@ $(call Package/lua/Default)
SECTION:=libs
CATEGORY:=Libraries
TITLE+= (libraries)
ABI_VERSION:=5.1.5
endef
define Package/liblua/description
@ -98,7 +99,7 @@ define Build/Compile
RANLIB="$(TARGET_CROSS)ranlib" \
INSTALL_ROOT=/usr \
CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \
MYLDFLAGS="$(TARGET_LDFLAGS)" \
MYLDFLAGS="$(TARGET_LDFLAGS) $(if $(CONFIG_USE_GLIBC),-lm)" \
PKG_VERSION=$(PKG_VERSION) \
linux
rm -rf $(PKG_INSTALL_DIR)
@ -132,11 +133,15 @@ define Host/Install
$(MAKE) -C $(HOST_BUILD_DIR) \
INSTALL_TOP="$(STAGING_DIR_HOSTPKG)" \
install
$(LN) $(STAGING_DIR_HOSTPKG)/bin/lua5.1 $(STAGING_DIR_HOSTPKG)/bin/lua
$(LN) $(STAGING_DIR_HOSTPKG)/bin/luac5.1 $(STAGING_DIR_HOSTPKG)/bin/luac
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/lua{,lib,conf}.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lua.hpp $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lauxlib.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lnum_config.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
@ -153,12 +158,14 @@ endef
define Package/lua/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/lua $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/lua5.1 $(1)/usr/bin/
$(LN) lua5.1 $(1)/usr/bin/lua
endef
define Package/luac/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/luac $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/luac5.1 $(1)/usr/bin/
$(LN) luac5.1 $(1)/usr/bin/luac
endef
define Package/lua-examples/install

View File

@ -0,0 +1,57 @@
From 96576b44a1b368bd6590eb0778ae45cc9ccede3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
Date: Fri, 21 Jun 2019 14:08:38 +0200
Subject: [PATCH] include version number
Including it allows multiple lua versions to coexist.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -41,10 +41,10 @@ RANLIB= ranlib
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
# What to install.
-TO_BIN= lua luac
+TO_BIN= lua$V luac$V
TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
TO_LIB= liblua.a
-TO_MAN= lua.1 luac.1
+TO_MAN= lua$V.1 luac$V.1
# Lua version and release.
V= 5.1
@@ -53,7 +53,7 @@ R= 5.1.5
all: $(PLAT)
$(PLATS) clean:
- cd src && $(MAKE) $@
+ cd src && $(MAKE) $@ V=$V
test: dummy
src/lua test/hello.lua
diff --git a/doc/lua.1 b/doc/lua5.1.1
rename from doc/lua.1
rename to doc/lua5.1.1
diff --git a/doc/luac.1 b/doc/luac5.1.1
rename from doc/luac.1
rename to doc/luac5.1.1
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,10 +29,10 @@ CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
lstrlib.o loadlib.o linit.o
-LUA_T= lua
+LUA_T= lua$V
LUA_O= lua.o
-LUAC_T= luac
+LUAC_T= luac$V
LUAC_O= luac.o print.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)

View File

@ -1,13 +1,13 @@
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@
@@ -42,7 +42,7 @@ PLATS= aix ansi bsd freebsd generic linu
# What to install.
TO_BIN= lua luac
TO_BIN= lua$V luac$V
-TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
+TO_INC= lua.h luaconf.h lualib.h lauxlib.h lnum_config.h ../etc/lua.hpp
TO_LIB= liblua.a
TO_MAN= lua.1 luac.1
TO_MAN= lua$V.1 luac$V.1
--- a/src/Makefile
+++ b/src/Makefile
@ -1020,6 +1020,7 @@
-#define PI (3.14159265358979323846)
-#define RADIANS_PER_DEGREE (PI/180.0)
-
-
+#ifdef LNUM_FLOAT
+# define PI (3.14159265358979323846F)
+#elif defined(M_PI)
@ -1028,7 +1029,7 @@
+# define PI (3.14159265358979323846264338327950288)
+#endif
+#define RADIANS_PER_DEGREE (PI/180)
+
+#undef HUGE
+#ifdef LNUM_FLOAT
+# define HUGE HUGE_VALF
@ -3432,10 +3433,10 @@
+ case TM_POW: if (try_powint( ri, ib, ic)) return; break;
+ case TM_UNM: if (try_unmint( ri, ib)) return; break;
+ default: lua_assert(0);
+ }
}
+ }
+ /* Fallback to floating point, when leaving range. */
+
+#ifdef LNUM_COMPLEX
+ if ((nvalue_img(b)!=0) || (nvalue_img(c)!=0)) {
+ lua_Complex r;
@ -3455,7 +3456,7 @@
+ default: lua_assert(0); r=0;
+ }
+ setnvalue_complex( ra, r );
}
+ }
+ return;
+ }
+#endif
@ -3476,7 +3477,7 @@
+ if (!call_binTM(L, rb, rc, ra, op))
+ luaG_aritherror(L, rb, rc);
+}
+
+/* Helper macro to sort arithmetic operations into four categories:
+ * TK_INT: integer - integer operands
+ * TK_NUMBER: number - number (non complex, either may be integer)

View File

@ -1,6 +1,6 @@
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -284,7 +284,8 @@ int luaV_lessthan (lua_State *L, const T
@@ -281,7 +281,8 @@ int luaV_lessthan (lua_State *L, const T
else
return luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
@ -10,7 +10,7 @@
return res;
return luaG_ordererror(L, l, r);
@@ -322,7 +323,8 @@ static int lessequal (lua_State *L, cons
@@ -319,7 +320,8 @@ static int lessequal (lua_State *L, cons
else
return luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );

View File

@ -0,0 +1,48 @@
diff --git a/src/lnum.c b/src/lnum.c
index 1456b6a2ed23..b0632b04c2b7 100644
--- a/src/lnum.c
+++ b/src/lnum.c
@@ -127,6 +127,8 @@ static int luaO_str2i (const char *s, lua_Integer *res, char **endptr_ref) {
#else
return 0; /* Reject the number */
#endif
+ } else if (v > LUA_INTEGER_MAX) {
+ return TK_NUMBER;
}
} else if ((v > LUA_INTEGER_MAX) || (*endptr && (!isspace(*endptr)))) {
return TK_NUMBER; /* not in signed range, or has '.', 'e' etc. trailing */
@@ -310,3 +312,13 @@ int try_unmint( lua_Integer *r, lua_Integer ib ) {
return 0;
}
+#ifdef LONG_OVERFLOW_LUA_INTEGER
+unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base ) {
+ unsigned long v= strtoul(str, endptr, base);
+ if ( v > LUA_INTEGER_MAX ) {
+ errno= ERANGE;
+ v= ULONG_MAX;
+ }
+ return (unsigned LUA_INTEGER)v;
+}
+#endif
diff --git a/src/lnum_config.h b/src/lnum_config.h
index 19d7a4231a49..1092eead6629 100644
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -141,7 +141,12 @@
#endif
#ifndef lua_str2ul
-# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# if LONG_MAX > LUA_INTEGER_MAX
+# define LONG_OVERFLOW_LUA_INTEGER
+ unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base );
+# else
+# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# endif
#endif
#ifndef LUA_INTEGER_MIN
# define LUA_INTEGER_MIN (-LUA_INTEGER_MAX -1) /* -2^16|32 */
--
1.9.1

View File

@ -0,0 +1,57 @@
From 96576b44a1b368bd6590eb0778ae45cc9ccede3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
Date: Fri, 21 Jun 2019 14:08:38 +0200
Subject: [PATCH] include version number
Including it allows multiple lua versions to coexist.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -41,10 +41,10 @@ RANLIB= ranlib
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
# What to install.
-TO_BIN= lua luac
+TO_BIN= lua$V luac$V
TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
TO_LIB= liblua.a
-TO_MAN= lua.1 luac.1
+TO_MAN= lua$V.1 luac$V.1
# Lua version and release.
V= 5.1
@@ -53,7 +53,7 @@ R= 5.1.5
all: $(PLAT)
$(PLATS) clean:
- cd src && $(MAKE) $@
+ cd src && $(MAKE) $@ V=$V
test: dummy
src/lua test/hello.lua
diff --git a/doc/lua.1 b/doc/lua5.1.1
rename from doc/lua.1
rename to doc/lua5.1.1
diff --git a/doc/luac.1 b/doc/luac5.1.1
rename from doc/luac.1
rename to doc/luac5.1.1
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,10 +29,10 @@ CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
lstrlib.o loadlib.o linit.o
-LUA_T= lua
+LUA_T= lua$V
LUA_O= lua.o
-LUAC_T= luac
+LUAC_T= luac$V
LUAC_O= luac.o print.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)

View File

@ -0,0 +1,48 @@
diff --git a/src/lnum.c b/src/lnum.c
index 1456b6a2ed23..b0632b04c2b7 100644
--- a/src/lnum.c
+++ b/src/lnum.c
@@ -127,6 +127,8 @@ static int luaO_str2i (const char *s, lua_Integer *res, char **endptr_ref) {
#else
return 0; /* Reject the number */
#endif
+ } else if (v > LUA_INTEGER_MAX) {
+ return TK_NUMBER;
}
} else if ((v > LUA_INTEGER_MAX) || (*endptr && (!isspace(*endptr)))) {
return TK_NUMBER; /* not in signed range, or has '.', 'e' etc. trailing */
@@ -310,3 +312,13 @@ int try_unmint( lua_Integer *r, lua_Integer ib ) {
return 0;
}
+#ifdef LONG_OVERFLOW_LUA_INTEGER
+unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base ) {
+ unsigned long v= strtoul(str, endptr, base);
+ if ( v > LUA_INTEGER_MAX ) {
+ errno= ERANGE;
+ v= ULONG_MAX;
+ }
+ return (unsigned LUA_INTEGER)v;
+}
+#endif
diff --git a/src/lnum_config.h b/src/lnum_config.h
index 19d7a4231a49..1092eead6629 100644
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -141,7 +141,12 @@
#endif
#ifndef lua_str2ul
-# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# if LONG_MAX > LUA_INTEGER_MAX
+# define LONG_OVERFLOW_LUA_INTEGER
+ unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base );
+# else
+# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# endif
#endif
#ifndef LUA_INTEGER_MIN
# define LUA_INTEGER_MIN (-LUA_INTEGER_MAX -1) /* -2^16|32 */
--
1.9.1

View File

@ -3,12 +3,12 @@
@@ -42,8 +42,8 @@ PLATS= aix ansi bsd freebsd generic linu
# What to install.
TO_BIN= lua luac
TO_BIN= lua$V luac$V
-TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
-TO_LIB= liblua.a
+TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp lnum_config.h
+TO_LIB= liblua.a liblua.so.$R
TO_MAN= lua.1 luac.1
TO_MAN= lua$V.1 luac$V.1
# Lua version and release.
@@ -63,6 +63,7 @@ install: dummy
@ -87,10 +87,10 @@
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
lundump.o lvm.o lzio.o lnum.o
@@ -33,11 +34,12 @@ LUA_T= lua
@@ -33,11 +34,12 @@ LUA_T= lua$V
LUA_O= lua.o
LUAC_T= luac
LUAC_T= luac$V
-LUAC_O= luac.o print.o
+LUAC_O= luac.o print.o lopcodes.o