Avoid "warning: The macro `AC_PROG_CC_STDC' is obsolete".
[gnulib.git] / doc / gnulib-intro.texi
blobaaae5b93153cc56dd278209a5f44bf5f6db8713e
1 @node Benefits
2 @section Benefits of using Gnulib
4 Gnulib is useful to enhance various aspects of a package:
6 @itemize @bullet
7 @item
8 Portability: With Gnulib, a package maintainer can program against the
9 POSIX and GNU libc APIs and nevertheless expect good portability to
10 platforms that don't implement POSIX.
12 @item
13 Maintainability: When a package uses modules from Gnulib instead of code
14 written specifically for that package, the maintainer has less code to
15 maintain.
17 @item
18 Security: Gnulib provides functions that are immune against vulnerabilities
19 that plague the uses of the corresponding commonplace functions. For
20 example, @code{asprintf}, @code{canonicalize_file_name} are not affected
21 by buffer sizing problems that affect @code{sprintf}, @code{realpath}.
22 @code{openat} does not have the race conditions that @code{open} has. Etc.
24 @item
25 Reliability: Gnulib provides functions that combine a call to a system
26 function with a check of the result. Examples are @code{xalloc},
27 @code{xprintf}, @code{xstrtod}, @code{xgetcwd}.
29 @item
30 Structure: Gnulib offers a way to structure code into modules, typically
31 one include file, one source code file, and one autoconf macro for each
32 functionality. Modularity helps maintainability.
33 @end itemize
35 @node Library vs Reusable Code
36 @section Library vs. Reusable Code
38 Classical libraries are installed as binary object code.  Gnulib is
39 different: It is used as a source code library.  Each package that uses
40 Gnulib thus ships with part of the Gnulib source code.  The used portion
41 of Gnulib is tailored to the package: A build tool, called
42 @code{gnulib-tool}, is provided that copies a tailored subset of Gnulib
43 into the package.
45 @node Portability and Application Code
46 @section Portability and Application Code
48 One of the goals of Gnulib is to make portable programming easy, on
49 the basis of the standards relevant for GNU (and Unix).  The objective
50 behind that is to avoid a fragmentation of the user community into
51 disjoint user communities according to the operating system, and
52 instead allow synergies between users on different operating systems.
54 Another goal of Gnulib is to provide application code that can be shared
55 between several applications.  Some people wonder: "What? glibc doesn't
56 have a function to copy a file?"  Indeed, the scope of a system's libc is
57 to implement the relevant standards (ISO C, POSIX) and to provide
58 access functions to the kernel's system calls, and little more.
60 There is no clear borderline between both areas.
62 For example, Gnulib has a facility for generating the name of backup
63 files.  While this task is entirely at the application level---no
64 standard specifies an API for it---the na@"{@dotless{i}}ve code has
65 some portability problems because on some platforms the length of file
66 name components is limited to 30 characters or so.  Gnulib handles
67 that.
69 Similarly, Gnulib has a facility for executing a command in a
70 subprocess.  It is at the same time a portability enhancement (it
71 works on GNU, Unix, and Windows, compared to the classical
72 @code{fork}/@code{exec} idiom which is not portable to Windows), as well
73 as an application aid: it takes care of redirecting stdin and/or
74 stdout if desired, and emits an error message if the subprocess
75 failed.
77 @node Target Platforms
78 @section Target Platforms
80 Gnulib supports a number of platforms that we call the ``reasonable
81 portability targets''.  This class consists of widespread operating systems,
82 for three years after their last availability, or---for proprietary
83 operating systems---as long as the vendor provides commercial support for
84 it.  Already existing Gnulib code for older operating systems is usually
85 left in place for longer than these three years.  So it comes that programs
86 that use Gnulib run pretty well also on these older operating systems.
88 Some operating systems are not very widespread, but are Free Software and
89 are actively developed.  Such platforms are also supported by Gnulib, if
90 that OS's developers community keeps in touch with the Gnulib developers,
91 by providing bug reports, analyses, or patches.  For such platforms, Gnulib
92 supports only the versions of the last year or the last few months,
93 depending on the maturity of said OS project, the number of its users, and
94 how often these users upgrade.
96 Niche operating systems are generally unsupported by Gnulib, unless some
97 of their developers or users contribute support to Gnulib.
99 The degree of support Gnulib guarantees for a platform depends on the
100 amount of testing it gets from volunteers.  Platforms on which Gnulib
101 is frequently tested are the best supported.  Then come platforms with
102 occasional testing, then platforms which are rarely tested.  Usually,
103 we fix bugs when they are reported.  Except that some rarely tested
104 platforms are also low priority; bug fixes for these platforms can
105 take longer.
107 As of 2019, the list of supported platforms is the following:
109 @itemize
110 @item
111 glibc systems.  With glibc 2.19 or newer, they are frequently tested.
112 @c [Not very relevant in the long term.]
113 @c The distributions Ubuntu, Fedora, RHEL, Arch Linux are frequently tested.
114 @c CentOS is occasionally tested.
115 @c Debian, gNewSense, Trisquel, OpenSUSE are rarely tested.
116 About the kernels:
117 @itemize
118 @item
119 glibc on Linux is frequently tested.
120 @item
121 glibc on kFreeBSD is rarely tested.
122 @end itemize
123 @item
124 Mac OS X@.  In versions 10.13, it's occasionally tested.  In version
125 10.5, it's rarely tested.
126 @item
127 FreeBSD 11.0 or newer is occasionally tested.
128 @item
129 OpenBSD 6.1 or newer is occasionally tested.
130 @item
131 NetBSD 7.0 or newer is occasionally tested.
132 @item
133 AIX 7.1 is occasionally tested.
134 @item
135 Solaris 10 and 11 are occasionally tested.  Solaris 9 is rarely
136 tested and low priority.
137 @item
138 Cygwin 2.9 is occasionally tested.  Cygwin 1.7.x is rarely tested.
139 @item
140 mingw is occasionally tested.  But note that some modules are currently
141 unsupported on mingw: @code{mgetgroups}, @code{getugroups}, @code{idcache},
142 @code{userspec}, @code{openpty}, @code{login_tty}, @code{forkpty},
143 @code{pt_chown}, @code{grantpt}, @code{pty}, @code{savewd},
144 @code{mkancesdirs}, @code{mkdir-p}, @code{euidaccess}, @code{faccessat}.
145 The versions of Windows that are supported are Windows XP and newer.
146 Only the latest version of mingw is tested; older versions are not supported.
147 @item
148 GNU Hurd 0.7 is rarely tested.
149 @item
150 Native Windows, with MSVC as compiler, is rarely tested and low priority.
151 The versions of MSVC that are supported are MSVC 14 (Visual Studio 2015) or
152 newer.
153 @item
154 @c There is musl-gcc on Ubuntu, and Alpine Linux 3.3.3.
155 musl libc is rarely tested.
156 @item
157 Minix 3.3.0 is rarely tested.
158 @item
159 @c IRIX 6.5 cc has no option for C99 support. You would need to use gcc instead.
160 IRIX 6.5 is very rarely tested.
161 @item
162 Haiku is no longer tested.
163 @item
164 uClibc on Linux is no longer tested.
165 @item
166 QNX is no longer tested.
167 @end itemize
169 The following platforms were supported in the past, but are no longer
170 supported:
171 @itemize
172 @item
173 glibc versions 2.1.x and older.
174 @item
175 Mac OS X 10.4 and older.
176 @item
177 AIX 4 and older.
178 @item
179 HP-UX 11.31.
180 @item
181 IRIX 6.4 and older.
182 @item
183 OSF/1 5.1.
184 @item
185 Solaris 8 and older.
186 @item
187 Interix.
188 @item
189 BeOS.
190 @end itemize
192 Gnulib supports these operating systems only in an unvirtualized environment.
193 When you run an OS inside a virtual machine, you have to be aware that the
194 virtual machine can bring in bugs of its own.  For example, floating-point
195 operations on Solaris can behave slightly differently in QEMU than on real
196 hardware.  And Haiku's @command{bash} program misbehaves in VirtualBox 3,
197 whereas it behaves fine in VirtualBox 4.
199 Similarly, running native Windows binaries on GNU/Linux under WINE is
200 rarely tested and low priority: WINE has a set of behaviours and bugs that
201 is slightly different from native Windows.
203 The following platforms are not supported by Gnulib.  The cost of
204 supporting them would exceed the benefit because they are rarely used, or
205 poorly documented, or have been supplanted by other platforms, or diverge
206 too much from POSIX, or some combination of these and other factors.
207 Please don't bother sending us patches for them.
209 @itemize
210 @item
211 Windows 95/98/ME.
212 @item
213 DJGPP and EMX (the 32-bit operating systems running in DOS).
214 @item
215 MSDOS (the 16-bit operating system).
216 @item
217 Windows Mobile, Symbian OS, iOS.
218 @end itemize
220 @node Modules
221 @section Modules
223 Gnulib is divided into modules.  Every module implements a single
224 facility.  Modules can depend on other modules.
226 A module consists of a number of files and a module description.  The
227 files are copied by @code{gnulib-tool} into the package that will use it,
228 usually verbatim, without changes.  Source code files (.h, .c files)
229 reside in the @file{lib/} subdirectory.  Autoconf macro files reside in
230 the @file{m4/} subdirectory.  Build scripts reside in the
231 @file{build-aux/} subdirectory.
233 The module description contains the list of files; @code{gnulib-tool}
234 copies these files.  It contains the module's
235 dependencies; @code{gnulib-tool} installs them as well.  It also
236 contains the autoconf macro invocation (usually a single line or
237 nothing at all); @code{gnulib-tool} ensures this is invoked from the
238 package's @file{configure.ac} file.  And also a @file{Makefile.am}
239 snippet; @code{gnulib-tool} collects these into a @file{Makefile.am}
240 for the tailored Gnulib part.  The module description and include file
241 specification are for documentation purposes; they are combined into
242 @file{MODULES.html}.
244 The module system serves two purposes:
246 @enumerate
247 @item
248 It ensures consistency of the used autoconf macros and @file{Makefile.am}
249 rules with the source code.  For example, source code which uses the
250 @code{getopt_long} function---this is a common way to implement parsing
251 of command line options in a way that complies with the GNU standards---needs
252 the source code (@file{lib/getopt.c} and others), the autoconf macro
253 which detects whether the system's libc already has this function (in
254 @file{m4/getopt.m4}), and a few @file{Makefile.am} lines that create the
255 substitute @file{getopt.h} if not.  These three pieces belong together.
256 They cannot be used without each other.  The module description and
257 @code{gnulib-tool} ensure that they are copied altogether into the
258 destination package.
260 @item
261 It allows for scalability.  It is well-known since the inception of the
262 MODULA-2 language around 1978 that dissection into modules with
263 dependencies allows for building large sets of code in a maintainable way.
264 The maintainability comes from the facts that:
266 @itemize @bullet
267 @item
268 Every module has a single purpose; you don't worry about other parts of
269 the program while creating, reading or modifying the code of a module.
271 @item
272 The code you have to read in order to understand a module is limited to
273 the source of the module and the .h files of the modules listed as
274 dependencies.  It is for this reason also that we recommend to put the
275 comments describing the functions exported by a module into its .h file.
276 @end itemize
278 In other words, the module is the elementary unit of code in Gnulib,
279 comparable to a class in object-oriented languages like Java or C#.
280 @end enumerate
282 The module system is the basis of @code{gnulib-tool}.  When
283 @code{gnulib-tool} copies a part of Gnulib into a package, it first
284 compiles a module list, starting with the requested modules and adding all
285 the dependencies, and then collects the files, @file{configure.ac}
286 snippets and @file{Makefile.am} snippets.
288 @node Various Kinds of Modules
289 @section Various Kinds of Modules
291 There are modules of various kinds in Gnulib.  For a complete list of the
292 modules, see in @file{MODULES.html}.
294 @subsection Support for ISO C or POSIX functions.
296 When a function is not implemented by a system, the Gnulib module provides
297 an implementation under the same name.  Examples are the @samp{snprintf}
298 and @samp{readlink} modules.
300 Similarly, when a function is not correctly implemented by a system,
301 Gnulib provides a replacement.  For functions, we use the pattern
303 @smallexample
304 #if !HAVE_WORKING_FOO
305 # define foo rpl_foo
306 #endif
307 @end smallexample
309 @noindent
310 and implement the @code{foo} function under the name @code{rpl_foo}.  This
311 renaming is needed to avoid conflicts at compile time (in case the system
312 header files declare @code{foo}) and at link/run time (because the code
313 making use of @code{foo} could end up residing in a shared library, and
314 the executable program using this library could be defining @code{foo}
315 itself).
317 For header files, such as @code{stdbool.h} or @code{stdint.h}, we provide
318 the substitute only if the system doesn't provide a correct one.  The
319 template of this replacement is distributed in a slightly different name,
320 with @samp{.in} inserted before the @samp{.h} extension, so that on
321 systems which do provide a correct
322 header file the system's one is used.
324 The modules in this category are supported in C++ mode as well.  This
325 means, while the autoconfiguration uses the C compiler, the resulting
326 header files and function substitutes can be used with a matching C++
327 compiler as well.
329 @subsection Enhancements of ISO C or POSIX functions
331 These are sometimes POSIX functions with GNU extensions also found in
332 glibc---examples: @samp{getopt}, @samp{fnmatch}---and often new
333 APIs---for example, for all functions that allocate memory in one way
334 or the other, we have variants which also include the error checking
335 against the out-of-memory condition.
337 @subsection Portable general use facilities
339 Examples are a module for copying a file---the portability problems
340 relate to the copying of the file's modification time, access rights,
341 and extended attributes---or a module for extracting the tail
342 component of a file name---here the portability to native Windows
343 requires a different API than the classical POSIX @code{basename} function.
345 @subsection Reusable application code
347 Examples are an error reporting function, a module that allows output of
348 numbers with K/M/G suffixes, or cryptographic facilities.
350 @subsection Object oriented classes
352 Examples are data structures like @samp{list}, or abstract output stream
353 classes that work around the fact that an application cannot implement an
354 stdio @code{FILE} with its logic.  Here, while staying in C, we use
355 implementation techniques like tables of function pointers, known from the
356 C++ language or from the Linux kernel.
358 @subsection Interfaces to external libraries
360 Examples are the @samp{iconv} module, which interfaces to the
361 @code{iconv} facility, regardless whether it is contained in libc or in
362 an external @code{libiconv}.  Or the @samp{readline} module, which
363 interfaces to the GNU readline library.
365 @subsection Build / maintenance infrastructure
367 An example is the @samp{maintainer-makefile} module, which provides extra
368 Makefile tags for maintaining a package.
370 @node Collaborative Development
371 @section Collaborative Development
373 Gnulib is maintained collaboratively.  The mailing list is
374 @code{<bug-gnulib at gnu dot org>}.  Be warned that some people on the
375 list may be very active at some times and unresponsive at other times.
377 Every module has one or more maintainers.  While issues are discussed
378 collaboratively on the list, the maintainer of a module nevertheless has
379 a veto right regarding changes in his module.
381 All patches should be posted to the list, regardless whether they are
382 proposed patches or whether they are committed immediately by the
383 maintainer of the particular module.  The purpose is not only to inform
384 the other users of the module, but mainly to allow peer review.  It is not
385 uncommon that several people contribute comments or spot bugs after a
386 patch was proposed.
388 Conversely, if you are using Gnulib, and a patch is posted that affects
389 one of the modules that your package uses, you have an interest in
390 proofreading the patch.
392 @node Copyright
393 @section Copyright
395 Most modules are under the GPL@.  Some, mostly modules which can
396 reasonably be used in libraries, are under LGPL@.  The source files
397 always say "GPL", but the real license specification is in the module
398 description file.  If the module description file says "GPL", it means
399 "GPLv3+" (GPLv3 or newer, at the licensee's choice); if it says "LGPL",
400 it means "LGPLv3+" (LGPLv3 or newer, at the licensee's choice).
402 More precisely, the license specification in the module description
403 file applies to the files in @file{lib/} and @file{build-aux/}.  Different
404 licenses apply to files in special directories:
406 @table @file
407 @item modules/
408 Module description files are under this copyright:
410 @quotation
411 Copyright @copyright{} 20XX--20YY Free Software Foundation, Inc.@*
412 Copying and distribution of this file, with or without modification,
413 in any medium, are permitted without royalty provided the copyright
414 notice and this notice are preserved.
415 @end quotation
417 @item m4/
418 Autoconf macro files are under this copyright:
420 @quotation
421 Copyright @copyright{} 20XX--20YY Free Software Foundation, Inc.@*
422 This file is free software; the Free Software Foundation
423 gives unlimited permission to copy and/or distribute it,
424 with or without modifications, as long as this notice is preserved.
425 @end quotation
427 @item tests/
428 If a license statement is not present in a test module, the test files are
429 under GPL@.  Even if the corresponding source module is under LGPL, this is
430 not a problem, since compiled tests are not installed by ``make install''.
432 @item doc/
433 Documentation files are under this copyright:
435 @quotation
436 Copyright @copyright{} 2004--20YY Free Software Foundation, Inc.@*
437 Permission is granted to copy, distribute and/or modify this document
438 under the terms of the GNU Free Documentation License, Version 1.3 or
439 any later version published by the Free Software Foundation; with no
440 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
441 copy of the license is at @url{https://www.gnu.org/licenses/fdl-1.3.en.html}.
442 @end quotation
443 @end table
445 If you want to use some Gnulib modules under LGPL, you can do so by
446 passing the option @samp{--lgpl} to @code{gnulib-tool}.  This will
447 replace the GPL header with an LGPL header while copying the source
448 files to your package.  Similarly, if you want some Gnulib modules
449 under LGPLv2+ (Lesser GPL version 2.1 or newer), you can do so by
450 passing the option @samp{--lgpl=2} to @code{gnulib-tool}.
452 Keep in mind that when you submit patches to files in Gnulib, you should
453 license them under a compatible license.  This means that sometimes the
454 contribution will have to be LGPL, if the original file is available
455 under LGPL@.  You can find out about it by looking for a "License: LGPL"
456 information in the corresponding module description.
458 @node Steady Development
459 @section Steady Development
461 Gnulib modules are continually adapted, to match new practices, to be
462 consistent with newly added modules, or simply as a response to build
463 failure reports.
465 If you are willing to report an occasional regression, we recommend to
466 use the newest version from git always, except in periods of major
467 changes.  Most Gnulib users do this.
469 @node Openness
470 @section Openness
472 Gnulib is open in the sense that we gladly accept contributions if they
473 are generally useful, well engineered, and if the contributors have signed
474 the obligatory papers with the FSF.
476 The module system is open in the sense that a package using Gnulib can
477 @enumerate
478 @item
479 locally patch or override files in Gnulib,
480 @item
481 locally add modules that are treated like Gnulib modules by
482 @code{gnulib-tool}.
483 @end enumerate
485 This is achieved by the @samp{--local-dir} option of @code{gnulib-tool}
486 (@pxref{Extending Gnulib}).