#!/usr/bin/perl
#
# Configuration Script for BlackMail
# by Ken Hollis <khollis@chatlink.com>
# slight mods by jsm
# Version 0.28
# This script REQUIRES perl 5

$| = 1;

%CONFIGS = ( "auto"	=> "Automatic configuration/OS detection",
	     "aix"	=> "IBM Aix",
	     "linux"	=> "Linux Operating System",
	     "bsd"	=> "BSDi, FreeBSD, OpenBSD and NetBSD OSes",
	     "irix"     => "Irix Operating System",
	     "solaris"	=> "Solaris Operating System",
             "sunos"	=> "SunOs (untested)",
	     "svr4"	=> "Unix System V Release 4.0 (may work)",
	     "next"	=> "NeXTStep 3.x" );

chomp($os = `uname`);
$os =~ tr/A-Z/a-z/;

sub show_configs
{
    print "The following is a listing of possible configuration options.\n\n";

    foreach(sort keys %CONFIGS)
    {
	printf("      %-14.14s %s\n", $_, $CONFIGS{$_});
    }

    print "\n";
}

sub make_link
{
    $osmake = $_[0];
    $osmake =~ tr/A-Z/a-z/;

    if ($CONFIGS{$osmake} ne "") {
	print "Making link for $osmake template... ";
	`rm -f Makefile.tmpl`;
	`ln -s templates/$osmake Makefile.tmpl`;
	print "Complete.\n\n";
    } else {
	print "Sorry, your operating system was not found in the list of supported\n";
	print "templates.  If you want to go for broke, simply type \"./Configure\"\n";
	print "on a line by itself, and attempt a make.  If you still don't get it\n";
	print "to compile, please modify a makefile template in the \"templates\"\n";
	print "directory, and add it to the \"%CONFIGS\" list.\n\n";
	exit(0);
    }
}

sub check_cmdline
{
    print "\n";
    print "Welcome to Configure for BlackMail.\n\n";

    if ($ARGV[0] ne "") {
	if ($ARGV[0] =~ /[Aa][Uu][Tt][Oo]/) {
	    &make_link($os);
	} else {
	    &make_link($ARGV[0]);
	}

	print "Type \"make\" then \"make install\" to begin.\n\n";
	exit(0);
    } else {
	&show_configs;
	exit(0);
    }
}

&check_cmdline;
