install.html 22 KB

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