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