#!/bin/sh
#
# This script is for grepping the directory 
# structure out of the Makefile to make it 
# compile into the IRCd.
#
# 2002-05-26 ; tr-ircd development team
# 
# - Talesin <eengin@talesoft.de>
#

if [ ! "$1" ] ; then
 echo "should not be called manually"
 exit 2
fi

tmpprefix="`grep '^prefix' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"
tmpexec_prefix="`grep '^exec_prefix' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"

tmpsysconfdir="`grep '^sysconfdir' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"
tmplibdir="`grep '^libdir' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"
tmplocalstatedir="`grep '^localstatedir' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"
tmpdatadir="`grep '^datadir' $1/Makefile | awk -F= {'print $2'} | sed -e 's/^\ //'`"

prefix="$tmpprefix"

if [ "\${prefix}" = "`echo $tmpexec_prefix | awk -F/ {'print $1'}`" ] ; then
 exec_prefix="$tmpprefix`echo $tmpexec_prefix | sed -e 's/${prefix}//g'`"
else
 exec_prefix="$tmpexec_prefix"
fi

if [ "\${prefix}" = "`echo $tmpsysconfdir | awk -F/ {'print $1'}`" ] ; then
 sysconfdir="$tmpprefix`echo $tmpsysconfdir | sed -e 's/${prefix}//g'`"
else
 sysconfdir="$tmpsysconfdir"
fi

if [ "\${prefix}" = "`echo $tmpsysconfdir | awk -F/ {'print $1'}`" ] ; then
 sysconfdir="$tmpprefix`echo $tmpsysconfdir | sed -e 's/${prefix}//g'`"
else
 sysconfdir="$tmpsysconfdir"
fi

if [ "\${exec_prefix}" = "`echo $tmplibdir | awk -F/ {'print $1'}`" ] ; then
 libdir="$exec_prefix`echo $tmplibdir | sed -e 's/${exec_prefix}//g'`"
elif [ "\${prefix}" = "`echo $tmplibdir | awk -F/ {'print $1'}`" ] ; then
 libdir="$tmpprefix`echo $tmplibdir | sed -e 's/${prefix}//g'`"
else
 libdir="$tmplibdir"
fi

if [ "\${prefix}" = "`echo $tmplocalstatedir | awk -F/ {'print $1'}`" ] ; then
 localstatedir="$tmpprefix`echo $tmplocalstatedir | sed -e 's/${prefix}//g'`"
else
 localstatedir="$tmplocalstatedir"
fi

if [ "\${prefix}" = "`echo $tmpdatadir | awk -F/ {'print $1'}`" ] ; then
 datadir="$tmpprefix`echo $tmpdatadir | sed -e 's/${prefix}//g' -e 's/^\ //g'`"
else
 datadir="$tmpdatadir"
fi

cat << EOF > $1/include/ircpath.h
/*
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
EOF

echo "#define IRCD_PREFIX_ETC \"$sysconfdir\"" >> $1/include/ircpath.h
echo "#define IRCD_PREFIX_VAR \"$localstatedir\"" >> $1/include/ircpath.h
echo "#define IRCD_PREFIX_LIB \"$libdir\"" >> $1/include/ircpath.h
echo "#define IRCD_PREFIX_DOC \"$datadir\"" >> $1/include/ircpath.h
echo "#define IRCD_PREFIX_LOG \"/var/log/tr-ircd\"" >> $1/include/ircpath.h


syntax highlighted by Code2HTML, v. 0.9.1