#!/bin/bash
#
# ToscoConf 0.02
# Copyright (c) 2003 Leandro Pereira <leandro@linuxmag.com.br>
# All rights reserved.
#
# This script is in the Tosco Public License. It may be copied and/or
# modified, in whole or in part, provided that all copies must retain the
# above copyright notice, this condition and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
#
# (yes, I did a copy&paste from the BSD license, eat me)
#
# ---------------------------------------------------------------------------

PACKAGE=`basename ${PWD} | cut -d"-" -f1`;
VERSION=`basename ${PWD} | cut -d"-" -f2`;

echo "ToscoConf (version 0.03) for $PACKAGE version $VERSION"

# ---------------------------------------------------------------------------

GTK2=-1
MIN_VERSION="2.2.0"
echo -n "Checking for GTK ${MIN_VERSION}... "
for i in `which pkg-config`; do
	pkg-config --errors-to-stdout gtk+-2.0 \
		--atleast-version=$MIN_VERSION > /dev/null
	case $? in
		0)
			GTK_FLAGS=`pkg-config gtk+-2.0 --cflags`
			GTK_LIBS=`pkg-config gtk+-2.0 --libs`
			pkg-config --modversion gtk+-2.0
			GTK2=1 ;;
		*)
			echo "not found."
			exit ;;
	esac
done

# ---------------------------------------------------------------------------

WNCK=-1
MIN_VERSION="2.2.0"
echo -n "Checking for libwnck ${MIN_VERSION}... "
for i in `which pkg-config`; do
	pkg-config --errors-to-stdout libwnck-1.0 \
		--atleast-version=$MIN_VERSION > /dev/null
	case $? in
		0)
			WNCK_FLAGS=`pkg-config libwnck-1.0 --cflags`
			WNCK_LIBS=`pkg-config libwnck-1.0 --libs`
			pkg-config --modversion libwnck-1.0
			WNCK=1 ;;
		*)
			echo "not found."
			exit ;;
	esac
done

# --------------------------------------------------------------------------

echo -e "\nWriting config.h..."
rm -f config.h
echo -e "#ifndef __CONFIG_H__\n#define __CONFIG_H__\n" > config.h

echo "#define VERSION \"$VERSION\"" >> config.h
echo "#define IMG_PREFIX \"/usr/share/suxpanel/pixmaps/\"" >> config.h
echo "#define _(x) x" >> config.h

echo -e "\n#endif	/* __CONFIG_H__ */" >> config.h

echo "Writing Makefile..."
rm -f Makefile

echo "GTK_LIBS = ${GTK_LIBS} `pkg-config gthread-2.0 --libs`" >> Makefile
echo "GTK_CFLAGS = ${GTK_FLAGS}" >> Makefile
echo "WNCK_LIBS = ${WNCK_LIBS}" >> Makefile
echo "WNCK_CFLAGS = ${WNCK_FLAGS}" >> Makefile
echo "PACKAGE = `basename ${PWD}`" >> Makefile

cat Makefile.in >> Makefile

echo -e "\nDone. Type \"gmake\" to compile the program.\n"
echo "If you get errors, probably you don't have the right libraries,"
echo "includes or utilities. However, if you're sure this is a bug in my"
echo -e "code, please send a patch (use \"diff -u\") to <leandro@linuxmag.com.br>.\n"

