aboutsummaryrefslogtreecommitdiff
path: root/src/nxbuild.bat
diff options
context:
space:
mode:
authorMike Pall <mike>2022-06-08 14:24:57 +0200
committerMike Pall <mike>2022-06-08 14:24:57 +0200
commit7beb3375e34583e01e5c6ab370721aaea56226cc (patch)
tree0c35ea9901f0e9ceed0fd7ee4096a318b980d536 /src/nxbuild.bat
parent96157d360db9dde81e7a3752f5c060f5111e1b07 (diff)
downloadluajit-7beb3375e34583e01e5c6ab370721aaea56226cc.tar.gz
luajit-7beb3375e34583e01e5c6ab370721aaea56226cc.tar.bz2
luajit-7beb3375e34583e01e5c6ab370721aaea56226cc.zip
Add Nintendo Switch port.
Contributed by Swyter and vdweller84.
Diffstat (limited to 'src/nxbuild.bat')
-rw-r--r--src/nxbuild.bat159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/nxbuild.bat b/src/nxbuild.bat
new file mode 100644
index 00000000..c4a21f05
--- /dev/null
+++ b/src/nxbuild.bat
@@ -0,0 +1,159 @@
1@rem Script to build LuaJIT with NintendoSDK + NX Addon.
2@rem Donated to the public domain by Swyter.
3@rem
4@rem To run this script you must open a "Native Tools Command Prompt for VS".
5@rem
6@rem Either the x86 version for NX32, or x64 for the NX64 target.
7@rem This is because the pointer size of the LuaJIT host tools (buildvm.exe)
8@rem must match the cross-compiled target (32 or 64 bits).
9@rem
10@rem Then cd to this directory and run this script.
11@rem
12@rem Recommended invocation:
13@rem
14@rem nxbuild # release build, amalgamated
15@rem nxbuild debug # debug build, amalgamated
16@rem
17@rem Additional command-line options (not generally recommended):
18@rem
19@rem noamalg # (after debug) non-amalgamated build
20
21@if not defined INCLUDE goto :FAIL
22@if not defined NINTENDO_SDK_ROOT goto :FAIL
23@if not defined PLATFORM goto :FAIL
24
25@if "%platform%" == "x86" goto :DO_NX32
26@if "%platform%" == "x64" goto :DO_NX64
27
28@echo Error: Current host platform is %platform%!
29@echo.
30@goto :FAIL
31
32@setlocal
33
34:DO_NX32
35@set DASC=vm_arm.dasc
36@set DASMFLAGS= -D HFABI -D FPU
37@set DASMTARGET= -D LUAJIT_TARGET=LUAJIT_ARCH_ARM
38@set HOST_PTR_SIZE=4
39goto :BEGIN
40
41:DO_NX64
42@set DASC=vm_arm64.dasc
43@set DASMFLAGS= -D ENDIAN_LE
44@set DASMTARGET= -D LUAJIT_TARGET=LUAJIT_ARCH_ARM64
45@set HOST_PTR_SIZE=8
46
47:BEGIN
48@rem ---- Host compiler ----
49@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /wo4146 /wo4244 /D_CRT_SECURE_NO_DEPRECATE
50@set LJLINK=link /nologo
51@set LJMT=mt /nologo
52@set DASMDIR=..\dynasm
53@set DASM=%DASMDIR%\dynasm.lua
54@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
55
56%LJCOMPILE% host\minilua.c
57@if errorlevel 1 goto :BAD
58%LJLINK% /out:minilua.exe minilua.obj
59@if errorlevel 1 goto :BAD
60if exist minilua.exe.manifest^
61 %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe
62
63@rem Check that we have the right 32/64 bit host compiler to generate the right virtual machine files.
64@minilua
65@if "%ERRORLEVEL%" == "%HOST_PTR_SIZE%" goto :PASSED_PTR_CHECK
66
67@echo The pointer size of the host in bytes (%HOST_PTR_SIZE%) does not match the expected value (%errorlevel%).
68@echo Check that the script is being ran under the correct x86/x64 VS prompt.
69@goto :BAD
70
71:PASSED_PTR_CHECK
72@set DASMFLAGS=%DASMFLAGS% %DASMTARGET% -D LJ_TARGET_NX -D LUAJIT_OS=LUAJIT_OS_OTHER -D LUAJIT_DISABLE_JIT -D LUAJIT_DISABLE_FFI
73minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC%
74@if errorlevel 1 goto :BAD
75%LJCOMPILE% /I "." /I %DASMDIR% %DASMTARGET% -D LJ_TARGET_NX -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c
76@if errorlevel 1 goto :BAD
77%LJLINK% /out:buildvm.exe buildvm*.obj
78@if errorlevel 1 goto :BAD
79if exist buildvm.exe.manifest^
80 %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe
81
82buildvm -m elfasm -o lj_vm.s
83@if errorlevel 1 goto :BAD
84buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%
85@if errorlevel 1 goto :BAD
86buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%
87@if errorlevel 1 goto :BAD
88buildvm -m libdef -o lj_libdef.h %ALL_LIB%
89@if errorlevel 1 goto :BAD
90buildvm -m recdef -o lj_recdef.h %ALL_LIB%
91@if errorlevel 1 goto :BAD
92buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%
93@if errorlevel 1 goto :BAD
94buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
95@if errorlevel 1 goto :BAD
96
97@rem ---- Cross compiler ----
98@if "%platform%" neq "x64" goto :NX32_CROSSBUILD
99@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
100@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-ar" rc
101@set TARGETLIB_SUFFIX=nx64
102
103%NINTENDO_SDK_ROOT%\Compilers\NX\nx\aarch64\bin\aarch64-nintendo-nx-elf-as -o lj_vm.o lj_vm.s
104goto :DEBUGCHECK
105
106:NX32_CROSSBUILD
107@set LJCOMPILE="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\clang" -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c
108@set LJLIB="%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-ar" rc
109@set TARGETLIB_SUFFIX=nx32
110
111%NINTENDO_SDK_ROOT%\Compilers\NX\nx\armv7l\bin\armv7l-nintendo-nx-eabihf-as -o lj_vm.o lj_vm.s
112:DEBUGCHECK
113
114@if "%1" neq "debug" goto :NODEBUG
115@shift
116@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_DEBUG -g -O0
117@set TARGETLIB=libluajitD_%TARGETLIB_SUFFIX%.a
118goto :BUILD
119:NODEBUG
120@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_RELEASE -O3
121@set TARGETLIB=libluajit_%TARGETLIB_SUFFIX%.a
122:BUILD
123del %TARGETLIB%
124@if "%1" neq "noamalg" goto :AMALG
125for %%f in (lj_*.c lib_*.c) do (
126 %LJCOMPILE% %%f
127 @if errorlevel 1 goto :BAD
128)
129
130%LJLIB% %TARGETLIB% lj_*.o lib_*.o
131@if errorlevel 1 goto :BAD
132@goto :NOAMALG
133:AMALG
134%LJCOMPILE% ljamalg.c
135@if errorlevel 1 goto :BAD
136%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o
137@if errorlevel 1 goto :BAD
138:NOAMALG
139
140@del *.o *.obj *.manifest minilua.exe buildvm.exe
141@echo.
142@echo === Successfully built LuaJIT for Nintendo Switch (%TARGETLIB_SUFFIX%) ===
143
144@goto :END
145:BAD
146@echo.
147@echo *******************************************************
148@echo *** Build FAILED -- Please check the error messages ***
149@echo *******************************************************
150@goto :END
151:FAIL
152@echo To run this script you must open a "Native Tools Command Prompt for VS".
153@echo.
154@echo Either the x86 version for NX32, or x64 for the NX64 target.
155@echo This is because the pointer size of the LuaJIT host tools (buildvm.exe)
156@echo must match the cross-compiled target (32 or 64 bits).
157@echo.
158@echo Keep in mind that NintendoSDK + NX Addon must be installed, too.
159:END