#!/usr/bin/perl -w
#
#  echo emdebian config variables 
#  to link the perl config with shell scripts
#
#  Copyright (C) 2007  Neil Williams <codehelp@debian.org>
#
#  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

use Cwd;
use File::HomeDir;
use Debian::Debhelper::Dh_Lib;
use Emdebian::Tools;
use Config::Auto;
use warnings;
use strict;
use vars qw($arch $ourversion $progname);
require "dpkg-cross.pl";
$ourversion = "0.2.0";

sub usageversion {
    print(STDERR <<END)
$progname version $ourversion

Usage:
 $progname [-a|--default-arch]
 $progname -h|--help|--version

Options:
 -a|--default-arch:   export the dpkg-cross default architecture
 -w|--work-dir:       export the emdebian-tools working directory
 -h|--help:           print this usage message and exit
 --version:           print this usage message and exit

END
        || die "$progname: failed to write usage: $!\n";
}

while( @ARGV ) {
    $_= shift( @ARGV );
    last if m/^--$/;
    if (!/^-/) {
        unshift(@ARGV,$_);
		last;
    }
	elsif (/^(-h|--help|--version)$/) {
        &usageversion();
		exit(0);
	}
	elsif (/^(-a|--default-arch)$/) {
		print &default_arch;
		exit(0);
	}
	elsif (/^(-w|--work-dir)$/) {
		print &workdir;
		exit(0);
	}
	else {
		die "$progname: Unknown option $_.\n";
	}
}
&usageversion if (!$ARGV[0]);
exit(0);

sub default_arch
{
	&read_config();
	my $arch = &get_architecture();
	die (qq/Could not determine the default architecture, please use $progname --arch\n/) if (!$arch);
	return $arch;
}

sub workdir
{
	&read_config;
	my $w = &get_workdir;
	$w = cwd if (! -d $w);
	return $w;
}
