1 {- # -*- Mode: perl -*-
3 # A cache of objects for which a recipe has already been generated
6 # resolvedepends and reducedepends work in tandem to make sure
7 # there are no duplicate dependencies and that they are in the
8 # right order. This is especially used to sort the list of
9 # libraries that a build depends on.
12 my @listsofar = @_; # to check if we're looping
13 my @list = @{$unified_info{depends}->{$thing}};
16 foreach my $item (@list) {
17 # It's time to break off when the dependency list starts looping
18 next if grep { $_ eq $item } @listsofar;
19 push @newlist, $item, resolvedepends($item, @listsofar, $item);
28 my $item = shift @list;
30 unless grep { $item eq $_ } @list;
35 # doobj is responsible for producing all the recipes that build
36 # object files as well as dependency files.
39 return "" if $cache{$obj};
40 (my $obj_no_o = $obj) =~ s|\.o$||;
43 if (@{$unified_info{sources}->{$obj}}) {
44 $OUT .= src2obj(obj => $obj_no_o,
45 srcs => $unified_info{sources}->{$obj},
46 deps => [ reducedepends(resolvedepends($obj)) ],
47 incs => [ @{$unified_info{includes}->{$bin}},
48 @{$unified_info{includes}->{$obj}} ],
54 # dolib is responsible for building libraries. It will call
55 # libobj2shlib is shared libraries are produced, and obj2lib in all
56 # cases. It also makes sure all object files for the library are
60 return "" if $cache{$lib};
61 unless ($disabled{shared}) {
63 $unified_info{ordinals}->{$lib}
64 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
65 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
67 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
68 @{$unified_info{sources}->{$lib}} ],
69 deps => [ reducedepends(resolvedepends($lib)) ],
72 $OUT .= obj2lib(lib => $lib,
73 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
74 @{$unified_info{sources}->{$lib}} ]);
75 map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
79 # doengine is responsible for building engines. It will call
80 # obj2dso, and also makes sure all object files for the library
84 return "" if $cache{$lib};
85 $OUT .= obj2dso(lib => $lib,
86 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
87 @{$unified_info{sources}->{$lib}} ],
88 deps => [ resolvedepends($lib) ]);
89 map { doobj($_, $lib, intent => "dso") } @{$unified_info{sources}->{$lib}};
93 # dobin is responsible for building programs. It will call obj2bin,
94 # and also makes sure all object files for the library are built.
97 return "" if $cache{$bin};
98 my $deps = [ reducedepends(resolvedepends($bin)) ];
99 $OUT .= obj2bin(bin => $bin,
100 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
101 @{$unified_info{sources}->{$bin}} ],
103 map { doobj($_, $bin, intent => "bin") } @{$unified_info{sources}->{$bin}};
107 # dobin is responsible for building scripts from templates. It will
111 return "" if $cache{$script};
112 $OUT .= in2script(script => $script,
113 sources => $unified_info{sources}->{$script});
117 # Build all known libraries, engines, programs and scripts.
118 # Everything else will be handled as a consequence.
119 map { dolib($_) } @{$unified_info{libraries}};
120 map { doengine($_) } @{$unified_info{engines}};
121 map { dobin($_) } @{$unified_info{programs}};
122 map { doscript($_) } @{$unified_info{scripts}};
124 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
125 # they are added here.
126 $OUT .= $_."\n" foreach(@{$unified_info{rawlines}});