How to Build a Better haproxy RPM

There are several RPM builds of haproxy that can be found throughout the Internet.  There are GitHub repositories with customized .spec files to build your own RPM.  In fact, there is an haproxy.spec file that may be found in the official .tar.gz file under examples.  However, here is a unique way to build one as close to the original, haproxy-1.5.4-2.el6.rpm, official build found in the CentOS 6  base repositories.

Using rpmrebuild, it was plain that the official build used this source, haproxy-1.5.4-2.el6.src.rpm.

Download Dependancies

yum install -y rpm-build rpmdevtools pcre-devel openssl-devel zlib-devel redhat-rpm-config gcc gcc-c++ make libstdc++-devel wget rpmlint vim

Create your build environment

cd ~/rpmbuild/SOURCES/

Download and Build

# Download the original source RPM used to create the official yum update RPM
wget http://vault.centos.org/6.7/os/Source/SPackages/haproxy-1.5.4-2.el6.src.rpm
# Extract to ~/rpmbuild/SOURCES/
rpm2cpio haproxy-1.5.4-2.el6.src.rpm | cpio --extract --make-directories --verbose

# Copy the haproxy.spec file to correct location
cp ~/rpmbuild/SOURCES/haproxy.spec ~/rpmbuild/SPECS/haproxy.spec

# Modify the haproxy.spec file
sed -i "/Version: / s/$(grep ^Version haproxy.spec | cut -d" " -f2-)/1.5.16/g" ~/rpmbuild/SPECS/haproxy.spec

# Download the dependencies
spectool -R -g ~/rpmbuild/SPECS/haproxy.spec

# Bump the build and comment it.
rpmdev-bumpspec --comment="Build from source" --userstring="Canon <canon@it.megocollector.com>" ~/rpmbuild/SPECS/haproxy.spec

# Optional: check the .spec
rpmlint ~/rpmbuild/SPECS/haproxy.spec

# Build it
rpmbuild -ba ~/rpmbuild/SPECS/haproxy.spec

Check out your Build

rpm -qlp /root/rpmbuild/RPMS/x86_64/haproxy-1.5.16-3.el6.x86_64.rpm

Install it

yum install haproxy-1.5.16-3.el6.x86_64.rpm

If you attempt to manually build from source ip6range, you may be presented with many, many errors and no build.

total 16
-rw-r--r--. 1 root root   160 Mar 13 19:16 Makefile
-rw-r--r--. 1 root root 11687 Mar 13 19:16 ip6range.c

For reasons that can be found elsewhere, the structure of one of the helper files and that of the ip6range.c file had changed.  Do this to fix it and use make to build it.  Enjoy.

sed -i 's/in6_u.u6_addr32/__in6_u.__u6_addr32/g' ip6range.c