install.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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-2011, 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. width: 600px;
  15. }
  16. table.compat td {
  17. border: 1px solid #bfcfff;
  18. font-size: 90%;
  19. height: 2.5em;
  20. }
  21. table.compat tr.compathead td {
  22. font-weight: bold;
  23. border-bottom: 2px solid #bfcfff;
  24. }
  25. tr.compathead td.compatos {
  26. vertical-align: top;
  27. }
  28. table.compat td.compatcpu {
  29. width: 16%;
  30. border-right: 2px solid #bfcfff;
  31. }
  32. td.compatos {
  33. width: 21%;
  34. vertical-align: middle;
  35. }
  36. td.compatno {
  37. background-color: #d0d0d0;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div id="site">
  43. <a href="http://luajit.org"><span>Lua<span id="logo">JIT</span></span></a>
  44. </div>
  45. <div id="head">
  46. <h1>Installation</h1>
  47. </div>
  48. <div id="nav">
  49. <ul><li>
  50. <a href="luajit.html">LuaJIT</a>
  51. <ul><li>
  52. <a class="current" href="install.html">Installation</a>
  53. </li><li>
  54. <a href="running.html">Running</a>
  55. </li></ul>
  56. </li><li>
  57. <a href="extensions.html">Extensions</a>
  58. <ul><li>
  59. <a href="ext_ffi.html">FFI Library</a>
  60. <ul><li>
  61. <a href="ext_ffi_tutorial.html">FFI Tutorial</a>
  62. </li><li>
  63. <a href="ext_ffi_api.html">ffi.* API</a>
  64. </li><li>
  65. <a href="ext_ffi_int64.html">64 bit Integers</a>
  66. </li><li>
  67. <a href="ext_ffi_semantics.html">FFI Semantics</a>
  68. </li></ul>
  69. </li><li>
  70. <a href="ext_jit.html">jit.* Library</a>
  71. </li><li>
  72. <a href="ext_c_api.html">Lua/C API</a>
  73. </li></ul>
  74. </li><li>
  75. <a href="status.html">Status</a>
  76. <ul><li>
  77. <a href="changes.html">Changes</a>
  78. </li></ul>
  79. </li><li>
  80. <a href="faq.html">FAQ</a>
  81. </li><li>
  82. <a href="http://luajit.org/performance.html">Performance <span class="ext">&raquo;</span></a>
  83. </li><li>
  84. <a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a>
  85. </li></ul>
  86. </div>
  87. <div id="main">
  88. <p>
  89. LuaJIT is only distributed as a source package. This page explains
  90. how to build and install LuaJIT with different operating systems
  91. and C&nbsp;compilers.
  92. </p>
  93. <p>
  94. For the impatient (on POSIX systems):
  95. </p>
  96. <pre class="code">
  97. make &amp;&amp; sudo make install
  98. </pre>
  99. <p>
  100. LuaJIT currently builds out-of-the box on most systems.
  101. Here's the compatibility matrix for the supported combinations of
  102. operating system, CPU and compilers:
  103. </p>
  104. <table class="compat">
  105. <tr class="compathead">
  106. <td class="compatcpu">CPU / OS</td>
  107. <td class="compatos"><a href="#posix">Linux</a></td>
  108. <td class="compatos"><a href="#posix">OSX<br>10.3-10.6</a></td>
  109. <td class="compatos"><a href="#posix">*BSD, other</a></td>
  110. <td class="compatos"><a href="#windows">Windows<br>98/XP/Vista/7</a></td>
  111. </tr>
  112. <tr class="odd separate">
  113. <td class="compatcpu">x86 (32 bit)</td>
  114. <td class="compatos">GCC 4.x<br>GCC 3.4</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">MSVC, MSVC/EE<br>WinSDK<br>MinGW, Cygwin</td>
  118. </tr>
  119. <tr class="even">
  120. <td class="compatcpu">x64 (64 bit)</td>
  121. <td class="compatos">GCC 4.x</td>
  122. <td class="compatos">GCC 4.x</td>
  123. <td class="compatos compatno">&nbsp;</td>
  124. <td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0</td>
  125. </tr>
  126. <tr class="odd">
  127. <td class="compatcpu">PPC/e500v2</td>
  128. <td class="compatos">GCC 4.3+</td>
  129. <td class="compatos compatno">&nbsp;</td>
  130. <td class="compatos compatno">&nbsp;</td>
  131. <td class="compatos compatno">&nbsp;</td>
  132. </tr>
  133. </table>
  134. <h2>Configuring LuaJIT</h2>
  135. <p>
  136. The standard configuration should work fine for most installations.
  137. Usually there is no need to tweak the settings. The following files
  138. hold all user-configurable settings:
  139. </p>
  140. <ul>
  141. <li><tt>src/luaconf.h</tt> sets some configuration variables.</li>
  142. <li><tt>Makefile</tt> has settings for <b>installing</b> LuaJIT (POSIX
  143. only).</li>
  144. <li><tt>src/Makefile</tt> has settings for <b>compiling</b> LuaJIT
  145. under POSIX, MinGW or Cygwin.</li>
  146. <li><tt>src/msvcbuild.bat</tt> has settings for compiling LuaJIT with
  147. MSVC or WinSDK.</li>
  148. </ul>
  149. <p>
  150. Please read the instructions given in these files, before changing
  151. any settings.
  152. </p>
  153. <h2 id="posix">POSIX Systems (Linux, OSX, *BSD etc.)</h2>
  154. <h3>Prerequisites</h3>
  155. <p>
  156. Depending on your distribution, you may need to install a package for
  157. GCC, the development headers and/or a complete SDK. E.g. on a current
  158. Debian/Ubuntu, install <tt>libc6-dev</tt> with the package manager.
  159. </p>
  160. <p>
  161. Download the current source package of LuaJIT (pick the .tar.gz),
  162. if you haven't already done so. Move it to a directory of your choice,
  163. open a terminal window and change to this directory. Now unpack the archive
  164. and change to the newly created directory:
  165. </p>
  166. <pre class="code">
  167. tar zxf LuaJIT-2.0.0-beta5.tar.gz
  168. cd LuaJIT-2.0.0-beta5</pre>
  169. <h3>Building LuaJIT</h3>
  170. <p>
  171. The supplied Makefiles try to auto-detect the settings needed for your
  172. operating system and your compiler. They need to be run with GNU Make,
  173. which is probably the default on your system, anyway. Simply run:
  174. </p>
  175. <pre class="code">
  176. make
  177. </pre>
  178. <p>
  179. This always builds a native x86, x64 or PPC binary, depending on the host OS
  180. you're running this command on. Check the section on
  181. <a href="#cross">cross-compilation</a> for more options.
  182. </p>
  183. <p>
  184. By default, modules are only searched under the prefix <tt>/usr/local</tt>.
  185. You can add an extra prefix to the search paths by appending the
  186. <tt>PREFIX</tt> option, e.g.:
  187. </p>
  188. <pre class="code">
  189. make PREFIX=/home/myself/lj2
  190. </pre>
  191. <p>
  192. Note for OSX: <tt>MACOSX_DEPLOYMENT_TARGET</tt> is set to <tt>10.4</tt>
  193. in <tt>src/Makefile</tt>. Change it, if you want to build on an older version.
  194. </p>
  195. <h3>Installing LuaJIT</h3>
  196. <p>
  197. The top-level Makefile installs LuaJIT by default under
  198. <tt>/usr/local</tt>, i.e. the executable ends up in
  199. <tt>/usr/local/bin</tt> and so on. You need root privileges
  200. to write to this path. So, assuming sudo is installed on your system,
  201. run the following command and enter your sudo password:
  202. </p>
  203. <pre class="code">
  204. sudo make install
  205. </pre>
  206. <p>
  207. Otherwise specify the directory prefix as an absolute path, e.g.:
  208. </p>
  209. <pre class="code">
  210. make install PREFIX=/home/myself/lj2
  211. </pre>
  212. <p>
  213. Obviously the prefixes given during build and installation need to be the same.
  214. </p>
  215. <p style="color: #c00000;">
  216. Note: to avoid overwriting a previous version, the beta test releases
  217. only install the LuaJIT executable under the versioned name (i.e.
  218. <tt>luajit-2.0.0-beta5</tt>). You probably want to create a symlink
  219. for convenience, with a command like this:
  220. </p>
  221. <pre class="code" style="color: #c00000;">
  222. sudo ln -sf luajit-2.0.0-beta5&nbsp;/usr/local/bin/luajit
  223. </pre>
  224. <h2 id="windows">Windows Systems</h2>
  225. <h3>Prerequisites</h3>
  226. <p>
  227. Either install one of the open source SDKs
  228. (<a href="http://mingw.org/"><span class="ext">&raquo;</span>&nbsp;MinGW</a> or
  229. <a href="http://www.cygwin.com/"><span class="ext">&raquo;</span>&nbsp;Cygwin</a>), which come with a modified
  230. GCC plus the required development headers.
  231. </p>
  232. <p>
  233. Or install Microsoft's Visual C++ (MSVC). The freely downloadable
  234. <a href="http://www.microsoft.com/Express/VC/"><span class="ext">&raquo;</span>&nbsp;Express Edition</a>
  235. works just fine, but only contains an x86 compiler.
  236. </p>
  237. <p>
  238. The freely downloadable
  239. <a href="http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx"><span class="ext">&raquo;</span>&nbsp;Windows SDK</a>
  240. only comes with command line tools, but this is all you need to build LuaJIT.
  241. It contains x86 and x64 compilers.
  242. </p>
  243. <p>
  244. Next, download the source package and unpack it using an archive manager
  245. (e.g. the Windows Explorer) to a directory of your choice.
  246. </p>
  247. <h3>Building with MSVC</h3>
  248. <p>
  249. Open a "Visual Studio .NET Command Prompt", <tt>cd</tt> to the
  250. directory where you've unpacked the sources and run these commands:
  251. </p>
  252. <pre class="code">
  253. cd src
  254. msvcbuild
  255. </pre>
  256. <p>
  257. Then follow the installation instructions below.
  258. </p>
  259. <h3>Building with the Windows SDK</h3>
  260. <p>
  261. Open a "Windows SDK Command Shell" and select the x86 compiler:
  262. </p>
  263. <pre class="code">
  264. setenv /release /x86
  265. </pre>
  266. <p>
  267. Or select the x64 compiler:
  268. </p>
  269. <pre class="code">
  270. setenv /release /x64
  271. </pre>
  272. <p>
  273. Then <tt>cd</tt> to the directory where you've unpacked the sources
  274. and run these commands:
  275. </p>
  276. <pre class="code">
  277. cd src
  278. msvcbuild
  279. </pre>
  280. <p>
  281. Then follow the installation instructions below.
  282. </p>
  283. <h3>Building with MinGW or Cygwin</h3>
  284. <p>
  285. Open a command prompt window and make sure the MinGW or Cygwin programs
  286. are in your path. Then <tt>cd</tt> to the directory where
  287. you've unpacked the sources and run this command for MinGW:
  288. </p>
  289. <pre class="code">
  290. mingw32-make
  291. </pre>
  292. <p>
  293. Or this command for Cygwin:
  294. </p>
  295. <pre class="code">
  296. make
  297. </pre>
  298. <p>
  299. Then follow the installation instructions below.
  300. </p>
  301. <h3>Installing LuaJIT</h3>
  302. <p>
  303. Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt> (built in the <tt>src</tt>
  304. directory) to a newly created directory (any location is ok).
  305. Add <tt>lua</tt> and <tt>lua\jit</tt> directories below it and copy
  306. all Lua files from the <tt>lib</tt> directory of the distribution
  307. to the latter directory.
  308. </p>
  309. <p>
  310. There are no hardcoded
  311. absolute path names &mdash; all modules are loaded relative to the
  312. directory where <tt>luajit.exe</tt> is installed
  313. (see <tt>src/luaconf.h</tt>).
  314. </p>
  315. <h2 id="cross">Cross-compiling LuaJIT</h2>
  316. <p>
  317. The build system has limited support for cross-compilation. For details
  318. check the comments in <tt>src/Makefile</tt>. Here are some popular examples:
  319. </p>
  320. <p>
  321. You can cross-compile to a 32 bit binary on a multilib x64 OS by
  322. installing the multilib development packages (e.g. <tt>libc6-dev-i386</tt>
  323. on Debian/Ubuntu) and running:
  324. </p>
  325. <pre class="code">
  326. make CC="gcc -m32"
  327. </pre>
  328. <p>
  329. You can cross-compile for a Windows target on Debian/Ubuntu by
  330. installing the <tt>mingw32</tt> package and running:
  331. </p>
  332. <pre class="code">
  333. make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
  334. </pre>
  335. <p>
  336. You can cross-compile for a PPC/e500v2 target on an x86 or x64 host system
  337. using a standard GNU cross-compile toolchain (Binutils, GCC, EGLIBC).
  338. The <tt>CROSS</tt> prefix may vary depending on the <tt>--target</tt>
  339. of the toolchain:
  340. </p>
  341. <pre class="code">
  342. make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe- TARGET=ppcspe
  343. </pre>
  344. <h2 id="embed">Embedding LuaJIT</h2>
  345. <p>
  346. LuaJIT is API-compatible with Lua 5.1. If you've already embedded Lua
  347. into your application, you probably don't need to do anything to switch
  348. to LuaJIT, except link with a different library:
  349. </p>
  350. <ul>
  351. <li>It's strongly suggested to build LuaJIT separately using the supplied
  352. build system. Please do <em>not</em> attempt to integrate the individual
  353. source files into your build tree. You'll most likely get the internal build
  354. dependencies wrong or mess up the compiler flags. Treat LuaJIT like any
  355. other external library and link your application with either the dynamic
  356. or static library, depending on your needs.</li>
  357. <li>If you want to load C modules compiled for plain Lua
  358. with <tt>require()</tt>, you need to make sure the public symbols
  359. (e.g. <tt>lua_pushnumber</tt>) are exported, too:
  360. <ul><li>On POSIX systems you can either link to the shared library
  361. or link the static library into your application. In the latter case
  362. you'll need to export all public symbols from your main executable
  363. (e.g. <tt>-Wl,-E</tt> on Linux) and add the external dependencies
  364. (e.g. <tt>-lm -ldl</tt> on Linux).</li>
  365. <li>Since Windows symbols are bound to a specific DLL name, you need to
  366. link to the <tt>lua51.dll</tt> created by the LuaJIT build (do not rename
  367. the DLL). You may link LuaJIT statically on Windows only if you don't
  368. intend to load Lua/C modules at runtime.
  369. </li></ul>
  370. </li>
  371. <li>
  372. If you're building a 64 bit application on OSX which links directly or
  373. indirectly against LuaJIT, you need to link your main executable
  374. with these flags:
  375. <pre class="code">
  376. -pagezero_size 10000 -image_base 100000000
  377. </pre>
  378. Also, it's recommended to <tt>rebase</tt> all (self-compiled) shared libraries
  379. which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua).
  380. See: <tt>man rebase</tt>
  381. </li>
  382. </ul>
  383. <p>Additional hints for initializing LuaJIT using the C API functions:</p>
  384. <ul>
  385. <li>Here's a
  386. <a href="http://lua-users.org/wiki/SimpleLuaApiExample"><span class="ext">&raquo;</span>&nbsp;simple example</a>
  387. for embedding Lua or LuaJIT into your application.</li>
  388. <li>Make sure you use <tt>luaL_newstate</tt>. Avoid using
  389. <tt>lua_newstate</tt>, since this uses the (slower) default memory
  390. allocator from your system (no support for this on x64).</tt></li>
  391. <li>Make sure you use <tt>luaL_openlibs</tt> and not the old Lua 5.0 style
  392. of calling <tt>luaopen_base</tt> etc. directly.</li>
  393. <li>To change or extend the list of standard libraries to load, copy
  394. <tt>src/lib_init.c</tt> to your project and modify it accordingly.
  395. Make sure the <tt>jit</tt> library is loaded or the JIT compiler
  396. will not be activated.</li>
  397. <li>The <tt>bit.*</tt> module for bitwise operations
  398. is already built-in. There's no need to statically link
  399. <a href="http://bitop.luajit.org/"><span class="ext">&raquo;</span>&nbsp;Lua BitOp</a> to your application.</li>
  400. </ul>
  401. <h2 id="distro">Hints for Distribution Maintainers</h2>
  402. <p>
  403. The LuaJIT build system has extra provisions for the needs of most
  404. POSIX-based distributions. If you're a package maintainer for
  405. a distribution, <em>please</em> make use of these features and
  406. avoid patching, subverting, autotoolizing or messing up the build system
  407. in unspeakable ways.
  408. </p>
  409. <p>
  410. There should be absolutely no need to patch <tt>luaconf.h</tt> or any
  411. of the Makefiles. And please do not hand-pick files for your packages &mdash;
  412. simply use whatever <tt>make install</tt> creates. There's a reason
  413. for all of the files <em>and</em> directories it creates.
  414. </p>
  415. <p>
  416. The build system uses GNU make and autodetects most settings based on
  417. the host you're building it on. This should work fine for native builds,
  418. even when sandboxed. You may need to pass some of the following flags to
  419. <em>both</em> the <tt>make</tt> and the <tt>make install</tt> command lines
  420. for a regular distribution build:
  421. </p>
  422. <ul>
  423. <li><tt>PREFIX</tt> overrides the installation path and should usually
  424. be set to <tt>/usr</tt>. Setting this also changes the module paths and
  425. the <tt>-rpath</tt> of the shared library.</li>
  426. <li><tt>DESTDIR</tt> is an absolute path which allows you to install
  427. to a shadow tree instead of the root tree of the build system.</li>
  428. <li>Have a look at the top-level <tt>Makefile</tt> and <tt>src/Makefile</tt>
  429. for additional variables to tweak. The following variables <em>may</em> be
  430. overriden, but it's <em>not</em> recommended, except for special needs
  431. like cross-builds:
  432. <tt>BUILDMODE, CC, HOST_CC, STATIC_CC, DYNAMIC_CC, CFLAGS, HOST_CFLAGS,
  433. TARGET_CFLAGS, LDFLAGS, HOST_LDFLAGS, TARGET_LDFLAGS, TARGET_SHLDFLAGS,
  434. LIBS, HOST_LIBS, TARGET_LIBS, CROSS, HOST_SYS, TARGET_SYS</tt></li>
  435. </ul>
  436. <p>
  437. The build system has a special target for an amalgamated build, i.e.
  438. <tt>make amalg</tt>. This compiles the LuaJIT core as one huge C file
  439. and allows GCC to generate faster and shorter code. Alas, this requires
  440. lots of memory during the build. This may be a problem for some users,
  441. that's why it's not enabled by default. But it shouldn't be a problem for
  442. most build farms. It's recommended that binary distributions use this
  443. target for their LuaJIT builds.
  444. </p>
  445. <p>
  446. The tl;dr version of the above:
  447. </p>
  448. <pre class="code">
  449. make amalg PREFIX=/usr && \
  450. make install PREFIX=/usr DESTDIR=/tmp/buildroot
  451. </pre>
  452. <p>
  453. Finally, if you encounter any difficulties, please
  454. <a href="contact.html">contact me</a> first, instead of releasing a broken
  455. package onto unsuspecting users. Because they'll usually gonna complain
  456. to me (the upstream) and not you (the package maintainer), anyway.
  457. </p>
  458. <br class="flush">
  459. </div>
  460. <div id="foot">
  461. <hr class="hide">
  462. Copyright &copy; 2005-2011 Mike Pall
  463. <span class="noprint">
  464. &middot;
  465. <a href="contact.html">Contact</a>
  466. </span>
  467. </div>
  468. </body>
  469. </html>