#!/bin/bash

. buildscripts/try

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

    In standard situations specify / as rootdir. 

    A 'physical installation dir' differing from 'rootdir' can be 
    specified when calling icm_install.

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

    'rootdir' *must* be absolute, so it *must* start with /
"                                     
    exit 0
fi

echo "
Creating the construction directory ./tmp"
    try rm -rf tmp          # remove an existing ./tmp directory
    try mkdir -p tmp        # and refresh a new one
    
echo "
Writing the 'rootdir' ($1) to ./tmp/ROOT
"
    ROOT=`echo $1 | sed 's_/$__'`
    echo "ROOT=${ROOT}/" > tmp/ROOT
    
# Prefix the subdirectories with the final installation (ROOT) directory name 
# and write the names to tmp/INSTALL.im and tmp/INSTALL.sh
    . scripts/prefixroot

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}\"
AUTHOR=\"$AUTHOR}\"
VERSION=\"${VERSION}\"
YEARS=\"${YEARS}\"" > tmp/INSTALL.sh

# Show the final installation paths
    echo "Final installation #defines:"
    cat tmp/INSTALL.im
    echo


echo "Creating intermediate construction directories below ./tmp"
try  mkdir -p tmp/usr/bin  tmp/usr/libexec/icmake  tmp/usr/share/icmake
try  mkdir -p tmp/etc/icmake tmp/usr/share/man/man1 
try  mkdir -p tmp/usr/share/man/man7 tmp/usr/share/doc/icmake

echo
echo Next: call ./buildlib x

echo
