{"id":432,"date":"2014-09-15T16:44:12","date_gmt":"2014-09-15T14:44:12","guid":{"rendered":"http:\/\/blogs.igalia.com\/itoral\/?p=432"},"modified":"2014-09-15T16:44:12","modified_gmt":"2014-09-15T14:44:12","slug":"setting-up-a-development-environment-for-mesa","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/itoral\/2014\/09\/15\/setting-up-a-development-environment-for-mesa\/","title":{"rendered":"Setting up a development environment for Mesa"},"content":{"rendered":"<p><strong>Recap<\/strong><\/p>\n<p><a href=\"http:\/\/blogs.igalia.com\/itoral\/2014\/09\/08\/an-eagle-eye-view-into-the-mesa-source-tree\/\" title=\"An eagle eye view into the Mesa source tree\" target=\"_blank\">In my previous post<\/a> I provided an overview of the Mesa source tree and identified some of its main modules.<\/p>\n<p>Since we are on that subject I thought it would make sense to give a few tips on how to setup the development environment for Mesa too, so here I go.<\/p>\n<p><strong>Development environment<\/strong><\/p>\n<p>Mesa is mostly written in a combination of <em>C<\/em> and <em>C++<\/em>, uses <em>autotools<\/em> for its build system and <em>Git<\/em> for version control, so it should be a fairly familiar environment for many people. I am not going to explain how to build <em>autotools<\/em> projects here, there is plenty of documentation available on that subject, so instead I will focus on the specifics of Mesa.<\/p>\n<p>First we need to checkout the source code. If you do not have a developer account then do an anonymous checkout:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# git clone git:\/\/anongit.freedesktop.org\/git\/mesa\/mesa\r\n<\/pre>\n<p>If you do have a developer account do this instead:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# git clone git+ssh:\/\/username@git.freedesktop.org\/git\/mesa\/mesa\r\n<\/pre>\n<p>Next, we will have to deal with dependencies. This should not be too hard though. Mesa is fairly low in the software stack so it does not have many and the ones it has seem to have a fairly stable API and don&#8217;t change too often, so typically, you should be able to build Mesa if you have a recent distribution and you keep it up to date. For reference, as of now I can build Mesa on my Ubuntu 14.04 without any problems.<\/p>\n<p>In any case, the actual dependencies you will need to get may vary depending on the drivers you want to build, the target platform and the features you want to enable. For example, the <em>R300 Gallium<\/em> driver requires <em>LLVM<\/em>, but the <em>Intel i965<\/em> driver doesn&#8217;t.<\/p>\n<p>Notice, however, that if you are hacking on features that require specific builds of the <em>XServer<\/em>, <em>Wayland\/Weston<\/em> or similar stuff the required setup will be more  complex, since you would probably need to include these other projects into the mix, together with their respective dependencies.<\/p>\n<p><strong>Configuring the source tree<\/strong><\/p>\n<p>Here I will mention some of the Mesa specific options that I found to be more useful in my time with Mesa:<\/p>\n<p><em>&#8211;enable-debug<\/em>: This is necessary, at least, to get assertions to work, and you want this while you are developing. Mesa and the drivers have assertions on many places to make sure that new code does not break certain assumptions or violate hardware constraints, so you really want to make sure that you have these activated when you are developing. It also adds <em>&#8220;-g -O0&#8221;<\/em> to enable debug support.<\/p>\n<p><em>&#8211;with-dri-driver<\/em>s: This is the list of classic Mesa DRI drivers you want to build. If you know you will only hack on the <em>i965<\/em> driver, for example, then building other drivers will only slow down your builds.<\/p>\n<p>&#8211;with-gallium-drivers: This is the list of Gallium drivers you want to build. Again, if you are hacking on the classic DRI <em>i965<\/em> driver you are probably not interested in building any Gallium drivers.<\/p>\n<p>Notice that if you are working on the Mesa framework layer, that is, the bits shared by all drivers, instead of the internals of a specific driver, you will probably want to include more drivers in the build to make sure that they keep building after your changes.<\/p>\n<p><em>&#8211;with-egl-platforms<\/em>: This is a list of supported platforms. Same as with the options above, you probably only want to build Mesa for the platform or platforms you are working on.<\/p>\n<p>Besides using a combination of these options, you probably also want to set your CFLAGS and CXXFLAGS (remember that Mesa uses both <em>C<\/em> and <em>C++<\/em>). I for one like to pass <em>&#8220;-g3&#8221;<\/em>, for example.<\/p>\n<p><strong>Using your built version of Mesa<\/strong><\/p>\n<p>Once you have built Mesa you can type &#8216;make install&#8217; to install the libraries and drivers. Probably, you have configured autotools (via the &#8211;<em>-prefix<\/em> option) to do this to a safe location that does not conflict with your distribution installation of Mesa and now your problem is to tell your OpenGL programs that they should use this version of Mesa instead of the one provided by your distro.<\/p>\n<p>You will have to adjust a couple of environment variables for this:<\/p>\n<p><em>LIBGL_DRIVERS_PATH<\/em>: Set this to the path where your built drivers have been installed. This will tell Mesa&#8217;s loader to look for the drivers here.<\/p>\n<p><em>LD_LIBRARY_PATH<\/em>: Set this to the path where your Mesa libraries have been installed. This will make it so that OpenGL programs load your recently  built libGL.so rather than your system&#8217;s.<\/p>\n<p>For more tips I&#8217;d suggest to read this <a href=\"http:\/\/lists.freedesktop.org\/archives\/mesa-dev\/2014-April\/057676.html\" title=\"Mesa development environment\" target=\"_blank\">short thread<\/a> in the Mesa mailing list, which has some Mesa developers discussing their development environment setup.<\/p>\n<p><strong>Coming up next<\/strong><\/p>\n<p>In the next post I will provide an introduction to modern 3D graphics hardware. After all, the job of the graphics driver is all about programming the hardware, so having a basic understanding of how it works is a requirement if want to do any meaningful driver development.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recap In my previous post I provided an overview of the Mesa source tree and identified some of its main modules. Since we are on that subject I thought it would make sense to give a few tips on how to setup the development environment for Mesa too, so here I go. Development environment Mesa &hellip; <a href=\"https:\/\/blogs.igalia.com\/itoral\/2014\/09\/15\/setting-up-a-development-environment-for-mesa\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting up a development environment for Mesa&#8221;<\/span><\/a><\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-432","post","type-post","status-publish","format-standard","hentry","category-graphics"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/posts\/432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/comments?post=432"}],"version-history":[{"count":3,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/posts\/432\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/posts\/432\/revisions\/435"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/media?parent=432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/categories?post=432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/itoral\/wp-json\/wp\/v2\/tags?post=432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}