Document new Cygwin compatibility
[nasm/avx512.git] / mkdep.pl
blob69743f6b3cab226dbc5b4b9c74968899fb6d2596
1 #!/usr/bin/perl
3 # Script to create Makefile-style dependencies.
5 # Usage: perl [-s path-separator] [-o obj-ext] mkdep.pl dir... > deps
8 sub scandeps($) {
9 my($file) = @_;
10 my($line, $nf);
11 my(@xdeps) = ();
12 my(@mdeps) = ();
14 open(FILE, "< $file\0") or return; # If not openable, assume generated
15 while ( defined($line = <FILE>) ) {
16 chomp $line;
17 $line =~ s:/\*.*\*/::g;
18 $line =~ s://.*$::;
19 if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
20 $nf = $1;
21 push(@mdeps, $nf);
22 push(@xdeps, $nf) unless ( defined($deps{$nf}) );
25 close(FILE);
26 $deps{$file} = [@mdeps];
28 foreach $file ( @xdeps ) {
29 scandeps($file);
33 # %deps contains direct dependencies. This subroutine resolves
34 # indirect dependencies that result.
35 sub alldeps($) {
36 my($file) = @_;
37 my(%adeps);
38 my($dep,$idep);
40 foreach $dep ( @{$deps{$file}} ) {
41 $adeps{$dep} = 1;
42 foreach $idep ( alldeps($dep) ) {
43 $adeps{$idep} = 1;
46 return keys(%adeps);
49 %deps = ();
50 @files = ();
51 $sep = '/'; # Default, and works on most systems
52 $obj = 'o'; # Object file extension
54 while ( defined($arg = shift(@ARGV)) ) {
55 if ( $arg =~ /^\-s$/ ) {
56 $sep = shift(@ARGV);
57 } elsif ( $arg =~ /^\-o$/ ) {
58 $obj = shift(@ARGV);
59 } elsif ( $arg =~ /^-/ ) {
60 die "Unknown option: $arg\n";
61 } else {
62 push(@files, $arg);
66 foreach $dir ( @files ) {
67 opendir(DIR, $dir) or die "$0: Cannot open directory: $dir";
69 while ( $file = readdir(DIR) ) {
70 $path = ($dir eq '.') ? $file : $dir.$sep.$file;
71 if ( $file =~ /\.[Cc]$/ ) {
72 scandeps($path);
75 closedir(DIR);
78 foreach $file ( sort(keys(%deps)) ) {
79 if ( $file =~ /\.[Cc]$/ ) {
80 $ofile = $file; $ofile =~ s/\.[Cc]$/\./; $ofile .= $obj;
81 print $ofile, ': ', $file, ' ';
82 print join(' ', alldeps($file));
83 print "\n";