makedist 5.2 KB

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