#!/bin/bash

prefix_path="/usr/local"
make_in=makefile.in.in
config_h=config.h
ver=0.0.2
help_usage()
{
 cat <<end
Usage :
      $0 [ --prefix=..] [--shell= ...] [ --debug ]

end
exit 1;
}

do_path(){
 echo -n -e "ops=-Dshell_path=\\\"$shell_path\\\"" >$make_in
# echo -n -e "\\ \n -Dprefix_path=\\\"$prefix_path\\\"" >>$make_in
if [ -f /etc/magic-release ];then
 echo -e -n "\\" >>$make_in
 echo -e -n "\n"  -Dmagic_linux >>$make_in
fi
 [ -z $debug ] ||echo -n -e " -D__${debug}__\n">>$make_in
 echo -n -e "\nshell_path=$shell_path\n" >>$make_in
 echo -n -e "prefix=$prefix_path\n" >>$make_in

cat <<eof >$config_h
//#define shell_path "$shell_path"
//testin configure .
eof
}

do_pro()
{
 echo -n -e "ver=$ver\n" >>$make_in
 sed -i -e "s|Exec=.*|Exec=${prefix_path}/bin/sudo_pppoe|g" gtk-pppoe.desktop

}

do_args()
{
 for o in $@
 do
  case $o in
   --prefix=*)
    prefix_path=${o#--prefix=};
  ;;
   --shell=*)
    shell_path={o#--shell=}
  ;;
   --debug*)
    debug="debug"
  ;;
  *)
    help_usage
  ;;
  esac
 done
 [ -z $shell_path ] &&shell_path="$prefix_path/share/gtk-pppoe"
}

do_args $@

do_path
CC=`which gcc`
if [ $? == 0 ] ;then
echo -n "Set CC to $CC "
cat <<eof >> $make_in
CC=$CC
eof
fi
do_pro
#touch *.c *.h
make clean 2>&1 >/dev/null
echo Done.
echo "You can run \"make\" ."
