Blame build/mkdep.perl

Packit 90a5c9
#!/usr/bin/perl
Packit 90a5c9
#
Packit 90a5c9
# Created: Thu Aug 15 11:57:33 1996 too
Packit 90a5c9
# Last modified: Mon Dec 27 09:23:56 1999 too
Packit 90a5c9
#
Packit 90a5c9
# Copyright (c) 1996-1999 Tomi Ollila.  All rights reserved.
Packit 90a5c9
#
Packit 90a5c9
# Redistribution and use in source and binary forms, with or without
Packit 90a5c9
# modification, are permitted provided that the following conditions
Packit 90a5c9
# are met:
Packit 90a5c9
# 1. Redistributions of source code must retain the above copyright
Packit 90a5c9
#    notice, this list of conditions and the following disclaimer.
Packit 90a5c9
# 2. Redistributions in binary form must reproduce the above copyright
Packit 90a5c9
#    notice, this list of conditions and the following disclaimer in the
Packit 90a5c9
#    documentation and/or other materials provided with the distribution.
Packit 90a5c9
# 
Packit 90a5c9
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit 90a5c9
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit 90a5c9
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
Packit 90a5c9
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 90a5c9
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit 90a5c9
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Packit 90a5c9
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit 90a5c9
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Packit 90a5c9
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit 90a5c9
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 90a5c9
Packit 90a5c9
die "Usage: mkdep CPP-command [CPP options] file1 [file2...]\n"
Packit 90a5c9
  if ($#ARGV < 1);
Packit 90a5c9
Packit 90a5c9
$cmdl = shift(@ARGV);
Packit 90a5c9
Packit 90a5c9
$cmdl = "$cmdl " . shift (@ARGV) while ($ARGV[0] =~ /^-[A-Z]/);
Packit 90a5c9
  
Packit 90a5c9
while ($file = shift(@ARGV))
Packit 90a5c9
{
Packit 90a5c9
    $file =~ s/\.o$/.c/;
Packit 90a5c9
Packit 90a5c9
    open(F, "$cmdl $file|");
Packit 90a5c9
Packit 90a5c9
    &parseout;
Packit 90a5c9
Packit 90a5c9
    close(F);
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
sub initinit
Packit 90a5c9
{
Packit 90a5c9
    %used = ();
Packit 90a5c9
    $of = $file;
Packit 90a5c9
    $of =~ s/\.c$/.lo/;
Packit 90a5c9
    $str = "$of:\t$file";
Packit 90a5c9
    $len = length $str;
Packit 90a5c9
}
Packit 90a5c9
	
Packit 90a5c9
sub initstr
Packit 90a5c9
{
Packit 90a5c9
    $str = "\t";
Packit 90a5c9
    $len = length $str;
Packit 90a5c9
}
Packit 90a5c9
Packit 90a5c9
sub parseout
Packit 90a5c9
{
Packit 90a5c9
    &initinit;
Packit 90a5c9
    while (<F>)
Packit 90a5c9
    {
Packit 90a5c9
        s/\\\\/\//g;
Packit 90a5c9
	next unless (/^# [0-9]* "(.*\.h)"/);
Packit 90a5c9
Packit 90a5c9
	next if ($1 =~ /^\//);
Packit 90a5c9
Packit 90a5c9
	next if $used{$1};
Packit 90a5c9
Packit 90a5c9
        $used{$1} = 1;
Packit 90a5c9
Packit 90a5c9
	$nlen = length($1) + 1;
Packit 90a5c9
Packit 90a5c9
	if ($len + $nlen > 72)
Packit 90a5c9
	{
Packit 90a5c9
	    print $str, "\\\n";
Packit 90a5c9
	    &initstr;
Packit 90a5c9
	    $str = $str . $1;
Packit 90a5c9
	}
Packit 90a5c9
	else { $str = $str . " " . $1; }
Packit 90a5c9
		     
Packit 90a5c9
	$len += $nlen;	
Packit 90a5c9
		     
Packit 90a5c9
    }
Packit 90a5c9
    print $str, "\n";
Packit 90a5c9
}