Mercurial
comparison third_party/luajit/doc/install.html @ 186:8cf4ec5e2191 hg-web
Fixed merge conflict.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 22:38:59 -0800 |
| parents | 94705b5986b3 |
| children |
comparison
equal
deleted
inserted
replaced
| 176:fed99fc04e12 | 186:8cf4ec5e2191 |
|---|---|
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Installation</title> | |
| 5 <meta charset="utf-8"> | |
| 6 <meta name="Copyright" content="Copyright (C) 2005-2023"> | |
| 7 <meta name="Language" content="en"> | |
| 8 <link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"> | |
| 9 <link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"> | |
| 10 <style type="text/css"> | |
| 11 table.compat { | |
| 12 line-height: 1.2; | |
| 13 font-size: 80%; | |
| 14 } | |
| 15 table.compat td { | |
| 16 border: 1px solid #bfcfff; | |
| 17 height: 1.5em; | |
| 18 } | |
| 19 table.compat tr.compathead td { | |
| 20 font-weight: bold; | |
| 21 border-bottom: 2px solid #bfcfff; | |
| 22 } | |
| 23 td.compatname { | |
| 24 width: 10%; | |
| 25 } | |
| 26 td.compatbits { | |
| 27 width: 5%; | |
| 28 } | |
| 29 td.compatx { | |
| 30 width: 21%; | |
| 31 } | |
| 32 </style> | |
| 33 </head> | |
| 34 <body> | |
| 35 <div id="site"> | |
| 36 <a href="https://luajit.org"><span>Lua<span id="logo">JIT</span></span></a> | |
| 37 </div> | |
| 38 <div id="head"> | |
| 39 <h1>Installation</h1> | |
| 40 </div> | |
| 41 <div id="nav"> | |
| 42 <ul><li> | |
| 43 <a href="luajit.html">LuaJIT</a> | |
| 44 <ul><li> | |
| 45 <a href="https://luajit.org/download.html">Download <span class="ext">»</span></a> | |
| 46 </li><li> | |
| 47 <a class="current" href="install.html">Installation</a> | |
| 48 </li><li> | |
| 49 <a href="running.html">Running</a> | |
| 50 </li></ul> | |
| 51 </li><li> | |
| 52 <a href="extensions.html">Extensions</a> | |
| 53 <ul><li> | |
| 54 <a href="ext_ffi.html">FFI Library</a> | |
| 55 <ul><li> | |
| 56 <a href="ext_ffi_tutorial.html">FFI Tutorial</a> | |
| 57 </li><li> | |
| 58 <a href="ext_ffi_api.html">ffi.* API</a> | |
| 59 </li><li> | |
| 60 <a href="ext_ffi_semantics.html">FFI Semantics</a> | |
| 61 </li></ul> | |
| 62 </li><li> | |
| 63 <a href="ext_buffer.html">String Buffers</a> | |
| 64 </li><li> | |
| 65 <a href="ext_jit.html">jit.* Library</a> | |
| 66 </li><li> | |
| 67 <a href="ext_c_api.html">Lua/C API</a> | |
| 68 </li><li> | |
| 69 <a href="ext_profiler.html">Profiler</a> | |
| 70 </li></ul> | |
| 71 </li><li> | |
| 72 <a href="https://luajit.org/status.html">Status <span class="ext">»</span></a> | |
| 73 </li><li> | |
| 74 <a href="https://luajit.org/faq.html">FAQ <span class="ext">»</span></a> | |
| 75 </li><li> | |
| 76 <a href="https://luajit.org/list.html">Mailing List <span class="ext">»</span></a> | |
| 77 </li></ul> | |
| 78 </div> | |
| 79 <div id="main"> | |
| 80 <p> | |
| 81 LuaJIT is only distributed as source code — get it from the | |
| 82 <a href="https://luajit.org/download.html"><span class="ext">»</span> git repository</a>. This page explains how to build | |
| 83 and install the LuaJIT binary and library for different operating systems. | |
| 84 </p> | |
| 85 <p> | |
| 86 For the impatient (on POSIX systems): | |
| 87 </p> | |
| 88 <pre class="code"> | |
| 89 make && sudo make install | |
| 90 </pre> | |
| 91 | |
| 92 <h2 id="req">Requirements</h2> | |
| 93 <p> | |
| 94 LuaJIT currently builds out-of-the box on most systems. Please check the | |
| 95 supported operating systems and CPU architectures on the | |
| 96 <a href="https://luajit.org/status.html"><span class="ext">»</span> status page</a>. | |
| 97 </p> | |
| 98 <p> | |
| 99 Building LuaJIT requires a recent toolchain based on GCC, Clang/LLVM or | |
| 100 MSVC++. | |
| 101 </p> | |
| 102 <p> | |
| 103 The Makefile-based build system requires GNU Make and supports | |
| 104 cross-builds. | |
| 105 </p> | |
| 106 <p> | |
| 107 Batch files are provided for MSVC++ builds and console cross-builds. | |
| 108 </p> | |
| 109 | |
| 110 <h2>Configuring LuaJIT</h2> | |
| 111 <p> | |
| 112 The standard configuration should work fine for most installations. | |
| 113 Usually there is no need to tweak the settings. The following files | |
| 114 hold all user-configurable settings: | |
| 115 </p> | |
| 116 <ul> | |
| 117 <li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX | |
| 118 only).</li> | |
| 119 <li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT | |
| 120 under POSIX, MinGW or Cygwin.</li> | |
| 121 <li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with | |
| 122 MSVC (Visual Studio).</li> | |
| 123 </ul> | |
| 124 <p> | |
| 125 Please read the instructions given in these files, before changing | |
| 126 any settings. | |
| 127 </p> | |
| 128 <p> | |
| 129 All LuaJIT 64 bit ports use 64 bit GC objects by default (<tt>LJ_GC64</tt>). | |
| 130 For x64, you can select the old 32-on-64 bit mode by adding | |
| 131 <tt>XCFLAGS=-DLUAJIT_DISABLE_GC64</tt> to the make command. | |
| 132 Please check the note about the | |
| 133 <a href="extensions.html#string_dump">bytecode format</a> differences, too. | |
| 134 </p> | |
| 135 | |
| 136 <h2 id="posix">POSIX Systems (Linux, macOS, *BSD etc.)</h2> | |
| 137 <h3>Prerequisites</h3> | |
| 138 <p> | |
| 139 Depending on your distribution, you may need to install a package for a | |
| 140 compiler (GCC or Clang/LLVM), the development headers and/or a complete SDK. | |
| 141 E.g. on a current Debian/Ubuntu, install <tt>build-essential</tt> with the | |
| 142 package manager. | |
| 143 </p> | |
| 144 </pre> | |
| 145 <h3>Building LuaJIT</h3> | |
| 146 <p> | |
| 147 The supplied Makefiles try to auto-detect the settings needed for your | |
| 148 operating system and your compiler. They need to be run with GNU Make, | |
| 149 which is probably the default on your system, anyway. Simply run: | |
| 150 </p> | |
| 151 <pre class="code"> | |
| 152 make | |
| 153 </pre> | |
| 154 <p> | |
| 155 This always builds a native binary, depending on the host OS | |
| 156 you're running this command on. Check the section on | |
| 157 <a href="#cross">cross-compilation</a> for more options. | |
| 158 </p> | |
| 159 <p> | |
| 160 By default, modules are only searched under the prefix <tt>/usr/local</tt>. | |
| 161 You can add an extra prefix to the search paths by appending the | |
| 162 <tt>PREFIX</tt> option, e.g.: | |
| 163 </p> | |
| 164 <pre class="code"> | |
| 165 make PREFIX=/home/myself/lj2 | |
| 166 </pre> | |
| 167 <p> | |
| 168 Note for macOS: you <b>must</b> set the <tt>MACOSX_DEPLOYMENT_TARGET</tt> | |
| 169 environment variable to a value supported by your toolchain: | |
| 170 </p> | |
| 171 <pre class="code"> | |
| 172 MACOSX_DEPLOYMENT_TARGET=XX.YY make | |
| 173 </pre> | |
| 174 <h3>Installing LuaJIT</h3> | |
| 175 <p> | |
| 176 The top-level Makefile installs LuaJIT by default under | |
| 177 <tt>/usr/local</tt>, i.e. the executable ends up in | |
| 178 <tt>/usr/local/bin</tt> and so on. You need root privileges | |
| 179 to write to this path. So, assuming sudo is installed on your system, | |
| 180 run the following command and enter your sudo password: | |
| 181 </p> | |
| 182 <pre class="code"> | |
| 183 sudo make install | |
| 184 </pre> | |
| 185 <p> | |
| 186 Otherwise specify the directory prefix as an absolute path, e.g.: | |
| 187 </p> | |
| 188 <pre class="code"> | |
| 189 make install PREFIX=/home/myself/lj2 | |
| 190 </pre> | |
| 191 <p> | |
| 192 Obviously the prefixes given during build and installation need to be the same. | |
| 193 </p> | |
| 194 | |
| 195 <h2 id="windows">Windows Systems</h2> | |
| 196 <h3>Prerequisites</h3> | |
| 197 <p> | |
| 198 Either install one of the open source SDKs | |
| 199 (<a href="http://mingw.org/"><span class="ext">»</span> MinGW</a> or | |
| 200 <a href="https://www.cygwin.com/"><span class="ext">»</span> Cygwin</a>), which come with a modified | |
| 201 GCC plus the required development headers. | |
| 202 Or install Microsoft's Visual Studio (MSVC). | |
| 203 </p> | |
| 204 <h3>Building with MSVC</h3> | |
| 205 <p> | |
| 206 Open a "Visual Studio Command Prompt" (either x86 or x64), <tt>cd</tt> to the | |
| 207 directory with the source code and run these commands: | |
| 208 </p> | |
| 209 <pre class="code"> | |
| 210 cd src | |
| 211 msvcbuild | |
| 212 </pre> | |
| 213 <p> | |
| 214 Check the <tt>msvcbuild.bat</tt> file for more options. | |
| 215 Then follow the installation instructions below. | |
| 216 </p> | |
| 217 <h3>Building with MinGW or Cygwin</h3> | |
| 218 <p> | |
| 219 Open a command prompt window and make sure the MinGW or Cygwin programs | |
| 220 are in your path. Then <tt>cd</tt> to the directory of the git repository. | |
| 221 Then run this command for MinGW: | |
| 222 </p> | |
| 223 <pre class="code"> | |
| 224 mingw32-make | |
| 225 </pre> | |
| 226 <p> | |
| 227 Or this command for Cygwin: | |
| 228 </p> | |
| 229 <pre class="code"> | |
| 230 make | |
| 231 </pre> | |
| 232 <p> | |
| 233 Then follow the installation instructions below. | |
| 234 </p> | |
| 235 <h3>Installing LuaJIT</h3> | |
| 236 <p> | |
| 237 Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt> | |
| 238 directory) to a newly created directory (any location is ok). | |
| 239 Add <tt>lua</tt> and <tt>lua\jit</tt> directories below it and copy | |
| 240 all Lua files from the <tt>src\jit</tt> directory of the distribution | |
| 241 to the latter directory. | |
| 242 </p> | |
| 243 <p> | |
| 244 There are no hardcoded | |
| 245 absolute path names — all modules are loaded relative to the | |
| 246 directory where <tt>luajit.exe</tt> is installed | |
| 247 (see <tt>src/luaconf.h</tt>). | |
| 248 </p> | |
| 249 | |
| 250 <h2 id="cross">Cross-compiling LuaJIT</h2> | |
| 251 <p> | |
| 252 First, let's clear up some terminology: | |
| 253 </p> | |
| 254 <ul> | |
| 255 <li>Host: This is your development system, usually based on a x64 or x86 CPU.</li> | |
| 256 <li>Target: This is the target system you want LuaJIT to run on, e.g. Android/ARM.</li> | |
| 257 <li>Toolchain: This comprises a C compiler, linker, assembler and a matching C library.</li> | |
| 258 <li>Host (or system) toolchain: This is the toolchain used to build native binaries for your host system.</li> | |
| 259 <li>Cross-compile toolchain: This is the toolchain used to build binaries for the target system. They can only be run on the target system.</li> | |
| 260 </ul> | |
| 261 <p> | |
| 262 The GNU Makefile-based build system allows cross-compiling on any host | |
| 263 for any supported target: | |
| 264 </p> | |
| 265 <ul> | |
| 266 <li>Yes, you need a toolchain for both your host <em>and</em> your target!</li> | |
| 267 <li>Both host and target architectures must have the same pointer size.</li> | |
| 268 <li>E.g. if you want to cross-compile to a 32 bit target on a 64 bit host, you need to install the multilib development package (e.g. <tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part (<tt>HOST_CC="gcc -m32"</tt>).</li> | |
| 269 <li>64 bit targets always require compilation on a 64 bit host.</li> | |
| 270 </ul> | |
| 271 <p> | |
| 272 You need to specify <tt>TARGET_SYS</tt> whenever the host OS and the | |
| 273 target OS differ, or you'll get assembler or linker errors: | |
| 274 </p> | |
| 275 <ul> | |
| 276 <li>E.g. if you're compiling on a Windows or macOS host for embedded Linux or Android, you need to add <tt>TARGET_SYS=Linux</tt> to the examples below.</li> | |
| 277 <li>For a minimal target OS, you may need to disable the built-in allocator in <tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.</li> | |
| 278 <li>Don't forget to specify the same <tt>TARGET_SYS</tt> for the install step, too.</li> | |
| 279 </ul> | |
| 280 <p> | |
| 281 Here are some examples where host and target have the same CPU: | |
| 282 </p> | |
| 283 <pre class="code"> | |
| 284 # Cross-compile to a 32 bit binary on a multilib x64 OS | |
| 285 make CC="gcc -m32" | |
| 286 | |
| 287 # Cross-compile on Debian/Ubuntu for Windows (mingw32 package) | |
| 288 make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows | |
| 289 </pre> | |
| 290 <p id="cross2"> | |
| 291 The <tt>CROSS</tt> prefix allows specifying a standard GNU cross-compile | |
| 292 toolchain (Binutils, GCC and a matching libc). The prefix may vary | |
| 293 depending on the <tt>--target</tt> the toolchain was built for (note the | |
| 294 <tt>CROSS</tt> prefix has a trailing <tt>"-"</tt>). The examples below | |
| 295 use the canonical toolchain triplets for Linux. | |
| 296 </p> | |
| 297 <p> | |
| 298 Since there's often no easy way to detect CPU features at runtime, it's | |
| 299 important to compile with the proper CPU or architecture settings: | |
| 300 </o> | |
| 301 <ul> | |
| 302 <li>The best way to get consistent results is to specify the correct settings when building the toolchain yourself.</li> | |
| 303 <li>For a pre-built, generic toolchain add <tt>-mcpu=...</tt> or <tt>-march=...</tt> and other necessary flags to <tt>TARGET_CFLAGS</tt>.</li> | |
| 304 <li>For ARM it's important to have the correct <tt>-mfloat-abi=...</tt> setting, too. Otherwise LuaJIT may not run at the full performance of your target CPU.</li> | |
| 305 <li>For MIPS it's important to select a supported ABI (o32 on MIPS32, n64 on MIPS64) and consistently compile your project either with hard-float or soft-float compiler settings.</li> | |
| 306 </ul> | |
| 307 <p> | |
| 308 Here are some examples for targets with a different CPU than the host: | |
| 309 </p> | |
| 310 <pre class="code"> | |
| 311 # ARM soft-float | |
| 312 make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ | |
| 313 TARGET_CFLAGS="-mfloat-abi=soft" | |
| 314 | |
| 315 # ARM soft-float ABI with VFP (example for Cortex-A9) | |
| 316 make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- \ | |
| 317 TARGET_CFLAGS="-mcpu=cortex-a9 -mfloat-abi=softfp" | |
| 318 | |
| 319 # ARM hard-float ABI with VFP (armhf, most modern toolchains) | |
| 320 make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabihf- | |
| 321 | |
| 322 # ARM64 | |
| 323 make CROSS=aarch64-linux-gnu- | |
| 324 | |
| 325 # PPC | |
| 326 make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- | |
| 327 | |
| 328 # MIPS32 big-endian | |
| 329 make HOST_CC="gcc -m32" CROSS=mips-linux-gnu- | |
| 330 # MIPS32 little-endian | |
| 331 make HOST_CC="gcc -m32" CROSS=mipsel-linux-gnu- | |
| 332 | |
| 333 # MIPS64 big-endian | |
| 334 make CROSS=mips-linux- TARGET_CFLAGS="-mips64r2 -mabi=64" | |
| 335 # MIPS64 little-endian | |
| 336 make CROSS=mipsel-linux- TARGET_CFLAGS="-mips64r2 -mabi=64" | |
| 337 </pre> | |
| 338 <p> | |
| 339 You can cross-compile for <b id="android">Android</b> using the <a href="https://developer.android.com/ndk/"><span class="ext">»</span> Android NDK</a>. | |
| 340 Please adapt the environment variables to match the install locations and the | |
| 341 desired target platform. E.g. Android 4.1 corresponds to ABI level 16. | |
| 342 </p> | |
| 343 <pre class="code"> | |
| 344 # Android/ARM64, aarch64, Android 5.0+ (L) | |
| 345 NDKDIR=/opt/android/ndk | |
| 346 NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin | |
| 347 NDKCROSS=$NDKBIN/aarch64-linux-android- | |
| 348 NDKCC=$NDKBIN/aarch64-linux-android21-clang | |
| 349 make CROSS=$NDKCROSS \ | |
| 350 STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ | |
| 351 TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ | |
| 352 TARGET_STRIP=$NDKBIN/llvm-strip | |
| 353 | |
| 354 # Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.1+ (JB) | |
| 355 NDKDIR=/opt/android/ndk | |
| 356 NDKBIN=$NDKDIR/toolchains/llvm/prebuilt/linux-x86_64/bin | |
| 357 NDKCROSS=$NDKBIN/arm-linux-androideabi- | |
| 358 NDKCC=$NDKBIN/armv7a-linux-androideabi16-clang | |
| 359 make HOST_CC="gcc -m32" CROSS=$NDKCROSS \ | |
| 360 STATIC_CC=$NDKCC DYNAMIC_CC="$NDKCC -fPIC" \ | |
| 361 TARGET_LD=$NDKCC TARGET_AR="$NDKBIN/llvm-ar rcus" \ | |
| 362 TARGET_STRIP=$NDKBIN/llvm-strip | |
| 363 </pre> | |
| 364 <p> | |
| 365 You can cross-compile for <b id="ios">iOS 3.0+</b> (iPhone/iPad) using the <a href="https://developer.apple.com/ios/"><span class="ext">»</span> iOS SDK</a>: | |
| 366 </p> | |
| 367 <p style="font-size: 8pt;"> | |
| 368 Note: <b>the JIT compiler is disabled for iOS</b>, because regular iOS Apps | |
| 369 are not allowed to generate code at runtime. You'll only get the performance | |
| 370 of the LuaJIT interpreter on iOS. This is still faster than plain Lua, but | |
| 371 much slower than the JIT compiler. Please complain to Apple, not me. | |
| 372 Or use Android. :-p | |
| 373 </p> | |
| 374 <pre class="code"> | |
| 375 # iOS/ARM64 | |
| 376 ISDKP=$(xcrun --sdk iphoneos --show-sdk-path) | |
| 377 ICC=$(xcrun --sdk iphoneos --find clang) | |
| 378 ISDKF="-arch arm64 -isysroot $ISDKP" | |
| 379 make DEFAULT_CC=clang CROSS="$(dirname $ICC)/" \ | |
| 380 TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS | |
| 381 </pre> | |
| 382 | |
| 383 <h3 id="consoles">Cross-compiling for consoles</h3> | |
| 384 <p> | |
| 385 Building LuaJIT for consoles requires both a supported host compiler | |
| 386 (x86 or x64) and a cross-compiler from the official console SDK. | |
| 387 </p> | |
| 388 <p> | |
| 389 Due to restrictions on consoles, the JIT compiler is disabled and only | |
| 390 the fast interpreter is built. This is still faster than plain Lua, | |
| 391 but much slower than the JIT compiler. The FFI is disabled, too, since | |
| 392 it's not very useful in such an environment. | |
| 393 </p> | |
| 394 <p> | |
| 395 The following commands build a static library <tt>libluajit.a</tt>, | |
| 396 which can be linked against your game, just like the Lua library. | |
| 397 </p> | |
| 398 <p> | |
| 399 To cross-compile for <b id="ps3">PS3</b> from a Linux host (requires | |
| 400 32 bit GCC, i.e. multilib Linux/x64) or a Windows host (requires | |
| 401 32 bit MinGW), run this command: | |
| 402 </p> | |
| 403 <pre class="code"> | |
| 404 make HOST_CC="gcc -m32" CROSS=ppu-lv2- | |
| 405 </pre> | |
| 406 <p> | |
| 407 To cross-compile for the other consoles from a Windows host, open a | |
| 408 "Native Tools Command Prompt for VS". You need to choose either the 32 | |
| 409 or the 64 bit version of the host compiler to match the target. | |
| 410 Then <tt>cd</tt> to the <tt>src</tt> directory below the source code | |
| 411 and run the build command given in the table: | |
| 412 </p> | |
| 413 <table class="compat"> | |
| 414 <tr class="compathead"> | |
| 415 <td class="compatname">Console</td> | |
| 416 <td class="compatbits">Bits</td> | |
| 417 <td class="compatx">Build Command</td> | |
| 418 </tr> | |
| 419 <tr class="odd separate"> | |
| 420 <td class="compatname"><b id="ps4">PS4</b></td> | |
| 421 <td class="compatbits">64</td> | |
| 422 <td class="compatx"><tt>ps4build</tt></td> | |
| 423 </tr> | |
| 424 <tr class="even"> | |
| 425 <td class="compatname"><b id="ps5">PS5</b></td> | |
| 426 <td class="compatbits">64</td> | |
| 427 <td class="compatx"><tt>ps5build</tt></td> | |
| 428 </tr> | |
| 429 <tr class="odd"> | |
| 430 <td class="compatname"><b id="psvita">PS Vita</b></td> | |
| 431 <td class="compatbits">32</td> | |
| 432 <td class="compatx"><tt>psvitabuild</tt></td> | |
| 433 </tr> | |
| 434 <tr class="even"> | |
| 435 <td class="compatname"><b id="xbox360">Xbox 360</b></td> | |
| 436 <td class="compatbits">32</td> | |
| 437 <td class="compatx"><tt>xedkbuild</tt></td> | |
| 438 </tr> | |
| 439 <tr class="odd"> | |
| 440 <td class="compatname"><b id="xboxone">Xbox One</b></td> | |
| 441 <td class="compatbits">64</td> | |
| 442 <td class="compatx"><tt>xb1build</tt></td> | |
| 443 </tr> | |
| 444 <tr class="even"> | |
| 445 <td class="compatname"><b id="nx32">Nintendo Switch NX32</b></td> | |
| 446 <td class="compatbits">32</td> | |
| 447 <td class="compatx"><tt>nxbuild</tt></td> | |
| 448 </tr> | |
| 449 <tr class="odd"> | |
| 450 <td class="compatname"><b id="nx64">Nintendo Switch NX64</b></td> | |
| 451 <td class="compatbits">64</td> | |
| 452 <td class="compatx"><tt>nxbuild</tt></td> | |
| 453 </tr> | |
| 454 </table> | |
| 455 <p> | |
| 456 Please check out the comments in the corresponding <tt>*.bat</tt> | |
| 457 file for more options. | |
| 458 </p> | |
| 459 | |
| 460 <h2 id="embed">Embedding LuaJIT</h2> | |
| 461 <p> | |
| 462 LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua | |
| 463 into your application, you probably don't need to do anything to switch | |
| 464 to LuaJIT, except link with a different library: | |
| 465 </p> | |
| 466 <ul> | |
| 467 <li>It's strongly suggested to build LuaJIT separately using the supplied | |
| 468 build system. Please do <em>not</em> attempt to integrate the individual | |
| 469 source files into your build tree. You'll most likely get the internal build | |
| 470 dependencies wrong or mess up the compiler flags. Treat LuaJIT like any | |
| 471 other external library and link your application with either the dynamic | |
| 472 or static library, depending on your needs.</li> | |
| 473 <li>If you want to load C modules compiled for plain Lua | |
| 474 with <tt>require()</tt>, you need to make sure the public symbols | |
| 475 (e.g. <tt>lua_pushnumber</tt>) are exported, too: | |
| 476 <ul><li>On POSIX systems you can either link to the shared library | |
| 477 or link the static library into your application. In the latter case | |
| 478 you'll need to export all public symbols from your main executable | |
| 479 (e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies | |
| 480 (e.g. <tt>-lm -ldl</tt> on Linux).</li> | |
| 481 <li>Since Windows symbols are bound to a specific DLL name, you need to | |
| 482 link to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename | |
| 483 the DLL). You may link LuaJIT statically on Windows only if you don't | |
| 484 intend to load Lua/C modules at runtime. | |
| 485 </li></ul> | |
| 486 </li> | |
| 487 </ul> | |
| 488 <p>Additional hints for initializing LuaJIT using the C API functions:</p> | |
| 489 <ul> | |
| 490 <li>Here's a | |
| 491 <a href="http://lua-users.org/wiki/SimpleLuaApiExample"><span class="ext">»</span> simple example</a> | |
| 492 for embedding Lua or LuaJIT into your application.</li> | |
| 493 <li>Make sure you use <tt>luaL_newstate</tt>. Avoid using | |
| 494 <tt>lua_newstate</tt>, since this uses the (slower) default memory | |
| 495 allocator from your system (no support for this on 64 bit architectures).</li> | |
| 496 <li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style | |
| 497 of calling <tt>luaopen_base</tt> etc. directly.</li> | |
| 498 <li>To change or extend the list of standard libraries to load, copy | |
| 499 <tt>src/lib_init.c</tt> to your project and modify it accordingly. | |
| 500 Make sure the <tt>jit</tt> library is loaded, or the JIT compiler | |
| 501 will not be activated.</li> | |
| 502 <li>The <tt>bit.*</tt> module for bitwise operations | |
| 503 is already built-in. There's no need to statically link | |
| 504 <a href="https://bitop.luajit.org/"><span class="ext">»</span> Lua BitOp</a> to your application.</li> | |
| 505 </ul> | |
| 506 | |
| 507 <h2 id="distro">Hints for Distribution Maintainers</h2> | |
| 508 <p> | |
| 509 The LuaJIT build system has extra provisions for the needs of most | |
| 510 POSIX-based distributions. If you're a package maintainer for | |
| 511 a distribution, <em>please</em> make use of these features and | |
| 512 avoid patching, subverting, autotoolizing or messing up the build system | |
| 513 in unspeakable ways. | |
| 514 </p> | |
| 515 <p> | |
| 516 There should be absolutely no need to patch <tt>luaconf.h</tt> or any | |
| 517 of the Makefiles. And please do not hand-pick files for your packages — | |
| 518 simply use whatever <tt>make install</tt> creates. There's a reason | |
| 519 for all the files <em>and</em> directories it creates. | |
| 520 </p> | |
| 521 <p> | |
| 522 The build system uses GNU make and auto-detects most settings based on | |
| 523 the host you're building it on. This should work fine for native builds, | |
| 524 even when sandboxed. You may need to pass some of the following flags to | |
| 525 <em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines | |
| 526 for a regular distribution build: | |
| 527 </p> | |
| 528 <ul> | |
| 529 <li><tt>PREFIX</tt> overrides the installation path and should usually | |
| 530 be set to <tt>/usr</tt>. Setting this also changes the module paths and | |
| 531 the paths needed to locate the shared library.</li> | |
| 532 <li><tt>DESTDIR</tt> is an absolute path which allows you to install | |
| 533 to a shadow tree instead of the root tree of the build system.</li> | |
| 534 <li><tt>MULTILIB</tt> sets the architecture-specific library path component | |
| 535 for multilib systems. The default is <tt>lib</tt>.</li> | |
| 536 <li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt> | |
| 537 for additional variables to tweak. The following variables <em>may</em> be | |
| 538 overridden, but it's <em>not</em> recommended, except for special needs | |
| 539 like cross-builds: | |
| 540 <tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS, | |
| 541 TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS, | |
| 542 TARGET_FLAGS, LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS | |
| 543 </tt></li> | |
| 544 </ul> | |
| 545 <p> | |
| 546 The build system has a special target for an amalgamated build, i.e. | |
| 547 <tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file | |
| 548 and allows GCC to generate faster and shorter code. Alas, this requires | |
| 549 lots of memory during the build. This may be a problem for some users, | |
| 550 that's why it's not enabled by default. But it shouldn't be a problem for | |
| 551 most build farms. It's recommended that binary distributions use this | |
| 552 target for their LuaJIT builds. | |
| 553 </p> | |
| 554 <p> | |
| 555 The tl;dr version of the above: | |
| 556 </p> | |
| 557 <pre class="code"> | |
| 558 make amalg PREFIX=/usr && \ | |
| 559 make install PREFIX=/usr DESTDIR=/tmp/buildroot | |
| 560 </pre> | |
| 561 <p> | |
| 562 Finally, if you encounter any difficulties, please | |
| 563 <a href="contact.html">contact me</a> first, instead of releasing a broken | |
| 564 package onto unsuspecting users. Because they'll usually gonna complain | |
| 565 to me (the upstream) and not you (the package maintainer), anyway. | |
| 566 </p> | |
| 567 <br class="flush"> | |
| 568 </div> | |
| 569 <div id="foot"> | |
| 570 <hr class="hide"> | |
| 571 Copyright © 2005-2023 | |
| 572 <span class="noprint"> | |
| 573 · | |
| 574 <a href="contact.html">Contact</a> | |
| 575 </span> | |
| 576 </div> | |
| 577 </body> | |
| 578 </html> |