]> git.ipfire.org Git - thirdparty/glibc.git/blob - INSTALL
Update.
[thirdparty/glibc.git] / INSTALL
1 Library Maintenance
2 *******************
3
4 Adding New Functions
5 ====================
6
7 The process of building the library is driven by the makefiles, which
8 make heavy use of special features of GNU `make'. The makefiles are
9 very complex, and you probably don't want to try to understand them.
10 But what they do is fairly straightforward, and only requires that you
11 define a few variables in the right places.
12
13 The library sources are divided into subdirectories, grouped by
14 topic.
15
16 The `string' subdirectory has all the string-manipulation functions,
17 `math' has all the mathematical functions, etc.
18
19 Each subdirectory contains a simple makefile, called `Makefile',
20 which defines a few `make' variables and then includes the global
21 makefile `Rules' with a line like:
22
23 include ../Rules
24
25 The basic variables that a subdirectory makefile defines are:
26
27 `subdir'
28 The name of the subdirectory, for example `stdio'. This variable
29 *must* be defined.
30
31 `headers'
32 The names of the header files in this section of the library, such
33 as `stdio.h'.
34
35 `routines'
36 `aux'
37 The names of the modules (source files) in this section of the
38 library. These should be simple names, such as `strlen' (rather
39 than complete file names, such as `strlen.c'). Use `routines' for
40 modules that define functions in the library, and `aux' for
41 auxiliary modules containing things like data definitions. But the
42 values of `routines' and `aux' are just concatenated, so there
43 really is no practical difference.
44
45 `tests'
46 The names of test programs for this section of the library. These
47 should be simple names, such as `tester' (rather than complete file
48 names, such as `tester.c'). `make tests' will build and run all
49 the test programs. If a test program needs input, put the test
50 data in a file called `TEST-PROGRAM.input'; it will be given to
51 the test program on its standard input. If a test program wants
52 to be run with arguments, put the arguments (all on a single line)
53 in a file called `TEST-PROGRAM.args'. Test programs should exit
54 with zero status when the test passes, and nonzero status when the
55 test indicates a bug in the library or error in building.
56
57 `others'
58 The names of "other" programs associated with this section of the
59 library. These are programs which are not tests per se, but are
60 other small programs included with the library. They are built by
61 `make others'.
62
63 `install-lib'
64 `install-data'
65 `install'
66 Files to be installed by `make install'. Files listed in
67 `install-lib' are installed in the directory specified by `libdir'
68 in `configparms' or `Makeconfig' (*note Installation::.). Files
69 listed in `install-data' are installed in the directory specified
70 by `datadir' in `configparms' or `Makeconfig'. Files listed in
71 `install' are installed in the directory specified by `bindir' in
72 `configparms' or `Makeconfig'.
73
74 `distribute'
75 Other files from this subdirectory which should be put into a
76 distribution tar file. You need not list here the makefile itself
77 or the source and header files listed in the other standard
78 variables. Only define `distribute' if there are files used in an
79 unusual way that should go into the distribution.
80
81 `generated'
82 Files which are generated by `Makefile' in this subdirectory.
83 These files will be removed by `make clean', and they will never
84 go into a distribution.
85
86 `extra-objs'
87 Extra object files which are built by `Makefile' in this
88 subdirectory. This should be a list of file names like `foo.o';
89 the files will actually be found in whatever directory object
90 files are being built in. These files will be removed by
91 `make clean'. This variable is used for secondary object files
92 needed to build `others' or `tests'.
93
94 Porting the GNU C Library
95 =========================
96
97 The GNU C library is written to be easily portable to a variety of
98 machines and operating systems. Machine- and operating system-dependent
99 functions are well separated to make it easy to add implementations for
100 new machines or operating systems. This section describes the layout of
101 the library source tree and explains the mechanisms used to select
102 machine-dependent code to use.
103
104 All the machine-dependent and operating system-dependent files in the
105 library are in the subdirectory `sysdeps' under the top-level library
106 source directory. This directory contains a hierarchy of
107 subdirectories (*note Hierarchy Conventions::.).
108
109 Each subdirectory of `sysdeps' contains source files for a
110 particular machine or operating system, or for a class of machine or
111 operating system (for example, systems by a particular vendor, or all
112 machines that use IEEE 754 floating-point format). A configuration
113 specifies an ordered list of these subdirectories. Each subdirectory
114 implicitly appends its parent directory to the list. For example,
115 specifying the list `unix/bsd/vax' is equivalent to specifying the list
116 `unix/bsd/vax unix/bsd unix'. A subdirectory can also specify that it
117 implies other subdirectories which are not directly above it in the
118 directory hierarchy. If the file `Implies' exists in a subdirectory,
119 it lists other subdirectories of `sysdeps' which are appended to the
120 list, appearing after the subdirectory containing the `Implies' file.
121 Lines in an `Implies' file that begin with a `#' character are ignored
122 as comments. For example, `unix/bsd/Implies' contains:
123 # BSD has Internet-related things.
124 unix/inet
125
126 and `unix/Implies' contains:
127 posix
128
129 So the final list is `unix/bsd/vax unix/bsd unix/inet unix posix'.
130
131 `sysdeps' has a "special" subdirectory called `generic'. It is
132 always implicitly appended to the list of subdirectories, so you
133 needn't put it in an `Implies' file, and you should not create any
134 subdirectories under it intended to be new specific categories.
135 `generic' serves two purposes. First, the makefiles do not bother to
136 look for a system-dependent version of a file that's not in `generic'.
137 This means that any system-dependent source file must have an analogue
138 in `generic', even if the routines defined by that file are not
139 implemented on other platforms. Second. the `generic' version of a
140 system-dependent file is used if the makefiles do not find a version
141 specific to the system you're compiling for.
142
143 If it is possible to implement the routines in a `generic' file in
144 machine-independent C, using only other machine-independent functions in
145 the C library, then you should do so. Otherwise, make them stubs. A
146 "stub" function is a function which cannot be implemented on a
147 particular machine or operating system. Stub functions always return an
148 error, and set `errno' to `ENOSYS' (Function not implemented). *Note
149 Error Reporting::. If you define a stub function, you must place the
150 statement `stub_warning(FUNCTION)', where FUNCTION is the name of your
151 function, after its definition; also, you must include the file
152 `<stub-tag.h>' into your file. This causes the function to be listed
153 in the installed `<gnu/stubs.h>', and makes GNU ld warn when the
154 function is used.
155
156 Some rare functions are only useful on specific systems and aren't
157 defined at all on others; these do not appear anywhere in the
158 system-independent source code or makefiles (including the `generic'
159 directory), only in the system-dependent `Makefile' in the specific
160 system's subdirectory.
161
162 If you come across a file that is in one of the main source
163 directories (`string', `stdio', etc.), and you want to write a machine-
164 or operating system-dependent version of it, move the file into
165 `sysdeps/generic' and write your new implementation in the appropriate
166 system-specific subdirectory. Note that if a file is to be
167 system-dependent, it *must not* appear in one of the main source
168 directories.
169
170 There are a few special files that may exist in each subdirectory of
171 `sysdeps':
172
173 `Makefile'
174 A makefile for this machine or operating system, or class of
175 machine or operating system. This file is included by the library
176 makefile `Makerules', which is used by the top-level makefile and
177 the subdirectory makefiles. It can change the variables set in the
178 including makefile or add new rules. It can use GNU `make'
179 conditional directives based on the variable `subdir' (see above)
180 to select different sets of variables and rules for different
181 sections of the library. It can also set the `make' variable
182 `sysdep-routines', to specify extra modules to be included in the
183 library. You should use `sysdep-routines' rather than adding
184 modules to `routines' because the latter is used in determining
185 what to distribute for each subdirectory of the main source tree.
186
187 Each makefile in a subdirectory in the ordered list of
188 subdirectories to be searched is included in order. Since several
189 system-dependent makefiles may be included, each should append to
190 `sysdep-routines' rather than simply setting it:
191
192 sysdep-routines := $(sysdep-routines) foo bar
193
194 `Subdirs'
195 This file contains the names of new whole subdirectories under the
196 top-level library source tree that should be included for this
197 system. These subdirectories are treated just like the
198 system-independent subdirectories in the library source tree, such
199 as `stdio' and `math'.
200
201 Use this when there are completely new sets of functions and header
202 files that should go into the library for the system this
203 subdirectory of `sysdeps' implements. For example,
204 `sysdeps/unix/inet/Subdirs' contains `inet'; the `inet' directory
205 contains various network-oriented operations which only make sense
206 to put in the library on systems that support the Internet.
207
208 `Dist'
209 This file contains the names of files (relative to the
210 subdirectory of `sysdeps' in which it appears) which should be
211 included in the distribution. List any new files used by rules in
212 the `Makefile' in the same directory, or header files used by the
213 source files in that directory. You don't need to list files that
214 are implementations (either C or assembly source) of routines
215 whose names are given in the machine-independent makefiles in the
216 main source tree.
217
218 `configure'
219 This file is a shell script fragment to be run at configuration
220 time. The top-level `configure' script uses the shell `.' command
221 to read the `configure' file in each system-dependent directory
222 chosen, in order. The `configure' files are often generated from
223 `configure.in' files using Autoconf.
224
225 A system-dependent `configure' script will usually add things to
226 the shell variables `DEFS' and `config_vars'; see the top-level
227 `configure' script for details. The script can check for
228 `--with-PACKAGE' options that were passed to the top-level
229 `configure'. For an option `--with-PACKAGE=VALUE' `configure'
230 sets the shell variable `with_PACKAGE' (with any dashes in PACKAGE
231 converted to underscores) to VALUE; if the option is just
232 `--with-PACKAGE' (no argument), then it sets `with_PACKAGE' to
233 `yes'.
234
235 `configure.in'
236 This file is an Autoconf input fragment to be processed into the
237 file `configure' in this subdirectory. *Note Introduction:
238 (autoconf.info)Introduction, for a description of Autoconf. You
239 should write either `configure' or `configure.in', but not both.
240 The first line of `configure.in' should invoke the `m4' macro
241 `GLIBC_PROVIDES'. This macro does several `AC_PROVIDE' calls for
242 Autoconf macros which are used by the top-level `configure'
243 script; without this, those macros might be invoked again
244 unnecessarily by Autoconf.
245
246 That is the general system for how system-dependencies are isolated.
247
248 Layout of the `sysdeps' Directory Hierarchy
249 -------------------------------------------
250
251 A GNU configuration name has three parts: the CPU type, the
252 manufacturer's name, and the operating system. `configure' uses these
253 to pick the list of system-dependent directories to look for. If the
254 `--nfp' option is *not* passed to `configure', the directory
255 `MACHINE/fpu' is also used. The operating system often has a "base
256 operating system"; for example, if the operating system is `Linux', the
257 base operating system is `unix/sysv'. The algorithm used to pick the
258 list of directories is simple: `configure' makes a list of the base
259 operating system, manufacturer, CPU type, and operating system, in that
260 order. It then concatenates all these together with slashes in
261 between, to produce a directory name; for example, the configuration
262 `i686-linux-gnu' results in `unix/sysv/linux/i386/i686'. `configure'
263 then tries removing each element of the list in turn, so
264 `unix/sysv/linux' and `unix/sysv' are also tried, among others. Since
265 the precise version number of the operating system is often not
266 important, and it would be very inconvenient, for example, to have
267 identical `irix6.2' and `irix6.3' directories, `configure' tries
268 successively less specific operating system names by removing trailing
269 suffixes starting with a period.
270
271 As an example, here is the complete list of directories that would be
272 tried for the configuration `i686-linux-gnu' (with the `crypt' and
273 `linuxthreads' add-on):
274
275 sysdeps/i386/elf
276 crypt/sysdeps/unix
277 linuxthreads/sysdeps/unix/sysv/linux
278 linuxthreads/sysdeps/pthread
279 linuxthreads/sysdeps/unix/sysv
280 linuxthreads/sysdeps/unix
281 linuxthreads/sysdeps/i386/i686
282 linuxthreads/sysdeps/i386
283 linuxthreads/sysdeps/pthread/no-cmpxchg
284 sysdeps/unix/sysv/linux/i386
285 sysdeps/unix/sysv/linux
286 sysdeps/gnu
287 sysdeps/unix/common
288 sysdeps/unix/mman
289 sysdeps/unix/inet
290 sysdeps/unix/sysv/i386/i686
291 sysdeps/unix/sysv/i386
292 sysdeps/unix/sysv
293 sysdeps/unix/i386
294 sysdeps/unix
295 sysdeps/posix
296 sysdeps/i386/i686
297 sysdeps/i386/i486
298 sysdeps/libm-i387/i686
299 sysdeps/i386/fpu
300 sysdeps/libm-i387
301 sysdeps/i386
302 sysdeps/wordsize-32
303 sysdeps/ieee754
304 sysdeps/libm-ieee754
305 sysdeps/generic
306
307 Different machine architectures are conventionally subdirectories at
308 the top level of the `sysdeps' directory tree. For example,
309 `sysdeps/sparc' and `sysdeps/m68k'. These contain files specific to
310 those machine architectures, but not specific to any particular
311 operating system. There might be subdirectories for specializations of
312 those architectures, such as `sysdeps/m68k/68020'. Code which is
313 specific to the floating-point coprocessor used with a particular
314 machine should go in `sysdeps/MACHINE/fpu'.
315
316 There are a few directories at the top level of the `sysdeps'
317 hierarchy that are not for particular machine architectures.
318
319 `generic'
320 As described above (*note Porting::.), this is the subdirectory
321 that every configuration implicitly uses after all others.
322
323 `ieee754'
324 This directory is for code using the IEEE 754 floating-point
325 format, where the C type `float' is IEEE 754 single-precision
326 format, and `double' is IEEE 754 double-precision format. Usually
327 this directory is referred to in the `Implies' file in a machine
328 architecture-specific directory, such as `m68k/Implies'.
329
330 `libm-ieee754'
331 This directory contains an implementation of a mathematical library
332 usable on platforms which use IEEE 754 conformant floating-point
333 arithmetic.
334
335 `libm-i387'
336 This is a special case. Ideally the code should be in
337 `sysdeps/i386/fpu' but for various reasons it is kept aside.
338
339 `posix'
340 This directory contains implementations of things in the library in
341 terms of POSIX.1 functions. This includes some of the POSIX.1
342 functions themselves. Of course, POSIX.1 cannot be completely
343 implemented in terms of itself, so a configuration using just
344 `posix' cannot be complete.
345
346 `unix'
347 This is the directory for Unix-like things. *Note Porting to
348 Unix::. `unix' implies `posix'. There are some special-purpose
349 subdirectories of `unix':
350
351 `unix/common'
352 This directory is for things common to both BSD and System V
353 release 4. Both `unix/bsd' and `unix/sysv/sysv4' imply
354 `unix/common'.
355
356 `unix/inet'
357 This directory is for `socket' and related functions on Unix
358 systems. `unix/inet/Subdirs' enables the `inet' top-level
359 subdirectory. `unix/common' implies `unix/inet'.
360
361 `mach'
362 This is the directory for things based on the Mach microkernel
363 from CMU (including the GNU operating system). Other basic
364 operating systems (VMS, for example) would have their own
365 directories at the top level of the `sysdeps' hierarchy, parallel
366 to `unix' and `mach'.
367
368 Porting the GNU C Library to Unix Systems
369 -----------------------------------------
370
371 Most Unix systems are fundamentally very similar. There are
372 variations between different machines, and variations in what
373 facilities are provided by the kernel. But the interface to the
374 operating system facilities is, for the most part, pretty uniform and
375 simple.
376
377 The code for Unix systems is in the directory `unix', at the top
378 level of the `sysdeps' hierarchy. This directory contains
379 subdirectories (and subdirectory trees) for various Unix variants.
380
381 The functions which are system calls in most Unix systems are
382 implemented in assembly code, which is generated automatically from
383 specifications in files named `syscalls.list'. There are several such
384 files, one in `sysdeps/unix' and others in its subdirectories. Some
385 special system calls are implemented in files that are named with a
386 suffix of `.S'; for example, `_exit.S'. Files ending in `.S' are run
387 through the C preprocessor before being fed to the assembler.
388
389 These files all use a set of macros that should be defined in
390 `sysdep.h'. The `sysdep.h' file in `sysdeps/unix' partially defines
391 them; a `sysdep.h' file in another directory must finish defining them
392 for the particular machine and operating system variant. See
393 `sysdeps/unix/sysdep.h' and the machine-specific `sysdep.h'
394 implementations to see what these macros are and what they should do.
395
396 The system-specific makefile for the `unix' directory
397 (`sysdeps/unix/Makefile') gives rules to generate several files from
398 the Unix system you are building the library on (which is assumed to be
399 the target system you are building the library *for*). All the
400 generated files are put in the directory where the object files are
401 kept; they should not affect the source tree itself. The files
402 generated are `ioctls.h', `errnos.h', `sys/param.h', and `errlist.c'
403 (for the `stdio' section of the library).
404