#!/bin/sh

#      configure
#      
#      Copyright 2012 Alex <alex@linuxonly.ru>
#      
#      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 3 of the License, 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, see <http://www.gnu.org/licenses/>.


prefix=/usr
cflags='-mtune=native -O3'
libindicate=0

for arg_iter in "$@"; do
    arg=`echo $arg_iter | cut -f1 -d=`
    arg_value=`echo $arg_iter | cut -f2 -d=`
    case $arg in
        --help)
echo "This script generates GMM configuration and build files. It also
checks if all dependencies are fulfilled.
Used without arguments, default settings are applied. Arguments are :
    --help : Display this message and exit.
    --enable-libindicate : Enable Unity message menu integration.
    --prefix=PATH : Set PATH as file-system root for installation.
    --cflags=PARAMETERS : Pass PARAMETERS to the compiler."
            exit 0;;

        --enable-libindicate)
            libindicate=1;;

        --prefix)
            prefix=$arg_value;;

        --cflags)
            echo "Using : \"$arg_value\" as compilation options."
            cflags="$arg_value ";;

        
    esac
done

echo -n "Checking depencies... "

if ! pkg-config  --print-errors --exists 'gtk+-3.0 >= 3.4.0'; then
  echo 'ERROR: Please install GTK+ version 3.0.0 or later'
  exit 1
fi

if ! test -e "/usr/include/gdbm/gdbm.h"; then
	if ! test -e "/usr/include/gdbm.h"; then
		echo 'ERROR: Please install GDBM library with development headers'
		exit 1
	fi
fi

if ! test -e "/usr/include/libnotify/notify.h"; then
	echo 'ERROR: Please install libnotify with development headers version 0.7.5 or later'
	exit 1
fi

if [ $libindicate = 1 ]; then
	if ! pkg-config  --print-errors --exists 'indicate-0.7'; then
  		echo 'ERROR: Please install libindicate with development headers version 0.7 or later'
  		exit 1
	fi
fi
echo done


echo -n "Generating Makefile_h... "
echo "#WARNING: Auto-generated file, edit with care.
CFLAGS := $cflags
LIBINDICATE := $libindicate
PREFIX := $prefix" > Makefile_h
echo done

echo -n "Generating resources.h... "
echo "/*
 *      resources.h
 *      
 *      Copyright 2012 Alex <alex@linuxonly.ru>
 *      
 *      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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */

/* WARNING: Auto-generated file, edit with care. */

#ifndef __RESOURCES_H__
#define __RESOURCES_H__

#define RESOURCE_MAINWINDOW_ICON         \"$prefix/share/pixmaps/modem-manager-gui.png\"
#define RESOURCE_MAINWINDOW_UI           \"$prefix/bin/modem-manager-gui.ui\"

#define RESOURCE_TOOLBAR_DEV             \"$prefix/share/modem-manager-gui/dev-tb.png\"
#define RESOURCE_TOOLBAR_SMS             \"$prefix/share/modem-manager-gui/sms-tb.png\"
#define RESOURCE_TOOLBAR_USSD            \"$prefix/share/modem-manager-gui/ussd-tb.png\"
#define RESOURCE_TOOLBAR_INFO            \"$prefix/share/modem-manager-gui/info-tb.png\"
#define RESOURCE_TOOLBAR_SCAN            \"$prefix/share/modem-manager-gui/scan-tb.png\"
#define RESOURCE_TOOLBAR_CONT            \"$prefix/share/modem-manager-gui/cont-tb.png\"
#define RESOURCE_TOOLBAR_TRAFFIC         \"$prefix/share/modem-manager-gui/traffic-tb.png\"

#define RESOURCE_DESKTOP_FILE            \"/usr/share/applications/extras-modem-manager-gui.desktop\"

#define RESOURCE_LOCALE_DIR              \"$prefix/share/locale/\"
#define RESOURCE_LOCALE_DOMAIN           \"modem-manager-gui\"

#endif // __RESOURCES_H__" > src/resources.h
echo done

echo -n "Generating launcher... "
echo "
[Desktop Entry]
Name=Modem Manager GUI
GenericName=Modem Manager GUI
Comment=Graphical interface for Modem manager daemon control
Comment[ru]=Программа для управления специфическими функциями EDGE/3G/4G модемов
Exec=$prefix/bin/modem-manager-gui
Icon=$prefix/share/pixmaps/modem-manager-gui.png
Terminal=false
Type=Application
Categories=System;" > resources/extras-modem-manager-gui.desktop
echo done

