2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2009 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
8 ## Copyright 1996-2009 the NASM Authors - All rights reserved.
10 ## Redistribution and use in source and binary forms, with or without
11 ## modification, are permitted provided that the following
12 ## conditions are met:
14 ## * Redistributions of source code must retain the above copyright
15 ## notice, this list of conditions and the following disclaimer.
16 ## * Redistributions in binary form must reproduce the above
17 ## copyright notice, this list of conditions and the following
18 ## disclaimer in the documentation and/or other materials provided
19 ## with the distribution.
21 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ## --------------------------------------------------------------------------
38 # Script to create Makefile-style dependencies.
40 # Usage: perl mkdep.pl [-s path-separator] [-o obj-ext] dir... > deps
47 $barrier = "#-- Everything below is generated by mkdep.pl - do not edit --#\n";
50 # Scan files for dependencies
58 sysopen(FILE
, $file, O_RDONLY
)
59 or return; # If not openable, assume generated
61 while ( defined($line = <FILE
>) ) {
63 $line =~ s
:/\*.*\*/::g
;
65 if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
68 push(@xdeps, $nf) unless ( defined($deps{$nf}) );
72 $deps{$file} = [@mdeps];
74 foreach $file ( @xdeps ) {
79 # %deps contains direct dependencies. This subroutine resolves
80 # indirect dependencies that result.
86 foreach $dep ( @
{$deps{$file}} ) {
88 foreach $idep ( alldeps
($dep) ) {
92 return sort(keys(%adeps));
95 # This converts a filename from host syntax to target syntax
96 # This almost certainly works only on relative filenames...
97 sub convert_file
($$) {
99 my(@fspec) = (basename
($file));
100 while ( ($file = dirname
($file)) ne File
::Spec
->curdir() &&
101 $file ne File
::Spec
->rootdir() ) {
102 unshift(@fspec, basename
($file));
106 # This means kill path completely. Used with Makes who do
107 # path searches, but doesn't handle output files in subdirectories,
108 # like OpenWatcom WMAKE.
109 return $fspec[scalar(@fspec)-1];
111 return join($sep, @fspec);
116 # Insert dependencies into a Makefile
120 $nexttemp++; # Unique serial number for each temp file
121 my($tmp) = File
::Spec
->catfile(dirname
($file), 'tmp.'.$nexttemp);
123 sysopen(IN
, $file, O_RDONLY
)
124 or die "$0: Cannot open input: $file\n";
125 sysopen(OUT
, $tmp, O_WRONLY
|O_CREAT
|O_TRUNC
, 0666)
126 or die "$0: Cannot open output: $tmp\n";
128 my($line,$parm,$val);
129 my($obj) = '.o'; # Defaults
132 my($maxline) = 78; # Seems like a reasonable default
133 my @exclude = (); # Don't exclude anything
135 while ( defined($line = <IN
>) ) {
136 if ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
137 $parm = $1; $val = $2;
138 if ( $parm eq 'object-ending' ) {
140 } elsif ( $parm eq 'path-separator' ) {
142 } elsif ( $parm eq 'line-width' ) {
144 } elsif ( $parm eq 'continuation' ) {
146 } elsif ( $parm eq 'exclude' ) {
147 @exclude = split(/\,/, $val);
149 } elsif ( $line eq $barrier ) {
150 last; # Stop reading input at barrier line
158 foreach $e (@exclude) {
162 my $dfile, $ofile, $str, $sl, $len;
167 foreach $dfile ( sort(keys(%deps)) ) {
168 if ( $dfile =~ /\.[Cc]$/ ) {
169 $ofile = $dfile; $ofile =~ s/\.[Cc]$//;
170 $str = convert_file
($ofile,$sep).$obj.':';
173 foreach $dep ($dfile, alldeps
($dfile)) {
174 unless ($do_exclude{$dep}) {
175 $str = convert_file
($dep,$sep);
176 $sl = length($str)+1;
177 if ( $len+$sl > $maxline-2 ) {
178 print OUT
' ', $cont, "\n ", $str;
191 (unlink($file) && rename($tmp, $file))
192 or die "$0: Failed to change $tmp -> $file\n";
204 while ( defined($arg = shift(@ARGV)) ) {
205 if ( $arg eq '-m' ) {
207 push(@mkfiles, $arg);
208 } elsif ( $arg eq '-M' ) {
209 $mkmode = 1; # Futher filenames are output Makefile names
210 } elsif ( $arg eq '--' && $mkmode ) {
212 } elsif ( $arg =~ /^-/ ) {
213 die "Unknown option: $arg\n";
216 push(@mkfiles, $arg);
223 foreach $dir ( @files ) {
224 opendir(DIR
, $dir) or die "$0: Cannot open directory: $dir";
226 while ( $file = readdir(DIR
) ) {
227 $path = ($dir eq File
::Spec
->curdir())
228 ?
$file : File
::Spec
->catfile($dir,$file);
229 if ( $file =~ /\.[Cc]$/ ) {
236 foreach $mkfile ( @mkfiles ) {
237 insert_deps
($mkfile);