📄 install.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<link HREF="mailto:drh@cs.princeton.edu" REV="made" TITLE="David R. Hanson">
<title>Installing lcc</title>
</head>
<body>
<h1>Installing lcc</h1>
<p ALIGN="LEFT"><strong><a HREF="http://www.research.microsoft.com/~cwfraser/">Christopher
W. Fraser</a> and <a HREF="http://www.research.microsoft.com/~drh/">David R. Hanson</a>, <a
HREF="http://www.research.microsoft.com/">Microsoft Research</a></strong><br>
September 2002</p>
<h2>Contents</h2>
<dir>
<li><a HREF="#intro">Introduction</a></li>
<li><a HREF="#unix">Installation on UNIX</a></li>
<li><a HREF="#driver">Building the Driver</a></li>
<li><a HREF="#rcc">Building the Compiler and Accessories</a></li>
<li><a HREF="#win32">Installation on Windows</a></li>
<li><a HREF="#bugs">Reporting Bugs</a></li>
<li><a HREF="#mailinglist">Keeping in Touch</a></li>
</dir>
<h2><a NAME="intro">Introduction</a></h2>
<p><a HREF="http://www.cs.princeton.edu/software/lcc/">lcc</a> is the ANSI C compiler
described in our book <cite>A Retargetable C Compiler: Design and Implementation</cite>
(Addison-Wesley, 1995, ISBN 0-8053-1670-1).</p>
<p>If you're installing lcc on a UNIX system, read the remainder of this section and
continue with the next section. If you're installing lcc on a Windows system, you should read the rest of this section, the following three sections, and the <a
HREF="#win32">Windows</a> section.</p>
<p>Extract the distribution into its own directory. All non-absolute paths below are
relative to this directory. The distribution holds the following subdirectories.</p>
<blockquote>
<table BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="80%">
<tr>
<td><a HREF="../src"><code>src</code></a></td>
<td></td>
<td>source code</td>
</tr>
<tr>
<td><a HREF="../etc"><code>etc</code></a></td>
<td></td>
<td>driver, accessories</td>
</tr>
<tr>
<td><a HREF="../lib"><code>lib</code></a></td>
<td></td>
<td>runtime library source code</td>
</tr>
<tr>
<td><a HREF="../cpp"><code>cpp</code></a></td>
<td></td>
<td>preprocessor source code</td>
</tr>
<tr>
<td><a HREF="../lburg"><code>lburg</code></a></td>
<td></td>
<td>code-generator generator source code</td>
</tr>
<tr>
<td><a HREF="../doc"><code>doc</code></a></td>
<td></td>
<td>this document, man pages</td>
</tr>
<tr>
<td><code><a HREF="../include">include</a>/*/*</code></td>
<td></td>
<td>include files</td>
</tr>
<tr>
<td><a HREF="../tst"><code>tst</code></a></td>
<td></td>
<td>test suite</td>
</tr>
<tr>
<td><code><a HREF="../alpha">alpha</a>/*/tst</code></td>
<td></td>
<td>ALPHA test outputs</td>
</tr>
<tr>
<td><code><a HREF="../mips">mips</a>/*/tst</code></td>
<td></td>
<td>MIPS test outputs</td>
</tr>
<tr>
<td><code><a HREF="../sparc">sparc</a>/*/tst</code></td>
<td></td>
<td>SPARC test outputs</td>
</tr>
<tr>
<td><code><a HREF="../x86">x86</a>/*/tst</code></td>
<td></td>
<td>X86 test outputs</td>
</tr>
</table>
</blockquote>
<p><code>doc/install.html</code> is the HTML file for this document.</p>
<p>The installation makefile is designed so that lcc can be installed from a read-only
file system or directory, which is common in networked environments, so the distribution
can be unloaded on a central file server. <strong>You will need an existing ANSI/ISO C
compiler to build and install lcc.</strong></p>
<h2><a NAME="unix">Installation on UNIX</a></h2>
<p>The compilation components (the preprocessor, include files, and compiler proper, etc.)
are installed in a single <em>build directory</em>. On multi-platform systems supported by
a central file server, it's common to store the build directory in a location specific to
the platform and to the version of lcc, and to point a symbolic link to this location. For
example,</p>
<blockquote>
<pre>% ln -s $BUILDDIR/sparc-solaris /usr/local/lib/lcc</pre>
</blockquote>
<p>points <code>/usr/local/lib/lcc</code> to a build directory for lcc on the SPARC under Solaris. Links into <code>/usr/local/lib/lcc</code> are created for the programs <code>lcc</code>
and <code>bprint</code>. Thus, a new distribution can be installed by building it in its
own build directory and changing one symbolic link to point to that directory. If these
conventions or their equivalents are followed, the host-specific parts of the driver
program, <code>lcc</code>, can be used unmodified.</p>
<p>Installation on a UNIX system involves the following steps. Below, the build directory
is referred to as <code>BUILDDIR</code>, and the commands below are executed
from the distribution directory.<ol>
<li>Create the build directory, using a version- and platform-specific naming convention as
suggested above, and record the name of this directory in the <code>BUILDDIR</code>
environment variable:<blockquote>
<pre>% setenv BUILDDIR $BUILDDIR/sparc-solaris
% mkdir -p $BUILDDIR</pre>
</blockquote>
<p>Here and below, commands assume the C shell. Also, you'll need a version of <code>mkdir</code>
that supports the <code>-p</code> option, which creates intermediate directories as
necessary.</p>
</li>
<li>Copy the man pages to the repository for local man pages, e.g.,<blockquote>
<pre>% cp doc/*.1 /usr/local/man/man1</pre>
</blockquote>
<p>Some users copy the man pages to the build directory and create the appropriate
symbolic links, e.g., </p>
<blockquote>
<pre>% cp doc/*.1 $BUILDDIR
% ln -s $BUILDDIR/*.1 /usr/local/man/man1</pre>
</blockquote>
</li>
<li>Platform-specific include files are in directories named <code>include/</code><em>target</em><code>/</code><em>os</em>.
Create the include directory in the build directory, and copy the include hierarchy for
your platform to this directory, e.g.,<blockquote>
<pre>% mkdir $BUILDDIR/include
% cp -p -R include/sparc/solaris/* $BUILDDIR/include</pre>
</blockquote>
<p>Again, some users create a symbolic link to the appropriate directory in the
distribution instead of copying the include files. For example, at Princeton, the
distributions are stored under <code>/proj/pkg/lcc</code>, so the included files are
"installed" by creating one symbolic link: </p>
<blockquote>
<pre>% ln -s $BUILDDIR/include/sparc/solaris $BUILDDIR/include</pre>
</blockquote>
<p>If you're installing lcc on Linux, you <em>must</em> also plant a symbolic link named <code>gcc</code>
to gcc's library directory, because lcc uses gcc's C preprocessor and most of gcc's header
files:</p>
<blockquote>
<pre>% ln -s /usr/lib/gcc-lib/i386-redhat-linux/2.96 $BUILDDIR/gcc</pre>
</blockquote>
<p>The library directory shown above may be different on your Linux machine; to determine
the correct directory, browse <code>/usr/lib/gcc-lib</code>, or execute</p>
<blockquote>
<pre>% cc -v tst/8q.c</pre>
</blockquote>
<p>and examine the diagnostic output. Make sure that <code>$BUILDDIR/gcc/cpp0</code> and <code>$BUILDDIR/gcc/include</code>
are, respectively, gcc's C preprocessor and header files. On Linux, lcc looks for
include files in <code>$BUILDDIR/include</code>, <code>$BUILDDIR/gcc/include</code>, and <code>/usr/include</code>,
in that order; see <a HREF="#driver"><em>Building the Driver</em></a> and <a
href="../etc/linux.c"><code>etc/linux.c</code></a> for details.</p>
</li>
<li>The <a HREF="../makefile"><code>makefile</code></a> includes the file named by the <code>CUSTOM</code>
macro; the default is <code>custom.mk</code>, and an empty <code>custom.mk</code> is
included in the distribution. If desired, prepare a site-specification customization file
and define <code>CUSTOM</code> to the path of that file when invoking make in steps 5 and
6, e.g.,<blockquote>
<pre>make CUSTOM=<a href="http://www.cs.princeton.edu/software/lcc/pkg/solaris.mk">solaris.mk</a></pre>
</blockquote>
<p>You can, for example, use customization files to record site-specific values for macros
instead of using environment variables, and to record targets for the steps in this list.</p>
</li>
<li>Build the host-specific driver, creating a custom host-specific part, if necessary. See <a
HREF="#driver"><em>Building the Driver</em></a>.</li>
<li>Build the preprocessor, compiler proper, library, and other accessories. See <a
HREF="#rcc"><em>Building the Compiler</em></a>.</li>
<li>Plant symbolic links to the build directory and to the installed programs, e.g.,<blockquote>
<pre>% ln -s $BUILDDIR /usr/local/lib/lcc
% ln -s /usr/local/lib/{lcc,bprint} /usr/local/bin</pre>
</blockquote>
<p>Some users copy <code>bprint</code> and <code>lcc</code> into <code>/usr/local/bin</code>
instead of creating symbolic links. The advantage of creating the links for <code>lcc</code>
and <code>bprint</code> as shown is that, once established, they point indirectly to
whatever <code>/usr/local/lib/lcc</code> points to; installing a new version of lcc can be done by changing <code>/usr/local/lib/lcc</code> to point to the build
directory for the new version.</p>
</li>
</ol>
<h2><a NAME="driver">Building the Driver</a></h2>
<p>The preprocessor, compiler, assembler, and loader are invoked by a driver program, <code>lcc</code>,
which is similar to <code>cc</code> on most systems. It's described in the man page <code>doc/lcc.1</code>.
The driver is built by combining the host-independent part, <a href="../etc/lcc.c"><code>etc/lcc.c</code></a>,
with a small host-specific part. Distributed host-specific parts are named <code>etc/</code><em>os</em><code>.c</code>,
where <em>os</em> is the name of the operating system for the host on which <code>lcc</code>
is being installed. If you're following the installations conventions described above, you
can probably use one of the host-specific parts unmodified; otherwise, pick one that is
closely related to your platform, copy it to <em>whatever</em><code>.c</code>, and edit it
as described below. You should not have to edit <code>etc/lcc.c</code>.</p>
<p>We'll use <a HREF="../etc/solaris.c"><code>etc/solaris.c</code></a> as an example in
describing how the host-specific part works. This example illustrates all the important
features. Make sure you have the environment variable <code>BUILDDIR</code> set correctly,
and build the driver with a <code>make</code> command, e.g.,</p>
<blockquote>
<pre>% make HOSTFILE=etc/solaris.c lcc
cc -g -c -o $BUILDDIR/sparc-solaris/lcc.o etc/lcc.c
cc -g -c -o $BUILDDIR/sparc-solaris/host.o etc/solaris.c
cc -g -o $BUILDDIR/lcc $BUILDDIR/sparc-solaris/lcc.o $BUILDDIR/sparc-solaris/host.o</pre>
</blockquote>
<p>Of course, the actual value of <code>BUILDDIR</code> will appear in place of
<code>$BUILDDIR</code>. The symbolic name <code>HOSTFILE</code> specifies the path to the host-specific part,
either one in the distribution or <em>whatever</em><code>.c</code>. Some versions of make
may require the <code>-e</code> option in order to read the environment.</p>
<p>Here's <code>etc/solaris.c</code>:</p>
<blockquote>
<pre>/* Sparcs running Solaris 2.5.1 at CS Dept., Princeton University */
#include <string.h>
static char rcsid[] = "$ Id: solaris.c,v 1.10 1998/09/14 20:36:33 drh Exp $";
#ifndef LCCDIR
#define LCCDIR "/usr/local/lib/lcc/"
#endif
#ifndef SUNDIR
#define SUNDIR "/opt/SUNWspro/SC4.2/lib/"
#endif
char *suffixes[] = { ".c", ".i", ".s", ".o", ".out", 0 };
char inputs[256] = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -