]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - scripts/package.sh
vendor/bc: import of version 5.2.5
[FreeBSD/FreeBSD.git] / scripts / package.sh
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 # * gzip
39 # * xz
40 # * sha512sum
41 # * sha256sum
42 # * gpg
43 # * zip
44 # * unzip
45
46 shasum() {
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
80 script="$0"
81 scriptdir=$(dirname "$script")
82
83 repo="$scriptdir/.."
84 proj="bc"
85
86 cd "$repo"
87
88 if [ ! -f "../vs.zip" ]; then
89         printf 'Must have Windows builds!\n'
90         exit 1
91 fi
92
93 # We want the absolute path for later.
94 repo=$(pwd)
95
96 # This convoluted mess does pull the version out. If you change the format of
97 # include/version.h, you may have to change this line.
98 version=$(cat include/version.h | grep "VERSION " - | awk '{ print $3 }' -)
99
100 tag_msg="Version $version"
101 projver="${proj}-${version}"
102
103 tempdir="/tmp/${projver}"
104 rm -rf $tempdir
105 mkdir -p $tempdir
106
107 make clean_tests > /dev/null 2> /dev/null
108
109 # Delete the tag and recreate it. This is the part of the script that makes it
110 # so you cannot run it twice on the same version, unless you know what you are
111 # doing. In fact, you cannot run it again if users have already started to use
112 # the old version of the tag.
113 if git rev-parse "$version" > /dev/null 2>&1; then
114         git push --delete origin "$version" > /dev/null 2> /dev/null
115         git tag --delete "$version" > /dev/null 2> /dev/null
116 fi
117
118 git push > /dev/null 2> /dev/null
119 git tg "$version" -m "$tag_msg" > /dev/null 2> /dev/null
120 git push --tags > /dev/null 2> /dev/null
121
122 # This line grabs the names of all of the files in .gitignore that still exist.
123 ignores=$(git check-ignore * **/*)
124
125 cp -r ./* "$tempdir"
126
127 cd $tempdir
128
129 # Delete all the ignored files.
130 for i in $ignores; do
131         rm -rf "./$i"
132 done
133
134 # This is a list of files that end users (including *software packagers* and
135 # *distro maintainers*!) do not care about. In particular, they *do* care about
136 # the testing infrastructure for the regular test suite because distro
137 # maintainers probably want to ensure the test suite runs. However, they
138 # probably don't care about fuzzing or other randomized testing. Also, I
139 # technically can't distribute tests/bc/scripts/timeconst.bc because it's from
140 # the Linux kernel, which is GPL.
141 extras=$(cat <<*EOF
142 .git/
143 .gitignore
144 .gitattributes
145 benchmarks/
146 manuals/bc.1.md.in
147 manuals/dc.1.md.in
148 manuals/benchmarks.md
149 manuals/development.md
150 manuals/header_bcl.txt
151 manuals/header_bc.txt
152 manuals/header_dc.txt
153 manuals/header.txt
154 manuals/release.md
155 scripts/afl.py
156 scripts/alloc.sh
157 scripts/benchmark.sh
158 scripts/bitfuncgen.c
159 scripts/fuzz_prep.sh
160 scripts/manpage.sh
161 scripts/ministat.c
162 scripts/package.sh
163 scripts/radamsa.sh
164 scripts/radamsa.txt
165 scripts/randmath.py
166 scripts/release_settings.txt
167 scripts/release.sh
168 scripts/test_settings.sh
169 scripts/test_settings.txt
170 tests/bc_outputs/
171 tests/dc_outputs/
172 tests/fuzzing/
173 tests/bc/scripts/timeconst.bc
174 *EOF
175 )
176
177 for i in $extras; do
178         rm -rf "./$i"
179 done
180
181 cd ..
182
183 parent="$repo/.."
184
185 # Cleanup old stuff.
186 if [ -f "$projver.tar.gz" ]; then
187         rm -rf "$projver.tar.gz"
188 fi
189
190 if [ -f "$projver.tar.gz.sig" ]; then
191         rm -rf "$projver.tar.gz.sig"
192 fi
193
194 if [ -f "$projver.tar.xz" ]; then
195         rm -rf "$projver.tar.xz"
196 fi
197
198 if [ -f "$projver.tar.xz.sig" ]; then
199         rm -rf "$projver.tar.xz.sig"
200 fi
201
202 # Tar and compress and move into the parent directory of the repo.
203 tar cf "$projver.tar" "$projver/"
204 gzip -k "$projver.tar"
205 mv "$projver.tar.gz" "$parent"
206 xz -z -v -9 -e "$projver.tar" > /dev/null 2> /dev/null
207 mv "$projver.tar.xz" "$parent"
208
209 cd "$parent"
210
211 # Clean up old Windows stuff.
212 if [ -d windows ]; then
213         rm -rf windows
214 fi
215
216 if [ -f windows.zip ]; then
217         rm -rf $projver-windows.zip
218 fi
219
220 # Prepare Windows stuff.
221 unzip vs.zip > /dev/null
222 mv vs windows
223
224 # Remove unneeded Windows stuff.
225 rm -rf windows/*.vcxproj.user
226 rm -rf windows/src2
227 rm -rf windows/tests
228 rm -rf windows/*.sln
229 rm -rf windows/*.vcxproj
230 rm -rf windows/*.vcxproj.filters
231
232 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/*.obj
233 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/*.iobj
234 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.exe.recipe
235 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.ilk
236 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.log
237 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.tlog
238 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.pdb
239 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.ipdb
240 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/bc.vcxproj.FileListAbsolute.txt
241 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/strgen.exe
242 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/vc142.idb
243 rm -rf windows/bin/{Win32,x64}/{Debug,Release}/vc142.pdb
244
245 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/*.obj
246 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.lib.recipe
247 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.log
248 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.tlog
249 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.idb
250 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.pdb
251 rm -rf windows/lib/{Win32,x64}/{Debug,ReleaseMD,ReleaseMT}/bcl.vcxproj.FileListAbsolute.txt
252
253 # Zip the Windows stuff.
254 zip -r $projver-windows.zip windows > /dev/null
255
256 printf '\n'
257 shasum "$projver.tar.gz"
258 printf '\n'
259 shasum "$projver.tar.xz"
260 printf '\n'
261 shasum "$projver-windows.zip"