install.html 27 KB

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