1 {- # -*- Mode: perl -*-
5 # A cache of objects for which a recipe has already been generated
8 # resolvedepends and reducedepends work in tandem to make sure
9 # there are no duplicate dependencies and that they are in the
10 # right order. This is especially used to sort the list of
11 # libraries that a build depends on.
14 my @listsofar = @_; # to check if we're looping
15 my @list = @{$unified_info{depends}->{$thing}};
18 foreach my $item (@list) {
19 # It's time to break off when the dependency list starts looping
20 next if grep { $_ eq $item } @listsofar;
21 push @newlist, $item, resolvedepends($item, @listsofar, $item);
30 my $item = shift @list;
32 unless grep { $item eq $_ } @list;
37 # is_installed checks if a given file will be installed (i.e. they are
38 # not defined _NO_INST in build.info)
41 if (grep { $product eq $_ }
42 map { (@{$unified_info{install}->{$_}}) }
43 keys %{$unified_info{install}}) {
49 # dogenerate is responsible for producing all the recipes that build
50 # generated source files. It recurses in case a dependency is also a
51 # generated source file.
54 return "" if $cache{$src};
58 if ($unified_info{generate}->{$src}) {
59 die "$src is generated by Configure, should not appear in build file\n"
60 if ref $unified_info{generate}->{$src} eq "";
61 my $script = $unified_info{generate}->{$src}->[0];
62 $OUT .= generatesrc(src => $src,
63 generator => $unified_info{generate}->{$src},
64 generator_incs => $unified_info{includes}->{$script},
65 generator_deps => $unified_info{depends}->{$script},
66 deps => $unified_info{depends}->{$src},
67 incs => [ @{$unified_info{includes}->{$bin}},
68 @{$unified_info{includes}->{$obj}} ],
70 foreach (@{$unified_info{depends}->{$src}}) {
71 dogenerate($_, $obj, $bin, %opts);
77 # doobj is responsible for producing all the recipes that build
78 # object files as well as dependency files.
81 return "" if $cache{$obj};
82 (my $obj_no_o = $obj) =~ s|\.o$||;
85 if (@{$unified_info{sources}->{$obj}}) {
86 $OUT .= src2obj(obj => $obj_no_o,
88 srcs => $unified_info{sources}->{$obj},
89 deps => $unified_info{depends}->{$obj},
90 incs => [ @{$unified_info{includes}->{$bin}},
91 @{$unified_info{includes}->{$obj}} ],
93 foreach ((@{$unified_info{sources}->{$obj}},
94 @{$unified_info{depends}->{$obj}})) {
95 dogenerate($_, $obj, $bin, %opts);
101 # dolib is responsible for building libraries. It will call
102 # libobj2shlib is shared libraries are produced, and obj2lib in all
103 # cases. It also makes sure all object files for the library are
107 return "" if $cache{$lib};
108 unless ($disabled{shared}) {
110 $unified_info{ordinals}->{$lib}
111 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
112 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
114 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
115 (@{$unified_info{sources}->{$lib}},
116 @{$unified_info{shared_sources}->{$lib}}) ],
117 deps => [ reducedepends(resolvedepends($lib)) ],
118 installed => is_installed($lib),
120 foreach (@{$unified_info{shared_sources}->{$lib}}) {
121 doobj($_, $lib, intent => "lib", installed => is_installed($lib));
124 $OUT .= obj2lib(lib => $lib,
125 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
126 @{$unified_info{sources}->{$lib}} ]);
127 foreach (@{$unified_info{sources}->{$lib}}) {
128 doobj($_, $lib, intent => "lib");
133 # doengine is responsible for building engines. It will call
134 # obj2dso, and also makes sure all object files for the library
138 return "" if $cache{$lib};
139 $OUT .= obj2dso(lib => $lib,
140 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
141 (@{$unified_info{sources}->{$lib}},
142 @{$unified_info{shared_sources}->{$lib}}) ],
143 deps => [ resolvedepends($lib) ],
144 installed => is_installed($lib));
145 foreach ((@{$unified_info{sources}->{$lib}},
146 @{$unified_info{shared_sources}->{$lib}})) {
147 doobj($_, $lib, intent => "dso", installed => is_installed($lib));
152 # dobin is responsible for building programs. It will call obj2bin,
153 # and also makes sure all object files for the library are built.
156 return "" if $cache{$bin};
157 my $deps = [ reducedepends(resolvedepends($bin)) ];
158 $OUT .= obj2bin(bin => $bin,
159 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
160 @{$unified_info{sources}->{$bin}} ],
162 installed => is_installed($bin));
163 foreach (@{$unified_info{sources}->{$bin}}) {
164 doobj($_, $bin, intent => "bin", installed => is_installed($bin));
169 # dobin is responsible for building scripts from templates. It will
173 return "" if $cache{$script};
174 $OUT .= in2script(script => $script,
175 sources => $unified_info{sources}->{$script},
176 installed => is_installed($script));
182 return "" if !exists(&generatedir) or $cache{$dir};
183 $OUT .= generatedir(dir => $dir,
184 deps => $unified_info{dirinfo}->{$dir}->{deps},
185 %{$unified_info{dirinfo}->{$_}->{products}});
189 # Start with populating the cache with all the overrides
190 %cache = map { $_ => 1 } @{$unified_info{overrides}};
192 # For convenience collect information regarding directories where
193 # files are generated, those generated files and the end product
194 # they end up in where applicable. Then, add build rules for those
196 if (exists &generatedir) {
197 my %loopinfo = ( "dso" => [ @{$unified_info{engines}} ],
198 "lib" => [ @{$unified_info{libraries}} ],
199 "bin" => [ @{$unified_info{programs}} ],
200 "script" => [ @{$unified_info{scripts}} ] );
201 foreach my $type (keys %loopinfo) {
202 foreach my $product (@{$loopinfo{$type}}) {
204 my $pd = dirname($product);
206 # We already have a "test" target, and the current directory
207 # is just silly to make a target for
208 $dirs{$pd} = 1 unless $pd eq "test" || $pd eq ".";
210 foreach (@{$unified_info{sources}->{$product}}) {
213 # We don't want to create targets for source directories
214 # when building out of source
215 next if ($config{sourcedir} ne $config{builddir}
216 && $d =~ m|^\Q$config{sourcedir}\E|);
217 # We already have a "test" target, and the current directory
218 # is just silly to make a target for
219 next if $d eq "test" || $d eq ".";
222 push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
225 foreach (keys %dirs) {
226 push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
233 # Build mandatory generated headers
234 foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
236 # Build all known libraries, engines, programs and scripts.
237 # Everything else will be handled as a consequence.
238 foreach (@{$unified_info{libraries}}) { dolib($_); }
239 foreach (@{$unified_info{engines}}) { doengine($_); }
240 foreach (@{$unified_info{programs}}) { dobin($_); }
241 foreach (@{$unified_info{scripts}}) { doscript($_); }
243 foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
245 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
246 # they are added here.
247 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};