autoupdate
[gnulib.git] / doc / gnulib-tool.texi
1 @node Invoking gnulib-tool
2 @chapter Invoking gnulib-tool
3
4 @c Copyright (C) 2005-2010 Free Software Foundation, Inc.
5
6 @c Permission is granted to copy, distribute and/or modify this document
7 @c under the terms of the GNU Free Documentation License, Version 1.3 or
8 @c any later version published by the Free Software Foundation; with no
9 @c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
10 @c Texts.  A copy of the license is included in the ``GNU Free
11 @c Documentation License'' file as part of this distribution.
12
13 @pindex gnulib-tool
14 @cindex invoking @command{gnulib-tool}
15
16 The @command{gnulib-tool} command is the recommended way to import
17 Gnulib modules.  It is possible to borrow Gnulib modules in a package
18 without using @command{gnulib-tool}, relying only on the
19 meta-information stored in the @file{modules/*} files, but with a
20 growing number of modules this becomes tedious.  @command{gnulib-tool}
21 simplifies the management of source files, @file{Makefile.am}s and
22 @file{configure.ac} in packages incorporating Gnulib modules.
23
24 @file{gnulib-tool} is not installed in a standard directory that is
25 contained in the @code{PATH} variable.  It needs to be run directly in
26 the directory that contains the Gnulib source code.  You can do this
27 either by specifying the absolute filename of @file{gnulib-tool}, or
28 you can also use a symbolic link from a place inside your @code{PATH}
29 to the @file{gnulib-tool} file of your preferred and most up-to-date
30 Gnulib checkout, like this:
31 @smallexample
32 $ ln -s $HOME/gnu/src/gnulib.git/gnulib-tool $HOME/bin/gnulib-tool
33 @end smallexample
34
35 Run @samp{gnulib-tool --help} for information.  To get familiar with
36 @command{gnulib-tool} without affecting your sources, you can also try
37 some commands with the option @samp{--dry-run}; then
38 @code{gnulib-tool} will only report which actions it would perform in
39 a real run without changing anything.
40
41 @menu
42 * Which modules?::              Determining the needed set of Gnulib modules
43 * Initial import::              First import of Gnulib modules.
44 * Modified imports::            Changing the import specification.
45 * Simple update::               Tracking Gnulib development.
46 * Source changes::              Impact of Gnulib on your source files.
47 * gettextize and autopoint::    Caveat: @code{gettextize} and @code{autopoint} users!
48 * Localization::                Handling Gnulib's own message translations.
49 * VCS Issues::                  Integration with Version Control Systems.
50 * Unit tests::                  Bundling the unit tests of the Gnulib modules.
51 @end menu
52
53
54 @node Which modules?
55 @section Finding modules
56 @cindex Finding modules
57
58 There are three ways of finding the names of Gnulib modules that you can use
59 in your package:
60
61 @itemize
62 @item
63 You have the complete module list, sorted according to categories, in
64 @url{http://www.gnu.org/software/gnulib/MODULES.html}.
65
66 @item
67 If you are looking for a particular POSIX header or function replacement,
68 look in the chapters @ref{Header File Substitutes} and
69 @ref{Function Substitutes}.  For headers and functions that are provided by
70 Glibc but not standardized by POSIX, look in the chapters
71 @ref{Glibc Header File Substitutes} and @ref{Glibc Function Substitutes}.
72
73 @item
74 If you have already found the source file in Gnulib and are looking for the
75 module that contains this source file, you can use the command
76 @samp{gnulib-tool --find @var{filename}}.
77 @end itemize
78
79
80 @node Initial import
81 @section Initial import
82 @cindex initial import
83
84 Gnulib assumes that your project uses Autoconf.  When using Gnulib, you
85 will need to have Autoconf and Automake among your build tools.  Note that
86 while the use of Automake in your project's top level directory is an
87 easy way to fulfil the Makefile conventions of the GNU coding standards,
88 Gnulib does not require it.  But when you use Gnulib, Automake will be
89 used at least in a subdirectory of your project.
90
91 Invoking @samp{gnulib-tool --import} will copy source files, create a
92 @file{Makefile.am} to build them, generate a file @file{gnulib-comp.m4} with
93 Autoconf M4 macro declarations used by @file{configure.ac}, and generate
94 a file @file{gnulib-cache.m4} containing the cached specification of how
95 Gnulib is used.
96
97 Our example will be a library that uses Autoconf, Automake and
98 Libtool.  It calls @code{strdup}, and you wish to use gnulib to make
99 the package portable to C89 and C99 (which don't have @code{strdup}).
100
101 @example
102 ~/src/libfoo$ gnulib-tool --import strdup
103 Module list with included dependencies:
104   absolute-header
105   extensions
106   strdup
107   string
108 File list:
109   lib/dummy.c
110   lib/strdup.c
111   lib/string.in.h
112   m4/absolute-header.m4
113   m4/extensions.m4
114   m4/gnulib-common.m4
115   m4/strdup.m4
116   m4/string_h.m4
117 Creating directory ./lib
118 Creating directory ./m4
119 Copying file lib/dummy.c
120 Copying file lib/strdup.c
121 Copying file lib/string.in.h
122 Copying file m4/absolute-header.m4
123 Copying file m4/extensions.m4
124 Copying file m4/gnulib-common.m4
125 Copying file m4/gnulib-tool.m4
126 Copying file m4/strdup.m4
127 Copying file m4/string_h.m4
128 Creating lib/Makefile.am
129 Creating m4/gnulib-cache.m4
130 Creating m4/gnulib-comp.m4
131 Finished.
132
133 You may need to add #include directives for the following .h files.
134   #include <string.h>
135
136 Don't forget to
137   - add "lib/Makefile" to AC_CONFIG_FILES in ./configure.ac,
138   - mention "lib" in SUBDIRS in Makefile.am,
139   - mention "-I m4" in ACLOCAL_AMFLAGS in Makefile.am,
140   - invoke gl_EARLY in ./configure.ac, right after AC_PROG_CC,
141   - invoke gl_INIT in ./configure.ac.
142 ~/src/libfoo$
143 @end example
144
145 By default, the source code is copied into @file{lib/} and the M4
146 macros in @file{m4/}.  You can override these paths by using
147 @code{--source-base=DIRECTORY} and @code{--m4-base=DIRECTORY}.  Some
148 modules also provide other files necessary for building. These files
149 are copied into the directory specified by @samp{AC_CONFIG_AUX_DIR} in
150 @file{configure.ac} or by the @code{--aux-dir=DIRECTORY} option.  If
151 neither is specified, the current directory is assumed.
152
153 @code{gnulib-tool} can make symbolic links instead of copying the
154 source files.  The option to specify for this is @samp{--symlink}, or
155 @samp{-s} for short.  This can be useful to save a few kilobytes of disk
156 space.  But it is likely to introduce bugs when @code{gnulib} is updated;
157 it is more reliable to use @samp{gnulib-tool --update} (see below)
158 to update to newer versions of @code{gnulib}.  Furthermore it requires
159 extra effort to create self-contained tarballs, and it may disturb some
160 mechanism the maintainer applies to the sources.  For these reasons,
161 this option is generally discouraged.
162
163 @code{gnulib-tool} will overwrite any pre-existing files, in
164 particular @file{Makefile.am}.  Unfortunately, separating the
165 generated @file{Makefile.am} content (for building the gnulib library)
166 into a separate file, say @file{gnulib.mk}, that could be included
167 by your handwritten @file{Makefile.am} is not possible, due to how
168 variable assignments are handled by Automake.
169
170 Consequently, it is a good idea to choose directories that are not
171 already used by your projects, to separate gnulib imported files from
172 your own files.  This approach is also useful if you want to avoid
173 conflicts between other tools (e.g., @code{gettextize} that also copy
174 M4 files into your package.  Simon Josefsson successfully uses a source
175 base of @file{gl/}, and a M4 base of @file{gl/m4/}, in several
176 packages.
177
178 After the @samp{--import} option on the command line comes the list of
179 Gnulib modules that you want to incorporate in your package.  The names
180 of the modules coincide with the filenames in Gnulib's @file{modules/}
181 directory.
182
183 Some Gnulib modules depend on other Gnulib modules.  @code{gnulib-tool}
184 will automatically add the needed modules as well; you need not list
185 them explicitly.  @code{gnulib-tool} will also memorize which dependent
186 modules it has added, so that when someday a dependency is dropped, the
187 implicitly added module is dropped as well (unless you have explicitly
188 requested that module).
189
190 If you want to cut a dependency, i.e., not add a module although one of
191 your requested modules depends on it, you may use the option
192 @samp{--avoid=@var{module}} to do so.  Multiple uses of this option are
193 possible.  Of course, you will then need to implement the same interface
194 as the removed module.
195
196 A few manual steps are required to finish the initial import.
197 @code{gnulib-tool} printed a summary of these steps.
198
199 First, you must ensure Autoconf can find the macro definitions in
200 @file{gnulib-comp.m4}.  Use the @code{ACLOCAL_AMFLAGS} specifier in
201 your top-level @file{Makefile.am} file, as in:
202
203 @example
204 ACLOCAL_AMFLAGS = -I m4
205 @end example
206
207 You are now ready to call the M4 macros in @code{gnulib-comp.m4} from
208 @file{configure.ac}.  The macro @code{gl_EARLY} must be called as soon
209 as possible after verifying that the C compiler is working.
210 Typically, this is immediately after @code{AC_PROG_CC}, as in:
211
212 @example
213 ...
214 AC_PROG_CC
215 gl_EARLY
216 ...
217 @end example
218
219 The core part of the gnulib checks are done by the macro
220 @code{gl_INIT}.  Place it further down in the file, typically where
221 you normally check for header files or functions.  It must come after
222 other checks which may affect the compiler invocation, such as
223 @code{AC_MINIX}.  For example:
224
225 @example
226 ...
227 # For gnulib.
228 gl_INIT
229 ...
230 @end example
231
232 @code{gl_INIT} will in turn call the macros related with the
233 gnulib functions, be it specific gnulib macros, like @code{gl_FUNC_ALLOCA}
234 or autoconf or automake macros like @code{AC_FUNC_ALLOCA} or
235 @code{AM_FUNC_GETLINE}.  So there is no need to call those macros yourself
236 when you use the corresponding gnulib modules.
237
238 You must also make sure that the gnulib library is built.  Add the
239 @code{Makefile} in the gnulib source base directory to
240 @code{AC_CONFIG_FILES}, as in:
241
242 @example
243 AC_CONFIG_FILES(... lib/Makefile ...)
244 @end example
245
246 You must also make sure that @code{make} will recurse into the gnulib
247 directory.  To achieve this, add the gnulib source base directory to a
248 @code{SUBDIRS} Makefile.am statement, as in:
249
250 @example
251 SUBDIRS = lib
252 @end example
253
254 or if you, more likely, already have a few entries in @code{SUBDIRS},
255 you can add something like:
256
257 @example
258 SUBDIRS += lib
259 @end example
260
261 Finally, you have to add compiler and linker flags in the appropriate
262 source directories, so that you can make use of the gnulib library.
263 Since some modules (@samp{getopt}, for example) may copy files into
264 the build directory, @file{top_builddir/lib} is needed as well
265 as @file{top_srcdir/lib}.  For example:
266
267 @example
268 ...
269 AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
270 ...
271 LDADD = lib/libgnu.a
272 ...
273 @end example
274
275 Don't forget to @code{#include} the various header files.  In this
276 example, you would need to make sure that @samp{#include <string.h>}
277 is evaluated when compiling all source code files, that want to make
278 use of @code{strdup}.
279
280 In the usual case where Autoconf is creating a @file{config.h} file,
281 you should include @file{config.h} first, before any other include
282 file.  That way, for example, if @file{config.h} defines
283 @samp{restrict} to be the empty string on a pre-C99 host, or a macro
284 like @samp{_FILE_OFFSET_BITS} that affects the layout of data
285 structures, the definition is consistent for all include files.
286 Also, on some platforms macros like @samp{_FILE_OFFSET_BITS} and
287 @samp{_GNU_SOURCE} may be ineffective, or may have only a limited
288 effect, if defined after the first system header file is included.
289
290 Finally, note that you can not use @code{AC_LIBOBJ} or
291 @code{AC_REPLACE_FUNCS} in your @file{configure.ac} and expect the
292 resulting object files to be automatically added to @file{lib/libgnu.a}.
293 This is because your @code{AC_LIBOBJ} and @code{AC_REPLACE_FUNCS} invocations
294 from @file{configure.ac} augment a variable @code{@@LIBOBJS@@} (and/or
295 @code{@@LTLIBOBJS@@} if using Libtool), whereas @file{lib/libgnu.a}
296 is built from the contents of a different variable, usually
297 @code{@@gl_LIBOBJS@@} (or @code{@@gl_LTLIBOBJS@@} if using Libtool).
298
299
300 @node Modified imports
301 @section Modified imports
302
303 You can at any moment decide to use Gnulib differently than the last time.
304
305 If you only want to use more Gnulib modules, simply invoke
306 @command{gnulib-tool --import @var{new-modules}}.  @code{gnulib-tool}
307 remembers which modules were used last time.  The list of modules that
308 you pass after @samp{--import} is @emph{added} to the previous list of
309 modules.
310
311 For most changes, such as added or removed modules, or even different
312 choices of @samp{--lib}, @samp{--source-base} or @samp{--aux-dir}, there
313 are two ways to perform the change.
314
315 The standard way is to modify manually the file @file{gnulib-cache.m4}
316 in the M4 macros directory, then launch @samp{gnulib-tool --import}.
317
318 The other way is to call @command{gnulib-tool} again, with the changed
319 command-line options.  Note that this doesn't let you remove modules,
320 because as you just learned, the list of modules is always cumulated.
321 Also this way is often impractical, because you don't remember the way
322 you invoked @code{gnulib-tool} last time.
323
324 The only change for which this doesn't work is a change of the
325 @samp{--m4-base} directory.  Because, when you pass a different value of
326 @samp{--m4-base}, @code{gnulib-tool} will not find the previous
327 @file{gnulib-cache.m4} file any more... A possible solution is to manually
328 copy the @file{gnulib-cache.m4} into the new M4 macro directory.
329
330 In the @file{gnulib-cache.m4}, the macros have the following meaning:
331 @table @code
332 @item gl_MODULES
333 The argument is a space separated list of the requested modules, not including
334 dependencies.
335
336 @item gl_AVOID
337 The argument is a space separated list of modules that should not be used,
338 even if they occur as dependencies.  Corresponds to the @samp{--avoid}
339 command line argument.
340
341 @item gl_SOURCE_BASE
342 The argument is the relative file name of the directory containing the gnulib
343 source files (mostly *.c and *.h files).  Corresponds to the
344 @samp{--source-base} command line argument.
345
346 @item gl_M4_BASE
347 The argument is the relative file name of the directory containing the gnulib
348 M4 macros (*.m4 files).  Corresponds to the @samp{--m4-base} command line
349 argument.
350
351 @item gl_TESTS_BASE
352 The argument is the relative file name of the directory containing the gnulib
353 unit test files.  Corresponds to the @samp{--tests-base} command line argument.
354
355 @item gl_LIB
356 The argument is the name of the library to be created.  Corresponds to the
357 @samp{--lib} command line argument.
358
359 @item gl_LGPL
360 The presence of this macro without arguments corresponds to the @samp{--lgpl}
361 command line argument.  The presence of this macro with an argument (whose
362 value must be 2 or 3) corresponds to the @samp{--lgpl=@var{arg}} command line
363 argument.
364
365 @item gl_LIBTOOL
366 The presence of this macro corresponds to the @samp{--libtool} command line
367 argument and to the absence of the @samp{--no-libtool} command line argument.
368 It takes no arguments.
369
370 @item gl_MACRO_PREFIX
371 The argument is the prefix to use for macros in the @file{gnulib-comp.m4}
372 file.  Corresponds to the @samp{--macro-prefix} command line argument.
373 @end table
374
375
376 @node Simple update
377 @section Simple update
378
379 When you want to update to a more recent version of Gnulib, without
380 changing the list of modules or other parameters, a simple call
381 does it:
382
383 @smallexample
384 $ gnulib-tool --import
385 @end smallexample
386
387 @noindent
388 This will create, update or remove files, as needed.
389
390 Note: From time to time, changes are made in Gnulib that are not backward
391 compatible.  When updating to a more recent Gnulib, you should consult
392 Gnulib's @file{NEWS} file to check whether the incompatible changes affect
393 your project.
394
395
396 @node Source changes
397 @section Changing your sources for use with Gnulib
398
399 Gnulib contains some header file overrides.  This means that when building
400 on systems with deficient header files in @file{/usr/include/}, it may create
401 files named @file{string.h}, @file{stdlib.h}, @file{stdint.h} or similar in
402 the build directory.  In the other source directories of your package you
403 will usually pass @samp{-I} options to the compiler, so that these Gnulib
404 substitutes are visible and take precedence over the files in
405 @file{/usr/include/}.
406
407 These Gnulib substitute header files rely on @file{<config.h>} being
408 already included.  Furthermore @file{<config.h>} must be the first include
409 in every compilation unit.  This means that to @emph{all your source files}
410 and likely also to @emph{all your tests source files} you need to add an
411 @samp{#include <config.h>} at the top.  Which source files are affected?
412 Exactly those whose compilation includes a @samp{-I} option that refers to
413 the Gnulib library directory.
414
415 This is annoying, but inevitable: On many systems, @file{<config.h>} is
416 used to set system dependent flags (such as @code{_GNU_SOURCE} on GNU systems),
417 and these flags have no effect after any system header file has been included.
418
419
420 @node gettextize and autopoint
421 @section Caveat: @code{gettextize} and @code{autopoint} users
422
423 @cindex gettextize, caveat
424 @cindex autopoint, caveat
425 The programs @code{gettextize} and @code{autopoint}, part of
426 GNU @code{gettext}, import or update the internationalization infrastructure.
427 Some of this infrastructure, namely ca.@: 20 autoconf macro files and the
428 @file{config.rpath} file, is also contained in Gnulib and may be imported
429 by @code{gnulib-tool}.  The use of @code{gettextize} or @code{autopoint}
430 will therefore overwrite some of the files that @code{gnulib-tool} has
431 imported, and vice versa.
432
433 Avoiding to use @code{gettextize} (manually, as package maintainer) or
434 @code{autopoint} (as part of a script like @code{autoreconf} or
435 @code{autogen.sh}) is not the solution: These programs also import the
436 infrastructure in the @file{po/} and optionally in the @file{intl/} directory.
437
438 The copies of the conflicting files in Gnulib are more up-to-date than
439 the copies brought in by @code{gettextize} and @code{autopoint}.  When a
440 new @code{gettext} release is made, the copies of the files in Gnulib will
441 be updated immediately.
442
443 The solution is therefore:
444
445 @enumerate
446 @item
447 When you run @code{gettextize}, always use the @code{gettextize} from the
448 matching GNU gettext release.  For the most recent Gnulib checkout, this is
449 the newest release found on @url{http://ftp.gnu.org/gnu/gettext/}.  For an
450 older Gnulib snapshot, it is the release that was the most recent release
451 at the time the Gnulib snapshot was taken.  Then, after @code{gettextize},
452 invoke @code{gnulib-tool}.
453
454 @item
455 When a script of yours run @code{autopoint}, invoke @code{gnulib-tool}
456 afterwards.
457
458 @item
459 If you get an error message like
460 @code{*** error: gettext infrastructure mismatch:
461 using a Makefile.in.in from gettext version ...
462 but the autoconf macros are from gettext version ...},
463 it means that a new GNU gettext release was made, and its autoconf macros
464 were integrated into Gnulib and now mismatch the @file{po/} infrastructure.
465 In this case, fetch and install the new GNU gettext release and run
466 @code{gettextize} followed by @code{gnulib-tool}.
467 @end enumerate
468
469
470 @node Localization
471 @section Handling Gnulib's own message translations
472
473 Gnulib provides some functions that emit translatable messages using GNU
474 @code{gettext}.  The @samp{gnulib} domain at the
475 @url{http://translationproject.org/, Translation Project} collects
476 translations of these messages, which you should incorporate into your
477 own programs.
478
479 There are two basic ways to achieve this.  The first, and older, method
480 is to list all the source files you use from Gnulib in your own
481 @file{po/POTFILES.in} file.  This will cause all the relevant
482 translatable strings to be included in your POT file.  When you send
483 this POT file to the Translation Project, translators will normally fill
484 in the translations of the Gnulib strings from their ``translation
485 memory'', and send you back updated PO files.
486
487 However, this process is error-prone: you might forget to list some
488 source files, or the translator might not be using a translation memory
489 and provide a different translation than another translator, or the
490 translation might not be kept in sync between Gnulib and your package.
491 It is also slow and causes substantial extra work, because a human
492 translator must be in the loop for each language and you will need to
493 incorporate their work on request.
494
495 For these reasons, a new method was designed and is now recommended.  If
496 you pass the @code{--po-base=@var{directory}} and @code{--po-domain=@var{domain}}
497 options to @code{gnulib-tool}, then @code{gnulib-tool} will create a
498 separate directory with its own @file{POTFILES.in}, and fetch current
499 translations directly from the Translation Project (using
500 @command{rsync} or @command{wget}, whichever is available).
501 The POT file in this directory will be called
502 @file{@var{domain}-gnulib.pot}, depending on the @var{domain} you gave to the
503 @code{--po-domain} option (typically the same as the package name).
504 This causes these translations to reside in a separate message domain,
505 so that they do not clash either with the translations for the main part
506 of your package nor with those of other packages on the system that use
507 possibly different versions of Gnulib.
508 When you use these options, the functions in Gnulib are built
509 in such a way that they will always use this domain regardless of the
510 default domain set by @code{textdomain}.
511
512 In order to use this method, you must -- in each program that might use
513 Gnulib code -- add an extra line to the part of the program that
514 initializes locale-dependent behavior.  Where you would normally write
515 something like:
516
517 @example
518 @group
519   setlocale (LC_ALL, "");
520   bindtextdomain (PACKAGE, LOCALEDIR);
521   textdomain (PACKAGE);
522 @end group
523 @end example
524
525 @noindent
526 you should add an additional @code{bindtextdomain} call to inform
527 gettext of where the MO files for the extra message domain may be found:
528
529 @example
530 @group
531   bindtextdomain (PACKAGE "-gnulib", LOCALEDIR);
532 @end group
533 @end example
534
535 (This example assumes that the @var{domain} that you specified
536 to @code{gnulib-tool} is the same as the value of the @code{PACKAGE}
537 preprocessor macro.)
538
539 Since you do not change the @code{textdomain} call, the default message
540 domain for your program remains the same and your own use of @code{gettext}
541 functions will not be affected.
542
543
544 @node VCS Issues
545 @section Issues with Version Control Systems
546
547 If a project stores its source files in a version control system (VCS),
548 such as CVS, Subversion, or Git, one needs to decide which files to commit.
549
550 In principle, all files created by @code{gnulib-tool}, except
551 @file{gnulib-cache.m4}, can be treated like generated source files,
552 like for example a @file{parser.c} file generated from
553 @file{parser.y}.  Alternatively, they can be considered source files
554 and updated manually.
555
556 Here are the three different approaches in common use.  Each has its
557 place, and you should use whichever best suits your particular project
558 and development methods.
559
560 @enumerate
561 @item
562 In projects which commit all source files, whether generated or not,
563 into their VCS, the @code{gnulib-tool} generated files should all be
564 committed.  In this case, you should pass the option
565 @samp{--no-vc-files} to @code{gnulib-tool}, which avoids alteration of
566 VCS-related files such as @file{.cvsignore}.
567
568 Gnulib also contains files generated by @command{make} (and removed by
569 @code{make clean}), using information determined by
570 @command{configure}.  For a Gnulib source file of the form
571 @file{lib/foo.in.h}, the corresponding @file{lib/foo.h} is such a
572 @command{make}-generated file.  These should @emph{not} be checked
573 into the VCS, but instead added to @file{.cvsignore} or equivalent.
574
575 @item
576 In projects which customarily omit from their VCS all files that are
577 generated from other source files, none of these files and directories
578 are added into the VCS.  The only file that must be added to the VCS
579 is @file{gnulib-cache.m4} in the M4 macros directory.  Also, the
580 script for restoring files not in the VCS, customarily called
581 @file{autogen.sh} or @file{bootstrap}, will typically contain the
582 statement for restoring the omitted files:
583
584 @smallexample
585 $ gnulib-tool --update
586 @end smallexample
587
588 The @samp{--update} option operates much like the @samp{--import} option,
589 but it does not offer the possibility to change the way Gnulib is used.
590 Also it does not report in the ChangeLogs the files that it had to add
591 because they were missing.
592
593 Gnulib includes the file @file{build-aux/bootstrap} to aid a developer
594 in using this setup.  Furthermore, in projects that use git for
595 version control, it is possible to use a git submodule containing the
596 precise commit of the gnulib repository, so that each developer
597 running @file{bootstrap} will get the same version of all
598 gnulib-provided files.  The location of the submodule can be chosen to
599 fit the package's needs; here's how to initially create the submodule
600 in the directory @file{.gnulib}:
601
602 @smallexample
603 $ dir=.gnulib
604 $ git submodule add -- git://git.sv.gnu.org/gnulib.git $dir
605 $ git config alias.syncsub "submodule foreach git pull origin master"
606 @end smallexample
607
608 @noindent
609 Thereafter, @file{bootstrap} can run this command to update the
610 submodule to the recorded checkout level:
611
612 @smallexample
613 git submodule update --init $dir
614 @end smallexample
615
616 @noindent
617 and a developer can use this sequence to update to a newer version of
618 gnulib:
619
620 @smallexample
621 $ git syncsub
622 $ git add $dir
623 $ ./bootstrap
624 @end smallexample
625
626 @item
627 Some projects take a ``middle road'': they do commit Gnulib source
628 files as in the first approach, but they do not commit other derived
629 files, such as a @code{Makefile.in} generated by Automake.  This
630 increases the size and complexity of the repository, but can help
631 occasional contributors by not requiring them to have a full Gnulib
632 checkout to do a build, and all developers by ensuring that all
633 developers are working with the same version of Gnulib in the
634 repository.  It also supports multiple Gnulib instances within a
635 project.  It remains important not to commit the
636 @command{make}-generated files, as described above.
637
638 @end enumerate
639
640
641 @node Unit tests
642 @section Bundling the unit tests of the Gnulib modules
643
644 You can bundle the unit tests of the Gnulib modules together with your
645 package, through the @samp{--with-tests} option.  Together with
646 @samp{--with-tests}, you also specify the directory for these tests
647 through the @samp{--tests-base} option.  Of course, you need to add this
648 directory to the @code{SUBDIRS} variable in the @code{Makefile.am} of
649 the parent directory.
650
651 The advantage of having the unit tests bundled is that when your program
652 has a problem on a particular platform, running the unit tests may help
653 determine quickly if the problem is on Gnulib's side or on your package's
654 side.  Also, it helps verifying Gnulib's portability, of course.
655
656 The unit tests will be compiled and run when the user runs @samp{make check}.
657 When the user runs only @samp{make}, the unit tests will not be compiled.
658
659 In the @code{SUBDIRS} variable, it is useful to put the Gnulib tests directory
660 after the directory containing the other tests, not before:
661
662 @smallexample
663 SUBDIRS = gnulib-lib src man tests gnulib-tests
664 @end smallexample
665
666 @noindent
667 This will ensure that on platforms where there are test failures in either
668 directory, users will see and report the failures from the tests of your
669 program.
670
671 Note: In packages which use more than one invocation of @code{gnulib-tool}
672 in the scope of the same @code{configure.ac}, you cannot use
673 @samp{--with-tests}.  You will have to use a separate @code{configure.ac}
674 in this case.