Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows bulding: Make dependency generation not quite as talkative #15006

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Configurations/10-main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1278,13 +1278,14 @@ my %targets = (
CPP => '"$(CC)" /EP /C',
CFLAGS => "/W3 /wd4090 /nologo",
coutflag => "/Fo",
cpp_depend_flags => "/Zs /showIncludes",
LD => "link",
LDFLAGS => "/nologo /debug",
ldoutflag => "/out:",
ldpostoutflag => "",
ld_resp_delim => "\n",
bin_lflags => "setargv.obj",
makedepcmd => '"$(CC)" /Zs /showIncludes',
makedep_scheme => 'VC',
AR => "lib",
ARFLAGS => "/nologo",
aroutflag => "/out:",
Expand Down Expand Up @@ -1838,6 +1839,7 @@ my %targets = (
dso_scheme => "vms",
thread_scheme => "pthreads",

makedep_scheme => 'VMS C',
AS => sub { vms_info()->{AS} },
ASFLAGS => sub { vms_info()->{ASFLAGS} },
asoutflag => sub { vms_info()->{asoutflag} },
Expand Down
8 changes: 7 additions & 1 deletion Configurations/50-cppbuilder.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ my %targets = (
bin_cflags => "-tWC",
lib_cflags => shared("-tWD -D_WINDLL -D_DLL"),
coutflag => "-o",
cpp_depend_flags => "-Hp",

# -Sx isn't documented, but 'cpp32 -H -S' explains it:
#
# -Sx Omit preprocessed text in output
makedepcmd => "cpp32 -oCON -Sx -Hp",
makedep_scheme => "embarcadero",

LD => "ilink32",
LDFLAGS => picker(default => "-x -Gn -q -w-dup",
debug => '-j"$(BDS)\lib\win32c\debug" ' .
Expand Down
2 changes: 1 addition & 1 deletion Configurations/descrip.mms.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ distclean : clean
depend : descrip.mms
descrip.mms : FORCE
@ ! {- output_off() if $disabled{makedepend}; "" -}
@ $(PERL) {- sourcefile("util", "add-depends.pl") -} "VMS C"
@ $(PERL) {- sourcefile("util", "add-depends.pl") -} "{- $config{makedep_scheme} -}"
@ ! {- output_on() if $disabled{makedepend}; "" -}

# Install helper targets #############################################
Expand Down
2 changes: 1 addition & 1 deletion Configurations/platform/Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sub shlibextsimple { (my $x = $target{shared_extension} || '.so')
=~ s|\.\$\(SHLIB_VERSION_NUMBER\)||;
$x; }
sub shlibvariant { $target{shlib_variant} || "" }
sub makedepprog { $disabled{makedepend} ? undef : $config{makedepprog} }
sub makedepcmd { $disabled{makedepend} ? undef : $config{makedepcmd} }

# No conversion of assembler extension on Unix
sub asm {
Expand Down
2 changes: 1 addition & 1 deletion Configurations/platform/mingw.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub resext { '.res.obj' }
sub shlibext { '.dll' }
sub shlibextimport { $target{shared_import_extension} || '.dll.a' }
sub shlibextsimple { undef }
sub makedepprog { $disabled{makedepend} ? undef : $config{makedepprog} }
sub makedepcmd { $disabled{makedepend} ? undef : $config{makedepcmd} }

(my $sover_filename = $config{shlib_version}) =~ s|\.|_|g;
sub shlib_version_as_filename {
Expand Down
14 changes: 6 additions & 8 deletions Configurations/unix-Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
##
## {- join("\n## ", @autowarntext) -}
{-
our $makedepprog = platform->makedepprog();
our $makedep_scheme = $config{makedep_scheme};
our $makedepcmd = platform->makedepcmd();

sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ }

Expand Down Expand Up @@ -315,7 +316,7 @@ CXXFLAGS={- join(' ', @{$config{CXXFLAGS}}) -}
LDFLAGS= {- join(' ', @{$config{LDFLAGS}}) -}
EX_LIBS= {- join(' ', @{$config{LDLIBS}}) -}

MAKEDEPEND={- $config{makedepprog} -}
MAKEDEPEND={- $config{makedepcmd} -}

PERL={- $config{PERL} -}

Expand Down Expand Up @@ -571,9 +572,7 @@ distclean: clean
# concatenate only if that is true.
depend:
@: {- output_off() if $disabled{makedepend}; "" -}
@$(PERL) $(SRCDIR)/util/add-depends.pl {-
defined $makedepprog && $makedepprog =~ /\/makedepend/
? 'makedepend' : 'gcc' -}
@$(PERL) $(SRCDIR)/util/add-depends.pl "{- $makedep_scheme -}"
@: {- output_on() if $disabled{makedepend}; "" -}

# Install helper targets #############################################
Expand Down Expand Up @@ -1517,8 +1516,7 @@ EOF
$obj: $deps
$cmd $incs $defs $cmdflags -c -o \$\@ $srcs
EOF
} elsif (defined $makedepprog && $makedepprog !~ /\/makedepend/
&& !grep /\.rc$/, @srcs) {
} elsif ($makedep_scheme eq 'gcc' && !grep /\.rc$/, @srcs) {
$recipe .= <<"EOF";
$obj: $deps
$cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
Expand All @@ -1534,7 +1532,7 @@ EOF
$obj: $deps
$cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
EOF
if (defined $makedepprog && $makedepprog =~ /\/makedepend/) {
if ($makedep_scheme eq 'makedepend') {
$recipe .= <<"EOF";
\$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
> $dep
Expand Down
6 changes: 3 additions & 3 deletions Configurations/windows-makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ distclean: clean

depend:
@ {- output_off() if $disabled{makedepend}; "" -}
@ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "VC"
@ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "{- $target{makedep_scheme} -}"
@ {- output_on() if $disabled{makedepend}; "" -}

# Install helper targets #############################################
Expand Down Expand Up @@ -809,7 +809,7 @@ EOF
lib => ' $(LIB_ASFLAGS)',
dso => ' $(DSO_ASFLAGS)',
bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
my $makedepprog = $config{makedepprog};
my $makedepcmd = $config{makedepcmd} unless $disabled{makedepend};
if ($srcs[0] =~ /\.rc$/) {
my $res = platform->res($args{obj});
return <<"EOF";
Expand All @@ -836,7 +836,7 @@ $obj: $deps
\$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
EOF
$recipe .= <<"EOF" unless $disabled{makedepend};
cmd /C "\$(CPP) $cflags $defs $target{cpp_depend_flags} $srcs > $dep 2>&1"
cmd /C "$makedepcmd $cflags $defs $srcs > $dep 2>&1"
EOF
return $recipe;
}
Expand Down
28 changes: 19 additions & 9 deletions Configure
Original file line number Diff line number Diff line change
Expand Up @@ -1533,22 +1533,32 @@ unless ($disabled{asm}) {

# Check for makedepend capabilities.
if (!$disabled{makedepend}) {
if ($config{target} =~ /^(VC|BC|vms)-/) {
# For VC-, BC- and vms- targets, there's nothing more to do here. The
# functionality is hard coded in the corresponding build files for
# cl/cpp32 (Windows) and CC/DECC (VMS).
# If the attribute makedep_scheme is defined, then we assume that the
# config target and its associated build file are programmed to deal
# with it.
# If makedep_scheme is undefined, we go looking for GCC compatible
# dependency making, and if that's not available, we try to fall back
# on 'makedepend'.
if ($target{makedep_scheme}) {
$config{makedep_scheme} = $target{makedep_scheme};
# If the makedepcmd attribute is defined, copy it. If not, the
# build files will have to fend for themselves.
$config{makedepcmd} = $target{makedepcmd} if $target{makedepcmd};
} elsif (($predefined_C{__GNUC__} // -1) >= 3
&& !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
# We know that GNU C version 3 and up as well as all clang
# versions support dependency generation, but Xcode did not
# handle $cc -M before clang support (but claims __GNUC__ = 3)
$config{makedepprog} = "\$(CROSS_COMPILE)$config{CC}";
$config{makedep_scheme} = 'gcc';
} else {
# In all other cases, we look for 'makedepend', and disable the
# capability if not found.
$config{makedepprog} = which('makedepend');
disable('unavailable', 'makedepend') unless $config{makedepprog};
# In all other cases, we look for 'makedepend', and set the
# makedep_scheme value if we found it.
$config{makedepcmd} = which('makedepend');
$config{makedep_scheme} = 'makedepend' if $config{makedepcmd};
}

# If no depend scheme is set, we disable makedepend
disable('unavailable', 'makedepend') unless $config{makedep_scheme};
}

if (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') {
Expand Down
77 changes: 61 additions & 16 deletions util/add-depends.pl
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,28 @@
}
return ($objfile, $depconv_cache{$line})
if defined $depconv_cache{$line};
print STDERR "DEBUG[VMS C]: ignoring $objfile <- $line\n"
print STDERR "DEBUG[$producer]: ignoring $objfile <- $line\n"
if $debug;

return undef;
},
'VC' =>
sub {
# On Windows, with Microsoft Visual C the flags /Zs /showIncludes
# give us the necessary output to be able to create dependencies
# that nmake (or any 'make' implementation) should be able to read,
# with a bit of help. The output we're interested in looks like
# this (it always starts the same)
# With Microsoft Visual C the flags /Zs /showIncludes give us the
# necessary output to be able to create dependencies that nmake
# (or any 'make' implementation) should be able to read, with a
# bit of help. The output we're interested in looks something
# like this (it always starts the same)
#
# Note: including file: {whatever header file}
#
# With Embarcadero C++Builder's preprocessor (cpp32.exe) the -Hp
# flag gives us the preprocessed output annotated with the following
# note whenever a #include file is read:
# This output is localized, so for example, the German pack gives
# us this:
#
# Including ->->{whatever header file}
# Hinweis: Einlesen der Datei: {whatever header file}
#
# where each "->" indicates the nesting level of the #include. The
# logic here is otherwise the same as the 'VC' case.
# To accomodate, 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,
# we must construct it ourselves.
Expand All @@ -188,13 +187,58 @@
# warnings, so we simply discard anything that doesn't start with
# the Note:

if (/^Note: including file: */ or /^Including (->)*/) {
if (/^[^:]*: [^:]*: */) {
(my $tail = $') =~ s/\s*\R$//;

# VC gives us absolute paths for all include files, so to
# remove system header dependencies, we need to check that
# they don't match $abs_srcdir or $abs_blddir. C++Builder gives
# us relative paths when possible, so convert to absolute paths.
# they don't match $abs_srcdir or $abs_blddir.
$tail = canonpath($tail);

unless (defined $depconv_cache{$tail}) {
my $dep = $tail;
# Since we have already pre-populated the cache with
# 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;
}
}
return ($objfile, '"'.$depconv_cache{$tail}.'"')
if defined $depconv_cache{$tail};
print STDERR "DEBUG[$producer]: ignoring $objfile <- $tail\n"
if $debug;
}

return undef;
},
'embarcadero' =>
sub {
# With Embarcadero C++Builder's preprocessor (cpp32.exe) the -Sx -Hp
# flags give us the list of #include files read, like the following:
#
# Including ->->{whatever header file}
#
# where each "->" indicates the nesting level of the #include. The
# logic here is otherwise the same as the 'VC' scheme.
#
# Since there's no object file name at all in that information,
# we must construct it ourselves.

(my $objfile = shift) =~ s|\.d$|.obj|i;
my $line = shift;

# There are also other lines mixed in, for example compiler
# warnings, so we simply discard anything that doesn't start with
# the Note:

if (/^Including (->)*/) {
(my $tail = $') =~ s/\s*\R$//;

# C++Builder gives us relative paths when possible, so to
# remove system header dependencies, we convert them to
# absolute paths and check that they don't match $abs_srcdir
# or $abs_blddir, just as the 'VC' scheme.
$tail = rel2abs($tail);

unless (defined $depconv_cache{$tail}) {
Expand All @@ -208,7 +252,7 @@
}
return ($objfile, '"'.$depconv_cache{$tail}.'"')
if defined $depconv_cache{$tail};
print STDERR "DEBUG[VC]: ignoring $objfile <- $tail\n"
print STDERR "DEBUG[$producer]: ignoring $objfile <- $tail\n"
if $debug;
}

Expand All @@ -220,6 +264,7 @@
'makedepend' => "\\",
'VMS C' => "-",
'VC' => "\\",
'embarcadero' => "\\",
);

die "Producer unrecognised: $producer\n"
Expand Down