1#!/bin/sh
2
3set -u
4set -e
5trap onexit INT
6trap onexit TERM
7trap onexit EXIT
8
9TMPDIR=
10SUDO=
11
12onexit()
13{
14	if [ ! "$TMPDIR" = "" ]; then
15		$SUDO rm -rf $TMPDIR
16	fi
17}
18
19uid()
20{
21	id | cut -f2 -d = | cut -f1 -d \(;
22}
23
24makedeb()
25{
26	SUPPLEMENT=$1
27	DIRNAME=$PACKAGE_NAME
28
29	if [ $SUPPLEMENT = 1 ]; then
30		PACKAGE_NAME=$PACKAGE_NAME\32
31		DEBARCH=amd64
32	fi
33
34	umask 022
35	rm -f $PACKAGE_NAME\_$VERSION\_$DEBARCH.deb
36	TMPDIR=`mktemp -d /tmp/$PACKAGE_NAME-build.XXXXXX`
37	mkdir $TMPDIR/DEBIAN
38
39	if [ $SUPPLEMENT = 1 ]; then
40		make install DESTDIR=$TMPDIR bindir=/dummy/bin datadir=/dummy/data \
41			docdir=/dummy/doc includedir=/dummy/include mandir=/dummy/man
42		rm -f $TMPDIR$LIBDIR/*.la
43		rm -rf $TMPDIR/dummy
44	else
45		make install DESTDIR=$TMPDIR docdir=/usr/share/doc/$DIRNAME-$VERSION \
46			exampledir=/usr/share/doc/$DIRNAME-$VERSION
47		rm -f $TMPDIR$LIBDIR/*.la
48		if [ "$PREFIX" = "/opt/libjpeg-turbo" -a "$DOCDIR" = "/opt/libjpeg-turbo/doc" ]; then
49			ln -fs /usr/share/doc/$DIRNAME-$VERSION $TMPDIR$DOCDIR
50		fi
51	fi
52
53	SIZE=`du -s $TMPDIR | cut -f1`
54	(cat $SRCDIR/release/deb-control.tmpl | sed s/{__PKGNAME}/$PACKAGE_NAME/g \
55		| sed s/{__VERSION}/$VERSION/g | sed s/{__BUILD}/$BUILD/g \
56		| sed s/{__ARCH}/$DEBARCH/g | sed s/{__SIZE}/$SIZE/g \
57		> $TMPDIR/DEBIAN/control)
58
59
60	/sbin/ldconfig -n $TMPDIR$LIBDIR
61
62	$SUDO chown -Rh root:root $TMPDIR/*
63	dpkg -b $TMPDIR $PACKAGE_NAME\_$VERSION\_$DEBARCH.deb
64}
65
66PACKAGE_NAME=@PKGNAME@
67VERSION=@VERSION@
68BUILD=@BUILD@
69DEBARCH=@DEBARCH@
70SRCDIR=@abs_top_srcdir@
71PREFIX=%{__prefix}
72DOCDIR=%{__docdir}
73LIBDIR=%{__libdir}
74
75if [ ! `uid` -eq 0 ]; then
76	SUDO=sudo
77fi
78
79makedeb 0
80if [ "$DEBARCH" = "i386" ]; then makedeb 1; fi
81
82exit
83