X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=util%2Fadd-depends.pl;h=1a87cdd36490886591bb3029655e46e942e8d7a4;hp=5aa03c4740798fbe283a90eb7025829996479ca1;hb=HEAD;hpb=3babc1e468c9a5cfb30582a3ea1d55c1ec776361 diff --git a/util/add-depends.pl b/util/add-depends.pl index 5aa03c4740..5f21adecbf 100644 --- a/util/add-depends.pl +++ b/util/add-depends.pl @@ -1,5 +1,5 @@ #! /usr/bin/env perl -# Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -23,6 +23,7 @@ ${^WIN32_SLOPPY_STAT} = 1; my $debug = $ENV{ADD_DEPENDS_DEBUG}; my $buildfile = $config{build_file}; my $build_mtime = (stat($buildfile))[9]; +my $configdata_mtime = (stat('configdata.pm'))[9]; my $rebuild = 0; my $depext = $target{dep_extension} || ".d"; my @depfiles = @@ -30,9 +31,11 @@ my @depfiles = grep { # This grep has side effects. Not only does if check the existence # of the dependency file given in $_, but it also checks if it's - # newer than the build file, and if it is, sets $rebuild. + # newer than the build file or older than configdata.pm, and if it + # is, sets $rebuild. my @st = stat($_); - $rebuild = 1 if @st && $st[9] > $build_mtime; + $rebuild = 1 + if @st && ($st[9] > $build_mtime || $st[9] < $configdata_mtime); scalar @st > 0; # Determines the grep result } map { (my $x = $_) =~ s|\.o$|$depext|; $x; } @@ -69,7 +72,41 @@ my %depconv_cache = keys %{$unified_info{generate}}; my %procedures = ( - 'gcc' => undef, # gcc style dependency files needs no mods + 'gcc' => + sub { + (my $objfile = shift) =~ s|\.d$|.o|i; + my $line = shift; + + # Remove the original object file + $line =~ s|^.*\.o: | |; + # All we got now is a dependency, shave off surrounding spaces + $line =~ s/^\s+//; + $line =~ s/\s+$//; + # Also, shave off any continuation + $line =~ s/\s*\\$//; + + # Split the line into individual header files, and keep those + # that exist in some form + my @headers; + for (split(/\s+/, $line)) { + my $x = rel2abs($_); + + if (!$depconv_cache{$x}) { + if (-f $x) { + $depconv_cache{$x} = $_; + } + } + + if ($depconv_cache{$x}) { + push @headers, $_; + } else { + print STDERR "DEBUG[$producer]: ignoring $objfile <- $line\n" + if $debug; + } + } + return ($objfile, join(' ', @headers)) if @headers; + return undef; + }, 'makedepend' => sub { # makedepend, in its infinite wisdom, wants to have the object file @@ -149,7 +186,10 @@ my %procedures = ( # mappings for generated headers, we only need to deal # with the source tree. if ($dep =~ s|^\Q$abs_srcdir_shaved\E([\.>\]])?|$srcdir_shaved$1|i) { - $depconv_cache{$line} = $dep; + # Also check that the header actually exists + if (-f $line) { + $depconv_cache{$line} = $dep; + } } } return ($objfile, $depconv_cache{$line}) @@ -174,7 +214,7 @@ my %procedures = ( # # Hinweis: Einlesen der Datei: {whatever header file} # - # To accomodate, we need to use a very general regular expression + # To accommodate, we need to use a very general regular expression # to parse those lines. # # Since there's no object file name at all in that information, @@ -201,7 +241,10 @@ my %procedures = ( # mappings for generated headers, we only need to deal # with the source tree. if ($dep =~ s|^\Q$abs_srcdir\E\\|\$(SRCDIR)\\|i) { - $depconv_cache{$tail} = $dep; + # Also check that the header actually exists + if (-f $line) { + $depconv_cache{$tail} = $dep; + } } } return ($objfile, '"'.$depconv_cache{$tail}.'"') @@ -247,7 +290,10 @@ my %procedures = ( # mappings for generated headers, we only need to deal # with the source tree. if ($dep =~ s|^\Q$abs_srcdir\E\\|\$(SRCDIR)\\|i) { - $depconv_cache{$tail} = $dep; + # Also check that the header actually exists + if (-f $line) { + $depconv_cache{$tail} = $dep; + } } } return ($objfile, '"'.$depconv_cache{$tail}.'"') @@ -260,7 +306,7 @@ my %procedures = ( }, ); my %continuations = ( - 'gcc' => undef, + 'gcc' => "\\", 'makedepend' => "\\", 'VMS C' => "-", 'VC' => "\\", @@ -276,16 +322,14 @@ my $continuation = $continuations{$producer}; my $buildfile_new = "$buildfile-$$"; my %collect = (); -if (defined $procedure) { - foreach my $depfile (@depfiles) { - open IDEP,$depfile or die "Trying to read $depfile: $!\n"; - while () { - s|\R$||; # The better chomp - my ($target, $deps) = $procedure->($depfile, $_); - $collect{$target}->{$deps} = 1 if defined $target; - } - close IDEP; +foreach my $depfile (@depfiles) { + open IDEP,$depfile or die "Trying to read $depfile: $!\n"; + while () { + s|\R$||; # The better chomp + my ($target, $deps) = $procedure->($depfile, $_); + $collect{$target}->{$deps} = 1 if defined $target; } + close IDEP; } open IBF, $buildfile or die "Trying to read $buildfile: $!\n"; @@ -298,31 +342,21 @@ close IBF; print OBF "# DO NOT DELETE THIS LINE -- make depend depends on it.\n"; -if (defined $procedure) { - foreach my $target (sort keys %collect) { - my $prefix = $target . ' :'; - my @deps = sort keys %{$collect{$target}}; +foreach my $target (sort keys %collect) { + my $prefix = $target . ' :'; + my @deps = sort keys %{$collect{$target}}; - while (@deps) { - my $buf = $prefix; - $prefix = ''; + while (@deps) { + my $buf = $prefix; + $prefix = ''; - while (@deps && ($buf eq '' - || length($buf) + length($deps[0]) <= 77)) { - $buf .= ' ' . shift @deps; - } - $buf .= ' '.$continuation if @deps; - - print OBF $buf,"\n" or die "Trying to print: $!\n" + while (@deps && ($buf eq '' + || length($buf) + length($deps[0]) <= 77)) { + $buf .= ' ' . shift @deps; } - } -} else { - foreach my $depfile (@depfiles) { - open IDEP,$depfile or die "Trying to read $depfile: $!\n"; - while () { - print OBF or die "Trying to print: $!\n"; - } - close IDEP; + $buf .= ' '.$continuation if @deps; + + print OBF $buf,"\n" or die "Trying to print: $!\n" } }