{"id":208,"date":"2008-08-11T13:05:30","date_gmt":"2008-08-11T21:05:30","guid":{"rendered":"http:\/\/wp.colliertech.org\/cj\/?p=208"},"modified":"2008-08-11T13:05:30","modified_gmt":"2008-08-11T21:05:30","slug":"writing-free-software-part-10-subdirectories","status":"publish","type":"post","link":"https:\/\/wp.c9h.org\/cj\/?p=208","title":{"rendered":"Writing Free Software &#8211; Part 10: Subdirectories"},"content":{"rendered":"<p>In this installment, I&#8217;ll cover creating different subdirectories for different parts of the code.  We&#8217;ll move NDesk.Options.cs into an <b>ndesk<\/b> directory and Greeting.cs into a <b>src<\/b> directory.  Some modifications need to be made to various pieces of the distribution in order for this to work out correctly.  We&#8217;ll do the minimum required now and cover the pieces that will make it more extensible but complex in future entries.<\/p>\n<h3>Return to the workplace<\/h3>\n<p><code><b>$<\/b> cd ~\/src\/greeting<\/code><\/p>\n<h3>Move the source to their new directories<\/h3>\n<p><code><b>$<\/b> mkdir src ndesk<br \/>\n<b>$<\/b> mv NDesk.Options.cs ndesk<br \/>\n<b>$<\/b> mv Greeting.cs src<br \/>\n<b>$<\/b> mv Makefile.am src<br \/>\n<\/code><\/p>\n<h3>Create a new root Makefile.am file<\/h3>\n<p><code><b>$<\/b> cat &gt; Makefile.am<br \/>\nSUBDIRS = src ndesk<\/p>\n<p>bin_SCRIPTS = greeting<br \/>\n^D<br \/>\n<\/code><\/p>\n<h3>Create ndesk\/Makefile.am<\/h3>\n<p><code><b>$<\/b> cat &gt; ndesk\/Makefile.am<br \/>\nEXTRA_DIST = NDesk.Options.cs<br \/>\n<\/code><\/p>\n<h3>Alter src\/Makefile.am to cope with new layout<\/h3>\n<p><code><b>$<\/b> patch src\/Makefile.am<\/p>\n<pre>10,11c10,11\r\n&lt; Greeting.exe: Greeting.cs NDesk.Options.cs\r\n&lt; # the same as $(CSC) -out:Greeting.exe Greeting.cs\r\n---\r\n&gt; Greeting.exe: Greeting.cs $(top_srcdir)\/ndesk\/NDesk.Options.cs\r\n&gt; # the same as $(CSC) -out:Greeting.exe Greeting.cs ...\r\n14,15c14\r\n&lt; EXTRA_DIST = Greeting.cs NDesk.Options.cs\r\n&lt;\r\n---\r\n&gt; EXTRA_DIST = Greeting.cs\r\n18,19d16\r\n&lt;\r\n&lt; bin_SCRIPTS = greeting\r\n^D^D\r\npatching file src\/Makefile.am<\/pre>\n<p><\/code><\/p>\n<h3>Alter configure.ac to cope with new layout<\/h3>\n<p><code><b>$<\/b> patch configure.ac<\/p>\n<pre>@@ -13,6 +13,8 @@\r\n&nbsp;\r\n AC_CONFIG_FILES([\r\n Makefile\r\n+ndesk\/Makefile\r\n+src\/Makefile\r\n greeting\r\n ])\r\n AC_OUTPUT\r\nmissing header for unified diff at line 1 of patch\r\npatching file configure.ac\r\n<\/pre>\n<p><\/code><\/p>\n<h3>Prove that we didn&#8217;t break anything<\/h3>\n<p><code><b>$<\/b>$ automake && autoconf && .\/configure<br \/>\n...<br \/>\n<b>$<\/b> make<br \/>\n...<br \/>\n<b>$<\/b> sudo make install<br \/>\n...<br \/>\n<b>$<\/b> greeting<br \/>\nGreetings, World!<br \/>\n<\/code><\/p>\n<h3>Conclusion<\/h3>\n<p>In this lesson, I gave an example of re-factoring the build system to use subdirectories.  This method can be used to separate portions of one&#8217;s codebase.  In addition, we saw the use of the $srcdir variable, which stores the location of the root of the source distribution.<\/p>\n<p>In future posts, we will use the work done in this lesson as a basis for some more re-factoring.  We will also learn how to do things such as<\/p>\n<ul>\n<li>creating sub projects<\/li>\n<li>inter-package dependencies using pkg-config<\/li>\n<\/ul>\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 installment, I&#8217;ll cover creating different subdirectories for different parts of the code. We&#8217;ll move NDesk.Options.cs into an ndesk directory and Greeting.cs into a src directory. Some modifications need to be made to various pieces of the distribution in order for this to work out correctly. We&#8217;ll do the minimum required now and cover [&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-208","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-3m","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts\/208","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=208"}],"version-history":[{"count":3,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions"}],"predecessor-version":[{"id":211,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=\/wp\/v2\/posts\/208\/revisions\/211"}],"wp:attachment":[{"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.c9h.org\/cj\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}