[f33f781] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Build and package mod_php on Slackware. |
---|
| 4 | # by: David Cantrell <david@slackware.com> |
---|
| 5 | # Modified for PHP 4-5 by volkerdi@slackware.com |
---|
| 6 | # Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2017, 2019, 2020, 2021 Patrick Volkerding, Sebeka, MN, USA |
---|
| 7 | # All rights reserved. |
---|
| 8 | # |
---|
| 9 | # Redistribution and use of this script, with or without modification, is |
---|
| 10 | # permitted provided that the following conditions are met: |
---|
| 11 | # |
---|
| 12 | # 1. Redistributions of this script must retain the above copyright |
---|
| 13 | # notice, this list of conditions and the following disclaimer. |
---|
| 14 | # |
---|
| 15 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
---|
| 16 | # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
---|
| 17 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
---|
| 18 | # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
| 19 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 20 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
---|
| 21 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
---|
| 22 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
---|
| 23 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
---|
| 24 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 25 | |
---|
| 26 | cd $(dirname $0) ; CWD=$(pwd) |
---|
| 27 | |
---|
| 28 | PKGNAM=php |
---|
| 29 | VERSION=${VERSION:-$(echo php-*.tar.xz | rev | cut -f 3- -d . | cut -f 1 -d - | rev)} |
---|
| 30 | ALPINE=2.25 |
---|
| 31 | BUILD=${BUILD:-1} |
---|
| 32 | |
---|
| 33 | # Automatically determine the architecture we're building on: |
---|
| 34 | if [ -z "$ARCH" ]; then |
---|
| 35 | case "$( uname -m )" in |
---|
| 36 | i?86) export ARCH=i586 ;; |
---|
| 37 | arm*) export ARCH=arm ;; |
---|
| 38 | # Unless $ARCH is already set, use uname -m for all other archs: |
---|
| 39 | *) export ARCH=$( uname -m ) ;; |
---|
| 40 | esac |
---|
| 41 | fi |
---|
| 42 | |
---|
| 43 | # If the variable PRINT_PACKAGE_NAME is set, then this script will report what |
---|
| 44 | # the name of the created package would be, and then exit. This information |
---|
| 45 | # could be useful to other scripts. |
---|
| 46 | if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then |
---|
| 47 | echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz" |
---|
| 48 | exit 0 |
---|
| 49 | fi |
---|
| 50 | |
---|
| 51 | NUMJOBS=${NUMJOBS:-" -j$(expr $(nproc) + 1) "} |
---|
| 52 | |
---|
| 53 | TMP=${TMP:-/tmp} |
---|
| 54 | PKG=$TMP/package-php/ |
---|
| 55 | rm -rf $PKG |
---|
| 56 | mkdir -p $TMP $PKG |
---|
| 57 | |
---|
| 58 | if [ "$ARCH" = "i386" ]; then |
---|
| 59 | SLKCFLAGS="-O2 -march=i386 -mcpu=i686" |
---|
| 60 | LIBDIRSUFFIX="" |
---|
| 61 | elif [ "$ARCH" = "i486" ]; then |
---|
| 62 | SLKCFLAGS="-O2 -march=i486 -mtune=i686" |
---|
| 63 | LIBDIRSUFFIX="" |
---|
| 64 | elif [ "$ARCH" = "i586" ]; then |
---|
| 65 | SLKCFLAGS="-O2 -march=i586 -mtune=i686" |
---|
| 66 | LIBDIRSUFFIX="" |
---|
| 67 | elif [ "$ARCH" = "s390" ]; then |
---|
| 68 | SLKCFLAGS="-O2" |
---|
| 69 | LIBDIRSUFFIX="" |
---|
| 70 | elif [ "$ARCH" = "x86_64" ]; then |
---|
| 71 | SLKCFLAGS="-O2 -fPIC" |
---|
| 72 | LIBDIRSUFFIX="64" |
---|
| 73 | else |
---|
| 74 | SLKCFLAGS="-O2" |
---|
| 75 | LIBDIRSUFFIX="" |
---|
| 76 | fi |
---|
| 77 | |
---|
| 78 | # Look for Kerberos on the machine and in any precompiled c-client.a: |
---|
| 79 | if /bin/ls /lib${LIBDIRSUFFIX}/libkrb5.so.? 1> /dev/null 2> /dev/null ; then |
---|
| 80 | # Remove the c-client library if it doesn't contain Kerberos support: |
---|
| 81 | if ! grep -q krb5_ /usr/local/lib${LIBDIRSUFFIX}/c-client/lib${LIBDIRSUFFIX}/c-client.a 2> /dev/null ; then |
---|
| 82 | rm -rf /usr/local/lib${LIBDIRSUFFIX}/c-client |
---|
| 83 | fi |
---|
| 84 | else |
---|
| 85 | # Remove the c-client library if it contains Kerberos support: |
---|
| 86 | if grep -q krb5_ /usr/local/lib${LIBDIRSUFFIX}/c-client/lib${LIBDIRSUFFIX}/c-client.a 2> /dev/null ; then |
---|
| 87 | rm -rf /usr/local/lib${LIBDIRSUFFIX}/c-client |
---|
| 88 | fi |
---|
| 89 | fi |
---|
| 90 | |
---|
| 91 | # we need to compile alpine to get c-client.a for IMAP support: |
---|
| 92 | # IMAPLIBDIR=/usr/local/lib${LIBDIRSUFFIX}/c-client |
---|
| 93 | # if [ -r $IMAPLIBDIR/lib${LIBDIRSUFFIX}/c-client.a ]; then |
---|
| 94 | # echo "Using IMAP library:" |
---|
| 95 | # ls -l $IMAPLIBDIR/lib${LIBDIRSUFFIX}/c-client.a |
---|
| 96 | # sleep 5 |
---|
| 97 | # else |
---|
| 98 | # ( cd $CWD/../alpine ; VERSION=${ALPINE} ; ./alpine.SlackBuild || exit 1 ) || exit 1 |
---|
| 99 | # ( cd $TMP/alpine-${ALPINE}/imap/c-client |
---|
| 100 | # strip -g c-client.a |
---|
| 101 | # mkdir -p $IMAPLIBDIR/lib${LIBDIRSUFFIX} |
---|
| 102 | # cp c-client.a $IMAPLIBDIR/lib${LIBDIRSUFFIX} |
---|
| 103 | # mkdir -p $IMAPLIBDIR/include |
---|
| 104 | # cp *.h $IMAPLIBDIR/include |
---|
| 105 | # ) |
---|
| 106 | # fi |
---|
| 107 | |
---|
| 108 | # Set Kerberos build option: |
---|
| 109 | if /bin/ls /lib${LIBDIRSUFFIX}/libkrb5.so.? 1> /dev/null 2> /dev/null ; then |
---|
| 110 | KRB5_OPTION="--with-kerberos" |
---|
| 111 | else |
---|
| 112 | unset KRB5_OPTION |
---|
| 113 | fi |
---|
| 114 | |
---|
| 115 | mkdir -p $PKG/etc/apache2 |
---|
| 116 | mkdir -p $PKG/etc/php.d |
---|
| 117 | # A trick from DaMouse to enable building php into $PKG. |
---|
| 118 | # We'll remove this later on. |
---|
| 119 | cat /etc/apache2/httpd.conf > $PKG/etc/apache2/httpd.conf |
---|
| 120 | |
---|
| 121 | cd $TMP |
---|
| 122 | rm -rf php-$VERSION |
---|
| 123 | tar xvf $CWD/php-$VERSION.tar.xz || exit 1 |
---|
| 124 | cd php-$VERSION || exit 1 |
---|
| 125 | |
---|
| 126 | # cleanup: |
---|
| 127 | find . -name "*.orig" -delete |
---|
| 128 | |
---|
| 129 | if [ "$ARCH" = "s390" ]; then |
---|
| 130 | zcat $CWD/php.configure.s390.diff.gz | patch -p1 || exit |
---|
| 131 | fi |
---|
| 132 | |
---|
| 133 | # Fixup perms/owners: |
---|
| 134 | chown -R root:root . |
---|
| 135 | find . \ |
---|
| 136 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
| 137 | -exec chmod 755 {} \+ -o \ |
---|
| 138 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
| 139 | -exec chmod 644 {} \+ |
---|
| 140 | |
---|
| 141 | find . -name "*.h" -exec chmod 644 {} \+ |
---|
| 142 | |
---|
| 143 | # Sometimes they ship a few of these: |
---|
| 144 | find . -name "*.orig" -exec rm {} \+ |
---|
| 145 | |
---|
| 146 | # Patch ini files: |
---|
| 147 | zcat $CWD/php.ini-development.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 148 | zcat $CWD/php.ini-development.diff.gz | patch -p1 --verbose php.ini-production || exit 1 |
---|
| 149 | zcat $CWD/php-fpm.conf.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 150 | |
---|
| 151 | # Fix for imap API change: |
---|
| 152 | # zcat $CWD/php.imap.api.diff.gz | patch -p1 --verbose || exit 1 |
---|
| 153 | |
---|
| 154 | # Use enchant-2: |
---|
| 155 | zcat $CWD/php.enchant-2.patch.gz | patch -p1 --verbose || exit 1 |
---|
| 156 | export ENCHANT_CFLAGS="-I/usr/include/enchant-2" |
---|
| 157 | export ENCHANT_LIBS="-lenchant-2" |
---|
| 158 | |
---|
| 159 | # Install the build folder into /usr/lib$LIBDIRSUFFIX/php/build |
---|
| 160 | # and adapt phpize accordingly: |
---|
| 161 | sed -i "s|build$|php/build|" scripts/Makefile.frag |
---|
| 162 | sed -i "s|build\"$|php/build\"|" scripts/phpize.in |
---|
| 163 | |
---|
| 164 | # NOTE: Added -DU_USING_ICU_NAMESPACE=1 to CXXFLAGS, which should be a temporary |
---|
| 165 | # requirement. See the link below: |
---|
| 166 | # http://site.icu-project.org/download/61#TOC-Migration-Issues |
---|
| 167 | |
---|
| 168 | # -DU_DEFINE_FALSE_AND_TRUE=1 since recent icu4c no longer defines these otherwise. |
---|
| 169 | |
---|
| 170 | # Generic "kitchen sink" configure function, with as many things as possible (and |
---|
| 171 | # maybe then some ;-) compiled as shared extensions: |
---|
| 172 | EXTENSION_DIR=/usr/lib${LIBDIRSUFFIX}/php/extensions \ |
---|
| 173 | CFLAGS="$SLKCFLAGS -DU_DEFINE_FALSE_AND_TRUE=1" \ |
---|
| 174 | CXXFLAGS="$SLKCFLAGS -DU_USING_ICU_NAMESPACE=1 -DU_DEFINE_FALSE_AND_TRUE=1" \ |
---|
| 175 | ./configure \ |
---|
| 176 | --prefix=/usr \ |
---|
| 177 | --libdir=/usr/lib${LIBDIRSUFFIX} \ |
---|
| 178 | --with-libdir=lib${LIBDIRSUFFIX} \ |
---|
| 179 | --localstatedir=/var \ |
---|
| 180 | --sysconfdir=/etc \ |
---|
| 181 | --datarootdir=/usr/share \ |
---|
| 182 | --datadir=/usr/share \ |
---|
| 183 | --infodir=/usr/info \ |
---|
| 184 | --mandir=/usr/man \ |
---|
| 185 | --with-apxs2=/usr/bin/apxs \ |
---|
| 186 | --enable-fpm \ |
---|
| 187 | --with-fpm-user=apache \ |
---|
| 188 | --with-fpm-group=apache \ |
---|
| 189 | --enable-maintainer-zts \ |
---|
| 190 | --enable-pcntl \ |
---|
| 191 | --enable-mbregex \ |
---|
| 192 | --enable-tokenizer=shared \ |
---|
| 193 | --with-config-file-scan-dir=/etc/php.d \ |
---|
| 194 | --with-config-file-path=/etc \ |
---|
| 195 | --with-layout=PHP \ |
---|
| 196 | --disable-sigchild \ |
---|
| 197 | --with-libxml \ |
---|
| 198 | --with-xmlrpc=shared \ |
---|
| 199 | --with-expat \ |
---|
| 200 | --enable-simplexml \ |
---|
| 201 | --enable-xmlreader=shared \ |
---|
| 202 | --enable-dom=shared \ |
---|
| 203 | --enable-filter \ |
---|
| 204 | --disable-debug \ |
---|
| 205 | --with-openssl=shared \ |
---|
| 206 | $KRB5_OPTION \ |
---|
| 207 | --with-external-pcre \ |
---|
| 208 | --with-zlib=shared,/usr \ |
---|
| 209 | --enable-bcmath=shared \ |
---|
| 210 | --with-bz2=shared,/usr \ |
---|
| 211 | --enable-calendar=shared \ |
---|
| 212 | --enable-ctype=shared \ |
---|
| 213 | --with-curl=shared \ |
---|
| 214 | --enable-exif=shared \ |
---|
| 215 | --enable-ftp=shared \ |
---|
| 216 | --enable-gd=shared \ |
---|
| 217 | --with-external-gd \ |
---|
| 218 | --with-jpeg \ |
---|
| 219 | --with-xpm \ |
---|
| 220 | --with-gettext=shared,/usr \ |
---|
| 221 | --with-gmp=shared,/usr \ |
---|
| 222 | --with-iconv=shared \ |
---|
| 223 | --with-ldap=shared \ |
---|
| 224 | --enable-mbstring=shared \ |
---|
| 225 | --enable-mysqlnd=shared \ |
---|
| 226 | --with-mysqli=shared,mysqlnd \ |
---|
| 227 | --with-mysql-sock=/var/run/mysql/mysql.sock \ |
---|
| 228 | --enable-pdo=shared \ |
---|
| 229 | --with-pdo-mysql=shared,mysqlnd \ |
---|
| 230 | --with-pdo-sqlite=shared,/usr \ |
---|
| 231 | --with-pspell=shared,/usr \ |
---|
| 232 | --enable-shmop=shared \ |
---|
| 233 | --enable-soap=shared \ |
---|
| 234 | --enable-sockets \ |
---|
| 235 | --with-sqlite3=shared \ |
---|
| 236 | --enable-sysvmsg \ |
---|
| 237 | --enable-sysvsem \ |
---|
| 238 | --enable-sysvshm \ |
---|
| 239 | --with-xsl=shared,/usr \ |
---|
| 240 | --with-tsrm-pthreads \ |
---|
| 241 | --enable-intl=shared \ |
---|
| 242 | --enable-opcache \ |
---|
| 243 | --enable-shared=yes \ |
---|
| 244 | --enable-static=no \ |
---|
| 245 | --with-gnu-ld \ |
---|
| 246 | --with-pic \ |
---|
| 247 | --enable-phpdbg \ |
---|
| 248 | --with-sodium \ |
---|
| 249 | --without-readline \ |
---|
| 250 | --with-pear \ |
---|
| 251 | --build=$ARCH-slackware-linux || exit 1 |
---|
| 252 | |
---|
| 253 | # I am told this option is worse than nothing. :-) |
---|
| 254 | # --enable-safe-mode |
---|
| 255 | # |
---|
| 256 | # I would recommend *against* and will take no responbility for turning on |
---|
| 257 | # "safe" mode. |
---|
| 258 | |
---|
| 259 | make $NUMJOBS || make || exit 1 |
---|
| 260 | make install INSTALL_ROOT=$PKG || exit 1 |
---|
| 261 | |
---|
| 262 | # Don't include the c-client library in php-config output: |
---|
| 263 | sed -i "s| -L/usr/local/lib${LIBDIRSUFFIX}/c-client/lib${LIBDIRSUFFIX}||g" $PKG/usr/bin/php-config |
---|
| 264 | sed -i "s| -lc-client||g" $PKG/usr/bin/php-config |
---|
| 265 | |
---|
| 266 | mkdir -p $PKG/etc/{rc.d,php-fpm.d} |
---|
| 267 | cp sapi/fpm/init.d.php-fpm $PKG/etc/rc.d/rc.php-fpm.new |
---|
| 268 | chmod 644 $PKG/etc/rc.d/rc.php-fpm.new |
---|
| 269 | |
---|
| 270 | # PHP (used to) install Pear with some strange permissions. |
---|
| 271 | chmod 755 $PKG/usr/bin/pear |
---|
| 272 | |
---|
| 273 | # PHP sometimes puts junk in the root directory: |
---|
| 274 | ( cd $PKG |
---|
| 275 | rm -rf .channels .depdb .depdblock .filemap .lock .registry |
---|
| 276 | ) |
---|
| 277 | |
---|
| 278 | # We do not package static extension libraries: |
---|
| 279 | rm -f $PKG/usr/lib${LIBDIRSUFFIX}/php/extensions/*.a |
---|
| 280 | |
---|
| 281 | # Fix $PKG/usr/lib/php perms: |
---|
| 282 | ( cd $PKG/usr/lib${LIBDIRSUFFIX}/php |
---|
| 283 | find . \ |
---|
| 284 | \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \ |
---|
| 285 | -exec chmod 755 {} \+ -o \ |
---|
| 286 | \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \ |
---|
| 287 | -exec chmod 644 {} \+ |
---|
| 288 | ) |
---|
| 289 | |
---|
| 290 | mkdir -p $PKG/usr/doc/php-$VERSION |
---|
| 291 | cp -a \ |
---|
| 292 | CODING_STANDARDS* CONTRIBUTING* EXTENSIONS* LICENSE* NEWS* README* UPGRADING* \ |
---|
| 293 | $PKG/usr/doc/php-$VERSION |
---|
| 294 | |
---|
| 295 | mkdir -p $PKG/etc/httpd |
---|
| 296 | cat $CWD/mod_php.conf.example | sed -e "s#lib/httpd#lib${LIBDIRSUFFIX}/httpd#" > $PKG/etc/httpd/mod_php.conf.new |
---|
| 297 | chmod 644 $PKG/etc/httpd/* |
---|
| 298 | chown root:root $PKG/etc/httpd/* |
---|
| 299 | |
---|
| 300 | cp -a php.ini-development php.ini-production $PKG/etc |
---|
| 301 | chmod 755 $PKG/etc/php.d $PKG/etc/php-fpm.d $PKG/etc/httpd |
---|
| 302 | chown root:root $PKG/etc/* |
---|
| 303 | |
---|
| 304 | # This can go now. |
---|
| 305 | rm -f $PKG/etc/httpd/httpd* |
---|
| 306 | |
---|
| 307 | # Session directory for PHP: |
---|
| 308 | mkdir -p $PKG/var/lib/php |
---|
| 309 | chmod 770 $PKG/var/lib/php |
---|
| 310 | # chown root:apache $PKG/var/lib/php |
---|
| 311 | |
---|
| 312 | # Strip ELF objects. |
---|
| 313 | find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \ |
---|
| 314 | | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null |
---|
| 315 | |
---|
| 316 | gzip -9 $PKG/usr/man/man?/*.? |
---|
| 317 | |
---|
| 318 | mkdir -p $PKG/install |
---|
| 319 | zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh |
---|
| 320 | cat $CWD/slack-desc > $PKG/install/slack-desc |
---|
| 321 | |
---|
| 322 | #if [ -d "$IMAPLIBDIR" ]; then |
---|
| 323 | # ( cd $IMAPLIBDIR && rm -rf * ) |
---|
| 324 | # rmdir $IMAPLIBDIR |
---|
| 325 | #fi |
---|
| 326 | |
---|
| 327 | cd $PKG |
---|
| 328 | /sbin/makepkg -l y -c n $TMP/php-$VERSION-$ARCH-$BUILD.txz |
---|
| 329 | |
---|