1#!/bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2024 Gavin D. Howard and contributors. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# * Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation 15# and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30# This script requires some non-POSIX utilities, but that's okay because it's 31# really for maintainer use only. 32# 33# The non-POSIX utilities include: 34# 35# * git 36# * stat 37# * tar 38# * gzip 39# * xz 40# * sha512sum 41# * sha256sum 42# * gpg 43# * zip 44# * unzip 45 46shasum() { 47 48 f="$1" 49 shift 50 51 # All this fancy stuff takes the sha512 and sha256 sums and signs it. The 52 # output after this point is what I usually copy into the release notes. 53 # (See manuals/release.md for more information.) 54 printf '$ sha512sum %s\n' "$f" 55 sha512sum "$f" 56 printf '\n' 57 printf '$ sha256sum %s\n' "$f" 58 sha256sum "$f" 59 printf '\n' 60 printf "$ stat -c '%%s %%n'\n" "$f" 61 stat -c '%s %n' "$f" 62 63 if [ -f "$f.sig" ]; then 64 rm -f "$f.sig" 65 fi 66 67 gpg --detach-sig -o "$f.sig" "$f" 2> /dev/null 68 69 printf '\n' 70 printf '$ sha512sum %s.sig\n' "$f" 71 sha512sum "$f.sig" 72 printf '\n' 73 printf '$ sha256sum %s.sig\n' "$f" 74 sha256sum "$f.sig" 75 printf '\n' 76 printf "$ stat -c '%%s %%n'\n" "$f.sig" 77 stat -c '%s %n' "$f.sig" 78} 79 80script="$0" 81scriptdir=$(dirname "$script") 82 83. "$scriptdir/functions.sh" 84 85repo="$scriptdir/.." 86proj="bc" 87 88cd "$repo" 89 90if [ ! -f "../vs.zip" ]; then 91 printf 'Must have Windows builds!\n' 92 exit 1 93fi 94 95# We want the absolute path for later. 96repo=$(pwd) 97 98# This convoluted mess does pull the version out. If you change the format of 99# include/version.h, you may have to change this line. 100version=$(cat include/version.h | grep "VERSION " - | awk '{ print $3 }' -) 101 102tag_msg="Version $version" 103projver="${proj}-${version}" 104 105tempdir="/tmp/${projver}" 106rm -rf $tempdir 107mkdir -p $tempdir 108 109make clean_tests > /dev/null 2> /dev/null 110 111# Delete the tag and recreate it. This is the part of the script that makes it 112# so you cannot run it twice on the same version, unless you know what you are 113# doing. In fact, you cannot run it again if users have already started to use 114# the old version of the tag. 115if git rev-parse "$version" > /dev/null 2>&1; then 116 git push --delete origin "$version" > /dev/null 2> /dev/null 117 git tag --delete "$version" > /dev/null 2> /dev/null 118fi 119 120git push > /dev/null 2> /dev/null 121git tg "$version" -m "$tag_msg" > /dev/null 2> /dev/null 122git push --tags > /dev/null 2> /dev/null 123 124# This line grabs the names of all of the files in .gitignore that still exist. 125ignores=$(git check-ignore * **/*) 126 127cp -r ./* "$tempdir" 128 129cd $tempdir 130 131# Delete all the ignored files. 132for i in $ignores; do 133 rm -rf "./$i" 134done 135 136# This is a list of files that end users (including *software packagers* and 137# *distro maintainers*!) do not care about. In particular, they *do* care about 138# the testing infrastructure for the regular test suite because distro 139# maintainers probably want to ensure the test suite runs. However, they 140# probably don't care about fuzzing or other randomized testing. Also, I 141# technically can't distribute tests/bc/scripts/timeconst.bc because it's from 142# the Linux kernel, which is GPL. 143extras=$(cat <<*EOF 144.git/ 145.gitignore 146.gitattributes 147benchmarks/ 148manuals/bc.1.md.in 149manuals/dc.1.md.in 150manuals/benchmarks.md 151manuals/development.md 152manuals/header_bcl.txt 153manuals/header_bc.txt 154manuals/header_dc.txt 155manuals/header.txt 156manuals/release.md 157scripts/afl.py 158scripts/alloc.sh 159scripts/benchmark.sh 160scripts/bitfuncgen.c 161scripts/fuzz_prep.sh 162scripts/manpage.sh 163scripts/ministat.c 164scripts/package.sh 165scripts/radamsa.sh 166scripts/radamsa.txt 167scripts/randmath.py 168scripts/release_settings.txt 169scripts/release.sh 170scripts/test_settings.sh 171scripts/test_settings.txt 172tests/bc_outputs/ 173tests/dc_outputs/ 174tests/fuzzing/ 175tests/bc/scripts/timeconst.bc 176*EOF 177) 178 179for i in $extras; do 180 rm -rf "./$i" 181done 182 183cd .. 184 185parent="$repo/.." 186 187# Cleanup old stuff. 188if [ -f "$projver.tar.gz" ]; then 189 rm -rf "$projver.tar.gz" 190fi 191 192if [ -f "$projver.tar.gz.sig" ]; then 193 rm -rf "$projver.tar.gz.sig" 194fi 195 196if [ -f "$projver.tar.xz" ]; then 197 rm -rf "$projver.tar.xz" 198fi 199 200if [ -f "$projver.tar.xz.sig" ]; then 201 rm -rf "$projver.tar.xz.sig" 202fi 203 204# Tar and compress and move into the parent directory of the repo. 205tar cf "$projver.tar" "$projver/" 206gzip -k "$projver.tar" 207mv "$projver.tar.gz" "$parent" 208xz -z -v -9 -e "$projver.tar" > /dev/null 2> /dev/null 209mv "$projver.tar.xz" "$parent" 210 211cd "$parent" 212 213# Clean up old Windows stuff. 214if [ -d windows ]; then 215 rm -rf windows 216fi 217 218if [ -f windows.zip ]; then 219 rm -rf $projver-windows.zip 220fi 221 222# Prepare Windows stuff. 223unzip vs.zip > /dev/null 224mv vs windows 225 226# Remove unneeded Windows stuff. 227rm -rf windows/*.vcxproj.user 228rm -rf windows/src2 229rm -rf windows/tests 230rm -rf windows/*.sln 231rm -rf windows/*.vcxproj 232rm -rf windows/*.vcxproj.filters 233 234rm -rf windows/bin/{Win32,x64}/{Debug,Release}/*.obj 235rm -rf windows/bin/{Win32,x64}/{Debug,Release}/*.iobj 236rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.exe.recipe 237rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.ilk 238rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.log 239rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.tlog 240rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.pdb 241rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.ipdb 242rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.vcxproj.FileListAbsolute.txt 243rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.Build.CppClean.log 244rm -rf windows/bin/{Win32,x64}/{Debug,Release}/strgen.exe 245rm -rf windows/bin/{Win32,x64}/{Debug,Release}/vc142.idb 246rm -rf windows/bin/{Win32,x64}/{Debug,Release}/vc142.pdb 247 248rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/*.obj 249rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.lib.recipe 250rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.log 251rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.tlog 252rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.idb 253rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.pdb 254rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.vcxproj.FileListAbsolute.txt 255rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.Build.CppClean.log 256 257# Zip the Windows stuff. 258zip -r $projver-windows.zip windows > /dev/null 259 260printf '\n' 261shasum "$projver.tar.gz" 262printf '\n' 263shasum "$projver.tar.xz" 264printf '\n' 265shasum "$projver-windows.zip" 266 267mkdir -p "releases/$projver" 268mv $projver* "releases/$projver" 269 270# Clean up old Windows stuff. 271if [ -d windows ]; then 272 rm -rf windows 273fi 274 275if [ -f vs.zip ]; then 276 rm -rf vs.zip 277fi 278