Skip to content

Commit 2e535eb

Browse files
committed
Configuration: rework how dependency making is handled
Previously, we had dependency making pretty much hard coded in the build file templates, with a bit of an exception for Unix family platforms, where we had different cases depending on what dependency making program was found. With the Embarcadero C++ builder, a separate scheme appeared, with a different logic. This change merges the two, and introduces two config target attributes: makedepcmd The program to use, where this is relevant. This replaces the earlier configuration attribute 'makedepprog'. makedep_scheme This is a keyword that can be used by build files templates to produce different sorts of commands, but most importantly, to pass as argument to util/add-depend.pl, which uses this keyword as a "producer" for the dependency lines. If the config target doesn't define the 'makedep_scheme' attribute, Configure tries to figure it out by looking for GCC compatible compilers or for the 'makedepend' command. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Matthias St. Pierre <[email protected]> (Merged from openssl#15006)
1 parent 0bd138b commit 2e535eb

File tree

9 files changed

+92
-41
lines changed

9 files changed

+92
-41
lines changed

Configurations/10-main.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@ my %targets = (
12761276
template => 1,
12771277
CC => "cl",
12781278
CPP => '"$(CC)" /EP /C',
1279-
make_depend => '"$(CC)" /Zs /showIncludes',
12801279
CFLAGS => "/W3 /wd4090 /nologo",
12811280
coutflag => "/Fo",
12821281
LD => "link",
@@ -1285,6 +1284,8 @@ my %targets = (
12851284
ldpostoutflag => "",
12861285
ld_resp_delim => "\n",
12871286
bin_lflags => "setargv.obj",
1287+
makedepcmd => '"$(CC)" /Zs /showIncludes',
1288+
makedep_scheme => 'VC',
12881289
AR => "lib",
12891290
ARFLAGS => "/nologo",
12901291
aroutflag => "/out:",
@@ -1838,6 +1839,7 @@ my %targets = (
18381839
dso_scheme => "vms",
18391840
thread_scheme => "pthreads",
18401841

1842+
makedep_scheme => 'VMS C',
18411843
AS => sub { vms_info()->{AS} },
18421844
ASFLAGS => sub { vms_info()->{ASFLAGS} },
18431845
asoutflag => sub { vms_info()->{asoutflag} },

Configurations/50-cppbuilder.conf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ my %targets = (
66
thread_scheme => "winthreads",
77
cc => "bcc32c",
88
CPP => "cpp32 -oCON -Sc -Sr",
9-
# -Sx isn't documented, but 'cpp32 -H -S' explains it:
10-
#
11-
# -Sx Omit preprocessed text in output
12-
make_depend => "cpp32 -oCON -Sx -Hp",
139
defines => add("WIN32_LEAN_AND_MEAN", "OPENSSL_SYS_WIN32",
1410
"L_ENDIAN", "DSO_WIN32", "_stricmp=stricmp",
1511
"_strnicmp=strnicmp", "_malloca=malloc",
@@ -22,6 +18,13 @@ my %targets = (
2218
bin_cflags => "-tWC",
2319
lib_cflags => shared("-tWD -D_WINDLL -D_DLL"),
2420
coutflag => "-o",
21+
22+
# -Sx isn't documented, but 'cpp32 -H -S' explains it:
23+
#
24+
# -Sx Omit preprocessed text in output
25+
makedepcmd => "cpp32 -oCON -Sx -Hp",
26+
makedep_scheme => "embarcadero",
27+
2528
LD => "ilink32",
2629
LDFLAGS => picker(default => "-x -Gn -q -w-dup",
2730
debug => '-j"$(BDS)\lib\win32c\debug" ' .

Configurations/descrip.mms.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ distclean : clean
523523
depend : descrip.mms
524524
descrip.mms : FORCE
525525
@ ! {- output_off() if $disabled{makedepend}; "" -}
526-
@ $(PERL) {- sourcefile("util", "add-depends.pl") -} "VMS C"
526+
@ $(PERL) {- sourcefile("util", "add-depends.pl") -} "{- $config{makedep_scheme} -}"
527527
@ ! {- output_on() if $disabled{makedepend}; "" -}
528528

529529
# Install helper targets #############################################

Configurations/platform/Unix.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sub shlibextsimple { (my $x = $target{shared_extension} || '.so')
3232
=~ s|\.\$\(SHLIB_VERSION_NUMBER\)||;
3333
$x; }
3434
sub shlibvariant { $target{shlib_variant} || "" }
35-
sub makedepprog { $disabled{makedepend} ? undef : $config{makedepprog} }
35+
sub makedepcmd { $disabled{makedepend} ? undef : $config{makedepcmd} }
3636

3737
# No conversion of assembler extension on Unix
3838
sub asm {

Configurations/platform/mingw.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sub resext { '.res.obj' }
2323
sub shlibext { '.dll' }
2424
sub shlibextimport { $target{shared_import_extension} || '.dll.a' }
2525
sub shlibextsimple { undef }
26-
sub makedepprog { $disabled{makedepend} ? undef : $config{makedepprog} }
26+
sub makedepcmd { $disabled{makedepend} ? undef : $config{makedepcmd} }
2727

2828
(my $sover_filename = $config{shlib_version}) =~ s|\.|_|g;
2929
sub shlib_version_as_filename {

Configurations/unix-Makefile.tmpl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
##
44
## {- join("\n## ", @autowarntext) -}
55
{-
6-
our $makedepprog = platform->makedepprog();
6+
our $makedep_scheme = $config{makedep_scheme};
7+
our $makedepcmd = platform->makedepcmd();
78

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

@@ -315,7 +316,7 @@ CXXFLAGS={- join(' ', @{$config{CXXFLAGS}}) -}
315316
LDFLAGS= {- join(' ', @{$config{LDFLAGS}}) -}
316317
EX_LIBS= {- join(' ', @{$config{LDLIBS}}) -}
317318

318-
MAKEDEPEND={- $config{makedepprog} -}
319+
MAKEDEPEND={- $config{makedepcmd} -}
319320

320321
PERL={- $config{PERL} -}
321322

@@ -570,9 +571,7 @@ distclean: clean
570571
# concatenate only if that is true.
571572
depend:
572573
@: {- output_off() if $disabled{makedepend}; "" -}
573-
@$(PERL) $(SRCDIR)/util/add-depends.pl {-
574-
defined $makedepprog && $makedepprog =~ /\/makedepend/
575-
? 'makedepend' : 'gcc' -}
574+
@$(PERL) $(SRCDIR)/util/add-depends.pl "{- $makedep_scheme -}"
576575
@: {- output_on() if $disabled{makedepend}; "" -}
577576

578577
# Install helper targets #############################################
@@ -1516,8 +1515,7 @@ EOF
15161515
$obj: $deps
15171516
$cmd $incs $defs $cmdflags -c -o \$\@ $srcs
15181517
EOF
1519-
} elsif (defined $makedepprog && $makedepprog !~ /\/makedepend/
1520-
&& !grep /\.rc$/, @srcs) {
1518+
} elsif ($makedep_scheme eq 'gcc' && !grep /\.rc$/, @srcs) {
15211519
$recipe .= <<"EOF";
15221520
$obj: $deps
15231521
$cmd $incs $defs $cmdflags -MMD -MF $dep.tmp -MT \$\@ -c -o \$\@ $srcs
@@ -1533,7 +1531,7 @@ EOF
15331531
$obj: $deps
15341532
$cmd $incs $defs $cmdflags $cmdcompile -o \$\@ $srcs
15351533
EOF
1536-
if (defined $makedepprog && $makedepprog =~ /\/makedepend/) {
1534+
if ($makedep_scheme eq 'makedepend') {
15371535
$recipe .= <<"EOF";
15381536
\$(MAKEDEPEND) -f- -Y -- $incs $cmdflags -- $srcs 2>/dev/null \\
15391537
> $dep

Configurations/windows-makefile.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ distclean: clean
457457

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

463463
# Install helper targets #############################################
@@ -809,7 +809,7 @@ EOF
809809
lib => ' $(LIB_ASFLAGS)',
810810
dso => ' $(DSO_ASFLAGS)',
811811
bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}};
812-
my $makedepprog = $config{makedepprog};
812+
my $makedepcmd = $config{makedepcmd} unless $disabled{makedepend};
813813
if ($srcs[0] =~ /\.rc$/) {
814814
my $res = platform->res($args{obj});
815815
return <<"EOF";
@@ -836,7 +836,7 @@ $obj: $deps
836836
\$(CC) $cflags $defs -c \$(COUTFLAG)\$\@ $srcs
837837
EOF
838838
$recipe .= <<"EOF" unless $disabled{makedepend};
839-
cmd /C "$target{make_depend} $cflags $defs $srcs > $dep 2>&1"
839+
cmd /C "$makedepcmd $cflags $defs $srcs > $dep 2>&1"
840840
EOF
841841
return $recipe;
842842
}

Configure

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,22 +1533,32 @@ unless ($disabled{asm}) {
15331533

15341534
# Check for makedepend capabilities.
15351535
if (!$disabled{makedepend}) {
1536-
if ($config{target} =~ /^(VC|BC|vms)-/) {
1537-
# For VC-, BC- and vms- targets, there's nothing more to do here. The
1538-
# functionality is hard coded in the corresponding build files for
1539-
# cl/cpp32 (Windows) and CC/DECC (VMS).
1536+
# If the attribute makedep_scheme is defined, then we assume that the
1537+
# config target and its associated build file are programmed to deal
1538+
# with it.
1539+
# If makedep_scheme is undefined, we go looking for GCC compatible
1540+
# dependency making, and if that's not available, we try to fall back
1541+
# on 'makedepend'.
1542+
if ($target{makedep_scheme}) {
1543+
$config{makedep_scheme} = $target{makedep_scheme};
1544+
# If the makedepcmd attribute is defined, copy it. If not, the
1545+
# build files will have to fend for themselves.
1546+
$config{makedepcmd} = $target{makedepcmd} if $target{makedepcmd};
15401547
} elsif (($predefined_C{__GNUC__} // -1) >= 3
15411548
&& !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) {
15421549
# We know that GNU C version 3 and up as well as all clang
15431550
# versions support dependency generation, but Xcode did not
15441551
# handle $cc -M before clang support (but claims __GNUC__ = 3)
1545-
$config{makedepprog} = "\$(CROSS_COMPILE)$config{CC}";
1552+
$config{makedep_scheme} = 'gcc';
15461553
} else {
1547-
# In all other cases, we look for 'makedepend', and disable the
1548-
# capability if not found.
1549-
$config{makedepprog} = which('makedepend');
1550-
disable('unavailable', 'makedepend') unless $config{makedepprog};
1554+
# In all other cases, we look for 'makedepend', and set the
1555+
# makedep_scheme value if we found it.
1556+
$config{makedepcmd} = which('makedepend');
1557+
$config{makedep_scheme} = 'makedepend' if $config{makedepcmd};
15511558
}
1559+
1560+
# If no depend scheme is set, we disable makedepend
1561+
disable('unavailable', 'makedepend') unless $config{makedep_scheme};
15521562
}
15531563

15541564
if (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') {

util/add-depends.pl

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,66 @@
154154
}
155155
return ($objfile, $depconv_cache{$line})
156156
if defined $depconv_cache{$line};
157-
print STDERR "DEBUG[VMS C]: ignoring $objfile <- $line\n"
157+
print STDERR "DEBUG[$producer]: ignoring $objfile <- $line\n"
158158
if $debug;
159159

160160
return undef;
161161
},
162162
'VC' =>
163163
sub {
164-
# On Windows, with Microsoft Visual C the flags /Zs /showIncludes
165-
# give us the necessary output to be able to create dependencies
166-
# that nmake (or any 'make' implementation) should be able to read,
167-
# with a bit of help. The output we're interested in looks like
168-
# this (it always starts the same)
164+
# With Microsoft Visual C the flags /Zs /showIncludes give us the
165+
# necessary output to be able to create dependencies that nmake
166+
# (or any 'make' implementation) should be able to read, with a
167+
# bit of help. The output we're interested in looks something
168+
# like this (it always starts the same)
169169
#
170170
# Note: including file: {whatever header file}
171171
#
172+
# Since there's no object file name at all in that information,
173+
# we must construct it ourselves.
174+
175+
(my $objfile = shift) =~ s|\.d$|.obj|i;
176+
my $line = shift;
177+
178+
# There are also other lines mixed in, for example compiler
179+
# warnings, so we simply discard anything that doesn't start with
180+
# the Note:
181+
182+
if (/^Note: including file: */) {
183+
(my $tail = $') =~ s/\s*\R$//;
184+
185+
# VC gives us absolute paths for all include files, so to
186+
# remove system header dependencies, we need to check that
187+
# they don't match $abs_srcdir or $abs_blddir.
188+
$tail = canonpath($tail);
189+
190+
unless (defined $depconv_cache{$tail}) {
191+
my $dep = $tail;
192+
# Since we have already pre-populated the cache with
193+
# mappings for generated headers, we only need to deal
194+
# with the source tree.
195+
if ($dep =~ s|^\Q$abs_srcdir\E\\|\$(SRCDIR)\\|i) {
196+
$depconv_cache{$tail} = $dep;
197+
}
198+
}
199+
return ($objfile, '"'.$depconv_cache{$tail}.'"')
200+
if defined $depconv_cache{$tail};
201+
print STDERR "DEBUG[$producer]: ignoring $objfile <- $tail\n"
202+
if $debug;
203+
}
204+
205+
return undef;
206+
},
207+
'embarcadero' =>
208+
sub {
172209
# With Embarcadero C++Builder's preprocessor (cpp32.exe) the -Hp
173210
# flag gives us the preprocessed output annotated with the following
174211
# note whenever a #include file is read:
175212
#
176213
# Including ->->{whatever header file}
177214
#
178215
# where each "->" indicates the nesting level of the #include. The
179-
# logic here is otherwise the same as the 'VC' case.
216+
# logic here is otherwise the same as the 'VC' scheme.
180217
#
181218
# Since there's no object file name at all in that information,
182219
# we must construct it ourselves.
@@ -188,13 +225,13 @@
188225
# warnings, so we simply discard anything that doesn't start with
189226
# the Note:
190227

191-
if (/^Note: including file: */ or /^Including (->)*/) {
228+
if (/^Including (->)*/) {
192229
(my $tail = $') =~ s/\s*\R$//;
193230

194-
# VC gives us absolute paths for all include files, so to
195-
# remove system header dependencies, we need to check that
196-
# they don't match $abs_srcdir or $abs_blddir. C++Builder gives
197-
# us relative paths when possible, so convert to absolute paths.
231+
# C++Builder gives us relative paths when possible, so to
232+
# remove system header dependencies, we convert them to
233+
# absolute paths and check that they don't match $abs_srcdir
234+
# or $abs_blddir, just as the 'VC' scheme.
198235
$tail = rel2abs($tail);
199236

200237
unless (defined $depconv_cache{$tail}) {
@@ -208,7 +245,7 @@
208245
}
209246
return ($objfile, '"'.$depconv_cache{$tail}.'"')
210247
if defined $depconv_cache{$tail};
211-
print STDERR "DEBUG[VC]: ignoring $objfile <- $tail\n"
248+
print STDERR "DEBUG[$producer]: ignoring $objfile <- $tail\n"
212249
if $debug;
213250
}
214251

@@ -220,6 +257,7 @@
220257
'makedepend' => "\\",
221258
'VMS C' => "-",
222259
'VC' => "\\",
260+
'embarcadero' => "\\",
223261
);
224262

225263
die "Producer unrecognised: $producer\n"

0 commit comments

Comments
 (0)