af5d0a3b886cc986e123698a8847f6761a51e067
[debian/amanda] / packaging / sun-pkg / buildpkg
1 #!/bin/sh
2 # This is useful for debugging
3 #set -x
4
5 #### CHECKS
6 if [ ! -f common-src/amanda.h ]; then
7     echo "Error: 'buildpkg' must be run from the root of an otherwise unused amanda source"
8     echo " directory." >&2
9     exit 1
10 fi
11
12 if [ ! -f configure ]; then
13     echo "Error: The source directory has not been autogen'd -- please download a source" 
14     echo " distribution tarball or run ./autogen.  You will need autoconf, automake,"
15     echo " and libtool to run autogen (but not to compile from a distribution tarball)."
16     exit 1
17 fi
18
19 # Until we get package revisioning in community.
20 [ -f "PKG_REV" ] || echo "1" > PKG_REV
21
22 pkg_root=packaging/sun-pkg
23 get_version() {
24     # Get our version using substitute.pl
25     echo "%%VERSION%%" > ${pkg_root}/version.src
26     /opt/csw/bin/perl packaging/common/substitute.pl ${pkg_root}/version.src ${pkg_root}/version || exit 1
27     VERSION=`cat ${pkg_root}/version`
28     rm ${pkg_root}/version.src ${pkg_root}/version || exit 1
29 }
30
31 do_substitution() {
32     file_list="client/pkginfo \
33         client/preinstall \
34         client/postinstall \
35         client/postremove \
36         server/pkginfo \
37         server/preinstall \
38         server/postinstall \
39         server/postremove"
40     for file in ${file_list}; do
41         /opt/csw/bin/perl packaging/common/substitute.pl \
42             ${pkg_root}/${file}.src \
43             ${pkg_root}/${file} || exit 1
44     done
45     chmod ug+x ${pkg_root}/*/pre* ${pkg_root}/*/post*
46 }
47
48 do_build() {
49     # Run for each server and client package.  .pkg files don't get whacked.
50     # $1 must be "client" or "server"
51     [ x"$1" = x"client" ] || [ x"$1" = x"server" ] || \
52         { echo "client or server not given" && exit 1; }
53     rm -rf ${INSTALL_DEST} ${PKG_DEST}
54     mkdir ${INSTALL_DEST} ${PKG_DEST} || exit 1
55     make distclean
56     echo "Running configure.."
57     CONF="$CONF \
58         STAR=/opt/csw/bin/star \
59         GNUTAR=/opt/csw/bin/gtar \
60         --quiet \
61         --with-user=amandabackup \
62         --with-group=disk \
63         --prefix=/${PREFIX} \
64         --exec-prefix=/${PREFIX} \
65         --sbindir=/${PREFIX}/sbin \
66         --sysconfdir=/${ETCDIR} \
67         --with-amandates=/${ETCDIR}/amandates \
68         --mandir=/${PREFIX}/share/man \
69         --with-amlibexecdir=/${amlibdir}/amanda \
70         --with-amperldir=/${amlibdir}/amanda/perl \
71         --localstatedir=/${LOCALSTATEDIR} \
72         --with-amdatadir=/${AMSTATEDIR} \
73         --with-gnutar-listdir=/${AMSTATEDIR}/gnutar-lists \
74         --with-index-server=localhost \
75         --with-tape-server=localhost \
76         --with-fqdn \
77         --with-bsd-security \
78         --with-bsdtcp-security \
79         --with-bsdudp-security \
80         --with-udpportrange=800,840 \
81         --with-tcpportrange=11000,11040 \
82         --with-low-tcpportrange=800,840 \
83         --with-ssh-security \
84         --with-debugging=/${DBGDIR} \
85         --with-assertions \
86         --with-readline \
87         --disable-installperms \
88         --disable-syntax-checks \
89         --disable-static"
90     
91     # PKG_CONFIG_PATH was exported, so is in the environment.
92     ./configure CFLAGS="${CFLAGS}" \
93         CPPFLAGS="${CPPFLAGS}" \
94         LDFLAGS="${LDFLAGS}" \
95         GLIB_CFLAGS="${GLIB_CFLAGS}" \
96         GLIB_LIBS="${GLIB_LIBS}" \
97         GLIB_GENMARSHAL=glib-genmarshal \
98         GOBJECT_QUERY=gobject-query \
99         GLIB_MKENUMS=glib-mkenums \
100         ${CONF} || exit 1
101
102     echo "Building.."
103
104     # rpcgen should be run natively on solaris, linux generated XDR stubs
105     # are not compatible. Specially when being compiled in 64 bit mode.
106     # Ideally this should be part of Make.
107
108     (cd ndmp-src;rpcgen ndmp0.x;rpcgen ndmp2.x;rpcgen ndmp3.x;rpcgen ndmp4.x; rpcgen ndmp9.x)
109
110     make || exit 1
111     make DESTDIR=${INSTALL_DEST} install || exit 1
112
113     # the gnulib makefiles create $amlibdir/charset.alias in hopes of "merging"
114     # it with a similar file from other applications.  This doesn't work with
115     # DESTDIR, and anyway Amanda doesn't need this kind of fanciness because it
116     # doesn't really use gettext.  So we just kill the file.  See bug 10955 for
117     # more detail.
118     rm -f ${INSTALL_DEST}/${amlibdir}/charset.alias
119
120     echo "Amanda Enterprise Edition - version ${VERSION}" > ${INSTALL_DEST}/${PREFIX}/amanda-release || exit 1
121 }
122
123 do_package() {
124     # First parameter is the subpkg, in all lower case.
125     subpkg=${1}
126     gnu_triplet=`/bin/sh ${src_dir}/config/config.guess`
127     # Some but not all solaris packages have arch-plat-os dependent depend
128     # files.
129     if [ -f ${src_dir}/${pkg_root}/${subpkg}/depend-${gnu_triplet} ]; then
130         # Move the arch-plat-os specific depend file to "depend"
131         mv ${src_dir}/${pkg_root}/${subpkg}/depend-${gnu_triplet} \
132            ${src_dir}/${pkg_root}/${subpkg}/depend || exit 1
133         # Delete extra depend-${gnu_triplet} files
134         rm ${src_dir}/${pkg_root}/${subpkg}/depend-*
135     fi
136     cp ${src_dir}/${pkg_root}/${subpkg}/* ${PKG_DEST} || exit 1
137     cd ${INSTALL_DEST} || exit 1
138     
139     # amanda does not create /etc/amanda 
140     mkdir -p ${AMSTATEDIR} || exit 1
141     mkdir -p ${ETCDIR}/amanda || exit 1
142
143     # Add the contents of 'pkgproto' along with all installed files to
144     # 'prototype'.  pkgproto will generate file list for provided base
145     # directories including the base dir. Including base dir in the pkg should
146     # be avoided as the pkg installation will try to alter the base directory
147     # permissions and ownership per pkg settings if included.
148     cat "${PKG_DEST}/pkgproto" \
149         >> ${PKG_DEST}/prototype || exit 1
150     pkgproto $PREFIX >> ${PKG_DEST}/prototype || exit 1
151
152     # Using --disable-installperms creates installperms.sh, which this bit of
153     # perl will merge into the prototype.  Note that this perl script is
154     # perl-5.4 compatible
155     cat > "${src_dir}/process_proto" <<'EOF'
156 # make a hash from installperms
157 open(INSTPERM, "<" . shift @ARGV) or die("open installperms.sh: $!");
158 my %installperms = map {
159     my ($u, $g, $m, $fn) = ($_ =~ /^installperm "([^:"]+)(?:([^:"]+))?" "([^"]*)" "(.*)"/);
160     $fn =~ s{^/}{}; # pkgproto has files without the leading slash
161     ($fn, [ $u, $g, $m ]);
162 } <INSTPERM>;
163 # set user/group/mode from installperms, defaulting to amandabackup:disk
164 open(PROTO, "<" . shift @ARGV) or die("open proto: $!");
165 for my $line (<PROTO>) {
166     if ($line !~ /^[df]/) {
167         print $line;
168         next;
169     }
170     my ($type, $class, $file, $mode, $user, $group) = split(/ /, $line);
171     # default to amandabackup:disk, without changing mode
172     ($user, $group) = ( "amandabackup", "disk" );
173     if (exists $installperms{$file}) {
174         ($u, $g, $m) = @{$installperms{$file}};
175         $user = $u if $u;
176         $group = $g if $g;
177         $mode = $m if $m;
178     }
179     print "$type $class $file $mode $user $group\n";
180 }
181 EOF
182
183     perl "${src_dir}/process_proto" \
184         "${src_dir}/installperms.sh" \
185         "${PKG_DEST}/prototype" \
186         > "${PKG_DEST}/prototype~" || exit 1
187     mv "${PKG_DEST}/prototype~" "${PKG_DEST}/prototype"
188
189     # Look for installed files in ${INSTALL_DEST}, send package to ${PKG_DEST}
190     pkgmk -r ${INSTALL_DEST} -o -f ${PKG_DEST}/prototype -d ${PKG_DEST} \
191         || exit 1
192     # pkgtrans puts the package back in our src_dir, where I would expected
193     # it, and "translates" it into a .pkg file at the same time.
194
195     pkgtrans -s ${PKG_DEST} ${src_dir}/AMANamanda-${subpkg}-${VERSION}-${gnu_triplet}.pkg<<EOF
196
197 EOF
198     cd ${src_dir} || exit 1
199
200 }
201
202 src_dir=`pwd`
203
204 get_version
205 do_substitution
206
207 PKG_TMP=`pwd`/pkg_${VERSION}; export PKG_TMP
208 INSTALL_DEST=${PKG_TMP}/install; export INSTALL_DEST
209 PKG_DEST=${PKG_TMP}/pkg; export PKG_DEST
210
211 # Explanation of solaris paths:
212 # /opt/SUNWspro/*: Sun compiler, NOT USED FOR PACKAGING.
213 # /opt/csw/*: blastwave.
214 # /usr/ccs/*: sun compilation tools (ld, lex, yacc)
215 # /usr/sfw/*: SunFreeware, sometimes. (solaris 10)
216 # /usr/local/*: SunFreeware, othertimes. (solaris 8)
217
218 # Not Absolute!  Remember to prefix a "/" except in pkgproto.
219 # sparc or intel
220 arch=`uname -p`
221 # 5.8 or 5.10
222 os_rel=`uname -r`
223
224 rm -rf ${PKG_TMP}
225 mkdir ${PKG_TMP} || exit 1
226
227 PATH=/opt/csw/bin:/usr/bin:/usr/sbin:/usr/ccs/bin;export PATH
228 # Compile 32bit because csw perl is 32bit and native is too old.
229 CFLAGS="-O2 -pipe -m32"; export CFLAGS
230 CPPFLAGS="-I/opt/csw/include"; export CPPFLAGS
231 PREFIX=opt/amanda; export PREFIX # Not absolute.  Pkgprot needs this.
232 amlibdir=${PREFIX}/lib     # Not absolute
233 LOCALSTATEDIR=var; export LOCALSTATEDIR
234 AMSTATEDIR=${LOCALSTATEDIR}/lib/amanda; export AMSTATEDIR
235 ETCDIR=etc; export ETCDIR
236 DBGDIR=${LOCALSTATEDIR}/log; export DBGDIR
237 # Each client and server and platform combination gets different compile options
238 if [ "x${1}" = "xclient" -o "x${1}" = "x" ]; then
239     CC=/usr/sfw/bin/gcc
240     # Variables with spaces must be entered on the configure line separate from
241     # CONF to maintain quoting.
242     LDFLAGS="-L/usr/lib -R/usr/lib \
243         -L/opt/csw/lib -R/opt/csw/lib \
244         -Wl,-z,ignore"; export LDFLAGS
245     PKG_CONFIG_PATH="/usr/lib/pkgconfig"; export PKG_CONFIG_PATH
246     if [ "x$arch" = "xsparc" -a "x$os_rel" = "x5.10" ]; then
247         # Use explicit flags for GLIB, because pkgconfig provides flags
248         # for SunStudio compiler (not compatible with gcc).
249         GLIB_CFLAGS="-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"; export GLIB_CFLAGS
250         GLIB_LIBS="-lglib-2.0 -lgobject-2.0 -lgthread-2.0"; export GLIB_LIBS
251     elif [ "x$arch" = "xi386" -a "x$os_rel" = "x5.10" ]; then
252         GLIB_CFLAGS="-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"; export GLIB_CFLAGS
253     elif [ "x$arch" = "xsparc" -a "x$os_rel" = "x5.8" ]; then
254         # CSW glib2.0 flags for gcc.  CSW compiles with Sunstudio, so some
255         # flags may not work
256         GLIB_CFLAGS="-I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include"; export GLIB_CFLAGS
257         GLIB_LIBS="-lglib-2.0 -lintl -lgobject-2.0 -lgthread-2.0"; export GLIB_LIBS
258         CC="/usr/local/bin/gcc"
259     fi
260     CONF="--with-amlibdir=/${amlibdir} \
261         --without-server \
262         --disable-s3-device \
263         CC=$CC \
264         PERL=/opt/csw/bin/perl"; export CONF
265
266     do_build "client"
267     do_package "client"
268 fi
269
270 if [ "x${1}" = "xserver"  -o "x${1}" = "x" ]; then
271     LDFLAGS="-L/usr/lib -R/usr/lib \
272         -L/opt/csw/lib -R/opt/csw/lib \
273         -L/usr/sfw/lib \
274         -Wl,-z,ignore"; export LDFLAGS
275     PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/opt/csw/lib/pkgconfig"; export PKG_CONFIG_PATH
276     if [ "x$arch" = "xsparc" -a "x$os_rel" = "x5.10" ]; then
277         # Use explicit flags for GLIB, because pkgconfig provides flags
278         # for SunStudio compiler (not compatible with gcc).
279         GLIB_CFLAGS="-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"; export GLIB_CFLAGS
280         GLIB_LIBS="-lglib-2.0 -lgobject-2.0 -lgthread-2.0"; export GLIB_LIBS
281     elif [ "x$arch" = "xi386" -a "x$os_rel" = "x5.10" ]; then
282         GLIB_CFLAGS="-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"; export GLIB_CFLAGS
283         GLIB_LIBS="-lglib-2.0 -lgobject-2.0 -lgthread-2.0"; export GLIB_LIBS
284     elif [ "x$arch" = "xsparc" -a "x$os_rel" = "x5.8" ]; then
285         msg="We don't support server on Solaris 5.8."
286         # if we were run with no arguments, then this is not an error, just a warning
287         if [ "x${1}" = "x" ]; then
288             echo "Note: $msg"
289             exit 0
290         else
291             echo "Error: $msg"
292             exit 1
293         fi
294     fi
295     CONF="--with-amlibdir=/${amlibdir} \
296         --enable-s3-device \
297         CC=/usr/sfw/bin/gcc \
298         PERL=/opt/csw/bin/perl \
299         MTX=/opt/csw/sbin/mtx" ; export CONF
300
301     do_build "server"
302     do_package "server"
303 fi