Listtree.mcc: rename variables in Listtree_GetEntry to match the template of other...
[AROS.git] / tools / cxref / contrib / make_depend.pl
blob374c86791ae8c107f42bfed05a65284587db3a3f
1 #!/bin/sh
3 # C Cross Referencing & Documentation tool. Version 1.5.
5 # A Perl script to produce a neat output for makefile dependencies.
7 # Written by Andrew M. Bishop
9 # This file Copyright 1999,2003 Andrew M. Bishop
10 # It may be distributed under the GNU Public License, version 2, or
11 # any higher version. See section COPYING of the GNU Public license
12 # for conditions under which this file may be redistributed.
15 exec perl -x $0 $*
17 exit 1
19 #!perl
21 # The C pre-processor arguments (-D, -I).
22 $cpp_args="";
24 # The files to check.
25 @cfiles=();
26 @hfiles=();
29 # Parse the command line arguments
32 if( $#ARGV==-1 )
34 print "Usage: make_depend filename1.h [filename2.h ...]\n";
35 print " filename1.c filename2.c\n";
36 print " [-Ddefine] [-Udefine] [-Iinclude]\n";
37 exit 0;
40 while ( $#ARGV >= 0 )
42 $_=$ARGV[0];
43 if(-f $_)
45 push(@cfiles,$_) if(m/\.c$/);
46 push(@hfiles,$_) if(m/\.h$/);
48 else
50 $cpp_args.=" '".$_."'";
52 shift;
55 die "Error: no source files specified\n" if($#cfiles==-1);
56 die "Error: no header files specified\n" if($#hfiles==-1);
59 # The main program
62 @cfiles=sort(@cfiles);
64 $longest=0;
65 foreach $cfile (@cfiles)
67 $longest=length($cfile) if(length($cfile)>$longest);
70 foreach $cfile (@cfiles)
72 %inc_headers=&GetFileHeaders($cfile);
74 $ofile = $cfile;
75 $ofile =~ s/\.c/.o/;
77 printf("%-".$longest."s : %-".$longest."s",$ofile,$cfile);
79 foreach $hfile (@hfiles)
81 if($inc_headers{$hfile})
83 print " $hfile";
85 else
87 print " "." "x(length($hfile));
91 print "\n";
96 # Get the included headers from an existing file.
99 sub GetFileHeaders
101 local($file)=@_;
102 local(%headers)=();
103 local($depends,$header)=("");
105 # Parse the file
107 open(IN,"gcc -MM $file $cpp_args|") || die "Cannot run 'gcc -MM $file $cpp_args'\n";
109 while(<IN>)
111 $depends.=$_;
114 close(IN);
116 $depends =~ s/\\?\n//g;
118 foreach $header (split(/ +/,$depends))
120 $headers{$header}=1;
123 return(%headers);