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.
12 sub extensionlesslib {
13 my @result = map { $_ =~ /(\.a)?$/; $` } @_;
14 return @result if wantarray;
19 my $extensionlessthing = extensionlesslib($thing);
20 my @listsofar = @_; # to check if we're looping
21 my @list = @{$unified_info{depends}->{$extensionlessthing}};
24 foreach my $item (@list) {
25 my $extensionlessitem = extensionlesslib($item);
26 # It's time to break off when the dependency list starts looping
27 next if grep { extensionlesslib($_) eq $extensionlessitem } @listsofar;
28 push @newlist, $item, resolvedepends($item, @listsofar, $item);
37 my $item = shift @list;
38 my $extensionlessitem = extensionlesslib($item);
40 unless grep { $extensionlessitem eq extensionlesslib($_) } @list;
45 # is_installed checks if a given file will be installed (i.e. they are
46 # not defined _NO_INST in build.info)
49 if (grep { $product eq $_ }
50 map { (@{$unified_info{install}->{$_}}) }
51 keys %{$unified_info{install}}) {
57 # dogenerate is responsible for producing all the recipes that build
58 # generated source files. It recurses in case a dependency is also a
59 # generated source file.
62 return "" if $cache{$src};
66 if ($unified_info{generate}->{$src}) {
67 die "$src is generated by Configure, should not appear in build file\n"
68 if ref $unified_info{generate}->{$src} eq "";
69 my $script = $unified_info{generate}->{$src}->[0];
70 $OUT .= generatesrc(src => $src,
71 generator => $unified_info{generate}->{$src},
72 generator_incs => $unified_info{includes}->{$script},
73 generator_deps => $unified_info{depends}->{$script},
74 deps => $unified_info{depends}->{$src},
75 incs => [ @{$unified_info{includes}->{$bin}},
76 @{$unified_info{includes}->{$obj}} ],
78 foreach (@{$unified_info{depends}->{$src}}) {
79 dogenerate($_, $obj, $bin, %opts);
85 # doobj is responsible for producing all the recipes that build
86 # object files as well as dependency files.
89 return "" if $cache{$obj};
90 (my $obj_no_o = $obj) =~ s|\.o$||;
93 if (@{$unified_info{sources}->{$obj}}) {
94 $OUT .= src2obj(obj => $obj_no_o,
96 srcs => $unified_info{sources}->{$obj},
97 deps => $unified_info{depends}->{$obj},
98 incs => [ @{$unified_info{includes}->{$bin}},
99 @{$unified_info{includes}->{$obj}} ],
101 foreach ((@{$unified_info{sources}->{$obj}},
102 @{$unified_info{depends}->{$obj}})) {
103 dogenerate($_, $obj, $bin, %opts);
109 # dolib is responsible for building libraries. It will call
110 # libobj2shlib is shared libraries are produced, and obj2lib in all
111 # cases. It also makes sure all object files for the library are
115 return "" if $cache{$lib};
116 unless ($disabled{shared}) {
118 $unified_info{ordinals}->{$lib}
119 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
120 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
122 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
123 (@{$unified_info{sources}->{$lib}},
124 @{$unified_info{shared_sources}->{$lib}}) ],
125 deps => [ reducedepends(resolvedepends($lib)) ],
126 installed => is_installed($lib),
128 foreach (@{$unified_info{shared_sources}->{$lib}}) {
129 doobj($_, $lib, intent => "lib", installed => is_installed($lib));
132 $OUT .= obj2lib(lib => $lib,
133 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
134 @{$unified_info{sources}->{$lib}} ]);
135 foreach (@{$unified_info{sources}->{$lib}}) {
136 doobj($_, $lib, intent => "lib");
141 # doengine is responsible for building engines. It will call
142 # obj2dso, and also makes sure all object files for the library
146 return "" if $cache{$lib};
147 $OUT .= obj2dso(lib => $lib,
148 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
149 (@{$unified_info{sources}->{$lib}},
150 @{$unified_info{shared_sources}->{$lib}}) ],
151 deps => [ resolvedepends($lib) ],
152 installed => is_installed($lib));
153 foreach ((@{$unified_info{sources}->{$lib}},
154 @{$unified_info{shared_sources}->{$lib}})) {
155 doobj($_, $lib, intent => "dso", installed => is_installed($lib));
160 # dobin is responsible for building programs. It will call obj2bin,
161 # and also makes sure all object files for the library are built.
164 return "" if $cache{$bin};
165 my $deps = [ reducedepends(resolvedepends($bin)) ];
166 $OUT .= obj2bin(bin => $bin,
167 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
168 @{$unified_info{sources}->{$bin}} ],
170 installed => is_installed($bin));
171 foreach (@{$unified_info{sources}->{$bin}}) {
172 doobj($_, $bin, intent => "bin", installed => is_installed($bin));
177 # dobin is responsible for building scripts from templates. It will
181 return "" if $cache{$script};
182 $OUT .= in2script(script => $script,
183 sources => $unified_info{sources}->{$script},
184 installed => is_installed($script));
190 return "" if !exists(&generatedir) or $cache{$dir};
191 $OUT .= generatedir(dir => $dir,
192 deps => $unified_info{dirinfo}->{$dir}->{deps},
193 %{$unified_info{dirinfo}->{$_}->{products}});
197 # Start with populating the cache with all the overrides
198 %cache = map { $_ => 1 } @{$unified_info{overrides}};
200 # For convenience collect information regarding directories where
201 # files are generated, those generated files and the end product
202 # they end up in where applicable. Then, add build rules for those
204 if (exists &generatedir) {
205 my %loopinfo = ( "dso" => [ @{$unified_info{engines}} ],
206 "lib" => [ @{$unified_info{libraries}} ],
207 "bin" => [ @{$unified_info{programs}} ],
208 "script" => [ @{$unified_info{scripts}} ] );
209 foreach my $type (keys %loopinfo) {
210 foreach my $product (@{$loopinfo{$type}}) {
212 my $pd = dirname($product);
214 # We already have a "test" target, and the current directory
215 # is just silly to make a target for
216 $dirs{$pd} = 1 unless $pd eq "test" || $pd eq ".";
218 foreach (@{$unified_info{sources}->{$product}}) {
221 # We don't want to create targets for source directories
222 # when building out of source
223 next if ($config{sourcedir} ne $config{builddir}
224 && $d =~ m|^\Q$config{sourcedir}\E|);
225 # We already have a "test" target, and the current directory
226 # is just silly to make a target for
227 next if $d eq "test" || $d eq ".";
230 push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
233 foreach (keys %dirs) {
234 push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
241 # Build mandatory generated headers
242 foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
244 # Build all known libraries, engines, programs and scripts.
245 # Everything else will be handled as a consequence.
246 foreach (@{$unified_info{libraries}}) { dolib($_); }
247 foreach (@{$unified_info{engines}}) { doengine($_); }
248 foreach (@{$unified_info{programs}}) { dobin($_); }
249 foreach (@{$unified_info{scripts}}) { doscript($_); }
251 foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
253 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
254 # they are added here.
255 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};