2016-01-30 07:57:33 +08:00
|
|
|
{- # -*- Mode: perl -*-
|
|
|
|
|
2016-04-03 04:26:38 +08:00
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
# A cache of objects for which a recipe has already been generated
|
|
|
|
my %cache;
|
2016-01-30 07:57:33 +08: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-10 03:01:51 +08:00
|
|
|
sub extensionlesslib {
|
|
|
|
my @result = map { $_ =~ /(\.a)?$/; $` } @_;
|
|
|
|
return @result if wantarray;
|
|
|
|
return $result[0];
|
|
|
|
}
|
2016-01-30 07:57:33 +08:00
|
|
|
sub resolvedepends {
|
|
|
|
my $thing = shift;
|
2016-11-10 03:01:51 +08:00
|
|
|
my $extensionlessthing = extensionlesslib($thing);
|
2016-01-30 07:57:33 +08:00
|
|
|
my @listsofar = @_; # to check if we're looping
|
2016-11-10 03:01:51 +08:00
|
|
|
my @list = @{$unified_info{depends}->{$extensionlessthing}};
|
2016-01-30 07:57:33 +08:00
|
|
|
my @newlist = ();
|
|
|
|
if (scalar @list) {
|
|
|
|
foreach my $item (@list) {
|
2016-11-10 03:01:51 +08:00
|
|
|
my $extensionlessitem = extensionlesslib($item);
|
2016-01-30 07:57:33 +08:00
|
|
|
# It's time to break off when the dependency list starts looping
|
2016-11-10 03:01:51 +08:00
|
|
|
next if grep { extensionlesslib($_) eq $extensionlessitem } @listsofar;
|
2016-01-30 07:57:33 +08:00
|
|
|
push @newlist, $item, resolvedepends($item, @listsofar, $item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@newlist;
|
|
|
|
}
|
|
|
|
sub reducedepends {
|
|
|
|
my @list = @_;
|
|
|
|
my @newlist = ();
|
|
|
|
while (@list) {
|
|
|
|
my $item = shift @list;
|
2016-11-10 03:01:51 +08:00
|
|
|
my $extensionlessitem = extensionlesslib($item);
|
2016-01-30 07:57:33 +08:00
|
|
|
push @newlist, $item
|
2016-11-10 03:01:51 +08:00
|
|
|
unless grep { $extensionlessitem eq extensionlesslib($_) } @list;
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
@newlist;
|
|
|
|
}
|
|
|
|
|
2016-09-09 00:09:47 +08:00
|
|
|
# is_installed checks if a given file will be installed (i.e. they are
|
|
|
|
# not defined _NO_INST in build.info)
|
|
|
|
sub is_installed {
|
|
|
|
my $product = shift;
|
|
|
|
if (grep { $product eq $_ }
|
|
|
|
map { (@{$unified_info{install}->{$_}}) }
|
|
|
|
keys %{$unified_info{install}}) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-10 16:04:09 +08: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 21:37:00 +08:00
|
|
|
sub dogenerate {
|
|
|
|
my $src = shift;
|
|
|
|
return "" if $cache{$src};
|
2016-03-10 16:04:09 +08:00
|
|
|
my $obj = shift;
|
|
|
|
my $bin = shift;
|
2016-03-07 21:37:00 +08:00
|
|
|
my %opts = @_;
|
|
|
|
if ($unified_info{generate}->{$src}) {
|
2016-05-16 20:54:39 +08:00
|
|
|
die "$src is generated by Configure, should not appear in build file\n"
|
|
|
|
if ref $unified_info{generate}->{$src} eq "";
|
2016-04-21 20:30:08 +08:00
|
|
|
my $script = $unified_info{generate}->{$src}->[0];
|
2016-03-07 21:37:00 +08:00
|
|
|
$OUT .= generatesrc(src => $src,
|
|
|
|
generator => $unified_info{generate}->{$src},
|
2016-04-21 20:30:08 +08:00
|
|
|
generator_incs => $unified_info{includes}->{$script},
|
|
|
|
generator_deps => $unified_info{depends}->{$script},
|
2016-03-07 21:37:00 +08:00
|
|
|
deps => $unified_info{depends}->{$src},
|
2016-03-10 16:04:09 +08:00
|
|
|
incs => [ @{$unified_info{includes}->{$bin}},
|
|
|
|
@{$unified_info{includes}->{$obj}} ],
|
2016-03-07 21:37:00 +08:00
|
|
|
%opts);
|
|
|
|
foreach (@{$unified_info{depends}->{$src}}) {
|
2016-03-10 16:04:09 +08:00
|
|
|
dogenerate($_, $obj, $bin, %opts);
|
2016-03-07 21:37:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$cache{$src} = 1;
|
|
|
|
}
|
|
|
|
|
2016-01-30 07:57:33 +08: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-28 02:12:14 +08:00
|
|
|
return "" if $cache{$obj};
|
2016-01-30 07:57:33 +08:00
|
|
|
(my $obj_no_o = $obj) =~ s|\.o$||;
|
|
|
|
my $bin = shift;
|
2016-02-20 05:02:41 +08:00
|
|
|
my %opts = @_;
|
2016-01-30 07:57:33 +08:00
|
|
|
if (@{$unified_info{sources}->{$obj}}) {
|
|
|
|
$OUT .= src2obj(obj => $obj_no_o,
|
2016-09-09 00:09:47 +08:00
|
|
|
product => $bin,
|
2016-01-30 07:57:33 +08:00
|
|
|
srcs => $unified_info{sources}->{$obj},
|
2016-03-07 21:37:00 +08:00
|
|
|
deps => $unified_info{depends}->{$obj},
|
2016-01-30 07:57:33 +08:00
|
|
|
incs => [ @{$unified_info{includes}->{$bin}},
|
2016-02-20 05:02:41 +08:00
|
|
|
@{$unified_info{includes}->{$obj}} ],
|
|
|
|
%opts);
|
2016-03-07 21:37:00 +08:00
|
|
|
foreach ((@{$unified_info{sources}->{$obj}},
|
|
|
|
@{$unified_info{depends}->{$obj}})) {
|
2016-03-10 16:04:09 +08:00
|
|
|
dogenerate($_, $obj, $bin, %opts);
|
2016-03-07 21:37:00 +08:00
|
|
|
}
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
2016-02-28 02:12:14 +08:00
|
|
|
$cache{$obj} = 1;
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# dolib is responsible for building libraries. It will call
|
|
|
|
# libobj2shlib is shared libraries are produced, and obj2lib in all
|
|
|
|
# cases. It also makes sure all object files for the library are
|
|
|
|
# built.
|
|
|
|
sub dolib {
|
|
|
|
my $lib = shift;
|
2016-02-28 02:12:14 +08:00
|
|
|
return "" if $cache{$lib};
|
2016-02-22 20:52:46 +08:00
|
|
|
unless ($disabled{shared}) {
|
2016-01-30 07:57:33 +08:00
|
|
|
my %ordinals =
|
|
|
|
$unified_info{ordinals}->{$lib}
|
|
|
|
? (ordinals => $unified_info{ordinals}->{$lib}) : ();
|
|
|
|
$OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
|
|
|
|
lib => $lib,
|
|
|
|
objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
|
2016-03-29 22:45:03 +08:00
|
|
|
(@{$unified_info{sources}->{$lib}},
|
|
|
|
@{$unified_info{shared_sources}->{$lib}}) ],
|
2016-01-30 07:57:33 +08:00
|
|
|
deps => [ reducedepends(resolvedepends($lib)) ],
|
2016-09-09 00:09:47 +08:00
|
|
|
installed => is_installed($lib),
|
2016-01-30 07:57:33 +08:00
|
|
|
%ordinals);
|
2016-04-06 21:02:57 +08:00
|
|
|
foreach (@{$unified_info{shared_sources}->{$lib}}) {
|
2016-09-09 00:09:47 +08:00
|
|
|
doobj($_, $lib, intent => "lib", installed => is_installed($lib));
|
2016-04-06 21:02:57 +08:00
|
|
|
}
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
$OUT .= obj2lib(lib => $lib,
|
|
|
|
objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
|
|
|
|
@{$unified_info{sources}->{$lib}} ]);
|
2016-04-06 21:02:57 +08:00
|
|
|
foreach (@{$unified_info{sources}->{$lib}}) {
|
|
|
|
doobj($_, $lib, intent => "lib");
|
|
|
|
}
|
2016-02-28 02:12:14 +08:00
|
|
|
$cache{$lib} = 1;
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# doengine is responsible for building engines. It will call
|
2016-02-16 01:45:54 +08:00
|
|
|
# obj2dso, and also makes sure all object files for the library
|
2016-01-30 07:57:33 +08:00
|
|
|
# are built.
|
|
|
|
sub doengine {
|
|
|
|
my $lib = shift;
|
2016-02-28 02:12:14 +08:00
|
|
|
return "" if $cache{$lib};
|
2016-02-16 01:45:54 +08:00
|
|
|
$OUT .= obj2dso(lib => $lib,
|
|
|
|
objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
|
2016-03-29 22:45:03 +08:00
|
|
|
(@{$unified_info{sources}->{$lib}},
|
|
|
|
@{$unified_info{shared_sources}->{$lib}}) ],
|
2016-09-09 00:09:47 +08:00
|
|
|
deps => [ resolvedepends($lib) ],
|
|
|
|
installed => is_installed($lib));
|
2016-04-06 21:02:57 +08:00
|
|
|
foreach ((@{$unified_info{sources}->{$lib}},
|
|
|
|
@{$unified_info{shared_sources}->{$lib}})) {
|
2016-09-09 00:09:47 +08:00
|
|
|
doobj($_, $lib, intent => "dso", installed => is_installed($lib));
|
2016-04-06 21:02:57 +08:00
|
|
|
}
|
2016-02-28 02:12:14 +08:00
|
|
|
$cache{$lib} = 1;
|
2016-01-30 07:57:33 +08: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-28 02:12:14 +08:00
|
|
|
return "" if $cache{$bin};
|
2016-01-30 07:57:33 +08:00
|
|
|
my $deps = [ reducedepends(resolvedepends($bin)) ];
|
|
|
|
$OUT .= obj2bin(bin => $bin,
|
|
|
|
objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
|
|
|
|
@{$unified_info{sources}->{$bin}} ],
|
2016-09-09 00:09:47 +08:00
|
|
|
deps => $deps,
|
|
|
|
installed => is_installed($bin));
|
2016-04-06 21:02:57 +08:00
|
|
|
foreach (@{$unified_info{sources}->{$bin}}) {
|
2016-09-09 00:09:47 +08:00
|
|
|
doobj($_, $bin, intent => "bin", installed => is_installed($bin));
|
2016-04-06 21:02:57 +08:00
|
|
|
}
|
2016-02-28 02:12:14 +08:00
|
|
|
$cache{$bin} = 1;
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# dobin is responsible for building scripts from templates. It will
|
|
|
|
# call in2script.
|
|
|
|
sub doscript {
|
|
|
|
my $script = shift;
|
2016-02-28 02:12:14 +08:00
|
|
|
return "" if $cache{$script};
|
2016-01-30 07:57:33 +08:00
|
|
|
$OUT .= in2script(script => $script,
|
2016-09-09 00:09:47 +08:00
|
|
|
sources => $unified_info{sources}->{$script},
|
|
|
|
installed => is_installed($script));
|
2016-02-28 02:12:14 +08:00
|
|
|
$cache{$script} = 1;
|
2016-01-30 07:57:33 +08:00
|
|
|
}
|
|
|
|
|
2016-04-03 04:26:38 +08: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 21:50:37 +08:00
|
|
|
# Start with populating the cache with all the overrides
|
|
|
|
%cache = map { $_ => 1 } @{$unified_info{overrides}};
|
|
|
|
|
2016-04-03 04:26:38 +08:00
|
|
|
# For convenience collect information regarding directories where
|
|
|
|
# files are generated, those generated files and the end product
|
|
|
|
# they end up in where applicable. Then, add build rules for those
|
|
|
|
# directories
|
|
|
|
if (exists &generatedir) {
|
|
|
|
my %loopinfo = ( "dso" => [ @{$unified_info{engines}} ],
|
|
|
|
"lib" => [ @{$unified_info{libraries}} ],
|
|
|
|
"bin" => [ @{$unified_info{programs}} ],
|
|
|
|
"script" => [ @{$unified_info{scripts}} ] );
|
|
|
|
foreach my $type (keys %loopinfo) {
|
|
|
|
foreach my $product (@{$loopinfo{$type}}) {
|
|
|
|
my %dirs = ();
|
|
|
|
my $pd = dirname($product);
|
2016-06-06 04:12:04 +08:00
|
|
|
|
|
|
|
# We already have a "test" target, and the current directory
|
|
|
|
# is just silly to make a target for
|
|
|
|
$dirs{$pd} = 1 unless $pd eq "test" || $pd eq ".";
|
|
|
|
|
2016-04-03 04:26:38 +08:00
|
|
|
foreach (@{$unified_info{sources}->{$product}}) {
|
|
|
|
my $d = dirname($_);
|
2016-06-06 04:12:04 +08:00
|
|
|
|
|
|
|
# We don't want to create targets for source directories
|
|
|
|
# when building out of source
|
|
|
|
next if ($config{sourcedir} ne $config{builddir}
|
|
|
|
&& $d =~ m|^\Q$config{sourcedir}\E|);
|
|
|
|
# We already have a "test" target, and the current directory
|
|
|
|
# is just silly to make a target for
|
|
|
|
next if $d eq "test" || $d eq ".";
|
|
|
|
|
2016-04-03 04:26:38 +08:00
|
|
|
$dirs{$d} = 1;
|
|
|
|
push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
|
|
|
|
if $d ne $pd;
|
|
|
|
}
|
|
|
|
foreach (keys %dirs) {
|
|
|
|
push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
|
|
|
|
$product;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 03:57:51 +08:00
|
|
|
# Build mandatory generated headers
|
|
|
|
foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
|
|
|
|
|
2016-01-30 07:57:33 +08:00
|
|
|
# Build all known libraries, engines, programs and scripts.
|
|
|
|
# Everything else will be handled as a consequence.
|
2016-04-06 23:30:01 +08:00
|
|
|
foreach (@{$unified_info{libraries}}) { dolib($_); }
|
|
|
|
foreach (@{$unified_info{engines}}) { doengine($_); }
|
|
|
|
foreach (@{$unified_info{programs}}) { dobin($_); }
|
|
|
|
foreach (@{$unified_info{scripts}}) { doscript($_); }
|
2016-01-30 07:57:33 +08:00
|
|
|
|
2016-04-03 04:26:38 +08:00
|
|
|
foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
|
|
|
|
|
2016-01-30 07:57:33 +08:00
|
|
|
# Finally, should there be any applicable BEGINRAW/ENDRAW sections,
|
|
|
|
# they are added here.
|
2016-04-06 21:02:57 +08:00
|
|
|
$OUT .= $_."\n" foreach @{$unified_info{rawlines}};
|
2016-01-30 07:57:33 +08:00
|
|
|
-}
|