| 1 | \input texinfo
|
|---|
| 2 | @c %**start of header
|
|---|
| 3 | @setfilename configure.info
|
|---|
| 4 | @settitle The GNU configure and build system
|
|---|
| 5 | @setchapternewpage off
|
|---|
| 6 | @c %**end of header
|
|---|
| 7 |
|
|---|
| 8 | @dircategory GNU admin
|
|---|
| 9 | @direntry
|
|---|
| 10 | * configure: (configure). The GNU configure and build system
|
|---|
| 11 | @end direntry
|
|---|
| 12 |
|
|---|
| 13 | @ifinfo
|
|---|
| 14 | This file documents the GNU configure and build system.
|
|---|
| 15 |
|
|---|
| 16 | Copyright (C) 1998 Cygnus Solutions.
|
|---|
| 17 |
|
|---|
| 18 | Permission is granted to make and distribute verbatim copies of
|
|---|
| 19 | this manual provided the copyright notice and this permission notice
|
|---|
| 20 | are preserved on all copies.
|
|---|
| 21 |
|
|---|
| 22 | @ignore
|
|---|
| 23 | Permission is granted to process this file through TeX and print the
|
|---|
| 24 | results, provided the printed document carries copying permission
|
|---|
| 25 | notice identical to this one except for the removal of this paragraph
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | @end ignore
|
|---|
| 29 | Permission is granted to copy and distribute modified versions of this
|
|---|
| 30 | manual under the conditions for verbatim copying, provided that the entire
|
|---|
| 31 | resulting derived work is distributed under the terms of a permission
|
|---|
| 32 | notice identical to this one.
|
|---|
| 33 |
|
|---|
| 34 | Permission is granted to copy and distribute translations of this manual
|
|---|
| 35 | into another language, under the above conditions for modified versions,
|
|---|
| 36 | except that this permission notice may be stated in a translation approved
|
|---|
| 37 | by the Foundation.
|
|---|
| 38 | @end ifinfo
|
|---|
| 39 |
|
|---|
| 40 | @titlepage
|
|---|
| 41 | @title The GNU configure and build system
|
|---|
| 42 | @author Ian Lance Taylor
|
|---|
| 43 |
|
|---|
| 44 | @page
|
|---|
| 45 | @vskip 0pt plus 1filll
|
|---|
| 46 | Copyright @copyright{} 1998 Cygnus Solutions
|
|---|
| 47 |
|
|---|
| 48 | Permission is granted to make and distribute verbatim copies of
|
|---|
| 49 | this manual provided the copyright notice and this permission notice
|
|---|
| 50 | are preserved on all copies.
|
|---|
| 51 |
|
|---|
| 52 | Permission is granted to copy and distribute modified versions of this
|
|---|
| 53 | manual under the conditions for verbatim copying, provided that the entire
|
|---|
| 54 | resulting derived work is distributed under the terms of a permission
|
|---|
| 55 | notice identical to this one.
|
|---|
| 56 |
|
|---|
| 57 | Permission is granted to copy and distribute translations of this manual
|
|---|
| 58 | into another language, under the above conditions for modified versions,
|
|---|
| 59 | except that this permission notice may be stated in a translation
|
|---|
| 60 | approved by the Free Software Foundation.
|
|---|
| 61 | @end titlepage
|
|---|
| 62 |
|
|---|
| 63 | @ifinfo
|
|---|
| 64 | @node Top
|
|---|
| 65 | @top GNU configure and build system
|
|---|
| 66 |
|
|---|
| 67 | The GNU configure and build system.
|
|---|
| 68 |
|
|---|
| 69 | @menu
|
|---|
| 70 | * Introduction:: Introduction.
|
|---|
| 71 | * Getting Started:: Getting Started.
|
|---|
| 72 | * Files:: Files.
|
|---|
| 73 | * Configuration Names:: Configuration Names.
|
|---|
| 74 | * Cross Compilation Tools:: Cross Compilation Tools.
|
|---|
| 75 | * Canadian Cross:: Canadian Cross.
|
|---|
| 76 | * Cygnus Configure:: Cygnus Configure.
|
|---|
| 77 | * Multilibs:: Multilibs.
|
|---|
| 78 | * FAQ:: Frequently Asked Questions.
|
|---|
| 79 | * Index:: Index.
|
|---|
| 80 | @end menu
|
|---|
| 81 |
|
|---|
| 82 | @end ifinfo
|
|---|
| 83 |
|
|---|
| 84 | @node Introduction
|
|---|
| 85 | @chapter Introduction
|
|---|
| 86 |
|
|---|
| 87 | This document describes the GNU configure and build systems. It
|
|---|
| 88 | describes how autoconf, automake, libtool, and make fit together. It
|
|---|
| 89 | also includes a discussion of the older Cygnus configure system.
|
|---|
| 90 |
|
|---|
| 91 | This document does not describe in detail how to use each of the tools;
|
|---|
| 92 | see the respective manuals for that. Instead, it describes which files
|
|---|
| 93 | the developer must write, which files are machine generated and how they
|
|---|
| 94 | are generated, and where certain common problems should be addressed.
|
|---|
| 95 |
|
|---|
| 96 | @ifnothtml
|
|---|
| 97 | This document draws on several sources, including the autoconf manual by
|
|---|
| 98 | David MacKenzie (@pxref{Top, , autoconf overview, autoconf, Autoconf}),
|
|---|
| 99 | the automake manual by David MacKenzie and Tom Tromey (@pxref{Top, ,
|
|---|
| 100 | automake overview, automake, GNU Automake}), the libtool manual by
|
|---|
| 101 | Gordon Matzigkeit (@pxref{Top, , libtool overview, libtool, GNU
|
|---|
| 102 | libtool}), and the Cygnus configure manual by K. Richard Pixley.
|
|---|
| 103 | @end ifnothtml
|
|---|
| 104 | @ifhtml
|
|---|
| 105 | This document draws on several sources, including
|
|---|
| 106 | @uref{http://www.delorie.com/gnu/docs/autoconf/autoconf_toc.html, the
|
|---|
| 107 | autoconf manual} by David MacKenzie,
|
|---|
| 108 | @uref{http://www.delorie.com/gnu/docs/automake/automake_toc.html, the
|
|---|
| 109 | automake manual} by David MacKenzie and Tom Tromey,
|
|---|
| 110 | @uref{http://www.delorie.com/gnu/docs/libtool/libtool_toc.html, the
|
|---|
| 111 | libtool manual} by Gordon Matzigkeit, and the Cygnus configure manual by
|
|---|
| 112 | K. Richard Pixley.
|
|---|
| 113 | @end ifhtml
|
|---|
| 114 |
|
|---|
| 115 | @menu
|
|---|
| 116 | * Goals:: Goals.
|
|---|
| 117 | * Tools:: The tools.
|
|---|
| 118 | * History:: History.
|
|---|
| 119 | * Building:: Building.
|
|---|
| 120 | @end menu
|
|---|
| 121 |
|
|---|
| 122 | @node Goals
|
|---|
| 123 | @section Goals
|
|---|
| 124 | @cindex goals
|
|---|
| 125 |
|
|---|
| 126 | The GNU configure and build system has two main goals.
|
|---|
| 127 |
|
|---|
| 128 | The first is to simplify the development of portable programs. The
|
|---|
| 129 | system permits the developer to concentrate on writing the program,
|
|---|
| 130 | simplifying many details of portability across Unix and even Windows
|
|---|
| 131 | systems, and permitting the developer to describe how to build the
|
|---|
| 132 | program using simple rules rather than complex Makefiles.
|
|---|
| 133 |
|
|---|
| 134 | The second is to simplify the building of programs distributed as source
|
|---|
| 135 | code. All programs are built using a simple, standardized, two step
|
|---|
| 136 | process. The program builder need not install any special tools in
|
|---|
| 137 | order to build the program.
|
|---|
| 138 |
|
|---|
| 139 | @node Tools
|
|---|
| 140 | @section Tools
|
|---|
| 141 |
|
|---|
| 142 | The GNU configure and build system is comprised of several different
|
|---|
| 143 | tools. Program developers must build and install all of these tools.
|
|---|
| 144 |
|
|---|
| 145 | People who just want to build programs from distributed sources normally
|
|---|
| 146 | do not need any special tools beyond a Unix shell, a make program, and a
|
|---|
| 147 | C compiler.
|
|---|
| 148 |
|
|---|
| 149 | @table @asis
|
|---|
| 150 | @item autoconf
|
|---|
| 151 | provides a general portability framework, based on testing the features
|
|---|
| 152 | of the host system at build time.
|
|---|
| 153 | @item automake
|
|---|
| 154 | a system for describing how to build a program, permitting the developer
|
|---|
| 155 | to write a simplified @file{Makefile}.
|
|---|
| 156 | @item libtool
|
|---|
| 157 | a standardized approach to building shared libraries.
|
|---|
| 158 | @item gettext
|
|---|
| 159 | provides a framework for translation of text messages into other
|
|---|
| 160 | languages; not really discussed in this document.
|
|---|
| 161 | @item m4
|
|---|
| 162 | autoconf requires the GNU version of m4; the standard Unix m4 does not
|
|---|
| 163 | suffice.
|
|---|
| 164 | @item perl
|
|---|
| 165 | automake requires perl.
|
|---|
| 166 | @end table
|
|---|
| 167 |
|
|---|
| 168 | @node History
|
|---|
| 169 | @section History
|
|---|
| 170 | @cindex history
|
|---|
| 171 |
|
|---|
| 172 | This is a very brief and probably inaccurate history.
|
|---|
| 173 |
|
|---|
| 174 | As the number of Unix variants increased during the 1980s, it became
|
|---|
| 175 | harder to write programs which could run on all variants. While it was
|
|---|
| 176 | often possible to use @code{#ifdef} to identify particular systems,
|
|---|
| 177 | developers frequently did not have access to every system, and the
|
|---|
| 178 | characteristics of some systems changed from version to version.
|
|---|
| 179 |
|
|---|
| 180 | By 1992, at least three different approaches had been developed:
|
|---|
| 181 | @itemize @bullet
|
|---|
| 182 | @item
|
|---|
| 183 | The Metaconfig program, by Larry Wall, Harlan Stenn, and Raphael
|
|---|
| 184 | Manfredi.
|
|---|
| 185 | @item
|
|---|
| 186 | The Cygnus configure script, by K. Richard Pixley, and the gcc configure
|
|---|
| 187 | script, by Richard Stallman. These use essentially the same approach,
|
|---|
| 188 | and the developers communicated regularly.
|
|---|
| 189 | @item
|
|---|
| 190 | The autoconf program, by David MacKenzie.
|
|---|
| 191 | @end itemize
|
|---|
| 192 |
|
|---|
| 193 | The Metaconfig program is still used for Perl and a few other programs.
|
|---|
| 194 | It is part of the Dist package. I do not know if it is being developed.
|
|---|
| 195 |
|
|---|
| 196 | In 1994, David MacKenzie and others modified autoconf to incorporate all
|
|---|
| 197 | the features of Cygnus configure. Since then, there has been a slow but
|
|---|
| 198 | steady conversion of GNU programs from Cygnus configure to autoconf. gcc
|
|---|
| 199 | has been converted, eliminating the gcc configure script.
|
|---|
| 200 |
|
|---|
| 201 | GNU autoconf was regularly maintained until late 1996. As of this
|
|---|
| 202 | writing in June, 1998, it has no public maintainer.
|
|---|
| 203 |
|
|---|
| 204 | Most programs are built using the make program, which requires the
|
|---|
| 205 | developer to write Makefiles describing how to build the programs.
|
|---|
| 206 | Since most programs are built in pretty much the same way, this led to a
|
|---|
| 207 | lot of duplication.
|
|---|
| 208 |
|
|---|
| 209 | The X Window system is built using the imake tool, which uses a database
|
|---|
| 210 | of rules to eliminate the duplication. However, building a tool which
|
|---|
| 211 | was developed using imake requires that the builder have imake
|
|---|
| 212 | installed, violating one of the goals of the GNU system.
|
|---|
| 213 |
|
|---|
| 214 | The new BSD make provides a standard library of Makefile fragments,
|
|---|
| 215 | which permits developers to write very simple Makefiles. However, this
|
|---|
| 216 | requires that the builder install the new BSD make program.
|
|---|
| 217 |
|
|---|
| 218 | In 1994, David MacKenzie wrote the first version of automake, which
|
|---|
| 219 | permitted writing a simple build description which was converted into a
|
|---|
| 220 | Makefile which could be used by the standard make program. In 1995, Tom
|
|---|
| 221 | Tromey completely rewrote automake in Perl, and he continues to enhance
|
|---|
| 222 | it.
|
|---|
| 223 |
|
|---|
| 224 | Various free packages built libraries, and by around 1995 several
|
|---|
| 225 | included support to build shared libraries on various platforms.
|
|---|
| 226 | However, there was no consistent approach. In early 1996, Gordon
|
|---|
| 227 | Matzigkeit began working on libtool, which provided a standardized
|
|---|
| 228 | approach to building shared libraries. This was integrated into
|
|---|
| 229 | automake from the start.
|
|---|
| 230 |
|
|---|
| 231 | The development of automake and libtool was driven by the GNITS project,
|
|---|
| 232 | a group of GNU maintainers who designed standardized tools to help meet
|
|---|
| 233 | the GNU coding standards.
|
|---|
| 234 |
|
|---|
| 235 | @node Building
|
|---|
| 236 | @section Building
|
|---|
| 237 |
|
|---|
| 238 | Most readers of this document should already know how to build a tool by
|
|---|
| 239 | running @samp{configure} and @samp{make}. This section may serve as a
|
|---|
| 240 | quick introduction or reminder.
|
|---|
| 241 |
|
|---|
| 242 | Building a tool is normally as simple as running @samp{configure}
|
|---|
| 243 | followed by @samp{make}. You should normally run @samp{configure} from
|
|---|
| 244 | an empty directory, using some path to refer to the @samp{configure}
|
|---|
| 245 | script in the source directory. The directory in which you run
|
|---|
| 246 | @samp{configure} is called the @dfn{object directory}.
|
|---|
| 247 |
|
|---|
| 248 | In order to use a object directory which is different from the source
|
|---|
| 249 | directory, you must be using the GNU version of @samp{make}, which has
|
|---|
| 250 | the required @samp{VPATH} support. Despite this restriction, using a
|
|---|
| 251 | different object directory is highly recommended:
|
|---|
| 252 | @itemize @bullet
|
|---|
| 253 | @item
|
|---|
| 254 | It keeps the files generated during the build from cluttering up your
|
|---|
| 255 | sources.
|
|---|
| 256 | @item
|
|---|
| 257 | It permits you to remove the built files by simply removing the entire
|
|---|
| 258 | build directory.
|
|---|
| 259 | @item
|
|---|
| 260 | It permits you to build from the same sources with several sets of
|
|---|
| 261 | configure options simultaneously.
|
|---|
| 262 | @end itemize
|
|---|
| 263 |
|
|---|
| 264 | If you don't have GNU @samp{make}, you will have to run @samp{configure}
|
|---|
| 265 | in the source directory. All GNU packages should support this; in
|
|---|
| 266 | particular, GNU packages should not assume the presence of GNU
|
|---|
| 267 | @samp{make}.
|
|---|
| 268 |
|
|---|
| 269 | After running @samp{configure}, you can build the tools by running
|
|---|
| 270 | @samp{make}.
|
|---|
| 271 |
|
|---|
| 272 | To install the tools, run @samp{make install}. Installing the tools
|
|---|
| 273 | will copy the programs and any required support files to the
|
|---|
| 274 | @dfn{installation directory}. The location of the installation
|
|---|
| 275 | directory is controlled by @samp{configure} options, as described below.
|
|---|
| 276 |
|
|---|
| 277 | In the Cygnus tree at present, the info files are built and installed as
|
|---|
| 278 | a separate step. To build them, run @samp{make info}. To install them,
|
|---|
| 279 | run @samp{make install-info}.
|
|---|
| 280 |
|
|---|
| 281 | All @samp{configure} scripts support a wide variety of options. The
|
|---|
| 282 | most interesting ones are @samp{--with} and @samp{--enable} options
|
|---|
| 283 | which are generally specific to particular tools. You can usually use
|
|---|
| 284 | the @samp{--help} option to get a list of interesting options for a
|
|---|
| 285 | particular configure script.
|
|---|
| 286 |
|
|---|
| 287 | The only generic options you are likely to use are the @samp{--prefix}
|
|---|
| 288 | and @samp{--exec-prefix} options. These options are used to specify the
|
|---|
| 289 | installation directory.
|
|---|
| 290 |
|
|---|
| 291 | The directory named by the @samp{--prefix} option will hold machine
|
|---|
| 292 | independent files such as info files.
|
|---|
| 293 |
|
|---|
| 294 | The directory named by the @samp{--exec-prefix} option, which is
|
|---|
| 295 | normally a subdirectory of the @samp{--prefix} directory, will hold
|
|---|
| 296 | machine dependent files such as executables.
|
|---|
| 297 |
|
|---|
| 298 | The default for @samp{--prefix} is @file{/usr/local}. The default for
|
|---|
| 299 | @samp{--exec-prefix} is the value used for @samp{--prefix}.
|
|---|
| 300 |
|
|---|
| 301 | The convention used in Cygnus releases is to use a @samp{--prefix}
|
|---|
| 302 | option of @file{/usr/cygnus/@var{release}}, where @var{release} is the
|
|---|
| 303 | name of the release, and to use a @samp{--exec-prefix} option of
|
|---|
| 304 | @file{/usr/cygnus/@var{release}/H-@var{host}}, where @var{host} is the
|
|---|
| 305 | configuration name of the host system (@pxref{Configuration Names}).
|
|---|
| 306 |
|
|---|
| 307 | Do not use either the source or the object directory as the installation
|
|---|
| 308 | directory. That will just lead to confusion.
|
|---|
| 309 |
|
|---|
| 310 | @node Getting Started
|
|---|
| 311 | @chapter Getting Started
|
|---|
| 312 |
|
|---|
| 313 | To start using the GNU configure and build system with your software
|
|---|
| 314 | package, you must write three files, and you must run some tools to
|
|---|
| 315 | manually generate additional files.
|
|---|
| 316 |
|
|---|
| 317 | @menu
|
|---|
| 318 | * Write configure.in:: Write configure.in.
|
|---|
| 319 | * Write Makefile.am:: Write Makefile.am.
|
|---|
| 320 | * Write acconfig.h:: Write acconfig.h.
|
|---|
| 321 | * Generate files:: Generate files.
|
|---|
| 322 | * Getting Started Example:: Example.
|
|---|
| 323 | @end menu
|
|---|
| 324 |
|
|---|
| 325 | @node Write configure.in
|
|---|
| 326 | @section Write configure.in
|
|---|
| 327 | @cindex @file{configure.in}, writing
|
|---|
| 328 |
|
|---|
| 329 | You must first write the file @file{configure.in}. This is an autoconf
|
|---|
| 330 | input file, and the autoconf manual describes in detail what this file
|
|---|
| 331 | should look like.
|
|---|
| 332 |
|
|---|
| 333 | You will write tests in your @file{configure.in} file to check for
|
|---|
| 334 | conditions that may change from one system to another, such as the
|
|---|
| 335 | presence of particular header files or functions.
|
|---|
| 336 |
|
|---|
| 337 | For example, not all systems support the @samp{gettimeofday} function.
|
|---|
| 338 | If you want to use the @samp{gettimeofday} function when it is
|
|---|
| 339 | available, and to use some other function when it is not, you would
|
|---|
| 340 | check for this by putting @samp{AC_CHECK_FUNCS(gettimeofday)} in
|
|---|
| 341 | @file{configure.in}.
|
|---|
| 342 |
|
|---|
| 343 | When the configure script is run at build time, this will arrange to
|
|---|
| 344 | define the preprocessor macro @samp{HAVE_GETTIMEOFDAY} to the value 1 if
|
|---|
| 345 | the @samp{gettimeofday} function is available, and to not define the
|
|---|
| 346 | macro at all if the function is not available. Your code can then use
|
|---|
| 347 | @samp{#ifdef} to test whether it is safe to call @samp{gettimeofday}.
|
|---|
| 348 |
|
|---|
| 349 | If you have an existing body of code, the @samp{autoscan} program may
|
|---|
| 350 | help identify potential portability problems, and hence configure tests
|
|---|
| 351 | that you will want to use.
|
|---|
| 352 | @ifnothtml
|
|---|
| 353 | @xref{Invoking autoscan, , , autoconf, the autoconf manual}.
|
|---|
| 354 | @end ifnothtml
|
|---|
| 355 | @ifhtml
|
|---|
| 356 | See @uref{http://www.delorie.com/gnu/docs/autoconf/autoconf_4.html, the
|
|---|
| 357 | autoscan documentation}.
|
|---|
| 358 | @end ifhtml
|
|---|
| 359 |
|
|---|
| 360 | Another handy tool for an existing body of code is @samp{ifnames}. This
|
|---|
| 361 | will show you all the preprocessor conditionals that the code already
|
|---|
| 362 | uses.
|
|---|
| 363 | @ifnothtml
|
|---|
| 364 | @xref{Invoking ifnames, , , autoconf, the autoconf manual}.
|
|---|
| 365 | @end ifnothtml
|
|---|
| 366 | @ifhtml
|
|---|
| 367 | See @uref{http://www.delorie.com/gnu/docs/autoconf/autoconf_5.html, the
|
|---|
| 368 | ifnames documentation}.
|
|---|
| 369 | @end ifhtml
|
|---|
| 370 |
|
|---|
| 371 | Besides the portability tests which are specific to your particular
|
|---|
| 372 | package, every @file{configure.in} file should contain the following
|
|---|
| 373 | macros.
|
|---|
| 374 |
|
|---|
| 375 | @table @samp
|
|---|
| 376 | @item AC_INIT
|
|---|
| 377 | @cindex @samp{AC_INIT}
|
|---|
| 378 | This macro takes a single argument, which is the name of a file in your
|
|---|
| 379 | package. For example, @samp{AC_INIT(foo.c)}.
|
|---|
| 380 |
|
|---|
| 381 | @item AC_PREREQ(@var{VERSION})
|
|---|
| 382 | @cindex @samp{AC_PREREQ}
|
|---|
| 383 | This macro is optional. It may be used to indicate the version of
|
|---|
| 384 | @samp{autoconf} that you are using. This will prevent users from
|
|---|
| 385 | running an earlier version of @samp{autoconf} and perhaps getting an
|
|---|
| 386 | invalid @file{configure} script. For example, @samp{AC_PREREQ(2.12)}.
|
|---|
| 387 |
|
|---|
| 388 | @item AM_INIT_AUTOMAKE
|
|---|
| 389 | @cindex @samp{AM_INIT_AUTOMAKE}
|
|---|
| 390 | This macro takes two arguments: the name of the package, and a version
|
|---|
| 391 | number. For example, @samp{AM_INIT_AUTOMAKE(foo, 1.0)}. (This macro is
|
|---|
| 392 | not needed if you are not using automake).
|
|---|
| 393 |
|
|---|
| 394 | @item AM_CONFIG_HEADER
|
|---|
| 395 | @cindex @samp{AM_CONFIG_HEADER}
|
|---|
| 396 | This macro names the header file which will hold the preprocessor macro
|
|---|
| 397 | definitions at run time. Normally this should be @file{config.h}. Your
|
|---|
| 398 | sources would then use @samp{#include "config.h"} to include it.
|
|---|
| 399 |
|
|---|
| 400 | This macro may optionally name the input file for that header file; by
|
|---|
| 401 | default, this is @file{config.h.in}, but that file name works poorly on
|
|---|
| 402 | DOS filesystems. Therefore, it is often better to name it explicitly as
|
|---|
| 403 | @file{config.in}.
|
|---|
| 404 |
|
|---|
| 405 | This is what you should normally put in @file{configure.in}:
|
|---|
| 406 | @example
|
|---|
| 407 | AM_CONFIG_HEADER(config.h:config.in)
|
|---|
| 408 | @end example
|
|---|
| 409 |
|
|---|
| 410 | @cindex @samp{AC_CONFIG_HEADER}
|
|---|
| 411 | (If you are not using automake, use @samp{AC_CONFIG_HEADER} rather than
|
|---|
| 412 | @samp{AM_CONFIG_HEADER}).
|
|---|
| 413 |
|
|---|
| 414 | @item AM_MAINTAINER_MODE
|
|---|
| 415 | @cindex @samp{AM_MAINTAINER_MODE}
|
|---|
| 416 | This macro always appears in Cygnus configure scripts. Other programs
|
|---|
| 417 | may or may not use it.
|
|---|
| 418 |
|
|---|
| 419 | If this macro is used, the @samp{--enable-maintainer-mode} option is
|
|---|
| 420 | required to enable automatic rebuilding of generated files used by the
|
|---|
| 421 | configure system. This of course requires that developers be aware of,
|
|---|
| 422 | and use, that option.
|
|---|
| 423 |
|
|---|
| 424 | If this macro is not used, then the generated files will always be
|
|---|
| 425 | rebuilt automatically. This will cause problems if the wrong versions
|
|---|
| 426 | of autoconf, automake, or others are in the builder's @samp{PATH}.
|
|---|
| 427 |
|
|---|
| 428 | (If you are not using automake, you do not need to use this macro).
|
|---|
| 429 |
|
|---|
| 430 | @item AC_EXEEXT
|
|---|
| 431 | @cindex @samp{AC_EXEEXT}
|
|---|
| 432 | @cindex @samp{AM_EXEEXT}
|
|---|
| 433 | Either this macro or @samp{AM_EXEEXT} always appears in Cygnus configure
|
|---|
| 434 | files. Other programs may or may not use one of them.
|
|---|
| 435 |
|
|---|
| 436 | This macro looks for the executable suffix used on the host system. On
|
|---|
| 437 | Unix systems, this is the empty string. On Windows systems, this is
|
|---|
| 438 | @samp{.exe}. This macro directs automake to use the executable suffix
|
|---|
| 439 | as appropriate when creating programs. This macro does not take any
|
|---|
| 440 | arguments.
|
|---|
| 441 |
|
|---|
| 442 | The @samp{AC_EXEEXT} form is new, and is part of a Cygnus patch to
|
|---|
| 443 | autoconf to support compiling with Visual C++. Older programs use
|
|---|
| 444 | @samp{AM_EXEEXT} instead.
|
|---|
| 445 |
|
|---|
| 446 | (Programs which do not use automake use neither @samp{AC_EXEEXT} nor
|
|---|
| 447 | @samp{AM_EXEEXT}).
|
|---|
| 448 |
|
|---|
| 449 | @item AC_PROG_CC
|
|---|
| 450 | @cindex @samp{AC_PROG_CC}
|
|---|
| 451 | If you are writing C code, you will normally want to use this macro. It
|
|---|
| 452 | locates the C compiler to use. It does not take any arguments.
|
|---|
| 453 |
|
|---|
| 454 | However, if this @file{configure.in} file is for a library which is to
|
|---|
| 455 | be compiled by a cross compiler which may not fully work, then you will
|
|---|
| 456 | not want to use @samp{AC_PROG_CC}. Instead, you will want to use a
|
|---|
| 457 | variant which does not call the macro @samp{AC_PROG_CC_WORKS}. Examples
|
|---|
| 458 | can be found in various @file{configure.in} files for libraries that are
|
|---|
| 459 | compiled with cross compilers, such as libiberty or libgloss. This is
|
|---|
| 460 | essentially a bug in autoconf, and there will probably be a better
|
|---|
| 461 | workaround at some point.
|
|---|
| 462 |
|
|---|
| 463 | @item AC_PROG_CXX
|
|---|
| 464 | @cindex @samp{AC_PROG_CXX}
|
|---|
| 465 | If you are writing C++ code, you will want to use this macro. It
|
|---|
| 466 | locates the C++ compiler to use. It does not take any arguments. The
|
|---|
| 467 | same cross compiler comments apply as for @samp{AC_PROG_CC}.
|
|---|
| 468 |
|
|---|
| 469 | @item AM_PROG_LIBTOOL
|
|---|
| 470 | @cindex @samp{AM_PROG_LIBTOOL}
|
|---|
| 471 | If you want to build libraries, and you want to permit them to be
|
|---|
| 472 | shared, or you want to link against libraries which were built using
|
|---|
| 473 | libtool, then you will need this macro. This macro is required in order
|
|---|
| 474 | to use libtool.
|
|---|
| 475 |
|
|---|
| 476 | @cindex @samp{AM_DISABLE_SHARED}
|
|---|
| 477 | By default, this will cause all libraries to be built as shared
|
|---|
| 478 | libraries. To prevent this--to change the default--use
|
|---|
| 479 | @samp{AM_DISABLE_SHARED} before @samp{AM_PROG_LIBTOOL}. The configure
|
|---|
| 480 | options @samp{--enable-shared} and @samp{--disable-shared} may be used
|
|---|
| 481 | to override the default at build time.
|
|---|
| 482 |
|
|---|
| 483 | @item AC_DEFINE(_GNU_SOURCE)
|
|---|
| 484 | @cindex @samp{_GNU_SOURCE}
|
|---|
| 485 | GNU packages should normally include this line before any other feature
|
|---|
| 486 | tests. This defines the macro @samp{_GNU_SOURCE} when compiling, which
|
|---|
| 487 | directs the libc header files to provide the standard GNU system
|
|---|
| 488 | interfaces including all GNU extensions. If this macro is not defined,
|
|---|
| 489 | certain GNU extensions may not be available.
|
|---|
| 490 |
|
|---|
| 491 | @item AC_OUTPUT
|
|---|
| 492 | @cindex @samp{AC_OUTPUT}
|
|---|
| 493 | This macro takes a list of file names which the configure process should
|
|---|
| 494 | produce. This is normally a list of one or more @file{Makefile} files
|
|---|
| 495 | in different directories. If your package lives entirely in a single
|
|---|
| 496 | directory, you would use simply @samp{AC_OUTPUT(Makefile)}. If you also
|
|---|
| 497 | have, for example, a @file{lib} subdirectory, you would use
|
|---|
| 498 | @samp{AC_OUTPUT(Makefile lib/Makefile)}.
|
|---|
| 499 | @end table
|
|---|
| 500 |
|
|---|
| 501 | If you want to use locally defined macros in your @file{configure.in}
|
|---|
| 502 | file, then you will need to write a @file{acinclude.m4} file which
|
|---|
| 503 | defines them (if not using automake, this file is called
|
|---|
| 504 | @file{aclocal.m4}). Alternatively, you can put separate macros in an
|
|---|
| 505 | @file{m4} subdirectory, and put @samp{ACLOCAL_AMFLAGS = -I m4} in your
|
|---|
| 506 | @file{Makefile.am} file so that the @samp{aclocal} program will be able
|
|---|
| 507 | to find them.
|
|---|
| 508 |
|
|---|
| 509 | The different macro prefixes indicate which tool defines the macro.
|
|---|
| 510 | Macros which start with @samp{AC_} are part of autoconf. Macros which
|
|---|
| 511 | start with @samp{AM_} are provided by automake or libtool.
|
|---|
| 512 |
|
|---|
| 513 | @node Write Makefile.am
|
|---|
| 514 | @section Write Makefile.am
|
|---|
| 515 | @cindex @file{Makefile.am}, writing
|
|---|
| 516 |
|
|---|
| 517 | You must write the file @file{Makefile.am}. This is an automake input
|
|---|
| 518 | file, and the automake manual describes in detail what this file should
|
|---|
| 519 | look like.
|
|---|
| 520 |
|
|---|
| 521 | The automake commands in @file{Makefile.am} mostly look like variable
|
|---|
| 522 | assignments in a @file{Makefile}. automake recognizes special variable
|
|---|
| 523 | names, and automatically add make rules to the output as needed.
|
|---|
| 524 |
|
|---|
| 525 | There will be one @file{Makefile.am} file for each directory in your
|
|---|
| 526 | package. For each directory with subdirectories, the @file{Makefile.am}
|
|---|
| 527 | file should contain the line
|
|---|
| 528 | @smallexample
|
|---|
| 529 | SUBDIRS = @var{dir} @var{dir} @dots{}
|
|---|
| 530 | @end smallexample
|
|---|
| 531 | @noindent
|
|---|
| 532 | where each @var{dir} is the name of a subdirectory.
|
|---|
| 533 |
|
|---|
| 534 | For each @file{Makefile.am}, there should be a corresponding
|
|---|
| 535 | @file{Makefile} in the @samp{AC_OUTPUT} macro in @file{configure.in}.
|
|---|
| 536 |
|
|---|
| 537 | Every @file{Makefile.am} written at Cygnus should contain the line
|
|---|
| 538 | @smallexample
|
|---|
| 539 | AUTOMAKE_OPTIONS = cygnus
|
|---|
| 540 | @end smallexample
|
|---|
| 541 | @noindent
|
|---|
| 542 | This puts automake into Cygnus mode. See the automake manual for
|
|---|
| 543 | details.
|
|---|
| 544 |
|
|---|
| 545 | You may to include the version number of @samp{automake} that you are
|
|---|
| 546 | using on the @samp{AUTOMAKE_OPTIONS} line. For example,
|
|---|
| 547 | @smallexample
|
|---|
| 548 | AUTOMAKE_OPTIONS = cygnus 1.3
|
|---|
| 549 | @end smallexample
|
|---|
| 550 | @noindent
|
|---|
| 551 | This will prevent users from running an earlier version of
|
|---|
| 552 | @samp{automake} and perhaps getting an invalid @file{Makefile.in}.
|
|---|
| 553 |
|
|---|
| 554 | If your package builds a program, then in the directory where that
|
|---|
| 555 | program is built you will normally want a line like
|
|---|
| 556 | @smallexample
|
|---|
| 557 | bin_PROGRAMS = @var{program}
|
|---|
| 558 | @end smallexample
|
|---|
| 559 | @noindent
|
|---|
| 560 | where @var{program} is the name of the program. You will then want a
|
|---|
| 561 | line like
|
|---|
| 562 | @smallexample
|
|---|
| 563 | @var{program}_SOURCES = @var{file} @var{file} @dots{}
|
|---|
| 564 | @end smallexample
|
|---|
| 565 | @noindent
|
|---|
| 566 | where each @var{file} is the name of a source file to link into the
|
|---|
| 567 | program (e.g., @samp{foo.c}).
|
|---|
| 568 |
|
|---|
| 569 | If your package builds a library, and you do not want the library to
|
|---|
| 570 | ever be built as a shared library, then in the directory where that
|
|---|
| 571 | library is built you will normally want a line like
|
|---|
| 572 | @smallexample
|
|---|
| 573 | lib_LIBRARIES = lib@var{name}.a
|
|---|
| 574 | @end smallexample
|
|---|
| 575 | @noindent
|
|---|
| 576 | where @samp{lib@var{name}.a} is the name of the library. You will then
|
|---|
| 577 | want a line like
|
|---|
| 578 | @smallexample
|
|---|
| 579 | lib@var{name}_a_SOURCES = @var{file} @var{file} @dots{}
|
|---|
| 580 | @end smallexample
|
|---|
| 581 | @noindent
|
|---|
| 582 | where each @var{file} is the name of a source file to add to the
|
|---|
| 583 | library.
|
|---|
| 584 |
|
|---|
| 585 | If your package builds a library, and you want to permit building the
|
|---|
| 586 | library as a shared library, then in the directory where that library is
|
|---|
| 587 | built you will normally want a line like
|
|---|
| 588 | @smallexample
|
|---|
| 589 | lib_LTLIBRARIES = lib@var{name}.la
|
|---|
| 590 | @end smallexample
|
|---|
| 591 | The use of @samp{LTLIBRARIES}, and the @samp{.la} extension, indicate a
|
|---|
| 592 | library to be built using libtool. As usual, you will then want a line
|
|---|
| 593 | like
|
|---|
| 594 | @smallexample
|
|---|
| 595 | lib@var{name}_la_SOURCES = @var{file} @var{file} @dots{}
|
|---|
| 596 | @end smallexample
|
|---|
| 597 |
|
|---|
| 598 | The strings @samp{bin} and @samp{lib} that appear above in
|
|---|
| 599 | @samp{bin_PROGRAMS} and @samp{lib_LIBRARIES} are not arbitrary. They
|
|---|
| 600 | refer to particular directories, which may be set by the @samp{--bindir}
|
|---|
| 601 | and @samp{--libdir} options to @file{configure}. If those options are
|
|---|
| 602 | not used, the default values are based on the @samp{--prefix} or
|
|---|
| 603 | @samp{--exec-prefix} options to @file{configure}. It is possible to use
|
|---|
| 604 | other names if the program or library should be installed in some other
|
|---|
| 605 | directory.
|
|---|
| 606 |
|
|---|
| 607 | The @file{Makefile.am} file may also contain almost anything that may
|
|---|
| 608 | appear in a normal @file{Makefile}. automake also supports many other
|
|---|
| 609 | special variables, as well as conditionals.
|
|---|
| 610 |
|
|---|
| 611 | See the automake manual for more information.
|
|---|
| 612 |
|
|---|
| 613 | @node Write acconfig.h
|
|---|
| 614 | @section Write acconfig.h
|
|---|
| 615 | @cindex @file{acconfig.h}, writing
|
|---|
| 616 |
|
|---|
| 617 | If you are generating a portability header file, (i.e., you are using
|
|---|
| 618 | @samp{AM_CONFIG_HEADER} in @file{configure.in}), then you will have to
|
|---|
| 619 | write a @file{acconfig.h} file. It will have to contain the following
|
|---|
| 620 | lines.
|
|---|
| 621 |
|
|---|
| 622 | @smallexample
|
|---|
| 623 | /* Name of package. */
|
|---|
| 624 | #undef PACKAGE
|
|---|
| 625 |
|
|---|
| 626 | /* Version of package. */
|
|---|
| 627 | #undef VERSION
|
|---|
| 628 | @end smallexample
|
|---|
| 629 |
|
|---|
| 630 | This requirement is really a bug in the system, and the requirement may
|
|---|
| 631 | be eliminated at some later date.
|
|---|
| 632 |
|
|---|
| 633 | The @file{acconfig.h} file will also similar comment and @samp{#undef}
|
|---|
| 634 | lines for any unusual macros in the @file{configure.in} file, including
|
|---|
| 635 | any macro which appears in a @samp{AC_DEFINE} macro.
|
|---|
| 636 |
|
|---|
| 637 | In particular, if you are writing a GNU package and therefore include
|
|---|
| 638 | @samp{AC_DEFINE(_GNU_SOURCE)} in @file{configure.in} as suggested above,
|
|---|
| 639 | you will need lines like this in @file{acconfig.h}:
|
|---|
| 640 | @smallexample
|
|---|
| 641 | /* Enable GNU extensions. */
|
|---|
| 642 | #undef _GNU_SOURCE
|
|---|
| 643 | @end smallexample
|
|---|
| 644 |
|
|---|
| 645 | Normally the @samp{autoheader} program will inform you of any such
|
|---|
| 646 | requirements by printing an error message when it is run. However, if
|
|---|
| 647 | you do anything particular odd in your @file{configure.in} file, you
|
|---|
| 648 | will have to make sure that the right entries appear in
|
|---|
| 649 | @file{acconfig.h}, since otherwise the results of the tests may not be
|
|---|
| 650 | available in the @file{config.h} file which your code will use.
|
|---|
| 651 |
|
|---|
| 652 | (Thee @samp{PACKAGE} and @samp{VERSION} lines are not required if you
|
|---|
| 653 | are not using automake, and in that case you may not need a
|
|---|
| 654 | @file{acconfig.h} file at all).
|
|---|
| 655 |
|
|---|
| 656 | @node Generate files
|
|---|
| 657 | @section Generate files
|
|---|
| 658 |
|
|---|
| 659 | Once you have written @file{configure.in}, @file{Makefile.am},
|
|---|
| 660 | @file{acconfig.h}, and possibly @file{acinclude.m4}, you must use
|
|---|
| 661 | autoconf and automake programs to produce the first versions of the
|
|---|
| 662 | generated files. This is done by executing the following sequence of
|
|---|
| 663 | commands.
|
|---|
| 664 |
|
|---|
| 665 | @smallexample
|
|---|
| 666 | aclocal
|
|---|
| 667 | autoconf
|
|---|
| 668 | autoheader
|
|---|
| 669 | automake
|
|---|
| 670 | @end smallexample
|
|---|
| 671 |
|
|---|
| 672 | The @samp{aclocal} and @samp{automake} commands are part of the automake
|
|---|
| 673 | package, and the @samp{autoconf} and @samp{autoheader} commands are part
|
|---|
| 674 | of the autoconf package.
|
|---|
| 675 |
|
|---|
| 676 | If you are using a @file{m4} subdirectory for your macros, you will need
|
|---|
| 677 | to use the @samp{-I m4} option when you run @samp{aclocal}.
|
|---|
| 678 |
|
|---|
| 679 | If you are not using the Cygnus tree, use the @samp{-a} option when
|
|---|
| 680 | running @samp{automake} command in order to copy the required support
|
|---|
| 681 | files into your source directory.
|
|---|
| 682 |
|
|---|
| 683 | If you are using libtool, you must build and install the libtool package
|
|---|
| 684 | with the same @samp{--prefix} and @samp{--exec-prefix} options as you
|
|---|
| 685 | used with the autoconf and automake packages. You must do this before
|
|---|
| 686 | running any of the above commands. If you are not using the Cygnus
|
|---|
| 687 | tree, you will need to run the @samp{libtoolize} program to copy the
|
|---|
| 688 | libtool support files into your directory.
|
|---|
| 689 |
|
|---|
| 690 | Once you have managed to run these commands without getting any errors,
|
|---|
| 691 | you should create a new empty directory, and run the @samp{configure}
|
|---|
| 692 | script which will have been created by @samp{autoconf} with the
|
|---|
| 693 | @samp{--enable-maintainer-mode} option. This will give you a set of
|
|---|
| 694 | Makefiles which will include rules to automatically rebuild all the
|
|---|
| 695 | generated files.
|
|---|
| 696 |
|
|---|
| 697 | After doing that, whenever you have changed some of the input files and
|
|---|
| 698 | want to regenerated the other files, go to your object directory and run
|
|---|
| 699 | @samp{make}. Doing this is more reliable than trying to rebuild the
|
|---|
| 700 | files manually, because there are complex order dependencies and it is
|
|---|
| 701 | easy to forget something.
|
|---|
| 702 |
|
|---|
| 703 | @node Getting Started Example
|
|---|
| 704 | @section Example
|
|---|
| 705 |
|
|---|
| 706 | Let's consider a trivial example.
|
|---|
| 707 |
|
|---|
| 708 | Suppose we want to write a simple version of @samp{touch}. Our program,
|
|---|
| 709 | which we will call @samp{poke}, will take a single file name argument,
|
|---|
| 710 | and use the @samp{utime} system call to set the modification and access
|
|---|
| 711 | times of the file to the current time. We want this program to be
|
|---|
| 712 | highly portable.
|
|---|
| 713 |
|
|---|
| 714 | We'll first see what this looks like without using autoconf and
|
|---|
| 715 | automake, and then see what it looks like with them.
|
|---|
| 716 |
|
|---|
| 717 | @menu
|
|---|
| 718 | * Getting Started Example 1:: First Try.
|
|---|
| 719 | * Getting Started Example 2:: Second Try.
|
|---|
| 720 | * Getting Started Example 3:: Third Try.
|
|---|
| 721 | * Generate Files in Example:: Generate Files.
|
|---|
| 722 | @end menu
|
|---|
| 723 |
|
|---|
| 724 | @node Getting Started Example 1
|
|---|
| 725 | @subsection First Try
|
|---|
| 726 |
|
|---|
| 727 | Here is our first try at @samp{poke.c}. Note that we've written it
|
|---|
| 728 | without ANSI/ISO C prototypes, since we want it to be highly portable.
|
|---|
| 729 |
|
|---|
| 730 | @example
|
|---|
| 731 | #include <stdio.h>
|
|---|
| 732 | #include <stdlib.h>
|
|---|
| 733 | #include <sys/types.h>
|
|---|
| 734 | #include <utime.h>
|
|---|
| 735 |
|
|---|
| 736 | int
|
|---|
| 737 | main (argc, argv)
|
|---|
| 738 | int argc;
|
|---|
| 739 | char **argv;
|
|---|
| 740 | @{
|
|---|
| 741 | if (argc != 2)
|
|---|
| 742 | @{
|
|---|
| 743 | fprintf (stderr, "Usage: poke file\n");
|
|---|
| 744 | exit (1);
|
|---|
| 745 | @}
|
|---|
| 746 |
|
|---|
| 747 | if (utime (argv[1], NULL) < 0)
|
|---|
| 748 | @{
|
|---|
| 749 | perror ("utime");
|
|---|
| 750 | exit (1);
|
|---|
| 751 | @}
|
|---|
| 752 |
|
|---|
| 753 | exit (0);
|
|---|
| 754 | @}
|
|---|
| 755 | @end example
|
|---|
| 756 |
|
|---|
| 757 | We also write a simple @file{Makefile}.
|
|---|
| 758 |
|
|---|
| 759 | @example
|
|---|
| 760 | CC = gcc
|
|---|
| 761 | CFLAGS = -g -O2
|
|---|
| 762 |
|
|---|
| 763 | all: poke
|
|---|
| 764 |
|
|---|
| 765 | poke: poke.o
|
|---|
| 766 | $(CC) -o poke $(CFLAGS) $(LDFLAGS) poke.o
|
|---|
| 767 | @end example
|
|---|
| 768 |
|
|---|
| 769 | So far, so good.
|
|---|
| 770 |
|
|---|
| 771 | Unfortunately, there are a few problems.
|
|---|
| 772 |
|
|---|
| 773 | On older Unix systems derived from BSD 4.3, the @samp{utime} system call
|
|---|
| 774 | does not accept a second argument of @samp{NULL}. On those systems, we
|
|---|
| 775 | need to pass a pointer to @samp{struct utimbuf} structure.
|
|---|
| 776 | Unfortunately, even older systems don't define that structure; on those
|
|---|
| 777 | systems, we need to pass an array of two @samp{long} values.
|
|---|
| 778 |
|
|---|
| 779 | The header file @file{stdlib.h} was invented by ANSI C, and older
|
|---|
| 780 | systems don't have a copy. We included it above to get a declaration of
|
|---|
| 781 | @samp{exit}.
|
|---|
| 782 |
|
|---|
| 783 | We can find some of these portability problems by running
|
|---|
| 784 | @samp{autoscan}, which will create a @file{configure.scan} file which we
|
|---|
| 785 | can use as a prototype for our @file{configure.in} file. I won't show
|
|---|
| 786 | the output, but it will notice the potential problems with @samp{utime}
|
|---|
| 787 | and @file{stdlib.h}.
|
|---|
| 788 |
|
|---|
| 789 | In our @file{Makefile}, we don't provide any way to install the program.
|
|---|
| 790 | This doesn't matter much for such a simple example, but a real program
|
|---|
| 791 | will need an @samp{install} target. For that matter, we will also want
|
|---|
| 792 | a @samp{clean} target.
|
|---|
| 793 |
|
|---|
| 794 | @node Getting Started Example 2
|
|---|
| 795 | @subsection Second Try
|
|---|
| 796 |
|
|---|
| 797 | Here is our second try at this program.
|
|---|
| 798 |
|
|---|
| 799 | We modify @file{poke.c} to use preprocessor macros to control what
|
|---|
| 800 | features are available. (I've cheated a bit by using the same macro
|
|---|
| 801 | names which autoconf will use).
|
|---|
| 802 |
|
|---|
| 803 | @example
|
|---|
| 804 | #include <stdio.h>
|
|---|
| 805 |
|
|---|
| 806 | #ifdef STDC_HEADERS
|
|---|
| 807 | #include <stdlib.h>
|
|---|
| 808 | #endif
|
|---|
| 809 |
|
|---|
| 810 | #include <sys/types.h>
|
|---|
| 811 |
|
|---|
| 812 | #ifdef HAVE_UTIME_H
|
|---|
| 813 | #include <utime.h>
|
|---|
| 814 | #endif
|
|---|
| 815 |
|
|---|
| 816 | #ifndef HAVE_UTIME_NULL
|
|---|
| 817 |
|
|---|
| 818 | #include <time.h>
|
|---|
| 819 |
|
|---|
| 820 | #ifndef HAVE_STRUCT_UTIMBUF
|
|---|
| 821 |
|
|---|
| 822 | struct utimbuf
|
|---|
| 823 | @{
|
|---|
| 824 | long actime;
|
|---|
| 825 | long modtime;
|
|---|
| 826 | @};
|
|---|
| 827 |
|
|---|
| 828 | #endif
|
|---|
| 829 |
|
|---|
| 830 | static int
|
|---|
| 831 | utime_now (file)
|
|---|
| 832 | char *file;
|
|---|
| 833 | @{
|
|---|
| 834 | struct utimbuf now;
|
|---|
| 835 |
|
|---|
| 836 | now.actime = now.modtime = time (NULL);
|
|---|
| 837 | return utime (file, &now);
|
|---|
| 838 | @}
|
|---|
| 839 |
|
|---|
| 840 | #define utime(f, p) utime_now (f)
|
|---|
| 841 |
|
|---|
| 842 | #endif /* HAVE_UTIME_NULL */
|
|---|
| 843 |
|
|---|
| 844 | int
|
|---|
| 845 | main (argc, argv)
|
|---|
| 846 | int argc;
|
|---|
| 847 | char **argv;
|
|---|
| 848 | @{
|
|---|
| 849 | if (argc != 2)
|
|---|
| 850 | @{
|
|---|
| 851 | fprintf (stderr, "Usage: poke file\n");
|
|---|
| 852 | exit (1);
|
|---|
| 853 | @}
|
|---|
| 854 |
|
|---|
| 855 | if (utime (argv[1], NULL) < 0)
|
|---|
| 856 | @{
|
|---|
| 857 | perror ("utime");
|
|---|
| 858 | exit (1);
|
|---|
| 859 | @}
|
|---|
| 860 |
|
|---|
| 861 | exit (0);
|
|---|
| 862 | @}
|
|---|
| 863 | @end example
|
|---|
| 864 |
|
|---|
| 865 | Here is the associated @file{Makefile}. We've added support for the
|
|---|
| 866 | preprocessor flags we use. We've also added @samp{install} and
|
|---|
| 867 | @samp{clean} targets.
|
|---|
| 868 |
|
|---|
| 869 | @example
|
|---|
| 870 | # Set this to your installation directory.
|
|---|
| 871 | bindir = /usr/local/bin
|
|---|
| 872 |
|
|---|
| 873 | # Uncomment this if you have the standard ANSI/ISO C header files.
|
|---|
| 874 | # STDC_HDRS = -DSTDC_HEADERS
|
|---|
| 875 |
|
|---|
| 876 | # Uncomment this if you have utime.h.
|
|---|
| 877 | # UTIME_H = -DHAVE_UTIME_H
|
|---|
| 878 |
|
|---|
| 879 | # Uncomment this if utime (FILE, NULL) works on your system.
|
|---|
| 880 | # UTIME_NULL = -DHAVE_UTIME_NULL
|
|---|
| 881 |
|
|---|
| 882 | # Uncomment this if struct utimbuf is defined in utime.h.
|
|---|
| 883 | # UTIMBUF = -DHAVE_STRUCT_UTIMBUF
|
|---|
| 884 |
|
|---|
| 885 | CC = gcc
|
|---|
| 886 | CFLAGS = -g -O2
|
|---|
| 887 |
|
|---|
| 888 | ALL_CFLAGS = $(STDC_HDRS) $(UTIME_H) $(UTIME_NULL) $(UTIMBUF) $(CFLAGS)
|
|---|
| 889 |
|
|---|
| 890 | all: poke
|
|---|
| 891 |
|
|---|
| 892 | poke: poke.o
|
|---|
| 893 | $(CC) -o poke $(ALL_CFLAGS) $(LDFLAGS) poke.o
|
|---|
| 894 |
|
|---|
| 895 | .c.o:
|
|---|
| 896 | $(CC) -c $(ALL_CFLAGS) poke.c
|
|---|
| 897 |
|
|---|
| 898 | install: poke
|
|---|
| 899 | cp poke $(bindir)/poke
|
|---|
| 900 |
|
|---|
| 901 | clean:
|
|---|
| 902 | rm poke poke.o
|
|---|
| 903 | @end example
|
|---|
| 904 |
|
|---|
| 905 | Some problems with this approach should be clear.
|
|---|
| 906 |
|
|---|
| 907 | Users who want to compile poke will have to know how @samp{utime} works
|
|---|
| 908 | on their systems, so that they can uncomment the @file{Makefile}
|
|---|
| 909 | correctly.
|
|---|
| 910 |
|
|---|
| 911 | The installation is done using @samp{cp}, but many systems have an
|
|---|
| 912 | @samp{install} program which may be used, and which supports optional
|
|---|
| 913 | features such as stripping debugging information out of the installed
|
|---|
| 914 | binary.
|
|---|
| 915 |
|
|---|
| 916 | The use of @file{Makefile} variables like @samp{CC}, @samp{CFLAGS} and
|
|---|
| 917 | @samp{LDFLAGS} follows the requirements of the GNU standards. This is
|
|---|
| 918 | convenient for all packages, since it reduces surprises for users.
|
|---|
| 919 | However, it is easy to get the details wrong, and wind up with a
|
|---|
| 920 | slightly nonstandard distribution.
|
|---|
| 921 |
|
|---|
| 922 | @node Getting Started Example 3
|
|---|
| 923 | @subsection Third Try
|
|---|
| 924 |
|
|---|
| 925 | For our third try at this program, we will write a @file{configure.in}
|
|---|
| 926 | script to discover the configuration features on the host system, rather
|
|---|
| 927 | than requiring the user to edit the @file{Makefile}. We will also write
|
|---|
| 928 | a @file{Makefile.am} rather than a @file{Makefile}.
|
|---|
| 929 |
|
|---|
| 930 | The only change to @file{poke.c} is to add a line at the start of the
|
|---|
| 931 | file:
|
|---|
| 932 | @smallexample
|
|---|
| 933 | #include "config.h"
|
|---|
| 934 | @end smallexample
|
|---|
| 935 |
|
|---|
| 936 | The new @file{configure.in} file is as follows.
|
|---|
| 937 |
|
|---|
| 938 | @example
|
|---|
| 939 | AC_INIT(poke.c)
|
|---|
| 940 | AM_INIT_AUTOMAKE(poke, 1.0)
|
|---|
| 941 | AM_CONFIG_HEADER(config.h:config.in)
|
|---|
| 942 | AC_PROG_CC
|
|---|
| 943 | AC_HEADER_STDC
|
|---|
| 944 | AC_CHECK_HEADERS(utime.h)
|
|---|
| 945 | AC_EGREP_HEADER(utimbuf, utime.h, AC_DEFINE(HAVE_STRUCT_UTIMBUF))
|
|---|
| 946 | AC_FUNC_UTIME_NULL
|
|---|
| 947 | AC_OUTPUT(Makefile)
|
|---|
| 948 | @end example
|
|---|
| 949 |
|
|---|
| 950 | The first four macros in this file, and the last one, were described
|
|---|
| 951 | above; see @ref{Write configure.in}. If we omit these macros, then when
|
|---|
| 952 | we run @samp{automake} we will get a reminder that we need them.
|
|---|
| 953 |
|
|---|
| 954 | The other macros are standard autoconf macros.
|
|---|
| 955 |
|
|---|
| 956 | @table @samp
|
|---|
| 957 | @item AC_HEADER_STDC
|
|---|
| 958 | Check for standard C headers.
|
|---|
| 959 | @item AC_CHECK_HEADERS
|
|---|
| 960 | Check whether a particular header file exists.
|
|---|
| 961 | @item AC_EGREP_HEADER
|
|---|
| 962 | Check for a particular string in a particular header file, in this case
|
|---|
| 963 | checking for @samp{utimbuf} in @file{utime.h}.
|
|---|
| 964 | @item AC_FUNC_UTIME_NULL
|
|---|
| 965 | Check whether @samp{utime} accepts a NULL second argument to set the
|
|---|
| 966 | file change time to the current time.
|
|---|
| 967 | @end table
|
|---|
| 968 |
|
|---|
| 969 | See the autoconf manual for a more complete description.
|
|---|
| 970 |
|
|---|
| 971 | The new @file{Makefile.am} file is as follows. Note how simple this is
|
|---|
| 972 | compared to our earlier @file{Makefile}.
|
|---|
| 973 |
|
|---|
| 974 | @example
|
|---|
| 975 | bin_PROGRAMS = poke
|
|---|
| 976 |
|
|---|
| 977 | poke_SOURCES = poke.c
|
|---|
| 978 | @end example
|
|---|
| 979 |
|
|---|
| 980 | This means that we should build a single program name @samp{poke}. It
|
|---|
| 981 | should be installed in the binary directory, which we called
|
|---|
| 982 | @samp{bindir} earlier. The program @samp{poke} is built from the source
|
|---|
| 983 | file @file{poke.c}.
|
|---|
| 984 |
|
|---|
| 985 | We must also write a @file{acconfig.h} file. Besides @samp{PACKAGE} and
|
|---|
| 986 | @samp{VERSION}, which must be mentioned for all packages which use
|
|---|
| 987 | automake, we must include @samp{HAVE_STRUCT_UTIMBUF}, since we mentioned
|
|---|
| 988 | it in an @samp{AC_DEFINE}.
|
|---|
| 989 |
|
|---|
| 990 | @example
|
|---|
| 991 | /* Name of package. */
|
|---|
| 992 | #undef PACKAGE
|
|---|
| 993 |
|
|---|
| 994 | /* Version of package. */
|
|---|
| 995 | #undef VERSION
|
|---|
| 996 |
|
|---|
| 997 | /* Whether utime.h defines struct utimbuf. */
|
|---|
| 998 | #undef HAVE_STRUCT_UTIMBUF
|
|---|
| 999 | @end example
|
|---|
| 1000 |
|
|---|
| 1001 | @node Generate Files in Example
|
|---|
| 1002 | @subsection Generate Files
|
|---|
| 1003 |
|
|---|
| 1004 | We must now generate the other files, using the following commands.
|
|---|
| 1005 |
|
|---|
| 1006 | @smallexample
|
|---|
| 1007 | aclocal
|
|---|
| 1008 | autoconf
|
|---|
| 1009 | autoheader
|
|---|
| 1010 | automake
|
|---|
| 1011 | @end smallexample
|
|---|
| 1012 |
|
|---|
| 1013 | When we run @samp{autoheader}, it will remind us of any macros we forgot
|
|---|
| 1014 | to add to @file{acconfig.h}.
|
|---|
| 1015 |
|
|---|
| 1016 | When we run @samp{automake}, it will want to add some files to our
|
|---|
| 1017 | distribution. It will add them automatically if we use the
|
|---|
| 1018 | @samp{--add-missing} option.
|
|---|
| 1019 |
|
|---|
| 1020 | By default, @samp{automake} will run in GNU mode, which means that it
|
|---|
| 1021 | will want us to create certain additional files; as of this writing, it
|
|---|
| 1022 | will want @file{NEWS}, @file{README}, @file{AUTHORS}, and
|
|---|
| 1023 | @file{ChangeLog}, all of which are files which should appear in a
|
|---|
| 1024 | standard GNU distribution. We can either add those files, or run
|
|---|
| 1025 | @samp{automake} with the @samp{--foreign} option.
|
|---|
| 1026 |
|
|---|
| 1027 | Running these tools will generate the following files, all of which are
|
|---|
| 1028 | described in the next chapter.
|
|---|
| 1029 |
|
|---|
| 1030 | @itemize @bullet
|
|---|
| 1031 | @item
|
|---|
| 1032 | @file{aclocal.m4}
|
|---|
| 1033 | @item
|
|---|
| 1034 | @file{configure}
|
|---|
| 1035 | @item
|
|---|
| 1036 | @file{config.in}
|
|---|
| 1037 | @item
|
|---|
| 1038 | @file{Makefile.in}
|
|---|
| 1039 | @item
|
|---|
| 1040 | @file{stamp-h.in}
|
|---|
| 1041 | @end itemize
|
|---|
| 1042 |
|
|---|
| 1043 | @node Files
|
|---|
| 1044 | @chapter Files
|
|---|
| 1045 |
|
|---|
| 1046 | As was seen in the previous chapter, the GNU configure and build system
|
|---|
| 1047 | uses a number of different files. The developer must write a few files.
|
|---|
| 1048 | The others are generated by various tools.
|
|---|
| 1049 |
|
|---|
| 1050 | The system is rather flexible, and can be used in many different ways.
|
|---|
| 1051 | In describing the files that it uses, I will describe the common case,
|
|---|
| 1052 | and mention some other cases that may arise.
|
|---|
| 1053 |
|
|---|
| 1054 | @menu
|
|---|
| 1055 | * Developer Files:: Developer Files.
|
|---|
| 1056 | * Build Files:: Build Files.
|
|---|
| 1057 | * Support Files:: Support Files.
|
|---|
| 1058 | @end menu
|
|---|
| 1059 |
|
|---|
| 1060 | @node Developer Files
|
|---|
| 1061 | @section Developer Files
|
|---|
| 1062 |
|
|---|
| 1063 | This section describes the files written or generated by the developer
|
|---|
| 1064 | of a package.
|
|---|
| 1065 |
|
|---|
| 1066 | @menu
|
|---|
| 1067 | * Developer Files Picture:: Developer Files Picture.
|
|---|
| 1068 | * Written Developer Files:: Written Developer Files.
|
|---|
| 1069 | * Generated Developer Files:: Generated Developer Files.
|
|---|
| 1070 | @end menu
|
|---|
| 1071 |
|
|---|
| 1072 | @node Developer Files Picture
|
|---|
| 1073 | @subsection Developer Files Picture
|
|---|
| 1074 |
|
|---|
| 1075 | Here is a picture of the files which are written by the developer, the
|
|---|
| 1076 | generated files which would be included with a complete source
|
|---|
| 1077 | distribution, and the tools which create those files.
|
|---|
| 1078 | @ifinfo
|
|---|
| 1079 | The file names are plain text and the tool names are enclosed by
|
|---|
| 1080 | @samp{*} characters
|
|---|
| 1081 | @end ifinfo
|
|---|
| 1082 | @ifnotinfo
|
|---|
| 1083 | The file names are in rectangles with square corners and the tool names
|
|---|
| 1084 | are in rectangles with rounded corners
|
|---|
| 1085 | @end ifnotinfo
|
|---|
| 1086 | (e.g., @samp{autoheader} is the name of a tool, not the name of a file).
|
|---|
| 1087 |
|
|---|
| 1088 | @image{configdev}
|
|---|
| 1089 |
|
|---|
| 1090 | @node Written Developer Files
|
|---|
| 1091 | @subsection Written Developer Files
|
|---|
| 1092 |
|
|---|
| 1093 | The following files would be written by the developer.
|
|---|
| 1094 |
|
|---|
| 1095 | @table @file
|
|---|
| 1096 | @item configure.in
|
|---|
| 1097 | @cindex @file{configure.in}
|
|---|
| 1098 | This is the configuration script. This script contains invocations of
|
|---|
| 1099 | autoconf macros. It may also contain ordinary shell script code. This
|
|---|
| 1100 | file will contain feature tests for portability issues. The last thing
|
|---|
| 1101 | in the file will normally be an @samp{AC_OUTPUT} macro listing which
|
|---|
| 1102 | files to create when the builder runs the configure script. This file
|
|---|
| 1103 | is always required when using the GNU configure system. @xref{Write
|
|---|
| 1104 | configure.in}.
|
|---|
| 1105 |
|
|---|
| 1106 | @item Makefile.am
|
|---|
| 1107 | @cindex @file{Makefile.am}
|
|---|
| 1108 | This is the automake input file. It describes how the code should be
|
|---|
| 1109 | built. It consists of definitions of automake variables. It may also
|
|---|
| 1110 | contain ordinary Makefile targets. This file is only needed when using
|
|---|
| 1111 | automake (newer tools normally use automake, but there are still older
|
|---|
| 1112 | tools which have not been converted, in which the developer writes
|
|---|
| 1113 | @file{Makefile.in} directly). @xref{Write Makefile.am}.
|
|---|
| 1114 |
|
|---|
| 1115 | @item acconfig.h
|
|---|
| 1116 | @cindex @file{acconfig.h}
|
|---|
| 1117 | When the configure script creates a portability header file, by using
|
|---|
| 1118 | @samp{AM_CONFIG_HEADER} (or, if not using automake,
|
|---|
| 1119 | @samp{AC_CONFIG_HEADER}), this file is used to describe macros which are
|
|---|
| 1120 | not recognized by the @samp{autoheader} command. This is normally a
|
|---|
| 1121 | fairly uninteresting file, consisting of a collection of @samp{#undef}
|
|---|
| 1122 | lines with comments. Normally any call to @samp{AC_DEFINE} in
|
|---|
| 1123 | @file{configure.in} will require a line in this file. @xref{Write
|
|---|
| 1124 | acconfig.h}.
|
|---|
| 1125 |
|
|---|
| 1126 | @item acinclude.m4
|
|---|
| 1127 | @cindex @file{acinclude.m4}
|
|---|
| 1128 | This file is not always required. It defines local autoconf macros.
|
|---|
| 1129 | These macros may then be used in @file{configure.in}. If you don't need
|
|---|
| 1130 | any local autoconf macros, then you don't need this file at all. In
|
|---|
| 1131 | fact, in general, you never need local autoconf macros, since you can
|
|---|
| 1132 | put everything in @file{configure.in}, but sometimes a local macro is
|
|---|
| 1133 | convenient.
|
|---|
| 1134 |
|
|---|
| 1135 | Newer tools may omit @file{acinclude.m4}, and instead use a
|
|---|
| 1136 | subdirectory, typically named @file{m4}, and define
|
|---|
| 1137 | @samp{ACLOCAL_AMFLAGS = -I m4} in @file{Makefile.am} to force
|
|---|
| 1138 | @samp{aclocal} to look there for macro definitions. The macro
|
|---|
| 1139 | definitions are then placed in separate files in that directory.
|
|---|
| 1140 |
|
|---|
| 1141 | The @file{acinclude.m4} file is only used when using automake; in older
|
|---|
| 1142 | tools, the developer writes @file{aclocal.m4} directly, if it is needed.
|
|---|
| 1143 | @end table
|
|---|
| 1144 |
|
|---|
| 1145 | @node Generated Developer Files
|
|---|
| 1146 | @subsection Generated Developer Files
|
|---|
| 1147 |
|
|---|
| 1148 | The following files would be generated by the developer.
|
|---|
| 1149 |
|
|---|
| 1150 | When using automake, these files are normally not generated manually
|
|---|
| 1151 | after the first time. Instead, the generated @file{Makefile} contains
|
|---|
| 1152 | rules to automatically rebuild the files as required. When
|
|---|
| 1153 | @samp{AM_MAINTAINER_MODE} is used in @file{configure.in} (the normal
|
|---|
| 1154 | case in Cygnus code), the automatic rebuilding rules will only be
|
|---|
| 1155 | defined if you configure using the @samp{--enable-maintainer-mode}
|
|---|
| 1156 | option.
|
|---|
| 1157 |
|
|---|
| 1158 | When using automatic rebuilding, it is important to ensure that all the
|
|---|
| 1159 | various tools have been built and installed on your @samp{PATH}. Using
|
|---|
| 1160 | automatic rebuilding is highly recommended, so much so that I'm not
|
|---|
| 1161 | going to explain what you have to do if you don't use it.
|
|---|
| 1162 |
|
|---|
| 1163 | @table @file
|
|---|
| 1164 | @item configure
|
|---|
| 1165 | @cindex @file{configure}
|
|---|
| 1166 | This is the configure script which will be run when building the
|
|---|
| 1167 | package. This is generated by @samp{autoconf} from @file{configure.in}
|
|---|
| 1168 | and @file{aclocal.m4}. This is a shell script.
|
|---|
| 1169 |
|
|---|
| 1170 | @item Makefile.in
|
|---|
| 1171 | @cindex @file{Makefile.in}
|
|---|
| 1172 | This is the file which the configure script will turn into the
|
|---|
| 1173 | @file{Makefile} at build time. This file is generated by
|
|---|
| 1174 | @samp{automake} from @file{Makefile.am}. If you aren't using automake,
|
|---|
| 1175 | you must write this file yourself. This file is pretty much a normal
|
|---|
| 1176 | @file{Makefile}, with some configure substitutions for certain
|
|---|
| 1177 | variables.
|
|---|
| 1178 |
|
|---|
| 1179 | @item aclocal.m4
|
|---|
| 1180 | @cindex @file{aclocal.m4}
|
|---|
| 1181 | This file is created by the @samp{aclocal} program, based on the
|
|---|
| 1182 | contents of @file{configure.in} and @file{acinclude.m4} (or, as noted in
|
|---|
| 1183 | the description of @file{acinclude.m4} above, on the contents of an
|
|---|
| 1184 | @file{m4} subdirectory). This file contains definitions of autoconf
|
|---|
| 1185 | macros which @samp{autoconf} will use when generating the file
|
|---|
| 1186 | @file{configure}. These autoconf macros may be defined by you in
|
|---|
| 1187 | @file{acinclude.m4} or they may be defined by other packages such as
|
|---|
| 1188 | automake, libtool or gettext. If you aren't using automake, you will
|
|---|
| 1189 | normally write this file yourself; in that case, if @file{configure.in}
|
|---|
| 1190 | uses only standard autoconf macros, this file will not be needed at all.
|
|---|
| 1191 |
|
|---|
| 1192 | @item config.in
|
|---|
| 1193 | @cindex @file{config.in}
|
|---|
| 1194 | @cindex @file{config.h.in}
|
|---|
| 1195 | This file is created by @samp{autoheader} based on @file{acconfig.h} and
|
|---|
| 1196 | @file{configure.in}. At build time, the configure script will define
|
|---|
| 1197 | some of the macros in it to create @file{config.h}, which may then be
|
|---|
| 1198 | included by your program. This permits your C code to use preprocessor
|
|---|
| 1199 | conditionals to change its behaviour based on the characteristics of the
|
|---|
| 1200 | host system. This file may also be called @file{config.h.in}.
|
|---|
| 1201 |
|
|---|
| 1202 | @item stamp.h-in
|
|---|
| 1203 | @cindex @file{stamp-h.in}
|
|---|
| 1204 | This rather uninteresting file, which I omitted from the picture, is
|
|---|
| 1205 | generated by @samp{automake}. It always contains the string
|
|---|
| 1206 | @samp{timestamp}. It is used as a timestamp file indicating whether
|
|---|
| 1207 | @file{config.in} is up to date. Using a timestamp file means that
|
|---|
| 1208 | @file{config.in} can be marked as up to date without actually changing
|
|---|
| 1209 | its modification time. This is useful since @file{config.in} depends
|
|---|
| 1210 | upon @file{configure.in}, but it is easy to change @file{configure.in}
|
|---|
| 1211 | in a way which does not affect @file{config.in}.
|
|---|
| 1212 | @end table
|
|---|
| 1213 |
|
|---|
| 1214 | @node Build Files
|
|---|
| 1215 | @section Build Files
|
|---|
| 1216 |
|
|---|
| 1217 | This section describes the files which are created at configure and
|
|---|
| 1218 | build time. These are the files which somebody who builds the package
|
|---|
| 1219 | will see.
|
|---|
| 1220 |
|
|---|
| 1221 | Of course, the developer will also build the package. The distinction
|
|---|
| 1222 | between developer files and build files is not that the developer does
|
|---|
| 1223 | not see the build files, but that somebody who only builds the package
|
|---|
| 1224 | does not have to worry about the developer files.
|
|---|
| 1225 |
|
|---|
| 1226 | @menu
|
|---|
| 1227 | * Build Files Picture:: Build Files Picture.
|
|---|
| 1228 | * Build Files Description:: Build Files Description.
|
|---|
| 1229 | @end menu
|
|---|
| 1230 |
|
|---|
| 1231 | @node Build Files Picture
|
|---|
| 1232 | @subsection Build Files Picture
|
|---|
| 1233 |
|
|---|
| 1234 | Here is a picture of the files which will be created at build time.
|
|---|
| 1235 | @file{config.status} is both a created file and a shell script which is
|
|---|
| 1236 | run to create other files, and the picture attempts to show that.
|
|---|
| 1237 |
|
|---|
| 1238 | @image{configbuild}
|
|---|
| 1239 |
|
|---|
| 1240 | @node Build Files Description
|
|---|
| 1241 | @subsection Build Files Description
|
|---|
| 1242 |
|
|---|
| 1243 | This is a description of the files which are created at build time.
|
|---|
| 1244 |
|
|---|
| 1245 | @table @file
|
|---|
| 1246 | @item config.status
|
|---|
| 1247 | @cindex @file{config.status}
|
|---|
| 1248 | The first step in building a package is to run the @file{configure}
|
|---|
| 1249 | script. The @file{configure} script will create the file
|
|---|
| 1250 | @file{config.status}, which is itself a shell script. When you first
|
|---|
| 1251 | run @file{configure}, it will automatically run @file{config.status}.
|
|---|
| 1252 | An @file{Makefile} derived from an automake generated @file{Makefile.in}
|
|---|
| 1253 | will contain rules to automatically run @file{config.status} again when
|
|---|
| 1254 | necessary to recreate certain files if their inputs change.
|
|---|
| 1255 |
|
|---|
| 1256 | @item Makefile
|
|---|
| 1257 | @cindex @file{Makefile}
|
|---|
| 1258 | This is the file which make will read to build the program. The
|
|---|
| 1259 | @file{config.status} script will transform @file{Makefile.in} into
|
|---|
| 1260 | @file{Makefile}.
|
|---|
| 1261 |
|
|---|
| 1262 | @item config.h
|
|---|
| 1263 | @cindex @file{config.h}
|
|---|
| 1264 | This file defines C preprocessor macros which C code can use to adjust
|
|---|
| 1265 | its behaviour on different systems. The @file{config.status} script
|
|---|
| 1266 | will transform @file{config.in} into @file{config.h}.
|
|---|
| 1267 |
|
|---|
| 1268 | @item config.cache
|
|---|
| 1269 | @cindex @file{config.cache}
|
|---|
| 1270 | This file did not fit neatly into the picture, and I omitted it. It is
|
|---|
| 1271 | used by the @file{configure} script to cache results between runs. This
|
|---|
| 1272 | can be an important speedup. If you modify @file{configure.in} in such
|
|---|
| 1273 | a way that the results of old tests should change (perhaps you have
|
|---|
| 1274 | added a new library to @samp{LDFLAGS}), then you will have to remove
|
|---|
| 1275 | @file{config.cache} to force the tests to be rerun.
|
|---|
| 1276 |
|
|---|
| 1277 | The autoconf manual explains how to set up a site specific cache file.
|
|---|
| 1278 | This can speed up running @file{configure} scripts on your system.
|
|---|
| 1279 |
|
|---|
| 1280 | @item stamp.h
|
|---|
| 1281 | @cindex @file{stamp-h}
|
|---|
| 1282 | This file, which I omitted from the picture, is similar to
|
|---|
| 1283 | @file{stamp-h.in}. It is used as a timestamp file indicating whether
|
|---|
| 1284 | @file{config.h} is up to date. This is useful since @file{config.h}
|
|---|
| 1285 | depends upon @file{config.status}, but it is easy for
|
|---|
| 1286 | @file{config.status} to change in a way which does not affect
|
|---|
| 1287 | @file{config.h}.
|
|---|
| 1288 | @end table
|
|---|
| 1289 |
|
|---|
| 1290 | @node Support Files
|
|---|
| 1291 | @section Support Files
|
|---|
| 1292 |
|
|---|
| 1293 | The GNU configure and build system requires several support files to be
|
|---|
| 1294 | included with your distribution. You do not normally need to concern
|
|---|
| 1295 | yourself with these. If you are using the Cygnus tree, most are already
|
|---|
| 1296 | present. Otherwise, they will be installed with your source by
|
|---|
| 1297 | @samp{automake} (with the @samp{--add-missing} option) and
|
|---|
| 1298 | @samp{libtoolize}.
|
|---|
| 1299 |
|
|---|
| 1300 | You don't have to put the support files in the top level directory. You
|
|---|
| 1301 | can put them in a subdirectory, and use the @samp{AC_CONFIG_AUX_DIR}
|
|---|
| 1302 | macro in @file{configure.in} to tell @samp{automake} and the
|
|---|
| 1303 | @file{configure} script where they are.
|
|---|
| 1304 |
|
|---|
| 1305 | In this section, I describe the support files, so that you can know what
|
|---|
| 1306 | they are and why they are there.
|
|---|
| 1307 |
|
|---|
| 1308 | @table @file
|
|---|
| 1309 | @item ABOUT-NLS
|
|---|
| 1310 | Added by automake if you are using gettext. This is a documentation
|
|---|
| 1311 | file about the gettext project.
|
|---|
| 1312 | @item ansi2knr.c
|
|---|
| 1313 | Used by an automake generated @file{Makefile} if you put @samp{ansi2knr}
|
|---|
| 1314 | in @samp{AUTOMAKE_OPTIONS} in @file{Makefile.am}. This permits
|
|---|
| 1315 | compiling ANSI C code with a K&R C compiler.
|
|---|
| 1316 | @item ansi2knr.1
|
|---|
| 1317 | The man page which goes with @file{ansi2knr.c}.
|
|---|
| 1318 | @item config.guess
|
|---|
| 1319 | A shell script which determines the configuration name for the system on
|
|---|
| 1320 | which it is run.
|
|---|
| 1321 | @item config.sub
|
|---|
| 1322 | A shell script which canonicalizes a configuration name entered by a
|
|---|
| 1323 | user.
|
|---|
| 1324 | @item elisp-comp
|
|---|
| 1325 | Used to compile Emacs LISP files.
|
|---|
| 1326 | @item install-sh
|
|---|
| 1327 | A shell script which installs a program. This is used if the configure
|
|---|
| 1328 | script can not find an install binary.
|
|---|
| 1329 | @item ltconfig
|
|---|
| 1330 | Used by libtool. This is a shell script which configures libtool for
|
|---|
| 1331 | the particular system on which it is used.
|
|---|
| 1332 | @item ltmain.sh
|
|---|
| 1333 | Used by libtool. This is the actual libtool script which is used, after
|
|---|
| 1334 | it is configured by @file{ltconfig} to build a library.
|
|---|
| 1335 | @item mdate-sh
|
|---|
| 1336 | A shell script used by an automake generated @file{Makefile} to pretty
|
|---|
| 1337 | print the modification time of a file. This is used to maintain version
|
|---|
| 1338 | numbers for texinfo files.
|
|---|
| 1339 | @item missing
|
|---|
| 1340 | A shell script used if some tool is missing entirely. This is used by
|
|---|
| 1341 | an automake generated @file{Makefile} to avoid certain sorts of
|
|---|
| 1342 | timestamp problems.
|
|---|
| 1343 | @item mkinstalldirs
|
|---|
| 1344 | A shell script which creates a directory, including all parent
|
|---|
| 1345 | directories. This is used by an automake generated @file{Makefile}
|
|---|
| 1346 | during installation.
|
|---|
| 1347 | @item texinfo.tex
|
|---|
| 1348 | Required if you have any texinfo files. This is used when converting
|
|---|
| 1349 | Texinfo files into DVI using @samp{texi2dvi} and @TeX{}.
|
|---|
| 1350 | @item ylwrap
|
|---|
| 1351 | A shell script used by an automake generated @file{Makefile} to run
|
|---|
| 1352 | programs like @samp{bison}, @samp{yacc}, @samp{flex}, and @samp{lex}.
|
|---|
| 1353 | These programs default to producing output files with a fixed name, and
|
|---|
| 1354 | the @file{ylwrap} script runs them in a subdirectory to avoid file name
|
|---|
| 1355 | conflicts when using a parallel make program.
|
|---|
| 1356 | @end table
|
|---|
| 1357 |
|
|---|
| 1358 | @node Configuration Names
|
|---|
| 1359 | @chapter Configuration Names
|
|---|
| 1360 | @cindex configuration names
|
|---|
| 1361 | @cindex configuration triplets
|
|---|
| 1362 | @cindex triplets
|
|---|
| 1363 | @cindex host names
|
|---|
| 1364 | @cindex host triplets
|
|---|
| 1365 | @cindex canonical system names
|
|---|
| 1366 | @cindex system names
|
|---|
| 1367 | @cindex system types
|
|---|
| 1368 |
|
|---|
| 1369 | The GNU configure system names all systems using a @dfn{configuration
|
|---|
| 1370 | name}. All such names used to be triplets (they may now contain four
|
|---|
| 1371 | parts in certain cases), and the term @dfn{configuration triplet} is
|
|---|
| 1372 | still seen.
|
|---|
| 1373 |
|
|---|
| 1374 | @menu
|
|---|
| 1375 | * Configuration Name Definition:: Configuration Name Definition.
|
|---|
| 1376 | * Using Configuration Names:: Using Configuration Names.
|
|---|
| 1377 | @end menu
|
|---|
| 1378 |
|
|---|
| 1379 | @node Configuration Name Definition
|
|---|
| 1380 | @section Configuration Name Definition
|
|---|
| 1381 |
|
|---|
| 1382 | This is a string of the form
|
|---|
| 1383 | @var{cpu}-@var{manufacturer}-@var{operating_system}. In some cases,
|
|---|
| 1384 | this is extended to a four part form:
|
|---|
| 1385 | @var{cpu}-@var{manufacturer}-@var{kernel}-@var{operating_system}.
|
|---|
| 1386 |
|
|---|
| 1387 | When using a configuration name in a configure option, it is normally
|
|---|
| 1388 | not necessary to specify an entire name. In particular, the
|
|---|
| 1389 | @var{manufacturer} field is often omitted, leading to strings such as
|
|---|
| 1390 | @samp{i386-linux} or @samp{sparc-sunos}. The shell script
|
|---|
| 1391 | @file{config.sub} will translate these shortened strings into the
|
|---|
| 1392 | canonical form. autoconf will arrange for @file{config.sub} to be run
|
|---|
| 1393 | automatically when it is needed.
|
|---|
| 1394 |
|
|---|
| 1395 | The fields of a configuration name are as follows:
|
|---|
| 1396 |
|
|---|
| 1397 | @table @var
|
|---|
| 1398 | @item cpu
|
|---|
| 1399 | The type of processor. This is typically something like @samp{i386} or
|
|---|
| 1400 | @samp{sparc}. More specific variants are used as well, such as
|
|---|
| 1401 | @samp{mipsel} to indicate a little endian MIPS processor.
|
|---|
| 1402 | @item manufacturer
|
|---|
| 1403 | A somewhat freeform field which indicates the manufacturer of the
|
|---|
| 1404 | system. This is often simply @samp{unknown}. Other common strings are
|
|---|
| 1405 | @samp{pc} for an IBM PC compatible system, or the name of a workstation
|
|---|
| 1406 | vendor, such as @samp{sun}.
|
|---|
| 1407 | @item operating_system
|
|---|
| 1408 | The name of the operating system which is run on the system. This will
|
|---|
| 1409 | be something like @samp{solaris2.5} or @samp{irix6.3}. There is no
|
|---|
| 1410 | particular restriction on the version number, and strings like
|
|---|
| 1411 | @samp{aix4.1.4.0} are seen. For an embedded system, which has no
|
|---|
| 1412 | operating system, this field normally indicates the type of object file
|
|---|
| 1413 | format, such as @samp{elf} or @samp{coff}.
|
|---|
| 1414 | @item kernel
|
|---|
| 1415 | This is used mainly for GNU/Linux. A typical GNU/Linux configuration
|
|---|
| 1416 | name is @samp{i586-pc-linux-gnulibc1}. In this case the kernel,
|
|---|
| 1417 | @samp{linux}, is separated from the operating system, @samp{gnulibc1}.
|
|---|
| 1418 | @end table
|
|---|
| 1419 |
|
|---|
| 1420 | The shell script @file{config.guess} will normally print the correct
|
|---|
| 1421 | configuration name for the system on which it is run. It does by
|
|---|
| 1422 | running @samp{uname} and by examining other characteristics of the
|
|---|
| 1423 | system.
|
|---|
| 1424 |
|
|---|
| 1425 | Because @file{config.guess} can normally determine the configuration
|
|---|
| 1426 | name for a machine, it is normally only necessary to specify a
|
|---|
| 1427 | configuration name when building a cross-compiler or when building using
|
|---|
| 1428 | a cross-compiler.
|
|---|
| 1429 |
|
|---|
| 1430 | @node Using Configuration Names
|
|---|
| 1431 | @section Using Configuration Names
|
|---|
| 1432 |
|
|---|
| 1433 | A configure script will sometimes have to make a decision based on a
|
|---|
| 1434 | configuration name. You will need to do this if you have to compile
|
|---|
| 1435 | code differently based on something which can not be tested using a
|
|---|
| 1436 | standard autoconf feature test.
|
|---|
| 1437 |
|
|---|
| 1438 | It is normally better to test for particular features, rather than to
|
|---|
| 1439 | test for a particular system. This is because as Unix evolves,
|
|---|
| 1440 | different systems copy features from one another. Even if you need to
|
|---|
| 1441 | determine whether the feature is supported based on a configuration
|
|---|
| 1442 | name, you should define a macro which describes the feature, rather than
|
|---|
| 1443 | defining a macro which describes the particular system you are on.
|
|---|
| 1444 |
|
|---|
| 1445 | Testing for a particular system is normally done using a case statement
|
|---|
| 1446 | in @file{configure.in}. The case statement might look something like
|
|---|
| 1447 | the following, assuming that @samp{host} is a shell variable holding a
|
|---|
| 1448 | canonical configuration name (which will be the case if
|
|---|
| 1449 | @file{configure.in} uses the @samp{AC_CANONICAL_HOST} or
|
|---|
| 1450 | @samp{AC_CANONICAL_SYSTEM} macro).
|
|---|
| 1451 |
|
|---|
| 1452 | @smallexample
|
|---|
| 1453 | case "$@{host@}" in
|
|---|
| 1454 | i[3456]86-*-linux-gnu*) do something ;;
|
|---|
| 1455 | sparc*-sun-solaris2.[56789]*) do something ;;
|
|---|
| 1456 | sparc*-sun-solaris*) do something ;;
|
|---|
| 1457 | mips*-*-elf*) do something ;;
|
|---|
| 1458 | esac
|
|---|
| 1459 | @end smallexample
|
|---|
| 1460 |
|
|---|
| 1461 | It is particularly important to use @samp{*} after the operating system
|
|---|
| 1462 | field, in order to match the version number which will be generated by
|
|---|
| 1463 | @file{config.guess}.
|
|---|
| 1464 |
|
|---|
| 1465 | In most cases you must be careful to match a range of processor types.
|
|---|
| 1466 | For most processor families, a trailing @samp{*} suffices, as in
|
|---|
| 1467 | @samp{mips*} above. For the i386 family, something along the lines of
|
|---|
| 1468 | @samp{i[3456]86} suffices at present. For the m68k family, you will
|
|---|
| 1469 | need something like @samp{m68*}. Of course, if you do not need to match
|
|---|
| 1470 | on the processor, it is simpler to just replace the entire field by a
|
|---|
| 1471 | @samp{*}, as in @samp{*-*-irix*}.
|
|---|
| 1472 |
|
|---|
| 1473 | @node Cross Compilation Tools
|
|---|
| 1474 | @chapter Cross Compilation Tools
|
|---|
| 1475 | @cindex cross tools
|
|---|
| 1476 |
|
|---|
| 1477 | The GNU configure and build system can be used to build @dfn{cross
|
|---|
| 1478 | compilation} tools. A cross compilation tool is a tool which runs on
|
|---|
| 1479 | one system and produces code which runs on another system.
|
|---|
| 1480 |
|
|---|
| 1481 | @menu
|
|---|
| 1482 | * Cross Compilation Concepts:: Cross Compilation Concepts.
|
|---|
| 1483 | * Host and Target:: Host and Target.
|
|---|
| 1484 | * Using the Host Type:: Using the Host Type.
|
|---|
| 1485 | * Specifying the Target:: Specifying the Target.
|
|---|
| 1486 | * Using the Target Type:: Using the Target Type.
|
|---|
| 1487 | * Cross Tools in the Cygnus Tree:: Cross Tools in the Cygnus Tree
|
|---|
| 1488 | @end menu
|
|---|
| 1489 |
|
|---|
| 1490 | @node Cross Compilation Concepts
|
|---|
| 1491 | @section Cross Compilation Concepts
|
|---|
| 1492 |
|
|---|
| 1493 | @cindex cross compiler
|
|---|
| 1494 | A compiler which produces programs which run on a different system is a
|
|---|
| 1495 | cross compilation compiler, or simply a @dfn{cross compiler}.
|
|---|
| 1496 | Similarly, we speak of cross assemblers, cross linkers, etc.
|
|---|
| 1497 |
|
|---|
| 1498 | In the normal case, a compiler produces code which runs on the same
|
|---|
| 1499 | system as the one on which the compiler runs. When it is necessary to
|
|---|
| 1500 | distinguish this case from the cross compilation case, such a compiler
|
|---|
| 1501 | is called a @dfn{native compiler}. Similarly, we speak of native
|
|---|
| 1502 | assemblers, etc.
|
|---|
| 1503 |
|
|---|
| 1504 | Although the debugger is not strictly speaking a compilation tool, it is
|
|---|
| 1505 | nevertheless meaningful to speak of a cross debugger: a debugger which
|
|---|
| 1506 | is used to debug code which runs on another system. Everything that is
|
|---|
| 1507 | said below about configuring cross compilation tools applies to the
|
|---|
| 1508 | debugger as well.
|
|---|
| 1509 |
|
|---|
| 1510 | @node Host and Target
|
|---|
| 1511 | @section Host and Target
|
|---|
| 1512 | @cindex host system
|
|---|
| 1513 | @cindex target system
|
|---|
| 1514 |
|
|---|
| 1515 | When building cross compilation tools, there are two different systems
|
|---|
| 1516 | involved: the system on which the tools will run, and the system for
|
|---|
| 1517 | which the tools generate code.
|
|---|
| 1518 |
|
|---|
| 1519 | The system on which the tools will run is called the @dfn{host} system.
|
|---|
| 1520 |
|
|---|
| 1521 | The system for which the tools generate code is called the @dfn{target}
|
|---|
| 1522 | system.
|
|---|
| 1523 |
|
|---|
| 1524 | For example, suppose you have a compiler which runs on a GNU/Linux
|
|---|
| 1525 | system and generates ELF programs for a MIPS embedded system. In this
|
|---|
| 1526 | case the GNU/Linux system is the host, and the MIPS ELF system is the
|
|---|
| 1527 | target. Such a compiler could be called a GNU/Linux cross MIPS ELF
|
|---|
| 1528 | compiler, or, equivalently, a @samp{i386-linux-gnu} cross
|
|---|
| 1529 | @samp{mips-elf} compiler.
|
|---|
| 1530 |
|
|---|
| 1531 | Naturally, most programs are not cross compilation tools. For those
|
|---|
| 1532 | programs, it does not make sense to speak of a target. It only makes
|
|---|
| 1533 | sense to speak of a target for tools like @samp{gcc} or the
|
|---|
| 1534 | @samp{binutils} which actually produce running code. For example, it
|
|---|
| 1535 | does not make sense to speak of the target of a tool like @samp{bison}
|
|---|
| 1536 | or @samp{make}.
|
|---|
| 1537 |
|
|---|
| 1538 | Most cross compilation tools can also serve as native tools. For a
|
|---|
| 1539 | native compilation tool, it is still meaningful to speak of a target.
|
|---|
| 1540 | For a native tool, the target is the same as the host. For example, for
|
|---|
| 1541 | a GNU/Linux native compiler, the host is GNU/Linux, and the target is
|
|---|
| 1542 | also GNU/Linux.
|
|---|
| 1543 |
|
|---|
| 1544 | @node Using the Host Type
|
|---|
| 1545 | @section Using the Host Type
|
|---|
| 1546 |
|
|---|
| 1547 | In almost all cases the host system is the system on which you run the
|
|---|
| 1548 | @samp{configure} script, and on which you build the tools (for the case
|
|---|
| 1549 | when they differ, @pxref{Canadian Cross}).
|
|---|
| 1550 |
|
|---|
| 1551 | @cindex @samp{AC_CANONICAL_HOST}
|
|---|
| 1552 | If your configure script needs to know the configuration name of the
|
|---|
| 1553 | host system, and the package is not a cross compilation tool and
|
|---|
| 1554 | therefore does not have a target, put @samp{AC_CANONICAL_HOST} in
|
|---|
| 1555 | @file{configure.in}. This macro will arrange to define a few shell
|
|---|
| 1556 | variables when the @samp{configure} script is run.
|
|---|
| 1557 |
|
|---|
| 1558 | @table @samp
|
|---|
| 1559 | @item host
|
|---|
| 1560 | The canonical configuration name of the host. This will normally be
|
|---|
| 1561 | determined by running the @file{config.guess} shell script, although the
|
|---|
| 1562 | user is permitted to override this by using an explicit @samp{--host}
|
|---|
| 1563 | option.
|
|---|
| 1564 | @item host_alias
|
|---|
| 1565 | In the unusual case that the user used an explicit @samp{--host} option,
|
|---|
| 1566 | this will be the argument to @samp{--host}. In the normal case, this
|
|---|
| 1567 | will be the same as the @samp{host} variable.
|
|---|
| 1568 | @item host_cpu
|
|---|
| 1569 | @itemx host_vendor
|
|---|
| 1570 | @itemx host_os
|
|---|
| 1571 | The first three parts of the canonical configuration name.
|
|---|
| 1572 | @end table
|
|---|
| 1573 |
|
|---|
| 1574 | The shell variables may be used by putting shell code in
|
|---|
| 1575 | @file{configure.in}. For an example, see @ref{Using Configuration
|
|---|
| 1576 | Names}.
|
|---|
| 1577 |
|
|---|
| 1578 | @node Specifying the Target
|
|---|
| 1579 | @section Specifying the Target
|
|---|
| 1580 |
|
|---|
| 1581 | By default, the @samp{configure} script will assume that the target is
|
|---|
| 1582 | the same as the host. This is the more common case; for example, it
|
|---|
| 1583 | leads to a native compiler rather than a cross compiler.
|
|---|
| 1584 |
|
|---|
| 1585 | @cindex @samp{--target} option
|
|---|
| 1586 | @cindex target option
|
|---|
| 1587 | @cindex configure target
|
|---|
| 1588 | If you want to build a cross compilation tool, you must specify the
|
|---|
| 1589 | target explicitly by using the @samp{--target} option when you run
|
|---|
| 1590 | @samp{configure}. The argument to @samp{--target} is the configuration
|
|---|
| 1591 | name of the system for which you wish to generate code.
|
|---|
| 1592 | @xref{Configuration Names}.
|
|---|
| 1593 |
|
|---|
| 1594 | For example, to build tools which generate code for a MIPS ELF embedded
|
|---|
| 1595 | system, you would use @samp{--target mips-elf}.
|
|---|
| 1596 |
|
|---|
| 1597 | @node Using the Target Type
|
|---|
| 1598 | @section Using the Target Type
|
|---|
| 1599 |
|
|---|
| 1600 | @cindex @samp{AC_CANONICAL_SYSTEM}
|
|---|
| 1601 | When writing @file{configure.in} for a cross compilation tool, you will
|
|---|
| 1602 | need to use information about the target. To do this, put
|
|---|
| 1603 | @samp{AC_CANONICAL_SYSTEM} in @file{configure.in}.
|
|---|
| 1604 |
|
|---|
| 1605 | @samp{AC_CANONICAL_SYSTEM} will look for a @samp{--target} option and
|
|---|
| 1606 | canonicalize it using the @file{config.sub} shell script. It will also
|
|---|
| 1607 | run @samp{AC_CANONICAL_HOST} (@pxref{Using the Host Type}).
|
|---|
| 1608 |
|
|---|
| 1609 | The target type will be recorded in the following shell variables. Note
|
|---|
| 1610 | that the host versions of these variables will also be defined by
|
|---|
| 1611 | @samp{AC_CANONICAL_HOST}.
|
|---|
| 1612 |
|
|---|
| 1613 | @table @samp
|
|---|
| 1614 | @item target
|
|---|
| 1615 | The canonical configuration name of the target.
|
|---|
| 1616 | @item target_alias
|
|---|
| 1617 | The argument to the @samp{--target} option. If the user did not specify
|
|---|
| 1618 | a @samp{--target} option, this will be the same as @samp{host_alias}.
|
|---|
| 1619 | @item target_cpu
|
|---|
| 1620 | @itemx target_vendor
|
|---|
| 1621 | @itemx target_os
|
|---|
| 1622 | The first three parts of the canonical target configuration name.
|
|---|
| 1623 | @end table
|
|---|
| 1624 |
|
|---|
| 1625 | Note that if @samp{host} and @samp{target} are the same string, you can
|
|---|
| 1626 | assume a native configuration. If they are different, you can assume a
|
|---|
| 1627 | cross configuration.
|
|---|
| 1628 |
|
|---|
| 1629 | It is arguably possible for @samp{host} and @samp{target} to represent
|
|---|
| 1630 | the same system, but for the strings to not be identical. For example,
|
|---|
| 1631 | if @samp{config.guess} returns @samp{sparc-sun-sunos4.1.4}, and somebody
|
|---|
| 1632 | configures with @samp{--target sparc-sun-sunos4.1}, then the slight
|
|---|
| 1633 | differences between the two versions of SunOS may be unimportant for
|
|---|
| 1634 | your tool. However, in the general case it can be quite difficult to
|
|---|
| 1635 | determine whether the differences between two configuration names are
|
|---|
| 1636 | significant or not. Therefore, by convention, if the user specifies a
|
|---|
| 1637 | @samp{--target} option without specifying a @samp{--host} option, it is
|
|---|
| 1638 | assumed that the user wants to configure a cross compilation tool.
|
|---|
| 1639 |
|
|---|
| 1640 | The variables @samp{target} and @samp{target_alias} should be handled
|
|---|
| 1641 | differently.
|
|---|
| 1642 |
|
|---|
| 1643 | In general, whenever the user may actually see a string,
|
|---|
| 1644 | @samp{target_alias} should be used. This includes anything which may
|
|---|
| 1645 | appear in the file system, such as a directory name or part of a tool
|
|---|
| 1646 | name. It also includes any tool output, unless it is clearly labelled
|
|---|
| 1647 | as the canonical target configuration name. This permits the user to
|
|---|
| 1648 | use the @samp{--target} option to specify how the tool will appear to
|
|---|
| 1649 | the outside world.
|
|---|
| 1650 |
|
|---|
| 1651 | On the other hand, when checking for characteristics of the target
|
|---|
| 1652 | system, @samp{target} should be used. This is because a wide variety of
|
|---|
| 1653 | @samp{--target} options may map into the same canonical configuration
|
|---|
| 1654 | name. You should not attempt to duplicate the canonicalization done by
|
|---|
| 1655 | @samp{config.sub} in your own code.
|
|---|
| 1656 |
|
|---|
| 1657 | By convention, cross tools are installed with a prefix of the argument
|
|---|
| 1658 | used with the @samp{--target} option, also known as @samp{target_alias}
|
|---|
| 1659 | (@pxref{Using the Target Type}). If the user does not use the
|
|---|
| 1660 | @samp{--target} option, and thus is building a native tool, no prefix is
|
|---|
| 1661 | used.
|
|---|
| 1662 |
|
|---|
| 1663 | For example, if gcc is configured with @samp{--target mips-elf}, then
|
|---|
| 1664 | the installed binary will be named @samp{mips-elf-gcc}. If gcc is
|
|---|
| 1665 | configured without a @samp{--target} option, then the installed binary
|
|---|
| 1666 | will be named @samp{gcc}.
|
|---|
| 1667 |
|
|---|
| 1668 | The autoconf macro @samp{AC_ARG_PROGRAM} will handle this for you. If
|
|---|
| 1669 | you are using automake, no more need be done; the programs will
|
|---|
| 1670 | automatically be installed with the correct prefixes. Otherwise, see
|
|---|
| 1671 | the autoconf documentation for @samp{AC_ARG_PROGRAM}.
|
|---|
| 1672 |
|
|---|
| 1673 | @node Cross Tools in the Cygnus Tree
|
|---|
| 1674 | @section Cross Tools in the Cygnus Tree
|
|---|
| 1675 |
|
|---|
| 1676 | The Cygnus tree is used for various packages including gdb, the GNU
|
|---|
| 1677 | binutils, and egcs. It is also, of course, used for Cygnus releases.
|
|---|
| 1678 |
|
|---|
| 1679 | In the Cygnus tree, the top level @file{configure} script uses the old
|
|---|
| 1680 | Cygnus configure system, not autoconf. The top level @file{Makefile.in}
|
|---|
| 1681 | is written to build packages based on what is in the source tree, and
|
|---|
| 1682 | supports building a large number of tools in a single
|
|---|
| 1683 | @samp{configure}/@samp{make} step.
|
|---|
| 1684 |
|
|---|
| 1685 | The Cygnus tree may be configured with a @samp{--target} option. The
|
|---|
| 1686 | @samp{--target} option applies recursively to every subdirectory, and
|
|---|
| 1687 | permits building an entire set of cross tools at once.
|
|---|
| 1688 |
|
|---|
| 1689 | @menu
|
|---|
| 1690 | * Host and Target Libraries:: Host and Target Libraries.
|
|---|
| 1691 | * Target Library Configure Scripts:: Target Library Configure Scripts.
|
|---|
| 1692 | * Make Targets in Cygnus Tree:: Make Targets in Cygnus Tree.
|
|---|
| 1693 | * Target libiberty:: Target libiberty
|
|---|
| 1694 | @end menu
|
|---|
| 1695 |
|
|---|
| 1696 | @node Host and Target Libraries
|
|---|
| 1697 | @subsection Host and Target Libraries
|
|---|
| 1698 |
|
|---|
| 1699 | The Cygnus tree distinguishes host libraries from target libraries.
|
|---|
| 1700 |
|
|---|
| 1701 | Host libraries are built with the compiler used to build the programs
|
|---|
| 1702 | which run on the host, which is called the host compiler. This includes
|
|---|
| 1703 | libraries such as @samp{bfd} and @samp{tcl}. These libraries are built
|
|---|
| 1704 | with the host compiler, and are linked into programs like the binutils
|
|---|
| 1705 | or gcc which run on the host.
|
|---|
| 1706 |
|
|---|
| 1707 | Target libraries are built with the target compiler. If gcc is present
|
|---|
| 1708 | in the source tree, then the target compiler is the gcc that is built
|
|---|
| 1709 | using the host compiler. Target libraries are libraries such as
|
|---|
| 1710 | @samp{newlib} and @samp{libstdc++}. These libraries are not linked into
|
|---|
| 1711 | the host programs, but are instead made available for use with programs
|
|---|
| 1712 | built with the target compiler.
|
|---|
| 1713 |
|
|---|
| 1714 | For the rest of this section, assume that gcc is present in the source
|
|---|
| 1715 | tree, so that it will be used to build the target libraries.
|
|---|
| 1716 |
|
|---|
| 1717 | There is a complication here. The configure process needs to know which
|
|---|
| 1718 | compiler you are going to use to build a tool; otherwise, the feature
|
|---|
| 1719 | tests will not work correctly. The Cygnus tree handles this by not
|
|---|
| 1720 | configuring the target libraries until the target compiler is built. In
|
|---|
| 1721 | order to permit everything to build using a single
|
|---|
| 1722 | @samp{configure}/@samp{make}, the configuration of the target libraries
|
|---|
| 1723 | is actually triggered during the make step.
|
|---|
| 1724 |
|
|---|
| 1725 | When the target libraries are configured, the @samp{--target} option is
|
|---|
| 1726 | not used. Instead, the @samp{--host} option is used with the argument
|
|---|
| 1727 | of the @samp{--target} option for the overall configuration. If no
|
|---|
| 1728 | @samp{--target} option was used for the overall configuration, the
|
|---|
| 1729 | @samp{--host} option will be passed with the output of the
|
|---|
| 1730 | @file{config.guess} shell script. Any @samp{--build} option is passed
|
|---|
| 1731 | down unchanged.
|
|---|
| 1732 |
|
|---|
| 1733 | This translation of configuration options is done because since the
|
|---|
| 1734 | target libraries are compiled with the target compiler, they are being
|
|---|
| 1735 | built in order to run on the target of the overall configuration. By
|
|---|
| 1736 | the definition of host, this means that their host system is the same as
|
|---|
| 1737 | the target system of the overall configuration.
|
|---|
| 1738 |
|
|---|
| 1739 | The same process is used for both a native configuration and a cross
|
|---|
| 1740 | configuration. Even when using a native configuration, the target
|
|---|
| 1741 | libraries will be configured and built using the newly built compiler.
|
|---|
| 1742 | This is particularly important for the C++ libraries, since there is no
|
|---|
| 1743 | reason to assume that the C++ compiler used to build the host tools (if
|
|---|
| 1744 | there even is one) uses the same ABI as the g++ compiler which will be
|
|---|
| 1745 | used to build the target libraries.
|
|---|
| 1746 |
|
|---|
| 1747 | There is one difference between a native configuration and a cross
|
|---|
| 1748 | configuration. In a native configuration, the target libraries are
|
|---|
| 1749 | normally configured and built as siblings of the host tools. In a cross
|
|---|
| 1750 | configuration, the target libraries are normally built in a subdirectory
|
|---|
| 1751 | whose name is the argument to @samp{--target}. This is mainly for
|
|---|
| 1752 | historical reasons.
|
|---|
| 1753 |
|
|---|
| 1754 | To summarize, running @samp{configure} in the Cygnus tree configures all
|
|---|
| 1755 | the host libraries and tools, but does not configure any of the target
|
|---|
| 1756 | libraries. Running @samp{make} then does the following steps:
|
|---|
| 1757 |
|
|---|
| 1758 | @itemize @bullet
|
|---|
| 1759 | @item
|
|---|
| 1760 | Build the host libraries.
|
|---|
| 1761 | @item
|
|---|
| 1762 | Build the host programs, including gcc. Note that we call gcc both a
|
|---|
| 1763 | host program (since it runs on the host) and a target compiler (since it
|
|---|
| 1764 | generates code for the target).
|
|---|
| 1765 | @item
|
|---|
| 1766 | Using the newly built target compiler, configure the target libraries.
|
|---|
| 1767 | @item
|
|---|
| 1768 | Build the target libraries.
|
|---|
| 1769 | @end itemize
|
|---|
| 1770 |
|
|---|
| 1771 | The steps need not be done in precisely this order, since they are
|
|---|
| 1772 | actually controlled by @file{Makefile} targets.
|
|---|
| 1773 |
|
|---|
| 1774 | @node Target Library Configure Scripts
|
|---|
| 1775 | @subsection Target Library Configure Scripts
|
|---|
| 1776 |
|
|---|
| 1777 | There are a few things you must know in order to write a configure
|
|---|
| 1778 | script for a target library. This is just a quick sketch, and beginners
|
|---|
| 1779 | shouldn't worry if they don't follow everything here.
|
|---|
| 1780 |
|
|---|
| 1781 | The target libraries are configured and built using a newly built target
|
|---|
| 1782 | compiler. There may not be any startup files or libraries for this
|
|---|
| 1783 | target compiler. In fact, those files will probably be built as part of
|
|---|
| 1784 | some target library, which naturally means that they will not exist when
|
|---|
| 1785 | your target library is configured.
|
|---|
| 1786 |
|
|---|
| 1787 | This means that the configure script for a target library may not use
|
|---|
| 1788 | any test which requires doing a link. This unfortunately includes many
|
|---|
| 1789 | useful autoconf macros, such as @samp{AC_CHECK_FUNCS}. autoconf macros
|
|---|
| 1790 | which do a compile but not a link, such as @samp{AC_CHECK_HEADERS}, may
|
|---|
| 1791 | be used.
|
|---|
| 1792 |
|
|---|
| 1793 | This is a severe restriction, but normally not a fatal one, as target
|
|---|
| 1794 | libraries can often assume the presence of other target libraries, and
|
|---|
| 1795 | thus know which functions will be available.
|
|---|
| 1796 |
|
|---|
| 1797 | As of this writing, the autoconf macro @samp{AC_PROG_CC} does a link to
|
|---|
| 1798 | make sure that the compiler works. This may fail in a target library,
|
|---|
| 1799 | so target libraries must use a different set of macros to locate the
|
|---|
| 1800 | compiler. See the @file{configure.in} file in a directory like
|
|---|
| 1801 | @file{libiberty} or @file{libgloss} for an example.
|
|---|
| 1802 |
|
|---|
| 1803 | As noted in the previous section, target libraries are sometimes built
|
|---|
| 1804 | in directories which are siblings to the host tools, and are sometimes
|
|---|
| 1805 | built in a subdirectory. The @samp{--with-target-subdir} configure
|
|---|
| 1806 | option will be passed when the library is configured. Its value will be
|
|---|
| 1807 | an empty string if the target library is a sibling. Its value will be
|
|---|
| 1808 | the name of the subdirectory if the target library is in a subdirectory.
|
|---|
| 1809 |
|
|---|
| 1810 | If the overall build is not a native build (i.e., the overall configure
|
|---|
| 1811 | used the @samp{--target} option), then the library will be configured
|
|---|
| 1812 | with the @samp{--with-cross-host} option. The value of this option will
|
|---|
| 1813 | be the host system of the overall build. Recall that the host system of
|
|---|
| 1814 | the library will be the target of the overall build. If the overall
|
|---|
| 1815 | build is a native build, the @samp{--with-cross-host} option will not be
|
|---|
| 1816 | used.
|
|---|
| 1817 |
|
|---|
| 1818 | A library which can be built both standalone and as a target library may
|
|---|
| 1819 | want to install itself into different directories depending upon the
|
|---|
| 1820 | case. When built standalone, or when built native, the library should
|
|---|
| 1821 | be installed in @samp{$(libdir)}. When built as a target library which
|
|---|
| 1822 | is not native, the library should be installed in @samp{$(tooldir)/lib}.
|
|---|
| 1823 | The @samp{--with-cross-host} option may be used to distinguish these
|
|---|
| 1824 | cases.
|
|---|
| 1825 |
|
|---|
| 1826 | This same test of @samp{--with-cross-host} may be used to see whether it
|
|---|
| 1827 | is OK to use link tests in the configure script. If the
|
|---|
| 1828 | @samp{--with-cross-host} option is not used, then the library is being
|
|---|
| 1829 | built either standalone or native, and a link should work.
|
|---|
| 1830 |
|
|---|
| 1831 | @node Make Targets in Cygnus Tree
|
|---|
| 1832 | @subsection Make Targets in Cygnus Tree
|
|---|
| 1833 |
|
|---|
| 1834 | The top level @file{Makefile} in the Cygnus tree defines targets for
|
|---|
| 1835 | every known subdirectory.
|
|---|
| 1836 |
|
|---|
| 1837 | For every subdirectory @var{dir} which holds a host library or program,
|
|---|
| 1838 | the @file{Makefile} target @samp{all-@var{dir}} will build that library
|
|---|
| 1839 | or program.
|
|---|
| 1840 |
|
|---|
| 1841 | There are dependencies among host tools. For example, building gcc
|
|---|
| 1842 | requires first building gas, because the gcc build process invokes the
|
|---|
| 1843 | target assembler. These dependencies are reflected in the top level
|
|---|
| 1844 | @file{Makefile}.
|
|---|
| 1845 |
|
|---|
| 1846 | For every subdirectory @var{dir} which holds a target library, the
|
|---|
| 1847 | @file{Makefile} target @samp{configure-target-@var{dir}} will configure
|
|---|
| 1848 | that library. The @file{Makefile} target @samp{all-target-@var{dir}}
|
|---|
| 1849 | will build that library.
|
|---|
| 1850 |
|
|---|
| 1851 | Every @samp{configure-target-@var{dir}} target depends upon
|
|---|
| 1852 | @samp{all-gcc}, since gcc, the target compiler, is required to configure
|
|---|
| 1853 | the tool. Every @samp{all-target-@var{dir}} target depends upon the
|
|---|
| 1854 | corresponding @samp{configure-target-@var{dir}} target.
|
|---|
| 1855 |
|
|---|
| 1856 | There are several other targets which may be of interest for each
|
|---|
| 1857 | directory: @samp{install-@var{dir}}, @samp{clean-@var{dir}}, and
|
|---|
| 1858 | @samp{check-@var{dir}}. There are also corresponding @samp{target}
|
|---|
| 1859 | versions of these for the target libraries , such as
|
|---|
| 1860 | @samp{install-target-@var{dir}}.
|
|---|
| 1861 |
|
|---|
| 1862 | @node Target libiberty
|
|---|
| 1863 | @subsection Target libiberty
|
|---|
| 1864 |
|
|---|
| 1865 | The @file{libiberty} subdirectory is currently a special case, in that
|
|---|
| 1866 | it is the only directory which is built both using the host compiler and
|
|---|
| 1867 | using the target compiler.
|
|---|
| 1868 |
|
|---|
| 1869 | This is because the files in @file{libiberty} are used when building the
|
|---|
| 1870 | host tools, and they are also incorporated into the @file{libstdc++}
|
|---|
| 1871 | target library as support code.
|
|---|
| 1872 |
|
|---|
| 1873 | This duality does not pose any particular difficulties. It means that
|
|---|
| 1874 | there are targets for both @samp{all-libiberty} and
|
|---|
| 1875 | @samp{all-target-libiberty}.
|
|---|
| 1876 |
|
|---|
| 1877 | In a native configuration, when target libraries are not built in a
|
|---|
| 1878 | subdirectory, the same objects are normally used as both the host build
|
|---|
| 1879 | and the target build. This is normally OK, since libiberty contains
|
|---|
| 1880 | only C code, and in a native configuration the results of the host
|
|---|
| 1881 | compiler and the target compiler are normally interoperable.
|
|---|
| 1882 |
|
|---|
| 1883 | Irix 6 is again an exception here, since the SGI native compiler
|
|---|
| 1884 | defaults to using the @samp{O32} ABI, and gcc defaults to using the
|
|---|
| 1885 | @samp{N32} ABI. On Irix 6, the target libraries are built in a
|
|---|
| 1886 | subdirectory even for a native configuration, avoiding this problem.
|
|---|
| 1887 |
|
|---|
| 1888 | There are currently no other libraries built for both the host and the
|
|---|
| 1889 | target, but there is no conceptual problem with adding more.
|
|---|
| 1890 |
|
|---|
| 1891 | @node Canadian Cross
|
|---|
| 1892 | @chapter Canadian Cross
|
|---|
| 1893 | @cindex canadian cross
|
|---|
| 1894 | @cindex building with a cross compiler
|
|---|
| 1895 | @cindex cross compiler, building with
|
|---|
| 1896 |
|
|---|
| 1897 | It is possible to use the GNU configure and build system to build a
|
|---|
| 1898 | program which will run on a system which is different from the system on
|
|---|
| 1899 | which the tools are built. In other words, it is possible to build
|
|---|
| 1900 | programs using a cross compiler.
|
|---|
| 1901 |
|
|---|
| 1902 | This is referred to as a @dfn{Canadian Cross}.
|
|---|
| 1903 |
|
|---|
| 1904 | @menu
|
|---|
| 1905 | * Canadian Cross Example:: Canadian Cross Example.
|
|---|
| 1906 | * Canadian Cross Concepts:: Canadian Cross Concepts.
|
|---|
| 1907 | * Build Cross Host Tools:: Build Cross Host Tools.
|
|---|
| 1908 | * Build and Host Options:: Build and Host Options.
|
|---|
| 1909 | * CCross not in Cygnus Tree:: Canadian Cross not in Cygnus Tree.
|
|---|
| 1910 | * CCross in Cygnus Tree:: Canadian Cross in Cygnus Tree.
|
|---|
| 1911 | * Supporting Canadian Cross:: Supporting Canadian Cross.
|
|---|
| 1912 | @end menu
|
|---|
| 1913 |
|
|---|
| 1914 | @node Canadian Cross Example
|
|---|
| 1915 | @section Canadian Cross Example
|
|---|
| 1916 |
|
|---|
| 1917 | Here is an example of a Canadian Cross.
|
|---|
| 1918 |
|
|---|
| 1919 | While running on a GNU/Linux, you can build a program which will run on
|
|---|
| 1920 | a Solaris system. You would use a GNU/Linux cross Solaris compiler to
|
|---|
| 1921 | build the program.
|
|---|
| 1922 |
|
|---|
| 1923 | Of course, you could not run the resulting program on your GNU/Linux
|
|---|
| 1924 | system. You would have to copy it over to a Solaris system before you
|
|---|
| 1925 | would run it.
|
|---|
|
|---|