summaryrefslogtreecommitdiff
path: root/public/build-bash-1.html
blob: 02206be7d5b7cc200376396ed380d6e898d01496 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Building Bash 1.14.7 on a modern system — Luke T. 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 T. 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 &lt;varargs.h&gt;</code> with
<code>#include &lt;stdarg.h&gt;</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) &amp;&amp; (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=&#39;-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&#39;</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>
  <aside class="sponsor"><p>I'd love it if you <a class="em"
      href="/sponsor/">sponsored me</a>.  It will allow me to continue
      my work on the GNU/Linux ecosystem.  Thanks!</p></aside>

<p>The content of this page is Copyright © 2015 <a href="mailto:lukeshu@lukeshu.com">Luke T. Shumaker</a>.</p>
<p>This page is licensed under the <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a> license.</p>
</footer>
</body>
</html>