<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ClearChain &#187; Programming</title>
	<atom:link href="http://www.clearchain.com/blog/categories/computers/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.clearchain.com/blog</link>
	<description>-= Daily Happenings =-</description>
	<lastBuildDate>Wed, 05 Oct 2011 23:02:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>libdc1394_video_set_mode doesn&#8217;t change the mode &#8211; A solution!</title>
		<link>http://www.clearchain.com/blog/posts/libdc1394_video_set_mode-doesnt-change-the-mode-a-solution</link>
		<comments>http://www.clearchain.com/blog/posts/libdc1394_video_set_mode-doesnt-change-the-mode-a-solution#comments</comments>
		<pubDate>Fri, 06 May 2011 03:29:06 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[1394]]></category>
		<category><![CDATA[broken]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[different resolution]]></category>
		<category><![CDATA[firewire]]></category>
		<category><![CDATA[ieee1394]]></category>
		<category><![CDATA[libdc1394]]></category>
		<category><![CDATA[libdc1394_video_set_mode]]></category>
		<category><![CDATA[mode not set]]></category>
		<category><![CDATA[video mode problem]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=991</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/libdc1394_video_set_mode-doesnt-change-the-mode-a-solution"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>This article details a reason libdc1394_video_set_mode/libdc1394_video_set_framerate  may not work. Whilst working on an application that makes use of a 1394a/firewire camera I found a strange bug/feature with libdc1394. The problem was dc1394 was being used to the mode of the camera to 800&#215;600 resolution. However, when querying the frame size after dequeuing the frame, the<a href="http://www.clearchain.com/blog/posts/libdc1394_video_set_mode-doesnt-change-the-mode-a-solution"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p><em>This article details a reason libdc1394_video_set_mode/libdc1394_video_set_framerate  may not work.</em></p>
<p>Whilst working on an application that makes use of a 1394a/firewire  camera I found a strange bug/feature with <a href="http://damien.douxchamps.net/ieee1394/libdc1394/">libdc1394</a>. The problem was  dc1394 was being used to the mode of the camera to 800&#215;600 resolution.  However, when querying the frame size after dequeuing the frame, the  size was only 640&#215;480. Ie: See the below snippits:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">..
<span style="color: #202020;">dc1394error_t</span> result <span style="color: #339933;">=</span> dc1394_video_set_mode<span style="color: #009900;">&#40;</span> this<span style="color: #339933;">-&gt;</span>camera<span style="color: #339933;">,</span> DC1394_VIDEO_MODE_800x600_RGB8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> result <span style="color: #339933;">!=</span> DC1394_SUCCESS <span style="color: #009900;">&#41;</span>
exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
....
<span style="color: #202020;">dc1394video_frame_t</span> <span style="color: #339933;">*</span>frame<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
dc1394error_t result<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// capture one frame</span>
result <span style="color: #339933;">=</span> dc1394_capture_dequeue<span style="color: #009900;">&#40;</span> this<span style="color: #339933;">-&gt;</span>camera<span style="color: #339933;">,</span> DC1394_CAPTURE_POLICY_WAIT<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>frame <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> result <span style="color: #339933;">!=</span> DC1394_SUCCESS <span style="color: #009900;">&#41;</span>
exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Allocate image memory if required</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> this<span style="color: #339933;">-&gt;</span>lastFrame.<span style="color: #202020;">image</span> <span style="color: #339933;">==</span> NULL <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
memcpy<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">-&gt;</span>lastFrame<span style="color: #339933;">,</span>frame<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>dc1394video_frame_t<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
this<span style="color: #339933;">-&gt;</span>lastFrame.<span style="color: #202020;">image</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">uint8_t</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>frame<span style="color: #339933;">-&gt;</span>total_bytes <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint8_t</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
..</pre></div></div>

<p>At this point total_bytes was 921600 which works out to be 640x480x3 (RGB);</p>
<p>I was stumped. I asked for one mode and got another back. All with no errors what so ever from libdc1394.</p>
<p>After over an hour of debugging, google searching and more,  I eventually found the reason.  The comment that ended up in the code explains the cause:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Shutdown any isotransports that are setup for the camera.</span>
<span style="color: #666666; font-style: italic;">// It turns out that libDC1394 will quite happily let you set modes,</span>
<span style="color: #666666; font-style: italic;">// framerates, etc but if there is an iso stream running none of them</span>
<span style="color: #666666; font-style: italic;">// will actually take affect. Hence you can set a 800x600 res and get</span>
<span style="color: #666666; font-style: italic;">// back 640x480 video frame - really nice libdc1394. It could at least</span>
<span style="color: #666666; font-style: italic;">// indicate there was a active stream when setting the mode!</span>
<span style="color: #666666; font-style: italic;">// Anyway to deal with this we force the camera to stop capturing</span>
<span style="color: #666666; font-style: italic;">// before we change the settings, if the camera was capturing prior to</span>
<span style="color: #666666; font-style: italic;">// setConfiguration being called, we restart the capture</span></pre></div></div>

<p>So the solution is to make sure the iso transmission stream has been shutdown. this can be achieved using:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">dc1394_video_set_transmission<span style="color: #009900;">&#40;</span> this<span style="color: #339933;">-&gt;</span>camera<span style="color: #339933;">,</span> DC1394_OFF <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
dc1394_capture_stop<span style="color: #009900;">&#40;</span> this<span style="color: #339933;">-&gt;</span>camera <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>An easy fix but certainly an annoying setup. I&#8217;ve not tested it but I&#8217;m guessing many of the other functions:</p>
<ul>
<li>dc1394_video_set_framerate</li>
<li>dc1394_video_set_iso_speed</li>
<li>dc1394_feature_set_mode</li>
<li>dc1394_video_set_one_shot</li>
</ul>
<p>are also affected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/libdc1394_video_set_mode-doesnt-change-the-mode-a-solution/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenGL glTexSubImage2D very slow &#8211; a solution!</title>
		<link>http://www.clearchain.com/blog/posts/opengl-gltexsubimage2d-very-slow-a-solution</link>
		<comments>http://www.clearchain.com/blog/posts/opengl-gltexsubimage2d-very-slow-a-solution#comments</comments>
		<pubDate>Fri, 06 May 2011 03:04:21 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[glTexSubImage2D]]></category>
		<category><![CDATA[mipmap]]></category>
		<category><![CDATA[mipmapping]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[performance issue]]></category>
		<category><![CDATA[shader]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[texture]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=988</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/opengl-gltexsubimage2d-very-slow-a-solution"><img align="left" hspace="5" width="150" src="http://www.clearchain.com/blog/images//2011/05/opengl2-300x135.png" class="alignleft wp-post-image tfe" alt="" title="opengl2" /></a>This article describes a possible reason glTexSubImage2D may be slow. Recently I was working on a piece of code that updated a texture with a camera frame. The application was using the fixed function (non shaders) pipeline of OpenGL. Whilst I didn&#8217;t notice it at first, I soon found that the camera image was very<a href="http://www.clearchain.com/blog/posts/opengl-gltexsubimage2d-very-slow-a-solution"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.clearchain.com/blog/images//2011/05/opengl2.png"><img class="alignleft size-medium wp-image-989" title="opengl2" src="http://www.clearchain.com/blog/images//2011/05/opengl2-300x135.png" alt="" width="300" height="135" /></a><em>This article describes a possible reason glTexSubImage2D may be slow.</em></p>
<p>Recently I was working on a piece of code that updated a texture with a camera frame. The application was using the fixed function (non shaders) pipeline of OpenGL. Whilst I didn&#8217;t notice it at first, I soon found that the camera image was very delayed. For example the camera was capturing at 30 frames per second, but the screen update rate was only 6 frames per second.</p>
<p>After commenting out vast amounts of code, disabling functions the reason behind the slow frame rates was traced to the OpenGL call: glTexSubImage2D. The exact call that was being made was:</p>
<pre>glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,  mWidth, mHeight,  GL_RGB, GL_UNSIGNED_BYTE, image-&gt;getData());</pre>
<p>Everything to this call looked normal. I tried a simple test program that used glTextSubImage2D and surprizingly it ran fast! So at this point I was a little confused. How could two very similar programs produce different results.<br />
I kept searching. I tried Google searches found various comments but none of them seemed to work.</p>
<p>Eventually I looked at the Texture class I had been using and began commenting lines out of that. It was only when I found and commented out the line:</p>
<pre>glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );</pre>
<p>Things improved. This makes perfect sense as well. Generating a mipmap each frame is expensive. A quick fix and the application was running smoothly!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/opengl-gltexsubimage2d-very-slow-a-solution/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Xinput 1 -&gt; XInput 2 conversion guide</title>
		<link>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide</link>
		<comments>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide#comments</comments>
		<pubDate>Thu, 30 Jul 2009 01:30:14 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[FreeDesktop]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[gtk+]]></category>
		<category><![CDATA[MPX]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[XI1]]></category>
		<category><![CDATA[XI2]]></category>
		<category><![CDATA[XInput 1.5]]></category>
		<category><![CDATA[XInput1]]></category>
		<category><![CDATA[Xinput2]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=415</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Details about the API changes between Xinput 1(XI1) and XInput 2 (XI2)]]></description>
			<content:encoded><![CDATA[<p>Recently I was tasked with porting <a href="http://www.gtk.org/">GTK+</a> to support Xinput 2 (XI2), and whilst the port isn&#8217;t finished I quickly discovered just how big the conversion was. This page is designed to help someone who is familiar with XInput 1 switch to XInput 2 &#8211; it&#8217;s certainly is by no means a complete guide and anyone reading this should also take a look at the various <a href="http://who-t.blogspot.com/">Input2 recipies published.</a></p>
<p>XI2 is the first major rewrite of the <a href="http://www.x.org/wiki/XInputSpec">XInput specification</a> in years and with it comes a lot of enhanced functionality, but also a <a href="http://cgit.freedesktop.org/xorg/lib/libXi/tree/man">new API</a>. The API was deliberately designed not to be backward compatible. Why? To prevent both XI1 and XI2 features to be intermingled. XI2 brings with it a new device model and a new input model. Both of these are incompatible with XI1. The decision to break the API was not a light one by <a href="http://who-t.blogspot.com/">Peter Hutterer</a>, the main XI2 developer.  Supporting XI1 would have ment future changes to XI2 would be impossible &#8211; there&#8217;s only so far you can push an out dated protocol and api. The added complexity of trying to maintain 2 code paths was also determined to be too high. XI2 is more than just a api/abi change. It literally change the entire input subsystem of the <a href="http://www.x.org">Xorg</a> Xserver. XI2 supports:</p>
<ul>
<li>Mulitple Independent Master Devices  (MPX)</li>
<li>Subpixel Accuracy for input devices</li>
<li>Support for 32bit key codes</li>
<li>.. lots more See: <a href="http://fedoraproject.org/wiki/Features/XI2">http://fedoraproject.org/wiki/Features/XI2</a> for full details</li>
</ul>
<p>With that in mind, the new XI2 API often leaves someone who&#8217;s been working with the XI1 wondering what the equivilant XI2 API call is.  Most functions have an equivilant in XI2 function though the usage has more often than not, changed dramatically. Below is some examples of how to convert XI1 code to XI2 compatible code and a list of <strong>some</strong> of the changes which have occurred. If you find something missing, please add to the comments.</p>
<h2>Change Overview</h2>
<p>The biggest change that any XI1 developer will notice is the <em><strong>XDevice *</strong></em> type has vanished. All XI2 devices make use of the <em><strong>XID</strong></em> type instead. Under the hoods, in the Xserver and XDevice really equates back to an XID anyway now. The next biggest change XI1 developers will notice is the entire XInput2 API has had shifted namespaces. All XInput2 functions, types, etc are now prefixed with XI (ie XIEventMask). This was designed to force segregation of XI1 -&gt; XI2 code.</p>
<p>The header file you include has also changed. Instead of:</p>
<pre>#include &lt;X11/extensions/XInput.h&gt;</pre>
<p>It&#8217;s now:</p>
<pre>#include &lt;X11/extensions/XInput<span style="text-decoration: underline;"><strong>2</strong></span>.h&gt;</pre>
<h2>Notable Changes</h2>
<ul>
<li>Proximity events are no longer supported, these are now reported as regular events on another axis (ie think of a pressure axis)</li>
<li>Events are  longer use device classes, instead all events are type XIEvent (a type of XEvent). Hence there is no need to pass around an array of integer classes anymore when registering for events, instead a single XIEventMask will do what is needed. The macros XISetMask and XIGetMask help with using the mask.</li>
</ul>
<p>There&#8217;s also been a lot of changes to structures, functions, types and how they are used.</p>
<h2>Event Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Event</th>
<th>XI2 Event</th>
<th>Notes</th>
</tr>
<tr>
<td>XDeviceKeyEvent,  XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent,  XDeviceButtonPressedEvent,  XDeviceButtonReleasedEvent ,XDeviceMotionEvent</td>
<td>XIDeviceEvent</td>
<td>The various events are now incorporated into the one event type. XIDeviceEvent-&gt;evtype indicates the subtype of event. Ie XIMotion is a motion event for that device.</td>
</tr>
<tr>
<td>XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent</td>
<td>XIDeviceEvent (See Note)</td>
<td>Proximity Events have been replaced with device events. Proximity is represented as a value in the valuator on one of the axes</td>
</tr>
</tbody>
</table>
<h2>Structure/Type Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Structure/Type</th>
<th>XI2 Structure/Type</th>
<th>Notes</th>
</tr>
<tr>
<td>XDeviceState</td>
<td>XIDeviceInfo</td>
<td>XIDeviceInfo also contains  a name and classes</td>
</tr>
<tr>
<td>XAnyClassPtr</td>
<td>XIAnyClassInfo *</td>
<td></td>
</tr>
<tr>
<td>XValuatorInfo</td>
<td>XIValuatorClassInfo</td>
<td></td>
</tr>
<tr>
<td>XInputClass</td>
<td>XIAnyClassInfo</td>
<td></td>
</tr>
<tr>
<td>XEventClass</td>
<td>XIEventMask</td>
<td>Used for selecting events to be monitored.<br />
One mask is used per device.  Standard usage is:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">XIEventMask mask<span style="color: #339933;">;</span>
mask.<span style="color: #202020;">deviceid</span><span style="color: #339933;">=</span><span style="color: #666666; font-style: italic;">//some device or XIAllDevices for all devices&amp;lt;</span>
mask.<span style="color: #202020;">mask_len</span><span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
mask.<span style="color: #202020;">mask</span><span style="color: #339933;">=</span>calloc<span style="color: #009900;">&#40;</span>mask.<span style="color: #202020;">mask_len</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask.<span style="color: #202020;">mask</span><span style="color: #339933;">,</span> XI_ButtonPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
..
<span style="color: #202020;">XISelectEvents</span><span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> win<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>mask<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span></pre></div></div>

</td>
</tr>
<tr>
<td>XExtensionVersion</td>
<td>Struct Removed</td>
<td>XIQueryVersion should be used instead</td>
</tr>
<tr>
<td>XDeviceKeyEvent, XDeviceKeyPressedEvent, XDeviceKeyReleasedEvent, XDeviceButtonEvent, XDeviceButtonPressedEvent, XDeviceButtonReleasedEvent,</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used instead</td>
</tr>
<tr>
<td>XDeviceFocusChangeEvnet, XDeviceFocusInEvent, XDeviceFocusOutEvent</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used</td>
</tr>
<tr>
<td>XProximityNotifyEvent, XProximityInEvent, XProximityOutEvent</td>
<td>Structs Removed</td>
<td>XIDeviceEvents are now used</td>
</tr>
</tbody>
</table>
<h2>Function/Macro Changes</h2>
<table border="1">
<tbody>
<tr>
<th>XI1 Function</th>
<th>XI2 Function</th>
<th>Notes</th>
</tr>
<tr>
<td>XFreeDeviceList</td>
<td>XIFreeDeviceInfo</td>
<td></td>
</tr>
<tr>
<td>XDefineDeviceCursor</td>
<td>XIDefineCursor</td>
<td></td>
</tr>
<tr>
<td>DeviceButton1Motion</p>
<p>DeviceButton2Motion</p>
<p>&#8230;</td>
<td>(No Equivelant)</td>
<td></td>
</tr>
<tr>
<td>XWarpPointer</p>
<p>XWarpDevicePointer</td>
<td>XIWarpPointer</td>
<td>XIWarpPointer makes use of the device id like XWarpDevicePointer (XI1.5).   XWarpPointer is considered obsolete as it has no concept of a device</td>
</tr>
<tr>
<td>XQueryDeviceState</td>
<td>XIQueryDevice</td>
<td>Return type is XIDeviceInfo *, can be called with deviceid = XIAllDevices to query all devices hence the ndevices return</td>
</tr>
<tr>
<td>XFreeDeviceState</td>
<td>XIFreeDeviceInfo</td>
<td></td>
</tr>
<tr>
<td>DeviceGrabButton</td>
<td>XIGrabButton</td>
<td></td>
</tr>
<tr>
<td>XSelectExtensionEvent</td>
<td>XISelectEvents</td>
<td>Instead of a list of classes now a list of XIEventMask is used, one mask per device. XSelectExtensionEvent is still used for other extension events not related to XInput2</td>
</tr>
<tr>
<td>XGetExtensionVersion</td>
<td>XIQueryVersion</td>
<td>If only XI1 is present this will be returned vi the major/minor numbers (ie major = 1)</td>
</tr>
</tbody>
</table>
<h2>Examples</h2>
<p>Below are some examples of how to use some of the new XI2 functions.</p>
<h3>Event Processing &#8211; Registering For Events</h3>
<p>A simple indication how to register for events (XI2 greatly simplifies this)</p>
<ul>
<li><strong>XInput 1 (Taken from: <a href="http://cgit.freedesktop.org/xorg/app/xinput/tree/src/test.c">http://cgit.freedesktop.org/xorg/app/xinput/tree/src/test.c)</a> </strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           motion_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           button_press_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           button_release_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           key_press_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           key_release_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           proximity_in_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>           proximity_out_type <span style="color: #339933;">=</span> INVALID_EVENT_TYPE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> register_event<span style="color: #009900;">&#40;</span>Display <span style="color: #339933;">*</span>dpy<span style="color: #339933;">,</span> XDeviceInfo <span style="color: #339933;">*</span>info<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    XEventClass         event_list<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span>                 i<span style="color: #339933;">;</span>
    XDevice             <span style="color: #339933;">*</span>device<span style="color: #339933;">;</span>
    XInputClassInfo     <span style="color: #339933;">*</span>ip<span style="color: #339933;">;</span>
&nbsp;
    device <span style="color: #339933;">=</span> XOpenDevice<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> info<span style="color: #339933;">-&gt;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check for open error</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>device<span style="color: #339933;">-&gt;</span>num_classes <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>ip <span style="color: #339933;">=</span> device<span style="color: #339933;">-&gt;</span>classes<span style="color: #339933;">,</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>info<span style="color: #339933;">-&gt;</span>num_classes<span style="color: #339933;">;</span> ip<span style="color: #339933;">++,</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>ip<span style="color: #339933;">-&gt;</span>input_class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">case</span> ButtonClass<span style="color: #339933;">:</span>
                DeviceButtonPress<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> button_press_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                DeviceButtonRelease<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> button_release_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">case</span> ValuatorClass<span style="color: #339933;">:</span>
                DeviceMotionNotify<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> motion_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>handle_proximity<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    ProximityIn<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> proximity_in_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                    ProximityOut<span style="color: #009900;">&#40;</span>device<span style="color: #339933;">,</span> proximity_out_type<span style="color: #339933;">,</span> event_list<span style="color: #009900;">&#91;</span>number<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> number<span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
                fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;unknown class<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>XSelectExtensionEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> root_win<span style="color: #339933;">,</span> event_list<span style="color: #339933;">,</span> number<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;error selecting extended events<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span></pre></div></div>

<ul>
<li><strong>XInput 2:<br />
(Taken from: <a href="http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html">http://who-t.blogspot.com/2009/05/xi2-recipes-part-1.html</a>)<br />
</strong></li>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">XIEventMask eventmask<span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> mask<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* the actual mask */</span>
&nbsp;
eventmask.<span style="color: #202020;">deviceid</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
eventmask.<span style="color: #202020;">mask_len</span> <span style="color: #339933;">=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>mask<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* always in bytes */</span>
eventmask.<span style="color: #202020;">mask</span> <span style="color: #339933;">=</span> mask<span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/* now set the mask */</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_ButtonPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_Motion<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
XISetMask<span style="color: #009900;">&#40;</span>mask<span style="color: #339933;">,</span> XI_KeyPress<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* select on the window */</span>
XISelectEvents<span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> window<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>eventmask<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</ul>
<h3>Event Processing &#8211; Listening/Processing Events</h3>
<p>A simple indication how to get events from XI1 and XI2</p>
<ul>
<li><strong>XInput 1: </strong>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//setup via other means</span>
<span style="color: #993333;">int</span> motion_type<span style="color: #339933;">,</span> button_press_type<span style="color: #339933;">,</span>button_release_type<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> doEvents<span style="color: #009900;">&#40;</span>Display    <span style="color: #339933;">*</span>dpy<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
 XEvent        Event<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        XNextEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> motion_type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            XDeviceMotionEvent <span style="color: #339933;">*</span>motion <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>XDeviceMotionEvent <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #339933;">;</span>
            ...
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> button_press_type<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
                   <span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span> <span style="color: #339933;">==</span> button_release_type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      XDeviceButtonEvent <span style="color: #339933;">*</span>button <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>XDeviceButtonEvent <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>Event<span style="color: #339933;">;</span>
&nbsp;
            ...
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Event.<span style="color: #202020;">type</span><span style="color: #339933;">=</span> .... <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            ...
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</li>
<li><strong>XInput 2 </strong><strong> </strong>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Somewhere else...</span>
&nbsp;
<span style="color: #993333;">int</span> xi_opcode<span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>XQueryExtension<span style="color: #009900;">&#40;</span>display<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;XInputExtension&quot;</span><span style="color: #339933;">,&amp;</span>xi_opcode<span style="color: #339933;">,&amp;</span>event<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>error<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;X Input extension not available.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> EXIT_FAILURE<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong> </strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> doEvents <span style="color: #009900;">&#40;</span>Display <span style="color: #339933;">*</span>dpy <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        XEvent        ev<span style="color: #339933;">;</span>
        XGenericEventCookie <span style="color: #339933;">*</span>cookie <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>ev.<span style="color: #202020;">xcookie</span><span style="color: #339933;">;</span>
        XNextEvent<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>ev<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>XGetEventData<span style="color: #009900;">&#40;</span>dpy<span style="color: #339933;">,</span> cookie<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> cookie<span style="color: #339933;">-&gt;</span>type <span style="color: #339933;">==</span> GenericEvent
            <span style="color: #339933;">&amp;&amp;</span> cookie<span style="color: #339933;">-&gt;</span>extension<span style="color: #339933;">==</span>xi_opcode<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            XIDeviceEvent <span style="color: #339933;">*</span>event <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;EVENT type %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> event<span style="color: #339933;">-&gt;</span>evtype<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">-&gt;</span>evtype<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//</span>
                <span style="color: #666666; font-style: italic;">// In all below event&gt;deviceid contains the id of the device</span>
                <span style="color: #666666; font-style: italic;">//</span>
                <span style="color: #b1b100;">case</span> XI_DeviceChanged<span style="color: #339933;">:</span>
                    XIDeviceChangedEvent <span style="color: #339933;">*</span>dc <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_HierarchyChanged<span style="color: #339933;">:</span>
                    XIHierarchyEvent <span style="color: #339933;">*</span>he <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_RawEvent<span style="color: #339933;">:</span>
                    XIRawEvent <span style="color: #339933;">*</span>re <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_FocusIn<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_Enter<span style="color: #339933;">:</span>
                    XIEnterEvent <span style="color: #339933;">*</span>ee <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_FocusOut<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_Leave<span style="color: #339933;">:</span>
                    XILeaveEvent <span style="color: #339933;">*</span>le <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_PropertyEvent<span style="color: #339933;">:</span>
                    XIPropertyEvent <span style="color: #339933;">*</span>pe <span style="color: #339933;">=</span> cookie<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">;</span>
                    ...
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">case</span> XI_Motion<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_ButtonPress<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_ButtonRelease<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_KeyPress<span style="color: #339933;">:</span>
                <span style="color: #b1b100;">case</span> XI_KeyRelease<span style="color: #339933;">:</span>
                    <span style="color: #666666; font-style: italic;">// do something with event (XIDeviceEvent contains data)</span>
                    <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/xinput-1-xinput-2-conversion-guide/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jhbuild just won&#8217;t build! (aka Include path madness)</title>
		<link>http://www.clearchain.com/blog/posts/jhbuild-just-wont-build-aka-include-path-madness</link>
		<comments>http://www.clearchain.com/blog/posts/jhbuild-just-wont-build-aka-include-path-madness#comments</comments>
		<pubDate>Mon, 17 Nov 2008 23:42:04 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[FreeDesktop]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[UniSA]]></category>
		<category><![CDATA[C_INCLUDE_PATH]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[jhbuild]]></category>
		<category><![CDATA[search paths]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=137</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/jhbuild-just-wont-build-aka-include-path-madness"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>I&#8217;ve been recently trying to work out why jhbuild fails to build xorg on my FreeBSD box. Traditionally I compile to /usr/local/ however after wanting to experiment with MPX I&#8217;ve set things up so that I compile to /usr/local/MPX Sadly this kept breaking in xorg/lib/libX11 with the error: xcb_io.c: In function 'require_socket': xcb_io.c:35: warning: implicit declaration<a href="http://www.clearchain.com/blog/posts/jhbuild-just-wont-build-aka-include-path-madness"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been recently trying to work out why jhbuild fails to build xorg on my FreeBSD box. Traditionally I compile to <em>/usr/local/</em> however after wanting to experiment with MPX I&#8217;ve set things up so that I compile to <em>/usr/local/MPX</em></p>
<p>Sadly this kept breaking in xorg/lib/libX11 with the error:</p>
<p><span id="more-137"></span></p>
<pre style="padding-left: 30px; ">xcb_io.c: In function 'require_socket':
xcb_io.c:35: warning: implicit declaration of function 'xcb_take_socket'
xcb_io.c:35: warning: nested extern declaration of 'xcb_take_socket'
xcb_io.c: In function 'process_responses':
xcb_io.c:188: error: 'GenericEvent' undeclared (first use in this function)
xcb_io.c:188: error: (Each undeclared identifier is reported only once
xcb_io.c:188: error: for each function it appears in.)
xcb_io.c:189: error: 'xcb_ge_event_t' undeclared (first use in this function)
xcb_io.c:189: error: expected expression before ')' token
xcb_io.c:193: error: expected expression before ')' token
xcb_io.c: In function '_XSend':
xcb_io.c:332: warning: implicit declaration of function 'xcb_writev'
xcb_io.c:332: warning: nested extern declaration of 'xcb_writev'</pre>
<p> </p>
<p>For the life of me I couldn&#8217;t make sense of it. GenericEvent is defined in xcb/xcb.h and checking the preprocessor output xcb.h was being included. Likewise the lack of xcb_ge_event_t was baffling me as it was certain in xcb/xcb.h. It wasn&#8217;t till I looked a little closer that I realised that the wrong xcb.h was being used. Turns out that /<em>usr/local/include/xcb/xcb.h</em> was being used however I wanted <em>/usr/local/MPX/include/xcb/xcb.h</em> to be used. Hence I tried adding <em>-I/usr/local/MPX</em> to CFLAGS with no success and also tried setting <em>CC=&#8221;gcc -I/usr/local/MPX&#8221;</em> also with no success. It just didn&#8217;t make sense!</p>
<p>Looking at the gcc line, <em>/u</em><em>sr/local/MPX</em> should have been used first. It wasn&#8217;t until I finally check the preprocessor what it thought the system paths were did it all make sense.</p>
<p>The output from cpp is below:</p>
<pre style="padding-left: 30px; "><span style="font-family: 'Lucida Grande'; line-height: 19px; white-space: normal; ">U</span>sing built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719  [FreeBSD]
 /usr/libexec/cc1 -E -quiet -v -I. -I../include/X11 -I../include -I../include/X11
-I../include -I../include/X11 -I../src/xcms -I../src/xkb -I../src/xlibi18n -I/usr/local/include 
-D_LONGLONG -DHAVE_CONFIG_H -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -D_THREAD_SAFE -D_BSD_SOURCE
-DX11_t -DTRANS_CLIENT -isystem /usr/local/MPX/include xcb_io.c -o xcb_io.lo -Wall -Wpointer-arith
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing -fworking-directory -O0</pre>
<pre style="padding-left: 30px; ">ignoring duplicate directory "/usr/local/MPX/include"
ignoring duplicate directory "/usr/include"
ignoring duplicate directory "../include/X11"
ignoring duplicate directory "../include"
ignoring duplicate directory "../include/X11"
#include "..." search starts here:
#include &lt;...&gt; search starts here:
 .
 ../include/X11
 ../include
 ../src/xcms
 ../src/xkb
 ../src/xlibi18n
 /usr/local/include
 /usr/local/MPX/include
 /usr/include
End of search list.</pre>
<p>It turns out that jhbuild sets the environment variable <em>C_INCLUDE_PATH, </em>in this case to <em>/usr/local/MPX/include</em>. This variable adds a library to the system search path. Whilst it prepends to the system search path,  -I<em> </em>options prepend the system search path, hence with one -I option being <em>/usr/local/include</em>, we get the ordering incorrect and the wrong header is used.  </p>
<p>So now it was up to working out why <em>/usr/local/include</em> was needed. Searching config.log it turns out the bigfontproto was needed by libX11, pkg_config was searching for it and finding it not in <em>/usr/local/MPX/lib/share/pkg_config</em> but in <em>/usr/local/lib/share/pkg_config</em>. The reason for this is bigfontproto wasn&#8217;t listed as a dependancy in the xorg.modules file used by jhbuild (avaliable at:<a href="http://cgit.freedesktop.org/xorg/util/modular/tree/xorg.modules">http://cgit.freedesktop.org/xorg/util/modular/tree/xorg.modules</a>). Because of this bigfont proto wasn&#8217;t being built by <a href="http://www.jamesh.id.au/software/jhbuild/">jhbuild</a>. Hence the only bigfontproto that existed on the box was the default system bigfont proto which WAS located under /usr/local/include. </p>
<p>The fix was simple. List xf86bigfontproto as a dependency in xorg.modules and all was good. bigfontproto is now pulled in as a dependency and hence gets built before libX11. pkg_config now correctly finds bigfontproto in /<em>usr/local/MPX/lib/share/pkg_config</em> hence doesn&#8217;t need to fallback to the system version so <em>-I/usr/local/include</em> doesn&#8217;t get added to the gcc line. Hence the compiler uses <em>/usr/local/MPX/include/xcb/xcb.h </em>rather than the one in <em>/usr/local/include/xcb/xcb.h</em> and the compiler errors vanish.</p>
<p>So now things are building and I&#8217;m off for a coffee!<br />
(xorg.modules has also been correctly updated so some other poor person doesn&#8217;t have the same issues).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/jhbuild-just-wont-build-aka-include-path-madness/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>stl::set</title>
		<link>http://www.clearchain.com/blog/posts/stlset</link>
		<comments>http://www.clearchain.com/blog/posts/stlset#comments</comments>
		<pubDate>Thu, 13 Nov 2008 14:26:24 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[stl]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=125</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/stlset"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Working with Mark&#8217;s dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under Visual Studio, it failed to compile under gcc/g++. With the error: dnlCommon/Logger.cpp: In member function 'void dnlCommon::Logger::setMask(std::ostream&#38;, std::bitset&#60;5ul&#62;)': dnlCommon/Logger.cpp:64: error: invalid initialization of reference of type 'dnlCommon::Logger::LoggerPair&#38;'<a href="http://www.clearchain.com/blog/posts/stlset"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p>Working with Mark&#8217;s dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under Visual Studio, it failed to compile under gcc/g++. With the error:</p>
<pre>dnlCommon/Logger.cpp: In member function 'void dnlCommon::Logger::setMask(std::ostream&amp;, std::bitset&lt;5ul&gt;)':
dnlCommon/Logger.cpp:64: error: invalid initialization of reference of type 'dnlCommon::Logger::LoggerPair&amp;' from expression of type 'const dnlCommon::Logger::LoggerPair'
/usr/local/lib/gcc-4.0.4/include/c++/bits/stl_algo.h: In function '_OutputIterator std::remove_copy(_InputIterator, _InputIterator, _OutputIterator, const _Tp&amp;) [with _InputIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _Tp = dnlCommon::Logger::LoggerPair]':
/usr/local/lib/gcc-4.0.4/include/c++/bits/stl_algo.h:1112:   instantiated from '_ForwardIterator std::remove(_ForwardIterator, _ForwardIterator, const _Tp&amp;) [with _ForwardIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _Tp = dnlCommon::Logger::LoggerPair]'
dnlCommon/Logger.cpp:54:   instantiated from here
/usr/local/lib/gcc-4.0.4/include/c++/bits/stl_algo.h:1037: error: passing 'const dnlCommon::Logger::LoggerPair' as 'this' argument of 'dnlCommon::Logger::LoggerPair&amp; dnlCommon::Logger::LoggerPair::operator=(const dnlCommon::Logger::LoggerPair&amp;)' discards qualifiers</pre>
<p>It turned out that the issue occurred with the assignment operator (operator = ) on the <code>stl::set</code> class. Tracing the problem we found that <code>set&lt;TYPE&gt;::iterator</code> is <code>const</code> rather than non cost. Hence calling stl functions that made use of the iterators but also the assignment operator would fail.</p>
<p>Looking further into the problem I found:</p>
<pre>      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // DR 103. set::iterator is required to be modifiable,
      // but this allows modification of keys.
      typedef typename _Rep_type::const_iterator iterator;
      typedef typename _Rep_type::const_iterator const_iterator;</pre>
<p>Hmm, that&#8217;s strange. A bit of <a class="external text" title="http://google.com" rel="nofollow" href="http://google.com/">googling</a> revieled the problem to be an issue with the stl standard. Fixes to gcc/g++ are listed at <a class="external free" title="http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html" rel="nofollow" href="http://gcc.gnu.org/onlinedocs/libstdc++/faq.html">http://gcc.gnu.org/onlinedocs/libstdc++/ext/howto.html</a> in particular error 103 is listed at <a class="external free" title="http://gcc.gnu.org/onlinedocs/libstdc++/ext/lwg-defects.html#103" rel="nofollow" href="http://gcc.gnu.org/onlinedocs/libstdc++/ext/lwg-defects.html#103">http://gcc.gnu.org/onlinedocs/libstdc++/ext/lwg-defects.html#103</a><br />
So it looks like the bug was ratified by the C++ committee in 1998 and it still isn&#8217;t fixed in Visual Studio 2005 (VC++ 8.0) !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/stlset/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Stl::reverse iterator</title>
		<link>http://www.clearchain.com/blog/posts/stlreverse-iterator</link>
		<comments>http://www.clearchain.com/blog/posts/stlreverse-iterator#comments</comments>
		<pubDate>Thu, 13 Nov 2008 14:21:10 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[stl]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=121</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/stlreverse-iterator"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>I was coding a little program a while back when I found a Quirk about the stl reverse_iterator. Use of the iterator is quite easy until you have to delete from one. I tried the normal way of: vector&#60;sometype&#62;::reverse_iterator myiterator... .. .. myvector.erase(myiterator). only to find the code didn&#8217;t compile. A little baffled I started<a href="http://www.clearchain.com/blog/posts/stlreverse-iterator"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p>I was coding a little program a while back when I found a <a title="Category:Programming Quirks" href="http://www.clearchain.com/blog/categories/computers/programming">Quirk</a> about the <code>stl  reverse_iterator</code>. Use of the iterator is quite easy until you have to delete from one. I tried the normal way of:</p>
<pre>vector&lt;sometype&gt;::reverse_iterator myiterator...
..
..
myvector.erase(myiterator).</pre>
<p>only to find the code didn&#8217;t compile. A little baffled I started to looking into why. It turns out you <strong>Can&#8217;t&#8217;<em> delete from a reverse iterator directly. So the question is </em>How do you delete from a reverse iterator?</strong>.</p>
<p>Not wanting to do a full forward traversal to get to the same point I did some <a class="external text" title="http://www.google.com" rel="nofollow" href="http://www.google.com/">Googling</a>. Eventually I found the page: <a class="external free" title="http://www.ddj.com/dept/cpp/184401406" rel="nofollow" href="http://www.ddj.com/dept/cpp/184401406">http://www.ddj.com/dept/cpp/184401406</a></p>
<p>which explains why you can&#8217;t delete from the reverse iterator. More importantly it indicates a way that you can delete from the reverse_iterator. So how?</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"> <span style="color: #993333;">void</span> Manager<span style="color: #339933;">::</span><span style="color: #202020;">raiseWindow</span><span style="color: #009900;">&#40;</span>WMWindow<span style="color: #339933;">*</span> wmwindow<span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
   <span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;</span>vector<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>WMWindow<span style="color: #339933;">*&amp;</span>gt<span style="color: #339933;">;::</span><span style="color: #202020;">reverse_iterator</span> it <span style="color: #339933;">=</span> windows.<span style="color: #202020;">rbegin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>strong<span style="color: #339933;">&gt;</span>
   <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>it <span style="color: #339933;">!=</span> windows.<span style="color: #202020;">rend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>it <span style="color: #339933;">==</span> wmwindow<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// why ++it see &lt;a class=&quot;external free&quot; title=&quot;http://www.ddj.com/dept/cpp/184401406&quot; rel=&quot;nofollow&quot; href=&quot;http://www.ddj.com/dept/cpp/184401406&quot;&gt;http://www.ddj.com/dept/cpp/184401406&lt;/a&gt;</span>
      <span style="color: #339933;">&lt;</span>strong<span style="color: #339933;">&gt;</span>windows.<span style="color: #202020;">erase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>it<span style="color: #009900;">&#41;</span>.<span style="color: #202020;">base</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>strong<span style="color: #339933;">&gt;</span>
      windows.<span style="color: #202020;">push_back</span><span style="color: #009900;">&#40;</span>wmwindow<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     it<span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   wmwindow<span style="color: #339933;">-&gt;</span>raise<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Gives an example of how to do it. However, be aware, doing the above erase, invalidates the iterator so don&#8217;t go trying to use it again afterwards! }</p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/stlreverse-iterator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gdb</title>
		<link>http://www.clearchain.com/blog/posts/gdb</link>
		<comments>http://www.clearchain.com/blog/posts/gdb#comments</comments>
		<pubDate>Fri, 07 Nov 2008 04:18:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[tui]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=64</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/gdb"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>Helpful hints for when using GDB]]></description>
			<content:encoded><![CDATA[<p>This page documents some tips on how to use GDB for advanced debugging. It was created as all information I could find on the web lacked some useful information.</p>
<p> </p>
<p><span id="more-64"></span></p>
<h1><span class="mw-headline">Assembly Debugging</span></h1>
<p> </p>
<h2><span class="mw-headline">Starting Out</span></h2>
<p>When debugging assembly in gdb, it&#8217;s useful to learn about TUI mode. TUI mode gives gdb text based windows. This allows you to see both the disassembled coded as well as the ability to issue commands at the same time &#8211; a must have for debugging.</p>
<p>To enter into TUI mode use:</p>
<pre>CTRL-X CTRL-1</pre>
<p>This will create a single window. (To get rid of it use</p>
<pre>CTRL-X a</pre>
<p>Initially this window will not be in the right <em>layout</em>. (In gdb TUI mode, a <em>layout</em> is like a mode, ie assembler mode, etc).</p>
<p>You can tell gdb to change to assembly mode using:</p>
<pre>layout asm</pre>
<p>Now you should be able to see your program in a disassembled text window.</p>
<ul>
<li><strong>Tip</strong>: If you want to see registers as well use: <code>layout regs</code></li>
</ul>
<p> </p>
<h2><span class="mw-headline">Common Tasks</span></h2>
<p>In assembly debugging, theres a few common tasks that you need to these are listed below:</p>
<h3><strong>View registers</strong></h3>
<p>To view registers you can either use:</p>
<pre>info all-registers     |   info reg     |  i r</pre>
<p>to view the all/some of the registers. You can use:</p>
<pre> layout reg</pre>
<p>to bring up a TUI window with all the registers. This window also shows what changes between instructions when your executing them.</p>
<p>To examine the current value of a register you can use:</p>
<pre> info reg es</pre>
<p>You can examine the memory the register points to using the <strong>x</strong> instruction ie:</p>
<pre> x/x $esp    # View mem in hex
 x/b $esp    # View mem in bin
 x/i $esp    # View instruction at address</pre>
<p>You can set a register using:</p>
<pre> set $eip = 0x90   # Set current eip to address 0x90</pre>
<p> </p>
<h3><span class="mw-headline">Memory Addresses</span></h3>
<p>If you recall the early lessons in computing there&#8217;s two main memory regions in a program &#8211; the code segment and the data segment.</p>
<p>The code segment normally consists of executable instructions and static things like constants and strings. You can view the instructions at a memory address using:</p>
<pre>disassemble 0x123123</pre>
<p>where 0&#215;123123 is an address in memory. This will show you a number of instructions at that address and onwards till the end of the function ends.</p>
<p>You can examine a memory address using</p>
<pre> x  0x123123</pre>
<p>The <strong>x</strong> command takes a number of different parameters/options. It can output binary, hex, strings, instructions etc. For more help on how to use it try: <code>help x</code> in gdb.<br />
You can also print out the value of an address using:</p>
<pre> p 0x123123</pre>
<p>like <em>x</em> the <strong>p</strong> (or print) command the p command takes a number of options for displaying hex, binary etc.</p>
<p> </p>
<h3><span class="mw-headline">Altering program execution</span></h3>
<p>Say you&#8217;ve been debugging a program in assembly. You&#8217;ve setup <strong>b</strong>reak points, either to memory or functions. Now you&#8217;ve found the instruction you want to change. There&#8217;s a number of ways you can change it. Chances are the instruction is some type of compare, (cmp, cmpl, jge, jmp, etc). You could possible make the instruction a no instruction (nop) or modify the register the compare relies on to be something else.</p>
<p>In order to alter the line to be a nop you can do something like:</p>
<pre> set *0xbxxxx = 0x90</pre>
<p>In this case the address is 0xbxxxx and the instruction (under x86 arch) is 0&#215;90 (nop). However this could cause an issue if the previous instruction was 2 bytes wide. ie:</p>
<pre>1&gt; 0x126c :   incl   0xfffff3dc(%ebp)
2&gt; 0x126d :   testb  %al,%al
3&gt; 0x126f :   jne    0x125c</pre>
<p>In the above the instruction at line 1 is a 1 byte instruction. The instruction at line 2 is a two byte instruction. How? Looks at the difference between the addresses:</p>
<pre> 0x126d - 0x126c = 1 byte
 0x126f - 0x126d = 2 byte</pre>
<p>In x86 arch, 0&#215;90 (nop) is only a 1 byte instruction.</p>
<p>If you wanted to modify line 2, you&#8217;ld have to set the al register so the test would succeed.</p>
<p><strong>Managing Signals</strong></p>
<p>You can enable/disable signals using the &#8216;<strong>handle</strong>&#8216; command. ie:</p>
<pre style="padding-left: 30px; ">handle SIGALARM stop</pre>
<p>The options to handle are:</p>
<p> </p>
<dl>
<dt style="padding-left: 30px; "><code>nostop</code> </dt>
<dd style="padding-left: 30px; "> GDB should not stop your program when this signal happens.  It may still print a message telling you that the signal has come in. </dd>
<dt style="padding-left: 30px; "><code>stop</code> </dt>
<dd style="padding-left: 30px; "> GDB should stop your program when this signal happens.  This implies the <code>print</code> keyword as well. </dd>
<dt style="padding-left: 30px; "><code>print</code> </dt>
<dd style="padding-left: 30px; "> GDB should print a message when this signal happens. </dd>
<dt style="padding-left: 30px; "><code>noprint</code> </dt>
<dd style="padding-left: 30px; "> GDB should not mention the occurrence of the signal at all.  This implies the <code>nostop</code> keyword as well. </dd>
<dt style="padding-left: 30px; "><code>pass</code> </dt>
<dd style="padding-left: 30px; "> GDB should allow your program to see this signal; your program can handle the signal, or else it may terminate if the signal is fatal and not handled. </dd>
<dt style="padding-left: 30px; "><code>nopass</code> </dt>
<dd style="padding-left: 30px; "> GDB should not allow your program to see this signal. </dd>
</dl>
<p>And to see what signals are currently set and their default setup use:</p>
<pre style="padding-left: 30px; ">info signals </pre>
<p> </p>
<h1><span class="mw-headline">Helpful External Links</span></h1>
<p><a class="external free" title="http://insecure.org/stf/mudge_buffer_overflow_tutorial.html" rel="nofollow" href="http://insecure.org/stf/mudge_buffer_overflow_tutorial.html">http://insecure.org/stf/mudge_buffer_overflow_tutorial.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/gdb/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CVS</title>
		<link>http://www.clearchain.com/blog/posts/cvs</link>
		<comments>http://www.clearchain.com/blog/posts/cvs#comments</comments>
		<pubDate>Fri, 07 Nov 2008 04:13:22 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[merge]]></category>
		<category><![CDATA[RCS]]></category>
		<category><![CDATA[revision control]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[VCS]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=55</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/cvs"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>This page contains various helpful hints for using CVS. Contents  [hide] 1 Importing To a NEW Vendor Branch 2 Importing to an EXISTING Vendor Branch 3 Ignoring files via cvsignore 4 Branches / Merging Branches / Trunk Merging 4.1 How to check out a branch 4.2 How to make a branch 4.2.1 You have no checked out trees 4.2.2 You have a checked<a href="http://www.clearchain.com/blog/posts/cvs"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p>This page contains various helpful hints for using CVS.</p>
<p><span id="more-55"></span></p>
<table id="toc" class="toc" border="0" summary="Contents">
<tbody>
<tr>
<td>
<div id="toctitle">
<h2>Contents</h2>
<p> <span class="toctoggle">[<a id="togglelink" class="internal" href="javascript:toggleToc()">hide</a>]</span></div>
<ul>
<li class="toclevel-1"><a href="http://www.clearchain.com/wiki/CVS#Importing_To_a_NEW_Vendor_Branch"><span class="tocnumber">1</span> <span class="toctext">Importing To a NEW Vendor Branch</span></a></li>
<li class="toclevel-1"><a href="http://www.clearchain.com/wiki/CVS#Importing_to_an_EXISTING_Vendor_Branch"><span class="tocnumber">2</span> <span class="toctext">Importing to an EXISTING Vendor Branch</span></a></li>
<li class="toclevel-1"><a href="http://www.clearchain.com/wiki/CVS#Ignoring_files_via_cvsignore"><span class="tocnumber">3</span> <span class="toctext">Ignoring files via cvsignore</span></a></li>
<li class="toclevel-1"><a href="http://www.clearchain.com/wiki/CVS#Branches_.2F_Merging_Branches_.2F_Trunk_Merging"><span class="tocnumber">4</span> <span class="toctext">Branches / Merging Branches / Trunk Merging</span></a>
<ul>
<li class="toclevel-2"><a href="http://www.clearchain.com/wiki/CVS#How_to_check_out_a_branch"><span class="tocnumber">4.1</span> <span class="toctext">How to check out a branch</span></a></li>
<li class="toclevel-2"><a href="http://www.clearchain.com/wiki/CVS#How_to_make_a_branch"><span class="tocnumber">4.2</span> <span class="toctext">How to make a branch</span></a>
<ul>
<li class="toclevel-3"><a href="http://www.clearchain.com/wiki/CVS#You_have_no_checked_out_trees"><span class="tocnumber">4.2.1</span> <span class="toctext">You have no checked out trees</span></a></li>
<li class="toclevel-3"><a href="http://www.clearchain.com/wiki/CVS#You_have_a_checked_out_trunk.2C_and_you_want_to_tag_it_and_start_using_it_as_a_branch"><span class="tocnumber">4.2.2</span> <span class="toctext">You have a checked out trunk, and you want to tag it and start using it as a branch</span></a></li>
</ul>
</li>
<li class="toclevel-2"><a href="http://www.clearchain.com/wiki/CVS#How_to_merge_the_trunk_into_your_branch"><span class="tocnumber">4.3</span> <span class="toctext">How to merge the trunk into your branch</span></a></li>
<li class="toclevel-2"><a href="http://www.clearchain.com/wiki/CVS#How_to_merge_your_branch_to_the_main_trunk"><span class="tocnumber">4.4</span> <span class="toctext">How to merge your branch to the main trunk</span></a></li>
</ul>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><a name="Importing_To_a_NEW_Vendor_Branch"></a></p>
<h2><span class="mw-headline">Importing To a NEW Vendor Branch</span></h2>
<p>This directory contains virgin sources of the original distribution files on a &#8220;vendor&#8221; branch. Do not, under any circumstances, attempt to upgrade the files in this directory via patches and a cvs commit. New versions or official-patch versions must be imported. Please remember to import with &#8220;-ko&#8221; to prevent CVS from corrupting any vendor RCS Ids.</p>
<p>To upgrade to a newer version of a project, when it is available:</p>
<ol>
<li>Unpack the new version into an empty directory.</li>
</ol>
<p>[Do not make ANY changes to the files.]</p>
<ul>
<li>Remove the any files that don&#8217;t apply to this project</li>
</ul>
<ul>
<li>3. Use the command:</li>
</ul>
<pre> cvs import -ko -m 'Virgin import of Project v&lt;version&gt;' www/share/contrib/project VENDOR project_&lt;version&gt;</pre>
<ul>
<li>Follow the instructions printed out in step 3 to resolve any conflicts between local changes and the newer version.</li>
</ul>
<p>Do not, under any circumstances, deviate from this procedure.</p>
<p>To make local changes to cpio, simply patch and commit to the main branch (aka <em>HEAD</em>). Never make local changes on them <em>VENDOR </em>branch.</p>
<p>All local changes should be submitted back to the maintainer of the project for inclusion in the next vendor release.</p>
<p><a name="Importing_to_an_EXISTING_Vendor_Branch"></a></p>
<h2><span class="mw-headline">Importing to an EXISTING Vendor Branch</span></h2>
<p>This text is taken from: <a class="external free" title="http://www.mewburn.net/luke/papers/3rdparty-and-cvs.html" rel="nofollow" href="http://www.mewburn.net/luke/papers/3rdparty-and-cvs.html">http://www.mewburn.net/luke/papers/3rdparty-and-cvs.html</a> Many thanks to the author as it has saved me lots of grief.</p>
<p>It is rare for third-party software to remain unchanged forever; updates are available (even on a regular basis).</p>
<p>An important part of managing third-party software is upgrading to a newer version in a sane way.</p>
<p>The process to import an updated version of a package is similar to importing the original package. However, because changes in the newer version may conflict with any local changes that you may have made to the product, there are a couple of steps that are different.</p>
<p>In this example, we&#8217;ll be upgrading dhcp 2.0b1 from pl18 to pl27.</p>
<p>In the directory containing the extracted source import the new version:</p>
<pre> % cvs import -m 'ISC dhcp 2.0b1pl27' net/dhcp ISC dhcp-2-0-b1-pl27
 U net/dhcp/CHANGES
 C net/dhcp/Makefile.conf
     ...
 U net/dhcp/server/dhcpd.leases.cat5
 1 conflicts created by this import.</pre>
<p>Use the following command to help the merge:</p>
<pre> cvs checkout -jISC:yesterday -jISC net/dhcp</pre>
<p>As you can see there was a conflict on the import (Makefile.conf; the file with the status character of &#8220;C&#8221;). This is CVS&#8217;s way of indicating that those files have been modified from the previous release of the vendor code. Checkout the updated source, automatically merging in any changes. Whether or not CVS suggests a checkout command, you should use a checkout of the form:</p>
<pre> cvs checkout -j old-release-tag -j new-release-tag module</pre>
<p>old-release-tag is the previous release tag, and new-release-tag is the one just imported.</p>
<p>For this example the cvs command is:</p>
<pre> % cvs checkout -j dhcp-2-0-b1-pl18 -j dhcp-2-0-b1-pl27 net/dhcp
 U net/dhcp/CHANGES
 U net/dhcp/Makefile.conf
 RCS file: /src/cvsroot/net/dhcp/Makefile.conf,v
 retrieving revision 1.1.1.1
 retrieving revision 1.1.1.2
 Merging differences between 1.1.1.1 and 1.1.1.2 into Makefile.conf
 	...
 U net/dhcp/server/dhcpd.leases.cat5</pre>
<p>The advantages of using checkout -j old-release-tag -j new-release-tag include:</p>
<ul>
<li>files added or deleted by the vendor between releases are handled automatically, and</li>
<li>merges between changes are cleaner.</li>
</ul>
<p>Remember; always use cvs checkout -j old-release-tag -j new-release-tag when checking out code for the first time after you have updated a vendor release. It saves a lot of time.</p>
<p>Search for and resolve any conflicts. A couple of CVS commands are useful for this. cvs update will show any files modified, added, or removed by the vendor between releases.</p>
<pre> % cvs update
 M Makefile.conf</pre>
<p>Note that even though include/site.h was locally modified in the previous release, it does not show up as modified here. This is because it was not actually modified by the vendor between the two vendor releases.</p>
<p>cvs diff will display any changes between the last release and this code; changes either from local updates or from the new release. The diff output will also display our changes to include/site.h.</p>
<p>It is probably more useful to use cvs diff -r VENDOR to display changes between the most recent vendor release and this code:</p>
<pre> % cvs diff -r ISC
 Index: Makefile.conf
 =======================================================
 RCS file: /src/cvsroot/net/dhcp/Makefile.conf,v
 retrieving revision 1.1.1.2
 diff -r1.1.1.2 Makefile.conf
 133a134,141
 &gt; ## RMITCS overrides
 &gt; #BINDIR = /usr/local/sbin
 &gt; #CLIENTBINDIR = /usr/local/sbin
 &gt; #ADMMANDIR = /usr/local/man/cat1m
 &gt; #FFMANDIR = /usr/local/man/cat4
 &gt; #VARRUN = /var/run
 &gt; #VARDB = /var/run/dhcp
 &gt; #SCRIPT=none
 Index: includes/site.h
 =======================================================
 RCS file: /src/cvsroot/net/dhcp/includes/site.h,v
 retrieving revision 1.1.1.1
 retrieving revision 1.2
 diff -r1.1.1.1 -r1.2
 39a40
 &gt; #define _PATH_DHCPD_PID       "/var/run/dhcpd.pid"
 45a47
 &gt; #define _PATH_DHCPD_DB        "/var/run/dhcpd.leases"
 50a53
 &gt; #define _PATH_DHCPD_CONF      "/usr/local/etc/dhcpd.conf"</pre>
<p>Peruse the output of the diffs and determine if things look reasonable. In this case I am fairly happy with the changes. Refer to the CVS info documentation [4] node &#8220;Conflicts example&#8221; for more information on resolving conflicts.</p>
<p><a name="Ignoring_files_via_cvsignore"></a></p>
<h2><span class="mw-headline">Ignoring files via cvsignore</span></h2>
<p>There are certain file names that frequently occur inside your working copy, but that you don&#8217;t want to put under CVS control. Examples are all the object files that you get while you compile your sources. Normally, when you run &#8216;cvs update&#8217;, it prints a line for each file it encounters that it doesn&#8217;t know about (see section A.16.2 update output).</p>
<p>CVS has a list of files (or sh(1) file name patterns) that it should ignore while running update, import and release. This list is constructed in the following way.</p>
<ul>
<li>The list is initialized to include certain file name patterns: names associated with CVS administration, or with other common source control systems; common names for patch files, object files, archive files, and editor backup files; and other names that are usually artifacts of assorted utilities. Currently, the default list of ignored file name patterns is:</li>
</ul>
<pre>   RCS     SCCS    CVS     CVS.adm
   RCSLOG  cvslog.*
   tags    TAGS
   .make.state     .nse_depinfo
   *~      #*      .#*     ,*      _$*     *$
   *.old   *.bak   *.BAK   *.orig  *.rej   .del-*
   *.a     *.olb   *.o     *.obj   *.so    *.exe
   *.Z     *.elc   *.ln
   core</pre>
<ul>
<li>The per-repository list in &#8216;$CVSROOT/CVSROOT/cvsignore&#8217; is appended to the list, if that file exists.</li>
<li>The per-user list in &#8216;.cvsignore&#8217; in your home directory is appended to the list, if it exists.</li>
<li>Any entries in the environment variable $CVSIGNORE are appended to the list.</li>
<li>Any &#8216;-I&#8217; options given to CVS is appended.</li>
<li>As CVS traverses through your directories, the contents of any &#8216;.cvsignore&#8217; will be appended to the list. The patterns found in &#8216;.cvsignore&#8217; are only valid for the directory that contains them, not for any sub-directories.</li>
</ul>
<p>In any of the 5 places listed above, a single exclamation mark (&#8216;!&#8217;) clears the ignore list. This can be used if you want to store any file which normally is ignored by CVS.</p>
<p>Specifying &#8216;-I !&#8217; to cvs import will import everything, which is generally what you want to do if you are importing files from a pristine distribution or any other source which is known to not contain any extraneous files. However, looking at the rules above you will see there is a fly in the ointment; if the distribution contains any &#8216;.cvsignore&#8217; files, then the patterns from those files will be processed even if &#8216;-I !&#8217; is specified. The only workaround is to remove the &#8216;.cvsignore&#8217; files in order to do the import. Because this is awkward, in the future &#8216;-I !&#8217; might be modified to override &#8216;.cvsignore&#8217; files in each directory.</p>
<p>Note that the syntax of the ignore files consists of a series of lines, each of which contains a space separated list of filenames. This offers no clean way to specify filenames which contain spaces, but you can use a workaround like &#8216;foo?bar&#8217; to match a file named &#8216;foo bar&#8217; (it also matches &#8216;fooxbar&#8217; and the like). Also note that there is currently no way to specify comments.</p>
<p><a name="Branches_.2F_Merging_Branches_.2F_Trunk_Merging"></a></p>
<h2><span class="mw-headline">Branches / Merging Branches / Trunk Merging</span></h2>
<p>This example was taken from: <a class="external free" title="http://dri.freedesktop.org/wiki/CvsPolicy" rel="nofollow" href="http://dri.freedesktop.org/wiki/CvsPolicy">http://dri.freedesktop.org/wiki/CvsPolicy</a></p>
<p> </p>
<p><a name="How_to_check_out_a_branch"></a></p>
<h3><span class="mw-headline">How to check out a branch</span></h3>
<pre>  cvs co -r &lt;keyword&gt;-&lt;revision&gt;-branch xc</pre>
<p><a name="How_to_make_a_branch"></a></p>
<h3><span class="mw-headline">How to make a branch</span></h3>
<p><a name="You_have_no_checked_out_trees"></a></p>
<h4><span class="mw-headline">You have no checked out trees</span></h4>
<p>If you want to use the main trunk as the anchor for your branch:</p>
<pre>  cvs rtag -b &lt;keyword&gt;-&lt;revision&gt;-branch
  cvs co -b &lt;keyword&gt;-&lt;revision&gt;-branch</pre>
<p>If you want to use some other tag as the anchor for your branch:</p>
<pre>  cvs rtag -b -r &lt;tag&gt; &lt;keyword&gt;-&lt;revision&gt;-branch
  cvs co -b &lt;keyword&gt;-&lt;revision&gt;-branch</pre>
<p><a name="You_have_a_checked_out_trunk.2C_and_you_want_to_tag_it_and_start_using_it_as_a_branch"></a></p>
<h4><span class="mw-headline">You have a checked out trunk, and you want to tag it and start using it as a branch</span></h4>
<pre>  cd &lt;root-of-your-checked-out-tree&gt;
  cvs tag -b &lt;keyword&gt;-&lt;revision&gt;-branch
  cvs update -r &lt;keyword&gt;-&lt;revision&gt;-branch</pre>
<p>This makes the {{{&lt;keyword&gt;-&lt;revision&gt;-branch}}} tag sticky. You can verify this by using {{{cvs status}}}, for example in `XFree39/xc`, do this:</p>
<pre>  cvs status Makefile</pre>
<p>or</p>
<pre>  cvs status -v Makefile</pre>
<p><a name="How_to_merge_the_trunk_into_your_branch"></a></p>
<h3><span class="mw-headline">How to merge the trunk into your branch</span></h3>
<p>Before you merge your code into the trunk you should first merge the latest trunk code into your branch. After merged code has been tested on your branch, merging into the trunk should be simple.</p>
<ul>
<li>Be sure all the changes on your branch are checked in.</li>
<li>Tag your branch with a &#8216;freeze&#8217; tag:</li>
</ul>
<pre>  cvs tag &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt;-freeze</pre>
<ul>
<li>Merge from the trunk:</li>
</ul>
<pre>  cvs update -d -j HEAD</pre>
<ul>
<li>Resolve any conflicts from the merge.</li>
<li>Recompile and build your branch. Test it.</li>
<li>Check in your changes from the merge.</li>
<li>Tag your branch with a merge tag:</li>
</ul>
<pre>  cvs tag &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt;</pre>
<p><a name="How_to_merge_your_branch_to_the_main_trunk"></a></p>
<h3><span class="mw-headline">How to merge your branch to the main trunk</span></h3>
<ul>
<li>Be sure your &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt;-merge tag (on the branch) is up</li>
</ul>
<p>to date (i.e., in case you changed some files from between the time you merged the trunk onto the branch until you merged the branch onto the trunk).</p>
<p>You can make the tag with:</p>
<pre>  cvs tag &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt;</pre>
<ul>
<li>Revert your working tree to the main trunk:</li>
</ul>
<pre>  cvs update -A</pre>
<p>(Alternatively, you can just check out a new copy of the main trunk.)</p>
<ul>
<li>Merge in the changes from your branch:</li>
</ul>
<pre>  cvs update -j &lt;keyword&gt;-&lt;revision&gt;-branch</pre>
<ul>
<li>Test your merged tree</li>
</ul>
<ul>
<li>Check in your merged tree to the main branch;</li>
</ul>
<pre>  cvs commit -m 'Merged &lt;keyword&gt;-&lt;revision&gt;'</pre>
<ul>
<li>Tag your merge so we can find it again:</li>
</ul>
<pre>  cvs tag &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt;-merge</pre>
<ul>
<li>Now you can make diffs to send to XFree86</li>
</ul>
<p>Say you keep hacking on your branch after the merge to test a few extra things and you want to merge again. You get the main trunk checked out, as in step 1, then you merge only those changes between your last merge and the most recent revision in your branch:</p>
<pre>  cvs update -j &lt;keyword&gt;-&lt;revision&gt;-&lt;date&gt; \
             -j &lt;keyword&gt;-&lt;revision&gt;-branch</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/cvs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autotools Tips (configure.ac, Makefile.am, autoconf, automake, etc)</title>
		<link>http://www.clearchain.com/blog/posts/autotools</link>
		<comments>http://www.clearchain.com/blog/posts/autotools#comments</comments>
		<pubDate>Fri, 07 Nov 2008 03:48:12 +0000</pubDate>
		<dc:creator>Benjamin Close</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[autoheader]]></category>
		<category><![CDATA[automake]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[libtool]]></category>
		<category><![CDATA[make]]></category>

		<guid isPermaLink="false">http://www.clearchain.com/blog/?p=46</guid>
		<description><![CDATA[<a href="http://www.clearchain.com/blog/posts/autotools"><img align="left" hspace="5" width="150" height="150" src="http://www.clearchain.com/blog/wp-content/plugins/thumbnail-for-excerpts/tfe_no_thumb.png" class="alignleft wp-post-image tfe" alt="" title="" /></a>The Autotools build system is a great system. It consists of a number of tools. These are aclocal[1], autoconf[2], automake[3], autoheader[4], and to some extent libtool[5] These tools all work together to aid in building applications, libraries and providing a consistent framework for doing so. The problem however, is the tools are hard to use, poorly documented and the<a href="http://www.clearchain.com/blog/posts/autotools"> <font size=-2>[..more..]</font></a>]]></description>
			<content:encoded><![CDATA[<p>The Autotools build system is a great system. It consists of a number of tools. These are</p>
<p><strong>aclocal</strong><sup><a href="http://www.clearchain.com/wiki/Autotools#_note-0">[1]</a></sup>, <strong>autoconf</strong><sup><a href="http://www.clearchain.com/wiki/Autotools#_note-1">[2]</a></sup>, <strong>automake</strong><sup><a href="http://www.clearchain.com/wiki/Autotools#_note-2">[3]</a></sup>, <strong>autoheader</strong><sup><a href="http://www.clearchain.com/wiki/Autotools#_note-3">[4]</a></sup>, and to some extent <strong>libtool</strong><sup><a href="http://www.clearchain.com/wiki/Autotools#_note-4">[5]</a></sup></p>
<p>These tools all work together to aid in building applications, libraries and providing a consistent framework for doing so. The problem however, is the tools are hard to use, poorly documented and the learning curve to getting things done is extremely high. Added to this, the tutorials on the web show only the basics of using the system and leave all the useful stuff to the user. The problem is the useful stuff is hard to work out.</p>
<p><span id="more-46"></span></p>
<p>Hence this page is not about showing you yet another <em>hello world</em> autotools setup. Instead it give you tips on how to use the autotools and what you can put in those highly cryptic config files: <em>configure.ac</em>, <em>Makefile.am</em>,<em>config.in</em>.</p>
<h1><span class="mw-headline">configure.ac/configure.in Tips</span></h1>
<p>This page lists common things that one often needs to do with autoconf. These can be placed either in the<em>configure.ac</em> file or if the project is old enough <em>configure.in</em></p>
<h2><span class="mw-headline">Checking Which Operating System The User is Using</span></h2>
<p>This check test to see if the build is for Linux, BSD, Mac, etc. This allows you to tune specific options depending on the platform. This test goes in the <em>configure.ac</em> or <em>configure.in</em> file (depending on what your using).</p>
<pre>#
# Platform specific setup
#
#############################
AC_CANONICAL_HOST
# Check for which host we are on and setup a few things
# specifically based on the host
case $host_os in
  darwin* )
        # Do something specific for mac
        ;;
  linux*)
        # Do something specific for linux
        ;;
   *BSD*)
        # Do something specific for BSD
        ;;
    *)
        #Default Case
        AC_MSG_ERROR([Your platform is not currently supported])
        ;;
esac</pre>
<h2><span class="mw-headline">Setting CFlags/CXXFlags/LDFlags/LIBS</span></h2>
<p>In <em>configure.ac</em> setting &#8216;<em>CFLAGS</em> and similar variables can be done quite easily. You simply set the variable. However, make sure if your aiming to support multiple platforms you do it in a way that is supported. For instance<em>/bin/sh</em> &#8211; the true borne shell doesn&#8217;t understands the <em>+=</em> variable syntax. Hence something like:</p>
<pre> CFLAGS+=" something"</pre>
<p>will fail. You might say that everyone uses <em>bash</em> but things like MacOSX doesn&#8217;t. Instead use the syntax:</p>
<pre> CFLAGS="$CFLAGS something"</pre>
<p>It&#8217;ll work on any platform.</p>
<h2><span class="mw-headline">Passing A Variable from configure.ac to Makefile.am</span></h2>
<p>One of the first things that I found myself needing to do was pass the content of a variable from <em>configure.ac</em> to<em>Makefile.am</em>. Whilst this is burried in the autoconf documentation, here&#8217;s the 2 second version.</p>
<p>In <em>configure.ac</em> do something like:</p>
<pre> GL_LIBS="-lGLU -lGL"
 AC_SUBST(GL_LIBS)</pre>
<p>Then in Makefile.am put:</p>
<p>myapplication_bin_LDADD=@GL_LIBS@<br />
The <strong>AC_SUBST</strong> tells autoconfig that a substitution should happen when building the Makefile (s). Hence<em>GL_LIBS</em> is expanded correctly. Of course, you probably want to do a much better check for your libs :)</p>
<h2><span class="mw-headline">Defining a #defining for use in C/C++ code</span></h2>
<p>In configure.ac</p>
<pre> AC_DEFINE([MYDEFINE],[SOMEVALUE],[Description: Make #define MYDEFINE SOMEVALUE])</pre>
<p>in config.h.in</p>
<pre> #undef MYDEFINE</pre>
<h2>Checking for C++ headers/C++ Libraries, not pkg-config supported</h2>
<pre>AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([boost/foreach.hpp])
AC_CHECK_LIBS([boost])
AC_LANG_POP([C++])
</pre>
<h2>Checking the size of a type</h2>
<pre>AC_CHECK_SIZEOF(uid_t)
if test $ac_cv_sizeof_uid_t = "4"; then
...
fi
</pre>
<h2>Checking the endianess of a platform</h2>
<p>﻿﻿﻿</p>
<pre>
AC_CHECK_HEADERS([endian.h],
 AC_TRY_COMPILE([#include &lt;endian.h&gt;], [switch (1) { case __LITTLE_ENDIAN: break; case __BYTE_ORDER: break; } ],[is_little_endian=0], [is_little_endian=1]),
 AC_MSG_ERR([Can't Determine Endianess])
)
if test $is_little_endian = 1 ; then
...
fi</pre>
<h1><span class="mw-headline">A Simple configure.ac</span></h1>
<p>For those that just want a quick start, below is a simple <strong>configure.ac</strong> file</p>
<pre>#
# A good reference for macros for this config file is at:
# http://sourceware.org/autobook/autobook/autobook_283.html

AC_PREREQ(2.50)

AC_INIT(PROJECTNAMEHERE, VERSIONHERE, EMAILADDRESSHERE)

# Define where autogenerated build files such as 'missing'
# should be located. This is also the location of any additional
# m4 macros that are required
AC_CONFIG_AUX_DIR(cfg)

#
# Init Automake subsystem
#
AM_INIT_AUTOMAKE(PROJECTNAMEHERE,VERSIONHERE)
AM_CONFIG_HEADER(config.h)

# Indicate this is a release build and that
# dependancies for changes between Makefile.am and Makefile.in
# should not be checked. This makes compiling faster. If you are working
# on the library, run: ./configure --enable-maintainer-mode to enable the dependancies
dnl AM_MAINTAINER_MODE

# Need the C++ Compiler, Installer and ranlib to strip libraries
#
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T

AC_CONFIG_FILES([Makefile])

AC_OUTPUT</pre>
<h1><span class="mw-headline">A Simple Makefile.am</span></h1>
<p>Here&#8217;s a simple Makefile.am that can be used in the root directory of a project</p>
<pre># Indicate this is not a GNU project and that
# missing files should be automatically created
AUTOMAKE_OPTIONS=foreign

# Instruct aclocal to check the cfg directory for
# extra macros
ACLOCAL_AMFLAGS=-I cfg

INCLUDES= -I@top_srcdir@

# Global C Flags
#AM_CFLAGS = 

#EXTRA_DIST=libwcl.pc

# Programs to build
bin_PROGRAMS = evaluateTablet

# Evaluate Table Application
evaluateTablet_includedir=@top_srcdir@
evaluateTablet_LDADD=-l
evaluateTablet_SOURCES=.....</pre>
<h1><span class="mw-headline">References</span></h1>
<ol class="references">
<li id="_note-0"><a href="http://www.clearchain.com/wiki/Autotools#_ref-0">↑</a> <a class="external free" title="http://www.gnu.org/software/automake/manual/html_node/Invoking-aclocal.html" rel="nofollow" href="http://www.gnu.org/software/automake/manual/html_node/Invoking-aclocal.html">http://www.gnu.org/software/automake/manual/html_node/Invoking-aclocal.html</a></li>
<li id="_note-1"><a href="http://www.clearchain.com/wiki/Autotools#_ref-1">↑</a> <a class="external free" title="http://www.gnu.org/software/autoconf/" rel="nofollow" href="http://www.gnu.org/software/autoconf/">http://www.gnu.org/software/autoconf/</a></li>
<li id="_note-2"><a href="http://www.clearchain.com/wiki/Autotools#_ref-2">↑</a> <a class="external free" title="http://www.gnu.org/software/automake/" rel="nofollow" href="http://www.gnu.org/software/automake/">http://www.gnu.org/software/automake/</a></li>
<li id="_note-3"><a href="http://www.clearchain.com/wiki/Autotools#_ref-3">↑</a> <a class="external free" title="http://www.gnu.org/software/autoconf/manual/autoconf-2.57/html_node/autoconf_29.html" rel="nofollow" href="http://www.gnu.org/software/autoconf/manual/html_node/index.html">http://www.gnu.org/software/autoconf/manual/autoconf-2.57/html_node/autoconf_29.html</a></li>
<li id="_note-4"><a href="http://www.clearchain.com/wiki/Autotools#_ref-4">↑</a> <a class="external free" title="http://www.gnu.org/software/libtool/" rel="nofollow" href="http://www.gnu.org/software/libtool/">http://www.gnu.org/software/libtool/</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.clearchain.com/blog/posts/autotools/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

