{"id":188,"date":"2008-08-06T15:13:41","date_gmt":"2008-08-06T23:13:41","guid":{"rendered":"http:\/\/wp.colliertech.org\/cj\/?p=188"},"modified":"2008-08-07T11:09:34","modified_gmt":"2008-08-07T19:09:34","slug":"writing-free-software-part-4-configureac","status":"publish","type":"post","link":"https:\/\/wp.c9h.org\/cj\/?p=188","title":{"rendered":"Writing Free Software &#8211; Part 4: configure.ac"},"content":{"rendered":"<p>In this section, we&#8217;ll create a minimalist configure.ac, re-name our Makefile to Makefile.am, generate a configure script, and use this configure script to produce a Makefile.  The end result won&#8217;t do much more than our manually-created Makefile.  It will, however, allow us to make use of the autoconf and automake infrastructure in future lessons.  So let&#8217;s get started.<\/p>\n<h3>Return to our workplace<\/h3>\n<p><code><b>$<\/b> cd ~\/src\/greeting<\/code><\/p>\n<h3>Create a configure.ac file<\/h3>\n<pre style=\"color: grey; margin: 0px; padding: 0px;\"><b>$<\/b> cat &gt; configure.ac\r\nAC_INIT([greeting],[0.0.1])\r\nAM_INIT_AUTOMAKE([1.9 tar-ustar])\r\nAC_PATH_PROG(CSC, gmcs, no)\r\nif test \"x$CSC\" = \"x\" ; then\r\n  AC_MSG_ERROR([Can't find \"gmcs\" in your PATH])\r\nfi\r\nAC_CONFIG_FILES([\r\nMakefile\r\n])\r\nAC_OUTPUT\r\n^D<\/pre>\n<h3>Re-name your Makefile<\/h3>\n<p><code><b>$<\/b> mv Makefile Makefile.am<\/code><\/p>\n<h3>Install autoconf &amp; automake<\/h3>\n<p><code><b>$<\/b> sudo apt-get install autoconf automake<\/code><\/p>\n<h3>Create files required by automake<\/h3>\n<p><code><b>$<\/b> for i in NEWS README AUTHORS ChangeLog ; do touch $i ; done<\/code><\/p>\n<h3>Import required m4 macros<\/h3>\n<p><code><b>$<\/b> aclocal<\/code><\/p>\n<h3>Ask automake to install missing pieces<\/h3>\n<p><code><b>$<\/b> automake -a<\/code><\/p>\n<h3>Process configure.ac and Makefile.am<\/h3>\n<p><code><b>$<\/b> autoreconf<\/code><\/p>\n<h3>Create a Makefile using configure script<\/h3>\n<p><code><b>$<\/b> .\/configure<\/code><\/p>\n<h3>Test the targets we created before<\/h3>\n<pre style=\"color: grey; margin: 0px; padding: 0px;\"><b>$<\/b> make\r\ngmcs -out:Greeting.exe Greeting.cs NDesk.Options.cs\r\n<b>$<\/b> make clean\r\nrm Greeting.exe\r\n<b>$<\/b> make Greeting.exe\r\ngmcs -out:Greeting.exe Greeting.cs NDesk.Options.cs<\/pre>\n<h3>Verify that our code still runs<\/h3>\n<pre style=\"color: grey; margin: 0px; padding: 0px;\"><b>$<\/b> .\/Greeting.exe -n 1\r\nGreetings, Mercury!\r\n<b>$<\/b> .\/Greeting.exe -1\r\nGreetings, World!\r\n<b>$<\/b> .\/Greeting.exe &ndash;&ndash;number 3\r\nGreetings, Earth!<\/pre>\n<h3>Try some of the targets that automake generates<\/h3>\n<pre style=\"color: grey; margin: 0px; padding: 0px;\"><b>$<\/b> touch Makefile.in && make Makefile\r\n cd . && \/bin\/sh .\/config.status Makefile \r\nconfig.status: creating Makefile\r\nmake: `Makefile' is up to date.\r\n<b>$<\/b> make distdir\r\n...\r\n<b>$<\/b> ls greeting-0.0.1\r\nAUTHORS  ChangeLog  Makefile.am  NEWS    aclocal.m4  configure.ac  missing\r\nCOPYING  INSTALL    Makefile.in  README  configure   install-sh\r\n<b>$<\/b> make dist\r\n...\r\n<b>$<\/b> ls greeting-0.0.1.tar.gz \r\ngreeting-0.0.1.tar.gz\r\n<\/pre>\n<h3>Conclusion<\/h3>\n<p>We have now created a simple autotools framework to do what we were doing manually.  I&#8217;ll be honest: this is still pretty manual.  In future lessons we&#8217;ll make some tweaks to it which make use of the extensive features of the system.<\/p>\n\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=cjamescollier\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this section, we&#8217;ll create a minimalist configure.ac, re-name our Makefile to Makefile.am, generate a configure script, and use this configure script to produce a Makefile. The end result won&#8217;t do much more than our manually-created Makefile. It will, however, allow us to make use of the autoconf and automake infrastructure in future lessons. So [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","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":""},"categories":[180,38,188,17,79,7,166],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-autotools","category-c","category-cli","category-debian","category-free-software","category-mono","category-software"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1YDIB-32","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=188"}],"version-history":[{"count":0,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}