This is the PostgreSQL Installer build system. This document attempts to describe how the system is architected, how to set it up and how to extend it. It is a work in progress and will no doubt require further refinement over time. There there is one goal however:
Build all PostgresSQL & add-on package installers for all supported platforms with a single command.
Note that this system is not intended to replace the existing installer system used on Windows (pgInstaller) - it is intended to mirror it's basic functionality however.
The modular system is designed to be as flexible as possible and allow package authors as much freedom as possible in the way they design their installers. There are some basic rules about how we design add-on packages however - it remains up to the individual author to determine whether or not breaking any rules will break their package. They had better not break the system though!
A central registry file is used in which packages should register themselves. This data will be used by StackBuilder to locate installed packages. The registry file is /etc/postgres-reg.ini, and should be considered analagous in function to the sections of the Windows registry used for the same purposes on that platform.
StackBuilder requires specific entries for the PostgreSQL server, as well as an entry indicating the installed version of each unique package. An example file is show below.
; This section is for a server, and is analagous to the PostgreSQL key under ; HKEY_CURRENT_USER\Software on Windows [PostgreSQL\8.3] Version=8.3.3 InstallationDirectory=/opt/PostgreSQL/8.3 DataDirectory=/opt/PostgreSQL/8.3/data Port=5432 Superuser=postgres
[PostGIS_1_3_PG83] Version=1.3.2
[pgAdmin3] Version=1.8.4 InstallationDirectory=/opt/pgAdmin3
It is up to the uninstaller for each package to leave or clean the data during uninstallation. The version number for a package should always be cleared, but other data may be retained. For example, the server package will not remove the data directory, thus it is appropriate to leave the DataDirectory, Port and Superuser values intact.
Each package installer should be capable of being silently or interactively installing and uninstalling the package. When uninstalling, as much of the package as possible should be removed, however it is not always possible (through lack of reference counting between packages) or desirable to remove everything.
The build platform is Mac OS X Snow Leopard. We use OS X because it allows us to run all other Intel based OS's on the same machine. All other supported platforms are run in VMWare Fusion virtual machines, with the exception of Solaris Sparc which obviously must be an external machine. The supported platforms can be set as external machines if required by exposing nfs shares from mac.
A number of additional dependencies are required when setting up the system, such as libxml2 and libxslt, as well as useful utilties such as wget. Setting these up correct is essentially to ensuring future Universal binary builds will work as expected on all supported OS X versions (10.5/Leopard and above).
Utilities should be installed using MacPorts:
Download the installer from http://www.macports.org/ and install the package.
Add /opt/local/bin:/opt/local/sbin to the end of the path. Add the following line to ~/.bash_profile for the buildfarm user:
export PATH=$PATH:/opt/local/bin:/opt/local/sbin
$ sudo port install cmake $ sudo port install wget $ sudo port install apache-ant $ sudo port install bison $ sudo port install flex $ sudo port install ossp-uuid
Dependency libraries must be built with a little more control to ensure they use the correct SDK to allow them to be used on Tiger and above. We manually build and install these packages into /usr/local/
Download the source for each library (eg. libuuid, libxml2 & libxslt).
Unpack the source into /usr/local/src
Configure the source with a command such as:
CFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -arch i386 -arch x86_64 -arch ppc" LDFLAGS="-arch i386 -arch ppc -arch x86_64" ./configure --prefix=/usr/local/ --disable-dependency-tracking
make all sudo make install
Note that we must make sure all additional libraries link against these libraries, and not the older, system copies. In the case of libxslt, we can do this by configuring with --with-libxml-prefix=/usr/local
libuuid will typically link only in the primary architecture of the build machine. To fix this, remove the library (libuuid.16.dylib) from .libs/ and re-run the final link command, with the addition of appropriate -arch flags.
Install unix2dos utility: $sudo port install unix2dos
Set up DocBook SGML
Configuring DocBook SGML on Mac OS X with MacPorts.
1) Install the following packages using MacPorts:
opensp
openjade
docbook-xsl
docbook2X
2) Download the docbook-dsssl stylesheets from http://sourceforge.net/project/showfiles.php?group_id=21935&package_id=16611 and then unpack the archive in /opt/local/share/sgml
3) Add a symlink so PostgreSQL can find the stylesheets:
sudo ln -s /opt/local/share/sgml/docbook-dsssl-1.79 \
/usr/local/share/sgml/docbook-dsssl
3) Download DockBook 4.2 (http://www.docbook.org/sgml/4.2/docbook-4.2.zip) and the ISO 8879 character entities (http://www.oasis-open.org/cover/ISOEnts.zip)
4) Unzip both archives into /opt/local/share/sgml/docbook-4.2
5) Ensure that all the unpacked files are world readable.
6) Run the following command in the docbook-4.2 directory:
perl -pi -e 's/iso-(.*).gml/ISO\1/g' docbook.cat
7) Create the file /opt/local/share/sgml/catalog, with the following contents:
CATALOG "openjade/catalog"
CATALOG "docbook-4.2/docbook.cat"
CATALOG "docbook-dsssl-1.79/catalog"
8) Make sure that settings.sh is updated with docbook installation path.
When building on Snow Leopard, using the Leopard SDK a failure may be seen when configuring PostgreSQL for PAM. This is because the PAM header location moved from /usr/include/pam in 10.5 to /usr/include/security in 10.6. The difference between the base OS and the SDK confuses configure. To avoid this, it may be necessary to move the PAM headers in /usr/include/security/security so configure cannot find them.
Snow Leopard only ships with Java 1.6, but most of our code, as well as pl/java should be compiled with 1.5.
1) Download the Jlast Java update for Leopard: http://support.apple.com/downloads/java_for_Mac_OS_X_10_5_Update_5
2) Download Pacifist from http://www.charlessoft.com/
3) IMPORTANT Delete the symlinks, 1.5 and 1.5.0 from /System/Library/Frameworks/JavaVM.framework/Versions
4) Open the Java update in Pacifist, and extract the /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0 directory into the corresponding location on the hard disk.
5) Recreate the 1.5 symlink, to point to the 1.5.0 directory.
You can now use Java 1.5, by setting JAVA_HOME to: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
NOTE: That this update may have to be repeated following any Java updates from Apple.
Couple of packages needs hacking, while building on snow leopard. PHP: http://www.firewing1.com/node/31 Slony-I: http://www.slony.info/bugzilla/show_bug.cgi?id=109
All VMs (and in fact, the host machine) are setup to use user accounts called 'buildfarm'. In order to access each, the VMs must be setup with fixed IP addresses which are recorded with an appropriate hostname in DNS. Each hostname is specified in settings.sh. It may be necessary to manually configure VMWare Fusion to bridge the network adaptor instead of using NAT.
The top level 'pginstaller' directory is shared with all the VMs using the VMware shared folders feature. The path to this directory is specified in settings.h for each VM. Note that VMware doesn't map UIDs/GIDs between the host and the VMs so it may be necessary to mount the shared directory using the UID/GID of the user in the VM, eg using the following in /etc/fstab:
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5,uid=500,gid=500 0 0
SSH authentication between hosts is achieved using certificates. These can be generated on the host machine using:
ssh-keygen -t rsa
Copy the resulting id_rsa.pub file to ~/.ssh/authorized_keys on each VM.
Linux/Linux-x64
Install chrpath utility in order to change the rpath of the installed PostgreSQL binaries in the staging directory. Use the following command to install the chrpath:
Windows
The Windows VM is the most tricky to setup:
Note: In case of Windows-64 setup you may get errors related to: LINK : fatal error LNK1181: cannot open input file 'bufferoverflowU.lib'^M Main reason of this issue is bufferoverflowU.lib file missing in parallel directory structures of VC installation. To reslove this copy said file into parallel structure e.g.: cp /cygdrive/c/Program\ Files\ (x86)/Microsoft\ SDKs/Windows/v5.0/Lib/IA64/bufferoverflowu.lib /cygdrive/c/Program\ Files/Microsoft\ SDKs/Windows/v6.0A/Lib/x64/.
Creating a new VM for new codepath from an existing VM on the same machine:
In order to set build machines as external machines, Create NFS share pointing to top level 'pginstaller' directory on Mac. For this purpose free tool 'NFS Manager' can be used. On linux side, update /etc/fstab to create nfs mount to this NFS share.
This script is derived from settings.sh.in which is stored in source control. It is configured for the specific build machine, and allows us to specify what platforms and modules we're building, and some global configuration options.
This script (and the source version, settings.h.in) must be edited whenever new platforms or packages are added.
This script contains common utility functions that may be used throughout the build system.
This script is the main build script. To build everything, simply run the following command on the build host:
sh build.sh
For quick rebuilds, an option is provided to rebuild just the installers from the existing code in the staging directories:
sh build.sh -skipbuild
This script must be edited whenever a new module is added to call the appropriate functions in the package build script.
This directory will contain all the completed installers.
This directory contains miscellaneous scripts that may be useful to multiple modules or the overall build system.
This directory contains installer resources that may be useful to multiple modules or the overall build system.
This directory contains all the tarballs we use for builds
Each additional directory contains a single package. These may be internally built
as required, though the interface should remain consistent - ie. a single build
script called build.sh, exposing functions called prep
For a description fo the build system for a single package, see server/README.
Adding gd module to php in Windows
Prequisites:
1) jpeg (http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/jpeg-6b-4.exe) 2) libpng (http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/libpng-1.2.36-setup.exe) 3) freetype (http://nchc.dl.sourceforge.net/sourceforge/gnuwin32/freetype-2.3.5-1-setup.exe)
Install these in the pgBuild directory as jpeg, libpng and freetype respectively.
Modifications:
Freetype:
1) Modify the directory structure as:
freetype --> include --> freetype2 --> freetype to freetype --> include --> freetype
(leave the ft2build.h file in include directory as it is.)
2) Copy the files:
freetype/lib/freetype.lib to freetype/lib/freetype2.lib
jpeg:
1) Copy the files:
jpeg/lib/jpeg.lib to jpeg/lib/libjpeg.lib
Adding gd module to php in osx
Prequisites: 1) Install jpeg libraries Download and extract jpeg from http://www.ijg.org/ Compile and install:
env CFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -arch i386 -arch ppc -arch x86_64" LDFLAGS="-arch i386 -arch ppc -arch x86_64" ./configure --prefix=/usr/local --disable-dependency-tracking make sudo make install
2) Install libpng (User only 1.2.x version - php-5.2.1 has not yet include support for 1.4.x version) Download and extract libpng from http://www.libpng.org/pub/png/pngcode.html Compile and install:
env CFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -arch i386 -arch ppc -arch x86_64" LDFLAGS="-arch i386 -arch ppc -arch x86_64" ./configure --prefix=/usr/local --disable-dependency-tracking make sudo make install
3) Install freetype Download and extract freetype from http://freetype.org/download.html
env CFLAGS="-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -arch i386 -arch ppc -arch x86_64" LDFLAGS="-arch i386 -arch ppc -arch x86_64" ./configure --prefix=/usr/local --disable-dependency-tracking make sudo make install
Adding gd module to php in linux
Prequisites: (linux/linux-x64)
1) yum install freetype 2) yum install libpng (libjpeg.so should also be present in /usr/lib and /usr/lib64 for linux and linux-x64 respectively)
Install the latest version of ActiveState Python, Perl & TCL/Tk on all the platforms.
Install SPHINX for generating documentation for generating documentations for
pgAdmin3.
i.e.
Trouble-Shooting:
/opt/ActivePython-3.2/bin/python3.2 ActivePython 3.2.2.3 (ActiveState Software Inc.) based on Python 3.2.2 (default, Sep 8 2011, 12:20:28) [GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import hashlib; ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 141, in
globals()[func_name] = __get_hash(func_name) File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 91, in get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type md5 ERROR:root:code for hash sha1 was not found. Traceback (most recent call last): File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 141, in globals()[ func_name] = get_hash(__func_name) File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 91, in get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha1 ERROR:root:code for hash sha224 was not found. Traceback (most recent call last): File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 141, inglobals()[func_name] = __get_hash(func_name) File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 91, in get_builtin_constructor raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha224 ERROR:root:code for hash sha256 was not found. Traceback (most recent call last): File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 141, in globals()[ func_name] = get_hash(__func_name) File "/opt/ActivePython-3.2/lib/python3.2/hashlib.py", line 91, in get_builtin_constructor raise ValueError('unsupported hash type %s' % name)In order to resolve the issue, I had to run the following command as 'root' user. chcon -t texrel_shlib_t /opt/ActivePython-3.2/lib/python3.2/lib-dynload/_hashlib.cpython-32m.so
Contact dpage@pgadmin.org for further info.