/
dmd_deb.sh
executable file
·367 lines (284 loc) · 9.59 KB
/
dmd_deb.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/bin/bash
set -e -o pipefail
# error function
ferror(){
echo "==========================================================" >&2
echo $1 >&2
echo $2 >&2
echo "==========================================================" >&2
exit 1
}
# check if in debian like system
if test ! -f /etc/debian_version ; then
ferror "Refusing to build on a non-debian like system" "Exiting..."
fi
# show help
if test -z $1 ;then
echo "Script to create dmd v2 binary deb packages."
echo
echo "Usage:"
echo " dmd_deb.sh -v\"version\" -m\"model\" [-f]"
echo
echo "Options:"
echo " -v dmd version (mandatory)"
echo " -m 32 or 64 (mandatory)"
echo " -f force to rebuild"
exit
fi
# check if too many parameters
if test $# -gt 3 ;then
ferror "Too many arguments" "Exiting..."
fi
# check version parameter
if test "${1:0:2}" != "-v" ;then
ferror "Unknown first argument (-v)" "Exiting..."
else
VER="${1:2}"
if ! [[ $VER =~ ^[0-9]"."[0-9][0-9][0-9]$ || $VER =~ ^[0-9]"."[0-9][0-9][0-9]"."[0-9]+$ ]]
then
ferror "incorrect version number" "Exiting..."
elif test ${VER:0:1} -ne 2
then
ferror "for dmd v2 only" "Exiting..."
elif test ${VER:0:1}${VER:2:3} -lt 2063
then
ferror "dmd v2.063 and newer only" "Exiting..."
fi
fi
# check model parameter
if test $# -eq 1 ;then
ferror "Second argument is mandatory (-m[32-64])" "Exiting..."
elif test "$2" != "-m32" -a "$2" != "-m64" ;then
ferror "Unknown second argument '$2'" "Exiting..."
fi
# check forced build parameter
if test $# -eq 3 -a "$3" != "-f" ;then
ferror "Unknown third argument '$3'" "Exiting..."
fi
# needed commands function
E=0
fcheck(){
if ! `which $1 1>/dev/null 2>&1` ;then
LIST=$LIST" "$1
E=1
fi
}
fcheck gzip
fcheck unzip
fcheck curl
fcheck dpkg
fcheck dpkg-shlibdeps
fcheck fakeroot
fcheck dpkg-deb
if [ $E -eq 1 ]; then
ferror "Missing commands on Your system:" "$LIST"
fi
# assign variables
MAINTAINER="Jordi Sayol <g.sayol@yahoo.es>"
VERSION=${1:2}
MAJOR=0
MINOR=$(awk -F. '{ print $2 +0 }' <<<$VERSION)
RELEASE=$(awk -F. '{ print $3 +0 }' <<<$VERSION)
if [ "$REVISION" == "" ]
then
REVISION=0
fi
DESTDIR=`pwd`
TEMPDIR='/tmp/'`date +"%s%N"`
UNZIPDIR="dmd2"
DMDURL="http://ftp.digitalmars.com/dmd.$VERSION.zip"
if test "$2" = "-m64" ;then
ARCH="amd64"
elif test "$2" = "-m32" ;then
ARCH="i386"
fi
ZIPFILE=`basename $DMDURL`
DMDDIR="dmd_"$VERSION"-"$REVISION"_"$ARCH
DIR32="i386-linux-gnu"
DIR64="x86_64-linux-gnu"
DEBFILE=$DMDDIR".deb"
# check if destination deb file already exist
if `dpkg -I $DESTDIR"/"$DEBFILE &>/dev/null` && test "$3" != "-f" ;then
echo -e "$DEBFILE - already exist"
else
# remove bad formated deb file
rm -f $DESTDIR"/"$DEBFILE
# download zip file if not exist
if ! $(unzip -c $DESTDIR"/"$ZIPFILE &>/dev/null)
then
rm -f $DESTDIR"/"$ZIPFILE
echo "Downloading $ZIPFILE..."
curl -fo $DESTDIR"/"$ZIPFILE $DMDURL
fi
# create temp dir
mkdir -p $TEMPDIR"/"$DMDDIR
# unpacking sources
unzip -q $DESTDIR"/"$ZIPFILE -d $TEMPDIR
# add dmd-completion if present
if test -f `dirname $0`"/"dmd-completion ;then
mkdir -p $TEMPDIR"/"$DMDDIR"/etc/bash_completion.d/"
cp `dirname $0`"/"dmd-completion $TEMPDIR"/"$DMDDIR"/etc/bash_completion.d/dmd"
fi
# change unzipped folders and files permissions
chmod -R 0755 $TEMPDIR/$UNZIPDIR/*
chmod 0644 $(find -L $TEMPDIR/$UNZIPDIR ! -type d)
# switch to temp dir
pushd $TEMPDIR"/"$DMDDIR
# install binaries
mkdir -p usr/bin
if test "$ARCH" = "amd64" ;then
cp -f ../$UNZIPDIR/linux/bin64/{dmd,dumpobj,obj2asm,rdmd,ddemangle,dman} usr/bin
elif test "$ARCH" = "i386" ;then
cp -f ../$UNZIPDIR/linux/bin32/{dmd,dumpobj,obj2asm,rdmd,ddemangle,dman} usr/bin
fi
# install libraries
mkdir -p usr/lib
A_LIB="libphobos2.a"
SO_LIB="libphobos2.so"
SO_VERSION=$MAJOR.$MINOR
mkdir -p usr/lib/{$DIR32,$DIR64}
cp -f ../$UNZIPDIR/linux/lib32/$A_LIB usr/lib/$DIR32
cp -f ../$UNZIPDIR/linux/lib64/$A_LIB usr/lib/$DIR64
cp -f ../$UNZIPDIR/linux/lib32/$SO_LIB usr/lib/$DIR32/$SO_LIB.$SO_VERSION.$RELEASE
cp -f ../$UNZIPDIR/linux/lib64/$SO_LIB usr/lib/$DIR64/$SO_LIB.$SO_VERSION.$RELEASE
ln -s $SO_LIB.$SO_VERSION.$RELEASE usr/lib/$DIR32/$SO_LIB.$SO_VERSION
ln -s $SO_LIB.$SO_VERSION.$RELEASE usr/lib/$DIR64/$SO_LIB.$SO_VERSION
ln -s $SO_LIB.$SO_VERSION.$RELEASE usr/lib/$DIR32/$SO_LIB
ln -s $SO_LIB.$SO_VERSION.$RELEASE usr/lib/$DIR64/$SO_LIB
# install include
find ../$UNZIPDIR/src/ -iname "*.mak" -print0 -o -iname "*.ddoc" -print0 | xargs -0 rm -f
mkdir -p usr/include/dmd/druntime/
cp -Rf ../$UNZIPDIR/src/phobos/ usr/include/dmd
cp -Rf ../$UNZIPDIR/src/druntime/import/ usr/include/dmd/druntime
# install samples and HTML
mkdir -p usr/share/dmd/
cp -Rf ../$UNZIPDIR/samples/ usr/share/dmd
cp -Rf ../$UNZIPDIR/html/ usr/share/dmd
# remove unneeded files
find usr/share/dmd/html -regex ".*\.\(d\|c\|h\|lib\|obj\)" -print0 | xargs -0 rm -f
# install man pages
gzip ../$UNZIPDIR/man/man1/{dmd.1,dumpobj.1,obj2asm.1,rdmd.1}
gzip ../$UNZIPDIR/man/man5/dmd.conf.5
chmod 0644 ../$UNZIPDIR/man/man1/{dmd.1.gz,dumpobj.1.gz,obj2asm.1.gz,rdmd.1.gz}
chmod 0644 ../$UNZIPDIR/man/man5/dmd.conf.5.gz
mkdir -p usr/share/man/man1/
cp -f ../$UNZIPDIR/man/man1/{dmd.1.gz,dumpobj.1.gz,obj2asm.1.gz,rdmd.1.gz} usr/share/man/man1
mkdir -p usr/share/man/man5/
cp -f ../$UNZIPDIR/man/man5/dmd.conf.5.gz usr/share/man/man5
# generate copyright file
mkdir -p usr/share/doc/dmd
for I in ../$UNZIPDIR/license.txt ../$UNZIPDIR/src/druntime/LICENSE
do
sed 's/\r//;s/^[ \t]\+$//;s/^$/./;s/^/ /' $I > $I"_tmp"
if [ $(sed -n '/====/=' $I"_tmp") ]
then
sed -i '1,/====/d' $I"_tmp"
fi
sed -i ':a;$!{N;ba};s/^\( .\s*\n\)*\|\(\s*\n .\)*$//g' $I"_tmp"
done
echo 'Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Source: https://github.com/D-Programming-Language
Files: usr/bin/*
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
echo "License: Digital Mars License
Files: usr/lib/*
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
License: Boost License 1.0
Files: usr/include/*
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
License: Boost License 1.0
License: Digital Mars License' | sed 's/^\t//' > usr/share/doc/dmd/copyright
cat ../$UNZIPDIR/license.txt_tmp >> usr/share/doc/dmd/copyright
echo '
License: Boost License 1.0' | sed 's/^\t//' >> usr/share/doc/dmd/copyright
cat ../$UNZIPDIR/src/druntime/LICENSE_tmp >> usr/share/doc/dmd/copyright
# link changelog
ln -s ../../dmd/html/d/changelog.html usr/share/doc/dmd/
# create shlibs file
mkdir -p DEBIAN
echo "libphobos2 "$MAJOR.$MINOR" libphobos2-"$MINOR > DEBIAN/shlibs
# create /etc/dmd.conf file
mkdir -p etc/
echo -en ';
; dmd.conf file for dmd
;
; dmd will look for dmd.conf in the following sequence of directories:
; - current working directory
; - directory specified by the HOME environment variable
; - directory dmd resides in
; - /etc directory
;
; Names enclosed by %% are searched for in the existing environment and inserted
;
; The special name %@P% is replaced with the path to this file
;
[Environment]
DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import' | sed 's/^\t//' > etc/dmd.conf
if [ "$ARCH" = "amd64" ]; then
echo -n " -L-L/usr/lib/$DIR64 -L-L/usr/lib/$DIR32" >> etc/dmd.conf
elif [ "$ARCH" = "i386" ]; then
echo -n " -L-L/usr/lib/$DIR32 -L-L/usr/lib/$DIR64" >> etc/dmd.conf
fi
echo " -L--no-warn-search-mismatch -L--export-dynamic" >> etc/dmd.conf
# create conffiles file
mkdir -p DEBIAN
echo "/etc/dmd.conf" > DEBIAN/conffiles
if test -f etc/bash_completion.d/dmd ;then
echo "/etc/bash_completion.d/dmd" >> DEBIAN/conffiles
fi
# set deb package dependencies
DEPENDS="libc6, libc6-dev, gcc, gcc-multilib, libgcc1, libstdc++6, xdg-utils, libcurl3"
SUGGESTS="libcurl4-openssl-dev"
# create control file
echo -e 'Package: dmd
Version: '$VERSION-$REVISION'
Architecture: '$ARCH'
Maintainer: '$MAINTAINER'
Installed-Size: '$(du -ks usr/ | awk '{print $1}')'
Depends: '$DEPENDS'
Suggests: '$SUGGESTS'
Provides: dmd'$MINOR'
Section: devel
Priority: optional
Homepage: http://dlang.org/
Description: Digital Mars D Compiler
D is a systems programming language. Its focus is on combining the power and
high performance of C and C++ with the programmer productivity of modern
languages like Ruby and Python. Special attention is given to the needs of
quality assurance, documentation, management, portability and reliability.
.
The D language is statically typed and compiles directly to machine code.
It\047s multiparadigm, supporting many programming styles: imperative,
object oriented, functional, and metaprogramming. It\047s a member of the C
syntax family, and its appearance is very similar to that of C++.
.
It is not governed by a corporate agenda or any overarching theory of
programming. The needs and contributions of the D programming community form
the direction it goes.
.
Main designer: Walter Bright' | sed 's/^\t//' > DEBIAN/control
# create md5sum file
find usr/ -type f -print0 | xargs -0 md5sum > DEBIAN/md5sum
if test -d etc/ ;then
find etc/ -type f -print0 | xargs -0 md5sum >> DEBIAN/md5sum
fi
# create postinst
echo -e '#!/bin/sh
ldconfig || :' | sed 's/^\t//' > DEBIAN/postinst
# create postrm
echo -e '#!/bin/sh
ldconfig || :' | sed 's/^\t//' > DEBIAN/postrm
# change folders and files permissions
chmod -R 0755 *
chmod 0644 $(find -L . ! -type d)
chmod 0755 usr/bin/{dmd,dumpobj,obj2asm,rdmd,ddemangle,dman} DEBIAN/{postinst,postrm}
# create deb package
cd ..
fakeroot dpkg-deb -b $DMDDIR
# disable pushd
popd
# place deb package
mv $TEMPDIR"/"$DEBFILE $DESTDIR
# delete temp dir
rm -Rf $TEMPDIR
fi