We need to install various packages in order to build ibm_db2. Most of these can be installed with yum:
yum group install 'Development tools'
yum install gitNext, since Zend PHP is 32-bit, we need a compiler that can build 32-bit binaries. The version of GCC shipped by yum can't do this. If you already have an AIX gcc compiler installed, you can skip to the next section, otherwise read on.
We'll need to get some more tools to install these AIX rpms, since the IBM i rpm cannot install them directly:
yum install wget cpio-gnumkdir ~/gcc-rpms
cd ~/gcc-rpms
wget http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/gcc-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/gcc-cplusplus-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/gcc-cpp-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/libstdcplusplus-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/libstdcplusplus-devel-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc-7.1/gcc/libgcc-6.3.0-1.aix7.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc/mpfr/mpfr-3.1.2-3.aix6.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc/libmpc/libmpc-1.0.3-1.aix6.1.ppc.rpm \
http://public.dhe.ibm.com/aix/freeSoftware/aixtoolbox/RPMS/ppc/gmp/gmp-5.1.3-2.aix6.1.ppc.rpm
for f in *.rpm
do
rpm2cpio $f | /QOpenSys/pkgs/bin/cpio -id
done
mkdir /QOpenSys/opt
ln -s /QOpenSys/opt /opt
cp -r opt/freeware /optYou should now have gcc installed under /opt/freeware/bin.
The build process needs the CLI headers to build against libdb400. These are the same headers that are used to build ILE CLI applications (linking to QSQCLI service program), but unfortunately they are not shipped in a format that can be used by the PASE compilers.
The following code snippet will copy the necessary CLI headers to /QOpenSys/usr/include and in the process: convert from EBCDIC to UTF-8, split at 80 columns, and replace any trailing whitespace.
for f in sql.h sqlcli.h sqlsystm.h sqludf.h
do
/QOpenSys/usr/bin/iconv -f IBM-037 -t UTF-8 /QIBM/include/$f | fold -b -w 80 | sed 's| *$||g' > /QOpenSys/usr/include/$f
doneThe ibm_db2 uses sqlcli1.h as its main header file, since that's what Db2 LUW uses, but IBM i does not have such a header. We can easily fix this by making our own which just imports sqlcli.h:
cat <<EOF > /QOpenSys/usr/include/sqlcli1.h
#include <sqlcli.h>
EOFPHP has a bug in how it generates PHP modules on AIX so before we can build our PHP module, we have to patch it. This only has to be done once.
yum install wget
pushd /usr/local/zendphp7/lib/php/build
wget --no-check-certifiates https://gist.github.com/kadler/ce6d6e3ce2b1d837636f9866410a0840/raw/74be487c181071468c58d0e8a7e993b9f0cff852/php-acinclude.m4.patch
patch -p0 < php-aclocal.m4.patch
popdNormally, you could download the source from https://pecl.php.net/package/ibm_db2, but as of version 2.0.6, it will not build on IBM i due to bugs. Instead, we'll download the code from my GitHub repo.
cd ~ # or wherever you want the code to live
git clone https://github.com/kadler/pecl-database-ibm_db2.git ibm_db2Now that we have the source code, we're ready to build. The basics of building a PECL are:
phpize
./configure
makeHere's what we actually need to do to get things configured. This usually only needs to be done once:
PATH=/usr/local/zendphp7/bin:/opt/freeware/bin:$PATH
export LDFLAGS='-Wl,-brtl -Wl,-blibpath:/QOpenSys/usr/lib:/opt/freeware/lib'
export OBJECT_MODE=32
export CC=gcc
export CXX=g++
phpize
./configure --with-IBM_DB2=/QOpenSys/usr --host=powerpc-ibm-aix6 --build=powerpc-ibm-aix6Once configure has finished successfully, we can run make:
makeIf all goes, well you should see:
Build complete.
Don't forget to run 'make test'.
If you make changes to ibm_db2.c or php_ibm_db2.h, you'll need to re-run make (but not configure or other previous build steps).
** TODO **