2005-08-08 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> (tiny change)
[gnulib.git] / README
1 GNULib
2 ======
3
4 GNULib is intended to be the canonical source for most of the important
5 "Portability" files for GNU projects.
6
7 While portability is not one of our primary goals, it has helped
8 introduce many people to the GNU system, and is worthwhile when it can
9 be achieved at a low cost.  This collection helps lower that cost.
10
11 There are three directories that contain all of the files:
12
13 gpl/   - Any source files licensed under the GNU General Public License
14 lgpl/  - Any source files licensed under the GNU Lesser GPL
15 doc/   - Any documents that may be nice to have in applications.  This
16 includes such files as 'COPYING, COPYING.LIB, etc.'
17
18 Contributing to GNULib
19 ======================
20
21 All software here is Copyright (c) Free Software Foundation - you need
22 to have filled out an assignment form for a project that uses the
23 module for that contribution to be accepted here.
24
25 If you have a piece of code that you would like to contribute, please
26 email bug-gnulib@gnu.org.  We will add you to the maintainers list.
27
28 Generally we are looking for files that fulfill at least one of the
29 following requirements:
30
31     * If your .c and .h files define functions that are broken or
32 missing on some other system, we should be able to include it.
33
34     * If your functions remove arbitrary limits from existing
35 functions (either under the same name, or as a slightly different
36 name), we should be able to include it.
37
38 If your functions define completely new but rarely used functionality,
39 you should probably consider packaging it as a separate library.
40
41 License
42 -------
43
44 GNULib contains code both under GPL and LGPL.  Because several packages
45 that use GNULib are GPL, the files state they are licensed under GPL.
46 However, to support LGPL projects as well, you may use some of the
47 files under LGPL.  The "License:" information in the files under
48 modules/ clarifies the real license that applies to the module source.
49
50 Keep in mind that if you submit patches to files in GNULib, you should
51 license them under a compatible license, which means that sometimes
52 the contribution will have to be LGPL, if the original file is
53 available under LGPL via a "License: LGPL" information in the
54 projects' modules/ file.
55
56 How to add a new module
57 -----------------------
58
59 * Add the header files and source files to lib/.
60 * If the module needs configure-time checks, write an autoconf
61   macro for it in m4/<module>.m4. See m4/README for details.
62 * Write a module description modules/<module>, based on modules/TEMPLATE.
63 * Add the module to the list in MODULES.html.sh.
64
65 You can test that a module builds correctly with:
66   $ ./gnulib-tool --create-testdir --dir=/tmp/testdir module1 ... moduleN
67   $ cd /tmp/testdir
68   $ ./configure && make
69
70 Other things:
71 * Check the license and copyright year of headers.
72 * Check that the source code follows the GNU coding standards;
73   see <http://www.gnu.org/prep/standards>.
74 * Add source files to config/srclist* if they are identical to upstream
75   and should be upgraded in gnulib whenever the upstream source changes.
76 * Include header files in source files to verify the function prototypes.
77 * Make sure a replacement function doesn't cause warnings or clashes on
78   systems that have the function.
79 * Autoconf functions can use gl_* prefix. The AC_* prefix is for
80   autoconf internal functions.
81 * Build files only if they are needed on a platform.  Look at the
82   alloca and fnmatch modules for how to achieve this.  If for some
83   reason you cannot do this, and you have a .c file that leads to an
84   empty .o file on some platforms (through some big #if around all the
85   code), then ensure that the compilation unit is not empty after
86   preprocessing.  One way to do this is to #include <stddef.h> or
87   <stdio.h> before the big #if.
88
89 Portability guidelines
90 ----------------------
91
92 GNULib code is intended to be portable to a wide variety of platforms,
93 not just GNU platforms.
94
95 Many GNULib modules exist so that applications need not worry about
96 undesirable variability in implementations.  For example, an
97 application that uses the 'malloc' module need not worry about (malloc
98 (0)) returning NULL on some Standard C platforms; and 'time_r' users
99 need not worry about localtime_r returning int (not char *) on some
100 platforms that predate POSIX 1003.1-2001.
101
102 Originally much of the GNULib code was portable to ancient hosts like
103 4.2BSD, but it is a maintenance hassle to maintain compatibility with
104 unused hosts, so currently we assume at least a freestanding C89
105 compiler, possibly operating with a C library that predates C89.  The
106 oldest environment currently ported to is probably SunOS 4 + GCC 1.x,
107 though we haven't tested this exact combination.  SunOS 4 last shipped
108 on 1998-09-30, and Sun dropped support for it on 2003-10-01, so at
109 some point we may start assuming a C89 library as well.
110
111 Because we assume a freestanding C89 compiler, GNULib code can include
112 <float.h>, <limits.h>, <stdarg.h>, and <stddef.h> unconditionally.  It
113 can also include hosted headers like <errno.h> that were present in
114 Unix Version 7 and are thus widely available.  Similarly, many modules
115 include <sys/types.h> even though it's not even in C99; that's OK
116 since <sys/types.h> has been around nearly forever.  <string.h> and
117 <stdlib.h> were not in Unix Version 7, so they weren't universally
118 available on ancient hosts, but they are both in SunOS 4 (the oldest
119 platform still in relatively-common use) so GNULib assumes them now.
120
121 Even if the include files exist, they may not conform to C89.
122 However, GCC has a "fixincludes" script that attempts to fix most
123 C89-conformance problems.  So GNULib currently assumes include files
124 largely conform to C89 or better.  People still using ancient hosts
125 should use fixincludes or fix their include files manually.
126
127 Even if the include files conform to C89, the library itself may not.
128 For example, SunOS 4's (free (NULL)) can dump core, so GNULib code
129 must avoid freeing a null pointer, even though C89 allows it.
130 You can work around some of these problems by requiring the relevant
131 modules, e.g., the GNULib 'free' module supplies a conforming 'free'.
132
133 The GNU coding standards allow one departure from strict C99: GNULib
134 code can assume that standard internal types like size_t are no wider
135 than 'long'.  POSIX 1003.1-2001 and the GNU coding standards both
136 require 'int' to be at least 32 bits wide, so GNULib code assumes this
137 as well.  GNULib code makes the following additional assumptions:
138
139  * Signed integer arithmetic is two's complement, without runtime
140    overflow checking.  This is the traditional behavior, and is
141    supported by C99 implementations that conform to ISO/IEC 10967-1
142    (LIA-1) and that define signed integer types as being modulo.
143
144  * There are no "holes" in integer values: all the bits of an integer
145    contribute to its value in the usual way.
146
147  * If two nonoverlapping objects have sizes S and T represented as
148    size_t values, then S + T cannot overflow.  This assumption is true
149    for all practical hosts with flat address spaces, but it is not
150    always true for hosts with segmented address spaces.
151
152  * If an existing object has size S, and if T is sufficiently small
153    (e.g., 8 KiB), then S + T cannot overflow.  Overflow in this case
154    would mean that the rest of your program fits into T bytes, which
155    can't happen in realistic flat-address-space hosts.
156
157  * Objects with all bits zero are treated as 0 or NULL.  For example,
158    memset (A, 0, sizeof A) initializes an array A of pointers to NULL.
159
160  * Adding zero to a null pointer does not change the pointer.
161    For example, 0 + (char *) NULL == (char *) NULL.
162
163 The above assumptions are not required by the C or POSIX standards but
164 hold on all practical porting targets that we're familiar with.  If
165 you have a porting target where these assumptions are not true, we'd
166 appreciate hearing of any fixes.  We need fixes that do not increase
167 runtime overhead on standard hosts and that are relatively easy to
168 maintain.
169
170 With the above caveats, GNULib code should port without problem to new
171 hosts, e.g., hosts conforming to C99 or to recent POSIX standards.
172 Hence GNULib code should avoid using constructs (e.g., undeclared
173 functions return 'int') that do not conform to C99.
174
175 High Quality
176 ============
177
178 We will be developing a testsuite for these applications.  The goal is
179 to have a 100% firm interface so that maintainers can feel free to
180 update to the code in CVS at *any* time and know that their
181 application will not break.  This means that before any change can be
182 committed to the repository, a test suite program must be produced
183 that exposes the bug for regression testing.  All experimental work
184 should be done on branches to help promote this.
185
186 CVS
187 ===
188
189 GNULib is available for anonymous checkout.  In any Bourne-shell the
190 following should work:
191
192 $ cvs -d :pserver:anoncvs@cvs.gnu.org:/cvsroot/gnulib login
193 (Just hit Enter or Return when prompt for a password)
194 $ cvs -d :pserver:anoncvs@cvs.gnu.org:/cvsroot/gnulib checkout gnulib
195
196
197 -----
198
199 Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
200
201 This program is free software; you can redistribute it and/or modify
202 it under the terms of the GNU General Public License as published by
203 the Free Software Foundation; either version 2, or (at your option)
204 any later version.
205
206 This program is distributed in the hope that it will be useful,
207 but WITHOUT ANY WARRANTY; without even the implied warranty of
208 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
209 GNU General Public License for more details.
210
211 You should have received a copy of the GNU General Public License
212 along with this program; if not, write to the Free Software Foundation,
213 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */