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 # dogenerate is responsible for producing all the recipes that build
38 # generated source files. It recurses in case a dependency is also a
39 # generated source file.
42 return "" if $cache{$src};
46 if ($unified_info{generate}->{$src}) {
47 die "$src is generated by Configure, should not appear in build file\n"
48 if ref $unified_info{generate}->{$src} eq "";
49 my $script = $unified_info{generate}->{$src}->[0];
50 $OUT .= generatesrc(src => $src,
51 generator => $unified_info{generate}->{$src},
52 generator_incs => $unified_info{includes}->{$script},
53 generator_deps => $unified_info{depends}->{$script},
54 deps => $unified_info{depends}->{$src},
55 incs => [ @{$unified_info{includes}->{$bin}},
56 @{$unified_info{includes}->{$obj}} ],
58 foreach (@{$unified_info{depends}->{$src}}) {
59 dogenerate($_, $obj, $bin, %opts);
65 # doobj is responsible for producing all the recipes that build
66 # object files as well as dependency files.
69 return "" if $cache{$obj};
70 (my $obj_no_o = $obj) =~ s|\.o$||;
73 if (@{$unified_info{sources}->{$obj}}) {
74 $OUT .= src2obj(obj => $obj_no_o,
75 srcs => $unified_info{sources}->{$obj},
76 deps => $unified_info{depends}->{$obj},
77 incs => [ @{$unified_info{includes}->{$bin}},
78 @{$unified_info{includes}->{$obj}} ],
80 foreach ((@{$unified_info{sources}->{$obj}},
81 @{$unified_info{depends}->{$obj}})) {
82 dogenerate($_, $obj, $bin, %opts);
88 # dolib is responsible for building libraries. It will call
89 # libobj2shlib is shared libraries are produced, and obj2lib in all
90 # cases. It also makes sure all object files for the library are
94 return "" if $cache{$lib};
95 unless ($disabled{shared}) {
97 $unified_info{ordinals}->{$lib}
98 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
99 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
101 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
102 (@{$unified_info{sources}->{$lib}},
103 @{$unified_info{shared_sources}->{$lib}}) ],
104 deps => [ reducedepends(resolvedepends($lib)) ],
106 foreach (@{$unified_info{shared_sources}->{$lib}}) {
107 doobj($_, $lib, intent => "lib");
110 $OUT .= obj2lib(lib => $lib,
111 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
112 @{$unified_info{sources}->{$lib}} ]);
113 foreach (@{$unified_info{sources}->{$lib}}) {
114 doobj($_, $lib, intent => "lib");
119 # doengine is responsible for building engines. It will call
120 # obj2dso, and also makes sure all object files for the library
124 return "" if $cache{$lib};
125 $OUT .= obj2dso(lib => $lib,
126 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
127 (@{$unified_info{sources}->{$lib}},
128 @{$unified_info{shared_sources}->{$lib}}) ],
129 deps => [ resolvedepends($lib) ]);
130 foreach ((@{$unified_info{sources}->{$lib}},
131 @{$unified_info{shared_sources}->{$lib}})) {
132 doobj($_, $lib, intent => "dso");
137 # dobin is responsible for building programs. It will call obj2bin,
138 # and also makes sure all object files for the library are built.
141 return "" if $cache{$bin};
142 my $deps = [ reducedepends(resolvedepends($bin)) ];
143 $OUT .= obj2bin(bin => $bin,
144 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
145 @{$unified_info{sources}->{$bin}} ],
147 foreach (@{$unified_info{sources}->{$bin}}) {
148 doobj($_, $bin, intent => "bin");
153 # dobin is responsible for building scripts from templates. It will
157 return "" if $cache{$script};
158 $OUT .= in2script(script => $script,
159 sources => $unified_info{sources}->{$script});
165 return "" if !exists(&generatedir) or $cache{$dir};
166 $OUT .= generatedir(dir => $dir,
167 deps => $unified_info{dirinfo}->{$dir}->{deps},
168 %{$unified_info{dirinfo}->{$_}->{products}});
172 # Start with populating the cache with all the overrides
173 %cache = map { $_ => 1 } @{$unified_info{overrides}};
175 # For convenience collect information regarding directories where
176 # files are generated, those generated files and the end product
177 # they end up in where applicable. Then, add build rules for those
179 if (exists &generatedir) {
180 my %loopinfo = ( "dso" => [ @{$unified_info{engines}} ],
181 "lib" => [ @{$unified_info{libraries}} ],
182 "bin" => [ @{$unified_info{programs}} ],
183 "script" => [ @{$unified_info{scripts}} ] );
184 foreach my $type (keys %loopinfo) {
185 foreach my $product (@{$loopinfo{$type}}) {
187 my $pd = dirname($product);
189 # We already have a "test" target, and the current directory
190 # is just silly to make a target for
191 $dirs{$pd} = 1 unless $pd eq "test" || $pd eq ".";
193 foreach (@{$unified_info{sources}->{$product}}) {
196 # We don't want to create targets for source directories
197 # when building out of source
198 next if ($config{sourcedir} ne $config{builddir}
199 && $d =~ m|^\Q$config{sourcedir}\E|);
200 # We already have a "test" target, and the current directory
201 # is just silly to make a target for
202 next if $d eq "test" || $d eq ".";
205 push @{$unified_info{dirinfo}->{$d}->{deps}}, $_
208 foreach (keys %dirs) {
209 push @{$unified_info{dirinfo}->{$_}->{products}->{$type}},
216 # Build mandatory generated headers
217 foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
219 # Build all known libraries, engines, programs and scripts.
220 # Everything else will be handled as a consequence.
221 foreach (@{$unified_info{libraries}}) { dolib($_); }
222 foreach (@{$unified_info{engines}}) { doengine($_); }
223 foreach (@{$unified_info{programs}}) { dobin($_); }
224 foreach (@{$unified_info{scripts}}) { doscript($_); }
226 foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
228 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
229 # they are added here.
230 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};