1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Building Bash 1.14.7 on a modern system — Luke Shumaker</title>
<link rel="stylesheet" href="assets/style.css">
<link rel="alternate" type="application/atom+xml" href="./index.atom" name="web log entries"/>
</head>
<body>
<header><a href="/">Luke Shumaker</a> » <a href=/blog>blog</a> » build-bash-1</header>
<article>
<h1 id="building-bash-1.14.7-on-a-modern-system">Building Bash 1.14.7 on a modern system</h1>
<p>In a previous revision of my <a href="./bash-arrays.html">Bash arrays post</a>, I wrote:</p>
<blockquote>
<p>Bash 1.x won't compile with modern GCC, so I couldn't verify how it behaves.</p>
</blockquote>
<p>I recall spending a little time fighting with it, but apparently I didn't try very hard: getting Bash 1.14.7 to build on a modern box is mostly just adjusting it to use <code>stdarg</code> instead of the no-longer-implemented <code>varargs</code>. There's also a little fiddling with the pre-autoconf automatic configuration.</p>
<h2 id="stdarg">stdarg</h2>
<p>Converting to <code>stdarg</code> is pretty simple: For each variadic function (functions that take a variable number of arguments), follow these steps:</p>
<ol type="1">
<li>Replace <code>#include <varargs.h></code> with <code>#include <stdarg.h></code></li>
<li>Replace <code>function_name (va_alist) va_dcl</code> with <code>function_name (char *format, ...)</code>.</li>
<li>Removing the declaration and assignment for <code>format</code> from the function body.</li>
<li>Replace <code>va_start (args);</code> with <code>va_start (args, format);</code> in the function bodies.</li>
<li>Replace <code>function_name ();</code> with <code>function_name (char *, ...)</code> in header files and/or at the top of C files.</li>
</ol>
<p>There's one function that uses the variable name <code>control</code> instead of <code>format</code>.</p>
<p>I've prepared <a href="./bash-1.14.7-gcc4-stdarg.patch">a patch</a> that does this.</p>
<h2 id="configuration">Configuration</h2>
<p>Instead of using autoconf-style tests to test for compiler and platform features, Bash 1 used the file <code>machines.h</code> that had <code>#ifdefs</code> and a huge database of of different operating systems for different platforms. It's gross. And quite likely won't handle your modern operating system.</p>
<p>I made these two small changes to <code>machines.h</code> to get it to work correctly on my box:</p>
<ol type="1">
<li>Replace <code>#if defined (i386)</code> with <code>#if defined (i386) || defined (__x86_64__)</code>. The purpose of this is obvious.</li>
<li>Add <code>#define USE_TERMCAP_EMULATION</code> to the section for Linux [sic] on i386 (<code># if !defined (done386) && (defined (__linux__) || defined (linux))</code>). What this does is tell it to link against libcurses to use curses termcap emulation, instead of linking against libtermcap (which doesn't exist on modern GNU/Linux systems).</li>
</ol>
<p>Again, I've prepared <a href="./bash-1.14.7-machines-config.patch">a patch</a> that does this.</p>
<h2 id="building">Building</h2>
<p>With those adjustments, it should build, but with quite a few warnings. Making a couple of changes to <code>CFLAGS</code> should fix that:</p>
<pre><code>make CFLAGS='-O -g -Werror -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-deprecated-declarations -include stdio.h -include stdlib.h -include string.h -Dexp2=bash_exp2'</code></pre>
<p>That's a doozy! Let's break it down:</p>
<ul>
<li><code>-O -g</code> The default value for CFLAGS (defined in <code>cpp-Makefile</code>)</li>
<li><code>-Werror</code> Treat warnings as errors; force us to deal with any issues.</li>
<li><code>-Wno-int-to-pointer-cast -Wno-pointer-to-int-cast</code> Allow casting between integers and pointers. Unfortunately, the way this version of Bash was designed requires this.</li>
<li><code>-Wno-deprecated-declarations</code> The <code>getwd</code> function in <code>unistd.h</code> is considered deprecated (use <code>getcwd</code> instead). However, if <code>getcwd</code> is available, Bash uses it's own <code>getwd</code> wrapper around <code>getcwd</code> (implemented in <code>general.c</code>), and only uses the signature from <code>unistd.h</code>, not the actuall implementation from libc.</li>
<li><code>-include stdio.h -include stdlib.h -include string.h</code> Several files are missing these header file includes. If not for <code>-Werror</code>, the default function signature fallbacks would work.</li>
<li><code>-Dexp2=bash_exp2</code> Avoid a conflict between the parser's <code>exp2</code> helper function and <code>math.h</code>'s base-2 exponential function.</li>
</ul>
<p>Have fun, software archaeologists!</p>
</article>
<footer>
<p>The content of this page is Copyright © 2015 <a href="mailto:lukeshu@sbcglobal.net">Luke Shumaker</a>.</p>
<p>This page is licensed under the <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA-3.0</a> license.</p>
</footer>
</body>
</html>
|