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