install.html 17 KB

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