#!/bin/sh
# the next line restarts using wish \
exec tclsh "$0" "$@"

#    Copyright 2003 Regis Damongeot

#    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 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, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

set install_dir "/usr/local/bin"


if { [string equal "--help" $argv] } {
	puts "configure options:"
	puts "--help			display this help and exit"
	puts "--prefix=PREFIX		install architecture-independent files in PREFIX \[/usr/local/bin\]"
} elseif { [string equal -length 9 "--prefix=" $argv]} {
			if { [file isdirectory [string range $argv 9 end]] } {
				set install_dir "[file normalize [string range $argv 9 end]]"
				puts "TkDVD will be installed in $install_dir" 
			} else {
				puts "This directory does not exist: [string range $argv 9 end]. Create it if you want to install TkDVD in."
			}
}  elseif { ! [ string equal "" $argv ] } {
		puts "Invalid option, see configure --help"
} else {
	puts "install dir not specified, default location: $install_dir"
}

set makefile [open Makefile w]
puts $makefile "# Automatically generated by configure"
puts $makefile ""
puts $makefile "default:"
puts $makefile "	./install.tcl"
puts $makefile ""
puts $makefile "install: default"
#cp to allow root owning the file
puts $makefile "	cp tkdvd-install.sh $install_dir/TkDVD.sh"
puts $makefile "	chmod a+x $install_dir/TkDVD.sh"
puts $makefile ""
puts $makefile "clean:"
puts $makefile "	rm -f tkdvd-install.sh"
puts $makefile "	rm -f Makefile"
puts $makefile ""
puts $makefile "uninstall:"
puts $makefile "	rm -f $install_dir/TkDVD.sh"
