home *** CD-ROM | disk | FTP | other *** search
- eval 'exec /bin/perl -wS $0 ${1+"$@"}'
- if 0;
-
- # $Id: makedeps,v 1.6 1991/03/08 22:27:10 chip Exp $
- #
- # Make a list of dependencies for the given file(s).
- #
- # $Log: makedeps,v $
- # Revision 1.6 1991/03/08 22:27:10 chip
- # Add "-o" and "-u" options.
- #
- # Revision 1.5 1990/11/29 13:39:37 chip
- # Fix typo.
- #
- # Revision 1.4 90/09/28 11:01:51 chip
- # Handle C++.
- #
- # Revision 1.3 90/05/03 16:49:30 chip
- # checked in with -k by chip at 90.08.17.15.17.16.
- #
- # Revision 1.3 90/05/03 16:49:30 chip
- # Remove temp files each time around the loop.
- # Never mention temp files in output.
- #
- # Revision 1.2 90/05/02 16:43:07 chip
- # Oops. Write deps for the object file.
- #
- # Revision 1.1 90/05/02 16:24:39 chip
- # Initial revision
- #
-
- ($ME = $0) =~ s#^.*/##;
-
- ################################################################
- ## Configuration.
- ################################################################
-
- $INF = "/usr/informix" unless $INF = $ENV{'INFORMIXDIR'};
- chop($HOME = `pwd`) unless $HOME = $ENV{'HOME'};
-
- @COPY = ("cp");
- @CPP = ("cc", "-E");
- @CPLUSPP = ("g++", "-E");
- @ESQLC = ("$INF/lib/esqlc", "-e");
-
- $T = "dep_$$";
-
- ################################################################
- ## Options.
- ################################################################
-
- undef $OPT_OUTPUT;
- $OPT_USER = 0;
- @CPPOPTS = ();
- while (@ARGV) {
- $_ = $ARGV[0];
- last unless /^-/;
- if (/^-o(.*)$/) {
- shift;
- die "$ME: -o needs argument"
- unless defined($OPT_OUTPUT = length($1) ? $1 : shift);
- }
- elsif (/^-u$/) {
- shift;
- $OPT_USER = 1;
- }
- else {
- push(@CPPOPTS, shift);
- }
- }
-
- # Avoid warnings
- @CPP, @CPLUSPP;
-
- &DEP("## These dependences were generated by the \"$ME\" program.\n");
- &DEP("## Any changes made by hand will be lost!\n");
-
- foreach $file (@ARGV) {
- unless (-f $file) {
- print STDERR "$ME: $file: no such file\n";
- next;
- }
-
- if (($basename) = ($file =~ /^(\S+)\.c$/)) {
- open(CPP, "@CPP @CPPOPTS $file |");
- }
- elsif (($basename) = ($file =~ /^(\S+)\.(C|cc|cxx|cpp)$/)) {
- open(CPP, "@CPLUSPP @CPPOPTS $file |");
- }
- elsif (($basename) = ($file =~ /^(\S+)\.ec$/)) {
- if (system(@COPY, $file, "$T.ec")
- || system(@ESQLC, "$T.ec")) {
- print STDERR "$ME: can't compile $file\n";
- next;
- }
- open(CPP, "@CPP @CPPOPTS $T.c |");
- }
- else {
- print STDERR "$ME: $file: not C, C++ or ESQL/C\n";
- next;
- }
-
- undef %D;
- while (<CPP>) {
- next unless @F = /^#\s*(line\s*)?(\d+)\s+"(.+)"/;
- $i = @F[2];
-
- # Perform transformations on include filename here.
- $i =~ s#//*#/#g;
- $i =~ s#^\./##;
-
- $D{$i} = 1 unless grep($i eq $_, $file, "$T.c", "$T.ec");
- }
- close(CPP);
-
- &DEP("\n");
- &DEP("# $file\n");
- foreach (sort BYPATH keys(%D)) {
- next if $OPT_USER && m#^/usr/include/#;
- &DEP("$basename.o: $_\n");
- }
-
- unlink("$T.ec", "$T.c");
- }
-
- &DEPDONE;
- exit(0);
-
- sub BYPATH {
- $_ = 0;
- --$_ if $a =~ m#^/#;
- ++$_ if $b =~ m#^/#;
- return $_ if $_;
- return -1 if $a lt $b;
- return 1 if $a gt $b;
- return 0;
- }
-
- sub DEP {
- $DEP = "" unless defined($DEP);
- for $x (@_) { $DEP .= $x; }
- }
-
- sub DEPDONE {
- if (defined($OPT_OUTPUT)) {
- die "$ME: can't create $OUT: $!\n"
- unless open(OUT, "> $OPT_OUTPUT");
- print OUT $DEP;
- close(OUT);
- }
- else {
- print $DEP;
- }
- $DEP = "";
- }
-