Thanks to Eddie Edwards.
<tr class="even">
<td class="compatcpu">x64 (64 bit)</td>
<td class="compatos">GCC 4.x</td>
-<td class="compatos compatno"> </td>
+<td class="compatos">ORBIS (<a href="#ps4">PS4</a>)</td>
<td class="compatos">GCC 4.x</td>
<td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0</td>
</tr>
</pre>
<p>
You can cross-compile for <b id="ps3">PS3</b> using the PS3 SDK from
-a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host,
+a Linux host or a Windows host (requires 32 bit MinGW (GCC) on the host,
too). Due to restrictions on consoles, the JIT compiler is disabled and
only the fast interpreter is built:
</p>
make HOST_CC="gcc -m32" CROSS=ppu-lv2-
</pre>
<p>
+You can cross-compile for <b id="ps4">PS4</b> from a Windows host using
+the PS4 SDK (ORBIS) plus 64 bit MSVC. Due to restrictions on
+consoles, the JIT compiler is disabled and only the fast interpreter
+is built.
+</p>
+<p>
+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
+the following commands. This builds a static library <tt>libluajit.a</tt>,
+which can be linked against your game, just like the Lua library.
+</p>
+<pre class="code">
+cd src
+ps4build
+</pre>
+<p>
You can cross-compile for <b id="xbox360">Xbox 360</b> using the
Xbox 360 SDK (MSVC + XEDK). Due to restrictions on consoles, the
JIT compiler is disabled and only the fast interpreter is built.
<tr><td>Windows</td><td>Linux</td><td>BSD</td><td>OSX</td><td>POSIX</td></tr>
</table>
<table class="feature os os2">
-<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td><td>Xbox 360</td></tr>
+<tr><td><span style="font-size:90%;">Embedded</span></td><td>Android</td><td>iOS</td><td>PS3</td><td>PS4</td><td>Xbox 360</td></tr>
</table>
<table class="feature compiler">
<tr><td>GCC</td><td>CLANG<br>LLVM</td><td>MSVC</td></tr>
LJLIB_CF(io_tmpfile)
{
IOFileUD *iof = io_file_new(L);
-#if LJ_TARGET_PS3
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4
iof->fp = NULL; errno = ENOSYS;
#else
iof->fp = tmpfile();
LJLIB_CF(os_tmpname)
{
-#if LJ_TARGET_PS3
+#if LJ_TARGET_PS3 || LJ_TARGET_PS4
lj_err_caller(L, LJ_ERR_OSUNIQF);
return 0;
#else
return ptr;
}
-#elif LJ_TARGET_OSX || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__)
+#elif LJ_TARGET_OSX || LJ_TARGET_PS4 || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun__)
/* OSX and FreeBSD mmap() use a naive first-fit linear search.
** That's perfect for us. Except that -pagezero_size must be set for OSX,
*/
#if LJ_TARGET_OSX
#define MMAP_REGION_START ((uintptr_t)0x10000)
+#elif LJ_TARGET_PS4
+#define MMAP_REGION_START ((uintptr_t)0x4000)
#else
#define MMAP_REGION_START ((uintptr_t)0x10000000)
#endif
#define MMAP_REGION_END ((uintptr_t)0x80000000)
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
#include <sys/resource.h>
#endif
/* Hint for next allocation. Doesn't need to be thread-safe. */
static uintptr_t alloc_hint = MMAP_REGION_START;
int retry = 0;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !LJ_TARGET_PS4
static int rlimit_modified = 0;
if (LJ_UNLIKELY(rlimit_modified == 0)) {
struct rlimit rlim;
#define LUAJIT_OS LUAJIT_OS_LINUX
#elif defined(__MACH__) && defined(__APPLE__)
#define LUAJIT_OS LUAJIT_OS_OSX
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
- defined(__NetBSD__) || defined(__OpenBSD__)
+#elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__ORBIS__)
#define LUAJIT_OS LUAJIT_OS_BSD
#elif (defined(__sun__) && defined(__svr4__)) || defined(__CYGWIN__)
#define LUAJIT_OS LUAJIT_OS_POSIX
#define LJ_TARGET_CONSOLE 1
#endif
+#ifdef __ORBIS__
+#define LJ_TARGET_PS4 1
+#define LJ_TARGET_CONSOLE 1
+#undef NULL
+#define NULL ((void*)0)
+#endif
+
#if _XBOX_VER >= 200
#define LJ_TARGET_XBOX360 1
#define LJ_TARGET_CONSOLE 1
--- /dev/null
+@rem Script to build LuaJIT with the PS4 SDK.\r
+@rem Donated to the public domain.\r
+@rem\r
+@rem Open a "Visual Studio .NET Command Prompt" (64 bit host compiler)\r
+@rem Then cd to this directory and run this script.\r
+\r
+@if not defined INCLUDE goto :FAIL\r
+@if not defined SCE_ORBIS_SDK_DIR goto :FAIL\r
+\r
+@setlocal\r
+@rem ---- Host compiler ----\r
+@set LJCOMPILE=cl /nologo /c /MD /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE\r
+@set LJLINK=link /nologo\r
+@set LJMT=mt /nologo\r
+@set DASMDIR=..\dynasm\r
+@set DASM=%DASMDIR%\dynasm.lua\r
+@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\r
+\r
+%LJCOMPILE% host\minilua.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLINK% /out:minilua.exe minilua.obj\r
+@if errorlevel 1 goto :BAD\r
+if exist minilua.exe.manifest^\r
+ %LJMT% -manifest minilua.exe.manifest -outputresource:minilua.exe\r
+\r
+@rem Check for 64 bit host compiler.\r
+@minilua\r
+@if not errorlevel 8 goto :FAIL\r
+\r
+@set DASMFLAGS=-D P64\r
+minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc\r
+@if errorlevel 1 goto :BAD\r
+\r
+%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLINK% /out:buildvm.exe buildvm*.obj\r
+@if errorlevel 1 goto :BAD\r
+if exist buildvm.exe.manifest^\r
+ %LJMT% -manifest buildvm.exe.manifest -outputresource:buildvm.exe\r
+\r
+buildvm -m elfasm -o lj_vm.s\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m bcdef -o lj_bcdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m ffdef -o lj_ffdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m libdef -o lj_libdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m recdef -o lj_recdef.h %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m vmdef -o jit\vmdef.lua %ALL_LIB%\r
+@if errorlevel 1 goto :BAD\r
+buildvm -m folddef -o lj_folddef.h lj_opt_fold.c\r
+@if errorlevel 1 goto :BAD\r
+\r
+@rem ---- Cross compiler ----\r
+@set LJCOMPILE="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-clang" -c -Wall -DLUAJIT_DISABLE_FFI\r
+@set LJLIB="%SCE_ORBIS_SDK_DIR%\host_tools\bin\orbis-ar" rcus\r
+@set INCLUDE=""\r
+\r
+orbis-as -o lj_vm.o lj_vm.s\r
+\r
+@if "%1" neq "debug" goto :NODEBUG\r
+@shift\r
+@set LJCOMPILE=%LJCOMPILE% -g -O0\r
+@set TARGETLIB=libluajitD.a\r
+goto :BUILD\r
+:NODEBUG\r
+@set LJCOMPILE=%LJCOMPILE% -O2\r
+@set TARGETLIB=libluajit.a\r
+:BUILD\r
+del %TARGETLIB%\r
+@if "%1"=="amalg" goto :AMALG\r
+for %%f in (lj_*.c lib_*.c) do (\r
+ %LJCOMPILE% %%f\r
+ @if errorlevel 1 goto :BAD\r
+)\r
+\r
+%LJLIB% %TARGETLIB% lj_*.o lib_*.o\r
+@if errorlevel 1 goto :BAD\r
+@goto :NOAMALG\r
+:AMALG\r
+%LJCOMPILE% ljamalg.c\r
+@if errorlevel 1 goto :BAD\r
+%LJLIB% %TARGETLIB% ljamalg.o lj_vm.o\r
+@if errorlevel 1 goto :BAD\r
+:NOAMALG\r
+\r
+@del *.o *.obj *.manifest minilua.exe buildvm.exe\r
+@echo.\r
+@echo === Successfully built LuaJIT for PS4 ===\r
+\r
+@goto :END\r
+:BAD\r
+@echo.\r
+@echo *******************************************************\r
+@echo *** Build FAILED -- Please check the error messages ***\r
+@echo *******************************************************\a\r
+@goto :END\r
+:FAIL\r
+@echo To run this script you must open a "Visual Studio .NET Command Prompt"\r
+@echo (64 bit host compiler). The PS4 Orbis SDK must be installed, too.\r
+:END\r