summaryrefslogtreecommitdiff
path: root/libpq/README-DEV
blob: 6ccf1cc98be7665e3ddf012e8dd6561bf06a16f3 (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
This document describes how libpq was packaged for build2. In particular, this
understanding will be useful when upgrading to a new upstream version. See
../README-DEV for general notes on PostgreSQL packaging.

The upstream package builds the common and ports static libraries and links
them to the libpq library. These static libraries are generic enough to fit
all the binaries built by the package. We will build libpq by only selecting
the required static libraries source files, relying on the linker diagnostics
(unresolved symbol errors, etc).

Symlink the required upstream components and provide our own implementations
for auto-generated headers:

$ ln -s ../upstream/COPYRIGHT

Note that we symlink the libpq directory under the different name not to
confuse the headers auto-generating machinery while it maps the header
directory prefixes.

$ ln -s ../../upstream/src/interfaces/libpq libpq/pq

Note that symlinking all the upstream's top source directories is a bad idea
since this would potentially bloat the distribution, uglify the buildfile, and
complicate pg_config.h change tracking on upgrade (see below). Also note that
some of the source files are shared with the psql package and this sharing
doesn't align with such an approach. Thus, we selectively symlink only the
required files.

$ mkdir -p libpq/include/libpq libpq/include/mb libpq/include/port
$ ln -s ../../../upstream/src/include/{c,getaddrinfo,pg_config_manual,port,postgres_ext,postgres_fe}.h libpq/include
$ ln -s ../../../upstream/src/include/common libpq/include
$ ln -s ../../../../upstream/src/include/libpq/{libpq-fs,pqcomm}.h libpq/include/libpq
$ ln -s ../../../../upstream/src/include/mb/pg_wchar.h libpq/include/mb
$ ln -s ../../../../upstream/src/include/port/{linux,freebsd,darwin,win32,win32_port,pg_bswap}.h libpq/include/port
$ ln -s ../../../../upstream/src/include/port/{win32,win32_msvc} libpq/include/port

$ mkdir libpq/common
$ ln -s ../../../upstream/src/common/{base64,cryptohash_openssl,encnames,hmac_openssl,ip,link-canary,md5,md5_common,saslprep,scram-common,string,unicode_norm,wchar}.c libpq/common
$ ln -s ../../../upstream/src/common/md5_int.h libpq/common

$ mkdir libpq/port
$ ln -s ../../../upstream/src/port/{chklocale,explicit_bzero,getaddrinfo,getpeereid,gettimeofday,inet_aton,inet_net_ntop,noblock,open,pg_strong_random,pgsleep,pgstrcasecmp,snprintf,strerror,strlcpy,system,thread,win32error,win32setlocale,win32stat}.c libpq/port
$ ln -s ../../../upstream/src/port/pthread-win32.h libpq/port

$ ln -s ../../upstream/src/include/pg_config_ext.h.in libpq/pg_config_ext.h.in.orig
$ ln -s ../../upstream/src/include/pg_config.h.in libpq/pg_config.h.in.orig

$ ln -s ../../../upstream/src/interfaces/libpq/test/uri-regress.c tests/conninfo

Create libpq/{pg_config,pg_config_ext,pg_config_os,pg_config_paths}.h using as
a base the upstream's auto-generated headers and/or the corresponding
templates, makefiles, and perl/batch/shell scripts.

Note that re-creating libpq/pg_config.h from scratch every time we upgrade to
a new upstream version would be a real pain. Instead we can only (un)define
the newly introduced macros, comparing the already defined and currently used
macro sets:

$ for m in `cat libpq/pg_config.h.in.orig | \
            sed -n 's/^.*#\s*\(define\|undef\)\s\{1,\}\([_A-Z0-9]\{1,\}\)\(\s.*\)\{0,1\}$/\2/p' | \
            sort -u`; do
    if grep -q -e "\b$m\b" `find -L . ../psql -name '*.h' -a ! -name 'pg_config.h' -o -name '*.c'`; then
      echo "$m"
    fi
  done >used-macros

$ cat libpq/pg_config.h | \
  sed -n 's/^#\s*\(define\|undef\)\s\{1,\}\([_A-Z0-9]\{1,\}\)\(\s.*\)\{0,1\}$/\2/p' | \
  sort -u >defined-macros

$ diff defined-macros used-macros