#!/usr/bin/perl -w
# check for source package cruft -- lintian check script

# Copyright (C) 2000 Sean 'Shaleh' Perry
# based on debhelper check, copyright Joey Hess 1999
#
# 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, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.

use strict;

use Cwd;
use File::Basename;
use File::Find;

($#ARGV == 1) or fail("syntax: cruft <pkg> <type>");
my $pkg = shift;
my $type = shift;

unless ((not -e "debfiles/files") or (-z "debfiles/files")) {
    print "E: $pkg $type: debian-files-list-in-source\n";
}

my $cwd = cwd;

sub find_cruft {
    my $basename = basename($File::Find::name);
    my $name = $File::Find::name;
    $name =~ s#^\Q$cwd\E/unpacked/##;
    if ($basename eq 'config.cache' or $basename eq 'config.status') {
	print "E: $pkg $type: autoconf-generated-file-in-source $name\n";
    }
}

find(\&find_cruft, "$cwd/unpacked");

# -----------------------------------

sub fail {
    if ($_[0]) {
	print STDERR "internal error: $_[0]\n";
    } elsif ($!) {
	print STDERR "internal error: $!\n";
    } else {
	print STDERR "internal error.\n";
    }
    exit 1;
}
