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 selecting only 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 while we could symlink the upstream's top source directories, this would potentially bloat the distribution, uglify the buildfile, and complicate pg_config.h change tracking on upgrade (see below). Thus, we selectively symlink only the required files. $ mkdir libpq/mb $ ln -s ../../../upstream/src/backend/utils/mb/{encnames,wchar}.c libpq/mb $ 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/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/{md5,scram-common,ip,sha2_openssl,link-canary,base64,saslprep,unicode_norm}.c \ libpq/common $ mkdir libpq/port $ ln -s ../../../upstream/src/port/{pgstrcasecmp,snprintf,getpeereid,pg_strong_random,thread,strerror,chklocale,noblock,inet_net_ntop,strlcpy,win32setlocale,getaddrinfo,open,inet_aton,pgsleep,win32error,system}.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_ext.h.win32 libpq/pg_config_ext.h.win32.orig $ ln -s ../../upstream/src/include/pg_config.h.in libpq/pg_config.h.in.orig $ ln -s ../../upstream/src/include/pg_config.h.win32 libpq/pg_config.h.win32.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 libpq/pg_config.h.win32.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 . -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 Copy upstream's auto-generated src/interfaces/libpq/{exports.list,libpqdll.def} to libpq/{libpqdll.map,libpqdll.def} or create them manually based on pq/exports.txt. Comment out the "LIBRARY LIBPQ" line in libpqdll.def.