forked from BRL-CAD/brlcad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_rpm.sh
305 lines (256 loc) · 8.86 KB
/
make_rpm.sh
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/bin/sh
# M A K E _ R P M . S H
# BRL-CAD
#
# Copyright (c) 2005-2022 United States Government as represented by
# the U.S. Army Research Laboratory.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###
set -e
ferror(){
echo "=========================================================="
echo $1
echo $2
echo "=========================================================="
exit 1
}
# test if in project root
if test ! -f misc/debian/control ; then
ferror "\"make_rpm.sh\" should be run from project root directory." "Exiting..."
fi
# get distribution name
DNAME=""
fdist(){
if test `cat /etc/*-release | grep -i "$1" | wc -l` -gt 0 ;then
DNAME="$1"
fi
}
fdist fedora
fdist openSUSE
if test "$DNAME" = "" ;then
ferror "Only \"fedora\" and \"openSUSE\" supported at this time" "Exiting..."
fi
# check needed packages
E=0
if test ! -x "`which rpm 2>/dev/null`" ; then
ferror "Missing \"rpm\" command" "Exiting..."
fi
fcheck(){
if ! rpm -q $1 >/dev/null 2>&1 ; then
echo "* Missing $1..."
LLIST=$LLIST" "$1
E=1
else
echo "Found package $1..."
fi
}
if test "$DNAME" = "fedora" ;then
fcheck rpm-build
fcheck fakeroot
fcheck gcc-c++
fcheck make
fcheck cmake
fcheck sed
fcheck bison
fcheck flex
fcheck libXi-devel
fcheck libxslt
fcheck mesa-libGLU-devel
fcheck pango-devel
fi
if test "$DNAME" = "openSUSE" ;then
fcheck rpm-build
fcheck fakeroot
fcheck gcc-c++
fcheck make
fcheck cmake
fcheck sed
fcheck bison
fcheck flex
fcheck libXi-devel
fcheck libxslt1
fcheck Mesa-devel
fcheck pango-devel
fi
if [ $E -eq 1 ]; then
ferror "Mandatory to install these packages first:" "$LLIST"
fi
# set variables
BVERSION="`sed 's/[^0-9]//g' include/conf/MAJOR`.`sed 's/[^0-9]//g' include/conf/MINOR`.`sed 's/[^0-9]//g' include/conf/PATCH`"
TMPDIR="misc/$DNAME-tmp"
RELEASE="0"
if test `gcc -dumpmachine | grep -iE "i[3-6]86" | wc -l` -eq 1 ;then
ARCH="i386"
SARCH="i[3-6]86"
FARCH="x86-32"
elif test `gcc -dumpmachine | grep -iE "x86_64" | wc -l` -eq 1 ;then
ARCH=`uname -m`
SARCH=$ARCH
FARCH="x86-64"
else
ferror "Unknown architecture. \"`gcc -dumpmachine`\"" "Exiting..."
fi
NJOBS=`getconf _NPROCESSORS_ONLN`
if test ! $NJOBS -gt 0 2>/dev/null ;then
NJOBS=1
fi
# #
rm -Rf $TMPDIR
mkdir -p $TMPDIR/tmp
cp -Rf misc/debian/* $TMPDIR
# create "version" file
echo $BVERSION >$TMPDIR/version
# compile and install in tmp dir
cmake -DCMAKE_INSTALL_PREFIX=/usr/brlcad
make -j$NJOBS
fakeroot make install DESTDIR=`pwd`"/$TMPDIR/tmp"
# copy menu files and others
mkdir -p $TMPDIR/tmp/etc/profile.d
cp -f $TMPDIR/brlcad.sh $TMPDIR/tmp/etc/profile.d
mkdir -p $TMPDIR/tmp/etc/xdg/menus/applications-merged
cp -f $TMPDIR/brlcad.menu $TMPDIR/tmp/etc/xdg/menus/applications-merged
mkdir -p $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/archer.desktop $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/brlcad-db.desktop $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/brlcad-doc.desktop $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/brlcad-doc-mged.desktop $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/mged.desktop $TMPDIR/tmp/usr/share/applications
cp -f $TMPDIR/rtwizard.desktop $TMPDIR/tmp/usr/share/applications
mkdir -p $TMPDIR/tmp/usr/share/desktop-directories
cp -f $TMPDIR/brlcad.directory $TMPDIR/tmp/usr/share/desktop-directories
cp -f $TMPDIR/brlcad-doc.directory $TMPDIR/tmp/usr/share/desktop-directories
mkdir -p $TMPDIR/tmp/usr/share/mime/packages
cp -f $TMPDIR/brlcad.xml $TMPDIR/tmp/usr/share/mime/packages
mkdir -p $TMPDIR/tmp/usr/brlcad
cp -f $TMPDIR/version $TMPDIR/tmp/usr/brlcad
# copy icons
for I in 16x16 24x24 36x36 48x48 64x64 96x96 128x128 256x256
do
mkdir -p $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/archer.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/brlcad.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/brlcad-db.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/brlcad-doc.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/mged.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
cp -f $TMPDIR/icons/$I/rtwizard.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/apps
mkdir -p $TMPDIR/tmp/usr/share/icons/hicolor/$I/mimetypes
cp -f $TMPDIR/icons/$I/brlcad-v4.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/mimetypes
cp -f $TMPDIR/icons/$I/brlcad-v5.png $TMPDIR/tmp/usr/share/icons/hicolor/$I/mimetypes
done
#Create brlcad.spec file
echo -e 'Name: brlcad
Version: '$BVERSION'
Release: '$RELEASE'
Summary: BRL-CAD open source solid modeling
Group: Productivity/Graphics/CAD
License: LGPL, BSD
URL: http://brlcad.org
Packager: Jordi Sayol <[email protected]>
ExclusiveArch: '$ARCH'
Provides: brlcad = '$BVERSION'-'$RELEASE', brlcad('$FARCH') = '$BVERSION'-'$RELEASE > $TMPDIR/brlcad.spec
if test "$DNAME" = "fedora" ;then
echo -e 'Requires: xorg-x11-fonts-ISO8859-1-75dpi' >> $TMPDIR/brlcad.spec
fi
echo -e '
%description
BRL-CAD is a powerful cross-platform Open Source combinatorial
Constructive Solid Geometry (CSG) solid modeling system that
includes interactive 3D solid geometry editing, high-performance
ray-tracing support for rendering and geometric analysis,
network-distributed framebuffer support, image and signal-processing
tools, path-tracing and photon mapping support for realistic image
synthesis, a system performance analysis benchmark suite, an embedded
scripting interface, and libraries for robust high-performance
geometric representation and analysis.
Homepage: http://brlcad.org
%post
file="/usr/share/applications/mimeapps.list"
section="Added Associations"
app="archer.desktop;mged.desktop;rtwizard.desktop;"
key_v4="application/brlcad-v4=$app"
key_v5="application/brlcad-v5=$app"
if [ ! -e $file ]
then
touch $file || :
fi
if [ -f $file ]
then
sed --follow-symlinks -i "/application\/brlcad-v[45]/d" $file || :
line=$(sed -n "/^\[$section\]/=" $file | tail -1) || :
if [ -z "$line" ]
then
echo "[$section]\n$key_v4\n$key_v5" >> $file || :
else
sed --follow-symlinks -i "$line a$key_v4\n$key_v5" $file || :
fi
fi
update-mime-database /usr/share/mime || :
update-desktop-database -q || :
gtk-update-icon-cache -qf /usr/share/icons/hicolor || :' >> $TMPDIR/brlcad.spec
if test "$DNAME" = "openSUSE" ;then
echo -e 'SuSEconfig || :' >> $TMPDIR/brlcad.spec
fi
echo -e '
%postun
file="/usr/share/applications/mimeapps.list"
section="Added Associations"
if [ -f $file ] && [ $1 -eq 0 ]
then
sed --follow-symlinks -i "/application\/brlcad-v[45]/d" $file
fi
if [ -f $file ] && [ -z "$(sed "/\[$section\]/d" $file)" ]
then
rm $file || :
fi
update-mime-database /usr/share/mime || :
update-desktop-database -q || :
gtk-update-icon-cache -qf /usr/share/icons/hicolor || :' >> $TMPDIR/brlcad.spec
if test "$DNAME" = "openSUSE" ;then
echo -e 'SuSEconfig || :' >> $TMPDIR/brlcad.spec
fi
echo -e '
%files' >> $TMPDIR/brlcad.spec
find $TMPDIR/tmp/usr/brlcad -type d | sed 's:'$TMPDIR'/tmp:%dir ":' | sed 's:$:":' >> $TMPDIR/brlcad.spec
find $TMPDIR/tmp/ ! -type d | sed 's:'$TMPDIR'/tmp:":' | sed 's:$:":' >> $TMPDIR/brlcad.spec
# create rpm file
fakeroot rpmbuild -vv --buildroot=`pwd`/$TMPDIR/tmp -bb --target $ARCH $TMPDIR/brlcad.spec > $TMPDIR/rpmbuild.log
RPMFILE=`grep "brlcad-$BVERSION-$RELEASE.$ARCH.rpm" "$TMPDIR/rpmbuild.log" | awk '{print $(NF)}'`
mv $RPMFILE ../brlcad-$BVERSION-$RELEASE.$DNAME.$ARCH.rpm
# #
rm -Rf $TMPDIR
# Local Variables:
# mode: sh
# tab-width: 8
# sh-indentation: 4
# sh-basic-offset: 4
# indent-tabs-mode: t
# End:
# ex: shiftwidth=4 tabstop=8