#!/bin/sh
echo DEFANGED.126017
exit
#! /bin/sh

# Based slightly on an original by John H Terpstra but not much left of his.
# S Liddicott 1999 sam@campbellsci.co.uk

PREFIX="php"
TARDIR="`basename \`pwd\``"
RELEASE=${1:-1}
VERSION=${2:-`echo $TARDIR | sed "s/$PREFIX-//g"`}

if	[ "$VERSION" = "" ]
then	cat <<"EOH"
$PREFIX source needs to be installed in a folder that contains the version
number, e.g. ${PREFIX}5 or ${PREFIX}5b2
EOH
fi
	
echo "Usage:"
echo "$0 <release> <version>"
echo
echo "e.g.:"
echo "$0 2"
echo -n "Building RPM version $VERSION, release: $RELEASE "
sleep 1 ; echo -n . ; sleep 1 ; echo -n . ; sleep 1 ; echo -n .
echo

TAR=php-$VERSION.tar.gz
SPEC=php-$VERSION.spec
PREQUIRES=`rpm -q --provides apache|grep "\(webserver\|httpd\)"`
if  [ "$PREQUIRES" = "" ]
then PREQUIRES="webserver"
fi

# cace rpm database
rpm -qa --provides|awk '/[a-zA-Z_.-]+[0-9]* =.*/ {print$1}'|grep "^lib\(cpdf\|crypto\|db4\|ldap\|mhash\|ming\|mysql\|openssl\|pgsql\|xslt\)" > rpm.cache

# write out the .spec file
sed -e "s/PVERSION/$VERSION/g" \
    -e "s/PRELEASE/$RELEASE/g" \
    -e "s/TARDIR/$TARDIR/g" \
    -e "s/PREQUIRES/$PREQUIRES/g" \
    -e "s/PREREQ_CPDF/`cat rpm.cache|awk '/libcpdf[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libcpdf"} END{print "Prereq: " LIB " >= 2"}'`/g" \
    -e "s/PREREQ_DB4/`cat rpm.cache|awk '/libdb4[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libdb4"} END{print "Prereq: " LIB}'`/g" \
    -e "s/PREREQ_LDAP/`cat rpm.cache|awk '/libldap[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libldap"} END{print "Prereq: " LIB}'`/g" \
    -e "s/PREREQ_MHASH/`cat rpm.cache|awk '/libmhash[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libmhash"} END{print "Prereq: " LIB}'`/g" \
    -e "s/PREREQ_MING/`cat rpm.cache|awk '/libming[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libming"} END{print "Prereq: " LIB " >= 0.3"}'`/g" \
    -e "s/PREREQ_MYSQLI/`cat rpm.cache|awk '/libmysql[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libmysql"} END{print "Prereq: " LIB " >= 4.1.1"}'`/g" \
    -e "s/PREREQ_OPENSSL/`cat rpm.cache|awk '/libopenssl[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libopenssl"} END{print "Prereq: " LIB " >= 0.9.6"}'`/g" \
    -e "s/PREREQ_PGSQL/`cat rpm.cache|awk '/libpgsql[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libpgsql"} END{print "Prereq: " LIB " >= 7.0"}'`/g" \
    -e "s/PREREQ_XSLT/`cat rpm.cache|awk '/libxslt[0-9]* =.*/ {LIB=$1} BEGIN{LIB="libxslt"} END{print "Prereq: " LIB " >= 1.0.18"}'`/g" \
    > $SPEC <<'EOF'
Summary: PHP 5 - A powerful scripting language
Name: php5
Version: PVERSION
Release: PRELEASE
Group: Networking/Daemons
Source0: http://www.php.net/distributions/php-%{PACKAGE_VERSION}.tar.gz
Copyright: PHP License
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
Requires: PREQUIRES
Requires: php5-common

%description
PHP 5 is a powerful apache module that adds scripting and database connection
capabilities to the apache server.


%package common
Summary: PHP 5 - A powerful scripting language
Group: Networking/Daemons
BuildRequires: autoconf >= 2.13 automake >= 1.4 libtool >= 1.4 bison >= 1.28 flex >= 2.5.4
BuildRequires: awk gcc
Prereq: php5-ini >= PVERSION-PRELEASE
Prereq: libcrypt
Prereq: libresolve
Prereq: libxml2
Prereq: libz

%description common
PHP is a widely-used general-purpose scripting language that is especially 
suited for Web development and can be embedded into HTML. 

This package provides the common files and the command line interpreter of
PHP. You need this package if you install the CGI exceutable or PHP module
(ie: mod_php5) for the apache webserver.


%package cgi
Summary: PHP 5 - CGI executable
Group: Networking/Daemons
Requires: php5-common

%description cgi
The CGI exceutable for webservers.


%package ini
Summary: PHP 5 - INI file
Group: Networking/Daemons

%description ini
This package provides the recommended ini file. You only need this package
once and must not update it. Hence you can modify your ini file and do not 
need to backup/restore it.


%package cpdf
Summary: PHP 5 - cpdf extension
Group: Networking/Daemons
Requires: php5-common
PREREQ_CPDF

%description cpdf
The PHP extension cpdf to generate PDF files.


%package dba
Summary: PHP 5 - dba extension
Group: Networking/Daemons
Requires: php5-common

%description dba
The PHP extension dba without any external requirement. This extension 
supports the following handlers: cdb, cdb_make, flatfile, inifile.


%package dba-db4
Summary: PHP 5 - dba extension with db2
Group: Networking/Daemons
Requires: php5-common
PREREQ_DB4


%description dba-db4
The PHP extension dba with db4 support. This extension also supports the
following handlers: cdb, cdb_make, flatfile, inifile.


%package iconv
Summary: PHP 5 - iconv extension
Group: Networking/Daemons
Requires: php5-common

%description iconv
The PHP extension iconv.


%package ldap
Summary: PHP 5 - ldap extension
Group: Networking/Daemons
Requires: php5-common

%description ldap
The PHP extension ldap.


%package mhash
Summary: PHP 5 - mhash extension
Group: Networking/Daemons
Requires: php5-common
PREREQ_MHASH

%description mhash
The PHP extension mhash.


%package ming
Summary: PHP 5 - ming extension
Group: Networking/Daemons
Requires: php5-common
PREREQ_MING

%description ming
The PHP extension ming to generate SWF files.


%package mysqli
Summary: PHP 5 - mysqli extension
Group: Networking/Daemons
Requires: php5-common
PREREQ_MYSQLI

%description mysqli
The PHP extension mysqli to connect to MySQL v4.1.1 databases.


%package openssl
Summary: PHP 5 - openssl extension
Group: Networking/Daemons
Requires: php5-common
PREREQ_OPENSSL

%description openssl
The PHP extension openssl.


%package pgsql
Summary: PHP 5 - pgsql extenstion
Group: Networking/Daemons
Requires: php5-common
PREREQ_PGSQL

%description pgsql
The PHP extension pgsql to connect to PostgreSQL databases.


%package xsl
Summary: PHP 5 - xsl extenstion
Group: Networking/Daemons
Requires: php5-common
PREREQ_XSLT

%description xsl
The PHP extension xsl that allows XSLT processing.

%prep
%setup -q -n TARDIR
./buildconf --force

%build
# first the standalone (why can't you build both at once?)
# need to run this under sh or it breaks

CFLAGS='-Wall -Wno-strict-aliasing -ggdb'
sh ./configure \
	--prefix=%{_prefix} \
	--with-exec-dir=%{_bindir} \
	--with-config-file-path=%{_sysconfdir} \
	--disable-cli \
	--without-pear \
	--enable-force-cgi-redirect \
	--enable-safe-mode \
	--enable-simplexml \
	--enable-spl \
	--with-sqlite \
	--enable-xml \
	--with-zlib \
	--enable-shared \
	\
	--disable-bcmath \
	--disable-calendar \
	--enable-dba=shared \
	--disable-dbx \
	--disable-dom \
	--disable-exif \
	--disable-filepro \
	--disable-ftp \
	--without-gd \
	--disable-gdchart \
	--without-iconv \
	--disable-mbstring \
	--without-ldap \
	--without-mhash \
	--without-ming \
	--without-mysql \
	--without-mysqli \
	--without-openssl \
	--disable-pcntl \
	--without-pgsql \
	--disable-sockets \
	--without-sqlite \
	--disable-sysvmsg \
	--disable-sysvsem \
	--disable-sysvshm \
	--disable-tokenizer \
	--disable-wddx \
	--without-xsl \
	\
	--disable-xdebug \
	--enable-vld \

CFLAGS='-Wall -Wconversion -Wno-strict-aliasing -ggdb' make
mv sapi/cgi/php php.keepme
mv modules/dba.so dba.so.keepme

# then the apache module 
test -f config.cache && rm -f config.cache
sh ./configure \
	--prefix=%{_prefix} \
	--with-exec-dir=%{_bindir} \
	--with-config-file-path=%{_sysconfdir} \
	--with-apxs2=%{_sbindir}/apxs2 \
	--enable-cli \
	--enable-safe-mode \
	--enable-simplexml \
	--enable-spl \
	--with-sqlite \
	--enable-xml \
	--with-zlib \
	--enable-shared \
	\
	--enable-bcmath=shared \
	--enable-calendar=shared \
	--with-cpdflib=shared \
	--enable-dba=shared \
	    --with`test ! -f %{_libdir}/libqdbm.so -a ! -f /usr/local/lib/libqdbm.so && echo out`-qdbm \
		--with-db4 \
	--enable-dbx=shared \
	--enable-dom=shared \
	--enable-exif=shared \
	--enable-filepro=shared \
    --with-freetype-dir \
	--enable-ftp=shared \
	--with-gd=shared \
	  --with-jpeg-dir \
	  --with-png-dir \
	  --with-zlib-dir \
	  --with-xpm-dir \
	--enable-gd-native-ttf \
	--enable-gdchart=shared,`pwd`/ext/gd \
	--with-iconv=shared \
	--enable-mbstring=shared \
	--with-ldap=shared \
	--with-mhash=shared \
	--with-ming=shared \
	--without-mysql \
	--with-mysqli=shared,/usr/local/bin/mysql_config \
	--with-openssl=shared \
	--enable-pcntl=shared \
	--with`if test ! -f %{_libdir}/libpdf.so -a ! -f /usr/local/lib/libpdf.so; then echo "out-pdflib"; else echo "-pdflib=shared"; fi` \
	--with-pgsql=shared \
	--enable-sockets=shared \
	--enable-sysvmsg=shared \
	--enable-sysvsem=shared \
	--enable-sysvshm=shared \
	--enable-tokenizer=shared \
	--enable-wddx=shared \
	--enable-xdebug=shared	\
	\
	--with-xsl=shared \
	--enable-vld \

make clean
CFLAGS='-Wall -Wconversion -Wno-strict-aliasing -ggdb' make
mv modules/dba.so modules/dba-db4.so
# restore cgi version
mv php.keepme sapi/cgi/php
mv dba.so.keepme modules/dba.so

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_libdir}/apache
install -m 0755 .libs/libphp5.so $RPM_BUILD_ROOT%{_libdir}/apache
mkdir -p $RPM_BUILD_ROOT%{_bindir}
install -m 0755 sapi/cli/php $RPM_BUILD_ROOT%{_bindir}
install -m 0755 sapi/cgi/php $RPM_BUILD_ROOT%{_bindir}/php_cgi
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
install -m 0755 sapi/cli/php.1 $RPM_BUILD_ROOT%{_mandir}/man1
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}
install -m 0755 php.ini-recommended $RPM_BUILD_ROOT%{_sysconfdir}/php.ini
mkdir -p $RPM_BUILD_ROOT%{_libdir}/php/extensions
install -m 0755 modules/*.so $RPM_BUILD_ROOT%{_libdir}/php/extensions

%clean
rm -rf $RPM_BUILD_ROOT

%changelog
* Thu Dec 12 2003 Marcus Boerger <helly@php.net>
- Split into different packages.

* Thu Nov 27 2003 Marcus Boerger <helly@php.net>
- Fix requirements for older systems.
- Fix rpm build directory for the major distributions.
- Fix config dir.
- Rename package to php.
- Add gd extension.
- Support building of shared extensions.
- Build CLI only once.

* Thu Oct 31 2003 Marcus Boerger <helly@php.net>
- Update version to 5.
- Remove unsure external requirements.
- Remove non existing directories
- Fix targets.
- Install both CLI and CGI.
- Install manpage.
- Install ini.

* Mon Mar 04 2002 Arjen Lentz <agl@bitbike.com>
- Fix path and remove --with-imap due to conflicts with kerberos.

* Fri Jun 29 2001 Jani Taskinen <sniper@iki.fi>
- Removed some useless configure options. Made the tar names correct.

* Sun Apr 30 2000 Joey Smith <joey@samaritan.com>
- Small fix: Description still referred to package as PHP3.

* Wed Jul 21 1999 Sam Liddicott <sam@campbellsci.co.uk>
- added php4b1 and modified cgi building rules so it doesn't break module

* Wed Mar 17 1999 Sam Liddicott <sam@campbellsci.co.uk>
- Stuffed in 3.0.7 source tar and added "php" as a build destination

* Mon Oct 12 1998 Cristian Gafton <gafton@redhat.com>
- rebuild for apache 1.3.3

* Thu Oct 08 1998 Preston Brown <pbrown@redhat.com>
- updated to 3.0.5, fixes nasty bugs in 3.0.4.

* Sun Sep 27 1998 Cristian Gafton <gafton@redhat.com>
- updated to 3.0.4 and recompiled for apache 1.3.2

* Thu Sep 03 1998 Preston Brown <pbrown@redhat.com>
- improvements; builds with apache-devel package installed.

* Tue Sep 01 1998 Preston Brown <pbrown@redhat.com>
- Made initial cut for PHP3.

%files
%defattr(-,root,root)
%{_libdir}/apache/libphp5.so

%files ini
%{_sysconfdir}/php.ini

%files cgi
%defattr(-,root,root)
%{_bindir}/php_cgi

%files cpdf
%defattr(-,root,root)
%{_libdir}/php/extensions/cpdf.so

%files dba-db4
%defattr(-,root,root)
%{_libdir}/php/extensions/dba-db4.so

%files iconv
%defattr(-,root,root)
%{_libdir}/php/extensions/iconv.so

%files ldap
%defattr(-,root,root)
%{_libdir}/php/extensions/ldap.so

%files mhash
%defattr(-,root,root)
%{_libdir}/php/extensions/mhash.so

%files ming
%defattr(-,root,root)
%{_libdir}/php/extensions/ming.so

%files mysqli
%defattr(-,root,root)
%{_libdir}/php/extensions/mysqli.so

%files openssl
%defattr(-,root,root)
%{_libdir}/php/extensions/openssl.so

%files pgsql
%defattr(-,root,root)
%{_libdir}/php/extensions/pgsql.so

%files xsl
%defattr(-,root,root)
%{_libdir}/php/extensions/xsl.so

%files common
%defattr(-,root,root)
%{_bindir}/php
%{_mandir}/man1/php.1*
%{_libdir}/php/extensions/bcmath.so
%{_libdir}/php/extensions/calendar.so
%{_libdir}/php/extensions/dba.so
%{_libdir}/php/extensions/dbx.so
%{_libdir}/php/extensions/dom.so
%{_libdir}/php/extensions/exif.so
%{_libdir}/php/extensions/filepro.so
%{_libdir}/php/extensions/ftp.so
%{_libdir}/php/extensions/gd.so
%{_libdir}/php/extensions/mbstring.so
%{_libdir}/php/extensions/pcntl.so
%{_libdir}/php/extensions/pdf.so
%{_libdir}/php/extensions/sockets.so
%{_libdir}/php/extensions/sysvmsg.so
%{_libdir}/php/extensions/sysvsem.so
%{_libdir}/php/extensions/sysvshm.so
%{_libdir}/php/extensions/tokenizer.so
%{_libdir}/php/extensions/wddx.so
%{_libdir}/php/extensions/util.so
%{_libdir}/php/extensions/xdebug.so
%doc README.* TODO CODING_STANDARDS CREDITS ChangeLog LICENSE NEWS Zend/ZEND_CHANGES

EOF

RPMBASE=/usr/src/redhat
for i in /usr/src/redhat /usr/src/packages /usr/src/RPM; do
  if test -d $i; then
    RPMBASE=$i
    break
  fi
done

RPMDIR=${RPMBASE}/RPMS
SPECDIR=${RPMBASE}/SPECS
SRCDIR=${RPMBASE}/SOURCES

(
test -x cvsclean && ./cvsclean
make clean
find . -name config.cache -exec rm -f '{}' \;
cd .. 
tar czvf ${SRCDIR}/${TAR} $TARDIR )

cp -a $SPEC $SPECDIR/${SPEC}
#cp -a *.patch $SRCDIR
cd $SRCDIR
cd $SPECDIR
rpm -ba -v ${SPEC}
