windows-stat-override: New module.
[gnulib.git] / doc / gnulib-readme.texi
blob1422135f575361795a4aa4b19123a9552a8be226
1 @c Gnulib README
3 @c Copyright 2001, 2003-2017 Free Software Foundation, Inc.
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.
12 @menu
13 * Gnulib Basics::
14 * Git Checkout::
15 * Keeping Up-to-date::
16 * Contributing to Gnulib::
17 * Portability guidelines::
18 * High Quality::
19 @end menu
21 @node Gnulib Basics
22 @section Gnulib Basics
24 While portability across operating systems is not one of GNU's primary
25 goals, it has helped introduce many people to the GNU system, and is
26 worthwhile when it can be achieved at a low cost.  This collection helps
27 lower that cost.
29 Gnulib is intended to be the canonical source for most of the important
30 ``portability'' and/or common files for GNU projects.  These are files
31 intended to be shared at the source level; Gnulib is not a typical
32 library meant to be installed and linked against.  Thus, unlike most
33 projects, Gnulib does not normally generate a source tarball
34 distribution; instead, developers grab modules directly from the
35 source repository.
37 The easiest, and recommended, way to do this is to use the
38 @command{gnulib-tool} script.  Since there is no installation
39 procedure for Gnulib, @command{gnulib-tool} needs to be run directly
40 in the directory that contains the Gnulib source code.  You can do
41 this either by specifying the absolute filename of
42 @command{gnulib-tool}, or by using a symbolic link from a place inside
43 your @env{PATH} to the @command{gnulib-tool} file of your preferred
44 Gnulib checkout.  For example:
46 @example
47 $ ln -s $HOME/gnu/src/gnulib.git/gnulib-tool $HOME/bin/gnulib-tool
48 @end example
50 @node Git Checkout
51 @section Git Checkout
53 Gnulib is available for anonymous checkout.  In any Bourne-shell the
54 following should work:
56 @example
57 $ git clone git://git.sv.gnu.org/gnulib.git
58 @end example
60 For a read-write checkout you need to have a login on
61 @samp{savannah.gnu.org} and be a member of the Gnulib project at
62 @url{http://savannah.gnu.org/projects/gnulib}.  Then, instead of the
63 URL @url{git://git.sv.gnu.org/gnulib}, use the URL
64 @samp{ssh://@var{user}@@git.sv.gnu.org/srv/git/gnulib} where
65 @var{user} is your login name on savannah.gnu.org.
67 git resources:
69 @table @asis
70 @item Overview:
71 @url{http://en.wikipedia.org/wiki/Git_(software)}
72 @item Homepage:
73 @url{http://git-scm.com/}
74 @end table
76 When you use @code{git annotate} or @code{git blame} with Gnulib, it's
77 recommended that you use the @option{-w} option, in order to ignore
78 massive whitespace changes that happened in 2009.
80 @node Keeping Up-to-date
81 @section Keeping Up-to-date
83 The best way to work with Gnulib is to check it out of git.
84 To synchronize, you can use @code{git pull}.
86 Subscribing to the @email{bug-gnulib@@gnu.org} mailing list will help
87 you to plan when to update your local copy of Gnulib (which you use to
88 maintain your software) from git.  You can review the archives,
89 subscribe, etc., via
90 @url{https://lists.gnu.org/mailman/listinfo/bug-gnulib}.
92 Sometimes, using an updated version of Gnulib will require you to use
93 newer versions of GNU Automake or Autoconf.  You may find it helpful
94 to join the autotools-announce mailing list to be advised of such
95 changes.
97 @node Contributing to Gnulib
98 @section Contributing to Gnulib
100 All software here is copyrighted by the Free Software Foundation---you need
101 to have filled out an assignment form for a project that uses the
102 module for that contribution to be accepted here.
104 If you have a piece of code that you would like to contribute, please
105 email @email{bug-gnulib@@gnu.org}.
107 Generally we are looking for files that fulfill at least one of the
108 following requirements:
110 @itemize
111 @item
112 If your @file{.c} and @file{.h} files define functions that are broken or
113 missing on some other system, we should be able to include it.
115 @item
116 If your functions remove arbitrary limits from existing
117 functions (either under the same name, or as a slightly different
118 name), we should be able to include it.
119 @end itemize
121 If your functions define completely new but rarely used functionality,
122 you should probably consider packaging it as a separate library.
124 @menu
125 * Gnulib licensing::
126 * Indent with spaces not TABs::
127 * How to add a new module::
128 @end menu
130 @node Gnulib licensing
131 @subsection Gnulib licensing
133 Gnulib contains code both under GPL and LGPL@.  Because several packages
134 that use Gnulib are GPL, the files state they are licensed under GPL@.
135 However, to support LGPL projects as well, you may use some of the
136 files under LGPL@.  The ``License:'' information in the files under
137 modules/ clarifies the real license that applies to the module source.
139 Keep in mind that if you submit patches to files in Gnulib, you should
140 license them under a compatible license, which means that sometimes
141 the contribution will have to be LGPL, if the original file is
142 available under LGPL via a ``License: LGPL'' information in the
143 projects' modules/ file.
145 @node Indent with spaces not TABs
146 @subsection Indent with spaces not TABs
148 We use space-only indentation in nearly all files. This includes all
149 @file{*.h}, @file{*.c}, @file{*.y} files, except for the @code{regex}
150 module. Makefile and ChangeLog files are excluded, since TAB
151 characters are part of their format.
153 In order to tell your editor to produce space-only indentation, you
154 can use these instructions.
156 @itemize
157 @item
158 For Emacs: Add these lines to your Emacs initialization file
159 (@file{$HOME/.emacs} or similar):
161 @example
162 ;; In Gnulib, indent with spaces everywhere (not TABs).
163 ;; Exceptions: Makefile and ChangeLog modes.
164 (add-hook 'find-file-hook '(lambda ()
165   (if (and buffer-file-name
166            (string-match "/gnulib\\>" (buffer-file-name))
167            (not (string-equal mode-name "Change Log"))
168            (not (string-equal mode-name "Makefile")))
169       (setq indent-tabs-mode nil))))
170 @end example
172 @item
173 For vi (vim): Add these lines to your @file{$HOME/.vimrc} file:
175 @example
176 " Don't use tabs for indentation. Spaces are nicer to work with.
177 set expandtab
178 @end example
180 For Makefile and ChangeLog files, compensate for this by adding this
181 to your @file{$HOME/.vim/after/indent/make.vim} file, and similarly
182 for your @file{$HOME/.vim/after/indent/changelog.vim} file:
184 @example
185 " Use tabs for indentation, regardless of the global setting.
186 set noexpandtab
187 @end example
189 @item
190 For Eclipse: In the ``Window|Preferences'' dialog (or ``Eclipse|Preferences''
191 dialog on Mac OS),
193 @enumerate
194 @item
195 Under ``General|Editors|Text Editors'', select the ``Insert spaces for tabs''
196 checkbox.
198 @item
199 Under ``C/C++|Code Style'', select a code style profile that has the
200 ``Indentation|Tab policy'' combobox set to ``Spaces only'', such as the
201 ``GNU [built-in]'' policy.
202 @end enumerate
204 If you use the GNU indent program, pass it the option @option{--no-tabs}.
205 @end itemize
207 @node How to add a new module
208 @subsection How to add a new module
210 @itemize
211 @item
212 Add the header files and source files to @file{lib/}.
214 @item
215 If the module needs configure-time checks, write an Autoconf
216 macro for it in @file{m4/@var{module}.m4}. See @file{m4/README} for details.
218 @item
219 Write a module description @file{modules/@var{module}}, based on
220 @file{modules/TEMPLATE}.
222 @item
223 If the module contributes a section to the end-user documentation,
224 put this documentation in @file{doc/@var{module}.texi} and add it to the ``Files''
225 section of @file{modules/@var{module}}.  Most modules don't do this; they have only
226 documentation for the programmer (= Gnulib user).  Such documentation
227 usually goes into the @file{lib/} source files.  It may also go into @file{doc/};
228 but don't add it to the module description in this case.
230 @item
231 Add the module to the list in @file{MODULES.html.sh}.
232 @end itemize
234 @noindent
235 You can test that a module builds correctly with:
237 @example
238 $ ./gnulib-tool --create-testdir --dir=/tmp/testdir module1 ... moduleN
239 $ cd /tmp/testdir
240 $ ./configure && make
241 @end example
243 @noindent
244 Other things:
246 @itemize
247 @item
248 Check the license and copyright year of headers.
250 @item
251 Check that the source code follows the GNU coding standards;
252 see @url{http://www.gnu.org/prep/standards}.
254 @item
255 Add source files to @file{config/srclist*} if they are identical to upstream
256 and should be upgraded in Gnulib whenever the upstream source changes.
258 @item
259 Include header files in source files to verify the function prototypes.
261 @item
262 Make sure a replacement function doesn't cause warnings or clashes on
263 systems that have the function.
265 @item
266 Autoconf functions can use @samp{gl_*} prefix. The @samp{AC_*} prefix is for
267 autoconf internal functions.
269 @item
270 Build files only if they are needed on a platform.  Look at the
271 @code{alloca} and @code{fnmatch} modules for how to achieve this.  If
272 for some reason you cannot do this, and you have a @file{.c} file that
273 leads to an empty @file{.o} file on some platforms (through some big
274 @code{#if} around all the code), then ensure that the compilation unit
275 is not empty after preprocessing.  One way to do this is to
276 @code{#include <stddef.h>} or @code{<stdio.h>} before the big
277 @code{#if}.
278 @end itemize
280 @node Portability guidelines
281 @section Portability guidelines
283 Gnulib code is intended to be portable to a wide variety of platforms,
284 not just GNU platforms.  Gnulib typically attempts to support a
285 platform as long as it is still supported by its provider, even if the
286 platform is not the latest version.  @xref{Target Platforms}.
288 Many Gnulib modules exist so that applications need not worry about
289 undesirable variability in implementations.  For example, an
290 application that uses the @code{malloc} module need not worry about
291 @code{malloc@ (0)} returning @code{NULL} on some Standard C
292 platforms; and @code{glob} users need not worry about @code{glob}
293 silently omitting symbolic links to nonexistent files on some
294 platforms that do not conform to POSIX.
296 Gnulib code is intended to port without problem to new hosts, e.g.,
297 hosts conforming to recent C and POSIX standards.  Hence Gnulib code
298 should avoid using constructs that these newer standards no longer
299 require, without first testing for the presence of these constructs.
300 For example, because C11 made variable length arrays optional, Gnulib
301 code should avoid them unless it first uses the @code{vararrays}
302 module to check whether they are supported.
304 The following subsections discuss some exceptions and caveats to the
305 general Gnulib portability guidelines.
307 @menu
308 * C language versions::
309 * C99 features assumed::
310 * C99 features avoided::
311 * Other portability assumptions::
312 @end menu
314 @node C language versions
315 @subsection C language versions
317 Currently Gnulib assumes at least a freestanding C99 compiler,
318 possibly operating with a C library that predates C99; with time this
319 assumption will likely be strengthened to later versions of the C
320 standard.  Old platforms currently supported include AIX 6.1, HP-UX
321 11i v1 and Solaris 10, though these platforms are rarely tested.
322 Gnulib itself is so old that it contains many fixes for obsolete
323 platforms, fixes that may be removed in the future.
325 Because of the freestanding C99 assumption, Gnulib code can include
326 @code{<float.h>}, @code{<limits.h>}, @code{<stdarg.h>},
327 @code{<stdbool.h>}, @code{<stddef.h>}, and @code{<stdint.h>}
328 unconditionally.   Gnulib code can also assume the existence
329 of @code{<ctype.h>}, @code{<errno.h>}, @code{<fcntl.h>},
330 @code{<locale.h>}, @code{<signal.h>}, @code{<stdio.h>},
331 @code{<stdlib.h>}, @code{<string.h>}, and @code{<time.h>}.  Similarly,
332 many modules include @code{<sys/types.h>} even though it's not even in
333 C11; that's OK since @code{<sys/types.h>} has been around nearly
334 forever.
336 Even if the include files exist, they may not conform to the C standard.
337 However, GCC has a @command{fixincludes} script that attempts to fix most
338 C89-conformance problems.  Gnulib currently assumes include files
339 largely conform to C89 or better.  People still using ancient hosts
340 should use fixincludes or fix their include files manually.
342 Even if the include files conform, the library itself may not.
343 For example, @code{strtod} and @code{mktime} have some bugs on some platforms.
344 You can work around some of these problems by requiring the relevant
345 modules, e.g., the Gnulib @code{mktime} module supplies a working and
346 conforming @code{mktime}.
348 @node C99 features assumed
349 @subsection C99 features assumed by Gnulib
351 Although the C99 standard specifies many features, Gnulib code
352 is conservative about using them, partly because Gnulib predates
353 the widespread adoption of C99, and partly because many C99
354 features are not well-supported in practice.  C99 features that
355 are reasonably portable nowadays include:
357 @itemize
358 @item
359 A declarations after a statement, or as the first clause in a
360 @code{for} statement.
362 @item
363 @code{long long int}.
365 @item
366 @code{<stdbool.h>}, assuming the @code{stdbool} module is used.
367 @xref{stdbool.h}.
369 @item
370 @code{<stdint.h>}, assuming the @code{stdint} module is used.
371 @xref{stdint.h}.
373 @item
374 Compound literals and designated initializers.
376 @item
377 Variadic macros.
379 @item
380 @code{static inline} functions.
382 @item
383 @code{__func__}, assuming the @code{func} module is used.  @xref{func}.
385 @item
386 The @code{restrict} qualifier, assuming
387 @code{AC_REQUIRE([AC_C_RESTRICT])} is used.
389 @item
390 Flexible array members (however, see the @code{flexmember} module).
391 @end itemize
393 @node C99 features avoided
394 @subsection C99 features avoided by Gnulib
396 Gnulib avoids some features even though they are standardized by C99,
397 as they have portability problems in practice.  Here is a partial list
398 of avoided C99 features.  Many other C99 features are portable only if
399 their corresponding modules are used; Gnulib code that uses such a
400 feature should require the corresponding module.
402 @itemize
403 @item
404 Variable length arrays, unless @code{__STDC_NO_VLA__} is defined.
405 See the @code{vararrays} module.
407 @item
408 @code{extern inline} functions, without checking whether they are
409 supported.  @xref{extern inline}.
411 @item
412 Type-generic math functions.
414 @item
415 Universal character names in source code.
417 @item
418 @code{<iso646.h>}, since GNU programs need not worry about deficient
419 source-code encodings.
421 @item
422 Comments beginning with @samp{//}.  This is mostly for style reasons.
423 @end itemize
425 @node Other portability assumptions
426 @subsection Other portability assumptions made by Gnulib
428 The GNU coding standards allow one departure from strict C: Gnulib
429 code can assume that standard internal types like @code{size_t} are no
430 wider than @code{long}.  POSIX requires implementations to support at
431 least one programming environment where this is true, and such
432 environments are recommended for Gnulib-using applications.  When it
433 is easy to port to non-POSIX platforms like MinGW where these types
434 are wider than @code{long}, new Gnulib code should do so, e.g., by
435 using @code{ptrdiff_t} instead of @code{long}.  However, it is not
436 always that easy, and no effort has been made to check that all Gnulib
437 modules work on MinGW-like environments.
439 Gnulib code makes the following additional assumptions:
441 @itemize
442 @item
443 @code{int} and @code{unsigned int} are at least 32 bits wide.  POSIX
444 and the GNU coding standards both require this.
446 @item
447 Signed integer arithmetic is two's complement.
449 Previously, Gnulib code sometimes assumed that signed integer
450 arithmetic wraps around, but modern compiler optimizations
451 sometimes do not guarantee this, and Gnulib code with this
452 assumption is now considered to be questionable.
453 @xref{Integer Properties}.
455 Although some Gnulib modules contain explicit support for the other signed
456 integer representations allowed by the C standard (ones' complement and signed
457 magnitude), these modules are the exception rather than the rule.
458 All practical Gnulib targets use two's complement.
460 @item
461 There are no ``holes'' in integer values: all the bits of an integer
462 contribute to its value in the usual way.
464 @item
465 Addresses and sizes behave as if objects reside in a flat address space.
466 In particular:
468 @itemize
469 @item
470 If two nonoverlapping objects have sizes @var{S} and @var{T} represented as
471 @code{size_t} values, then @code{@var{S} + @var{T}} cannot overflow.
473 @item
474 A pointer @var{P} points within an object @var{O} if and only if
475 @code{(char *) &@var{O} <= (char *) @var{P} && (char *) @var{P} <
476 (char *) (&@var{O} + 1)}.
478 @item
479 If an existing object has size @var{S}, and if @var{T} is sufficiently
480 small (e.g., 8 KiB), then @code{@var{S} + @var{T}} cannot overflow.
481 Overflow in this case would mean that the rest of your program fits
482 into @var{T} bytes, which can't happen in realistic flat-address-space
483 hosts.
485 @item
486 Objects with all bits zero are treated as 0 or NULL@.  For example,
487 @code{memset@ (A, 0, sizeof@ A)} initializes an array @code{A} of
488 pointers to NULL.
490 @item
491 Adding zero to a null pointer does not change the pointer.
492 For example, @code{0 + (char *) NULL == (char *) NULL}.
493 @end itemize
494 @end itemize
496 The above assumptions are not required by the C or POSIX standards but
497 hold on all practical porting targets that we're familiar with.  If
498 you have a porting target where these assumptions are not true, we'd
499 appreciate hearing of any fixes.  We need fixes that do not increase
500 runtime overhead on standard hosts and that are relatively easy to
501 maintain.
503 @node High Quality
504 @section High Quality
506 We develop and maintain a testsuite for Gnulib.  The goal is to have a
507 100% firm interface so that maintainers can feel free to update to the
508 code in git at @emph{any} time and know that their application will not
509 break.  This means that before any change can be committed to the
510 repository, a test suite program must be produced that exposes the bug
511 for regression testing.  All experimental work should be done on
512 branches to help promote this.