doc: move README into manual
[gnulib.git] / doc / gnulib-readme.texi
1 @c Gnulib README
2
3 @c Copyright 2001, 2003-2012 Free Software Foundation, Inc.
4
5 @c Permission is granted to copy, distribute and/or modify this document
6 @c under the terms of the GNU Free Documentation License, Version 1.3
7 @c or any later version published by the Free Software Foundation;
8 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9 @c Texts.  A copy of the license is included in the ``GNU Free
10 @c Documentation License'' file as part of this distribution.
11
12 @menu
13 * Gnulib Basics::
14 * git and CVS::
15 * Keeping Up-to-date::
16 * Contributing to Gnulib::
17 * High Quality::
18 @end menu
19
20 @node Gnulib Basics
21 @section Gnulib Basics
22
23 While portability across operating systems is not one of GNU's primary
24 goals, it has helped introduce many people to the GNU system, and is
25 worthwhile when it can be achieved at a low cost.  This collection helps
26 lower that cost.
27
28 Gnulib is intended to be the canonical source for most of the important
29 ``portability'' and/or common files for GNU projects.  These are files
30 intended to be shared at the source level; Gnulib is not a typical
31 library meant to be installed and linked against.  Thus, unlike most
32 projects, Gnulib does not normally generate a source tarball
33 distribution; instead, developers grab modules directly from the
34 source repository.
35
36 The easiest, and recommended, way to do this is to use the
37 @command{gnulib-tool} script.  Since there is no installation
38 procedure for Gnulib, @command{gnulib-tool} needs to be run directly
39 in the directory that contains the Gnulib source code.  You can do
40 this either by specifying the absolute filename of
41 @command{gnulib-tool}, or by using a symbolic link from a place inside
42 your @env{PATH} to the @command{gnulib-tool} file of your preferred
43 Gnulib checkout.  For example:
44
45 @example
46 $ ln -s $HOME/gnu/src/gnulib.git/gnulib-tool $HOME/bin/gnulib-tool
47 @end example
48
49 The home page for Gnulib is @url{http://www.gnu.org/software/gnulib}.
50
51 @node git and CVS
52 @section git and CVS
53
54 Gnulib is available for anonymous checkout.  In any Bourne-shell the
55 following should work:
56
57 @example
58 $ git clone git://git.sv.gnu.org/gnulib.git
59 @end example
60
61 For a read-write checkout you need to have a login on
62 @samp{savannah.gnu.org} and be a member of the Gnulib project at
63 @url{http://savannah.gnu.org/projects/gnulib}.  Then, instead of the
64 URL @url{git://git.sv.gnu.org/gnulib}, use the URL
65 @samp{ssh://@var{user}@@git.sv.gnu.org/srv/git/gnulib} where
66 @var{user} is your login name on savannah.gnu.org.
67
68 git resources:
69
70 @table @asis
71 @item Overview:
72 @url{http://en.wikipedia.org/wiki/Git_(software)}
73 @item Homepage:
74 @url{http://git.or.cz/}
75 @item Download:
76 @url{http://www.kernel.org/pub/software/scm/git/}
77 @item Tutorial:
78 @url{http://git.or.cz/course/}
79 @url{http://www.kernel.org/pub/software/scm/git/docs/tutorial.html}
80 @item FAQ:
81 @url{http://git.or.cz/gitwiki/GitFaq}
82 @end table
83
84 When you use @code{git annotate} or @code{git blame} with Gnulib, it's
85 recommended that you use the @option{-w} option, in order to ignore
86 massive whitespace changes that happened in 2009.
87
88 CVS checkouts are also supported:
89
90 @example
91 $ cvs -d :pserver:anonymous@@pserver.git.sv.gnu.org:/gnulib.git co -d gnulib HEAD
92 @end example
93
94 Gnulib is hosted on @samp{savannah.gnu.org}.  The project page is
95 @url{http://savannah.gnu.org/projects/gnulib}.
96
97 @node Keeping Up-to-date
98 @section Keeping Up-to-date
99
100 The best way to work with Gnulib is to check it out of git.
101 Subscribing to the @email{bug-gnulib@@gnu.org} mailing list will help you to
102 plan when to update your local copy of Gnulib (which you use to
103 maintain your software) from git.  To synchronize, you can use @code{git pull},
104 or @code{cvs update -dP} if you are still using CVS.
105
106 Sometimes, using an updated version of Gnulib will require you to use
107 newer versions of GNU Automake or Autoconf.  You may find it helpful
108 to join the autotools-announce mailing list to be advised of such
109 changes.
110
111 @node Contributing to Gnulib
112 @section Contributing to Gnulib
113
114 All software here is copyrighted by the Free Software Foundation---you need
115 to have filled out an assignment form for a project that uses the
116 module for that contribution to be accepted here.
117
118 If you have a piece of code that you would like to contribute, please
119 email @email{bug-gnulib@@gnu.org}.  You can review the archives,
120 subscribe, etc., via
121 @url{http://lists.gnu.org/mailman/listinfo/bug-gnulib}.
122
123 Generally we are looking for files that fulfill at least one of the
124 following requirements:
125
126 @itemize
127 @item
128 If your @file{.c} and @file{.h} files define functions that are broken or
129 missing on some other system, we should be able to include it.
130
131 @item
132 If your functions remove arbitrary limits from existing
133 functions (either under the same name, or as a slightly different
134 name), we should be able to include it.
135 @end itemize
136
137 If your functions define completely new but rarely used functionality,
138 you should probably consider packaging it as a separate library.
139
140 @menu
141 * Gnulib licensing::
142 * Indent with spaces not TABs::
143 * How to add a new module::
144 * Portability guidelines::
145 @end menu
146
147 @node Gnulib licensing
148 @subsection Gnulib licensing
149
150 Gnulib contains code both under GPL and LGPL@.  Because several packages
151 that use Gnulib are GPL, the files state they are licensed under GPL@.
152 However, to support LGPL projects as well, you may use some of the
153 files under LGPL@.  The ``License:'' information in the files under
154 modules/ clarifies the real license that applies to the module source.
155
156 Keep in mind that if you submit patches to files in Gnulib, you should
157 license them under a compatible license, which means that sometimes
158 the contribution will have to be LGPL, if the original file is
159 available under LGPL via a ``License: LGPL'' information in the
160 projects' modules/ file.
161
162 @node Indent with spaces not TABs
163 @subsection Indent with spaces not TABs
164
165 We use space-only indentation in nearly all files. This includes all
166 @file{*.h}, @file{*.c}, @file{*.y} files, except for the @code{regex}
167 module. Makefile and ChangeLog files are excluded, since TAB
168 characters are part of their format.
169
170 In order to tell your editor to produce space-only indentation, you
171 can use these instructions.
172
173 @itemize
174 @item
175 For Emacs: Add these lines to your Emacs initialization file
176 (@file{$HOME/.emacs} or similar):
177
178 @example
179 ;; In Gnulib, indent with spaces everywhere (not TABs).
180 ;; Exceptions: Makefile and ChangeLog modes.
181 (add-hook 'find-file-hook '(lambda ()
182   (if (and buffer-file-name
183            (string-match "/gnulib\\>" (buffer-file-name))
184            (not (string-equal mode-name "Change Log"))
185            (not (string-equal mode-name "Makefile")))
186       (setq indent-tabs-mode nil))))
187 @end example
188
189 @item
190 For vi (vim): Add these lines to your @file{$HOME/.vimrc} file:
191
192 @example
193 " Don't use tabs for indentation. Spaces are nicer to work with.
194 set expandtab
195 @end example
196
197 For Makefile and ChangeLog files, compensate this by adding this to
198 your @file{$HOME/.vim/after/indent/make.vim} and
199 @file{$HOME/.vim/after/indent/changelog.vim} files:
200
201 @example
202 " Use tabs for indentation, regardless of the global setting.
203 set noexpandtab
204 @end example
205
206 @item
207 For Eclipse: In the ``Window|Preferences'' dialog (or ``Eclipse|Preferences''
208 dialog on Mac OS),
209
210 @enumerate
211 @item
212 Under ``General|Editors|Text Editors'', select the ``Insert spaces for tabs''
213 checkbox.
214
215 @item
216 Under ``C/C++|Code Style'', select a code style profile that has the
217 ``Indentation|Tab policy'' combobox set to ``Spaces only'', such as the
218 ``GNU [built-in]'' policy.
219 @end enumerate
220
221 If you use the GNU indent program, pass it the option @option{--no-tabs}.
222 @end itemize
223
224 @node How to add a new module
225 @subsection How to add a new module
226
227 @itemize
228 @item
229 Add the header files and source files to @file{lib/}.
230
231 @item
232 If the module needs configure-time checks, write an Autoconf
233 macro for it in @file{m4/@var{module}.m4}. See @file{m4/README} for details.
234
235 @item
236 Write a module description @file{modules/@var{module}}, based on
237 @file{modules/TEMPLATE}.
238
239 @item
240 If the module contributes a section to the end-user documentation,
241 put this documentation in @file{doc/@var{module}.texi} and add it to the ``Files''
242 section of @file{modules/@var{module}}.  Most modules don't do this; they have only
243 documentation for the programmer (= Gnulib user).  Such documentation
244 usually goes into the @file{lib/} source files.  It may also go into @file{doc/};
245 but don't add it to the module description in this case.
246
247 @item
248 Add the module to the list in @file{MODULES.html.sh}.
249 @end itemize
250
251 @noindent
252 You can test that a module builds correctly with:
253
254 @example
255 $ ./gnulib-tool --create-testdir --dir=/tmp/testdir module1 ... moduleN
256 $ cd /tmp/testdir
257 $ ./configure && make
258 @end example
259
260 @noindent
261 Other things:
262
263 @itemize
264 @item
265 Check the license and copyright year of headers.
266
267 @item
268 Check that the source code follows the GNU coding standards;
269 see @url{http://www.gnu.org/prep/standards}.
270
271 @item
272 Add source files to @file{config/srclist*} if they are identical to upstream
273 and should be upgraded in Gnulib whenever the upstream source changes.
274
275 @item
276 Include header files in source files to verify the function prototypes.
277
278 @item
279 Make sure a replacement function doesn't cause warnings or clashes on
280 systems that have the function.
281
282 @item
283 Autoconf functions can use @samp{gl_*} prefix. The @samp{AC_*} prefix is for
284 autoconf internal functions.
285
286 @item
287 Build files only if they are needed on a platform.  Look at the
288 @code{alloca} and @code{fnmatch} modules for how to achieve this.  If
289 for some reason you cannot do this, and you have a @file{.c} file that
290 leads to an empty @file{.o} file on some platforms (through some big
291 @code{#if} around all the code), then ensure that the compilation unit
292 is not empty after preprocessing.  One way to do this is to
293 @code{#include <stddef.h>} or @code{<stdio.h>} before the big
294 @code{#if}.
295 @end itemize
296
297 @node Portability guidelines
298 @subsection Portability guidelines
299
300 Gnulib code is intended to be portable to a wide variety of platforms,
301 not just GNU platforms.  See the documentation section ``Target Platforms''
302 for details.
303
304 Many Gnulib modules exist so that applications need not worry about
305 undesirable variability in implementations.  For example, an
306 application that uses the @code{malloc} module need not worry about
307 @code{malloc@ (0)} returning @code{NULL} on some Standard C
308 platforms; and @code{time_r} users need not worry about
309 @code{localtime_r} returning @code{int} (not @code{char@ *}) on some
310 platforms that predate POSIX 1003.1-2001.
311
312 Currently we assume at least a freestanding C89 compiler, possibly
313 operating with a C library that predates C89.  The oldest environments
314 currently ported to are probably HP-UX 10.20 and IRIX 5.3, though we
315 are not testing these platforms very often.
316
317 Because we assume a freestanding C89 compiler, Gnulib code can include
318 @code{<float.h>}, @code{<limits.h>}, @code{<stdarg.h>}, and
319 @code{<stddef.h>} unconditionally.  It can also assume the existence
320 of @code{<ctime.h>}, @code{<errno.h>}, @code{<fcntl.h>},
321 @code{<locale.h>}, @code{<signal.h>}, @code{<stdio.h>},
322 @code{<stdlib.h>}, @code{<string.h>}, and @code{<time.h>}.  Similarly,
323 many modules include @code{<sys/types.h>} even though it's not even in
324 C99; that's OK since @code{<sys/types.h>} has been around nearly
325 forever.
326
327 Even if the include files exist, they may not conform to C89.
328 However, GCC has a @command{fixincludes} script that attempts to fix most
329 C89-conformance problems.  So Gnulib currently assumes include files
330 largely conform to C89 or better.  People still using ancient hosts
331 should use fixincludes or fix their include files manually.
332
333 Even if the include files conform to C89, the library itself may not.
334 For example, @code{strtod} and @code{mktime} have some bugs on some platforms.
335 You can work around some of these problems by requiring the relevant
336 modules, e.g., the Gnulib @code{mktime} module supplies a working and
337 conforming @code{mktime}.
338
339 The GNU coding standards allow one departure from strict C99: Gnulib
340 code can assume that standard internal types like @code{size_t} are no wider
341 than @code{long}.  POSIX 1003.1-2001 and the GNU coding standards both
342 require @code{int} to be at least 32 bits wide, so Gnulib code assumes this
343 as well.  Gnulib code makes the following additional assumptions:
344
345 @itemize
346 @item
347 Signed integer arithmetic is two's complement.
348
349 Previously, Gnulib code sometimes assumed that signed integer
350 arithmetic wraps around, but modern compiler optimizations
351 sometimes do not guarantee this, and Gnulib code with this
352 assumption is now considered to be questionable.
353 @xref{Integer Properties}.
354
355 Some Gnulib modules contain explicit support for the other signed
356 integer representations allowed by C99 (ones' complement and signed
357 magnitude), but these modules are the exception rather than the rule.
358 All practical Gnulib targets use two's complement.
359
360 @item
361 There are no ``holes'' in integer values: all the bits of an integer
362 contribute to its value in the usual way.
363
364 @item
365 Addresses and sizes behave as if objects reside in a flat address space.
366 In particular:
367
368 @itemize
369 @item
370 If two nonoverlapping objects have sizes @var{S} and @var{T} represented as
371 @code{size_t} values, then @code{@var{S} + @var{T}} cannot overflow.
372
373 @item
374 A pointer @var{P} points within an object @var{O} if and only if
375 @code{(char *) &@var{O} <= (char *) @var{P} && (char *) @var{P} <
376 (char *) (&@var{O} + 1)}.
377
378 @item
379 If an existing object has size @var{S}, and if @var{T} is sufficiently
380 small (e.g., 8 KiB), then @code{@var{S} + @var{T}} cannot overflow.
381 Overflow in this case would mean that the rest of your program fits
382 into @var{T} bytes, which can't happen in realistic flat-address-space
383 hosts.
384
385 @item
386 Objects with all bits zero are treated as 0 or NULL@.  For example,
387 @code{memset@ (A, 0, sizeof@ A)} initializes an array @code{A} of
388 pointers to NULL.
389
390 @item
391 Adding zero to a null pointer does not change the pointer.
392 For example, @code{0 + (char *) NULL == (char *) NULL}.
393 @end itemize
394 @end itemize
395
396 The above assumptions are not required by the C or POSIX standards but
397 hold on all practical porting targets that we're familiar with.  If
398 you have a porting target where these assumptions are not true, we'd
399 appreciate hearing of any fixes.  We need fixes that do not increase
400 runtime overhead on standard hosts and that are relatively easy to
401 maintain.
402
403 With the above caveats, Gnulib code should port without problem to new
404 hosts, e.g., hosts conforming to C99 or to recent POSIX standards.
405 Hence Gnulib code should avoid using constructs (e.g., undeclared
406 functions return @code{int}) that do not conform to C99.
407
408 @node High Quality
409 @section High Quality
410
411 We develop and maintain a testsuite for Gnulib.  The goal is to have a
412 100% firm interface so that maintainers can feel free to update to the
413 code in git at @emph{any} time and know that their application will not
414 break.  This means that before any change can be committed to the
415 repository, a test suite program must be produced that exposes the bug
416 for regression testing.  All experimental work should be done on
417 branches to help promote this.
418
419 @c This copyright notice applies to this file.
420 @c Generate it as output too, if the file is being formatted by itself.
421 @c Otherwise, it should be formatted as part of a larger document
422 @c that contains the relevant copyright notice.
423 @ifset standalone
424 Copyright @copyright{} 2001, 2003--2012 Free Software Foundation, Inc.
425
426 Permission is granted to copy, distribute and/or modify this document
427 under the terms of the GNU Free Documentation License, Version 1.3 or
428 any later version published by the Free Software Foundation; with no
429 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
430 Texts.  A copy of the license is included in the ``GNU Free
431 Documentation License'' file as part of this distribution.
432 @end ifset