summaryrefslogblamecommitdiff
path: root/user/php7/APKBUILD
blob: c86d41e8401a387a1554cb08ae42c6e13c26eda8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                         
                                                         

                                                     
                                                         












                                                         
            
        


                 
                                          
                      
          
                                                                                                                                                                                              
          
                                                                               
                           


                        
                

                 
                 



                   
                
                    



                   
                 
                   
                   
                   


                    
                     
                    
                 



                      



                                                                
                                           
                                                                   



                               
                       
                       






                             




                                        

















                      
















                                                                                       
             




                                                                            
                     

                  
 


                                                                 
            
                                        
 

                               
                   
                                                    
                                                                        


                                            

                                                                                    

                          
                                          
                                                                  
                          
                    

            

                                       
 
                    
                                  




                    


                               



                         
                                                               








                          
                        
                      
                                                                                         
                                 

                                                 

                           
                                   

                   

                               


                        
                               
                                
                                       
                       
                         
                                            
                        
                               
                         
                                     








                     
                                 

                   
                                  









                         



                     


                      

                      

           
                       
 















                                                                                             















                                                                        


                                                                              




                
          

                                                     














                                                               

                                    
                                      


                                              
                    




            
                                                                      

                             


                                  




                                                         



                                             


         


                                                                       














                                                                          


                                                                       
                                                     
                                   

                                                 




                                                                                



















                                                                         
                                                       




                                                     
                                                        








                                                                      
 
                                                          



                                       



                                                              

                                               
                                           





                                                           
                                           






                                                                   


                                                              












                                                             
                                                                         






                                                                              

                                                               

















                                                           




                                                                  
            
 

                                                                            
 


                                                        
 

                                                
 








                                                                            



                                                                               

                                                                        
                         




                                                      




                                                    


                                                                    


       


                                                     

 
                                                                                                                                                               
                                                                                                                                               

                                                                                                                                                   
                                                                                                                                                     
                                                                                                                                                 
                                                                                                                                                 





                                                                                                                                                       
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Max Rees <maxcrees@me.com>

# Bundled libraries
#
# Name      | License | Location               | State
# ----------+---------+------------------------+---------
# bcmath    | LGPL2   | ext/bcmath/libbcmath   | used
# date      | MIT     | ext/date/lib           | used
# gd        | BSD     | ext/gd/libgd           | not used
# file      | BSD     | ext/fileinfo/libmagic  | used
# libmbfl   | LGPLv2  | ext/mbstring/libmbfl   | used
# oniguruma | BSD     | ext/mbstring/oniguruma | not used
# pcre      | BSD     | ext/pcre/pcrelib       | not used
# sqlite3   | Public  | ext/sqlite3/libsqlite  | not used
# libzip    | BSD     | ext/zip/lib            | not used
# libXMLRPC | BSD     | ext/xmlrpc/libxmlrpc   | used

# Static extensions
#
# Name      | Reason
# ----------+--------------------------------------------
# zlib      | https://bugs.alpinelinux.org/issues/8299

pkgname=php7
_pkgname=php
pkgver=7.4.4
pkgrel=0
_apiver=20190902
_zendver=20190902
_pdover=20170320
pkgdesc="The PHP7 language runtime engine"
url="https://php.net/"
arch="all"
license="PHP-3.01 AND Zend-2.0 AND Custom:TSRM AND LGPL-2.1+ AND MIT AND Beerware AND Public-Domain AND BSD-3-Clause AND Apache-1.0 AND PostgreSQL AND BSD-2-Clause AND Zlib AND BSD-4-Clause"
depends=""
depends_dev="$pkgname=$pkgver-r$pkgrel autoconf icu-dev libedit-dev libxml2-dev
	pcre2-dev zlib-dev"
makedepends="autoconf
	apache-httpd-dev
	aspell-dev
	automake
	bison
	bzip2-dev
	cmd:which
	curl-dev
	db-dev
	enchant-dev
	freetds-dev
	gdbm-dev
	gettext-tiny
	gmp-dev
	icu-dev
	krb5-dev
	libedit-dev
	libgd-dev
	libical-dev
	openssl-dev
	libxml2-dev
	libxslt-dev
	libzip-dev
	net-snmp-dev
	oniguruma-dev
	openldap-dev
	pcre2-dev
	postgresql-dev
	re2c
	sqlite-dev
	unixodbc-dev
	zlib-dev
	"
subpackages="$pkgname-dev $pkgname-doc $pkgname-phpdbg
	$pkgname-embed $pkgname-cgi $pkgname-fpm $pkgname-apache
	$pkgname-pear::noarch $pkgname-dbg"
source="https://www.php.net/distributions/$_pkgname-$pkgver.tar.bz2
	$_pkgname-fpm.initd
	$_pkgname-fpm.logrotate
	$_pkgname-module.conf
	disabled-tests.list
	enchant-2.patch
	fpm-paths.patch
	getsockopt.patch
	install-pear.patch
	no-max-ent-size.patch
	test-fixes.patch
	zend_bool.patch
	zip-glob-pathc.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"
_libdir="/usr/lib/$_pkgname"
_extension_dir="$_libdir/modules"
_extension_confd="/etc/$_pkgname/conf.d"

# secfixes: php
#   7.2.16-r0:
#     - CVE-2016-10166
#     - CVE-2018-20783
#     - CVE-2019-6977
#     - CVE-2019-9020
#     - CVE-2019-9021
#     - CVE-2019-9022
#     - CVE-2019-9023
#     - CVE-2019-9024
#   7.2.19-r0:
#     - CVE-2019-11036
#     - CVE-2019-11038
#     - CVE-2019-11039
#     - CVE-2019-11040
#   7.2.21-r0:
#     - CVE-2019-11041
#     - CVE-2019-11042
#   7.4.4-r0:
#     - CVE-2019-11043
#     - CVE-2019-11045
#     - CVE-2019-11046
#     - CVE-2019-11047
#     - CVE-2019-11050
#     - CVE-2019-13224
#     - CVE-2020-7059
#     - CVE-2020-7060
#     - CVE-2020-7062
#     - CVE-2020-7063
#     - CVE-2020-7064
#     - CVE-2020-7066

# Usage: _add_ext [with|enable] name [extension dependencies...] [configure options...]
_add_ext() {
	_ext="$1"
	shift
	# _add_ext [with|enable] name -> --[with|enable]-name=shared
	case "$_ext" in
	with|enable)
		_configure_ext_opts="$_configure_ext_opts --$_ext-$1=shared"
		_ext="$1"
		shift
		;;
	esac

	case "$_ext" in
	phar) subpackages="$subpackages $pkgname-$_ext:$_ext";;
	*) subpackages="$subpackages $pkgname-$_ext:_extension";;
	esac
	_extensions="$_extensions $_ext"

	for _opt; do
		case "$_opt" in
		-*)
			# Add more configure options
			_configure_ext_opts="$_configure_ext_opts $_opt"
			;;
		license:*)
			# Add custom license
			_opt="$(printf '%s' "${_opt#license:}" | sed 's/:/ AND /g')"
			eval "_licenses_$_ext='$_opt'"
			;;
		*)
			# Add dependencies
			eval "_deps_$_ext=\"\$_deps_$_ext $_opt\""
			;;
		esac
	done
}
_enable_ext() { _add_ext enable "$@"; }
_with_ext() { _add_ext with "$@"; }

_enable_ext bcmath \
	license:LGPL-2.0+:PHP-3.01
_with_ext bz2
_enable_ext calendar
_enable_ext ctype
_with_ext curl
_enable_ext dba \
	--with-db4 \
	--with-dbmaker=shared \
	--with-gdbm
_enable_ext dom
_with_ext enchant
_enable_ext exif mbstring
_enable_ext fileinfo \
	license:PHP-3.0:BSD-2-Clause:BSD-3-Clause:Public-Domain
_enable_ext ftp
_enable_ext gd \
	--with-external-gd
_with_ext gettext
_with_ext gmp
_with_ext iconv
_enable_ext intl
_enable_ext json
_with_ext ldap \
	--with-ldap-sasl
_enable_ext mbstring \
	license:PHP-3.01:OLDAP-2.8:BSD-2-Clause:Public-Domain:LGPL-2.0-only:LGPL-2.1-only
_add_ext mysqli mysqlnd openssl \
	--with-mysqli=shared,mysqlnd \
	--with-mysql-sock=/run/mysqld/mysqld.sock
_enable_ext mysqlnd openssl
_add_ext odbc \
	--with-unixODBC=shared,/usr
_enable_ext opcache
_with_ext openssl \
	--with-system-ciphers \
	--with-kerberos
_enable_ext pcntl
_enable_ext pdo
_add_ext pdo_dblib pdo \
	--with-pdo-dblib=shared
_add_ext pdo_mysql pdo mysqlnd \
	--with-pdo-mysql=shared,mysqlnd
_add_ext pdo_odbc pdo \
	license:PHP-3.0 \
	--with-pdo-odbc=shared,unixODBC,/usr
_add_ext pdo_pgsql pdo \
	--with-pdo-pgsql=shared
_add_ext pdo_sqlite pdo \
	--with-pdo-sqlite=shared,/usr
_with_ext pgsql
_enable_ext phar
_enable_ext posix
_with_ext pspell
_enable_ext session
_enable_ext shmop
_enable_ext simplexml
_with_ext snmp
_enable_ext soap \
	license:PHP-3.01:PHP-2.02
_enable_ext sockets
_add_ext sqlite3 \
	--with-sqlite3=shared,/usr
_enable_ext sysvmsg
_enable_ext sysvsem
_enable_ext sysvshm
_enable_ext tokenizer
_enable_ext xml
_enable_ext xmlreader dom
_with_ext xmlrpc xml
_enable_ext xmlwriter
_with_ext xsl dom
_with_ext zip

# secfixes:
#   7.2.5-r0:
#     - CVE-2018-5712
#   7.2.8-r0:
#     - CVE-2015-9253
#     - CVE-2018-12882
#   7.2.11-r2:
#     - CVE-2018-19935

prepare() {
	default_prepare

	_vapi="$(sed -n '/#define PHP_API_VERSION/{s/.* //;p}' main/php.h)"
	if [ "$_vapi" != "$_apiver" ]; then
		error "Upstream API version $_vapi != $_apiver"
		die "All third-party extensions must be rebuilt"
	fi

	_zapi="$(sed -n '/#define ZEND_MODULE_API_NO/{s/^[^0-9]*//;p;}' Zend/zend_modules.h)"
	if [ "$_zapi" != "$_zendver" ]; then
		error "Upstream Zend API version $_zapi != $_zendver"
		die "All third-party extensions must be rebuilt"
	fi

	_papi="$(sed -n '/#define PDO_DRIVER_API/{s/.*[	]//;p}' ext/pdo/php_pdo_driver.h)"
	if [ "$_papi" != "$_pdover" ]; then
		error "Upstream PDO API version $_papi != $_pdover"
		die "All third-party extensions must be rebuilt"
	fi

	# https://bugs.php.net/63362 - Not needed but installed headers.
	# Drop some Windows specific headers to avoid installation,
	# before build to ensure they are really not needed.
	rm -f TSRM/tsrm_win32.h \
		TSRM/tsrm_config.w32.h \
		Zend/zend_config.w32.h \
		ext/mysqlnd/config-win.h \
		ext/standard/winver.h \
		main/win32_internal_function_disabled.h \
		main/win95nt.h

	# Fix some bogus permissions.
	find . -name '*.[ch]' -exec chmod 644 {} +

	# XXX: Disable failing tests.
	sed -n '/^[^#]/p' "$srcdir/disabled-tests.list" | while read _test; do
		mv "$_test" "${_test}d"
	done

	autoconf
}

_build() {
	# libxml cannot be build as shared.
	EXTENSION_DIR="$_extension_dir" ./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libdir=$_libdir \
		--datadir=/usr/share/$_pkgname \
		--sysconfdir=/etc/$_pkgname \
		--localstatedir=/var \
		--enable-debug \
		--with-layout=GNU \
		--with-pic \
		--enable-maintainer-zts \
		--with-pear=/usr/share/$_pkgname \
		--with-config-file-path=/etc/$_pkgname \
		--with-config-file-scan-dir=$_extension_confd \
		--disable-short-tags \
		--with-libedit \
		--without-readline \
		--with-external-pcre \
		--with-zlib \
			--with-zlib-dir=/usr \
		$_configure_ext_opts \
		"$@"

	make
}

build() {
	export CFLAGS="$CFLAGS -fno-strict-aliasing -Wno-pointer-sign"

	# apache-httpd module
	_build --disable-fpm \
		--disable-embed \
		--disable-phpdbg \
		--disable-cgi \
		--disable-cli \
		--with-apxs2
	mv libs/libphp7.so sapi/apache2handler/mod_php.so

	_build --enable-fpm=yes \
		--enable-embed=yes \
		--enable-phpdbg=yes \
		--enable-phpdbg-webhelper=yes
}

check() {
	# PHP is so stupid that it's not able to resolve dependencies
	# between extensions and load them in correct order, so we must
	# help it...
	#
	# * opcache is Zend extension, it's handled specially in Makefile
	# * skip pdo_dblib since it slowly tries to connect to nonexistent
	# * ditto snmp

	cat > php-check.ini <<-EOF
	extension_dir=$builddir/modules
	$(_extensions_by_load_order \
		| grep -vxe opcache -e pdo_dblib -e snmp \
		| sed -e 's/^/extension=/' -e 's/$/.so/')
	EOF

	# Note: We use the combination of PHPRC=... and
	# PHP_MODULES=(nothing) so we can set the module load order
	# correctly. Cf. test-fixes.patch

	NO_INTERACTION=1 REPORT_EXIT_STATUS=1 \
		SKIP_SLOW_TESTS=1 SKIP_ONLINE_TESTS=1 TEST_TIMEOUT=10 \
		TEST_PHP_ARGS="-j$JOBS -W test.log" \
		TZ= LANG= LC_ALL= \
		PHPRC="$builddir"/php-check.ini \
		make test PHP_MODULES=

	echo 'NOTE: We have skipped quite a lot tests, see disabled-tests.list.'
}

package() {
	make -j1 INSTALL_ROOT="$pkgdir" install

	install -Dm644 php.ini-production "$pkgdir"/etc/$_pkgname/php.ini
	find "$pkgdir" -name '.*' | xargs rm -rf
	rmdir "$pkgdir"/var/run
}

dev() {
	default_dev
	cd "$pkgdir"

	_mv usr/bin/phpize "$subpkgdir"/usr/bin/
	_mv ./$_libdir/build "$subpkgdir"/$_libdir/
}

doc() {
	default_doc
	cd "$builddir"

	mkdir -p "$subpkgdir/usr/share/doc/$_pkgname"
	cp EXTENSIONS LICENSE NEWS README* UPGRADING* \
		"$subpkgdir/usr/share/doc/$_pkgname/"
}

apache() {
	pkgdesc="PHP7 Module for apache-httpd"
	depends="$pkgname=$pkgver-r$pkgrel apache-httpd"

	install -D -m 755 "$builddir"/sapi/apache2handler/mod_php.so \
		"$subpkgdir"/usr/libexec/apache2/mod_php.so
	install -D -m 644 "$srcdir"/php-module.conf \
		"$subpkgdir"/etc/apache2/conf.d/php-module.conf
}

phpdbg() {
	pkgdesc="Interactive PHP7 debugger"

	_mv "$pkgdir"/usr/bin/phpdbg "$subpkgdir"/usr/bin/
}

embed() {
	pkgdesc="PHP7 Embedded Library"

	_mv "$pkgdir"/usr/lib/libphp*.so "$subpkgdir"/usr/lib/
}

cgi() {
	pkgdesc="PHP7 Common Gateway Interface"
	depends="$pkgname=$pkgver-r$pkgrel"

	_mv "$pkgdir"/usr/bin/php-cgi "$subpkgdir"/usr/bin/
}

fpm() {
	pkgdesc="PHP7 FastCGI Process Manager"
	depends="$pkgname=$pkgver-r$pkgrel"
	cd "$pkgdir"

	_mv var "$subpkgdir"/
	_mv usr/share/$_pkgname/fpm "$subpkgdir"/var/lib/$_pkgname/
	_mv usr/sbin "$subpkgdir"/usr/
	_mv etc/$_pkgname/php-fpm* "$subpkgdir"/etc/$_pkgname/

	for _file in php-fpm.conf php-fpm.d/www.conf; do
		mv "$subpkgdir/etc/$_pkgname/$_file.default" \
			"$subpkgdir/etc/$_pkgname/$_file"
	done

	install -D -m 755 "$srcdir"/$_pkgname-fpm.initd \
		"$subpkgdir"/etc/init.d/php-fpm

	install -D -m 644 "$srcdir"/$_pkgname-fpm.logrotate \
		"$subpkgdir"/etc/logrotate.d/php-fpm

	mkdir -p "$subpkgdir"/var/log/$_pkgname
}

pear() {
	pkgdesc="PHP7 Extension and Application Repository"
	depends="$pkgname=$pkgver-r$pkgrel $pkgname-xml=$pkgver-r$pkgrel"
	cd "$pkgdir"

	# pecl needs xml extension and since we build it as shared, it must be
	# explicitly declared to be loaded.
	sed -i 's/\$INCARG/& -d extension=xml.so/' usr/bin/pecl

	mkdir -p "$subpkgdir"/usr/bin
	for _file in pecl pear peardev; do
		mv "usr/bin/$_file" "$subpkgdir/usr/bin/$_file"
	done

	_mv etc/php/pear.conf "$subpkgdir"/etc/php/
	_mv usr/share "$subpkgdir"/usr/
}

phar() {
	_extension
	cd "$pkgdir"

	mkdir -p "$subpkgdir"/usr/bin
	mv usr/bin/phar.phar "$subpkgdir"/usr/bin/phar.phar

	rm usr/bin/phar
	ln -s phar.phar "$subpkgdir"/usr/bin/phar
}

_extension() {
	_ext="${subpkgname#$pkgname-}"

	depends="$pkgname=$pkgver-r$pkgrel"
	for _dep in $(eval echo \$_deps_$_ext); do
		depends="$depends $pkgname-$_dep=$pkgver-r$pkgrel"
	done

	pkgdesc="$(head -n1 "$builddir/_ext/$_ext/CREDITS" 2>/dev/null ||:)"
	pkgdesc="PHP7 extension: ${pkgdesc:-$_ext}"

	if [ -n "$(eval echo \$_licenses_$_ext)" ]; then
		license="$(eval echo \$_licenses_$_ext)"
	fi

	_mv "$pkgdir/$_extension_dir/$_ext.so" \
		"$subpkgdir/$_extension_dir/"

	_load_order="$(printf %02d "$(_extension_load_order "$_ext")")"
	case "$_ext" in
	opcache) _prefix=zend_;;
	*) _prefix=;;
	esac
	mkdir -p "$subpkgdir/$_extension_confd"
	cat > "$subpkgdir/$_extension_confd/${_load_order}_$_ext.ini" <<-EOF
		${_prefix}extension=$_ext.so
	EOF
}

# Prints a load order (0-based integer) for the given extension name. Extension
# with lower load order should be loaded before exts with higher load order.
# It's based on number of dependencies of the extension which is flawed,
# but simple and good enough for now.
_extension_load_order() {
	_ext="$1"
	case "$_ext" in
	# depends=$pkgname
	phar) echo 1;;
	*) echo "$(eval echo \$_deps_$_ext)" | wc -w;;
	esac
}

# Prints $_extensions sorted by load order and name.
_extensions_by_load_order() {
	for _ext in $_extensions; do
		printf '%s\n' "$(_extension_load_order $_ext);$_ext"
	done | sort -t ';' -k 1 | sed -E 's/[0-9]+;//'
}

_mv() {
	for _dest; do true; done  # get last argument
	mkdir -p "$_dest"
	mv "$@"
}

sha512sums="5676023858ffbef4997c2ed99ce1689de2b56d09a0925b8fc6527d56e7f6031b380e433e417e44f84196e713d84c16b33212ed6d116b5c347d1d60586288c248  php-7.4.4.tar.bz2
cb3ba48fbd412f12d98ef1f88b509b40bc4ca44a16779a06d43e4db3cb8d24d54404b9e11ca941b5339af8d3281ca9c8ea3ba5ced4339f91fb40608b5ce9a647  php-fpm.initd
01d4ba3ef104ea378eb0e8cbb7bdee3fdf65e4bd6865eb3bc6c0dc4af31c2d52887abdf0150b5ef984b877860285a3b1af84b11ffebb5b8b722ea9faf83edfeb  php-fpm.logrotate
a7f9ba5e11652fd1cb9e756c3269269a95de083ecb5be936a85c7a09c1396db9088e0251c6a643c40235c0e776fce2a471e5c7f5a033b85c7d3b3110c2b39e48  php-module.conf
587057aaf93feec2936e2851dbb42ba78310fc012e340d90c58a8912437a8b6a15585895490c31ac31cf36969ea1f2999993c5ca42031c378f31fb83d361fd73  disabled-tests.list
7c8c3cac9efce81d525cb5a70e1402e393881b83ef4c7b5d39d3565803d21cd283daf3d74e9a8b059ecac66cf339756acc63608ffcb83d960dba86583bd45108  enchant-2.patch
a77dd3bdf9dc7a0f2c06ff3e7c425d062bbaa29902c17402ce98701dc99499be863ad543aa5e6a7d1c249702d6afb193398dd3199ae58e42b32b95d434fb1883  fpm-paths.patch
821bf6fde83302e7613429a61066e2bd3ca4e998dcb7c11e39f4ae84829056537501b47a051e1feba752f72d98644b9a214633db9ccb16d137d3242d145acfe0  getsockopt.patch
951fa8445c20513aa48bf7c7d773c6b4012322e7e7592c13d965758e761b9898c484f0dbc5ae565c05787e6ab868769c97c71504624b10c9570e1d4214f75b10  install-pear.patch
5fd358dfd660901c8ffdaffe0bce398ab020f8c1beb89e26ba1b21646212fe132927d52ae088220d0b9c53017cfc67f4c9b88f7602df61d36eba5768ce94e355  no-max-ent-size.patch
9160e5c6b8bf2d87299f38421caf498519eb42243118570754a5764b5e682c546309548e76df6163df49e841ff51fb07e50fadeed1687da5d73dec1810c393ee  test-fixes.patch
0cd6b8739533511c0d1edcb1ecff4d8d21a6b51d21f77c382645cf31d1645eeb2ebd80e2720557ceefa58f538385e097402bdc50e613dc7699bd8f033aefa543  zend_bool.patch
1b22dfa547bd1e14e065966f5268adda771c4ad039b83acee30772cd95f0f0b1a320d75fc6ab71a0bc6ca5ce04d58d9f410767c4fae4d5e16537393c78439f21  zip-glob-pathc.patch"