#! /usr/bin/perl -w
#                              -*- Mode: Perl -*- 
# pkg-nodep --- 
# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On       : Wed Jul 16 01:11:21 1997
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Sat Jul 19 00:02:19 1997
# Last Machine Used: tiamat.datasync.com
# Update Count     : 12
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 

use strict;
use diagnostics;
use Carp;
require 5.001;

use Debian::Package::Dependency_List;
use Debian::Package::Package;
use Debian::Package::List;
use Getopt::Long;

package main;


#Handle The auto generated eval line.
use vars qw($running_under_some_shell);

=head1 NAME

pkg-nodep - List of packages that are not targets.

=cut

=head1 SYNOPSIS

 usage: pkg-node [options] 
 where the options are:

=over 2

=item --nocheck-recommends 

=item --check-recommends   Check Recommends as well [OFF]

=item --nocheck-suggests

=item --check-suggests     Check Suggests as well   [OFF]

=item --installed-packages <Package-file-for-installed-packages> 

=back

=cut

=head1 DESCRIPTION

This utility details out the list of packages installed that have no
other packages that depend on them (optionally also checks Recommends
and Suggestions).

 The default is to assume that the list of installed packages may be
 derived from the file I</var/lib/dpkg/status>, but the user may
 override this by providing a I<Packages> file listing all the
 packages that are assumed to be installed.

=cut 

sub main {
  my $installed;
  my $candidates;
  my $ret;
  my $do_depends = 1;
  my $strict_depends = 1;
  my $do_order = 1;
  my $recommends = 0;
  my $suggests = 0;
  my $consistent = 1;
  my $print_failures = 1;
  my $print_found = 0;
  my $installed_packages = '';
  my $filename;
  my $usage;
  my $MYNAME;
  
  ($MYNAME     = $0) =~ s|.*/||;


  $usage= <<EOUSAGE;
 usage: $MYNAME [options] <Package-file-for-new-packages>
 where the options are:
 --nocheck-recommends
 --check-recommends   Check the Recommends field as well            [OFF]
 --nocheck-suggests
 --check-suggests     Check the Suggests field as well              [OFF]
 --installed-packages <Package-file-for-installed-packages> 
EOUSAGE
  
  $ret = GetOptions("check-recommends!"   => \$recommends,
                    "check-suggests!"     => \$suggests,
		    "installed-packages=s" => \$installed_packages);
  die "$usage" unless $ret;

  ######################################################################
  #                     Phase One: Gather data                         #
  ######################################################################

  # Installed file (default value taken from status file)
  if (-f $installed_packages) {
    $installed = Debian::Package::New->new('filename' => $installed_packages);
  }
  else {
    $installed = Debian::Package::Installed->new();
  }
  
  $installed->get_dependency_information();
  
  ######################################################################
  #                 Phase Two: Check dependencies                      #
  ######################################################################

  # Check Pre-Dependencies
  $installed->check_relations('Consistent' => $consistent,
			      'Installed' => $installed,
			      'Field' => 'Pre-Depends');
  # Check Dependencies
  $installed->check_relations('Consistent' => $consistent,
			      'Installed' => $installed,
			      'Field' => 'Depends');
  # Check Recommendations
  $installed->check_relations('Consistent' => $consistent,
			      'Installed' => $installed,
			      'Warn'       => 'True',
			      'Field' => 'Recommendations')
    if $recommends;
  # Check Suggestions
  $installed->check_relations('Consistent' => $consistent,
			      'Installed'  => $installed,
			      'Warn'       => 'True',
			      'Field'      => 'Suggestions')
    if $suggests;
    
  
  ######################################################################
  #                Phase Three: Gather ordering data                    #
  ######################################################################
  
  print "The non targets are:\n",
            $installed->non_target_as_string('Type' => "All");
  

  exit 0;
}

=head1 CAVEATS

This is very inchoate, at the moment, and needs testing.

=cut

=head1 BUGS

None Known so far.

=cut

=head1 AUTHOR

Manoj Srivastava <srivasta@debian.org>

=cut

&main::main();

    
