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