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 # dogenerate is responsible for producing all the recipes that build
36 # generated source files. It recurses in case a dependency is also a
37 # generated source file.
40 return "" if $cache{$src};
44 if ($unified_info{generate}->{$src}) {
45 my $script = $unified_info{generate}->{$src}->[0];
46 $OUT .= generatesrc(src => $src,
47 generator => $unified_info{generate}->{$src},
48 generator_incs => $unified_info{includes}->{$script},
49 generator_deps => $unified_info{depends}->{$script},
50 deps => $unified_info{depends}->{$src},
51 incs => [ @{$unified_info{includes}->{$bin}},
52 @{$unified_info{includes}->{$obj}} ],
54 foreach (@{$unified_info{depends}->{$src}}) {
55 dogenerate($_, $obj, $bin, %opts);
61 # doobj is responsible for producing all the recipes that build
62 # object files as well as dependency files.
65 return "" if $cache{$obj};
66 (my $obj_no_o = $obj) =~ s|\.o$||;
69 if (@{$unified_info{sources}->{$obj}}) {
70 $OUT .= src2obj(obj => $obj_no_o,
71 srcs => $unified_info{sources}->{$obj},
72 deps => $unified_info{depends}->{$obj},
73 incs => [ @{$unified_info{includes}->{$bin}},
74 @{$unified_info{includes}->{$obj}} ],
76 foreach ((@{$unified_info{sources}->{$obj}},
77 @{$unified_info{depends}->{$obj}})) {
78 dogenerate($_, $obj, $bin, %opts);
84 # dolib is responsible for building libraries. It will call
85 # libobj2shlib is shared libraries are produced, and obj2lib in all
86 # cases. It also makes sure all object files for the library are
90 return "" if $cache{$lib};
91 unless ($disabled{shared}) {
93 $unified_info{ordinals}->{$lib}
94 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
95 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
97 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
98 (@{$unified_info{sources}->{$lib}},
99 @{$unified_info{shared_sources}->{$lib}}) ],
100 deps => [ reducedepends(resolvedepends($lib)) ],
102 foreach (@{$unified_info{shared_sources}->{$lib}}) {
103 doobj($_, $lib, intent => "lib");
106 $OUT .= obj2lib(lib => $lib,
107 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
108 @{$unified_info{sources}->{$lib}} ]);
109 foreach (@{$unified_info{sources}->{$lib}}) {
110 doobj($_, $lib, intent => "lib");
115 # doengine is responsible for building engines. It will call
116 # obj2dso, and also makes sure all object files for the library
120 return "" if $cache{$lib};
121 $OUT .= obj2dso(lib => $lib,
122 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
123 (@{$unified_info{sources}->{$lib}},
124 @{$unified_info{shared_sources}->{$lib}}) ],
125 deps => [ resolvedepends($lib) ]);
126 foreach ((@{$unified_info{sources}->{$lib}},
127 @{$unified_info{shared_sources}->{$lib}})) {
128 doobj($_, $lib, intent => "dso");
133 # dobin is responsible for building programs. It will call obj2bin,
134 # and also makes sure all object files for the library are built.
137 return "" if $cache{$bin};
138 my $deps = [ reducedepends(resolvedepends($bin)) ];
139 $OUT .= obj2bin(bin => $bin,
140 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
141 @{$unified_info{sources}->{$bin}} ],
143 foreach (@{$unified_info{sources}->{$bin}}) {
144 doobj($_, $bin, intent => "bin");
149 # dobin is responsible for building scripts from templates. It will
153 return "" if $cache{$script};
154 $OUT .= in2script(script => $script,
155 sources => $unified_info{sources}->{$script});
159 # Start with populating the cache with all the overrides
160 %cache = map { $_ => 1 } @{$unified_info{overrides}};
162 # Build all known libraries, engines, programs and scripts.
163 # Everything else will be handled as a consequence.
164 foreach (@{$unified_info{libraries}}) { dolib($_); }
165 foreach (@{$unified_info{engines}}) { doengine($_); }
166 foreach (@{$unified_info{programs}}) { dobin($_); }
167 foreach (@{$unified_info{scripts}}) { doscript($_); }
169 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
170 # they are added here.
171 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};