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