install.html 25 KB

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