2016-01-29 23:57:33 +00:00
|
|
|
{- # -*- Mode: perl -*-
|
|
|
|
|
2016-04-02 20:26:38 +00:00
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
# A cache of objects for which a recipe has already been generated
|
|
|
|
my %cache;
|
2016-01-29 23:57:33 +00:00
|
|
|
|
|
|
|
# resolvedepends and reducedepends work in tandem to make sure
|
|
|
|
# there are no duplicate dependencies and that they are in the
|
|
|
|
# right order. This is especially used to sort the list of
|
|
|
|
# libraries that a build depends on.
|
2016-11-09 19:01:51 +00:00
|
|
|
sub extensionlesslib {
|
|
|
|
my @result = map { $_ =~ /(\.a)?$/; $` } @_;
|
|
|
|
return @result if wantarray;
|
|
|
|
return $result[0];
|
|
|
|
}
|
2016-01-29 23:57:33 +00:00
|
|
|
sub resolvedepends {
|
|
|
|
my $thing = shift;
|
2016-11-09 19:01:51 +00:00
|
|
|
my $extensionlessthing = extensionlesslib($thing);
|
2016-01-29 23:57:33 +00:00
|
|
|
my @listsofar = @_; # to check if we're looping
|
2017-04-18 14:24:23 +00:00
|
|
|
my @list = @{$unified_info{depends}->{$thing} //
|
|
|
|
$unified_info{depends}->{$extensionlessthing}};
|
2016-01-29 23:57:33 +00:00
|
|
|
my @newlist = ();
|
|
|
|
if (scalar @list) {
|
|
|
|
foreach my $item (@list) {
|
2016-11-09 19:01:51 +00:00
|
|
|
my $extensionlessitem = extensionlesslib($item);
|
2016-01-29 23:57:33 +00:00
|
|
|
# It's time to break off when the dependency list starts looping
|
2016-11-09 19:01:51 +00:00
|
|
|
next if grep { extensionlesslib($_) eq $extensionlessitem } @listsofar;
|
2016-01-29 23:57:33 +00:00
|
|
|
push @newlist, $item, resolvedepends($item, @listsofar, $item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@newlist;
|
|
|
|
}
|
|
|
|
sub reducedepends {
|
|
|
|
my @list = @_;
|
|
|
|
my @newlist = ();
|
2017-04-18 14:24:23 +00:00
|
|
|
my %replace = ();
|
2016-01-29 23:57:33 +00:00
|
|
|
while (@list) {
|
|
|
|
my $item = shift @list;
|
2016-11-09 19:01:51 +00:00
|
|
|
my $extensionlessitem = extensionlesslib($item);
|
2017-04-18 14:24:23 +00:00
|
|
|
if (grep { $extensionlessitem eq extensionlesslib($_) } @list) {
|
|
|
|
if ($item ne $extensionlessitem) {
|
2017-11-12 00:03:10 +00:00
|
|
|
# If this instance of the library is explicitly static, we
|
2017-04-18 14:24:23 +00:00
|
|
|
# prefer that to any shared library name, since it must have
|
|
|
|
# been done on purpose.
|
|
|
|
$replace{$extensionlessitem} = $item;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
push @newlist, $item;
|
|
|
|
}
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
2017-04-18 14:24:23 +00:00
|
|
|
map { $replace{$_} // $_; } @newlist;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 08:04:09 +00:00
|
|
|
# dogenerate is responsible for producing all the recipes that build
|
|
|
|
# generated source files. It recurses in case a dependency is also a
|
|
|
|
# generated source file.
|
2016-03-07 13:37:00 +00:00
|
|
|
sub dogenerate {
|
|
|
|
my $src = shift;
|
|
|
|
return "" if $cache{$src};
|
2016-03-10 08:04:09 +00:00
|
|
|
my $obj = shift;
|
|
|
|
my $bin = shift;
|
2016-03-07 13:37:00 +00:00
|
|
|
my %opts = @_;
|
|
|
|
if ($unified_info{generate}->{$src}) {
|
2016-05-16 12:54:39 +00:00
|
|
|
die "$src is generated by Configure, should not appear in build file\n"
|
|
|
|
if ref $unified_info{generate}->{$src} eq "";
|
2016-04-21 12:30:08 +00:00
|
|
|
my $script = $unified_info{generate}->{$src}->[0];
|
2016-03-07 13:37:00 +00:00
|
|
|
$OUT .= generatesrc(src => $src,
|
2018-10-04 15:41:12 +00:00
|
|
|
product => $bin,
|
2016-03-07 13:37:00 +00:00
|
|
|
generator => $unified_info{generate}->{$src},
|
2016-04-21 12:30:08 +00:00
|
|
|
generator_incs => $unified_info{includes}->{$script},
|
|
|
|
generator_deps => $unified_info{depends}->{$script},
|
2016-03-07 13:37:00 +00:00
|
|
|
deps => $unified_info{depends}->{$src},
|
2018-09-10 00:18:22 +00:00
|
|
|
incs => [ @{$unified_info{includes}->{$obj}},
|
|
|
|
@{$unified_info{includes}->{$bin}} ],
|
2018-11-02 12:08:38 +00:00
|
|
|
defs => [ @{$unified_info{defines}->{$obj}},
|
|
|
|
@{$unified_info{defines}->{$bin}} ],
|
2016-03-07 13:37:00 +00:00
|
|
|
%opts);
|
|
|
|
foreach (@{$unified_info{depends}->{$src}}) {
|
2016-03-10 08:04:09 +00:00
|
|
|
dogenerate($_, $obj, $bin, %opts);
|
2016-03-07 13:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$cache{$src} = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-29 23:57:33 +00:00
|
|
|
# doobj is responsible for producing all the recipes that build
|
|
|
|
# object files as well as dependency files.
|
|
|
|
sub doobj {
|
|
|
|
my $obj = shift;
|
2016-02-27 18:12:14 +00:00
|
|
|
return "" if $cache{$obj};
|
2016-01-29 23:57:33 +00:00
|
|
|
my $bin = shift;
|
2016-02-19 21:02:41 +00:00
|
|
|
my %opts = @_;
|
2016-01-29 23:57:33 +00:00
|
|
|
if (@{$unified_info{sources}->{$obj}}) {
|
2017-12-04 13:27:58 +00:00
|
|
|
$OUT .= src2obj(obj => $obj,
|
2016-09-08 16:09:47 +00:00
|
|
|
product => $bin,
|
2016-01-29 23:57:33 +00:00
|
|
|
srcs => $unified_info{sources}->{$obj},
|
2016-03-07 13:37:00 +00:00
|
|
|
deps => $unified_info{depends}->{$obj},
|
2018-09-10 00:18:22 +00:00
|
|
|
incs => [ @{$unified_info{includes}->{$obj}},
|
|
|
|
@{$unified_info{includes}->{$bin}} ],
|
2018-11-02 12:08:38 +00:00
|
|
|
defs => [ @{$unified_info{defines}->{$obj}},
|
|
|
|
@{$unified_info{defines}->{$bin}} ],
|
2016-02-19 21:02:41 +00:00
|
|
|
%opts);
|
2016-03-07 13:37:00 +00:00
|
|
|
foreach ((@{$unified_info{sources}->{$obj}},
|
|
|
|
@{$unified_info{depends}->{$obj}})) {
|
2016-03-10 08:04:09 +00:00
|
|
|
dogenerate($_, $obj, $bin, %opts);
|
2016-03-07 13:37:00 +00:00
|
|
|
}
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
2016-02-27 18:12:14 +00:00
|
|
|
$cache{$obj} = 1;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# dolib is responsible for building libraries. It will call
|
2018-09-12 08:59:06 +00:00
|
|
|
# obj2shlib is shared libraries are produced, and obj2lib in all
|
2016-01-29 23:57:33 +00:00
|
|
|
# cases. It also makes sure all object files for the library are
|
|
|
|
# built.
|
|
|
|
sub dolib {
|
|
|
|
my $lib = shift;
|
2016-02-27 18:12:14 +00:00
|
|
|
return "" if $cache{$lib};
|
2017-04-18 14:24:23 +00:00
|
|
|
unless ($disabled{shared} || $lib =~ /\.a$/) {
|
2018-09-12 08:59:06 +00:00
|
|
|
my $obj2shlib = defined &obj2shlib ? \&obj2shlib : \&libobj2shlib;
|
2018-10-23 13:45:24 +00:00
|
|
|
$OUT .= $obj2shlib->(lib => $lib,
|
2018-11-07 10:10:50 +00:00
|
|
|
attrs => $unified_info{attributes}->{$lib},
|
2018-09-10 00:21:40 +00:00
|
|
|
objs => $unified_info{shared_sources}->{$lib},
|
2019-01-22 14:46:54 +00:00
|
|
|
deps => [ reducedepends(resolvedepends($lib)) ]);
|
2017-12-04 13:27:58 +00:00
|
|
|
foreach ((@{$unified_info{shared_sources}->{$lib}},
|
|
|
|
@{$unified_info{sources}->{$lib}})) {
|
|
|
|
# If this is somehow a compiled object, take care of it that way
|
|
|
|
# Otherwise, it might simply be generated
|
|
|
|
if (defined $unified_info{sources}->{$_}) {
|
2019-01-22 14:46:54 +00:00
|
|
|
doobj($_, $lib, intent => "shlib",
|
|
|
|
attrs => $unified_info{attributes}->{$lib});
|
2017-12-04 13:27:58 +00:00
|
|
|
} else {
|
|
|
|
dogenerate($_, undef, undef, intent => "lib");
|
|
|
|
}
|
2016-04-06 13:02:57 +00:00
|
|
|
}
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
$OUT .= obj2lib(lib => $lib,
|
2018-11-07 10:10:50 +00:00
|
|
|
attrs => $unified_info{attributes}->{$lib},
|
2017-12-04 13:27:58 +00:00
|
|
|
objs => [ @{$unified_info{sources}->{$lib}} ]);
|
2016-04-06 13:02:57 +00:00
|
|
|
foreach (@{$unified_info{sources}->{$lib}}) {
|
2019-01-22 14:46:54 +00:00
|
|
|
doobj($_, $lib, intent => "lib",
|
|
|
|
attrs => $unified_info{attributes}->{$lib});
|
2016-04-06 13:02:57 +00:00
|
|
|
}
|
2016-02-27 18:12:14 +00:00
|
|
|
$cache{$lib} = 1;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 23:06:50 +00:00
|
|
|
# domodule is responsible for building modules. It will call
|
2016-02-15 17:45:54 +00:00
|
|
|
# obj2dso, and also makes sure all object files for the library
|
2016-01-29 23:57:33 +00:00
|
|
|
# are built.
|
2019-01-30 23:06:50 +00:00
|
|
|
sub domodule {
|
2016-01-29 23:57:33 +00:00
|
|
|
my $lib = shift;
|
2016-02-27 18:12:14 +00:00
|
|
|
return "" if $cache{$lib};
|
2016-02-15 17:45:54 +00:00
|
|
|
$OUT .= obj2dso(lib => $lib,
|
2018-11-07 10:10:50 +00:00
|
|
|
attrs => $unified_info{attributes}->{$lib},
|
2019-03-31 13:14:00 +00:00
|
|
|
objs => $unified_info{sources}->{$lib},
|
2019-01-22 14:46:54 +00:00
|
|
|
deps => [ resolvedepends($lib) ]);
|
2019-03-31 13:14:00 +00:00
|
|
|
foreach (@{$unified_info{sources}->{$lib}}) {
|
2018-10-04 15:41:12 +00:00
|
|
|
# If this is somehow a compiled object, take care of it that way
|
|
|
|
# Otherwise, it might simply be generated
|
|
|
|
if (defined $unified_info{sources}->{$_}) {
|
2019-01-22 14:46:54 +00:00
|
|
|
doobj($_, $lib, intent => "dso",
|
|
|
|
attrs => $unified_info{attributes}->{$lib});
|
2018-10-04 15:41:12 +00:00
|
|
|
} else {
|
|
|
|
dogenerate($_, undef, $lib, intent => "dso");
|
|
|
|
}
|
2016-04-06 13:02:57 +00:00
|
|
|
}
|
2016-02-27 18:12:14 +00:00
|
|
|
$cache{$lib} = 1;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# dobin is responsible for building programs. It will call obj2bin,
|
|
|
|
# and also makes sure all object files for the library are built.
|
|
|
|
sub dobin {
|
|
|
|
my $bin = shift;
|
2016-02-27 18:12:14 +00:00
|
|
|
return "" if $cache{$bin};
|
2016-01-29 23:57:33 +00:00
|
|
|
my $deps = [ reducedepends(resolvedepends($bin)) ];
|
|
|
|
$OUT .= obj2bin(bin => $bin,
|
2018-11-07 10:10:50 +00:00
|
|
|
attrs => $unified_info{attributes}->{$bin},
|
2017-12-04 13:27:58 +00:00
|
|
|
objs => [ @{$unified_info{sources}->{$bin}} ],
|
2019-01-22 14:46:54 +00:00
|
|
|
deps => $deps);
|
2016-04-06 13:02:57 +00:00
|
|
|
foreach (@{$unified_info{sources}->{$bin}}) {
|
2019-01-22 14:46:54 +00:00
|
|
|
doobj($_, $bin, intent => "bin",
|
|
|
|
attrs => $unified_info{attributes}->{$bin});
|
2016-04-06 13:02:57 +00:00
|
|
|
}
|
2016-02-27 18:12:14 +00:00
|
|
|
$cache{$bin} = 1;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# dobin is responsible for building scripts from templates. It will
|
|
|
|
# call in2script.
|
|
|
|
sub doscript {
|
|
|
|
my $script = shift;
|
2016-02-27 18:12:14 +00:00
|
|
|
return "" if $cache{$script};
|
2016-01-29 23:57:33 +00:00
|
|
|
$OUT .= in2script(script => $script,
|
2018-11-07 10:10:50 +00:00
|
|
|
attrs => $unified_info{attributes}->{$script},
|
2019-01-22 14:46:54 +00:00
|
|
|
sources => $unified_info{sources}->{$script});
|
2016-02-27 18:12:14 +00:00
|
|
|
$cache{$script} = 1;
|
2016-01-29 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 20:26:38 +00:00
|
|
|
sub dodir {
|
|
|
|
my $dir = shift;
|
|
|
|
return "" if !exists(&generatedir) or $cache{$dir};
|
|
|
|
$OUT .= generatedir(dir => $dir,
|
|
|
|
deps => $unified_info{dirinfo}->{$dir}->{deps},
|
|
|
|
%{$unified_info{dirinfo}->{$_}->{products}});
|
|
|
|
$cache{$dir} = 1;
|
|
|
|
}
|
|
|
|
|
2016-03-07 13:50:37 +00:00
|
|
|
# Start with populating the cache with all the overrides
|
|
|
|
%cache = map { $_ => 1 } @{$unified_info{overrides}};
|
|
|
|
|
2016-06-13 19:57:51 +00:00
|
|
|
# Build mandatory generated headers
|
|
|
|
foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
|
|
|
|
|
2019-01-30 23:06:50 +00:00
|
|
|
# Build all known libraries, modules, programs and scripts.
|
2016-01-29 23:57:33 +00:00
|
|
|
# Everything else will be handled as a consequence.
|
2016-04-06 15:30:01 +00:00
|
|
|
foreach (@{$unified_info{libraries}}) { dolib($_); }
|
2019-01-30 23:06:50 +00:00
|
|
|
foreach (@{$unified_info{modules}}) { domodule($_); }
|
2016-04-06 15:30:01 +00:00
|
|
|
foreach (@{$unified_info{programs}}) { dobin($_); }
|
|
|
|
foreach (@{$unified_info{scripts}}) { doscript($_); }
|
2016-01-29 23:57:33 +00:00
|
|
|
|
2016-04-02 20:26:38 +00:00
|
|
|
foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
|
2016-01-29 23:57:33 +00:00
|
|
|
-}
|