#!/usr/bin/perl
# Sherlock Configure Script
# (c) 2005 Martin Mares <mj@ucw.cz>

use warnings;
use strict;

our $srcdir;
BEGIN {
	my $pkgfile = "lib/wildmatch.c";
	if (!defined ($srcdir = $ENV{"SRCDIR"})) {
		if (-f $pkgfile) {
			$srcdir=".";
		} elsif ($0 =~ m@^(.*)/configure$@ && -f "$1/$pkgfile") {
			$srcdir=$1;
		} else {
			die "Don't know how to find myself. Please set SRCDIR manually.";
		}
	}
	require "$srcdir/lib/perl/Configure.pm";
	UCW::Configure::import UCW::Configure;
}

Init($srcdir, undef);
Include "sherlock/default.cfg";
Log "### Configuring Sherlock " . Get("SHERLOCK_VERSION") . " with configuration " . Get("CONFIG") . "\n";
Include Get("CONFIG");
Include "lib/autoconf.cfg";
Include "sherlock/autoconf.cfg";
Finish();

my $cust = FindFile(Get("CUSTOM_DIR") . "/Makefile");
$cust =~ s@/Makefile$@@;
Log "Linking custom to $cust ... ";
-l "custom" and unlink "custom";
-e "custom" and Fail "custom already exists and it's not a link";
symlink $cust, "custom" or Fail $!;
Log "done\n";

Log "\nConfigured, run `make' to build everything.\n";
