2 # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
15 use File::Spec::Functions qw(canonpath rel2abs);
17 my $abs_srcdir = rel2abs($config{sourcedir});
18 my $abs_blddir = rel2abs($config{builddir});
20 my $producer = shift @ARGV;
21 die "Producer not given\n" unless $producer;
28 # makedepend, in its infinite wisdom, wants to have the object file
29 # in the same directory as the source file. This doesn't work too
30 # well with out-of-source-tree builds, so we must resort to tricks
31 # to get things right. The trick is to call makedepend with an
32 # extra suffix that contains the desired object file path, like
35 # makedepend -f- -o"|dir/foo.o" -- $(CFLAGS) -- ../some/foo.c
37 # The result will look something like this:
39 # ../somewhere/foo|dir/foo.o: deps...
41 # Which is easy to massage by removing everything up to the first |
43 # Remove everything up to the first |
45 # Also, remove any dependency that starts with a /, because those
46 # are typically system headers
47 $line =~ s/\s+\/(\\.|\S)*//g;
48 # Finally, discard all empty lines or comment lines
49 return undef if $line =~ /:\s*$/ || $line =~ /^(#.*|\s*)$/;
51 $line.="\n" unless $line =~ /\R$/g;
59 # current versions of DEC / Compaq / HP / VSI C strips away all
60 # directory information from the object file, so we must insert it
61 # back. Just to be safe against future changes, we check that there
62 # really is no directory information.
63 my $directory = shift;
65 # The pattern for target and dependencies will always take this
68 # target SPACE : SPACE deps
70 # This is so a volume delimiter (a : without any spaces around it)
71 # won't get mixed up with the target / deps delimiter. We use this
72 # fact in the regexp below to make sure we do look at the target.
73 $line =~ s/^/$directory/ unless /^\S+[:>\]]\S+\s+:/;
75 # We know that VMS has system header files in text libraries,
76 # extension .TLB. We also know that our header files aren't stored
77 # in text libraries. Finally, we know that VMS C produces exactly
78 # one dependency per line, so we simply discard any line ending with
80 return undef if /\.TLB\s*$/;
89 # For the moment, we only support Visual C on native Windows, or
90 # compatible compilers. With those, the flags /Zs /showIncludes
91 # give us the necessary output to be able to create dependencies
92 # that nmake (or any 'make' implementation) should be able to read,
93 # with a bit of help. The output we're interested in looks like
94 # this (it always starts the same)
96 # Note: including file: {whatever header file}
98 # So all we really have to do is to is to replace the start of the
99 # line with an object file specification, given to us as an extra
100 # argument (passed from $ARGV[1]);
102 # There are also other lines mixed in, for example compiler
103 # warnings, so we simply discard anything that doesn't start with
106 if (/^Note: including file: */) {
107 (my $tail = $') =~ s/\s*\R$//;
109 # VC gives us absolute paths for all include files, so to
110 # remove system header dependencies, we need to check that
111 # they don't match $abs_srcdir or $abs_blddir
112 $tail = canonpath($tail);
113 if ($tail =~ m|^\Q$abs_srcdir\E|i
114 || $tail =~ m|^\Q$abs_blddir\E|i) {
115 return "${object}: \"$tail\"\n";
123 die "Producer unrecognised: $producer\n" unless defined $procedure;
126 if ($_ = $procedure->($_, @ARGV)) {