{"id":40,"date":"2008-04-26T22:16:00","date_gmt":"2008-04-27T06:16:00","guid":{"rendered":"http:\/\/eschatologist.net\/blog\/?p=40"},"modified":"2009-01-25T20:22:10","modified_gmt":"2009-01-26T04:22:10","slug":"build-llvm-and-clang","status":"publish","type":"post","link":"https:\/\/eschatologist.net\/blog\/?p=40","title":{"rendered":"Build LLVM and clang!"},"content":{"rendered":"<p>I&#8217;ve talked about the <a href=\"http:\/\/chanson.livejournal.com\/172642.html\">LLVM Compiler Infrastructure<\/a> in the past, but what I haven&#8217;t talked about yet is just how <em>easy<\/em> and <em>quickly<\/em> you can build it on your own Mac running Leopard!  This is a great way to get into hacking on compiler lexical analyzers and parsers, code generators, optimizers, and so on.<\/p>\n<p>What&#8217;s more, you can build both <a href=\"http:\/\/llvm.org\/\">LLVM<\/a> and the new C front-end <code><a href=\"http:\/\/clang.llvm.org\/\">clang<\/a><\/code> very easily and in <strong>five to ten minutes<\/strong>.<\/p>\n<p>First, create a work area to check them out into, wherever you normally create your projects.  <code><\/p>\n<pre>[~]% cd \/Projects\n[\/Projects]% mkdir LLVM\n[\/Projects]% cd LLVM\n[\/Projects\/LLVM]%<\/pre>\n<p><\/code>  Then check out LLVM itself and <code>clang<\/code> from the <a href=\"http:\/\/llvm.org\/docs\/GettingStarted.html#checkout\">LLVM Subversion repository<\/a>.  <code><\/p>\n<pre>[\/Projects\/LLVM]% svn checkout http:\/\/llvm.org\/svn\/llvm-project\/llvm\/trunk llvm\n[\/Projects\/LLVM]% cd llvm\/tools\n[\/Projects\/LLVM\/llvm\/tools]% svn checkout http:\/\/llvm.org\/svn\/llvm-project\/cfe\/trunk clang\n[\/Projects\/LLVM\/llvm\/tools]% cd ..\/..\n[\/Projects\/LLVM]%<\/pre>\n<p><\/code>  Then edit the <code>PARALLEL_DIRS<\/code> definition in <code>llvm\/tools\/Makefile<\/code> to tell it about <code>clang<\/code>.  Just add <code>clang<\/code> onto the end, like this:  <code><\/p>\n<pre>PARALLEL_DIRS := llvm-config  \\\n                 opt llvm-as llvm-dis \\\n                 llc llvm-ranlib llvm-ar llvm-nm \\\n                 llvm-ld llvm-prof llvm-link \\\n                 lli gccas gccld llvm-extract llvm-db \\\n                 bugpoint llvm-bcanalyzer llvm-stub llvmc2 \\\n                 clang<\/pre>\n<p><\/code>  Now create a directory to build into, next to your <code>llvm<\/code> directory, and change into it.  <code><\/p>\n<pre>[\/Projects\/LLVM]% mkdir build\n[\/Projects\/LLVM]% cd build\n[\/Projects\/LLVM\/build]%<\/pre>\n<p><\/code>  This is where you&#8217;ll actually run <code>configure<\/code>.  This will ensure your source tree isn&#8217;t polluted with build products, and that everything stays self-contained while you hack.  <code><\/p>\n<pre>[\/Projects\/LLVM\/build]% ..\/llvm\/configure --enable-targets=host-only\n# lots of logging\n[\/Projects\/LLVM\/build]%<\/pre>\n<p><\/code>  You&#8217;ll note that above I passed an argument to <code>configure<\/code>.  This ensures that LLVM is only built to target the architecture I&#8217;m running on, to speed up the build process; this is generally fine for simple front-end development.<\/p>\n<p>Now, to build LLVM as well as <code>clang<\/code> all I have to do is invoke <code>make<\/code>.  LLVM is set up to correctly do parallel builds, so I&#8217;ll pass the number of CPUs I have in my machine via <code>make -j 4<\/code>.  <code><\/p>\n<pre>[\/Projects\/LLVM\/build]% make -j 4\n# lots of logging\n[\/Projects\/LLVM\/build]%<\/pre>\n<p><\/code>  That&#8217;s it!  LLVM is now (hopefully) successfully built.  All of the pieces are in the <code>build<\/code> directory under <code>Debug\/bin<\/code> and <code>Debug\/lib<\/code> and so on; see the LLVM web site for details about what the various components are.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve talked about the LLVM Compiler Infrastructure in the past, but what I haven&#8217;t talked about yet is just how easy and quickly you can build it on your own Mac running Leopard! This is a great way to get into hacking on compiler lexical analyzers and parsers, code generators, optimizers, and so on. What&#8217;s&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[23,35,34,4,18,22],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-technology","tag-c","tag-compilers","tag-llvm","tag-mac","tag-objective-c","tag-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p74loH-E","_links":{"self":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":3,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/43"}],"wp:attachment":[{"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eschatologist.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}