-
Notifications
You must be signed in to change notification settings - Fork 16
/
pkg
executable file
·197 lines (165 loc) · 4.84 KB
/
pkg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# -----------------------------------------------------------------------------
# Copyright 2014 if(we)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
usage() {
echo Usage: `basename $0` '[--debug] [--asan (yes|no)] [tar|rpm|rpm_noconfig]' 1>&2
echo 1>&2
echo 'Option --asan is ignored if --debug is not specified.'
exit 1
}
make_tar() {
echo ------------------------------------------------------------
echo Building tar archive
echo
dbg=$1
# The contents of the tarball are exactly the same regardless of whether we
# call it 'bruce' or 'bruce_debug'. The only reason for the name
# difference is to make building the 'bruce_debug' RPM package a bit
# easier.
if [ $dbg -eq 0 ]; then
pkg_base_name=bruce
else
pkg_base_name=bruce_debug
fi
pkg_name=${pkg_base_name}-${version}
rm -fr out/pkg/tar
mkdir -p out/pkg/tar/${pkg_name}
for f in `ls | grep -v out`; do
cp -a $f out/pkg/tar/${pkg_name}
done
cp .gitignore out/pkg/tar/${pkg_name}
src/bruce/scripts/gen_version -q > out/pkg/tar/${pkg_name}/version.txt
if [ "$?" -ne 0 ]; then
echo Failed to generate version.txt 1>&2
exit 1
fi
cwd=`pwd`
cd out/pkg/tar
tar cf ${pkg_name}.tar ${pkg_name}
gzip --best ${pkg_name}.tar
rm -fr ${pkg_name}
cd $cwd
echo ------------------------------------------------------------
}
make_rpm() {
echo ------------------------------------------------------------
echo Building RPM package
echo
cwd=`pwd`
dbg=$1
asan=$2
if [ $dbg -eq 0 ]; then
pkg_subdir=release
pkg_name=bruce
else
pkg_subdir=debug
pkg_name=bruce_debug
fi
if [ "$target" == "rpm_noconfig" ]; then
rpm_dir=out/pkg/${pkg_subdir}/rpm_noconfig
spec_in=rpm_specs/bruce_noconfig.spec.in
else
rpm_dir=out/pkg/${pkg_subdir}/rpm
spec_in=rpm_specs/bruce.spec.in
fi
rm -fr $rpm_dir
base=${rpm_dir}/build
mkdir -p $base/BUILD
mkdir -p $base/BUILDROOT
mkdir -p $base/RPMS
mkdir -p $base/SOURCES
mkdir -p $base/SPECS
mkdir -p $base/SRPMS
if [ $dbg -eq 0 ]; then
sed "s/BRUCE_VERSION/${version}/" < $spec_in | \
sed 's/BUILD_TYPE/release/' | \
sed 's/BRUCE_PKG_NAME/bruce/' | \
sed 's/SANITIZE_ADDRESS/no/' > $base/SPECS/bruce.spec
else
sed "s/BRUCE_VERSION/${version}/" < $spec_in | \
sed 's/BUILD_TYPE/debug/' | \
sed 's/BRUCE_PKG_NAME/bruce_debug/' | \
sed "s/SANITIZE_ADDRESS/${asan}/" > $base/SPECS/bruce.spec
fi
cp out/pkg/tar/${pkg_name}-${version}.tar.gz $base/SOURCES
cd $base
rpmbuild --define "_topdir `pwd`" -ba SPECS/bruce.spec
if [ "$?" -ne 0 ]; then
echo RPM build failed 1>&2
exit 1
fi
for f in `find RPMS -type f`; do
mv $f ..
done
for f in `find SRPMS -type f`; do
mv $f ..
done
cd $cwd
rm -fr $base
echo ------------------------------------------------------------
}
debug=0
asan=yes
target=
while [ $# -gt 0 ]; do
key="$1"
case $key in
--debug)
if [ ! -z "$target" ]; then
usage
fi
debug=1
;;
--asan)
if [ ! -z "$target" ]; then
usage
fi
if [ "$2" == "yes" ] || [ "$2" == "no" ]; then
asan=$2
else
usage
fi
shift
;;
*)
if [ "$key" == "tar" ] || [ "$key" == "rpm" ] || \
[ "$key" == "rpm_noconfig" ]; then
target=$key
else
usage
fi
;;
esac
shift
done
if [ -z "$target" ]; then
usage
fi
if [ "$debug" -eq 0 ]; then
asan=no
fi
if [ ! -f "SConstruct" ] || [ ! -d "src" ]; then
echo This script must be executed from the root of the tree 1>&2
exit 1
fi
version=`src/bruce/scripts/gen_version -q`
echo Software version is $version
echo
# Always make a tarball, since that is required for building an RPM package.
make_tar $debug
if [ "$target" == "rpm" ] || [ "$target" == "rpm_noconfig" ]; then
make_rpm $debug $asan
fi