#!/bin/sh

# $Header: /cvsroot/camram/build_tools/build_crm114,v 1.7 2003/07/06 17:51:43 s
egmentation Exp $
. ./shell_libs


echo
echo
echo
patchdir=`pwd`

# XXX 2 packages we still need to check for if OpenBSD
# -rw-r--r--   1445934 Jul  6 01:29 libiconv-1.8.tgz
# -rw-r--r--    527544 Jul  6 01:31 gettext-0.10.40p1.tgz
if [ X`uname` = XOpenBSD ]
then
   pkg_info | grep ^libiconv-1.8
   if [ $? -ne 0 ]
   then
       cd
       [ -d packages ] || mkdir packages
       cd ./packages
       [ -f libiconv-1.8.tgz ] || \
       sh_download ftp://ftp.esat.net/pub/OpenBSD/3.3/packages/i386/libiconv-1.
8.tgz
       sudo sh -c 'pkg_add -v libiconv-1.8.tgz'
   fi
   pkg_info | grep ^gettext-0.10.40p1
   if [ $? -ne 0 ]
   then
       cd
       [ -d packages ] || mkdir packages
       cd ./packages
       [ -f gettext-0.10.40p1.tgz ] || \
       sh_download ftp://ftp.esat.net/pub/OpenBSD/3.3/packages/i386/gettext-0.1
0.40p1.tgz
       sudo sh -c 'pkg_add -v gettext-0.10.40p1.tgz'
   fi
fi



crma -v
if [ 0 -eq $? ]
then
    echo Some form of crma exists.
    version=`crma -v 2>&1`
    echo crma has version :$version:
    if [ 2003-06-23-alpha = "$version" ]
    then
        echo Accepting crma $version
        shdie ...still a lot of crm configuration to do ...
    fi
fi

patch --version >/dev/null 2>/dev/null ||  shdie patch program needed

for dir in $1 . $HOME src crm114 END-OF-LIST
do
    if [ "$dir" = END-OF-LIST ]
    then
        echo
        echo "Usage: $0   [/directory/holding/tgz-files]"
        echo "crm114 tar.gz file not found"
        echo "Try download now [y/N] ?"
        sh_yesno 0
        if  [ 1 -eq $? ]
        then
            cd
            [ -d src ] || mkdir src
            cd src
            sh_download  http://crm114.sourceforge.net/crm114-2003-06-23-alpha.
tar.gz
            if [ 0 -eq $? ]
            then
                echo Download looks successful - trying again with build...
                cd $patchdir && exec make
            fi
        fi
        shdie crm114 tar.gz file not found - quitting
    fi
    cd $dir 2>/dev/null || continue
    # a shell function
    check_and_extract 'crm114-*-alpha.tar.gz'          \
                      crm114-2003-06-23-alpha.tar.gz   \
                      crm114-2003-06-23-alpha          \
         && break
    #
    check_and_extract 'crm114-*-alpha.tgz'          \
                      crm114-2003-06-23-alpha.tgz   \
                      crm114-2003-06-23-alpha          \
         && break
    #
    echo Not using `pwd` ...
done

# Include here any modifications from the camram team.

mainwd=`pwd`

patch < $patchdir/crm114_P1_Makefile || shdie Failed to apply patch

cd tre-*     || shdie cd failed to tre subdirectory
./configure  || shdie configure failed
echo
echo  Current directory is `pwd`
echo  'Run "make install", "make experimental" crm114 as root ? [y/N]'
sh_yesno 0
if [ 1 -eq $? ]
then
    echo sudo may ask for _your_ password, `whoami`
    sudo sh -c 'make install'
    cd $mainwd  || shdie cd failed to $mainwd directory

    sudo sh -c "LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH ; expo
rt LD_LIBRARY_PATH; make experimental && ln /usr/bin/crma /usr/bin/crm"
else
    shdie Not installing this part of CRM114 at present.
fi
exit 0

