Debian Codegraph @

doc/README.maintaining

raw
1 BUILD SCRIPTS: how they work and how to modify them
2 ===================================================
3
4 A guide to the Gutenprint build system.
5
6
7 Introduction
8 ------------
9
10 Gutenprint uses GNU autoconf and automake to generate the scripts that
11 build the software. It also uses libtool to create shared libraries.
12 This file describes how they work together. It also discusses the
13 thinking behind how they are used in Gutenprint, and how to modify the
14 Gutenprint build scripts without breaking other things. If you have
15 used autoconf and automake before, there will be little that is new in
16 this file, but you should note the conventions used in Gutenprint.
17
18 This file is split into the following sections:
19
20 o Setting up the autotools
21 o Integration of the autotools
22 o Normal use of the tools
23 - Using GIT
24 - Setting up the build scripts from GIT
25 - Building the package
26 o configure.ac
27 - Layout
28 - AC_SUBST
29 - AC_DEFINE and AC_DEFINE_UNQUOTED
30 - AM_CONDITIONAL
31 o Makefile.am
32 - Automake basics
33 - Make and subdirectories
34 - Conditional compilation
35 - When automake is not enough...
36 + Rule syntax
37 + Correctly referencing files
38 o aclocal
39 o config.h
40 o libgutenprint
41 o automake subtleties
42 o libtool tricks
43 o Testing changes to the build scripts
44 o Further information
45 o Known problems
46
47 I hope you find this useful. If any part was not clear, or there was
48 something that you would like covering, please let me know!
49
50 -- Roger Leigh <[email protected]>
51
52
53
54 1. Setting up the autotools
55 ---------------------------
56
57 To build Gutenprint from git, or to regenerate the build scripts after
58 modifying them, you need to install a number of GNU tools:
59
60 i. GNU autoconf (at least 2.54; at least 2.59 recommended)
61 ii. GNU automake (at least 1.9)
62 iii. GNU libtool (at least 1.5; at least 1.5.20 recommended)
63 iv. GNU gettext (at least 0.16)
64 v. GNU make (any recent version)
65
66 and also
67
68 vi. pkg-config (at least 0.18.0)
69
70 Additional packages are required to build certain parts of Gutenprint
71 directly from git that are not needed when building from a normal
72 distribution. These packages include:
73
74 vii. flex/lex (for building the GIMP plugin and the test pattern generator)
75 viii. bison/yacc (for building the GIMP plugin and the test pattern generator)
76 ix. doxygen (for building documentation)
77 x. DocBook processors (db2html, db2pdf) (for building documentation)
78 xi. DocBook-toys (called docbook-utils on some systems) (for building
79 documentation)
80
81 These packages are in addition to the packages normally required to
82 build Gutenprint, as described in the README at top level.
83
84 If you are running a Debian-derived system (such as Ubuntu), installing
85 the following packages should prepare your environment for building
86 Gutenprint:
87
88 autoconf
89 autopoint
90 byacc
91 git
92 docbook-utils
93 doxygen
94 flex
95 gettext
96 libglib2.0-dev
97 libtool
98 pkg-config
99 sgmltools-lite
100 texi2html
101
102
103 2. Integration of the autotools
104 -------------------------------
105
106 Each directory has a Makefile.am file which is processed by automake
107 to produce a Makefile.in. In the root directory there is a
108 configure.ac.in which is processed by autoconf to make a script called
109 configure. When run, configure does various tests and checks, and
110 then reads each Makefile.in to make a Makefile, and also generates a
111 header called config.h from config.h.in. config.h.in is produced with
112 autoheader from configure.ac and acconfig.h. autoconf also requires a
113 file aclocal.m4 which is generated by aclocal.
114
115 All these files are generated simply by running `./autogen.sh' in the
116 top directory. If you are using a distributed version of Gutenprint,
117 as opposed to git, then they will already be present and the following
118 will not be necessary.
119
120 This is probably best demonstrated graphically. The relationships
121 between the files are as follows:
122
123 During package setup (from git), running autogen.sh:
124
125 autogen.sh
126 m4extra/stp_release.m4.in ------------> m4/stp_release.m4
127
128 gettext files added
129 libtool files added
130 aclocal
131 m4/* + m4local/* + configure.ac ------------> aclocal.m4
132
133 autoheader
134 acconfig.h + configure.ac ------------> config.h.in
135
136 automake
137 Makefile.am ------------> Makefile.in
138
139 autoconf
140 aclocal.m4 + configure.ac ------------> configure
141
142 Running configure:
143 configure (->config.status)
144 Makefile.in ------------> Makefile
145 config.h.in ------------> config.h
146 headers.h.in ------------> headers.h
147 manpage.n.in ------------> manpage.n
148
149
150 3. Normal use of the tools
151 --------------------------
152
153 This section describes how to use the scripts for basic day-to-day
154 working.
155
156 3.1 Using git
157 -------------
158 The latest working copy of Gutenprint (HEAD) and all prior releases
159 are available via our git repository:
160
161 $ git clone https://git.code.sf.net/p/gimp-print/source gutenprint
162 $ git clone git://git.code.sf.net/p/gimp-print/source gutenprint
163
164 For developers with write/commit access, the URI would be:
165
166 $ git clone ssh://[email protected]/p/gimp-print/source gutenprint
167
168 How to set up your local environment to work with "git forges" is beyond
169 the scope of this documentation, please see Sourceforge.net's documentation
170 for how to achieve this.
171
172 Meanwhile, the git documentation has very detailed explanations of
173 everything that can be done with git.
174
175 3.2 Setting up the build scripts from git
176 -----------------------------------------
177 After initially getting a copy of Gutenprint from git, or if any of
178 the scripts have changed, simply run autogen.sh:
179
180 $ ./autogen.sh [options]
181
182 Note that one can pass any options to autogen.sh that one would
183 normally pass to configure. './configure --help' will give a complete
184 list of options one can use.
185
186 3.3 Building the package
187 ------------------------
188 The normal method for building from git is to run the `autogen.sh'
189 script, and then `make'. The package can then be installed with 'make
190 install':
191
192 $ ./autogen.sh [options]
193 $ make
194 $ make [DESTDIR=... VAR1=val1 VARn=valn] install
195
196 If the build scripts have been modified, it will not normally be
197 necessary to re-run autogen.sh: the Makefiles will notice and
198 regenerate themselves, running autoconf, automake, aclocal and
199 configure again if needed.
200
201 The build is only guaranteed to work if make is run from the top
202 level. It should be possible to make individual subdirectories, but
203 sometimes this will cause problems e.g. if it depends on some other
204 directory that should have been built first.
205
206 A common problem is getting errors about a non-existent file called
207 `doc/version.texi'. This file is automatically generated. It will be
208 generated if you run make after running './autogen.sh' or './configure
209 --enable-maintainer-mode'. It is only generated if `maintainer-mode'
210 is enabled, and should be present in the release tarball.
211
212 3.4 Extra make targets
213 ----------------------
214 The Makefiles can do much more than build the package. `targets' can
215 be given to make, which do various things. They are used as follows:
216
217 $ make target1 target2 ...
218
219 Some of the targets available are:
220
221 all same as make with no targets
222 clean remove everything generated by 'make all'
223 distclean as clean, and everything generated by configure
224 maintainer-clean as distclean, and everything generated by
225 autogen.sh
226 install install the package
227 uninstall uninstall the package
228 tags make tags tables
229 dist make a distribution
230 distcheck as dist, but test it as well
231
232 Other targets are available. See Makefile for details.
233
234
235 4. configure.ac
236 ---------------
237
238 This file is a Bourne shell script with m4 macros embedded in it.
239 autoconf expands the m4 macros to produce configure. The configure
240 script includes macros from the m4 and m4local directories, including
241 ones to hard-code the release date into configure.
242
243 4.1 Layout
244 ----------
245 The file is split into mostly discrete sections:
246
247 i. Versioning details (including library versioning)
248 ii. autoconf and automake initialisation
249 iii. libtool setup
250 iv. Default settings (now part of v)
251 v. configure --with and --enable options
252 vi. Checks for programs
253 vii. Compiler flags
254 viii. Checks for libraries
255 ix. Checks for headers
256 x. Checks for typedefs, structures, and compiler characteristics
257 xi. Define what has to be built (conditional compilation of things)
258 xii. CUPS path settings
259 xiii. Definitions and substitutions
260 xiv. Parse and output files
261
262 The ordering of sections is based solely on that some checks depend on
263 checks being performed previously. There is sometimes some overlap
264 between sections, but any additions should go into the appropriate
265 section, if at all possible. A new section may be created if there is
266 no suitable section.
267
268 4.2 AC_SUBST
269 ------------
270 The main use of the configure script is to produce customised
271 Makefiles, and other files too. This is done through the use of
272 AC_SUBST, which makes a variable get substituted in a file:
273
274 ESCPUTIL_BIN="escputil"
275 AC_SUBST(ESCPUTIL_BIN)
276
277 will replace any instance of @ESCPUTIL_BIN@ in a template file (ending
278 in .in'). E.g.
279
280 bin_PROGRAMS = @ESCPUTIL_BIN@
281
282 4.3 AC_DEFINE and AC_DEFINE_UNQUOTED
283 ------------------------------------
284 These macros are used to insert a #define in config.h.
285
286 AC_DEFINE(MACRO)
287
288 will cause '#define MACRO 1' to appear in config.h (this will be of
289 the form '#undef MACRO' in config.h.in)
290
291 AC_DEFINE_UNQUOTED is the same as AC_DEFINE, except that a second
292 option can be used to define a string literal.
293
294 4.4 AM_CONDITIONAL
295 ------------------
296 This is used to make certain parts of a Makefile conditional depending
297 on what happens in configure. It is used in the form:
298
299 AM_CONDITIONAL(NAME, test)
300 where name is the name of the conditional you define, and test
301 is a check that must return true for the conditional to be
302 defined.
303
304 This is used in a Makefile.am as follows:
305
306 if NAME
307 [do stuff]
308 endif
309
310 Note that you cannot also use normal make conditionals. Its main use
311 is to define macros, or to make a rule conditional.
312
313
314 5. Makefile.am
315 --------------
316
317 There is a Makefile.am in each directory, apart from a few where the
318 Makefile the next level up handles things. Each Makefile.am is split
319 into several sections:
320
321 i. Macros common to every Makefile.am
322 ii. Path macros
323 iii. Compiler macros
324 iv. Build dependencies. This is further split into a) binaries and b) data.
325 Each of these sections has
326 1. list of objects to build (if applicable)
327 2. EXTRA_ objects (if applicable)
328 3. Dependencies for each object (e.g. sources)
329 v. Rules
330 vi. Cleaning macros
331 vii. EXTRA_DIST
332
333 Keeping everything in this logical order keeps them neat and readable.
334 Not every Makefile.am will have all these sections, but those that are
335 present should be ordered in this way.
336
337 5.1 Automake basics
338 -------------------
339 Automake parses Makefile.am, and generates rules in Makefile.in
340 depending on what it finds. There are `primary' variables, such as
341 PROGRAMS, SCRIPTS, MANS, HEADERS and DATA that describe the type of
342 source one is defining. These are coupled with a location to install
343 into. For example, these are a few standard locations: bindir,
344 sbindir, mandir, datadir, pkgdatadir. You can define your own quite
345 easily. They are used together as follows:
346
347 bin_PROGRAMS = myprog [where bindir=$(prefix)/bin]
348 pkgdata_DATA = datafile1 datafile2
349 [where pkgdatadir=$(prefix)/share/$(PACKAGE)]
350
351 Note! the 'dir' postfix is stripped off the location. I.e. bindir ->
352 bin. That is all there is to it! You can use these simple variables
353 to describe everything in your source, and where is gets installed to.
354
355 In the case of PROGRAMS, one also has to specify the SOURCES as well.
356 E.g. in the example above, a binary called `myprog' was defined. The
357 sources for this program are defined as follows:
358
359 myprog_SOURCES = myprog.c myprog.h
360
361 automake will create all of the rules needed to build and install
362 everything. An extra point is that suppose one doesn't want to
363 install something? For this there is a 'noinst' macro, so that
364 noinst_PROGRAMS will not ever be installed. One might also want
365 noinst_HEADERS. If one wanted to install headers, one would define
366
367 includedir=$(prefix)/include
368 and then
369 pkgincludedir=$(includedir)/$(PACKAGE).
370 Now
371 pkginclude_HEADERS = myheader.h
372
373 will install the header into the correct location. Some of the
374 locations in the above examples are defined by default. The others
375 must be defined by hand.
376
377 There are also some macros with specific functions. Any file that is
378 not mentioned in a macro, and also and MANS, will have to be put in an
379 EXTRA_DIST macro, so that automake knows to distribute them.
380
381 Also, some files might not be automatically cleaned. There are
382 CLEANFILES, DISTCLEANFILES and MAINTAINERCLEANFILES macros for use
383 with the 'clean', 'distclean' and 'maintainer-clean' make targets
384 respectively. Use with caution! One does not want to clean things
385 that cannot be recreated! CLEANFILES should be regenerated with
386 'make' as part of the build process, DISTCLEANFILES by configure
387 (e.g. Makefiles) and MAINTAINERCLEANFILES should be created by
388 'autogen.sh' and the programs it calls (e.g. Makefile.in's which are
389 created by automake).
390
391 5.2 Make and subdirectories
392 ---------------------------
393 If a Makefile.am has a SUBDIRS macro, make will recurse through these
394 subdirectories, running make in each one. e.g. in the top-level
395 Makefile.am:
396
397 SUBDIRS = include src samples test po man doc scripts
398
399 In this case the order of directories is critical: lib, src and test
400 depend on include being built. Also, test depends on libgutenprint in
401 src and po must be run after all the source has been built (as it
402 parses all C source, possibly including dynamically generated code).
403 The same applies in src/Makefile.am: most directories require
404 libgutenprint for linking with, and libgutenprint requires printdef.
405
406 Therefore the order of building is critical! It should be technically
407 possible to run make in any subdirectory and have all the dependencies
408 satisfied by rules in that Makefile. Unfortunately, this requires
409 complex rules in each directory, and this cannot be done as the source
410 tree gets bigger and more complex. As a result, one should only run
411 make from the top level, as only this is certain to satisfy all
412 dependencies.
413
414 5.3 Conditional compilation
415 ---------------------------
416 Most of the source is conditionally compiled according to the defaults
417 in configure.ac, which may be overridden by passing options to
418 configure, or possibly by the results of configure checks. Depending
419 on the result, configure may substitute what to build into the
420 generated Makefile, e.g.:
421
422 if BUILD_ESCPUTIL
423 bin_PROGRAMS = escputil
424 endif
425
426 If you use @@ substitutions, make sure that you use the EXTRA_ prefix
427 (e.g. EXTRA_PROGRAMS), so that automake knows what is to be built.
428
429 5.4 When automake is not enough...
430 ----------------------------------
431 When one wants to do something that is not within the scope of the
432 facilities automake provides, one can write one's own rules, just like
433 in any other Makefile.
434
435 4.4.1 Rule syntax
436 Make rules take the following form:
437
438 target ... : prerequisites ...
439 commands
440 ...
441 ...
442 where
443 target is the name of a file (or files) to create
444 prerequisites are files that are needed to make the target
445 commands are commands to make the target
446
447 The target will only be made if it does not exist or the timestamp on
448 any of the prerequisites is newer, indicating that it is out of date.
449
450 make is a complex program, and this is just the bare basic
451 operation. See the GNU make info documentation for a detailed
452 explanation.
453
454 4.4.2 Correctly referencing files
455 A file may be present either in the _source_ or _build_ directory,
456 which may or may not be the same. The source directory contains the
457 unchanging source files, whereas the build directory contains all the
458 generated files, such as Makefiles, object code, libraries and
459 executables and also generated headers, C source and manual pages.
460 The macros to use are:
461
462 $(srcdir) The equivalent directory in the source tree
463 . The build directory (current directory)
464 $(top_srcdir) The highest level of the source tree
465 $(top_builddir) The highest level of the build tree
466
467
468 6. aclocal
469 ----------
470
471 aclocal contains all the macros that are needed by autoconf to
472 generate configure from configure.ac. It is created by running
473 'aclocal'. If any of the macros are not present on your system, you
474 can point out where the macros distributed with Gutenprint are by
475 using '-I macrodir' with aclocal.
476
477
478 7. config.h
479 -----------
480
481 config.h is created by configure and should beincluded by all of the C
482 source files in the distribution. It is created from config.h.in by
483 'configure'. config.h.in is created from configure.ac by
484 'autoheader'.
485
486
487 8. libgutenprint
488 ----------------
489
490 Any source that is to link with libgutenprint should include the gutenprint.h
491 header. The right way to do this is as follows:
492
493 #include <gutenprint/gutenprint.h>
494
495 To ensure proper linking, the Makefile.am should have the following:
496
497 program_LDADD = $(LIBGUTENPRINT_LIBS)
498
499 The Makefile.am should also include any necessary CFLAGS with:
500
501 LOCAL_CPPFLAGS = $(LIBGUTENPRINT_CFLAGS)
502
503
504 9. automake subtleties
505 ----------------------
506
507 Automake parses Makefile.am to produce Makefile.in. Makefile.am looks
508 much like a normal Makefile, e.g. you can write your own rules in it.
509 However, it is not entirely like a normal Makefile. In particular,
510 automake conditionals are not the same as make conditionals (which are
511 not available).
512
513 Another gotcha is that automake adds rules of its own, so you must make sure
514 that the names do not clash, or you may get obscure problems occurring
515 when you override an automake rule.
516
517
518 10. libtool tricks
519 ------------------
520
521 libtool is used to create shared libraries. One gotcha with libtool
522 is that if a program is linked with a libtool shared library in the
523 build tree, then it is actually created in '.libs/program', and not
524 'program'. However, if it is statically linked (e.g. the platform
525 does not support shared libraries, or you used --disable-shared with
526 configure, perhaps to make the build faster or to be able to use
527 `valgrind' usefully), then it will be created as 'program'. This is
528 so that you can run the program before you install it. If it is
529 linked with shared libraries, a wrapper script does some magic with
530 LD_LIBRARY_PATH. However, this means that your install rules must
531 take this into account by checking that '.libs/program exists', and
532 installing it if it is present, but otherwise installing 'program'.
533 Automake install rules do this automatically, but it you write your
534 own, you must take this into consideration. The best option is to not
535 use custom install rules for binaries.
536
537
538 11. Testing changes to the build scripts
539 ---------------------------------------
540
541 If you make a change to one of the scripts, simply running autogen.sh
542 and seeing if 'make' and 'make install' work is not enough. In
543 particular, you must check that it does not break 'VPATH' builds where
544 the source and build directories are not the same. To do this:
545
546 $ mkdir /var/tmp/tmp-build
547 $ cd /var/tmp/tmp-build
548 $ ~roger/gutenprint/current/configure [options]
549 $ make
550 $ make DESTDIR=/var/tmp/tmp-inst install
551
552 You should also test that 'make install' works with and without
553 DESTDIR set. Note that old gettext releases do not support DESTDIR,
554 but the current 0.10.x versions do. The old gettext also breaks in
555 VPATH builds due to MKINSTALLDIRS being wrongly defined. This is also
556 fixed in the current version.
557
558
559 12. Further information
560 -----------------------
561
562 autoconf: autoconf.info
563 automake: automake.info
564 git: git.info
565 gettext: gettext.info
566 libtool: libtool.info
567 make: make.info
568
569
570
571 Local Variables:
572 mode: text
573 End: