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