1@rem Script to build LuaJIT with MSVC. 2@rem Copyright (C) 2005-2021 Mike Pall. See Copyright Notice in luajit.h 3@rem 4@rem Open a "Visual Studio Command Prompt" (either x86 or x64). 5@rem Then cd to this directory and run this script. Use the following 6@rem options (in order), if needed. The default is a dynamic release build. 7@rem 8@rem nogc64 disable LJ_GC64 mode for x64 9@rem debug emit debug symbols 10@rem amalg amalgamated build 11@rem static static linkage 12 13@if not defined INCLUDE goto :FAIL 14 15@setlocal 16@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_APICHECK 17@set DEBUGCFLAGS= 18@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline 19@set LJLINK=link /nologo 20@set LJMT=mt /nologo 21@set LJLIB=lib /nologo /nodefaultlib 22@set DASMDIR=..\dynasm 23@set DASM=%DASMDIR%\dynasm.lua 24@set DASC=vm_x64.dasc 25@set LJDLLNAME=lua51.dll 26@set LJLIBNAME=lua51.lib 27@set BUILDTYPE=release 28@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 29 30%LJCOMPILE% host\minilua.c 31@if errorlevel 1 goto :BAD 32%LJLINK% /out:minilua.exe minilua.obj 33@if errorlevel 1 goto :BAD 34if exist minilua.exe.manifest^ 35 %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe 36 37@set DASMFLAGS=-D WIN -D JIT -D FFI -D P64 38@set LJARCH=x64 39@minilua 40@if errorlevel 8 goto :X64 41@set DASC=vm_x86.dasc 42@set DASMFLAGS=-D WIN -D JIT -D FFI 43@set LJARCH=x86 44@set LJCOMPILE=%LJCOMPILE% /arch:SSE2 45:X64 46@if "%1" neq "nogc64" goto :GC64 47@shift 48@set DASC=vm_x86.dasc 49@set LJCOMPILE=%LJCOMPILE% /DLUAJIT_DISABLE_GC64 50:GC64 51minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h %DASC% 52@if errorlevel 1 goto :BAD 53 54%LJCOMPILE% /I "." /I %DASMDIR% host\buildvm*.c 55@if errorlevel 1 goto :BAD 56%LJLINK% /out:buildvm.exe buildvm*.obj 57@if errorlevel 1 goto :BAD 58if exist buildvm.exe.manifest^ 59 %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe 60 61buildvm -m peobj -o lj_vm.obj 62@if errorlevel 1 goto :BAD 63buildvm -m bcdef -o lj_bcdef.h %ALL_LIB% 64@if errorlevel 1 goto :BAD 65buildvm -m ffdef -o lj_ffdef.h %ALL_LIB% 66@if errorlevel 1 goto :BAD 67buildvm -m libdef -o lj_libdef.h %ALL_LIB% 68@if errorlevel 1 goto :BAD 69buildvm -m recdef -o lj_recdef.h %ALL_LIB% 70@if errorlevel 1 goto :BAD 71buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB% 72@if errorlevel 1 goto :BAD 73buildvm -m folddef -o lj_folddef.h lj_opt_fold.c 74@if errorlevel 1 goto :BAD 75 76@if "%1" neq "debug" goto :NODEBUG 77@shift 78@set BUILDTYPE=debug 79@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS% 80@set LJLINK=%LJLINK% /opt:ref /opt:icf /incremental:no 81:NODEBUG 82@set LJLINK=%LJLINK% /%BUILDTYPE% 83@if "%1"=="amalg" goto :AMALGDLL 84@if "%1"=="static" goto :STATIC 85%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL lj_*.c lib_*.c 86@if errorlevel 1 goto :BAD 87%LJLINK% /DLL /out:%LJDLLNAME% lj_*.obj lib_*.obj 88@if errorlevel 1 goto :BAD 89@goto :MTDLL 90:STATIC 91%LJCOMPILE% lj_*.c lib_*.c 92@if errorlevel 1 goto :BAD 93%LJLIB% /OUT:%LJLIBNAME% lj_*.obj lib_*.obj 94@if errorlevel 1 goto :BAD 95@goto :MTDLL 96:AMALGDLL 97%LJCOMPILE% /MD /DLUA_BUILD_AS_DLL ljamalg.c 98@if errorlevel 1 goto :BAD 99%LJLINK% /DLL /out:%LJDLLNAME% ljamalg.obj lj_vm.obj 100@if errorlevel 1 goto :BAD 101:MTDLL 102if exist %LJDLLNAME%.manifest^ 103 %LJMT% -manifest %LJDLLNAME%.manifest -outputresource:%LJDLLNAME%;2 104 105%LJCOMPILE% luajit.c 106@if errorlevel 1 goto :BAD 107%LJLINK% /out:luajit.exe luajit.obj %LJLIBNAME% 108@if errorlevel 1 goto :BAD 109if exist luajit.exe.manifest^ 110 %LJMT% -manifest luajit.exe.manifest -outputresource:luajit.exe 111 112@del *.obj *.manifest minilua.exe buildvm.exe 113@del host\buildvm_arch.h 114@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h 115@echo. 116@echo === Successfully built LuaJIT for Windows/%LJARCH% === 117 118@goto :END 119:BAD 120@echo. 121@echo ******************************************************* 122@echo *** Build FAILED -- Please check the error messages *** 123@echo ******************************************************* 124@goto :END 125:FAIL 126@echo You must open a "Visual Studio Command Prompt" to run this script 127:END 128