This document describes an approach applied to packaging PostgreSQL for build2. In particular, this understanding will be useful when upgrading to a new upstream version. The upstream package contains the PostgreSQL server, libpq library, and client utilities. Currently, we only package libpq and psql (see the respective README-DEV files for details). We add the upstream package as a git submodule and symlink the required files and subdirectories into the build2 package subdirectories. Then, when required, we "overlay" the upstream with our own headers, placing them into the library directory. Note that symlinking upstream submodule subdirectories into a build2 package subdirectory results in creating intermediate build files (.d, .o, etc) inside upstream directory while building the package in source tree. That's why we need to make sure that packages do not share upstream source files via subdirectory symlinks, not to also share the related intermediate files. If several packages need to compile the same upstream source file, then only one of them can symlink it via the parent directory while others must symlink it directly. We also add the `ignore = untracked` configuration option into .gitmodules to make sure that git ignores the intermediate build files under upstream/ subdirectory. The upstream package can be configured to contain a specific feature set. We reproduce the union of features configured for the upstream source package in Debian and Fedora distributions. The configuration options defining these sets are specified in the Debian's rules and Fedora's RPM .spec files. These files can be obtained as follows: $ wget http://deb.debian.org/debian/pool/main/p/postgresql-14/postgresql-14_14.0-1.debian.tar.xz $ tar xf postgresql-14_14.0-1.debian.tar.xz $ wget https://kojipkgs.fedoraproject.org/packages/libpq/14.1/2.fc36/src/libpq-14.1-2.fc36.src.rpm $ rpm2cpio libpq-14.1-2.fc36.src.rpm | cpio -civ '*.spec' $ wget https://kojipkgs.fedoraproject.org/packages/postgresql/14.1/3.fc36/src/postgresql-14.1-3.fc36.src.rpm $ rpm2cpio postgresql-14.1-3.fc36.src.rpm | cpio -civ '*.spec' Note that on Fedora libpq and psql are build from the separate source RPM packages and so by using the different RPM specs. As a side note, on Debian and Fedora the source, library, headers, and program are packaged as follows: src libpq headers psql Debian/Ubuntu: postgresql-11 libpq5 libpq-dev postgresql-client-11 Fedora/RHEL: libpq libpq libpq-devel postgresql postgresql Search for the Debian and Fedora packages at https://packages.debian.org/search and https://src.fedoraproject.org/. Here are the discovered configuration options. Debian: --with-icu --with-tcl --with-perl --with-python --with-pam --with-openssl --with-libxml --with-libxslt --enable-nls --with-lz4 --with-gssapi --with-ldap --enable-thread-safety Fedora: libpq: --with-ldap --with-openssl --with-gssapi --enable-nls --without-readline postgresql: --disable-rpath --with-tcl --with-ldap --with-openssl --with-pam --with-gssapi --with-ossp-uuid --with-libxml --with-libxslt --enable-nls --enable-dtrace --with-selinux --with-system-tzdata --datadir --with-systemd --with-icu --with-llvm --with-python The union of these feature sets translates into the following options, after suppressing the defaults: --with-icu --with-tcl --with-perl --with-python --with-pam --with-openssl --with-libxml --with-libxslt --enable-nls --with-gssapi --with-ldap --with-ossp-uuid --enable-dtrace --enable-dtrace --with-selinux --with-system-tzdata --datadir --with-systemd --with-llvm We, however, drop the external dependencies that are irrelevant for libpq and psql or are not packaged for build2 and end up with the following options: --with-ssl=openssl --without-readline --without-zlib See the configuration options description at the "Installation Procedure" page (https://www.postgresql.org/docs/14/install-procedure.html). Normally, when packaging a project, we need to replace some auto-generated headers with our own implementations and deduce compilation/linking options. For PostgreSQL we can rely on the configure.in, GNUmakefile.in, and the manually maintained makefiles for that. In practice, however, that can be uneasy and error prone, so you may also need to refer to auto-generated header files or to see the actual compiler and linker command lines in the build log. If that's the case, you can configure/build the upstream package on the platform of interest running the following commands in the upstream project root directory. On POSIX and for MinGW GCC: $ mkdir build $ cd build $ ../configure --with-ssl=openssl --without-readline --without-zlib >build.log 2>&1 $ cd src/interfaces/libpq $ make VERBOSE=1 >>../../../build.log 2>&1 $ cd ../../bin/psql $ make VERBOSE=1 >>../../../build.log 2>&1 See the "Installation from Source Code" page (https://www.postgresql.org/docs/14/installation.html) for details. For MSVC: Add bison and flex to PATH, if building in the git repository. Install OpenSSL and zlib. > cd src\tools\msvc Edit config_default.pl to enable OpenSSL: openssl => 'c:\OpenSSL', # --with-openssl= > build libpq >>build.log 2>&1 > build psql >>build.log 2>&1 See the "Installation from Source Code on Windows" page (https://www.postgresql.org/docs/14/install-windows.html) for details. When the packaging is complete, build all the project packages in source tree and make sure that no PostgreSQL headers are included from the system, running the following commands from the project root: $ cat `find . -name '*.d'` | sort -u >headers $ emacs headers # Edit, leaving system headers only. $ fgrep PostgreSQL