| 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 |
| 39 |
goto :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 |
| 60 |
if 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 |
| 73 |
minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC% |
| 74 |
@if errorlevel 1 goto :BAD |
| 75 |
|
| 76 |
if exist ..\.git ( git show -s --format=%%ct >luajit_relver.txt ) else ( type ..\.relver >luajit_relver.txt ) |
| 77 |
minilua host\genversion.lua |
| 78 |
|
| 79 |
%LJCOMPILE% /I "." /I %DASMDIR% %DASMTARGET% -D LJ_TARGET_NX -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c |
| 80 |
@if errorlevel 1 goto :BAD |
| 81 |
%LJLINK% /out:buildvm.exe buildvm*.obj |
| 82 |
@if errorlevel 1 goto :BAD |
| 83 |
if exist buildvm.exe.manifest^ |
| 84 |
%LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe |
| 85 |
|
| 86 |
buildvm -m elfasm -o lj_vm.s |
| 87 |
@if errorlevel 1 goto :BAD |
| 88 |
buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% |
| 89 |
@if errorlevel 1 goto :BAD |
| 90 |
buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% |
| 91 |
@if errorlevel 1 goto :BAD |
| 92 |
buildvm -m libdef -o lj_libdef.h %ALL_LIB% |
| 93 |
@if errorlevel 1 goto :BAD |
| 94 |
buildvm -m recdef -o lj_recdef.h %ALL_LIB% |
| 95 |
@if errorlevel 1 goto :BAD |
| 96 |
buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% |
| 97 |
@if errorlevel 1 goto :BAD |
| 98 |
buildvm -m folddef -o lj_folddef.h lj_opt_fold.c |
| 99 |
@if errorlevel 1 goto :BAD |
| 100 |
|
| 101 |
@rem ---- Cross compiler ---- |
| 102 |
@set NXCOMPILER_ROOT="%NINTENDO_SDK_ROOT%\Compilers\NintendoClang" |
| 103 |
@if "%platform%" neq "x64" goto :NX32_CROSSBUILD |
| 104 |
@set LJCOMPILE="%NXCOMPILER_ROOT%\bin\clang" --target=aarch64-nintendo-nx-elf -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c |
| 105 |
@set LJLIB="%NXCOMPILER_ROOT%\bin\llvm-ar" rc |
| 106 |
@set TARGETLIB_SUFFIX=nx64 |
| 107 |
|
| 108 |
%NXCOMPILER_ROOT%\bin\clang --target=aarch64-nintendo-nx-elf -o lj_vm.o -c lj_vm.s |
| 109 |
goto :DEBUGCHECK |
| 110 |
|
| 111 |
:NX32_CROSSBUILD |
| 112 |
@set LJCOMPILE="%NXCOMPILER_ROOT%\bin\clang" --target=armv7l-nintendo-nx-eabihf -Wall -I%NINTENDO_SDK_ROOT%\Include %DASMTARGET% -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_USE_SYSMALLOC -c |
| 113 |
@set LJLIB="%NXCOMPILER_ROOT%\bin\llvm-ar" rc |
| 114 |
@set TARGETLIB_SUFFIX=nx32 |
| 115 |
|
| 116 |
%NXCOMPILER_ROOT%\bin\clang --target=armv7l-nintendo-nx-eabihf -o lj_vm.o -c lj_vm.s |
| 117 |
:DEBUGCHECK |
| 118 |
|
| 119 |
@if "%1" neq "debug" goto :NODEBUG |
| 120 |
@shift |
| 121 |
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_DEBUG -g -O0 |
| 122 |
@set TARGETLIB=libluajitD_%TARGETLIB_SUFFIX%.a |
| 123 |
goto :BUILD |
| 124 |
:NODEBUG |
| 125 |
@set LJCOMPILE=%LJCOMPILE% -DNN_SDK_BUILD_RELEASE -O3 |
| 126 |
@set TARGETLIB=libluajit_%TARGETLIB_SUFFIX%.a |
| 127 |
:BUILD |
| 128 |
del %TARGETLIB% |
| 129 |
@set LJCOMPILE=%LJCOMPILE% -fPIC |
| 130 |
@if "%1" neq "noamalg" goto :AMALG |
| 131 |
for %%f in (lj_*.c lib_*.c) do ( |
| 132 |
%LJCOMPILE% %%f |
| 133 |
@if errorlevel 1 goto :BAD |
| 134 |
) |
| 135 |
|
| 136 |
%LJLIB% %TARGETLIB% lj_*.o lib_*.o |
| 137 |
@if errorlevel 1 goto :BAD |
| 138 |
@goto :NOAMALG |
| 139 |
:AMALG |
| 140 |
%LJCOMPILE% ljamalg.c |
| 141 |
@if errorlevel 1 goto :BAD |
| 142 |
%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o |
| 143 |
@if errorlevel 1 goto :BAD |
| 144 |
:NOAMALG |
| 145 |
|
| 146 |
@del *.o *.obj *.manifest minilua.exe buildvm.exe |
| 147 |
@echo. |
| 148 |
@echo === Successfully built LuaJIT for Nintendo Switch (%TARGETLIB_SUFFIX%) === |
| 149 |
|
| 150 |
@goto :END |
| 151 |
:BAD |
| 152 |
@echo. |
| 153 |
@echo ******************************************************* |
| 154 |
@echo *** Build FAILED -- Please check the error messages *** |
| 155 |
@echo ******************************************************* |
| 156 |
@goto :END |
| 157 |
:FAIL |
| 158 |
@echo To run this script you must open a "Native Tools Command Prompt for VS". |
| 159 |
@echo. |
| 160 |
@echo Either the x86 version for NX32, or x64 for the NX64 target. |
| 161 |
@echo This is because the pointer size of the LuaJIT host tools (buildvm.exe) |
| 162 |
@echo must match the cross-compiled target (32 or 64 bits). |
| 163 |
@echo. |
| 164 |
@echo Keep in mind that NintendoSDK + NX Addon must be installed, too. |
| 165 |
:END |