#!/bin/sh
#
# Script to make a static version of the Bacula
#  File daemon and to copy it to the current
#  directory.
#
export LANG=C
topdir=$1

if test -e $topdir/src/filed/static-bacula-fd ; then
   if test ! -e bin/bacula-fd.conf ; then
      cp -f $topdir/src/filed/bacula-fd.conf bin/bacula-fd.conf
   fi
   cp -f $topdir/src/filed/static-bacula-fd bin/bacula-fd
else
   cwd=`pwd`
   cd $topdir
   make
   cd src/filed
   make static-bacula-fd 2>/dev/null >/dev/null
   cd $cwd       
   if test $? -ne 0 ; then
      echo " "
      echo "Build of static-bacula-fd failed."
      echo "This is most likely because you did not do a ./configure"
      echo "before running this script, or your build includes some"
      echo "options such as TLS that require static libraries that"
      echo "not loaded on your system.  I'm going to try to run a simplifed"
      echo "./configure in your Bacula source directory.  Please take note"
      echo "that your original configuration will be left changed."
      echo " "
      cd $topdir
      ./configure \
         --prefix=/usr \
         --sbindir=/usr/sbin \
         --sysconfdir=/etc/bacula \
         --with-scriptdir=/etc/bacula \
         --enable-smartalloc \
         --enable-client-only \
         --enable-static-fd
      make
      cd $cwd       
      if test ! -e bin/bacula-fd.conf ; then
         cp -f $topdir/src/filed/bacula-fd.conf bin/bacula-fd.conf
      fi
      cp -f $topdir/src/filed/static-bacula-fd bin/bacula-fd
      if test $? -ne 0 ; then
         echo " "
         echo "Build of static-bacula-fd failed. I give up."
      fi
   fi
   rm -f $topdir/src/filed/static-bacula-fd
fi
