maketgz 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/bin/sh
  2. # Script to build release-archives with. Note that this requires a checkout
  3. # from git and you should first run autoreconf -fi and build curl once.
  4. #
  5. #***************************************************************************
  6. # _ _ ____ _
  7. # Project ___| | | | _ \| |
  8. # / __| | | | |_) | |
  9. # | (__| |_| | _ <| |___
  10. # \___|\___/|_| \_\_____|
  11. #
  12. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  13. #
  14. # This software is licensed as described in the file COPYING, which
  15. # you should have received as part of this distribution. The terms
  16. # are also available at https://curl.se/docs/copyright.html.
  17. #
  18. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  19. # copies of the Software, and permit persons to whom the Software is
  20. # furnished to do so, under the terms of the COPYING file.
  21. #
  22. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  23. # KIND, either express or implied.
  24. #
  25. # SPDX-License-Identifier: curl
  26. #
  27. ###########################################################################
  28. set -eu
  29. export LC_ALL=C
  30. export TZ=UTC
  31. version="${1:-}"
  32. cmd="${2:-}"
  33. if [ -z "$version" ]; then
  34. echo "Specify a version number!"
  35. exit
  36. fi
  37. echo "$cmd"
  38. only=""
  39. if [ "only" = "$cmd" ]; then
  40. echo "Setup version number only!"
  41. only=1
  42. fi
  43. commit=""
  44. if [ "commit" = "$cmd" ]; then
  45. commit=1
  46. fi
  47. libversion="$version"
  48. # we make curl the same version as libcurl
  49. curlversion="$libversion"
  50. major=$(echo "$libversion" | cut -d. -f1 | sed -e "s/[^0-9]//g")
  51. minor=$(echo "$libversion" | cut -d. -f2 | sed -e "s/[^0-9]//g")
  52. patch=$(echo "$libversion" | cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g")
  53. if test -z "$patch"; then
  54. echo "invalid version number? needs to be z.y.z"
  55. exit
  56. fi
  57. #
  58. # As a precaution, remove all *.dist files that may be lying around, to reduce
  59. # the risk of old leftovers getting shipped. The root 'Makefile.dist' is the
  60. # exception.
  61. echo "removing all old *.dist files"
  62. find . -name "*.dist" -a ! -name Makefile.dist -exec rm {} \;
  63. numeric="$(printf "%02x%02x%02x\n" "$major" "$minor" "$patch")"
  64. HEADER=include/curl/curlver.h
  65. CHEADER=src/tool_version.h
  66. if test -z "$only"; then
  67. ext=".dist"
  68. # when not setting up version numbers locally
  69. for a in $HEADER $CHEADER; do
  70. cp "$a" "$a$ext"
  71. done
  72. HEADER="$HEADER$ext"
  73. CHEADER="$CHEADER$ext"
  74. fi
  75. # requires a date command that knows + for format and -d for date input
  76. timestamp=${SOURCE_DATE_EPOCH:-$(date +"%s")}
  77. datestamp=$(date -d "@$timestamp" +"%F")
  78. filestamp=$(date -d "@$timestamp" +"%Y%m%d%H%M.%S")
  79. # Replace version number in header file:
  80. sed -i \
  81. -e "s/^#define LIBCURL_VERSION .*/#define LIBCURL_VERSION \"$libversion\"/g" \
  82. -e "s/^#define LIBCURL_VERSION_NUM .*/#define LIBCURL_VERSION_NUM 0x$numeric/g" \
  83. -e "s/^#define LIBCURL_VERSION_MAJOR .*/#define LIBCURL_VERSION_MAJOR $major/g" \
  84. -e "s/^#define LIBCURL_VERSION_MINOR .*/#define LIBCURL_VERSION_MINOR $minor/g" \
  85. -e "s/^#define LIBCURL_VERSION_PATCH .*/#define LIBCURL_VERSION_PATCH $patch/g" \
  86. -e "s/^#define LIBCURL_TIMESTAMP .*/#define LIBCURL_TIMESTAMP \"$datestamp\"/g" \
  87. "$HEADER"
  88. # Replace version number in header file:
  89. sed -i "s/#define CURL_VERSION .*/#define CURL_VERSION \"$curlversion\"/g" "$CHEADER"
  90. if test -n "$only"; then
  91. # done!
  92. exit
  93. fi
  94. echo "curl version $curlversion"
  95. echo "libcurl version $libversion"
  96. echo "libcurl numerical $numeric"
  97. echo "datestamp $datestamp"
  98. findprog() {
  99. file="$1"
  100. for part in $(echo "$PATH" | tr ':' ' '); do
  101. path="$part/$file"
  102. if [ -x "$path" ]; then
  103. # there it is!
  104. return 1
  105. fi
  106. done
  107. # no such executable
  108. return 0
  109. }
  110. ############################################################################
  111. #
  112. # Enforce a rerun of configure (updates the VERSION)
  113. #
  114. echo "Re-running config.status"
  115. ./config.status --recheck >/dev/null
  116. echo "Recreate the built-in manual (with correct version)"
  117. export CURL_MAKETGZ_VERSION="$version"
  118. rm -f docs/cmdline-opts/curl.txt
  119. make -C src
  120. ############################################################################
  121. #
  122. # automake is needed to run to make a non-GNU Makefile.in if Makefile.am has
  123. # been modified.
  124. #
  125. if { findprog automake >/dev/null 2>/dev/null; } then
  126. echo "- Could not find or run automake, I hope you know what you are doing!"
  127. else
  128. echo "Runs automake --include-deps"
  129. automake --include-deps Makefile >/dev/null
  130. fi
  131. if test -n "$commit"; then
  132. echo "produce docs/tarball-commit.txt"
  133. git rev-parse HEAD >docs/tarball-commit.txt.dist
  134. fi
  135. echo "produce RELEASE-TOOLS.md"
  136. ./scripts/release-tools.sh "$timestamp" "$version" "$commit" > docs/RELEASE-TOOLS.md.dist
  137. ############################################################################
  138. #
  139. # Now run make dist to generate a tar.gz archive
  140. #
  141. echo "make dist"
  142. targz="curl-$version.tar.gz"
  143. make -sj dist "VERSION=$version"
  144. res=$?
  145. if test "$res" != 0; then
  146. echo "make dist failed"
  147. exit 2
  148. fi
  149. retar() {
  150. tempdir=$1
  151. rm -rf "$tempdir"
  152. mkdir "$tempdir"
  153. cd "$tempdir"
  154. gzip -dc "../$targz" | tar -xf -
  155. find curl-* -depth -exec touch -c -t "$filestamp" '{}' +
  156. tar --create --format=ustar --owner=0 --group=0 --numeric-owner --sort=name curl-* | gzip --best --no-name > out.tar.gz
  157. mv out.tar.gz ../
  158. cd ..
  159. rm -rf "$tempdir"
  160. }
  161. retar ".tarbuild"
  162. echo "replace $targz with out.tar.gz"
  163. mv out.tar.gz "$targz"
  164. ############################################################################
  165. #
  166. # Now make a bz2 archive from the tar.gz original
  167. #
  168. bzip2="curl-$version.tar.bz2"
  169. echo "Generating $bzip2"
  170. gzip -dc "$targz" | bzip2 --best > "$bzip2"
  171. ############################################################################
  172. #
  173. # Now make an xz archive from the tar.gz original
  174. #
  175. xz="curl-$version.tar.xz"
  176. echo "Generating $xz"
  177. gzip -dc "$targz" | xz -6e - > "$xz"
  178. ############################################################################
  179. #
  180. # Now make a zip archive from the tar.gz original
  181. #
  182. makezip() {
  183. rm -rf "$tempdir"
  184. mkdir "$tempdir"
  185. cd "$tempdir"
  186. gzip -dc "../$targz" | tar -xf -
  187. find . | sort | zip -9 -X "$zip" -@ >/dev/null
  188. mv "$zip" ../
  189. cd ..
  190. rm -rf "$tempdir"
  191. }
  192. zip="curl-$version.zip"
  193. echo "Generating $zip"
  194. tempdir=".builddir"
  195. makezip
  196. # Set deterministic timestamp
  197. touch -c -t "$filestamp" "$targz" "$bzip2" "$xz" "$zip"
  198. echo "------------------"
  199. echo "maketgz report:"
  200. echo ""
  201. ls -l "$targz" "$bzip2" "$xz" "$zip"
  202. sha256sum "$targz" "$bzip2" "$xz" "$zip"
  203. echo "Run this:"
  204. echo "gpg -b -a '$targz' && gpg -b -a '$bzip2' && gpg -b -a '$xz' && gpg -b -a '$zip'"