Skip to content

Commit caaf81c

Browse files
author
H. Peter Anvin
committed
deps: don't break if run in a build directory; don't delete unconfig.h
Don't break Makefile.dep generation if run from a separate build directory. config/unconfig.h is a bit special; it is kept in the repository for the benefit of non-configure users. Therefore, don't have "make spotless" delete it. Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 392f47d commit caaf81c

File tree

4 files changed

+143
-88
lines changed

4 files changed

+143
-88
lines changed

Makefile.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ EXTERNAL_DEPENDENCIES = 1
537537
# the dependency information will remain external, so it doesn't
538538
# pollute the git logs.
539539
#
540-
Makefile.dep: $(PERLREQ) $(tools)/mkdep.pl config.status
541-
$(RUNPERL) $(tools)/mkdep.pl -M Makefile.in -- $(DEPDIRS)
540+
Makefile.dep: $(tools)/mkdep.pl config.status $(PERLREQ)
541+
$(RUNPERL) $(tools)/mkdep.pl -s '$(top_srcdir)' \
542+
-M $(srcdir)/Makefile.in -- $(DEPDIRS)
542543

543544
dep: Makefile.dep
544545

Mkfiles/msvc.mak

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ WARNSRCS = $(patsubst %.obj,%.c,$(LIBOBJ_NW))
157157
# have Perl just to recompile NASM from the distribution.
158158

159159
# Perl-generated source files
160-
PERLREQ = config\unconfig.h \
160+
PERLREQ_CLEANABLE = \
161161
x86\insnsb.c x86\insnsa.c x86\insnsd.c x86\insnsi.h x86\insnsn.c \
162162
x86\regs.c x86\regs.h x86\regflags.c x86\regdis.c x86\regdis.h \
163163
x86\regvals.c asm\tokhash.c asm\tokens.h asm\pptok.h asm\pptok.c \
@@ -168,10 +168,14 @@ PERLREQ = config\unconfig.h \
168168
misc\nasmtok.el \
169169
version.h version.mac version.mak nsis\version.nsh
170170

171+
# Special hack to keep config\unconfig.h from getting deleted
172+
# by "make spotless"...
173+
PERLREQ = config\unconfig.h $(PERLREQ_CLEANABLE)
174+
171175
INSDEP = x86\insns.dat x86\insns.pl x86\insns-iflags.ph x86\iflags.ph
172176

173-
config\unconfig.h: config\config.h.in
174-
$(RUNPERL) $(tools)\unconfig.pl \
177+
config\unconfig.h: config\config.h.in autoconf\unconfig.pl
178+
$(RUNPERL) '$(srcdir)'\autoconf\unconfig.pl \
175179
'$(srcdir)' config\config.h.in config\unconfig.h
176180

177181
x86\iflag.c: $(INSDEP)
@@ -243,11 +247,12 @@ x86\regs.h: x86\regs.dat x86\regs.pl
243247
# reasonable, but doesn't update the time stamp if the files aren't
244248
# changed, to avoid rebuilding everything every time. Track the actual
245249
# dependency by the empty file asm\warnings.time.
246-
warnings:
247-
$(RM_F) $(WARNFILES) $(WARNTIMES)
250+
.PHONY: warnings
251+
warnings: dirs
252+
$(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time
248253
$(MAKE) asm\warnings.time
249254

250-
asm\warnings.time: $(WARNSRCS)
255+
asm\warnings.time: $(WARNSRCS) asm\warnings.pl
251256
$(EMPTY) asm\warnings.time
252257
$(MAKE) $(WARNTIMES)
253258

Mkfiles/openwcom.mak

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ WARNSRCS = $(LIBOBJ_NW:.obj=.c)
170170
# have Perl just to recompile NASM from the distribution.
171171

172172
# Perl-generated source files
173-
PERLREQ = config\unconfig.h &
173+
PERLREQ_CLEANABLE = &
174174
x86\insnsb.c x86\insnsa.c x86\insnsd.c x86\insnsi.h x86\insnsn.c &
175175
x86\regs.c x86\regs.h x86\regflags.c x86\regdis.c x86\regdis.h &
176176
x86\regvals.c asm\tokhash.c asm\tokens.h asm\pptok.h asm\pptok.c &
@@ -181,10 +181,14 @@ PERLREQ = config\unconfig.h &
181181
misc\nasmtok.el &
182182
version.h version.mac version.mak nsis\version.nsh
183183

184+
# Special hack to keep config\unconfig.h from getting deleted
185+
# by "make spotless"...
186+
PERLREQ = config\unconfig.h $(PERLREQ_CLEANABLE)
187+
184188
INSDEP = x86\insns.dat x86\insns.pl x86\insns-iflags.ph x86\iflags.ph
185189

186-
config\unconfig.h: config\config.h.in
187-
$(RUNPERL) $(tools)\unconfig.pl &
190+
config\unconfig.h: config\config.h.in autoconf\unconfig.pl
191+
$(RUNPERL) '$(srcdir)'\autoconf\unconfig.pl &
188192
'$(srcdir)' config\config.h.in config\unconfig.h
189193

190194
x86\iflag.c: $(INSDEP)
@@ -256,11 +260,12 @@ x86\regs.h: x86\regs.dat x86\regs.pl
256260
# reasonable, but doesn't update the time stamp if the files aren't
257261
# changed, to avoid rebuilding everything every time. Track the actual
258262
# dependency by the empty file asm\warnings.time.
259-
warnings:
260-
$(RM_F) $(WARNFILES) $(WARNTIMES)
263+
.PHONY: warnings
264+
warnings: dirs
265+
$(RM_F) $(WARNFILES) $(WARNTIMES) asm\warnings.time
261266
$(MAKE) asm\warnings.time
262267

263-
asm\warnings.time: $(WARNSRCS)
268+
asm\warnings.time: $(WARNSRCS) asm\warnings.pl
264269
$(EMPTY) asm\warnings.time
265270
$(MAKE) $(WARNTIMES)
266271

tools/mkdep.pl

Lines changed: 118 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,52 @@
3636
# Script to create Makefile-style dependencies.
3737
#
3838
# Usage:
39-
# perl mkdep.pl [-s path-separator][-o obj-ext] dir... > deps
4039
# perl mkdep.pl [-i][-e][-m makefile]...[-M makefile... --] dir...
4140
#
4241

42+
use strict;
43+
use integer;
44+
4345
use File::Spec;
4446
use File::Basename;
4547
use File::Copy;
4648
use File::Temp;
4749
use Fcntl;
4850

49-
$barrier = "#-- Everything below is generated by mkdep.pl - do not edit --#\n";
51+
my $barrier =
52+
"#-- Everything below is generated by mkdep.pl - do not edit --#\n";
5053

5154
# This converts from filenames to full pathnames for our dependencies
52-
%dep_path = ();
55+
my %dep_path = ();
5356

5457
# List of files that cannot be found; these *must* be excluded
55-
@must_exclude = ();
58+
my @must_exclude = ();
59+
60+
#
61+
# Variables derived from the command line
62+
#
63+
my %deps;
64+
my %excludes;
65+
my @files;
66+
my @mkfiles;
67+
my $mkmode = 0;
68+
my @searchdirs = (File::Spec->curdir());
69+
my %searchdirs = (File::Spec->curdir() => 1);
70+
my $force_inline = 0;
71+
my $externalize = 0;
72+
my $debug = 0;
5673

5774
#
5875
# Scan files for dependencies
5976
#
60-
sub scandeps($) {
61-
my($file) = @_;
77+
sub scandeps {
78+
# path is the filesystem path, file what the output should call it
79+
my($path, $file) = @_;
6280
my $line;
6381
my %xdeps;
6482
my %mdeps;
6583

66-
open(my $fh, '<', $file)
84+
open(my $fh, '<', $path)
6785
or return; # If not openable, assume generated
6886

6987
while ( defined($line = <$fh>) ) {
@@ -128,8 +146,8 @@ ($$)
128146
#
129147
# Insert dependencies into a Makefile
130148
#
131-
sub _insert_deps($$) {
132-
my($file, $out) = @_;
149+
sub insert_deps($) {
150+
my($file) = @_;
133151

134152
open(my $in, '<', $file)
135153
or die "$0: Cannot open input: $file\n";
@@ -192,8 +210,13 @@ ($$)
192210
$is_external = $is_external && defined($external);
193211
undef $external if ( !$is_external );
194212

213+
my $out;
214+
my $outpath;
195215
if ( !$is_external || $externalize ) {
216+
$out = File::Temp->new(DIR => dirname($outpath = $file));
196217
print $out @outfile;
218+
} else {
219+
$out = File::Temp->new(DIR => dirname($outpath = $external));
197220
}
198221

199222
print $out $barrier;
@@ -204,78 +227,60 @@ ($$)
204227
print $out "$include_command $external\n";
205228
}
206229
unlink($external);
207-
return undef;
208-
}
230+
} else {
209231

210-
my $e;
232+
my $e;
211233

212-
foreach my $dfile ($external, sort(keys(%deps)) ) {
213-
my $ofile;
214-
my @deps;
234+
foreach my $dfile ($external, sort(keys(%deps)) ) {
235+
my $ofile;
236+
my @deps;
215237

216-
next unless (defined($dfile));
238+
next unless (defined($dfile));
217239

218-
if ( $selfrule && $dfile eq $external ) {
219-
$ofile = convert_file($dfile, $sep).':';
220-
@deps = sort(keys(%deps));
221-
} elsif ( $dfile =~ /^(.*)\.[Cc]$/ ) {
222-
$ofile = convert_file($1, $sep).$obj.':';
223-
@deps = ($dfile,alldeps($dfile,1));
224-
}
240+
if ( $selfrule && $dfile eq $external ) {
241+
$ofile = convert_file($dfile, $sep).':';
242+
@deps = sort(keys(%deps));
243+
} elsif ( $dfile =~ /^(.*)\.[Cc]$/ ) {
244+
$ofile = convert_file($1, $sep).$obj.':';
245+
@deps = ($dfile,alldeps($dfile,1));
246+
}
225247

226-
if (defined($ofile)) {
227-
my $len = length($ofile);
228-
print $out $ofile;
229-
foreach my $dep (@deps) {
230-
unless ($excludes{$dep}) {
231-
my $str = convert_file($dep, $sep);
232-
my $sl = length($str)+1;
233-
if ( $len+$sl > $maxline-2 ) {
234-
print $out ' ', $cont, "\n ", $str;
235-
$len = $sl;
236-
} else {
237-
print $out ' ', $str;
238-
$len += $sl;
248+
if (defined($ofile)) {
249+
my $len = length($ofile);
250+
print $out $ofile;
251+
foreach my $dep (@deps) {
252+
unless ($excludes{$dep}) {
253+
my $str = convert_file($dep, $sep);
254+
my $sl = length($str)+1;
255+
if ( $len+$sl > $maxline-2 ) {
256+
print $out ' ', $cont, "\n ", $str;
257+
$len = $sl;
258+
} else {
259+
print $out ' ', $str;
260+
$len += $sl;
261+
}
239262
}
240263
}
264+
print $out "\n";
241265
}
242-
print $out "\n";
243266
}
244267
}
245268

246-
return $external;
247-
}
248-
249-
sub insert_deps($)
250-
{
251-
my($mkfile) = @_;
252-
my $tmp = File::Temp->new(DIR => dirname($mkfile));
253-
my $tmpname = $tmp->filename;
254-
255-
my $newname = _insert_deps($mkfile, $tmp);
256-
close($tmp);
257-
258-
$newname = $mkfile unless(defined($newname));
259-
260-
move($tmpname, $newname);
269+
close($out);
270+
move($out->filename, $outpath);
261271
}
262272

263273
#
264274
# Main program
265275
#
266276

267-
my %deps = ();
268-
my @files = ();
269-
my @mkfiles = ();
270-
my $mkmode = 0;
271-
$force_inline = 0;
272-
$externalize = 0;
273-
$debug = 0;
274-
275277
while ( defined(my $arg = shift(@ARGV)) ) {
276278
if ( $arg eq '-m' ) {
277279
$arg = shift(@ARGV);
278280
push(@mkfiles, $arg);
281+
} elsif ( $arg eq '-s' ) {
282+
$arg = shift(@ARGV);
283+
push(@searchdirs, $arg);
279284
} elsif ( $arg eq '-i' ) {
280285
$force_inline = 1;
281286
} elsif ( $arg eq '-e' ) {
@@ -297,27 +302,66 @@ ($)
297302
}
298303
}
299304

305+
sub mycatdir($$) {
306+
my($a,$b) = @_;
307+
return $b if ($a eq File::Spec->curdir());
308+
return $a if ($b eq File::Spec->curdir());
309+
return File::Spec->catdir($a,$b);
310+
}
311+
312+
sub mycatfile($$) {
313+
my($d,$f) = @_;
314+
return $f if ($d eq File::Spec->curdir());
315+
return File::Spec->catfile($d,$f);
316+
}
317+
300318
my @cfiles = ();
301319

302-
foreach my $dir ( @files ) {
303-
opendir(DIR, $dir) or die "$0: Cannot open directory: $dir";
304-
305-
while ( my $file = readdir(DIR) ) {
306-
$path = ($dir eq File::Spec->curdir())
307-
? $file : File::Spec->catfile($dir,$file);
308-
if ( $file =~ /\.[Cc]$/ ) {
309-
push(@cfiles, $path);
310-
} elsif ( $file =~ /\.[Hh]$/ ) {
311-
print STDERR "Filesystem: $file -> $path\n" if ( $debug );
312-
$dep_path{$file} = $path; # Allow the blank filename
313-
$dep_path{$path} = $path; # Also allow the full pathname
320+
my $err = 0;
321+
my %scanned;
322+
323+
foreach my $fdir ( @files ) {
324+
my $found = 0;
325+
326+
foreach my $sdir ( @searchdirs ) {
327+
my $dir = mycatdir($sdir, $fdir);
328+
if ($scanned{$dir}) {
329+
# Have already been here
330+
$found = 1;
331+
next;
332+
}
333+
334+
opendir(DIR, $dir) or next;
335+
$scanned{$dir}++;
336+
$found++;
337+
338+
while ( my $file = readdir(DIR) ) {
339+
# $fdir is correct here, because we expect VPATH to do
340+
# its job, and the output filename depends on that, not
341+
# on the full source dir path.
342+
my $path = mycatfile($fdir, $file);
343+
my $fullpath = mycatfile($dir, $file);
344+
if ( $file =~ /\.[Cc]$/ ) {
345+
push(@cfiles, [$fullpath, $path]);
346+
} elsif ( $file =~ /\.[Hh]$/ ) {
347+
print STDERR "Filesystem: $file -> $path\n" if ( $debug );
348+
$dep_path{$file} = $path; # Allow the blank filename
349+
$dep_path{$path} = $path; # Also allow the full pathname
350+
}
314351
}
352+
closedir(DIR);
353+
}
354+
355+
if (!$found) {
356+
print STDERR "$0: cannot find directory: $fdir\n";
357+
$err++;
315358
}
316-
closedir(DIR);
317359
}
318360

361+
exit(1) if ($err);
362+
319363
foreach my $cfile ( @cfiles ) {
320-
scandeps($cfile);
364+
scandeps(@$cfile);
321365
}
322366

323367
foreach my $mkfile ( @mkfiles ) {

0 commit comments

Comments
 (0)