#!/bin/bash

if [ "$#" == "0" ] ; then
echo "
    Usage: icm_prepare rootdir

    In standard situations specify / as rootdir. 

    The physical installation dir is specified when calling icm_install.

    The here specified rootdir is hard-coded in icmake's programs, so
    eventually the icmake files should be available under rootdir.
"                                     
    exit 0
fi

try()
{
    echo "  $*"
    $* || exit 1
}

echo Creating the intermediate destination directory ./tmp

try rm -rf tmp 
                # icmake/tmp icmun/tmp/ icm-*/tmp
                # try find -name '*.o' -exec rm -f '{}' \;
try mkdir -p tmp

echo    Writing tmp/ROOT
ROOT=`echo $1 | sed 's_/$__'`
echo "ROOT=${ROOT}/" > tmp/ROOT
 
. scripts/conversions

echo "
#define BINDIR      \"${BINDIR}\"
#define SKELDIR     \"${SKELDIR}\"
#define MANDIR      \"${MANDIR}\"
#define LIBDIR      \"${LIBDIR}\"
#define CONFDIR     \"${CONFDIR}\"
#define DOCDIR      \"${DOCDIR}\"
#define AUTHOR      \"${AUTHOR}\"
#define VERSION     \"${VERSION}\"
#define YEARS       \"${YEARS}\"
" > tmp/INSTALL.im

echo "
BINDIR=\"${BINDIR}\"
SKELDIR=\"${SKELDIR}\"
MANDIR=\"${MANDIR}\"
LIBDIR=\"${LIBDIR}\"
CONFDIR=\"${CONFDIR}\"
DOCDIR=\"${DOCDIR}\"
VERSION=\"${VERSION}\"
YEARS=\"${YEARS}\"
" > tmp/INSTALL.sh

echo Creating the intermediate destination directories
try  mkdir -p tmp${BINDIR}  tmp${LIBDIR}      tmp${SKELDIR}  
try  mkdir -p tmp${CONFDIR} tmp${MANDIR}/man1 tmp${MANDIR}/man7 
try  mkdir -p tmp${DOCDIR}



