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
@ -73,7 +73,7 @@
return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
}
@@ -264,6 +265,14 @@ LUA_API int lua_isnumber (lua_State *L,
@@ -264,6 +265,14 @@ LUA_API int lua_isnumber (lua_State *L,
}
@ -88,7 +88,7 @@
LUA_API int lua_isstring (lua_State *L, int idx) {
int t = lua_type(L, idx);
return (t == LUA_TSTRING || t == LUA_TNUMBER);
@@ -309,31 +318,66 @@ LUA_API int lua_lessthan (lua_State *L,
@@ -309,31 +318,66 @@ LUA_API int lua_lessthan (lua_State *L,
}
@ -173,7 +173,7 @@
case LUA_TNUMBER: {
size_t l;
lua_lock(L); /* `luaV_tostring' may create a new string */
@@ -426,6 +471,8 @@ LUA_API void lua_pushnil (lua_State *L)
@@ -426,6 +471,8 @@ LUA_API void lua_pushnil (lua_State *L)
}
@ -207,7 +207,7 @@
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
@@ -569,7 +626,7 @@ LUA_API void lua_rawgeti (lua_State *L,
@@ -569,7 +626,7 @@ LUA_API void lua_rawgeti (lua_State *L,
lua_lock(L);
o = index2adr(L, idx);
api_check(L, ttistable(o));
@ -216,7 +216,7 @@
api_incr_top(L);
lua_unlock(L);
}
@@ -597,6 +654,9 @@ LUA_API int lua_getmetatable (lua_State
@@ -597,6 +654,9 @@ LUA_API int lua_getmetatable (lua_State
case LUA_TUSERDATA:
mt = uvalue(obj)->metatable;
break;
@ -226,7 +226,7 @@
default:
mt = G(L)->mt[ttype(obj)];
break;
@@ -687,7 +747,7 @@ LUA_API void lua_rawseti (lua_State *L,
@@ -687,7 +747,7 @@ LUA_API void lua_rawseti (lua_State *L,
api_checknelems(L, 1);
o = index2adr(L, idx);
api_check(L, ttistable(o));
@ -235,7 +235,7 @@
luaC_barriert(L, hvalue(o), L->top-1);
L->top--;
lua_unlock(L);
@@ -721,7 +781,7 @@ LUA_API int lua_setmetatable (lua_State
@@ -721,7 +781,7 @@ LUA_API int lua_setmetatable (lua_State
break;
}
default: {
@ -297,7 +297,7 @@
#define FREELIST_REF 0 /* free list of references */
@@ -66,7 +66,7 @@ LUALIB_API int luaL_typerror (lua_State
@@ -66,7 +66,7 @@ LUALIB_API int luaL_typerror (lua_State
static void tag_error (lua_State *L, int narg, int tag) {
@ -362,7 +362,7 @@
@@ -54,20 +56,25 @@ static int luaB_tonumber (lua_State *L)
@@ -54,20 +56,25 @@ static int luaB_tonumber (lua_State *L)
int base = luaL_optint(L, 2, 10);
if (base == 10) { /* standard conversion */
luaL_checkany(L, 1);
@ -514,7 +514,7 @@
case VKNUM:
case VTRUE:
case VFALSE:
@@ -451,6 +489,10 @@ int luaK_exp2RK (FuncState *fs, expdesc
@@ -451,6 +489,10 @@ int luaK_exp2RK (FuncState *fs, expdesc
if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
e->u.s.info = (e->k == VNIL) ? nilK(fs) :
(e->k == VKNUM) ? luaK_numberK(fs, e->u.nval) :
@ -907,7 +907,7 @@
lua_assert(isdigit(ls->current));
do {
save_and_next(ls);
@@ -202,8 +215,9 @@ static void read_numeral (LexState *ls,
@@ -202,8 +215,9 @@ static void read_numeral (LexState *ls,
save_and_next(ls);
save(ls, '\0');
buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
@ -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
@ -2114,7 +2115,7 @@
case LUA_TBOOLEAN:
return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */
case LUA_TLIGHTUSERDATA:
@@ -86,21 +106,6 @@ int luaO_rawequalObj (const TValue *t1,
@@ -86,21 +106,6 @@ int luaO_rawequalObj (const TValue *t1,
}
}
@ -2617,7 +2618,7 @@
nums[ceillog2(k)]++; /* count as such */
return 1;
}
@@ -308,7 +322,7 @@ static void resize (lua_State *L, Table
@@ -308,7 +322,7 @@ static void resize (lua_State *L, Table
/* re-insert elements from vanishing slice */
for (i=nasize; i<oldasize; i++) {
if (!ttisnil(&t->array[i]))
@ -2661,7 +2662,7 @@
} while (n);
return luaO_nilobject;
}
@@ -470,14 +487,12 @@ const TValue *luaH_get (Table *t, const
@@ -470,14 +487,12 @@ const TValue *luaH_get (Table *t, const
switch (ttype(key)) {
case LUA_TNIL: return luaO_nilobject;
case LUA_TSTRING: return luaH_getstr(t, rawtsvalue(key));
@ -3072,7 +3073,7 @@
/*
@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
** CHANGE it if your system requires alignments larger than double. (For
@@ -728,28 +652,6 @@ union luai_Cast { double l_d; long l_l;
@@ -728,28 +652,6 @@ union luai_Cast { double l_d; long l_l;
#define luai_userstateyield(L,n) ((void)L)
@ -3103,7 +3104,7 @@
/*
--- a/src/lundump.c
+++ b/src/lundump.c
@@ -73,6 +73,13 @@ static lua_Number LoadNumber(LoadState*
@@ -73,6 +73,13 @@ static lua_Number LoadNumber(LoadState*
return x;
}
@ -3117,7 +3118,7 @@
static TString* LoadString(LoadState* S)
{
size_t size;
@@ -119,6 +126,9 @@ static void LoadConstants(LoadState* S,
@@ -119,6 +126,9 @@ static void LoadConstants(LoadState* S,
case LUA_TNUMBER:
setnvalue(o,LoadNumber(S));
break;
@ -3209,7 +3210,7 @@
setsvalue2s(L, obj, luaS_new(L, s));
return 1;
}
@@ -222,59 +234,127 @@ static int l_strcmp (const TString *ls,
@@ -222,59 +234,127 @@ static int l_strcmp (const TString *ls,
}
@ -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