Subject: [alpine-devel] [PATCH] main/php: improved APKBUILD, see changes

From: Matt Smith <[email-masked]>
Date: Thu, 13 Jan 2011 04:35:08 -0600

php-5.3.5-r2 changelog:
- Recreated php-cli subpackage and moved it out of the main php package;
- Combined php-cli and php-pear in the build() function (one less `make`
  to perform);
- Created php-common subpackage, currently containing php.ini;
- Converted the main php package into a metapackage, which currently depends
  on php-common and php-cgi;
- Updated the dev() split function to include all the build dirs we used,
  and then symlinked /usr/lib/php/build to build-cgi by default;
- Moved the phar command to the php-phar subpackage;

Let me know what you think.

Matt
---
 main/php/APKBUILD |   84 +++++++++++++++++++++++++++++------------------------
 1 files changed, 46 insertions(+), 38 deletions(-)

diff --git a/main/php/APKBUILD b/main/php/APKBUILD
index 43eafcc..cdb4699 100644
--- a/main/php/APKBUILD
+++ b/main/php/APKBUILD
@@ -3,12 +3,12 @@
 pkgname=php
 pkgver=5.3.5
 _suhosinver=5.3.4-0.9.10
-pkgrel=1
+pkgrel=2
 pkgdesc="The PHP language runtime engine"
 url="http://www.php.net/"
 arch="x86 x86_64"
 license="PHP-3"
-depends=
+depends="$pkgname-common $pkgname-cgi"
 install="$pkgname.post-upgrade"
 makedepends="pcre-dev libxml2-dev libiconv-dev openssl-dev zlib-dev bzip2-dev
 	curl-dev libpng-dev jpeg-dev freetype-dev libmcrypt-dev mysql-dev
@@ -17,8 +17,8 @@ makedepends="pcre-dev libxml2-dev libiconv-dev openssl-dev zlib-dev bzip2-dev
 	net-snmp-dev libxslt-dev cyrus-sasl-dev openldap-dev pkgconfig
 	libgcrypt-dev apache2-dev apr-dev apr-util-dev libevent-dev
 	readline-dev"
-subpackages="$pkgname-dev $pkgname-doc $pkgname-cgi $pkgname-fpm
-	$pkgname-apache2 $pkgname-embed $pkgname-pear
+subpackages="$pkgname-dev $pkgname-doc $pkgname-common $pkgname-cgi
+	$pkgname-cli $pkgname-fpm $pkgname-apache2 $pkgname-embed $pkgname-pear
 	$pkgname-bcmath
 	$pkgname-bz2
 	$pkgname-calendar
@@ -87,8 +87,6 @@ prepare() {
 }
 
 build() {
-	cd "$srcdir"/$pkgname-$pkgver
-
 	_phpconfig="--build=${CHOST:-i486-alpine-linux-uclibc} \
 		--prefix=/usr \
 		--sysconfdir=/etc/php \
@@ -170,17 +168,7 @@ build() {
 #		--with-enchant=shared,/usr \
 #		--with-tidy=shared \
 
-	# php
-	./configure ${_phpconfig} \
-		--disable-cgi \
-		--with-readline \
-		--enable-pcntl \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
-
 	# cgi and fcgi
-	# reuse the previous run; this will save us a lot of time
 	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-cgi
 	cd "$srcdir"/$pkgname-cgi
 	./configure ${_phpconfig} \
@@ -191,7 +179,7 @@ build() {
 	make || return 1
 
 	# fpm
-	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-fpm
+	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-fpm
 	cd "$srcdir"/$pkgname-fpm
 	./configure ${_phpconfig} \
 		--disable-cli \
@@ -201,7 +189,7 @@ build() {
 	make || return 1
 
 	# apache2
-	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-apache2
+	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-apache2
 	cd "$srcdir"/$pkgname-apache2
 	./configure ${_phpconfig} \
 		--disable-cli \
@@ -211,7 +199,7 @@ build() {
 	make || return 1
 
 	# embed
-	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-embed
+	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-embed
 	cd "$srcdir"/$pkgname-embed
 	./configure ${_phpconfig} \
 		--disable-cli \
@@ -220,9 +208,9 @@ build() {
 	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
 	make || return 1
 
-	# pear
-	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-pear
-	cd "$srcdir"/$pkgname-pear
+	# cli and pear
+	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-cli-pear
+	cd "$srcdir"/$pkgname-cli-pear
 	./configure ${_phpconfig} \
 		--disable-cgi \
 		--with-readline \
@@ -234,35 +222,51 @@ build() {
 }
 
 package() {
-	cd "$srcdir"/$pkgname-$pkgver
-	make -j1 INSTALL_ROOT="$pkgdir" install || return 1
-	install -D -m644 php.ini-production "$pkgdir"/etc/php/php.ini
-	sed -i -e "s:^; extension_dir = \"./\":extension_dir = \"$_extdir\":" "$pkgdir"/etc/php/php.ini
-	sed -ri "s~^([;]*cgi\.rfc2616_headers.*)$~\1\n\n\; If this is enabled, the PHP CGI binary can safely be placed outside of the\n; web tree and people will not be able to circumvent .htaccess security.\ncgi\.discard_path = 1~" "$pkgdir"/etc/php/php.ini
-	rm -rf "$pkgdir"/usr/share/man
+	mkdir -p "$pkgdir" && return 0
 }
 
 dev() {
-	default_dev
+	pkgdesc="PHP Development Files"
 	mkdir -p "$subpkgdir"/usr/lib/php/ "$subpkgdir"/usr/bin/
-	mv "$pkgdir"/usr/lib/php/build "$subpkgdir"/usr/lib/php/
-	mv "$pkgdir"/usr/bin/phpize "$subpkgdir"/usr/bin/
+	cp -a "$srcdir"/php-cli-pear/build "$subpkgdir"/usr/lib/php/build-cli-pear
+	cp -a "$srcdir"/php-cgi/build "$subpkgdir"/usr/lib/php/build-cgi
+	cp -a "$srcdir"/php-fpm/build "$subpkgdir"/usr/lib/php/build-fpm
+	cp -a "$srcdir"/php-apache2/build "$subpkgdir"/usr/lib/php/build-apache2
+	cp -a "$srcdir"/php-embed/build "$subpkgdir"/usr/lib/php/build-embed
+	ln -fs /usr/lib/php/build-cgi "$subpkgdir"/usr/lib/php/build
+
+	cp -a "$srcdir"/php-cli-pear/scripts/phpize "$subpkgdir"/usr/bin/
 }
 
 doc() {
-	install -D -m644 "$srcdir"/$pkgname-$pkgver/sapi/cli/php.1 "$subpkgdir"/usr/share/man/man1/php.1
-	install -D -m644 "$srcdir"/$pkgname-$pkgver/scripts/man1/phpize.1 "$subpkgdir"/usr/share/man/man1/phpize.1
-	install -D -m644 "$srcdir"/$pkgname-$pkgver/scripts/man1/php-config.1 "$subpkgdir"/usr/share/man/man1/php-config.1
+	pkgdesc="PHP Documentation"
+	install -D -m644 "$srcdir"/$pkgname-cli-pear/sapi/cli/php.1 "$subpkgdir"/usr/share/man/man1/php.1
+	install -D -m644 "$srcdir"/$pkgname-cli-pear/scripts/man1/phpize.1 "$subpkgdir"/usr/share/man/man1/phpize.1
+	install -D -m644 "$srcdir"/$pkgname-cli-pear/scripts/man1/php-config.1 "$subpkgdir"/usr/share/man/man1/php-config.1
 	install -D -m644 "$srcdir"/$pkgname-fpm/sapi/fpm/php-fpm.8 "$subpkgdir"/usr/share/man/man8/php-fpm.8
 }
 
+common() {
+	pkgdesc="PHP Common Files"
+	cd "$srcdir"/$pkgname-$pkgver
+	install -D -m644 php.ini-production "$subpkgdir"/etc/php/php.ini
+	sed -i -e "s:^; extension_dir = \"./\":extension_dir = \"$_extdir\":" "$subpkgdir"/etc/php/php.ini
+	sed -ri "s~^([;]*cgi\.rfc2616_headers.*)$~\1\n\n\; If this is enabled, the PHP CGI binary can safely be placed outside of the\n; web tree and people will not be able to circumvent .htaccess security.\ncgi\.discard_path = 1~" "$subpkgdir"/etc/php/php.ini
+}
+
 cgi() {
 	pkgdesc="PHP Common Gateway Interface (CGI)"
 	install -D -m755 "$srcdir"/$pkgname-cgi/sapi/cgi/php-cgi "$subpkgdir"/usr/bin/php-cgi
 }
 
+cli() {
+	pkgdesc="PHP Command Line Interface (CLI)"
+	install -D -m755 "$srcdir"/$pkgname-cli-pear/sapi/cli/php "$subpkgdir"/usr/bin/php
+}
+
 fpm() {
 	pkgdesc="PHP FastCGI Process Manager (FPM)"
+
 	install -D -m755 "$srcdir"/$pkgname-fpm/sapi/fpm/php-fpm "$subpkgdir"/usr/bin/php-fpm
 	install -D -m644 "$srcdir"/$pkgname-fpm/sapi/fpm/php-fpm.conf "$subpkgdir"/etc/php/php-fpm.conf
 	install -D -m755 "$srcdir"/php-fpm.init "$subpkgdir"/etc/init.d/php-fpm
@@ -289,8 +293,8 @@ embed() {
 pear() {
 	pkgdesc="PHP Extension and Application Repository (PEAR)"
 	depends="php"
-	cd "$srcdir"/$pkgname-pear
-	make install-pear INSTALL_ROOT=""$subpkgdir""
+	cd "$srcdir"/$pkgname-cli-pear
+	make INSTALL_ROOT="$subpkgdir" install-pear || return 1
 	for _rmpear in `find "$subpkgdir" -name '.*'`; do
 		rm -rf ${_rmpear}
 	done
@@ -299,7 +303,7 @@ pear() {
 _mv_mod() {
 	pkgdesc="$1 php extension"
 	mkdir -p "$subpkgdir"/$_extdir
-	mv "$pkgdir"/$_extdir/${1}.so "$subpkgdir"/$_extdir/ || return 1
+	mv "$srcdir"/php-cgi/modules/${1}.so "$subpkgdir"/$_extdir/ || return 1
 	install -d "$subpkgdir"/etc/php/conf.d
 	echo "extension=${1}.so" > "$subpkgdir"/etc/php/conf.d/${1}.ini
 	return 0
@@ -331,7 +335,11 @@ pdo_mysql()	{ _mv_mod pdo_mysql; }
 pdo_odbc()	{ _mv_mod pdo_odbc; }
 pdo_pgsql()	{ _mv_mod pdo_pgsql; }
 pdo_sqlite()	{ _mv_mod pdo_sqlite; }
-phar()		{ _mv_mod phar; }
+phar()		{
+			_mv_mod phar;
+			cd "$srcdir"/$pkgname-cli-pear
+			make INSTALL_ROOT="$subpkgdir" install-pharcmd || return 1
+		}
 posix()		{ _mv_mod posix; }
 pgsql()		{ _mv_mod pgsql; }
 pspell()	{ _mv_mod pspell; }
-- 
1.7.3.3

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Natanael Copa <[email-masked]>
Date: Thu, 13 Jan 2011 15:39:56 +0100

On Thu, 13 Jan 2011 04:35:08 -0600
Matt Smith <[email-masked]> wrote:

> - Combined php-cli and php-pear in the build() function (one less
> `make` to perform);
> - Converted the main php package into a metapackage, which currently
> depends on php-common and php-cgi;
> - Updated the dev() split function to include all the build dirs we
> used, and then symlinked /usr/lib/php/build to build-cgi by default;

perfect! Applied.

some of the code is repetitive. Could go in a function so if you in the future needs to modify the sed line then you only need to do it one place.

--- a/main/php/APKBUILD
+++ b/main/php/APKBUILD
@@ -86,7 +86,12 @@ prepare() {
 	patch -p1 -i "${srcdir}"/suhosin-patch-${_suhosinver}.patch || return 1
 }
 
-build() {
+_do_build() {
+	local cp_from="$1"
+	local cp_to="$2"
+	shift
+	shift
+
 	_phpconfig="--build=${CHOST:-i486-alpine-linux-uclibc} \
 		--prefix=/usr \
 		--sysconfdir=/etc/php \
@@ -167,58 +172,48 @@ build() {
 		"
 #		--with-enchant=shared,/usr \
 #		--with-tidy=shared \
+	cp -a "$srcdir"/$cp_from "$srcdir"/$cp_to
+	cd "$srcdir"/$cp_to
+	./configure ${_phpconfig} \
+		"$@" \
+		${_phpextensions} \
+		|| return 1
+	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
+	make || return 1
+}
 
+build() {
 	# cgi and fcgi
-	cp -a "$srcdir"/$pkgname-$pkgver "$srcdir"/$pkgname-cgi
-	cd "$srcdir"/$pkgname-cgi
-	./configure ${_phpconfig} \
+	_do_build $pkgname-$pkgver $pkgname-cgi \
 		--disable-cli \
 		--enable-cgi \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
+		|| return 1
 
 	# fpm
-	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-fpm
-	cd "$srcdir"/$pkgname-fpm
-	./configure ${_phpconfig} \
+	_do_build $pkgname-cgi $pkgname-fpm \
 		--disable-cli \
 		--enable-fpm \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
+		|| return 1
 
 	# apache2
-	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-apache2
-	cd "$srcdir"/$pkgname-apache2
-	./configure ${_phpconfig} \
+	_do_build $pkgname-cgi $pkgname-apache2 \
 		--disable-cli \
 		--with-apxs2 \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
+		|| return 1
 
 	# embed
-	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-embed
-	cd "$srcdir"/$pkgname-embed
-	./configure ${_phpconfig} \
+	_do_build $pkgname-cgi $pkgname-embed \
 		--disable-cli \
 		--enable-embed=shared \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
+		|| return 1
 
 	# cli and pear
-	cp -a "$srcdir"/$pkgname-cgi "$srcdir"/$pkgname-cli-pear
-	cd "$srcdir"/$pkgname-cli-pear
-	./configure ${_phpconfig} \
+	_do_build $pkgname-cgi $pkgname-cli-pear \
 		--disable-cgi \
 		--with-readline \
 		--enable-pcntl \
 		--with-pear \
-		${_phpextensions}
-	sed -ri "s/^(EXTRA_LDFLAGS[ ]*\=.*)/\1 -lpthread/" Makefile  # see #183
-	make || return 1
+		|| return 1
 }
 
 package() {

-nc

---