install.rst revision 7ec681f3
17ec681f3SmrgCompiling and Installing
27ec681f3Smrg========================
37ec681f3Smrg
47ec681f3Smrg.. toctree::
57ec681f3Smrg   :maxdepth: 1
67ec681f3Smrg   :hidden:
77ec681f3Smrg
87ec681f3Smrg   meson
97ec681f3Smrg
107ec681f3Smrg1. Prerequisites for building
117ec681f3Smrg-----------------------------
127ec681f3Smrg
137ec681f3Smrg1.1 General
147ec681f3Smrg~~~~~~~~~~~
157ec681f3Smrg
167ec681f3SmrgBuild system
177ec681f3Smrg^^^^^^^^^^^^
187ec681f3Smrg
197ec681f3Smrg-  `Meson <https://mesonbuild.com>`__ is required when building on \*nix
207ec681f3Smrg   platforms and on Windows.
217ec681f3Smrg-  Android Build system when building as native Android component. Meson
227ec681f3Smrg   is used when building ARC.
237ec681f3Smrg
247ec681f3SmrgCompiler
257ec681f3Smrg^^^^^^^^
267ec681f3Smrg
277ec681f3SmrgThe following compilers are known to work, if you know of others or
287ec681f3Smrgyou're willing to maintain support for other compiler get in touch.
297ec681f3Smrg
307ec681f3Smrg-  GCC 4.2.0 or later (some parts of Mesa may require later versions)
317ec681f3Smrg-  Clang - exact minimum requirement is currently unknown.
327ec681f3Smrg-  Microsoft Visual Studio 2015 or later is required, for building on
337ec681f3Smrg   Windows.
347ec681f3Smrg
357ec681f3SmrgThird party/extra tools.
367ec681f3Smrg^^^^^^^^^^^^^^^^^^^^^^^^
377ec681f3Smrg
387ec681f3Smrg-  `Python <https://www.python.org/>`__ - Python 3.5 or newer is required.
397ec681f3Smrg-  `Python Mako module <http://www.makotemplates.org/>`__ - Python Mako
407ec681f3Smrg   module is required. Version 0.8.0 or later should work.
417ec681f3Smrg-  Lex / Yacc - for building the Mesa IR and GLSL compiler.
427ec681f3Smrg
437ec681f3Smrg   On Linux systems, Flex and Bison versions 2.5.35 and 2.4.1,
447ec681f3Smrg   respectively, (or later) should work. On Windows with MinGW, install
457ec681f3Smrg   Flex and Bison with:
467ec681f3Smrg
477ec681f3Smrg   .. code-block:: console
487ec681f3Smrg
497ec681f3Smrg      mingw-get install msys-flex msys-bison
507ec681f3Smrg
517ec681f3Smrg   For MSVC on Windows, install `Win
527ec681f3Smrg   flex-bison <http://winflexbison.sourceforge.net/>`__.
537ec681f3Smrg
547ec681f3Smrg.. note::
557ec681f3Smrg
567ec681f3Smrg   Some versions can be buggy (e.g. Flex 2.6.2) so do try others
577ec681f3Smrg   if things fail.
587ec681f3Smrg
597ec681f3Smrg1.2 Requirements
607ec681f3Smrg~~~~~~~~~~~~~~~~
617ec681f3Smrg
627ec681f3SmrgThe requirements depends on the features selected at configure stage.
637ec681f3SmrgCheck/install the respective development package as prompted by the
647ec681f3Smrgconfigure error message.
657ec681f3Smrg
667ec681f3SmrgHere are some common ways to retrieve most/all of the dependencies based
677ec681f3Smrgon the packaging tool used by your distro.
687ec681f3Smrg
697ec681f3Smrg.. code-block:: console
707ec681f3Smrg
717ec681f3Smrg     zypper source-install --build-deps-only Mesa # openSUSE/SLED/SLES
727ec681f3Smrg     yum-builddep mesa # yum Fedora, OpenSuse(?)
737ec681f3Smrg     dnf builddep mesa # dnf Fedora
747ec681f3Smrg     apt-get build-dep mesa # Debian and derivatives
757ec681f3Smrg     ... # others
767ec681f3Smrg
777ec681f3Smrg2. Building with meson
787ec681f3Smrg----------------------
797ec681f3Smrg
807ec681f3Smrg**Meson >= 0.46.0 is required**
817ec681f3Smrg
827ec681f3SmrgMeson is the latest build system in mesa, it is currently able to build
837ec681f3Smrgfor \*nix systems like Linux and BSD, macOS, Haiku, and Windows.
847ec681f3Smrg
857ec681f3SmrgThe general approach is:
867ec681f3Smrg
877ec681f3Smrg.. code-block:: console
887ec681f3Smrg
897ec681f3Smrg     meson builddir/
907ec681f3Smrg     ninja -C builddir/
917ec681f3Smrg     sudo ninja -C builddir/ install
927ec681f3Smrg
937ec681f3SmrgOn Windows you can also use the Visual Studio backend
947ec681f3Smrg
957ec681f3Smrg.. code-block:: console
967ec681f3Smrg
977ec681f3Smrg     meson builddir --backend=vs
987ec681f3Smrg     cd builddir
997ec681f3Smrg     msbuild mesa.sln /m
1007ec681f3Smrg
1017ec681f3SmrgPlease read the :doc:`detailed meson instructions <meson>` for more
1027ec681f3Smrginformation
1037ec681f3Smrg
1047ec681f3Smrg3. Running against a local build
1057ec681f3Smrg--------------------------------
1067ec681f3Smrg
1077ec681f3SmrgIt's often necessary or useful when debugging driver issues or testing new
1087ec681f3Smrgbranches to run against a local build of Mesa without doing a system-wide
1097ec681f3Smrginstall.  To do this, choose a temporary location for the install.  A directory
1107ec681f3Smrgcalled ``installdir`` inside your mesa tree is as good as anything.  All of the
1117ec681f3Smrgcommands below will assume ``$MESA_INSTALLDIR`` is an absolute path to this
1127ec681f3Smrglocation.
1137ec681f3Smrg
1147ec681f3SmrgFirst, configure Mesa and install in the temporary location:
1157ec681f3Smrg
1167ec681f3Smrg.. code-block:: console
1177ec681f3Smrg
1187ec681f3Smrg   meson builddir/ -Dprefix="$MESA_INSTALLDIR" OTHER_OPTIONS
1197ec681f3Smrg   ninja -C builddir/ install
1207ec681f3Smrg
1217ec681f3Smrgwhere ``OTHER_OPTIONS`` is replaced by any meson configuration options you may
1227ec681f3Smrgwant.  For instance, if you want to build the LLVMpipe drivers, it would look
1237ec681f3Smrglike this:
1247ec681f3Smrg
1257ec681f3Smrg.. code-block:: console
1267ec681f3Smrg
1277ec681f3Smrg   meson builddir/ -Dprefix="$MESA_INSTALLDIR" -Ddri-drivers= \
1287ec681f3Smrg      -Dgallium-drivers=swrast -Dvulkan-drivers=swrast
1297ec681f3Smrg   ninja -C builddir/ install
1307ec681f3Smrg
1317ec681f3SmrgOnce Mesa has built and installed to ``$MESA_INSTALLDIR``, you can run any app
1327ec681f3Smrgagainst your temporary install by setting the right environment variables.
1337ec681f3SmrgWhich variable you have to set depends on the API.
1347ec681f3Smrg
1357ec681f3SmrgOpenGL
1367ec681f3Smrg~~~~~~
1377ec681f3Smrg
1387ec681f3Smrg.. code-block:: console
1397ec681f3Smrg
1407ec681f3Smrg   LD_LIBRARY_PATH="$MESA_INSTALLDIR/lib64" glxinfo
1417ec681f3Smrg
1427ec681f3SmrgYou may need to use ``lib`` instead of ``lib64`` on some systems or a full
1437ec681f3Smrglibrary specifier on debian.  Look inside ``installdir`` for the directory that
1447ec681f3Smrgcontains ``libGL.so`` and use that one.
1457ec681f3Smrg
1467ec681f3SmrgVulkan
1477ec681f3Smrg~~~~~~
1487ec681f3Smrg
1497ec681f3Smrg.. code-block:: console
1507ec681f3Smrg
1517ec681f3Smrg   VK_ICD_FILENAMES="$MESA_INSTALLDIR/share/vulkan/icd/my_icd.json" vulkaninfo
1527ec681f3Smrg
1537ec681f3Smrgwhere ``my_icd.json`` is replaced with the actual ICD json file name.  This
1547ec681f3Smrgwill depend on your driver.  For instance, the 64-bit lavapipe driver ICD file
1557ec681f3Smrgis named ``lvp_icd.x86_64.json``.
1567ec681f3Smrg
1577ec681f3SmrgOpenCL
1587ec681f3Smrg~~~~~~
1597ec681f3Smrg
1607ec681f3Smrg.. code-block:: console
1617ec681f3Smrg
1627ec681f3Smrg   OCL_ICD_VENDORS="$MESA_INSTALLDIR/etc/OpenCL/vendors" clinfo
1637ec681f3Smrg
1647ec681f3SmrgUnlike Vulkan, OpenCL takes a path to the whole ``vendors`` folder and will
1657ec681f3Smrgenumerate any drivers found there.
1667ec681f3Smrg
1677ec681f3SmrgTroubleshooting local builds
1687ec681f3Smrg~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1697ec681f3Smrg
1707ec681f3SmrgIf you are trying to run an app against a local build and it's not working,
1717ec681f3Smrghere are a few things to check:
1727ec681f3Smrg
1737ec681f3Smrg 1. Double-check your paths and try with the simplest app you can.  Before
1747ec681f3Smrg    banging your head on a Steam game, make sure your path works with
1757ec681f3Smrg    ``glxgears`` first.
1767ec681f3Smrg
1777ec681f3Smrg 2. Watch out for wrapper scripts.  Some more complex apps such as games have
1787ec681f3Smrg    big start-up scripts.  Sometimes those scripts scrub the environment or set
1797ec681f3Smrg    ``LD_LIBRARY_PATH`` to something in the game's install directory.
1807ec681f3Smrg
1817ec681f3Smrg 3. Is your Mesa build the same arch as your app?  Lots of games are still
1827ec681f3Smrg    32-bit and your Mesa build is probably 64-bit by default.
1837ec681f3Smrg
1847ec681f3Smrg 4. 32 and 64-bit builds in the same local install directory doesn't typically
1857ec681f3Smrg    work.  Distros go to great lengths to make this work in your system install
1867ec681f3Smrg    and it's hard to get it right for a local install.  If you've recently
1877ec681f3Smrg    built 64-bit and are now building 32-bit, throw away the install directory
1887ec681f3Smrg    first to prevent conflicts.
1897ec681f3Smrg
1907ec681f3Smrg4. Building with AOSP (Android)
1917ec681f3Smrg-------------------------------
1927ec681f3Smrg
1937ec681f3Smrg<TODO>
1947ec681f3Smrg
1957ec681f3Smrg5. Library Information
1967ec681f3Smrg----------------------
1977ec681f3Smrg
1987ec681f3SmrgWhen compilation has finished, look in the top-level ``lib/`` (or
1997ec681f3Smrg``lib64/``) directory. You'll see a set of library files similar to
2007ec681f3Smrgthis:
2017ec681f3Smrg
2027ec681f3Smrg.. code-block:: console
2037ec681f3Smrg
2047ec681f3Smrg   lrwxrwxrwx    1 brian    users          10 Mar 26 07:53 libGL.so -> libGL.so.1*
2057ec681f3Smrg   lrwxrwxrwx    1 brian    users          19 Mar 26 07:53 libGL.so.1 -> libGL.so.1.5.060100*
2067ec681f3Smrg   -rwxr-xr-x    1 brian    users     3375861 Mar 26 07:53 libGL.so.1.5.060100*
2077ec681f3Smrg   lrwxrwxrwx    1 brian    users          14 Mar 26 07:53 libOSMesa.so -> libOSMesa.so.6*
2087ec681f3Smrg   lrwxrwxrwx    1 brian    users          23 Mar 26 07:53 libOSMesa.so.6 -> libOSMesa.so.6.1.060100*
2097ec681f3Smrg   -rwxr-xr-x    1 brian    users       23871 Mar 26 07:53 libOSMesa.so.6.1.060100*
2107ec681f3Smrg
2117ec681f3Smrg**libGL** is the main OpenGL library (i.e. Mesa), while **libOSMesa** is
2127ec681f3Smrgthe OSMesa (Off-Screen) interface library.
2137ec681f3Smrg
2147ec681f3SmrgIf you built the DRI hardware drivers, you'll also see the DRI drivers:
2157ec681f3Smrg
2167ec681f3Smrg.. code-block:: console
2177ec681f3Smrg
2187ec681f3Smrg   -rwxr-xr-x   1 brian users 16895413 Jul 21 12:11 i915_dri.so
2197ec681f3Smrg   -rwxr-xr-x   1 brian users 16895413 Jul 21 12:11 i965_dri.so
2207ec681f3Smrg   -rwxr-xr-x   1 brian users 11849858 Jul 21 12:12 r200_dri.so
2217ec681f3Smrg   -rwxr-xr-x   1 brian users 11757388 Jul 21 12:12 radeon_dri.so
2227ec681f3Smrg
2237ec681f3SmrgIf you built with Gallium support, look in lib/gallium/ for
2247ec681f3SmrgGallium-based versions of libGL and device drivers.
2257ec681f3Smrg
2267ec681f3Smrg6. Building OpenGL programs with pkg-config
2277ec681f3Smrg-------------------------------------------
2287ec681f3Smrg
2297ec681f3SmrgRunning ``ninja install`` will install package configuration files for
2307ec681f3Smrgthe pkg-config utility.
2317ec681f3Smrg
2327ec681f3SmrgWhen compiling your OpenGL application you can use pkg-config to
2337ec681f3Smrgdetermine the proper compiler and linker flags.
2347ec681f3Smrg
2357ec681f3SmrgFor example, compiling and linking a GLUT application can be done with:
2367ec681f3Smrg
2377ec681f3Smrg.. code-block:: console
2387ec681f3Smrg
2397ec681f3Smrg      gcc `pkg-config --cflags --libs glut` mydemo.c -o mydemo
240