install.html 27 KB

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