#!/bin/sh
                                                                                                                                           
# Copyright (C) 2010, 2011 johnc
#
# 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, see <http://www.gnu.org/licenses/>.

PREFIX="/usr/local"
set -- $(getopt -o p: --long prefix: -- "$@") 
while [ $# -gt 0 ];do 
	case "$1" in 
		-p|--prefix) 
			#FIXME: I am not sure if $2 always starts/ends with '
			PREFIX=`echo $2 | sed "s/'//g"`
			shift 2;; 
		--)
			shift;
			break;;
	esac
done

# FIXME: I don't know how to detect conflict
KEYBINDING="<Super>c"
# Name of generated executable program
APP_NAME_GEN="gtranslator"
echo "PREFIX = \"$PREFIX\""
echo "KEYBINDING = \"$KEYBINDING\""
echo "APP_NAME_GEN = \"$APP_NAME_GEN\""
echo "\
/*
 * Copyright (C) 2010, 2011 johnc
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */

/* This file is generated by configure, do NOT edit it */

#ifndef GCONF_KEYBINDING_H_
#define GCONF_KEYBINDING_H_

#include <gconf/gconf-client.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#define PREFIX \"$PREFIX/bin/\"
#define KEYBINDING \"$KEYBINDING\"
#define APP_NAME_GEN \"$APP_NAME_GEN\"

#endif" > gconf-keybinding.h

echo "\
OBJS = window-util.o communicate.o translate.o

CC = gcc

GTKLIB = \`pkg-config --cflags --libs gtk+-2.0\`
GCONFLIB = \`pkg-config --cflags --libs gconf-2.0\`

all: gtranslator

window-util.o: window-util.c
	\$(CC) -c window-util.c \$(GTKLIB)

communicate.o: communicate.c
	\$(CC) -c communicate.c

translate.o: translate.c communicate.o
	\$(CC) -c translate.c

gtranslator: gtranslator.c \$(OBJS)
	\$(CC) gtranslator.c \$(OBJS) \$(GTKLIB) -o gtranslator

install: gtranslator
	cp gtranslator $PREFIX/bin/

keybinding: gconf-keybinding
	./gconf-keybinding

gconf-keybinding:
	\$(CC) gconf-keybinding.c -o gconf-keybinding \$(GCONFLIB)

clean:
	rm *.o
	rm gconf-keybinding gconf-keybinding.h" > Makefile
