mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-22 06:43:27 +00:00
Add initial NX64 support.
This commit is contained in:
parent
68bb11405c
commit
5cc85d5a48
@ -181,6 +181,12 @@ LuaJIT currently builds out-of-the box on most systems:
|
||||
<td class="compatx">Xbox One SDK (DURANGO)</td>
|
||||
<td class="compatx">v2.1 –</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td class="compatname"><a href="#consoles">Nintendo Switch</a></td>
|
||||
<td class="compatver"> </td>
|
||||
<td class="compatx">NintendoSDK + NX Addon</td>
|
||||
<td class="compatx">v2.1 –</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
The codebase has compatibility defines for some more systems, but
|
||||
@ -648,6 +654,21 @@ the following commands:
|
||||
cd src
|
||||
xb1build
|
||||
</pre>
|
||||
<p>
|
||||
To cross-compile for <b id="nx">Nintendo Switch</b> from a Windows host,
|
||||
open a "Visual Studio .NET Command Prompt" (64 bit host compiler),
|
||||
<tt>cd</tt> to the directory where you've unpacked the sources and run
|
||||
any of the following commands, depending on the NX32 or NX64 target:
|
||||
</p>
|
||||
<pre class="code">
|
||||
cd src
|
||||
nx32build
|
||||
</pre>
|
||||
|
||||
<pre class="code">
|
||||
cd src
|
||||
nx64build
|
||||
</pre>
|
||||
|
||||
<h2 id="embed">Embedding LuaJIT</h2>
|
||||
<p>
|
||||
|
@ -162,7 +162,7 @@ LuaJIT is Copyright © 2005-2022 Mike Pall, released under the
|
||||
<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td></tr>
|
||||
</table>
|
||||
<table class="feature os os3">
|
||||
<tr><td>PS3</td><td>PS4</td><td>PS5</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td></tr>
|
||||
<tr><td>PS3</td><td>PS4</td><td>PS5</td><td>PS Vita</td><td>Xbox 360</td><td>Xbox One</td><td>Nintendo Switch</td></tr>
|
||||
</table>
|
||||
<table class="feature compiler">
|
||||
<tr><td>GCC</td><td>Clang<br>LLVM</td><td>MSVC</td></tr>
|
||||
|
@ -439,7 +439,7 @@ LJLIB_CF(io_popen)
|
||||
LJLIB_CF(io_tmpfile)
|
||||
{
|
||||
IOFileUD *iof = io_file_new(L);
|
||||
#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA
|
||||
#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA || JL_TARGET_NX
|
||||
iof->fp = NULL; errno = ENOSYS;
|
||||
#else
|
||||
iof->fp = tmpfile();
|
||||
|
@ -76,7 +76,7 @@ LJLIB_CF(os_rename)
|
||||
|
||||
LJLIB_CF(os_tmpname)
|
||||
{
|
||||
#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA
|
||||
#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_PSVITA || LJ_TARGET_NX
|
||||
lj_err_caller(L, LJ_ERR_OSUNIQF);
|
||||
return 0;
|
||||
#else
|
||||
|
@ -169,6 +169,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __NX__
|
||||
#define LJ_TARGET_NX 1
|
||||
#define LJ_TARGET_CONSOLE 1
|
||||
#undef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
/* -- Arch-specific settings ---------------------------------------------- */
|
||||
|
||||
/* Set target architecture properties. */
|
||||
@ -641,7 +648,7 @@ extern void *LJ_WIN_LOADLIBA(const char *path);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5
|
||||
#if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5 || LJ_TARGET_NX
|
||||
#define LJ_NO_UNWIND 1
|
||||
#endif
|
||||
|
||||
|
@ -443,9 +443,9 @@ typedef struct jit_State {
|
||||
int32_t framedepth; /* Current frame depth. */
|
||||
int32_t retdepth; /* Return frame depth (count of RETF). */
|
||||
|
||||
uint32_t k32[LJ_K32__MAX]; /* Common 4 byte constants used by backends. */
|
||||
//uint32_t k32[LJ_K32__MAX]; /* Common 4 byte constants used by backends. */
|
||||
TValue ksimd[LJ_KSIMD__MAX*2+1]; /* 16 byte aligned SIMD constants. */
|
||||
TValue k64[LJ_K64__MAX]; /* Common 8 byte constants. */
|
||||
//TValue k64[LJ_K64__MAX]; /* Common 8 byte constants. */
|
||||
|
||||
IRIns *irbuf; /* Temp. IR instruction buffer. Biased with REF_BIAS. */
|
||||
IRRef irtoplim; /* Upper limit of instuction buffer (biased). */
|
||||
|
@ -87,6 +87,10 @@ extern int sys_get_random_number(void *buf, uint64_t len);
|
||||
|
||||
extern int sceRandomGetRandomNumber(void *buf, size_t len);
|
||||
|
||||
#elif LJ_TARGET_NX
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOXONE
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@ -176,6 +180,11 @@ int LJ_FASTCALL lj_prng_seed_secure(PRNGState *rs)
|
||||
if (sceRandomGetRandomNumber(rs->u, sizeof(rs->u)) == 0)
|
||||
goto ok;
|
||||
|
||||
#elif LJ_TARGET_NX
|
||||
|
||||
if (getentropy(rs->u, sizeof(rs->u)) == 0)
|
||||
goto ok;
|
||||
|
||||
#elif LJ_TARGET_UWP || LJ_TARGET_XBOXONE
|
||||
|
||||
if (BCryptGenRandom(NULL, (PUCHAR)(rs->u), (ULONG)sizeof(rs->u),
|
||||
|
130
src/ninten.bat
Normal file
130
src/ninten.bat
Normal file
@ -0,0 +1,130 @@
|
||||
@rem Script to build LuaJIT with NintendoSDK + NX Addon.
|
||||
@rem Donated to the public domain.
|
||||
@rem
|
||||
@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)
|
||||
@rem or "VS20xx x64 Native Tools Command Prompt".
|
||||
@rem
|
||||
@rem Then cd to this directory and run this script.
|
||||
@rem
|
||||
@rem Recommended invocation:
|
||||
@rem
|
||||
@rem nxbuild release build, amalgamated
|
||||
@rem nxbuild debug debug build, amalgamated
|
||||
@rem
|
||||
@rem Additional command-line options (not generally recommended):
|
||||
@rem
|
||||
@rem nx32 (before debug) 32-bit target library
|
||||
@rem noamalg (after debug) non-amalgamated build
|
||||
|
||||
@if not defined INCLUDE goto :FAIL
|
||||
@if not defined NINTENDO_SDK_ROOT goto :FAIL
|
||||
|
||||
@setlocal
|
||||
@rem ---- Host compiler ----
|
||||
@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE
|
||||
@set LJLINK=link /nologo
|
||||
@set LJMT=mt /nologo
|
||||
@set DASMDIR=..\dynasm
|
||||
@set DASM=%DASMDIR%\dynasm.lua
|
||||
@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
|
||||
::@set DASC=vm_arm.dasc
|
||||
|
||||
|
||||
::@if "%1" neq "nx32" goto :NOGC32
|
||||
@set DASC=vm_arm.dasc
|
||||
:::NOGC32
|
||||
|
||||
%LJCOMPILE% host\minilua.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:minilua.exe minilua.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist minilua.exe.manifest^
|
||||
%LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
|
||||
|
||||
@rem Check for 64 bit host compiler.
|
||||
@minilua
|
||||
@if not errorlevel 8 goto :FAIL
|
||||
|
||||
@set DASMFLAGS=-D HFABI -D FPU -D NO_UNWIND -D LUAJIT_TARGET=LUAJIT_ARCH_ARM -D LUAJIT_OS=LUAJIT_OS_OTHER -D LUAJIT_DISABLE_JIT -D LUAJIT_DISABLE_FFI
|
||||
minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:buildvm.exe buildvm*.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist buildvm.exe.manifest^
|
||||
%LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
|
||||
|
||||
buildvm -m elfasm -o lj_vm.s
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m libdef -o lj_libdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m recdef -o lj_recdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
|
||||
@rem ---- Cross compiler ----
|
||||
@if "%1" neq "nx32" goto :NX32BUILD
|
||||
@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_DISABLE_JIT -DLUAJIT_SECURITY_PRNG=0 -DLUAJIT_USE_SYSMALLOC -DNN_NINTENDO_SDK %GC64% -c
|
||||
@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-ar" rc
|
||||
@set TARGETLIB_SUFFIX="nx64"
|
||||
|
||||
%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-as -o lj_vm.o lj_vm.s
|
||||
goto :DEBUGCHECK
|
||||
|
||||
:NX32BUILD
|
||||
@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_DISABLE_JIT -DLUAJIT_SECURITY_PRNG=0 -DLUAJIT_USE_SYSMALLOC -DNN_NINTENDO_SDK %GC64% -c
|
||||
@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar" rc
|
||||
@set TARGETLIB_SUFFIX="nx32"
|
||||
|
||||
%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar -o lj_vm.o lj_vm.s
|
||||
:DEBUGCHECK
|
||||
|
||||
@if "%1" neq "debug" goto :NODEBUG
|
||||
@shift
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_DEBUG -g -O0
|
||||
@set TARGETLIB=liblua51D_%TARGETLIB_SUFFIX%.a
|
||||
goto :BUILD
|
||||
:NODEBUG
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_RELEASE -O3
|
||||
@set TARGETLIB=liblua51_%TARGETLIB_SUFFIX%.a
|
||||
:BUILD
|
||||
del %TARGETLIB%
|
||||
@if "%1" neq "noamalg" goto :AMALG
|
||||
for %%f in (lj_*.c lib_*.c) do (
|
||||
%LJCOMPILE% %%f
|
||||
@if errorlevel 1 goto :BAD
|
||||
)
|
||||
|
||||
%LJLIB% %TARGETLIB% lj_*.o lib_*.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
@goto :NOAMALG
|
||||
:AMALG
|
||||
%LJCOMPILE% ljamalg.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
:NOAMALG
|
||||
|
||||
@del *.o *.obj *.manifest minilua.exe buildvm.exe
|
||||
@echo.
|
||||
@echo === Successfully built LuaJIT for Nintendo Switch ===
|
||||
|
||||
@goto :END
|
||||
:BAD
|
||||
@echo.
|
||||
@echo *******************************************************
|
||||
@echo *** Build FAILED -- Please check the error messages ***
|
||||
@echo *******************************************************
|
||||
@goto :END
|
||||
:FAIL
|
||||
@echo To run this script you must open a "Visual Studio .NET Command Prompt"
|
||||
@echo (64 bit host compiler). NintendoSDK + NX Addon must be installed, too.
|
||||
:END
|
130
src/nxbuild.bat
Normal file
130
src/nxbuild.bat
Normal file
@ -0,0 +1,130 @@
|
||||
@rem Script to build LuaJIT with NintendoSDK + NX Addon.
|
||||
@rem Donated to the public domain.
|
||||
@rem
|
||||
@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)
|
||||
@rem or "VS20xx x64 Native Tools Command Prompt".
|
||||
@rem
|
||||
@rem Then cd to this directory and run this script.
|
||||
@rem
|
||||
@rem Recommended invocation:
|
||||
@rem
|
||||
@rem nxbuild release build, amalgamated
|
||||
@rem nxbuild debug debug build, amalgamated
|
||||
@rem
|
||||
@rem Additional command-line options (not generally recommended):
|
||||
@rem
|
||||
@rem nx32 (before debug) 32-bit target library
|
||||
@rem noamalg (after debug) non-amalgamated build
|
||||
|
||||
::@if not defined INCLUDE goto :FAIL
|
||||
@if not defined NINTENDO_SDK_ROOT goto :FAIL
|
||||
|
||||
@setlocal
|
||||
@rem ---- Host compiler ----
|
||||
@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /wo4146 /wo4244 /D_CRT_SECURE_NO_DEPRECATE
|
||||
@set LJLINK=link /nologo
|
||||
@set LJMT=mt /nologo
|
||||
@set DASMDIR=..\dynasm
|
||||
@set DASM=%DASMDIR%\dynasm.lua
|
||||
@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
|
||||
::@set DASC=vm_arm.dasc
|
||||
|
||||
|
||||
::@if "%1" neq "nx32" goto :NOGC32
|
||||
@set DASC=vm_arm64.dasc
|
||||
:::NOGC32
|
||||
|
||||
%LJCOMPILE% host\minilua.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:minilua.exe minilua.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist minilua.exe.manifest^
|
||||
%LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
|
||||
|
||||
@rem Check for 64 bit host compiler.
|
||||
@minilua
|
||||
@if not errorlevel 8 goto :FAIL
|
||||
|
||||
@set DASMFLAGS=-D P64 -D ENDIAN_LE -D NO_UNWIND -D LUAJIT_TARGET=LUAJIT_ARCH_ARM64 -D LUAJIT_OS=LUAJIT_OS_OTHER -D LUAJIT_DISABLE_JIT -D LUAJIT_DISABLE_FFI
|
||||
minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:buildvm.exe buildvm*.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist buildvm.exe.manifest^
|
||||
%LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
|
||||
|
||||
buildvm -m elfasm -o lj_vm.s
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m libdef -o lj_libdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m recdef -o lj_recdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
|
||||
@rem ---- Cross compiler ----
|
||||
::@if "%1" neq "nx32" goto :NX32BUILD
|
||||
@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_TARGET=LUAJIT_ARCH_ARM64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -DLUAJIT_NO_UNWIND -c
|
||||
@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-ar" rc
|
||||
@set TARGETLIB_SUFFIX="nx64"
|
||||
|
||||
%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-as -o lj_vm.o lj_vm.s
|
||||
::goto :DEBUGCHECK
|
||||
|
||||
:::NX32BUILD
|
||||
::@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_DISABLE_JIT -DLUAJIT_SECURITY_PRNG=0 -DLUAJIT_USE_SYSMALLOC -DNN_NINTENDO_SDK %GC64% -c
|
||||
::@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar" rc
|
||||
::@set TARGETLIB_SUFFIX="nx32"
|
||||
|
||||
::%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar -o lj_vm.o lj_vm.s
|
||||
:DEBUGCHECK
|
||||
|
||||
@if "%1" neq "debug" goto :NODEBUG
|
||||
@shift
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_DEBUG -g -O0
|
||||
@set TARGETLIB=liblua51D_%TARGETLIB_SUFFIX%.a
|
||||
goto :BUILD
|
||||
:NODEBUG
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_RELEASE -O3
|
||||
@set TARGETLIB=liblua51_%TARGETLIB_SUFFIX%.a
|
||||
:BUILD
|
||||
del %TARGETLIB%
|
||||
@if "%1" neq "noamalg" goto :AMALG
|
||||
for %%f in (lj_*.c lib_*.c) do (
|
||||
%LJCOMPILE% %%f
|
||||
@if errorlevel 1 goto :BAD
|
||||
)
|
||||
|
||||
%LJLIB% %TARGETLIB% lj_*.o lib_*.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
@goto :NOAMALG
|
||||
:AMALG
|
||||
%LJCOMPILE% ljamalg.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
:NOAMALG
|
||||
|
||||
@del *.o *.obj *.manifest minilua.exe buildvm.exe
|
||||
@echo.
|
||||
@echo === Successfully built LuaJIT for Nintendo Switch ===
|
||||
|
||||
@goto :END
|
||||
:BAD
|
||||
@echo.
|
||||
@echo *******************************************************
|
||||
@echo *** Build FAILED -- Please check the error messages ***
|
||||
@echo *******************************************************
|
||||
@goto :END
|
||||
:FAIL
|
||||
@echo To run this script you must open a "Visual Studio .NET Command Prompt"
|
||||
@echo (64 bit host compiler). NintendoSDK + NX Addon must be installed, too.
|
||||
:END
|
130
src/nxbuild_ugly_but_works_for_nx64.bat
Normal file
130
src/nxbuild_ugly_but_works_for_nx64.bat
Normal file
@ -0,0 +1,130 @@
|
||||
@rem Script to build LuaJIT with NintendoSDK + NX Addon.
|
||||
@rem Donated to the public domain.
|
||||
@rem
|
||||
@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)
|
||||
@rem or "VS20xx x64 Native Tools Command Prompt".
|
||||
@rem
|
||||
@rem Then cd to this directory and run this script.
|
||||
@rem
|
||||
@rem Recommended invocation:
|
||||
@rem
|
||||
@rem nxbuild release build, amalgamated
|
||||
@rem nxbuild debug debug build, amalgamated
|
||||
@rem
|
||||
@rem Additional command-line options (not generally recommended):
|
||||
@rem
|
||||
@rem nx32 (before debug) 32-bit target library
|
||||
@rem noamalg (after debug) non-amalgamated build
|
||||
|
||||
@if not defined INCLUDE goto :FAIL
|
||||
@if not defined NINTENDO_SDK_ROOT goto :FAIL
|
||||
|
||||
@setlocal
|
||||
@rem ---- Host compiler ----
|
||||
@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /wo4146 /wo4244 /D_CRT_SECURE_NO_DEPRECATE
|
||||
@set LJLINK=link /nologo
|
||||
@set LJMT=mt /nologo
|
||||
@set DASMDIR=..\dynasm
|
||||
@set DASM=%DASMDIR%\dynasm.lua
|
||||
@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
|
||||
::@set DASC=vm_arm.dasc
|
||||
|
||||
|
||||
::@if "%1" neq "nx32" goto :NOGC32
|
||||
@set DASC=vm_arm64.dasc
|
||||
:::NOGC32
|
||||
|
||||
%LJCOMPILE% host\minilua.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:minilua.exe minilua.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist minilua.exe.manifest^
|
||||
%LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
|
||||
|
||||
@rem Check for 64 bit host compiler.
|
||||
@minilua
|
||||
@if not errorlevel 8 goto :FAIL
|
||||
|
||||
@set DASMFLAGS=-D P64 -D ENDIAN_LE -D NO_UNWIND -D LUAJIT_TARGET=LUAJIT_ARCH_ARM64 -D LUAJIT_OS=LUAJIT_OS_OTHER -D LUAJIT_DISABLE_JIT -D LUAJIT_DISABLE_FFI
|
||||
minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_ARM64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLINK% /out:buildvm.exe buildvm*.obj
|
||||
@if errorlevel 1 goto :BAD
|
||||
if exist buildvm.exe.manifest^
|
||||
%LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
|
||||
|
||||
buildvm -m elfasm -o lj_vm.s
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m libdef -o lj_libdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m recdef -o lj_recdef.h %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
|
||||
@if errorlevel 1 goto :BAD
|
||||
buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
|
||||
@rem ---- Cross compiler ----
|
||||
::@if "%1" neq "nx32" goto :NX32BUILD
|
||||
@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_TARGET=LUAJIT_ARCH_ARM64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -DLUAJIT_NO_UNWIND -c
|
||||
@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-ar" rc
|
||||
@set TARGETLIB_SUFFIX="nx64"
|
||||
|
||||
%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-as -o lj_vm.o lj_vm.s
|
||||
::goto :DEBUGCHECK
|
||||
|
||||
:::NX32BUILD
|
||||
::@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include -DLUAJIT_DISABLE_JIT -DLUAJIT_SECURITY_PRNG=0 -DLUAJIT_USE_SYSMALLOC -DNN_NINTENDO_SDK %GC64% -c
|
||||
::@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar" rc
|
||||
::@set TARGETLIB_SUFFIX="nx32"
|
||||
|
||||
::%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar -o lj_vm.o lj_vm.s
|
||||
:DEBUGCHECK
|
||||
|
||||
@if "%1" neq "debug" goto :NODEBUG
|
||||
@shift
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_DEBUG -g -O0
|
||||
@set TARGETLIB=liblua51D_%TARGETLIB_SUFFIX%.a
|
||||
goto :BUILD
|
||||
:NODEBUG
|
||||
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_RELEASE -O3
|
||||
@set TARGETLIB=liblua51_%TARGETLIB_SUFFIX%.a
|
||||
:BUILD
|
||||
del %TARGETLIB%
|
||||
@if "%1" neq "noamalg" goto :AMALG
|
||||
for %%f in (lj_*.c lib_*.c) do (
|
||||
%LJCOMPILE% %%f
|
||||
@if errorlevel 1 goto :BAD
|
||||
)
|
||||
|
||||
%LJLIB% %TARGETLIB% lj_*.o lib_*.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
@goto :NOAMALG
|
||||
:AMALG
|
||||
%LJCOMPILE% ljamalg.c
|
||||
@if errorlevel 1 goto :BAD
|
||||
%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o
|
||||
@if errorlevel 1 goto :BAD
|
||||
:NOAMALG
|
||||
|
||||
@del *.o *.obj *.manifest minilua.exe buildvm.exe
|
||||
@echo.
|
||||
@echo === Successfully built LuaJIT for Nintendo Switch ===
|
||||
|
||||
@goto :END
|
||||
:BAD
|
||||
@echo.
|
||||
@echo *******************************************************
|
||||
@echo *** Build FAILED -- Please check the error messages ***
|
||||
@echo *******************************************************
|
||||
@goto :END
|
||||
:FAIL
|
||||
@echo To run this script you must open a "Visual Studio .NET Command Prompt"
|
||||
@echo (64 bit host compiler). NintendoSDK + NX Addon must be installed, too.
|
||||
:END
|
Loading…
Reference in New Issue
Block a user