<
h1 align=center>Using Autoconf With Mktclapp<
/h1>
<
p>This article describes one approach
for using
<
a href="http://www.gnu.ai.mit.edu/software/autoconf/autoconf.html">autoconf<
/a>
to generate configure scripts for projects that use
mktclapp. The configure scripts that are generated using this
approach have been tested to compile natively
on Linux, Windows95 (Cygwin20), SunOS,
and HPUX and to cross-compile from Linux to Windows95. The
configure script also supports using a build directory that
is completely independent of the source directory. The source
code can even be on a read-only filesystem, such as a CD-ROM.<
/p>
<
p>This information is provided as a public service, with the hope
that it might be useful to someone. There is no warranty as to
how well this system works. Nor is there any promise of support.<
/p>
<
img src="config.jpg" align=right>
<
p>The image to the right gives an overview of how the
scheme described
in this article works.
The developer must come up with two input files:
<
b>configure.in<
/b> and <
b>makemake.tcl.in<
/b>. The
first file, <
b>configure.in<
/b> is the M4 script that autoconf
uses to generate its <
b>configure<
/b> shell script. There
is a template <
b>configure.in<
/b> file included with this
article that should work in most applications with
little or no modification. The <
b>makemake.tcl.in<
/b>
is a TCL script that will be used to generate a
Makefile
for the project. The <
b>configure<
/b> script
will make a few modifications to this TCL script before
it runs, in order to customize it for the target platform.
A template <
b>makemake.tcl.in<
/b> is also included with
<
p>After generating the <
b>configure.in<
/b> file, the developer
then runs GNU Autoconf version 1.13 to generate a
<
b>configure<
/b> shell script. The <
b>configure<
/b> shell
script becomes part of the source tree. The <
b>configure<
/b>
shell script is not considered a build product. It is placed
under configuration management just like any other source
<
p>To build the project, the developer creates a new
directory that is separate from the source tree.
Suppose the source tree is rooted in a directory named
<
b>src<
/b> which is a peer of the build directory which
is named <
b>bld<
/b>. To build the project, the developer
changes to the <
b>bld<
/b> directory and types:<
/p>
../src/configure
<
p>This command runs the configure script that autoconf
generated. The configure script examines the system on
which it is running, discovers an appropriate C compiler,
compiler options,
Tcl/Tk libraries, and BLT libraries, then generates
a <
b>Makefile<
/b> and a file named <
b>makemake.tcl<
/b>
based on <
b>makemake.tcl.in<
/b>. All of these generated
files are in the build directory. (Notice that the
<
b>Makefile<
/b> is built without a template <
b>Makefile.in<
/b>.
This is a bit unusual for autoconf, but it is part of
the design. Read on...
)<
p>
<
p>After the configure script is run, the developer
make
<
p>This command launches the make utility on the <
b>Makefile<
/b>
that the <
b>configure<
/b> script generated. This <
b>Makefile<
/b>
is very simple. About all it does is run <
b>makemake.tcl<
/b>
to generate a new makefile called <
b>all.mk<
/b>. The make
program then calls itself recursively on the newly generated
<
b>all.mk<
/b> in order to build the project. Note that the
project is build in the local directory, not the source directory.
Note also that
any old version of the make utility will do. GNU make is
<
h2>Advantages To This Approach<
/h2>
<
p>There are, of course, many ways to make use of autoconf.
And most other ways are more conventional that the scheme
described above. But this approach does have certain
<
p><
b>The same source directory can be used to build
for multiple
<
p>By putting the source tree on an NFS- or SMB-mounted filesystem,
lots of different computers can read the sources at the same time.
And they can all compile off of the same source tree, putting there
build products in separate directories. The separate builds can
even take place at the same time.<
/p><
/li>
<
p><
b>The source tree can be on a read-only filesystem.<
/b><
/p>
<
p>This allows you to compile directly from a source tree
located on a CD-ROM, for example. There is no need to copy
the source tree onto read-write
media prior to the build.<
/p><
/li>
<
p><
b>The use of
"tclsh" in the build process gives much more
control to the developer.<
/b><
/p>
<
p>A makefile is not a program. There are a lot of interesting
things that a makefile will not do. For example, standard makefiles
have no provisions for conditional compilation. (GNU make has
this capability, but GNU make is not standard and is not
installed on every system.) Running tclsh to generate the makefile
allows the developer to radically change the build process depending
on the characteristics of the
target machine.<
/p><
/li>
<
h2>How To Adapt This Approach To Your Own Project<
/h2>
<
p>If you want to try using the build
scheme described here,
first get a copy of the <
b>configure.in<
/b> template. You
can find the template at:<
/p>
<
a href="http://www.hwaci.com/sw/mktclapp/configure.in">
http://www.hwaci.com/sw/mktclapp/configure.in
<
p>You will need to modify this file to suit your application.
But the modifications are normally modest. First change the
argument of the AC_INIT() macro to be the name of a file
in your project's source tree. If your project does not
use the BLT extension, then disable the tests for
BLT by commenting them out.
If your project uses some extensions other
than BLT, you may have to add new test to the <b>configure.in</b>.
Use the existing code as your guide.</p>
<p>The <b>configure.in</b> contains comments to help you understand
how it works. You may also want to refer to the Autoconf
manual for information on the Autoconf macros.</p>
<p>The next step is to generate a suitable <b>makemake.tcl.in</b>.
You can begin with the template at:</p>
<blockquote>
<a href="http://www.hwaci.com/sw/mktclapp/makemake.tcl.in">
http://www.hwaci.com/sw/mktclapp/makemake.tcl.in
</a>
</blockquote>
<p>The template is really a working <b>makemake.tcl.in</b> file for
a specific project. The project is not Open-Source and so the
source code is not available. But that is not important. The
comments in the template file should give you plenty of guidance
on how to adapt the template to your particular project. Remember,
you are working with plain ordinary TCL code. The output of
the script will become a makefile. Be creative.</p>
<p>The final step is to run autoconf version 1.13 or later
to generate the <b>configure</b> script. You can obtain a
copy of autoconf from lots of places on the net. Use a
search engine to find one near you if you don't already have
autoconf installed on your machine.<
/p>
<
p>
For additional information, read the template files.<
/p>
<
p>It is important to emphasize that there are many different
ways of building a project, and many different ways of using
autoconf. You are welcomed to use the approach outlined here
if it suits your needs. Hopefully you will find this information
helpful. But the techniques described here will not work in
every circumstance. You may have to change things. You may
have to use a completely different build
scheme.<
/p>
<
p>If you fix bugs or make extensions to the template files described above,
then patches sent to the author at
<
a href="mailto:drh@hwaci.com">drh@hwaci.com<
/a> will be
welcomed. Your patches will be gratefully acknowledged and
added to the distribution. Reports of bugs without fixes,
or requests for new features, may or may not be acknowledged.