]> git.ipfire.org Git - thirdparty/freeswitch.git/blame - debian/util.sh
Add build-dep for mod_sangoma_codec
[thirdparty/freeswitch.git] / debian / util.sh
CommitLineData
4ce0f57a
TC
1#!/bin/bash
2##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
3##### Author: Travis Cross <tc@traviscross.com>
4
495dd7e5
TC
5set -e
6
38379a5f
TC
7ddir="."
8[ -n "${0%/*}" ] && ddir="${0%/*}"
0bab77bf
TC
9cd $ddir/../
10
11#### lib
6c754892 12
6e01f317
TC
13err () {
14 echo "$0 error: $1" >&2
15 exit 1
16}
17
15a67097
TC
18announce () {
19 cat >&2 <<EOF
20
21########################################################################
22## $1
23########################################################################
24
25EOF
26}
27
6e01f317
TC
28xread () {
29 local xIFS="$IFS"
30 IFS=''
31 read $@
32 local ret=$?
33 IFS="$xIFS"
34 return $ret
35}
36
0bab77bf
TC
37mk_dver () { echo "$1" | sed -e 's/-/~/g'; }
38mk_uver () { echo "$1" | sed -e 's/-.*$//' -e 's/~/-/'; }
39dsc_source () { dpkg-parsechangelog | grep '^Source:' | awk '{print $2}'; }
40dsc_ver () { dpkg-parsechangelog | grep '^Version:' | awk '{print $2}'; }
41up_ver () { mk_uver "$(dsc_ver)"; }
42dsc_base () { echo "$(dsc_source)_$(dsc_ver)"; }
43up_base () { echo "$(dsc_source)-$(up_ver)"; }
44
45find_distro () {
46 case "$1" in
47 experimental) echo "sid";;
48 unstable) echo "sid";;
4448d6b7
TC
49 testing) echo "jessie";;
50 stable) echo "wheezy";;
51 oldstable) echo "squeeze";;
0bab77bf
TC
52 *) echo "$1";;
53 esac
54}
55
56find_suite () {
57 case "$1" in
58 sid) echo "unstable";;
4448d6b7
TC
59 jessie) echo "testing";;
60 wheezy) echo "stable";;
61 squeeze) echo "oldstable";;
0bab77bf
TC
62 *) echo "$1";;
63 esac
64}
65
66#### debian/rules helpers
67
4ce0f57a 68create_dbg_pkgs () {
6c754892 69 for x in $ddir/*; do
4ce0f57a
TC
70 test ! -d $x && continue
71 test "$x" = "tmp" -o "$x" = "source" && continue
72 test ! "$x" = "${x%-dbg}" && continue
73 test ! -d $x/usr/lib/debug && continue
74 mkdir -p $x-dbg/usr/lib
75 mv $x/usr/lib/debug $x-dbg/usr/lib/
76 done
77}
78
18de2447
TC
79cwget () {
80 local url="$1" f="${1##*/}"
81 echo "fetching: $url to $f" >&2
82 if [ -n "$FS_FILES_DIR" ]; then
83 if ! [ -s "$FS_FILES_DIR/$f" ]; then
84 (cd $FS_FILES_DIR && wget -N "$url")
85 fi
86 cp -a $FS_FILES_DIR/$f .
87 else
88 wget -N "$url"
89 fi
90}
91
92getlib () {
0bab77bf
TC
93 local url="$1" f="${1##*/}"
94 cwget "$url"
95 tar -xv --no-same-owner --no-same-permissions -f "$f"
96 rm -f "$f" && mkdir -p $f && touch $f/.download-stamp
18de2447
TC
97}
98
18de2447 99getlibs () {
18de2447 100 # get pinned libraries
0bab77bf
TC
101 getlib http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-v1.8-latest.tgz
102 getlib http://files.freeswitch.org/downloads/libs/json-c-0.9.tar.gz
e525dc38 103 getlib http://files.freeswitch.org/downloads/libs/soundtouch-1.7.1.tar.gz
0bab77bf 104 getlib http://files.freeswitch.org/downloads/libs/flite-1.5.4-current.tar.bz2
57325714
BW
105 getlib http://files.freeswitch.org/downloads/libs/sphinxbase-0.8.tar.gz
106 getlib http://files.freeswitch.org/downloads/libs/pocketsphinx-0.8.tar.gz
0bab77bf
TC
107 getlib http://files.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz
108 getlib http://files.freeswitch.org/downloads/libs/celt-0.10.0.tar.gz
03c4014d 109 getlib http://files.freeswitch.org/downloads/libs/opus-1.1-p2.tar.gz
0bab77bf
TC
110 getlib http://files.freeswitch.org/downloads/libs/openldap-2.4.19.tar.gz
111 getlib http://download.zeromq.org/zeromq-2.1.9.tar.gz \
112 || getlib http://download.zeromq.org/historic/zeromq-2.1.9.tar.gz
113 getlib http://files.freeswitch.org/downloads/libs/freeradius-client-1.1.6.tar.gz
114 getlib http://files.freeswitch.org/downloads/libs/lame-3.98.4.tar.gz
115 getlib http://files.freeswitch.org/downloads/libs/libshout-2.2.2.tar.gz
116 getlib http://files.freeswitch.org/downloads/libs/mpg123-1.13.2.tar.gz
b7623326 117 getlib http://files.freeswitch.org/downloads/libs/v8-3.24.14.tar.bz2
18de2447
TC
118 # cleanup mongo
119 (
0bab77bf 120 cd mongo-cxx-driver-v1.8
18de2447
TC
121 rm -rf config.log .sconf_temp *Test *Example
122 find . -name "*.o" -exec rm -f {} \;
123 )
124}
125
0bab77bf
TC
126check_repo_clean () {
127 git diff-index --quiet --cached HEAD \
128 || err "uncommitted changes present"
129 git diff-files --quiet \
130 || err "unclean working tree"
131 git diff-index --quiet HEAD \
132 || err "unclean repository"
133 ! git ls-files --other --error-unmatch . >/dev/null 2>&1 \
134 || err "untracked files or build products present"
18de2447
TC
135}
136
b1682194 137get_last_release_ver () {
83125dad 138 grep -m1 -e '^AC_INIT' configure.ac \
b1682194
TC
139 | cut -d, -f2 \
140 | sed -e 's/\[//' -e 's/\]//' -e 's/ //g'
141}
142
143get_nightly_version () {
144 local commit="$(git rev-list -n1 --abbrev=10 --abbrev-commit HEAD)"
5fd7643a 145 echo "$(get_last_release_ver)+git~$(date -u '+%Y%m%dT%H%M%SZ')~$commit"
b1682194
TC
146}
147
53c24a93
TC
148get_nightly_revision_human () {
149 echo "git $(git rev-list -n1 --abbrev=7 --abbrev-commit HEAD) $(date -u '+%Y-%m-%d %H:%M:%SZ')"
150}
151
8d366f7f 152create_orig () {
d3cb7036 153 {
a5d696d5 154 set -e
d3cb7036 155 local OPTIND OPTARG
0a50536a
TC
156 local uver="" hrev="" bundle_deps=false modules_list="" zl=9e
157 while getopts 'bm:nv:z:' o "$@"; do
d3cb7036
TC
158 case "$o" in
159 b) bundle_deps=true;;
0a50536a 160 m) modules_list="$OPTARG";;
d3cb7036
TC
161 n) uver="nightly";;
162 v) uver="$OPTARG";;
163 z) zl="$OPTARG";;
164 esac
165 done
166 shift $(($OPTIND-1))
53c24a93
TC
167 if [ -z "$uver" ] || [ "$uver" = "nightly" ]; then
168 uver="$(get_nightly_version)"
169 hrev="$(get_nightly_revision_human)"
170 fi
d3cb7036
TC
171 local treeish="$1" dver="$(mk_dver "$uver")"
172 local orig="../freeswitch_$dver.orig.tar.xz"
173 [ -n "$treeish" ] || treeish="HEAD"
174 check_repo_clean
175 git reset --hard "$treeish"
176 mv .gitattributes .gitattributes.orig
0a50536a
TC
177 local -a args=(-e '\bdebian-ignore\b')
178 test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b')
179 grep .gitattributes.orig "${args[@]}" \
d3cb7036
TC
180 | while xread l; do
181 echo "$l export-ignore" >> .gitattributes
182 done
183 if $bundle_deps; then
184 (cd libs && getlibs)
185 git add -f libs
186 fi
83125dad 187 ./build/set-fs-version.sh "$uver" "$hrev" && git add configure.ac
d18a7ffa 188 echo "$uver" > .version && git add -f .version
d3cb7036
TC
189 git commit --allow-empty -m "nightly v$uver"
190 git archive -v \
191 --worktree-attributes \
192 --format=tar \
193 --prefix=freeswitch-$uver/ \
194 HEAD \
195 | xz -c -${zl}v > $orig
196 mv .gitattributes.orig .gitattributes
197 git reset --hard HEAD^ && git clean -fdx
198 } 1>&2
0bab77bf 199 echo $orig
8d366f7f
TC
200}
201
2365f41f
TC
202set_modules_quicktest () {
203 cat > debian/modules.conf <<EOF
204applications/mod_commands
205EOF
206}
207
8d366f7f 208create_dsc () {
d3cb7036 209 {
a5d696d5 210 set -e
e364450a
TC
211 local OPTIND OPTARG modules_conf="" modules_list="" speed="normal" suite_postfix="" suite_postfix_p=false zl=9
212 while getopts 'f:m:s:u:z:' o "$@"; do
2365f41f 213 case "$o" in
f840eecd 214 f) modules_conf="$OPTARG";;
2365f41f 215 m) modules_list="$OPTARG";;
25287f38 216 s) speed="$OPTARG";;
e364450a 217 u) suite_postfix="$OPTARG"; suite_postfix_p=true; ;;
c8df04fc 218 z) zl="$OPTARG";;
2365f41f
TC
219 esac
220 done
221 shift $(($OPTIND-1))
d3cb7036
TC
222 local distro="$(find_distro $1)" orig="$2"
223 local suite="$(find_suite $distro)"
224 local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')"
225 local dver="${orig_ver}-1~${distro}+1"
e364450a 226 $suite_postfix_p && { suite="${distro}${suite_postfix}"; }
d3cb7036
TC
227 [ -x "$(which dch)" ] \
228 || err "package devscripts isn't installed"
f840eecd
TC
229 if [ -n "$modules_conf" ]; then
230 cp $modules_conf debian/modules.conf
231 fi
0a50536a 232 local bootstrap_args=""
2365f41f 233 if [ -n "$modules_list" ]; then
0a50536a
TC
234 if [ "$modules_list" = "non-dfsg" ]; then
235 bootstrap_args="-mnon-dfsg"
236 else set_modules_${modules_list}; fi
2365f41f 237 fi
0a50536a 238 (cd debian && ./bootstrap.sh -c $distro $bootstrap_args)
25287f38
TC
239 case "$speed" in
240 paranoid) sed -i ./debian/rules \
241 -e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;;
242 reckless) sed -i ./debian/rules \
243 -e '/\.stamp-build:/{:l2 n; /make/{s/$/ -j/; :l3 n; b l3}; b l2};' ;;
244 esac
c8df04fc 245 [ "$zl" -ge "1" ] || zl=1
25287f38 246 git add debian/rules
d3cb7036
TC
247 dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build."
248 git add debian/changelog && git commit -m "nightly v$orig_ver"
c8df04fc 249 dpkg-source -i.* -Zxz -z${zl} -b .
d3cb7036
TC
250 dpkg-genchanges -S > ../$(dsc_base)_source.changes
251 local dsc="../$(dsc_base).dsc"
252 git reset --hard HEAD^ && git clean -fdx
253 } 1>&2
0bab77bf 254 echo $dsc
8d366f7f
TC
255}
256
8fb3f54c
TC
257fmt_debug_hook () {
258 cat <<'EOF'
259#!/bin/bash
260export debian_chroot="cow"
261cd /tmp/buildd/*/debian/..
262/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
263EOF
264}
265
0bab77bf 266build_debs () {
d3cb7036 267 {
a5d696d5 268 set -e
cf68dc73 269 local OPTIND OPTARG debug_hook=false hookdir="" cow_build_opts=""
ed9ff6e3 270 while getopts 'Bbd' o "$@"; do
d3cb7036 271 case "$o" in
cf68dc73 272 B) cow_build_opts="--debbuildopts '-B'";;
ed9ff6e3 273 b) cow_build_opts="--debbuildopts '-b'";;
d3cb7036
TC
274 d) debug_hook=true;;
275 esac
276 done
277 shift $(($OPTIND-1))
278 local distro="$(find_distro $1)" dsc="$2" arch="$3"
279 if [ -z "$distro" ] || [ "$distro" = "auto" ]; then
280 if ! (echo "$dsc" | grep -e '-[0-9]*~[a-z]*+[0-9]*'); then
281 err "no distro specified or found"
282 fi
283 local x="$(echo $dsc | sed -e 's/^[^-]*-[0-9]*~//' -e 's/+[^+]*$//')"
284 distro="$(find_distro $x)"
0bab77bf 285 fi
d3cb7036
TC
286 [ -n "$arch" ] || arch="$(dpkg-architecture | grep '^DEB_BUILD_ARCH=' | cut -d'=' -f2)"
287 [ -x "$(which cowbuilder)" ] \
288 || err "package cowbuilder isn't installed"
289 local cow_img=/var/cache/pbuilder/base-$distro-$arch.cow
290 cow () {
291 cowbuilder "$@" \
292 --distribution $distro \
293 --architecture $arch \
294 --basepath $cow_img
295 }
296 if ! [ -d $cow_img ]; then
297 announce "Creating base $distro-$arch image..."
afb4a200 298 local x=30
8a4a8f6f 299 while ! cow --create; do
afb4a200 300 [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
8a4a8f6f 301 done
d3cb7036
TC
302 fi
303 announce "Updating base $distro-$arch image..."
afb4a200 304 local x=30
4ccdc1de 305 while ! cow --update --override-config; do
afb4a200 306 [ $x -lt 1 ] && break; sleep 120; x=$((x-1))
9b79922a 307 done
d3cb7036
TC
308 announce "Building $distro-$arch DEBs from $dsc..."
309 if $debug_hook; then
310 mkdir -p .hooks
311 fmt_debug_hook > .hooks/C10shell
312 chmod +x .hooks/C10shell
313 hookdir=$(pwd)/.hooks
314 fi
b4816ae9
TC
315 cow --build $dsc \
316 --hookdir "$hookdir" \
992e0566
TC
317 --buildresult ../ \
318 $cow_build_opts
d3cb7036 319 } 1>&2
337c9d43 320 echo ${dsc%.dsc}_${arch}.changes
15a67097
TC
321}
322
496b9a9c
TC
323build_all () {
324 local OPTIND OPTARG
671fc3bc 325 local orig_opts="" dsc_opts="" deb_opts="" modlist=""
383b77a1 326 local archs="" distros="" orig="" depinst=false par=false
e364450a 327 while getopts 'a:bc:df:ijl:m:no:s:u:v:z:' o "$@"; do
496b9a9c
TC
328 case "$o" in
329 a) archs="$archs $OPTARG";;
330 b) orig_opts="$orig_opts -b";;
331 c) distros="$distros $OPTARG";;
332 d) deb_opts="$deb_opts -d";;
f840eecd 333 f) dsc_opts="$dsc_opts -f$OPTARG";;
383b77a1 334 i) depinst=true;;
6679e3f5 335 j) par=true;;
671fc3bc 336 l) modlist="$OPTARG";;
0a50536a 337 m) orig_opts="$orig_opts -m$OPTARG"; dsc_opts="$dsc_opts -m$OPTARG";;
e38f0a1b 338 n) orig_opts="$orig_opts -n";;
f79a37a3 339 o) orig="$OPTARG";;
25287f38 340 s) dsc_opts="$dsc_opts -s$OPTARG";;
e364450a 341 u) dsc_opts="$dsc_opts -u$OPTARG";;
496b9a9c 342 v) orig_opts="$orig_opts -v$OPTARG";;
c8df04fc 343 z) orig_opts="$orig_opts -z$OPTARG"; dsc_opts="$dsc_opts -z$OPTARG";;
496b9a9c
TC
344 esac
345 done
346 shift $(($OPTIND-1))
347 [ -n "$archs" ] || archs="amd64 i386"
3cad3168 348 [ -n "$distros" ] || distros="sid jessie wheezy"
383b77a1
TC
349 ! $depinst || aptitude install -y \
350 rsync git less cowbuilder ccache \
351 devscripts equivs build-essential
f79a37a3 352 [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
671fc3bc
TC
353 if [ -n "$modlist" ]; then
354 local modtmp="$(mktemp /tmp/modules-XXXXXXXXXX.conf)"
355 > $modtmp
356 for m in "$modlist"; do printf '%s\n' "$m" >> $modtmp; done
357 dsc_opts="$dsc_opts -f${modtmp}"; fi
358 [ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
6679e3f5
TC
359 mkdir -p ../log
360 > ../log/changes
361 echo; echo; echo; echo
73b34cb3 362 trap 'echo "Killing children...">&2; for x in $(jobs -p); do kill $x; done' EXIT
496b9a9c 363 if [ "${orig:0:2}" = ".." ]; then
9a0032e9 364 echo "true" > ../log/builds-ok
496b9a9c 365 for distro in $distros; do
6679e3f5
TC
366 echo "Creating $distro dsc..." >&2
367 local dsc="$(create_dsc $dsc_opts $distro $orig 2>../log/$distro | tail -n1)"
368 echo "Done creating $distro dsc." >&2
496b9a9c 369 if [ "${dsc:0:2}" = ".." ]; then
ed9ff6e3 370 local lopts="-b"
496b9a9c 371 for arch in $archs; do
6679e3f5
TC
372 {
373 echo "Building $distro-$arch debs..." >&2
cf68dc73 374 local changes="$(build_debs $lopts $deb_opts $distro $dsc $arch 2>../log/$distro-$arch | tail -n1)"
6679e3f5
TC
375 echo "Done building $distro-$arch debs." >&2
376 if [ "${changes:0:2}" = ".." ]; then
377 echo "$changes" >> ../log/changes
9a0032e9
TC
378 else
379 echo "false" > ../log/builds-ok
6679e3f5
TC
380 fi
381 } &
382 $par || wait
c15613e0 383 lopts="-B"
496b9a9c
TC
384 done
385 fi
386 done
6679e3f5 387 ! $par || wait
496b9a9c 388 fi
671fc3bc 389 [ -z "$modlist" ] || rm -f $modtmp
73b34cb3 390 trap - EXIT
6679e3f5 391 cat ../log/changes
9a0032e9 392 test "$(cat ../log/builds-ok)" = true || exit 1
496b9a9c
TC
393}
394
f3c2180c
TC
395usage () {
396 cat >&2 <<EOF
397$0 [opts] [cmd] [cmd-opts]
398
399options:
400
401 -d Enable debugging mode.
402
403commands:
404
405 archive-orig
406
407 build-all
408
860d2aca
TC
409 [ This must be run as root! ]
410
f3c2180c
TC
411 -a Specify architectures
412 -b Bundle downloaded libraries in source package
413 -c Specify distributions
414 -d Enable cowbuilder debug hook
f840eecd
TC
415 -f <modules.conf>
416 Build only modules listed in this file
383b77a1 417 -i Auto install build deps on host system
f3c2180c 418 -j Build debs in parallel
671fc3bc 419 -l <modules>
0a50536a 420 -m [ quicktest | non-dfsg ]
f3c2180c 421 Choose custom list of modules to build
e38f0a1b 422 -n Nightly build
f79a37a3
TC
423 -o <orig-file>
424 Specify existing .orig.tar.xz file
f3c2180c
TC
425 -s [ paranoid | reckless ]
426 Set FS bootstrap/build -j flags
e364450a
TC
427 -u <suite-postfix>
428 Specify a custom suite postfix
f3c2180c
TC
429 -v Set version
430 -z Set compression level
431
432 build-debs <distro> <dsc-file> <architecture>
433
860d2aca
TC
434 [ This must be run as root! ]
435
cf68dc73 436 -B Binary architecture-dependent build
ed9ff6e3 437 -b Binary-only build
f3c2180c
TC
438 -d Enable cowbuilder debug hook
439
440 create-dbg-pkgs
441
442 create-dsc <distro> <orig-file>
443
f840eecd
TC
444 -f <modules.conf>
445 Build only modules listed in this file
0a50536a 446 -m [ quicktest | non-dfsg ]
f3c2180c
TC
447 Choose custom list of modules to build
448 -s [ paranoid | reckless ]
449 Set FS bootstrap/build -j flags
e364450a
TC
450 -u <suite-postfix>
451 Specify a custom suite postfix
c8df04fc 452 -z Set compression level
f3c2180c
TC
453
454 create-orig <treeish>
455
456 -b Bundle downloaded libraries in source package
0a50536a
TC
457 -m [ quicktest | non-dfsg ]
458 Choose custom list of modules to build
f3c2180c
TC
459 -n Nightly build
460 -v Set version
461 -z Set compression level
462
463EOF
464 exit 1
465}
466
467while getopts 'dh' o "$@"; do
0bab77bf
TC
468 case "$o" in
469 d) set -vx;;
f3c2180c 470 h) usage;;
0bab77bf
TC
471 esac
472done
473shift $(($OPTIND-1))
15a67097 474
f3c2180c 475cmd="$1"; [ -n "$cmd" ] || usage
b281e134
TC
476shift
477case "$cmd" in
0bab77bf 478 archive-orig) archive_orig "$@" ;;
496b9a9c 479 build-all) build_all "$@" ;;
0bab77bf 480 build-debs) build_debs "$@" ;;
b281e134 481 create-dbg-pkgs) create_dbg_pkgs ;;
8d366f7f 482 create-dsc) create_dsc "$@" ;;
18de2447 483 create-orig) create_orig "$@" ;;
f3c2180c 484 *) usage ;;
b281e134 485esac