Go to the first, previous, next, last section, table of contents.

Porting the GNU C Library

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.

and `unix/Implies' contains:


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':

A makefile for this machine or operating system, or class of machine or operating system. This file is included by the library makefile `Makerules', which is used by the top-level makefile and the subdirectory makefiles. It can change the variables set in the including makefile or add new rules. It can use GNU 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
This file contains the names of new whole subdirectories under the top-level library source tree that should be included for this system. These subdirectories are treated just like the system-independent subdirectories in the library source tree, such as `stdio' and `math'. Use this when there are completely new sets of functions and header files that should go into the library for the system this subdirectory of `sysdeps' implements. For example, `sysdeps/unix/inet/Subdirs' contains `inet'; the `inet' directory contains various network-oriented operations which only make sense to put in the library on systems that support the Internet.
This file contains the names of files (relative to the subdirectory of `sysdeps' in which it appears) which should be included in the distribution. List any new files used by rules in the `Makefile' in the same directory, or header files used by the source files in that directory. You don't need to list files that are implementations (either C or assembly source) of routines whose names are given in the machine-independent makefiles in the main source tree.
This file is a shell script fragment to be run at configuration time. The top-level `configure' script uses the shell . 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'.
This file is an Autoconf input fragment to be processed into the file `configure' in this subdirectory. See section `Introduction' in Autoconf: Generating Automatic Configuration Scripts, for a description of Autoconf. You should write either `configure' or `configure.in', but not both. The first line of `configure.in' should invoke the 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.