install.html 23 KB

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