• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
29set -eu
30
31export LC_ALL=C
32export TZ=UTC
33
34version="${1:-}"
35cmd="${2:-}"
36
37if [ -z "$version" ]; then
38  echo "Specify a version number!"
39  exit
40fi
41
42echo "$cmd"
43
44only=""
45if [ "only" = "$cmd" ]; then
46  echo "Setup version number only!"
47  only=1
48fi
49
50commit=""
51if [ "commit" = "$cmd" ]; then
52  commit=1
53fi
54
55libversion="$version"
56
57# we make curl the same version as libcurl
58curlversion="$libversion"
59
60major=$(echo "$libversion" | cut -d. -f1 | sed -e "s/[^0-9]//g")
61minor=$(echo "$libversion" | cut -d. -f2 | sed -e "s/[^0-9]//g")
62patch=$(echo "$libversion" | cut -d. -f3 | cut -d- -f1 | sed -e "s/[^0-9]//g")
63
64if test -z "$patch"; then
65  echo "invalid version number? needs to be z.y.z"
66  exit
67fi
68
69#
70# As a precaution, remove all *.dist files that may be lying around, to reduce
71# the risk of old leftovers getting shipped.
72echo "removing all old *.dist files"
73find . -name "*.dist" -exec rm {} \;
74
75numeric="$(printf "%02x%02x%02x\n" "$major" "$minor" "$patch")"
76
77HEADER=include/curl/curlver.h
78CHEADER=src/tool_version.h
79
80if test -z "$only"; then
81  ext=".dist"
82  # when not setting up version numbers locally
83  for a in $HEADER $CHEADER; do
84    cp "$a" "$a$ext"
85  done
86  HEADER="$HEADER$ext"
87  CHEADER="$CHEADER$ext"
88fi
89
90# requires a date command that knows + for format and -d for date input
91timestamp=${SOURCE_DATE_EPOCH:-$(date +"%s")}
92datestamp=$(date -d "@$timestamp" +"%F")
93filestamp=$(date -d "@$timestamp" +"%Y%m%d%H%M.%S")
94
95# Replace version number in header file:
96sed -i \
97  -e "s/^#define LIBCURL_VERSION .*/#define LIBCURL_VERSION \"$libversion\"/g" \
98  -e "s/^#define LIBCURL_VERSION_NUM .*/#define LIBCURL_VERSION_NUM 0x$numeric/g" \
99  -e "s/^#define LIBCURL_VERSION_MAJOR .*/#define LIBCURL_VERSION_MAJOR $major/g" \
100  -e "s/^#define LIBCURL_VERSION_MINOR .*/#define LIBCURL_VERSION_MINOR $minor/g" \
101  -e "s/^#define LIBCURL_VERSION_PATCH .*/#define LIBCURL_VERSION_PATCH $patch/g" \
102  -e "s/^#define LIBCURL_TIMESTAMP .*/#define LIBCURL_TIMESTAMP \"$datestamp\"/g" \
103  "$HEADER"
104
105# Replace version number in header file:
106sed -i "s/#define CURL_VERSION .*/#define CURL_VERSION \"$curlversion\"/g" "$CHEADER"
107
108if test -n "$only"; then
109  # done!
110  exit
111fi
112
113echo "curl version $curlversion"
114echo "libcurl version $libversion"
115echo "libcurl numerical $numeric"
116echo "datestamp $datestamp"
117
118findprog() {
119  file="$1"
120  for part in $(echo "$PATH" | tr ':' ' '); do
121    path="$part/$file"
122    if [ -x "$path" ]; then
123      # there it is!
124      return 1
125    fi
126  done
127
128  # no such executable
129  return 0
130}
131
132############################################################################
133#
134# Enforce a rerun of configure (updates the VERSION)
135#
136
137echo "Re-running config.status"
138./config.status --recheck >/dev/null
139
140echo "Recreate the built-in manual (with correct version)"
141export CURL_MAKETGZ_VERSION="$version"
142rm -f docs/cmdline-opts/curl.txt
143make -C src
144
145############################################################################
146#
147# automake is needed to run to make a non-GNU Makefile.in if Makefile.am has
148# been modified.
149#
150
151if { findprog automake >/dev/null 2>/dev/null; } then
152  echo "- Could not find or run automake, I hope you know what you are doing!"
153else
154  echo "Runs automake --include-deps"
155  automake --include-deps Makefile >/dev/null
156fi
157
158if test -n "$commit"; then
159  echo "produce docs/tarball-commit.txt"
160  git rev-parse HEAD >docs/tarball-commit.txt.dist
161fi
162
163echo "produce RELEASE-TOOLS.md"
164./scripts/release-tools.sh "$timestamp" "$version" "$commit" > docs/RELEASE-TOOLS.md.dist
165
166############################################################################
167#
168# Now run make dist to generate a tar.gz archive
169#
170
171echo "make dist"
172targz="curl-$version.tar.gz"
173make -sj dist "VERSION=$version"
174res=$?
175
176if test "$res" != 0; then
177  echo "make dist failed"
178  exit 2
179fi
180
181retar() {
182  tempdir=$1
183  rm -rf "$tempdir"
184  mkdir "$tempdir"
185  cd "$tempdir"
186  gzip -dc "../$targz" | tar -xf -
187  find curl-* -depth -exec touch -c -t "$filestamp" '{}' +
188  tar --create --format=ustar --owner=0 --group=0 --numeric-owner --sort=name curl-* | gzip --best --no-name > out.tar.gz
189  mv out.tar.gz ../
190  cd ..
191  rm -rf "$tempdir"
192}
193
194retar ".tarbuild"
195echo "replace $targz with out.tar.gz"
196mv out.tar.gz "$targz"
197
198############################################################################
199#
200# Now make a bz2 archive from the tar.gz original
201#
202
203bzip2="curl-$version.tar.bz2"
204echo "Generating $bzip2"
205gzip -dc "$targz" | bzip2 --best > "$bzip2"
206
207############################################################################
208#
209# Now make an xz archive from the tar.gz original
210#
211
212xz="curl-$version.tar.xz"
213echo "Generating $xz"
214gzip -dc "$targz" | xz -6e - > "$xz"
215
216############################################################################
217#
218# Now make a zip archive from the tar.gz original
219#
220makezip() {
221  rm -rf "$tempdir"
222  mkdir "$tempdir"
223  cd "$tempdir"
224  gzip -dc "../$targz" | tar -xf -
225  find . | sort | zip -9 -X "$zip" -@ >/dev/null
226  mv "$zip" ../
227  cd ..
228  rm -rf "$tempdir"
229}
230
231zip="curl-$version.zip"
232echo "Generating $zip"
233tempdir=".builddir"
234makezip
235
236# Set deterministic timestamp
237touch -c -t "$filestamp" "$targz" "$bzip2" "$xz" "$zip"
238
239echo "------------------"
240echo "maketgz report:"
241echo ""
242ls -l "$targz" "$bzip2" "$xz" "$zip"
243sha256sum "$targz" "$bzip2" "$xz" "$zip"
244
245echo "Run this:"
246echo "gpg -b -a '$targz' && gpg -b -a '$bzip2' && gpg -b -a '$xz' && gpg -b -a '$zip'"
247