The GNU C library is written to be easily portable to a variety of machines and operating systems. Machine- and operating system-dependent functions are well separated to make it easy to add implementations for new machines or operating systems. This section describes the layout of the library source tree and explains the mechanisms used to select machine-dependent code to use.
All the machine-dependent and operating system-dependent files in the library are in the subdirectory `sysdeps' under the top-level library source directory. This directory contains a hierarchy of subdirectories (see section Layout of the `sysdeps' Directory Hierarchy).
Each subdirectory of `sysdeps' contains source files for a particular machine or operating system, or for a class of machine or operating system (for example, systems by a particular vendor, or all machines that use IEEE 754 floating-point format). A configuration specifies an ordered list of these subdirectories. Each subdirectory implicitly appends its parent directory to the list. For example, specifying the list `unix/bsd/vax' is equivalent to specifying the list `unix/bsd/vax unix/bsd unix'. A subdirectory can also specify that it implies other subdirectories which are not directly above it in the directory hierarchy. If the file `Implies' exists in a subdirectory, it lists other subdirectories of `sysdeps' which are appended to the list, appearing after the subdirectory containing the `Implies' file. Lines in an `Implies' file that begin with a `#' character are ignored as comments. For example, `unix/bsd/Implies' contains:
# BSD has Internet-related things. unix/inet
and `unix/Implies' contains:
posix
So the final list is `unix/bsd/vax unix/bsd unix/inet unix posix'.
`sysdeps' has two "special" subdirectories, called `generic'
and `stub'. These two are always implicitly appended to the list
of subdirectories (in that order), so you needn't put them in an
`Implies' file, and you should not create any subdirectories under
them intended to be new specific categories. `generic' is for
things that can be implemented in machine-independent C, using only
other machine-independent functions in the C library. `stub' is
for stub versions of functions which cannot be implemented on a
particular machine or operating system. The stub functions always
return an error, and set errno
to ENOSYS
(Function not
implemented). See section Error Reporting.
A source file is known to be system-dependent by its having a version in `generic' or `stub'; every generally-available function whose implementation is system-dependent in should have either a generic or stub implementation (there is no point in having both). Some rare functions are only useful on specific systems and aren't defined at all on others; these do not appear anywhere in the system-independent source code or makefiles (including the `generic' and `stub' directories), only in the system-dependent `Makefile' in the specific system's subdirectory.
If you come across a file that is in one of the main source directories (`string', `stdio', etc.), and you want to write a machine- or operating system-dependent version of it, move the file into `sysdeps/generic' and write your new implementation in the appropriate system-specific subdirectory. Note that if a file is to be system-dependent, it must not appear in one of the main source directories.
There are a few special files that may exist in each subdirectory of `sysdeps':
make
conditional directives based on the variable `subdir' (see above) to
select different sets of variables and rules for different sections of
the library. It can also set the make
variable
`sysdep-routines', to specify extra modules to be included in the
library. You should use `sysdep-routines' rather than adding
modules to `routines' because the latter is used in determining
what to distribute for each subdirectory of the main source tree.
Each makefile in a subdirectory in the ordered list of subdirectories to
be searched is included in order. Since several system-dependent
makefiles may be included, each should append to `sysdep-routines'
rather than simply setting it:
sysdep-routines := $(sysdep-routines) foo bar
.
command to
read the `configure' file in each system-dependent directory
chosen, in order. The `configure' files are often generated from
`configure.in' files using Autoconf.
A system-dependent `configure' script will usually add things to
the shell variables `DEFS' and `config_vars'; see the
top-level `configure' script for details. The script can check for
`--with-package' options that were passed to the
top-level `configure'. For an option
`--with-package=value' `configure' sets the
shell variable `with_package' (with any dashes in
package converted to underscores) to value; if the option is
just `--with-package' (no argument), then it sets
`with_package' to `yes'.
m4
macro
`GLIBC_PROVIDES'. This macro does several AC_PROVIDE
calls
for Autoconf macros which are used by the top-level `configure'
script; without this, those macros might be invoked again unnecessarily
by Autoconf.
That is the general system for how system-dependencies are isolated. The next section explains how to decide what directories in `sysdeps' to use. section Porting the GNU C Library to Unix Systems, has some tips on porting the library to Unix variants.
Go to the first, previous, next, last section, table of contents.