add menu item and Makefile.in hook
[binutils-gdb.git] / cfg-paper.texi
1 \input texinfo @c -*-para-*-
2 @c %**start of header
3 @setfilename cfg-paper.info
4 @settitle On Configuring Development Tools
5 @c %**end of header
6 @setchapternewpage off
7
8 @titlepage
9 @sp 10
10 @title{On Configuring Development Tools}
11 @author{K. Richard Pixley}
12 @author{Cygnus Support}
13 @vskip 0pt plus 1filll
14 Copyright @copyright{} 1991 Cygnus Support
15 @end titlepage
16
17 @ifinfo
18 This document attempts to describe the general concepts behind
19 configuration of the Cygnus Support release of the @sc{gnu} Development
20 Tools. It also discusses common usage..
21
22 Copyright @copyright{} 1991 Cygnus Support
23 @end ifinfo
24
25 @ifinfo
26 @format
27 START-INFO-DIR-ENTRY
28 * configuration: (cfg-paper.info). Some theory on configuring source.
29 END-INFO-DIR-ENTRY
30 @end format
31 @end ifinfo
32
33 @node top, Some Basic Terms, (dir), (dir)
34
35 @ifinfo
36 This document attempts to describe the general concepts behind
37 configuration of the Cygnus Support release of the @sc{gnu} Development
38 Tools. It also discusses common usage.
39 @end ifinfo
40
41 @menu
42 * Some Basic Terms:: Some Basic Terms
43 * Specifics.:: Specifics
44 * Building Development Environments:: Building Development Environments
45 * A Walk Through:: A Walk Through
46 * Final Notes:: Final Notes
47 * Index:: Index
48 @end menu
49
50 @node Some Basic Terms, Specifics., top, top
51 @chapter Some Basic Terms
52
53 There are a lot of terms that are frequently used when discussing
54 development tools. Most of the common terms have been used for many
55 different concepts such that their meanings have become ambiguous to the
56 point of being confusing. Typically, we only guess at their meanings
57 from context and we frequently guess wrong.
58
59 This document uses very few terms by comparison. The intent is to make
60 the concepts as clear as possible in order to convey the usage and
61 intent of these tools.
62
63 @emph{Programs} run on @emph{machines}. Programs are very nearly always
64 written in @emph{source}. Programs are @emph{built} from source.
65 @emph{Compilation} is a process that is frequently, but not always, used
66 when building programs.
67 @cindex Programs
68 @cindex Machines
69 @cindex Source
70 @cindex Building
71 @cindex Compilation
72
73 @menu
74 * Host Environments:: Host Environments
75 * Configuration Time Options:: Configuration Time Options
76 @end menu
77
78 @node Host Environments, Configuration Time Options, Some Basic Terms, Some Basic Terms
79 @section Host Environments
80
81 @cindex host
82 In this document, the word @emph{host} refers to the environment in
83 which the source in question will be compiled. @emph{host} and
84 @emph{host name} have nothing to do with the proper name of your host,
85 like @emph{ucbvax}, @emph{prep.ai.mit.edu} or @emph{att.com}. Instead
86 they refer to things like @emph{sun4} and @emph{dec3100}.
87
88 Forget for a moment that this particular directory of source is the
89 source for a development environment. Instead, pretend that it is the
90 source for a simpler, more mundane, application, say, a desk calculator.
91
92 Source that can be compiled in more than one environment, generally
93 needs to be set up for each environment explicitly. Here we refer to
94 that process as configuration. That is, we configure the source for a
95 host.
96
97 For example, if we wanted to configure our mythical desk calculator to
98 compile on a SparcStation, we might configure for host sun4. With our
99 configuration system:
100
101 @example
102 cd desk-calculator ; ./configure sun4
103 @end example
104
105 @noindent
106 does the trick. @code{configure} is a shell script that sets up Makefiles,
107 subdirectories, and symbolic links appropriate for compiling the source
108 on a sun4.
109
110 The @emph{host} environment does not necessarily refer to the machine on
111 which the tools are built. It is possible to provide a sun3 development
112 environment on a sun4. If we wanted to use a cross compiler on the sun4
113 to build a program intended to be run on a sun3, we would configure the
114 source for sun3.
115
116 @example
117 cd desk-calculator ; ./configure sun3
118 @end example
119
120 @noindent
121 The fact that we are actually building the program on a sun4 makes no
122 difference if the sun3 cross compiler presents an environment that looks
123 like a sun3 from the point of view of the desk calculator source code.
124 Specifically, the environment is a sun3 environment if the header files,
125 predefined symbols, and libraries appear as they do on a sun3.
126
127 Nor does the host environment refer to the the machine on which the
128 program to be built will run. It is possible to provide a sun3
129 emulation environment on a sun4 such that programs built in a sun3
130 development environment actually run on the sun4. This technique is
131 often used within individual programs to remedy deficiencies in the host
132 operating system. For example, some operating systems do not provide
133 the @code{bcopy()} function and so it is emulated using the
134 @code{memset()} funtion.
135
136 Host environment simply refers to the environment in which the program
137 will be built from the source.
138
139
140 @node Configuration Time Options, , Host Environments, Some Basic Terms
141 @section Configuration Time Options
142
143 Many programs have compile time options. That is, features of the
144 program that are either compiled into the program or not based on a
145 choice made by the person who builds the program. We refer to these as
146 @emph{configuration options}. For example, our desk calculator might be
147 capable of being compiled into a program that either uses infix notation
148 or postfix as a configuration option. For a sun3, to choose infix you
149 might use:
150
151 @example
152 ./configure sun3 -notation=infix
153 @end example
154
155 @noindent
156 while for a sun4 with postfix you might use:
157
158 @example
159 ./configure sun4 -notation=postfix
160 @end example
161
162 If we wanted to build both at the same time, in the same directory
163 structure, the intermediate pieces used in the build process must be
164 kept separate.
165
166 @example
167 ./configure sun4 -subdirs -notation=postfix
168 ./configure sun3 -subdirs -notation=infix
169 @end example
170
171 @noindent
172 will create subdirectories for the intermediate pieces of the sun4 and
173 sun3 configurations. This is necessary as previous systems were only
174 capable of one configuration at a time. Otherwise, a second
175 configuration would write over the first. We've chosen to retain this
176 behaviour so the @code{-subdirs} configuration option is necessary to
177 get the new behaviour. The order of the arguments doesn't matter.
178 There should be exactly one argument without a leading '@minus{}' sign
179 and that argument will be assumed to be the host name.
180
181 From here on the examples will assume that you want to build the tools
182 @emph{in place} and won't show the @code{-subdirs} option, but remember
183 that it is available.
184
185 In order to actually install the program, the configuration system needs
186 to know where you would like the program installed. The default
187 location is @file{/usr/local}. We refer to this location as
188 @code{$(prefix)}. All user visible programs will be installed in
189 @file{@code{$(prefix)}/bin}. All other programs and files will be
190 installed in a subdirectory of @file{@code{$(prefix)}/lib}.
191
192 NOTE: @code{$(prefix)} was previously known as @code{$(destdir)}.
193
194 You can elect to change @code{$(prefix)} only as a configuration time
195 option.
196
197 @example
198 ./configure sun4 -notation=postfix -prefix=/local
199 @end example
200
201 @noindent
202 Will configure the source such that:
203
204 @example
205 make install
206 @end example
207
208 @noindent
209 will put it's programs in @file{/local/bin} and @file{/local/lib/gcc}.
210 If you change @code{$(prefix)} after building the source, you will need
211 to:
212
213 @example
214 make clean
215 @end example
216
217 @noindent
218 before the change will be propogated properly. This is because some
219 tools need to know the locations of other tools.
220
221 With these concepts in mind, we can drop the desk calculator example and
222 move on to the application that resides in these directories, namely,
223 the source to a development environment.
224
225 @node Specifics., Building Development Environments, Some Basic Terms, top
226 @chapter Specifics
227
228 The @sc{gnu} Development Tools can be built on a wide variety of hosts. So,
229 of course, they must be configured. Like the last example,
230
231 @example
232 ./configure sun4 -prefix=/local
233 ./configure sun3 -prefix=/local
234 @end example
235
236 @noindent
237 will configure the source to be built in subdirectories, in order to
238 keep the intermediate pieces separate, and to be installed in
239 @file{/local}.
240
241 When built with suitable development environments, these will be native
242 tools. We'll explain the term @emph{native} later.
243
244 @node Building Development Environments, A Walk Through, Specifics., top
245 @chapter Building Development Environments
246
247 @cindex Target
248
249 The Cygnus Support @sc{gnu} development tools can not only be built in a
250 number of host development environments, they can also be configured to
251 create a number of different development environments on each of those
252 hosts. We refer to a specific development environment created as a
253 @emph{target}. That is, the word @emph{target} refers to the development
254 environment produced by compiling this source and installing the
255 resulting programs.
256
257 For the Cygnus Support @sc{gnu} development tools, the default target is the
258 same as the host. That is, the development environment produced is
259 intended to be compatible with the environment used to build the tools.
260
261 In the example above, we created two configurations, one for sun4 and
262 one for sun3. The first configuration is expecting to be built in a
263 sun4 development environment, to create a sun4 development environment.
264 It doesn't necessarily need to be built on a sun4 if a sun4 development
265 environment is available elsewhere. Likewise, if the available sun4
266 development environment produces executables intended for something
267 other than sun4, then the development environment built from this sun4
268 configuration will run on something other than a sun4. From the point
269 of view of the configuration system and the @sc{gnu} development tools
270 source, this doesn't matter. What matters is that they will be built in
271 a sun4 environment.
272
273 Similarly, the second configuration given above is expecting to be built
274 in a sun3 development environment, to create a sun3 development
275 environment.
276
277 The development environment produced, is a configuration time option,
278 just like @code{$(prefix)}.
279
280 @example
281 ./configure sun4 -prefix=/local -target=sun3
282 ./configure sun3 -prefix=/local -target=sun4
283 @end example
284
285 In this example, like before, we create two configurations. The first
286 is intended to be built in a sun4 environment, in subdirectories, to be
287 installed in @file{/local}. The second is intended to be built in a
288 sun3 environment, in subdirectories, to be installed in @file{/local}.
289
290 Unlike the previous example, the first configuration will produce a sun3
291 development environment, perhaps even suitable for building the second
292 configuration. Likewise, the second configuration will produce a sun4
293 development environment, perhaps even suitable for building the first
294 configuration.
295
296 The development environment used to build these configurations will
297 determine the machines on which the resulting development environments
298 can be used.
299
300
301 @node A Walk Through, Final Notes, Building Development Environments, top
302 @chapter A Walk Through
303
304
305 @menu
306 * Native Development Environments:: Native Development Environments
307 * Emulation Environments:: Emulation Environments
308 * Simple Cross Environments:: Simple Cross Environments
309 * Crossing Into Targets:: Crossing Into Targets
310 * The Three Party Cross:: The Three Party Cross
311 @end menu
312
313 @node Native Development Environments, Emulation Environments, A Walk Through, A Walk Through
314 @section Native Development Environments
315
316 Let us assume for a moment that you have a sun4 and that with your sun4
317 you received a development environment. This development environment is
318 intended to be run on your sun4 to build programs that can be run on
319 your sun4. You could, for instance, run this development environment on
320 your sun4 to build our example desk calculator program. You could then
321 run the desk calculator program on your sun4.
322
323 @cindex Native
324 @cindex Foreign
325 The resulting desk calculator program is referred to as a @emph{native}
326 program. The development environment itself is composed of native
327 programs that, when run, build other native programs. Any other program
328 is referred to as @emph{foreign}. Programs intended for other machines are
329 foreign programs.
330
331 This type of development environment, which is by far the most common,
332 is refered to as @emph{native}. That is, a native development environment
333 runs on some machine to build programs for that same machine. The
334 process of using a native development environment to build native
335 programs is called a @emph{native} build.
336
337 @example
338 ./configure sun4
339 @end example
340
341 @noindent
342 will configure this source such that when built in a sun4 development
343 environment, with a development environment that builds programs
344 intended to be run on sun4 machines, the programs built will be native
345 programs and the resulting development environment will be a native
346 development environment.
347
348 The development system that came with your sun4 is one such environment.
349 Using it to build the @sc{gnu} Development Tools is a very common activity
350 and the resulting development environment is quite popular.
351
352 @example
353 make all
354 @end example
355
356 @noindent
357 will build the tools as configured and will assume that you want to use
358 the native development environment that came with your machine.
359
360 @cindex Bootstrapping
361 @cindex Stage1
362 Using a development environment to build a development environment is
363 called @emph{bootstrapping}. The Cygnus Support release of the @sc{gnu}
364 Development Tools is capable of bootstrapping itself. This is a very
365 powerful feature that we'll return to later. For now, let's pretend
366 that you used the native development environment that came with your
367 sun4 to bootstrap the Cygnus Support release and let's call the new
368 development environment @emph{stage1}.
369
370 Why bother? Well, most people find that the Cygnus Support release
371 builds programs that run faster and take up less space than the native
372 development environments that came with their machines. Some people
373 didn't get development environments with their machines and some people
374 just like using the @sc{gnu} tools better than using other tools.
375
376 @cindex Stage2
377 While you're at it, if the @sc{gnu} tools produce better programs, maybe you
378 should use them to build the @sc{gnu} tools. It's a good idea, so let's
379 pretend that you do. Let's call the new development environment
380 @emph{stage2}.
381
382 @cindex Stage3
383 So far you've built a development environment, stage1, and you've used
384 stage1 to build a new, faster and smaller development environment,
385 stage2, but you haven't run any of the programs that the @sc{gnu} tools have
386 built. You really don't yet know if these tools work. Do you have any
387 programs built with the @sc{gnu} tools? Yes, you do. stage2. What does
388 that program do? It builds programs. Ok, do you have any source handy
389 to build into a program? Yes, you do. The @sc{gnu} tools themselves. In
390 fact, if you use stage2 to build the @sc{gnu} tools again the resulting
391 programs should be identical to stage2. Let's pretend that you do and
392 call the new development environment @emph{stage3}.
393
394 @cindex Three stage boot
395 You've just completed what's called a @emph{three stage boot}. You now have
396 a small, fast, somewhat tested, development environment.
397
398 @example
399 make bootstrap
400 @end example
401
402 @noindent
403 will do a three stage boot across all tools and will compare stage2 to
404 stage3 and complain if they are not identical.
405
406 Once built,
407
408 @example
409 make install
410 @end example
411
412 @noindent
413 will install the development environment in the default location or in
414 @code{$(prefix)} if you specified an alternate when you configured.
415
416 @cindex Cross
417 Any development environment that is not a native development environment
418 is refered to as a @emph{cross} development environment. There are many
419 different types of cross development environments but most fall into one
420 of three basic categories.
421
422
423 @node Emulation Environments, Simple Cross Environments, Native Development Environments, A Walk Through
424 @section Emulation Environments
425
426 @cindex Emulation
427 The first category of cross development environment is called
428 @emph{emulation}. There are two primary types of emulation, but both
429 types result in programs that run on the native host.
430
431 @cindex Software emulation
432 @cindex Software emulator
433 The first type is @emph{software emulation}. This form of cross
434 development environment involves a native program that when run on the
435 native host, is capable of interpreting, and in most aspects running, a
436 program intended for some other machine. This technique is typically
437 used when the other machine is either too expensive, too slow, too fast,
438 or not available, perhaps because it hasn't yet been built. The native,
439 interpreting program is called a @emph{software emulator}.
440
441 The @sc{gnu} Development Tools do not currently include any software
442 emulators. Some do exist and the @sc{gnu} Development Tools can be
443 configured to create simple cross development environments for with
444 these emulators. More on this later.
445
446 The second type of emulation is when source intended for some other
447 development environment is built into a program intended for the native
448 host. The concepts of operating system universes and hosted operating
449 systems are two such development environments.
450
451 The Cygnus Support Release of the @sc{gnu} Development Tools can be
452 configured for one such emulation at this time.
453
454 @example
455 ./configure sun4 -ansi
456 @end example
457
458 @cindex ANSI
459 @cindex X3J11
460 @noindent
461 will configure the source such that when built in a sun4 development
462 environment the resulting development environment is capable of building
463 sun4 programs from strictly conforming @sc{ANSI X3J11 C} source.
464 Remember that the environment used to build the tools determines the
465 machine on which this tools will run, so the resulting programs aren't
466 necessarily intended to run on a sun4, although they usually are. Also
467 note that the source for the @sc{gnu} tools is not strictly conforming
468 @sc{ansi} source so this configuration cannot be used to bootstrap the
469 @sc{gnu} tools.
470
471
472 @node Simple Cross Environments, Crossing Into Targets, Emulation Environments, A Walk Through
473 @section Simple Cross Environments
474
475 @example
476 ./configure sun4 -target=a29k
477 @end example
478
479 @noindent
480 will configure the tools such that when compiled in a sun4 development
481 environment the resulting development environment can be used to create
482 programs intended for an a29k. Again, this does not necessarily mean
483 that the new development environment can be run on a sun4. That would
484 depend on the development environment used to build these tools.
485
486 Earlier you saw how to configure the tools to build a native development
487 environment, that is, a development environment that runs on your sun4
488 and builds programs for your sun4. Let's pretend that you use stage3 to
489 build this simple cross configuration and let's call the new development
490 environment gcc-a29k. Remember that this is a native build. Gcc-a29k
491 is a collection of native programs intended to run on your sun4. That's
492 what stage3 builds, programs for your sun4. Gcc-a29k represents an a29k
493 development environment that builds programs intended to run on an a29k.
494 But, remember, gcc-a29k runs on your sun4. Programs built with gcc-a29k
495 will run on your sun4 only with the help of an appropriate software
496 emulator.
497
498 @cindex Simple cross
499 @cindex Crossing to
500 Building gcc-a29k is also a bootstrap but of a slightly different sort.
501 We call gcc-a29k a @emph{simple cross} environment and using gcc-a29k to
502 build a program intended for a29k is called @emph{crossing to} a29k.
503 Simple cross environments are the second category of cross development
504 environments.
505
506
507 @node Crossing Into Targets, The Three Party Cross, Simple Cross Environments, A Walk Through
508 @section Crossing Into Targets
509
510 @example
511 ./configure a29k -target=a29k
512 @end example
513
514 @noindent
515 will configure the tools such that when compiled in an a29k development
516 environment, the resulting development environment can be used to create
517 programs intended for an a29k. Again, this does not necessarily mean
518 that the new development environment can be run on an a29k. That would
519 depend on the development environment used to build these tools.
520
521 If you've been following along this walk through, then you've already
522 built an a29k environment, namely gcc-a29k. Let's pretend you use
523 gcc-a29k to build the current configuration.
524
525 Gcc-a29k builds programs intended for the a29k so the new development
526 environment will be intended for use on an a29k. That is, this new gcc
527 consists of programs that are foreign to your sun4. They cannot be run
528 on your sun4.
529
530 @cindex Crossing into
531 The process of building this configuration is another a bootstrap. This
532 bootstrap is also a cross to a29k. Because this type of build is both a
533 bootstrap and a cross to a29k, it is sometimes referred to as a
534 @emph{cross into} a29k. This new development environment isn't really a
535 cross development environment at all. It is intended to run on an a29k
536 to produce programs for an a29k. You'll remember that this makes it, by
537 definition, an a29k native compiler. @emph{Crossing into} has been
538 introduced here not because it is a type of cross development
539 environment, but because it is frequently mistaken as one. The process
540 is @emph{a cross} but the resulting development environment is a native
541 development environment.
542
543 You could not have built this configuration with stage3, because stage3
544 doesn't provide an a29k environment. Instead it provides a sun4
545 environment.
546
547 If you happen to have an a29k lying around, you could now use this fresh
548 development environment on the a29k to three-stage these tools all over
549 again. This process would look just like it did when we built the
550 native sun4 development environment because we would be building another
551 native development environment, this one on a29k.
552
553
554 @node The Three Party Cross, , Crossing Into Targets, A Walk Through
555 @section The Three Party Cross
556
557 So far you've seen that our development environment source must be
558 configured for a specific host and for a specific target. You've also
559 seen that the resulting development environment depends on the
560 development environment used in the build process.
561
562 When all four match identically, that is, the configured host, the
563 configured target, the environment presented by the development
564 environment used in the build, and the machine on which the resulting
565 development environment is intended to run, then the new development
566 environment will be a native development environment.
567
568 When all four match except the configured host, then we can assume that
569 the development environment used in the build is some form of library
570 emulation.
571
572 When all four match except for the configured target, then the resulting
573 development environment will be a simple cross development environment.
574
575 When all four match except for the host on which the development
576 environment used in the build runs, the build process is a @emph{cross into}
577 and the resulting development environment will be native to some other
578 machine.
579
580 Most of the other permutations do exist in some form, but only one more
581 is interesting to the current discussion.
582
583 @example
584 ./configure a29k -target=sun3
585 @end example
586
587 @noindent
588 will configure the tools such that when compiled in an a29k development
589 environment, the resulting development environment can be used to create
590 programs intended for a sun3. Again, this does not necessarily mean
591 that the new development environment can be run on an a29k. That would
592 depend on the development environment used to build these tools.
593
594 If you are still following along, then you have two a29k development
595 environments, the native development environment that runs on a29k, and
596 the simple cross that runs on your sun4. If you use the a29k native
597 development environment on the a29k, you will be doing the same thing we
598 did a while back, namely building a simple cross from a29k to sun3.
599 Let's pretend that instead, you use gcc-a29k, the simple cross
600 development environment that runs on sun4 but produces programs for
601 a29k.
602
603 The resulting development environment will run on a29k because that's
604 what gcc-a29k builds, a29k programs. This development environment will
605 produce programs for a sun3 because that is how it was configured. This
606 means that the resulting development environment is a simple cross.
607
608 @cindex Three party cross
609 There really isn't a common name for this process because very few
610 development environments are capable of being configured this
611 extensively. For the sake of discussion, let's call this process a
612 @emph{three party cross}.
613
614 @node Final Notes, Index, A Walk Through, top
615 @chapter Final Notes
616
617 By @emph{configures}, I mean that links, Makefile, .gdbinit, and
618 config.status are built. Configuration is always done from the source
619 directory.
620
621 @table @code
622
623 @item ./configure @var{name}
624 configures this directory, perhaps recursively, for a single host+target
625 pair where the host and target are both @var{name}. If a previous
626 configuration existed, it will be overwritten.
627
628 @item ./configure @var{hostname} -target=@var{targetname}
629 configures this directory, perhaps recursively, for a single host+target
630 pair where the host is @var{hostname} and target is @var{targetname}.
631 If a previous configuration existed, it will be overwritten.
632
633 @item ./configure -subdirs @var{hostname} -target=@var{targetname}
634 creates a subdirectories @file{H-@var{hostname}} if @var{hostname} is @var{targetname} or
635 @file{X-@var{hostname}-@var{targetname}} if it is not and configures the new directory.
636
637 @end table
638
639 @menu
640 * Hacking Configurations:: Hacking Configurations
641 @end menu
642
643 @node Hacking Configurations, , Final Notes, Final Notes
644 @section Hacking Configurations
645
646 The configure scripts essentially do three things, create subdirectories
647 if appropriate, build a @file{Makefile}, and create links to files, all
648 based on and tailored to, a specific host+target pair. The scripts also
649 create a @file{.gdbinit} if appropriate but this is not tailored.
650
651 The Makefile is created by prepending some variable definitions to a
652 Makefile template called @file{Makefile.in} and then inserting host and
653 target specific Makefile fragments. The variables are set based on the
654 chosen host+target pair and build style, that is, if you use
655 subdirectories or not. The host and target specific Makefile may or may
656 not exist.
657
658 @itemize @bullet
659
660 @item
661 Makefiles can be edited directly, but those changes will eventually be
662 lost. Changes intended to be permanent for a specific host should be
663 made to the host specific Makefile fragment. This should be in
664 @file{./config/mh-@var{host}} if it exists. Changes intended to be
665 permanent for a specific target should be made to the target specific
666 Makefile fragment. This should be in @file{./config/mt-@var{target}} if
667 it exists. Changes intended to be permanent for the directory should be
668 made in @file{Makefile.in}. To propogate changes to any of these,
669 either use @code{make Makefile} or @code{./config.status} or
670 re-configure.
671
672 @end itemize
673
674 @page
675 @node Index, , Final Notes, top
676 @appendix Index
677
678 @printindex cp
679
680 @contents
681 @bye
682
683 @c Local Variables:
684 @c fill-column: 72
685 @c End: