• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2018-2021 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# * xz
39# * sha512sum
40# * sha256sum
41# * gpg
42# * zip
43# * unzip
44
45shasum() {
46
47	f="$1"
48	shift
49
50	# All this fancy stuff takes the sha512 and sha256 sums and signs it. The
51	# output after this point is what I usually copy into the release notes.
52	# (See manuals/release.md for more information.)
53	printf '$ sha512sum %s\n' "$f"
54	sha512sum "$f"
55	printf '\n'
56	printf '$ sha256sum %s\n' "$f"
57	sha256sum "$f"
58	printf '\n'
59	printf "$ stat -c '%%s  %%n'\n" "$f"
60	stat -c '%s  %n' "$f"
61
62	if [ -f "$f.sig" ]; then
63		rm -f "$f.sig"
64	fi
65
66	gpg --detach-sig -o "$f.sig" "$f" 2> /dev/null
67
68	printf '\n'
69	printf '$ sha512sum %s.sig\n' "$f"
70	sha512sum "$f.sig"
71	printf '\n'
72	printf '$ sha256sum %s.sig\n' "$f"
73	sha256sum "$f.sig"
74	printf '\n'
75	printf "$ stat -c '%%s  %%n'\n" "$f.sig"
76	stat -c '%s  %n' "$f.sig"
77}
78
79script="$0"
80scriptdir=$(dirname "$script")
81
82repo="$scriptdir/.."
83proj="bc"
84
85cd "$repo"
86
87if [ ! -f "../Debug.zip" ] || [ ! -f "../Release.zip" ]; then
88	printf 'Must have Windows builds!\n'
89	exit 1
90fi
91
92# We want the absolute path for later.
93repo=$(pwd)
94
95# This convoluted mess does pull the version out. If you change the format of
96# include/version.h, you may have to change this line.
97version=$(cat include/version.h | grep "VERSION " - | awk '{ print $3 }' -)
98
99tag_msg="Version $version"
100projver="${proj}-${version}"
101
102tempdir="/tmp/${projver}"
103rm -rf $tempdir
104mkdir -p $tempdir
105
106make clean_tests > /dev/null 2> /dev/null
107
108# Delete the tag and recreate it. This is the part of the script that makes it
109# so you cannot run it twice on the same version, unless you know what you are
110# doing. In fact, you cannot run it again if users have already started to use
111# the old version of the tag.
112if git rev-parse "$version" > /dev/null 2>&1; then
113	git push --delete origin "$version" > /dev/null 2> /dev/null
114	git tag --delete "$version" > /dev/null 2> /dev/null
115fi
116
117git push > /dev/null 2> /dev/null
118git tg "$version" -m "$tag_msg" > /dev/null 2> /dev/null
119git push --tags > /dev/null 2> /dev/null
120
121# This line grabs the names of all of the files in .gitignore that still exist.
122ignores=$(git check-ignore * **/*)
123
124cp -r ./* "$tempdir"
125
126cd $tempdir
127
128# Delete all the ignored files.
129for i in $ignores; do
130	rm -rf "./$i"
131done
132
133# This is a list of files that end users (including *software packagers* and
134# *distro maintainers*!) do not care about. In particular, they *do* care about
135# the testing infrastructure for the regular test suite because distro
136# maintainers probably want to ensure the test suite runs. However, they
137# probably don't care about fuzzing or other randomized testing. Also, I
138# technically can't distribute tests/bc/scripts/timeconst.bc because it's from
139# the Linux kernel, which is GPL.
140extras=$(cat <<*EOF
141.git/
142.gitignore
143.gitattributes
144benchmarks/
145manuals/bc.1.md.in
146manuals/dc.1.md.in
147manuals/benchmarks.md
148manuals/development.md
149manuals/header_bcl.txt
150manuals/header_bc.txt
151manuals/header_dc.txt
152manuals/header.txt
153manuals/release.md
154scripts/afl.py
155scripts/alloc.sh
156scripts/benchmark.sh
157scripts/bitfuncgen.c
158scripts/fuzz_prep.sh
159scripts/manpage.sh
160scripts/ministat.c
161scripts/package.sh
162scripts/radamsa.sh
163scripts/radamsa.txt
164scripts/randmath.py
165scripts/release_settings.txt
166scripts/release.sh
167scripts/test_settings.sh
168scripts/test_settings.txt
169tests/bc_outputs/
170tests/dc_outputs/
171tests/fuzzing/
172tests/bc/scripts/timeconst.bc
173*EOF
174)
175
176for i in $extras; do
177	rm -rf "./$i"
178done
179
180cd ..
181
182parent="$repo/.."
183
184# Tar and compress and move into the parent directory of the repo.
185tar cf "$projver.tar" "$projver/"
186xz -z -v -9 -e "$projver.tar" > /dev/null 2> /dev/null
187mv "$projver.tar.xz" "$parent"
188
189cd "$parent"
190
191# Clean up old Windows stuff.
192if [ -d Win32_Debug ]; then
193	rm -rf Win32_Debug
194fi
195
196if [ -d Win32_Release ]; then
197	rm -rf Win32_Release
198fi
199
200if [ -d Win64_Debug ]; then
201	rm -rf Win64_Debug
202fi
203
204if [ -d Win64_Release ]; then
205	rm -rf Win64_Release
206fi
207
208# Prepare Windows stuff.
209if [ ! -d Debug ]; then
210	unzip Debug.zip > /dev/null
211fi
212
213if [ ! -d Release ]; then
214	unzip Release.zip > /dev/null
215fi
216
217# Zip the Windows stuff.
218mkdir Win32_Debug
219cp Debug/Win32/bc/bc.exe Win32_Debug
220cp Debug/Win32/bc/dc.exe Win32_Debug
221cp Debug/Win32/bcl/bcl.lib Win32_Debug
222
223mkdir Win32_Release
224cp Release/Win32/bc/bc.exe Win32_Release
225cp Release/Win32/bc/dc.exe Win32_Release
226cp Release/Win32/bcl/bcl.lib Win32_Release
227
228mkdir Win64_Debug
229cp Debug/x64/bc/bc.exe Win64_Debug
230cp Debug/x64/bc/dc.exe Win64_Debug
231cp Debug/x64/bcl/bcl.lib Win64_Debug
232
233mkdir Win64_Release
234cp Release/x64/bc/bc.exe Win64_Release
235cp Release/x64/bc/dc.exe Win64_Release
236cp Release/x64/bcl/bcl.lib Win64_Release
237
238zip -r Win32_Debug.zip Win32_Debug > /dev/null
239zip -r Win32_Release.zip Win32_Release > /dev/null
240zip -r Win64_Debug.zip Win64_Debug > /dev/null
241zip -r Win64_Release.zip Win64_Release > /dev/null
242
243printf '\n'
244shasum "$projver.tar.xz"
245printf '\n'
246shasum "Win32_Debug.zip"
247printf '\n'
248shasum "Win32_Release.zip"
249printf '\n'
250shasum "Win64_Debug.zip"
251printf '\n'
252shasum "Win64_Release.zip"
253