Skip to content

Commit c13c2e7

Browse files
committed
Added DEB/RPM packaging
1 parent 779a47f commit c13c2e7

File tree

11 files changed

+382
-0
lines changed

11 files changed

+382
-0
lines changed

ext/packaging/build_deb.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
# Dependencies
4+
# sudo apt-get install git cmake curl build-essential debhelper devscripts autoconf automake libtool
5+
6+
function check_command {
7+
command=$1
8+
package=$2
9+
if ! type "$command" > /dev/null 2>&1; then
10+
echo "Missing command '$command', run: apt-get install $package"
11+
exit 1
12+
fi
13+
}
14+
15+
function header_version {
16+
read -d '' version_script << 'EOF'
17+
BEGIN { major="?"; minor="?"; patch="?" }
18+
/PHP_DRIVER_MAJOR/ { major=$3 }
19+
/PHP_DRIVER_MINOR/ { minor=$3 }
20+
/PHP_DRIVER_RELEASE/ { patch=$3 }
21+
END {
22+
printf "%s.%s.%s", major, minor, patch
23+
}
24+
EOF
25+
version=$(grep '#define[ \t]\+PHP_DRIVER_\(MAJOR\|MINOR\|RELEASE\)' $1 | awk "$version_script")
26+
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9_\-]+)?$ ]]; then
27+
echo "Unable to extract version from $1"
28+
exit 1
29+
fi
30+
echo "$version"
31+
}
32+
33+
function header_version_full {
34+
read -d '' version_script << 'EOF'
35+
BEGIN { major="?"; minor="?"; patch="?" }
36+
/PHP_DRIVER_MAJOR/ { major=$3 }
37+
/PHP_DRIVER_MINOR/ { minor=$3 }
38+
/PHP_DRIVER_RELEASE/ { patch=$3 }
39+
/PHP_DRIVER_STABILITY/ { suffix=$3; gsub(/"/, "", suffix) }
40+
END {
41+
if (length(suffix) > 0)
42+
printf "%s.%s.%s~%s", major, minor, patch, suffix
43+
else
44+
printf "%s.%s.%s", major, minor, patch
45+
}
46+
EOF
47+
version=$(grep '#define[ \t]\+PHP_DRIVER_\(MAJOR\|MINOR\|RELEASE\|STABILITY\)' $1 | awk "$version_script")
48+
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(~[a-zA-Z0-9_\-]+)?$ ]]; then
49+
echo "Unable to extract version from $1 $version"
50+
exit 1
51+
fi
52+
echo "$version"
53+
}
54+
55+
check_command "dch" "debhelper"
56+
check_command "lsb_release" "lsb-release"
57+
58+
pecl_name="cassandra"
59+
pecl_version=$(header_version "../version.h")
60+
version=$(header_version_full "../version.h")
61+
release=1
62+
dist=$(lsb_release -s -c)
63+
base="php-driver-$version"
64+
files="config.m4 php_driver.c php_driver.h php_driver_globals.h php_driver_types.h version.h src util"
65+
66+
echo "Building version $version"
67+
68+
libuv_version=$(dpkg -s libuv | grep 'Version' | awk '{ print $2 }')
69+
70+
if [[ -e $libuv_version ]]; then
71+
echo "'libuv' required, but not installed"
72+
exit 1
73+
fi
74+
75+
echo "Using libuv version $libuv_version"
76+
77+
if [[ -d build ]]; then
78+
read -p "Build directory exists, remove? [y|n] " -n 1 -r
79+
echo
80+
if [[ $REPLY =~ ^[Yy]$ ]]; then
81+
rm -rf build
82+
fi
83+
fi
84+
mkdir -p "build/$base"
85+
86+
echo "Copying files"
87+
mkdir -p "build/$base/$pecl_name-$pecl_version"
88+
cp ../package.xml "build/$base"
89+
for file in $files; do
90+
cp -r "../$file" "build/$base/$pecl_name-$pecl_version/$file"
91+
done
92+
cp -r debian "build/$base"
93+
94+
pushd "build/$base"
95+
echo "Updating changlog"
96+
dch -m -v "$version-$release" -D $dist "Version $version"
97+
98+
echo "Building package:"
99+
nprocs=$(grep -e '^processor' -c /proc/cpuinfo)
100+
DH_PHP_VERSIONS_OVERRIDE=7.0 DEB_BUILD_OPTIONS="parallel=$nprocs" debuild -i -b -uc -us
101+
popd

ext/packaging/build_rpm.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
function check_command {
4+
command=$1
5+
package=$2
6+
if ! type "$command" > /dev/null 2>&1; then
7+
echo "Missing command '$command', run: yum install $package"
8+
exit 1
9+
fi
10+
}
11+
12+
function header_version {
13+
read -d '' version_script << 'EOF'
14+
BEGIN { major="?"; minor="?"; patch="?" }
15+
/PHP_DRIVER_MAJOR/ { major=$3 }
16+
/PHP_DRIVER_MINOR/ { minor=$3 }
17+
/PHP_DRIVER_RELEASE/ { patch=$3 }
18+
/PHP_DRIVER_STABILITY/ { suffix=$3; gsub(/"/, "", suffix) }
19+
END {
20+
if (length(suffix) > 0)
21+
printf "%s.%s.%s%s", major, minor, patch, suffix
22+
else
23+
printf "%s.%s.%s", major, minor, patch
24+
}
25+
EOF
26+
version=$(grep '#define[ \t]\+PHP_DRIVER_\(MAJOR\|MINOR\|RELEASE\|STABILITY\)' $1 | awk "$version_script")
27+
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9_\-]+)?$ ]]; then
28+
echo "Unable to extract version from $1"
29+
exit 1
30+
fi
31+
echo "$version"
32+
}
33+
34+
# 'redhat-rpm-config' needs to be installed for the 'debuginfo' package
35+
check_command "rpmbuild" "rpm-build"
36+
37+
arch="x86_64"
38+
if [[ ! -z $1 ]]; then
39+
arch=$1
40+
fi
41+
42+
echo "Getting PHP version"
43+
php_version=$(php-config --version | sed -rn 's/^([0-9]+)\.([0-9]+)\.[0-9]+/\1\2w/p')
44+
45+
version=$(header_version "../version.h")
46+
package_name="php$php_version-cassandra-driver"
47+
base="$package_name-$version"
48+
archive="$base.tar.gz"
49+
files="config.m4 php_driver.c php_driver.h php_driver_globals.h php_driver_types.h version.h src util"
50+
51+
echo "Building version $version"
52+
53+
libuv_version=$(rpm -q --queryformat "%{VERSION}" libuv)
54+
55+
if [[ -e $libuv_version ]]; then
56+
echo "'libuv' required, but not installed"
57+
exit 1
58+
fi
59+
60+
echo "Using libuv version $libuv_version"
61+
62+
if [[ -d build ]]; then
63+
read -p "Build directory exists, remove? [y|n] " -n 1 -r
64+
echo
65+
if [[ $REPLY =~ ^[Yy]$ ]]; then
66+
rm -rf build
67+
fi
68+
fi
69+
mkdir -p build/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
70+
mkdir -p "build/SOURCES/$base"
71+
72+
echo "Copying files"
73+
for file in $files; do
74+
cp -r "../$file" "build/SOURCES/$base/$file"
75+
done
76+
77+
echo "Archiving $archive"
78+
pushd "build/SOURCES"
79+
tar zcf $archive $base
80+
popd
81+
82+
echo "Building package:"
83+
rpmbuild --target $arch --define "_topdir ${PWD}/build" --define "driver_version $version" --define "libuv_version $libuv_version" --define "package_name $package_name" -ba php-cassandra-driver.spec
84+
85+
exit 0

ext/packaging/debian/cassandra.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extension=cassandra.so

ext/packaging/debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
php-cassandra-driver (0.0.1-1) stable; urgency=low
2+
3+
* Initial release
4+
5+
-- Michael Penick <michael.penick@datastax.com> Fri, 30 Dec 2016 15:15:00 -0500

ext/packaging/debian/compat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

ext/packaging/debian/control

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Source: php-cassandra-driver
2+
Section: php
3+
Priority: optional
4+
Maintainer: Michael Penick <michael.penick@datastax.com>
5+
Build-Depends: debhelper (>= 9~),
6+
dh-php (>= 0.10~),
7+
php-all-dev,
8+
pkg-config,
9+
cassandra-cpp-driver-dev (>= 2.6.0)
10+
Homepage: http://datastax.github.io/php-driver/
11+
12+
Package: php-cassandra-driver
13+
Architecture: any
14+
Depends: ${misc:Depends},
15+
${php:Depends},
16+
${shlibs:Depends},
17+
cassandra-cpp-driver (>= 2.6.0)
18+
Provides: ${php:Provides}
19+
Description: A modern, feature-rich and highly tunable PHP client library for
20+
Apache Cassandra (1.2+) and DataStax Enterprise (3.1+) using exclusively
21+
Cassandra's binary protocol and Cassandra Query Language v3.

ext/packaging/debian/copyright

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Format: http://dep.debian.net/deps/dep5
2+
Upstream-Name: php-cassandra-driver
3+
Source: https://github.com/datastax/php-driver
4+
5+
Files: *
6+
Copyright: Copyright 2014-2017 DataStax
7+
License: Apache-2.0
8+
On Debian systems, the complete text of the Apache License Version 2.0
9+
can be found in `/usr/share/common-licenses/Apache-2.0'.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod debian/cassandra.ini

ext/packaging/debian/rules

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/make -f
2+
3+
# Copied from dh-php: /usr/share/dh-php/pkg-pecl.mk
4+
5+
# See debhelper(7) (uncomment to enable)
6+
# output every command that modifies files on the build system.
7+
#DH_VERBOSE = 1
8+
9+
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
10+
DPKG_EXPORT_BUILDFLAGS = 1
11+
include /usr/share/dpkg/default.mk
12+
13+
# see FEATURE AREAS in dpkg-buildflags(1)
14+
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
15+
16+
# see ENVIRONMENT in dpkg-buildflags(1)
17+
# package maintainers to append CFLAGS
18+
export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
19+
# package maintainers to append LDFLAGS
20+
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
21+
22+
# Don't ever use RPATH on Debian
23+
export PHP_RPATH=no
24+
25+
PHP_VERSIONS := $(shell /usr/sbin/phpquery -V)
26+
27+
PECL_NAME := $(if $(PECL_NAME_OVERRIDE),$(PECL_NAME_OVERRIDE),$(subst php-,,$(DEB_SOURCE)))
28+
INSTALL_ROOT = $(CURDIR)/debian/php-$(PECL_NAME)
29+
30+
# find corresponding package-PHP_MAJOR.PHP_MINOR.xml, package-PHP_MAJOR.xml or package.xml
31+
$(foreach ver,$(PHP_VERSIONS),$(eval PACKAGE_XML_$(ver) := $(word 1,$(wildcard package-$(ver).xml package-$(basename $(ver)).xml package.xml))))
32+
# fill DH_PHP_VERSIONS with versions that have corresponding package.xml and are not outside the specification
33+
$(foreach ver,$(PHP_VERSIONS),$(eval PHP_MIN_VER_$(ver) := $(if $(PACKAGE_XML_$(ver)),$(shell xml2 < $(PACKAGE_XML_$(ver)) | sed -ne "s,^/package/dependencies/required/php/min=\([0-9]\+\.[0-9]\+\).*,\1,p"),)))
34+
$(foreach ver,$(PHP_VERSIONS),$(eval PHP_MAX_VER_$(ver) := $(if $(PACKAGE_XML_$(ver)),$(shell xml2 < $(PACKAGE_XML_$(ver)) | sed -ne "s,^/package/dependencies/required/php/max=\([0-9]\+\.[0-9]\+\).*,\1,p"),)))
35+
MIN_PHP_VERSIONS := $(foreach ver,$(PHP_VERSIONS),$(if $(PHP_MIN_VER_$(ver)),$(shell dpkg --compare-versions "$(PHP_MIN_VER_$(ver))" le "$(ver)" && echo "$(ver)"),$(ver)))
36+
MAX_PHP_VERSIONS := $(foreach ver,$(MIN_PHP_VERSIONS),$(if $(PHP_MAX_VER_$(ver)),$(shell dpkg --compare-versions "$(PHP_MAX_VER_$(ver))" gt "$(ver)" && echo "$(ver)"),$(ver)))
37+
export DH_PHP_VERSIONS = $(if $(DH_PHP_VERSIONS_OVERRIDE),$(DH_PHP_VERSIONS_OVERRIDE),$(foreach ver,$(MAX_PHP_VERSIONS),$(if $(PACKAGE_XML_$(ver)),$(ver))))
38+
39+
# for each ver in $(DH_PHP_VERSIONS), look into each corresponding package.xml for upstream PECL version
40+
$(foreach ver,$(DH_PHP_VERSIONS),$(eval PECL_SOURCE_$(ver) := $(if $(PACKAGE_XML_$(ver)),$(shell xml2 < $(PACKAGE_XML_$(ver)) | sed -ne "s,^/package/name=,,p")-$(shell xml2 < $(PACKAGE_XML_$(ver)) | sed -ne "s,^/package/version/release=,,p"),undefined)))
41+
42+
CONFIGURE_TARGETS = $(addprefix configure-,$(addsuffix -stamp,$(DH_PHP_VERSIONS)))
43+
BUILD_TARGETS = $(addprefix build-,$(addsuffix -stamp,$(DH_PHP_VERSIONS)))
44+
INSTALL_TARGETS = $(addprefix install-,$(addsuffix -stamp,$(DH_PHP_VERSIONS)))
45+
CLEAN_TARGETS = $(addprefix clean-,$(addsuffix -stamp,$(DH_PHP_VERSIONS)))
46+
47+
%:
48+
dh $@ --with php
49+
50+
override_dh_auto_configure: $(CONFIGURE_TARGETS)
51+
override_dh_auto_build: $(BUILD_TARGETS)
52+
override_dh_auto_install: $(INSTALL_TARGETS)
53+
override_dh_auto_clean: $(CLEAN_TARGETS)
54+
-rm -f $(CONFIGURE_TARGETS) $(BUILD_TARGETS) $(INSTALL_TARGETS) $(CLEAN_TARGETS)
55+
56+
clean-%-stamp: SOURCE_DIR = build-$(*)
57+
clean-%-stamp:
58+
rm -rf $(SOURCE_DIR)
59+
touch clean-$*-stamp
60+
61+
configure-%-stamp: SOURCE_DIR = build-$(*)
62+
configure-%-stamp:
63+
cp -a $(PECL_SOURCE_$(*)) $(SOURCE_DIR)
64+
cd $(SOURCE_DIR) && phpize$(*)
65+
dh_auto_configure --sourcedirectory=$(SOURCE_DIR) -- --enable-$(PECL_NAME) --with-php-config=/usr/bin/php-config$* $(PECL_CONFIGURE_MAINT_APPEND)
66+
touch configure-$(*)-stamp
67+
68+
build-%-stamp: SOURCE_DIR = build-$(*)
69+
build-%-stamp:
70+
dh_auto_build --sourcedirectory=$(SOURCE_DIR)
71+
touch build-$*-stamp
72+
73+
install-%-stamp: SOURCE_DIR = build-$(*)
74+
install-%-stamp:
75+
dh_auto_install --sourcedirectory=$(SOURCE_DIR) -- INSTALL_ROOT=$(INSTALL_ROOT)
76+
touch install-$*-stamp
77+
78+
override_dh_gencontrol: ,:=,
79+
override_dh_gencontrol:
80+
dh_gencontrol -- "-Vphp:Provides=$(addprefix php,$(addsuffix -$(PECL_NAME)$(,) ,$(DH_PHP_VERSIONS)))"
81+
82+
override_dh_php:
83+
dh_php -p php-$(PECL_NAME)

ext/packaging/debian/source/format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0 (quilt)

0 commit comments

Comments
 (0)