1#!/usr/bin/perl 2# 3# Created: Thu Aug 15 11:57:33 1996 too 4# Last modified: Mon Dec 27 09:23:56 1999 too 5# 6# Copyright (c) 1996-1999 Tomi Ollila. All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28die "Usage: mkdep CPP-command [CPP options] file1 [file2...]\n" 29 if ($#ARGV < 1); 30 31$cmdl = shift(@ARGV); 32 33$cmdl = "$cmdl " . shift (@ARGV) while ($ARGV[0] =~ /^-[A-Z]/); 34 35while ($file = shift(@ARGV)) 36{ 37 $file =~ s/\.o$/.c/; 38 39 open(F, "$cmdl $file|"); 40 41 &parseout; 42 43 close(F); 44} 45 46 47sub initinit 48{ 49 %used = (); 50 $of = $file; 51 $of =~ s/\.c$/.lo/; 52 $str = "$of:\t$file"; 53 $len = length $str; 54} 55 56sub initstr 57{ 58 $str = "\t"; 59 $len = length $str; 60} 61 62sub parseout 63{ 64 &initinit; 65 while (<F>) 66 { 67 s/\\\\/\//g; 68 next unless (/^# [0-9]* "(.*\.h)"/); 69 70 next if ($1 =~ /^\//); 71 72 next if $used{$1}; 73 74 $used{$1} = 1; 75 76 $nlen = length($1) + 1; 77 78 if ($len + $nlen > 72) 79 { 80 print $str, "\\\n"; 81 &initstr; 82 $str = $str . $1; 83 } 84 else { $str = $str . " " . $1; } 85 86 $len += $nlen; 87 88 } 89 print $str, "\n"; 90} 91