Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | <html> |
| 2 | <head> |
||
| 3 | <title>Using Autoconf With Mktclapp</title> |
||
| 4 | </head> |
||
| 5 | <body bgcolor="white"> |
||
| 6 | <h1 align=center>Using Autoconf With Mktclapp</h1> |
||
| 7 | |||
| 8 | <p>This article describes one approach for using |
||
| 9 | <a href="http://www.gnu.ai.mit.edu/software/autoconf/autoconf.html">autoconf</a> |
||
| 10 | to generate configure scripts for projects that use |
||
| 11 | mktclapp. The configure scripts that are generated using this |
||
| 12 | approach have been tested to compile natively |
||
| 13 | on Linux, Windows95 (Cygwin20), SunOS, |
||
| 14 | and HPUX and to cross-compile from Linux to Windows95. The |
||
| 15 | configure script also supports using a build directory that |
||
| 16 | is completely independent of the source directory. The source |
||
| 17 | code can even be on a read-only filesystem, such as a CD-ROM.</p> |
||
| 18 | |||
| 19 | <p>This information is provided as a public service, with the hope |
||
| 20 | that it might be useful to someone. There is no warranty as to |
||
| 21 | how well this system works. Nor is there any promise of support.</p> |
||
| 22 | |||
| 23 | <h2>Overview</h2> |
||
| 24 | |||
| 25 | <img src="config.jpg" align=right> |
||
| 26 | |||
| 27 | <p>The image to the right gives an overview of how the scheme described |
||
| 28 | in this article works. |
||
| 29 | The developer must come up with two input files: |
||
| 30 | <b>configure.in</b> and <b>makemake.tcl.in</b>. The |
||
| 31 | first file, <b>configure.in</b> is the M4 script that autoconf |
||
| 32 | uses to generate its <b>configure</b> shell script. There |
||
| 33 | is a template <b>configure.in</b> file included with this |
||
| 34 | article that should work in most applications with |
||
| 35 | little or no modification. The <b>makemake.tcl.in</b> |
||
| 36 | is a TCL script that will be used to generate a |
||
| 37 | Makefile for the project. The <b>configure</b> script |
||
| 38 | will make a few modifications to this TCL script before |
||
| 39 | it runs, in order to customize it for the target platform. |
||
| 40 | A template <b>makemake.tcl.in</b> is also included with |
||
| 41 | this article.</p> |
||
| 42 | |||
| 43 | <p>After generating the <b>configure.in</b> file, the developer |
||
| 44 | then runs GNU Autoconf version 1.13 to generate a |
||
| 45 | <b>configure</b> shell script. The <b>configure</b> shell |
||
| 46 | script becomes part of the source tree. The <b>configure</b> |
||
| 47 | shell script is not considered a build product. It is placed |
||
| 48 | under configuration management just like any other source |
||
| 49 | file.</p> |
||
| 50 | |||
| 51 | <p>To build the project, the developer creates a new |
||
| 52 | directory that is separate from the source tree. |
||
| 53 | Suppose the source tree is rooted in a directory named |
||
| 54 | <b>src</b> which is a peer of the build directory which |
||
| 55 | is named <b>bld</b>. To build the project, the developer |
||
| 56 | changes to the <b>bld</b> directory and types:</p> |
||
| 57 | |||
| 58 | <blockquote><pre> |
||
| 59 | ../src/configure |
||
| 60 | </pre></blockquote> |
||
| 61 | |||
| 62 | <p>This command runs the configure script that autoconf |
||
| 63 | generated. The configure script examines the system on |
||
| 64 | which it is running, discovers an appropriate C compiler, |
||
| 65 | compiler options, |
||
| 66 | Tcl/Tk libraries, and BLT libraries, then generates |
||
| 67 | a <b>Makefile</b> and a file named <b>makemake.tcl</b> |
||
| 68 | based on <b>makemake.tcl.in</b>. All of these generated |
||
| 69 | files are in the build directory. (Notice that the |
||
| 70 | <b>Makefile</b> is built without a template <b>Makefile.in</b>. |
||
| 71 | This is a bit unusual for autoconf, but it is part of |
||
| 72 | the design. Read on...)<p> |
||
| 73 | |||
| 74 | <p>After the configure script is run, the developer |
||
| 75 | types:</p> |
||
| 76 | |||
| 77 | <blockquote><pre> |
||
| 78 | make |
||
| 79 | </pre></blockquote> |
||
| 80 | |||
| 81 | <p>This command launches the make utility on the <b>Makefile</b> |
||
| 82 | that the <b>configure</b> script generated. This <b>Makefile</b> |
||
| 83 | is very simple. About all it does is run <b>makemake.tcl</b> |
||
| 84 | to generate a new makefile called <b>all.mk</b>. The make |
||
| 85 | program then calls itself recursively on the newly generated |
||
| 86 | <b>all.mk</b> in order to build the project. Note that the |
||
| 87 | project is build in the local directory, not the source directory. |
||
| 88 | Note also that |
||
| 89 | any old version of the make utility will do. GNU make is |
||
| 90 | not required.</p> |
||
| 91 | |||
| 92 | <br clear=both> |
||
| 93 | <h2>Advantages To This Approach</h2> |
||
| 94 | |||
| 95 | <p>There are, of course, many ways to make use of autoconf. |
||
| 96 | And most other ways are more conventional that the scheme |
||
| 97 | described above. But this approach does have certain |
||
| 98 | advantages.</p> |
||
| 99 | |||
| 100 | <ul> |
||
| 101 | <li> |
||
| 102 | <p><b>The same source directory can be used to build for multiple |
||
| 103 | targets.</b></p> |
||
| 104 | |||
| 105 | <p>By putting the source tree on an NFS- or SMB-mounted filesystem, |
||
| 106 | lots of different computers can read the sources at the same time. |
||
| 107 | And they can all compile off of the same source tree, putting there |
||
| 108 | build products in separate directories. The separate builds can |
||
| 109 | even take place at the same time.</p></li> |
||
| 110 | |||
| 111 | <li> |
||
| 112 | <p><b>The source tree can be on a read-only filesystem.</b></p> |
||
| 113 | |||
| 114 | <p>This allows you to compile directly from a source tree |
||
| 115 | located on a CD-ROM, for example. There is no need to copy |
||
| 116 | the source tree onto read-write media prior to the build.</p></li> |
||
| 117 | |||
| 118 | <li> |
||
| 119 | <p><b>The use of "tclsh" in the build process gives much more |
||
| 120 | control to the developer.</b></p> |
||
| 121 | |||
| 122 | <p>A makefile is not a program. There are a lot of interesting |
||
| 123 | things that a makefile will not do. For example, standard makefiles |
||
| 124 | have no provisions for conditional compilation. (GNU make has |
||
| 125 | this capability, but GNU make is not standard and is not |
||
| 126 | installed on every system.) Running tclsh to generate the makefile |
||
| 127 | allows the developer to radically change the build process depending |
||
| 128 | on the characteristics of the target machine.</p></li> |
||
| 129 | </ul> |
||
| 130 | </p> |
||
| 131 | |||
| 132 | <h2>How To Adapt This Approach To Your Own Project</h2> |
||
| 133 | |||
| 134 | <p>If you want to try using the build scheme described here, |
||
| 135 | first get a copy of the <b>configure.in</b> template. You |
||
| 136 | can find the template at:</p> |
||
| 137 | |||
| 138 | <blockquote> |
||
| 139 | <a href="http://www.hwaci.com/sw/mktclapp/configure.in"> |
||
| 140 | http://www.hwaci.com/sw/mktclapp/configure.in |
||
| 141 | </a> |
||
| 142 | </blockquote> |
||
| 143 | |||
| 144 | <p>You will need to modify this file to suit your application. |
||
| 145 | But the modifications are normally modest. First change the |
||
| 146 | argument of the AC_INIT() macro to be the name of a file |
||
| 147 | in your project's source tree. If your project does not |
||
| 148 | use the BLT extension, then disable the tests for |
||
| 149 | BLT by commenting them out. |
||
| 150 | If your project uses some extensions other |
||
| 151 | than BLT, you may have to add new test to the <b>configure.in</b>. |
||
| 152 | Use the existing code as your guide.</p> |
||
| 153 | |||
| 154 | <p>The <b>configure.in</b> contains comments to help you understand |
||
| 155 | how it works. You may also want to refer to the Autoconf |
||
| 156 | manual for information on the Autoconf macros.</p> |
||
| 157 | |||
| 158 | <p>The next step is to generate a suitable <b>makemake.tcl.in</b>. |
||
| 159 | You can begin with the template at:</p> |
||
| 160 | |||
| 161 | <blockquote> |
||
| 162 | <a href="http://www.hwaci.com/sw/mktclapp/makemake.tcl.in"> |
||
| 163 | http://www.hwaci.com/sw/mktclapp/makemake.tcl.in |
||
| 164 | </a> |
||
| 165 | </blockquote> |
||
| 166 | |||
| 167 | <p>The template is really a working <b>makemake.tcl.in</b> file for |
||
| 168 | a specific project. The project is not Open-Source and so the |
||
| 169 | source code is not available. But that is not important. The |
||
| 170 | comments in the template file should give you plenty of guidance |
||
| 171 | on how to adapt the template to your particular project. Remember, |
||
| 172 | you are working with plain ordinary TCL code. The output of |
||
| 173 | the script will become a makefile. Be creative.</p> |
||
| 174 | |||
| 175 | <p>The final step is to run autoconf version 1.13 or later |
||
| 176 | to generate the <b>configure</b> script. You can obtain a |
||
| 177 | copy of autoconf from lots of places on the net. Use a |
||
| 178 | search engine to find one near you if you don't already have |
||
| 179 | autoconf installed on your machine.</p> |
||
| 180 | |||
| 181 | <h2>Parting Words</h2> |
||
| 182 | |||
| 183 | <p>For additional information, read the template files.</p> |
||
| 184 | |||
| 185 | <p>It is important to emphasize that there are many different |
||
| 186 | ways of building a project, and many different ways of using |
||
| 187 | autoconf. You are welcomed to use the approach outlined here |
||
| 188 | if it suits your needs. Hopefully you will find this information |
||
| 189 | helpful. But the techniques described here will not work in |
||
| 190 | every circumstance. You may have to change things. You may |
||
| 191 | have to use a completely different build scheme.</p> |
||
| 192 | |||
| 193 | <p>If you fix bugs or make extensions to the template files described above, |
||
| 194 | then patches sent to the author at |
||
| 195 | <a href="mailto:drh@hwaci.com">drh@hwaci.com</a> will be |
||
| 196 | welcomed. Your patches will be gratefully acknowledged and |
||
| 197 | added to the distribution. Reports of bugs without fixes, |
||
| 198 | or requests for new features, may or may not be acknowledged. |
||
| 199 | |||
| 200 | </body> |
||
| 201 | </html> |