<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Autotools on Roberto Selbach</title><link>https://rselbach.com/tags/autotools/</link><description>Recent content in Autotools on Roberto Selbach</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 05 Sep 2002 10:03:57 +0000</lastBuildDate><atom:link href="https://rselbach.com/tags/autotools/index.xml" rel="self" type="application/rss+xml"/><item><title>Adding a Source File to KDE Autotools</title><link>https://rselbach.com/adding-a-source-file-to-kde-autotools/</link><pubDate>Thu, 05 Sep 2002 10:03:57 +0000</pubDate><guid>https://rselbach.com/adding-a-source-file-to-kde-autotools/</guid><description>&lt;p&gt;I added &lt;code&gt;history.cpp&lt;/code&gt; to an application, ran &lt;code&gt;make&lt;/code&gt;, and spent several minutes wondering why none of my mistakes appeared in the compiler output. The build was not unusually forgiving. I had neglected to tell it that the file existed.&lt;/p&gt;
&lt;p&gt;In a typical KDE source tree, the immediate place to look is &lt;code&gt;Makefile.am&lt;/code&gt;. The target&amp;rsquo;s source list must contain both implementation and relevant headers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-make" data-lang="make"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;bin_PROGRAMS &lt;span style="color:#f92672"&gt;=&lt;/span&gt; notebook
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;notebook_SOURCES &lt;span style="color:#f92672"&gt;=&lt;/span&gt; main.cpp notebook.cpp history.cpp &lt;span style="color:#ae81ff"&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; notebook.h history.h
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;notebook_LDADD &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;LIB_KDEUI&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Automake uses this description to generate the lower-level make rules. KDE&amp;rsquo;s &lt;code&gt;admin&lt;/code&gt; machinery and configure input then arrange compiler flags, library checks, translations, installation paths, and &lt;code&gt;moc&lt;/code&gt; handling. Editing the generated &lt;code&gt;Makefile&lt;/code&gt; is temporary theatre; the next regeneration removes the change with admirable confidence.&lt;/p&gt;
&lt;p&gt;After changing the build description, I regenerate from the source root:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;make -f Makefile.cvs
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;./configure --prefix&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;$KDEDIR&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; --enable-debug
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;make
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For an out-of-tree build I run &lt;code&gt;configure&lt;/code&gt; from the build directory after regenerating the source-side files. If I have added a new subdirectory, it also needs to appear in the parent&amp;rsquo;s &lt;code&gt;SUBDIRS&lt;/code&gt;, and its makefile must be included by the configure machinery. A source file alone is simpler and normally needs only the target list.&lt;/p&gt;
&lt;p&gt;Headers with &lt;code&gt;Q_OBJECT&lt;/code&gt; are worth checking after the first build. If &lt;code&gt;moc&lt;/code&gt; output is absent, I confirm the header is listed and that the macro is visible in the class declaration. Stale dependencies can confuse matters, so I prefer a fresh build directory before rewriting build rules that may already be correct.&lt;/p&gt;
&lt;p&gt;Installation lists are a separate concern from compilation lists. A desktop file belongs in the appropriate data variable with its destination, translations belong in their directory, and public headers need an installation rule only if they truly form an interface. Putting every file into &lt;code&gt;EXTRA_DIST&lt;/code&gt; may make an archive complete, but it does not make installation correct.&lt;/p&gt;
&lt;p&gt;I check both operations before sending a change:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;make dist
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;make install DESTDIR&lt;span style="color:#f92672"&gt;=&lt;/span&gt;/tmp/notebook-install
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The staged installation makes missing icons and resources visible without scattering test files through the real prefix. I inspect the archive too, because a local build can use a file that never entered the distribution. Generated files and source files have different rules, and guessing which will be recreated on another machine is avoidable.&lt;/p&gt;
&lt;p&gt;I keep custom shell commands out of &lt;code&gt;Makefile.am&lt;/code&gt; unless the normal primary and source variables cannot express the job. Automake syntax can feel indirect, but the standard forms understand clean builds, distribution archives, and dependency tracking. A handcrafted shortcut often understands only the exact machine on which it was written, which is a rather narrow audience.&lt;/p&gt;</description></item></channel></rss>