summaryrefslogtreecommitdiffstats
path: root/pg_buildext.pod
blob: 37063f984048752ce821355482f9b2401e7e6c91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
=head1 NAME

pg_buildext - Build and install a PostgreSQL extension

=head1 SYNOPSIS

B<pg_buildext> [I<options>] I<action> [I<src-dir>] [I<arguments>]

=head1 DESCRIPTION

B<pg_buildext> is a script that will build a PostgreSQL extension in a C<VPATH>
way, for potentially several PostgreSQL server versions in parallel.
It builds for the intersection of versions known in
C<debian/pgversions> (versions supported by the package) and in
C</usr/share/postgresql-common/supported-versions> (versions supported in this
release).

Many PostgreSQL extension packages require no special handling at build time
and can use B<dh $@ --with pgxs> or B<dh $@ --with pgxs_loop> to
automatically execute the steps outlined below.

=head1 USAGE

Packages using B<pg_buildext> should be prepared to build binaries for
PostgreSQL versions that are not present in Debian unstable, e.g. for older
releases when building backports for Debian (old)stable (possibly including
backports of newer PostgreSQL releases), or for all PostgreSQL releases when
the package is built for B<apt.postgresql.org>.

As the set of binary packages depends on the target PostgreSQL versions,
C<debian/control> is generated from a template in C<debian/control.in> when
B<pg_buildext updatecontrol> is run.
Package sections that contain B<PGVERSION> in the package name are replaced by
a list of sections, filling in the supported PostgreSQL versions.
Package sections that contain B<PGVERSION> outside the package name have the
newest supported PostgreSQL version filled in (useful for meta packages).
Include
C</usr/share/postgresql-common/pgxs_debian_control.mk> in C<debian/rules> to
run a check at build time if updating debian/control is required.

As B<pg_buildext> invokes B<make> for the B<build>, B<install>, and B<clean>
actions, invocations from C<debian/rules> (which is a makefile) should be prefixed
with B<+> so the sub-makes can talk with the make jobserver. Additional makefile
variables can be passed to B<make> via the B<-m> option.

Many extensions support B<make installcheck> testing using B<pg_regress>. As
this needs the package to be installed, it cannot be run at build time.
Instead, the tests should be run using B<autopkgtest> from C<debian/tests/*>.

If C<debian/tests/control.in> exists, occurrences of package names containing
B<PGVERSION> are replaced by lists of package names with the target PostgreSQL
versions filled in. (If no replacing is needed in C<debian/tests/control>, it
is fine to provide the tests control file directly.)

=head1 OPTIONS

=over 4

=item B<-cio> I<arg>

=item B<-s>

Passed to B<pg_virtualenv> when running B<installcheck>.

=item B<-m> I<arg>

Passed to B<make>.

=back

=head1 ACTIONS

Most actions expect a directory name where to build the sources. It will get
created for you if it does not exist. If the I<build-dir> contains a C<%v>
sign, it will get replaced by the specific version of PostgreSQL being built
against. (Usually this parameter is C<build-%v>.)

=over 4

=item B<supported-versions>

Print effective list of supported versions, i.e. the intersection of the sets
of versions supported by the system
(from C</usr/share/postgresql-common/supported-versions>) and the package
(from C<debian/pgversions>).

Use this when building packages.

=item B<installed-versions>

In the list of installed packages, look for packages matching the B<PGVERSION>
package name templates from C<debian/control.in>, and print the PostgreSQL
major version number part.

Use this when testing packages.

=item B<checkcontrol>

Check if C<debian/control> needs updating from C<debian/control.in>. This is
invoked from C</usr/share/postgresql-common/pgxs_debian_control.mk>. When
building for a B<backports> or B<pgdg> suite as determined by
C<debian/changelog>, this action also updates the control file. Otherwise,
B<updatecontrol> needs to be run manually.

=item B<updatecontrol>

Update C<debian/control> from C<debian/control.in>, and C<debian/tests/control>
from C<debian/tests/control.in> if the latter exists.

=item B<configure> [I<src-dir>] I<build-dir> [I<extra-configure-options>]

For every supported version, call B<../configure> from the I<build-dir>
directory. (Most PostgreSQL extensions do not have a configure script.)

=item B<build> [I<src-dir>] I<build-dir> [I<extra-cflags>]

Build the extension in the I<build-dir> directory.

=item B<install> [I<src-dir>] I<build-dir> I<package-pattern>

Invoke B<make install> from the I<build-dir> directory.
The third parameter specifies the package name to use. Most packages
use B<postgresql-%v-pkgname>. Make will be
called with DESTDIR="$(CURDIR)/debian/I<package>".

The B<dpkg> substitution variable B<postgresql:Depends> is set to depend
on the required PostgreSQL server package. For compatibility with previous
packaging standards, the dependency is also added to B<misc:Depends> if
postgresql:Depends is not used.

=item B<clean> [I<src-dir>] [I<build-dir>] [I<package-pattern>]

Clean the build directories.

=item B<loop> [I<src-dir>] I<package-pattern>

As a variant to calling B<build> and B<install> separately for VPATH builds,
loop over the supported PostgreSQL versions in the top source directory. This
should be used if the package does not support VPATH builds. As it also invokes
B<make install>, it should be placed were installation happens in debian/rules,
rather than where build would normally be called.

=item B<installcheck> [I<src-dir>] [I<build-dir>] [I<package-pattern>]

Use B<pg_virtualenv make installcheck> to run the extension regression tests.
This is meant to be run from C<debian/tests/control> using B<autopkgtest>. If
I<build-dir> is omitted, the top source directory is used.

If I<package-pattern> is given, options are passed to B<pg_virtualenv> to set
up the temporary PostgreSQL instance to find extension files in
C<debian/package-directory/>.

Other than the other actions which run on the "supported" versions, if C<debian/control.in> exists, this one
runs on the "installed" versions as reported by B<installed-versions> (unless
I<package-pattern> is provided, which means we are called during a build).

=item B<psql> [I<src-dir>] [I<build-dir>] [I<package-pattern>]

=item B<virtualenv> [I<src-dir>] [I<build-dir>] [I<package-pattern>]

Like B<installcheck>, but invokes B<psql>, or a shell, both wrapped in
B<pg_virtualenv>. Input is read from stdin.

=back

Sometimes it is desirable to run extra code per version before invoking the
action, in that case the loop over supported versions needs to be in the
calling script. To facilitate this mode, actions can also be called as
I<action>B<->I<version>. See the installcheck example below.

=head1 SUPPORTED VERSIONS

B<pg_buildext> reads C<debian/pgversions> to decide which PostgreSQL to build
modules/extensions for. This file contains one PostgreSQL version number per
line, in the following formats:

=over 4

=item B<all>

Support all versions. This is recommended unless there are known incompatibilities.

=item I<NN>

Support this version.

=item I<NN>B<+>

Support this and all greater versions.

=item B<#>I<...>

Comment.

=back

For a version to be used, it must also be listed in the output of
C</usr/share/postgresql-common/supported-versions>. See this file for how to
configure the list of supported versions on your system.

=head1 EXAMPLE

=over 4

=item B<debian/control.in:>

  Source: postgresql-foobar
  Rules-Requires-Root: no
  Build-Depends:
   debhelper,
   postgresql-all <!nocheck>,
   postgresql-server-dev-all (>= 217~),

  Package: postgresql-PGVERSION-foobar
  Architecture: any
  Depends:
   ${misc:Depends},
   ${postgresql:Depends},
   ${shlibs:Depends},

=item B<debian/pgversions:>

  all

  # alternatives:
  #9.6
  #11+

=item B<debian/rules> using B<dh $@ --with pgxs>:

  #!/usr/bin/make -f

  override_dh_installdocs:
	  dh_installdocs --all README.*

  %:
	  dh $@ --with pgxs

=item If the package does no support building from subdirectories, use B<dh $@ --with pgxs_loop>:

  #!/usr/bin/make -f

  %:
	  dh $@ --with pgxs_loop

=item If the package does not use PGXS's "make installcheck" for testing:

  override_dh_pgxs_test:

=item B<debian/rules> using B<pg_buildext> directly:

  #!/usr/bin/make -f

  include /usr/share/postgresql-common/pgxs_debian_control.mk

  # omit this if the package does not use autoconf
  override_dh_auto_configure:
	  +pg_buildext configure build-%v "--libdir=/usr/lib/postgresql/%v/lib --datadir=/usr/share/postgresql-%v-foobar"

  override_dh_auto_build:
	  +pg_buildext build build-%v

  override_dh_auto_test:
	  # nothing to do here, see debian/tests/* instead

  override_dh_auto_install:
	  +pg_buildext install build-%v postgresql-%v-foobar

  override_dh_installdocs:
	  dh_installdocs --all README.*

  override_dh_auto_clean:
	  +pg_buildext clean build-%v

  %:
	  dh $@

=item B<debian/tests/control:>

  Depends: @, postgresql-server-dev-all
  Tests: installcheck
  Restrictions: allow-stderr

=item B<debian/tests/control.in:> (optional)

  Depends: @, postgresql-contrib-PGVERSION, postgresql-PGVERSION-bar
  Tests: installcheck
  Restrictions: allow-stderr

=item B<debian/tests/installcheck:>

  #!/bin/sh
  pg_buildext installcheck
  # alternatively: pg_buildext installcheck build-%v

  # Running extra code before invoking the actual action:
  set -e
  for v in $(pg_buildext installed-versions); do
	  test -L build-$v/sql || ln -s ../sql build-$v/
	  test -L build-$v/expected || ln -s ../expected build-$v/
	  pg_buildext installcheck-$v build-$v
  done

=back

=head1 SOURCE DIRECTORY

If the package source code is not in the top level directory (i.e. the directory
which has C<debian/> as subdirectory), use the I<src-dir> argument, where
I<src-dir> must be an absolute path. Example:

  override_dh_auto_build:
	  +pg_buildext build $(CURDIR)/postgresql-module build-%v

=head1 COMPATIBILITY

B<pg_buildext loop> was introduced in postgresql-server-dev-all (>= 141~).

The usage of "all" or "NN+" in debian/pgversions was introduced in
postgresql-server-dev-all (>= 148~).

B<pg_buildext installcheck> was introduced in postgresql-server-dev-all (>=
153~).

B<PG_VIRTUALENV_UNSHARE=-n> was introduced in postgresql-common (>= 170~).

Handling of C<debian/tests/control.in> with B<PGVERSION> replacement was
introduced in postgresql-common (>= 171~).

The action B<installed-versions> was introduced in postgresql-common (>= 208~).
B<installcheck> was switched to use it in the same version.

B<dh $@ --with pgxs> and B<pgxs_loop>, the corresponding B<--buildsystem>, and
the B<psql> and B<virtualenv> actions were introduced in postgresql-server-dev-all (>= 217~).

=head1 SEE ALSO

C</usr/share/postgresql-common/supported-versions>, autopkgtest(1),
pg_virtualenv(1).

=head1 AUTHORS

Dimitri Fontaine L<E<lt>dim@tapoueh.orgE<gt>>, with extensions by
Christoph Berg L<E<lt>myon@debian.orgE<gt>>.