1#!/bin/sh 2# 3# Creates PHP release packages. 4# 5# Written by Stig Bakken <ssb@guardian.no> 1997-05-28. 6# Adapted to Git by Stanislav Malyshev <stas@php.net>. 7 8# Check whether gtar is present (GNU tar) 9tar="$(which gtar)" 10tar="${tar:-$(which tar)}" 11 12# Handle GNU vs. BSD checksum utilities 13md5sum="$(which md5sum)" 14md5sum="${md5sum:-$(which md5)}" 15 16# GNU touch is preferred since it handles local TZ in timestamps 17touch="$(which gtouch)" 18touch="${touch:-$(which touch)}" 19 20if [[ $($tar --version) == *"bsdtar"* ]]; then 21 echo "Found bsdtar at $tar, but this script needs GNU tar." 22 exit 1 23fi 24 25# Go to project root directory. 26cd "$(CDPATH='' cd -- "$(dirname -- "$0")/../../" && pwd -P)" || exit 27 28# Process options and arguments. 29while :; do 30 case $1 in 31 -h|--help) 32 cat << HELP 33PHP distribution generator 34 35Creates PHP release packages (tar.gz, tar.bz2, tar.xz) from the php-src Git 36repository. The snapshot archive includes also generated configure script, 37configuration headers, parsers, lexers, and similar generated files to simplify 38the installation on the *nix systems. 39 40SYNOPSIS: 41 makedist [options] <tree-ish> 42 43OPTIONS: 44 -h, --help Display this help. 45 --remote=<repo> Instead of using a local repository, retrieve a tar archive 46 from a remote repository. 47 <tree-ish> The Git tree or Git commit to produce an archive for. This 48 script needs a consistent tagging of releases. Each release 49 of a package should have a tag of the form: 50 php-X.Y.Z[alpha|beta|RC] 51 52 or branch: 53 PHP-X.Y[.Z] 54 55 Where: 56 - X is major version number 57 - Y is minor version number 58 - Z is patch version number 59 - last part of tag is optional and is one of RC, alpha, or 60 beta and belonging number. 61 62EXAMPLES: 63 64 Create snapshot of the master branch: 65 scripts/dev/makedist 66 67 Create snapshot of the PHP-7.4 branch: 68 scripts/dev/makedist PHP-7.4 69 70 Create release packages for the stable tag php-7.4.0: 71 scripts/dev/makedist php-7.4.0 72 73 Create release candidate packages for the tag php-7.4.0RC1: 74 scripts/dev/makedist php-7.4.0RC1 75 76 Create release packages from a remote Git repository for the tag php-7.4.0: 77 scripts/dev/makedist --remote=git@github.com:php/php-src.git php-7.4.0 78HELP 79 exit 80 ;; 81 --remote) 82 # Check for an option argument. 83 if test -n "$2"; then 84 remote=$2 85 shift 86 else 87 echo "makedist: '--remote' requires a non-empty option argument." >&2 88 exit 1 89 fi 90 ;; 91 --remote=?*) 92 # Set everything after the "=". 93 remote=${1#*=} 94 ;; 95 --remote=) 96 # When passing empty "--remote=" option. 97 echo "makedist: '--remote' requires a non-empty option argument." >&2 98 exit 1 99 ;; 100 -?*) 101 echo "makedist WARNING: Unknown option (ignored): '$1'" >&2 102 ;; 103 *) 104 # When no more options, check for an argument and break out of the loop. 105 if test -n "$1"; then 106 treeish="$1" 107 prefix="$treeish" 108 elif test -z "$treeish"; then 109 treeish="master" 110 prefix="php-master-"$(date +"%Y-%m-%d-%H-%M") 111 fi 112 break 113 esac 114 115 shift 116done 117 118# Verify that the temporary directory for the package files doesn't exist. 119if test -d "$prefix"; then 120 echo "makedist: The directory $prefix" >&2 121 echo " already exists. Rename or remove it and run makedist again." >&2 122 exit 1 123fi 124 125if test -n "$remote"; then 126 remote_option="--remote=$remote" 127 git=$remote 128else 129 echo "makedist: Verifying that tree-ish $treeish exists in Git repository." 130 git rev-parse --verify $treeish 131 exit_code=$? 132 if test "$exit_code" != "0"; then 133 echo "makedist: $treeish is not found in the Git repository." >&2 134 exit $exit_code 135 else 136 echo "makedist: OK" 137 fi 138 139 git="current Git repository." 140fi 141 142# Export PHP. 143echo "makedist: Exporting $treeish from $git" 144git archive --format=tar $remote_option --prefix=$prefix/ $treeish | "$tar" xvf - || exit 4 145 146cd $prefix || exit 5 147 148# Generate configure script so autoconf is not required to install. 149echo "" 150echo "makedist: Generating files." 151./buildconf --force 152 153# Generate lexer and parser files so bison and re2c aren't required to install. 154./scripts/dev/genfiles 155exit_code=$? 156if test "$exit_code" != "0"; then 157 exit $exit_code 158fi 159 160# Remove not needed files. 161rm -rf autom4te.cache/ 162 163# Download PEAR. 164echo "" 165echo "makedist: Attempting to download PEAR's phar archive." 166if test ! -x wget; then 167 wget https://pear.php.net/install-pear-nozlib.phar -nd -P pear/ 168 if [ "x$?" != "x0" ]; then 169 echo "makedist: PEAR download failed." >&2 170 exit 1 171 fi 172else 173 echo "makedist: Missing wget binary needed for PEAR download." >&2 174 exit 1 175fi 176 177# Reset the modification and access times of all files to be packaged. 178commitDate="$(git log -1 --format=%cI $treeish)" 179echo "makedist: Resetting the modification and access times of package files to $commitDate" 180"$touch" -c -d"$commitDate" NEWS 181find . -exec "$touch" -r NEWS -c {} \; 182 183cd .. 184 185echo "" 186echo "makedist: Creating $prefix.tar archive." 187"$tar" cf "$prefix".tar --owner=0 --group=0 --numeric-owner --sort=name "$prefix" 188rm -rf "$prefix" "$prefix".tar.* 189 190echo "makedist: Creating $prefix.tar.gz archive." 191gzip -9 -k "$prefix".tar || exit 6 192"$md5sum" "$prefix".tar.gz 193gzip -t "$prefix".tar.gz 194 195sync 196sleep 2 197 198echo "makedist: Creating $prefix.tar.bz2 archive." 199bzip2 -9 -k $prefix.tar || exit 7 200"$md5sum" $prefix.tar.bz2 201bzip2 -t $prefix.tar.bz2 202 203sync 204sleep 2 205 206echo "makedist: Creating $prefix.tar.xz archive." 207xz -9 -k "$prefix".tar || exit 9 208"$md5sum" "$prefix".tar.xz 209xz -t "$prefix".tar.xz 210 211echo "" 212echo "makedist: Cleaning up." 213rm -f "$prefix".tar || exit 13 214echo "" 215echo "makedist: All done." 216