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 die "$src is generated by Configure, should not appear in build file\n"
46 if ref $unified_info{generate}->{$src} eq "";
47 my $script = $unified_info{generate}->{$src}->[0];
48 $OUT .= generatesrc(src => $src,
49 generator => $unified_info{generate}->{$src},
50 generator_incs => $unified_info{includes}->{$script},
51 generator_deps => $unified_info{depends}->{$script},
52 deps => $unified_info{depends}->{$src},
53 incs => [ @{$unified_info{includes}->{$bin}},
54 @{$unified_info{includes}->{$obj}} ],
56 foreach (@{$unified_info{depends}->{$src}}) {
57 dogenerate($_, $obj, $bin, %opts);
63 # doobj is responsible for producing all the recipes that build
64 # object files as well as dependency files.
67 return "" if $cache{$obj};
68 (my $obj_no_o = $obj) =~ s|\.o$||;
71 if (@{$unified_info{sources}->{$obj}}) {
72 $OUT .= src2obj(obj => $obj_no_o,
73 srcs => $unified_info{sources}->{$obj},
74 deps => $unified_info{depends}->{$obj},
75 incs => [ @{$unified_info{includes}->{$bin}},
76 @{$unified_info{includes}->{$obj}} ],
78 foreach ((@{$unified_info{sources}->{$obj}},
79 @{$unified_info{depends}->{$obj}})) {
80 dogenerate($_, $obj, $bin, %opts);
86 # dolib is responsible for building libraries. It will call
87 # libobj2shlib is shared libraries are produced, and obj2lib in all
88 # cases. It also makes sure all object files for the library are
92 return "" if $cache{$lib};
93 unless ($disabled{shared}) {
95 $unified_info{ordinals}->{$lib}
96 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
97 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
99 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
100 (@{$unified_info{sources}->{$lib}},
101 @{$unified_info{shared_sources}->{$lib}}) ],
102 deps => [ reducedepends(resolvedepends($lib)) ],
104 foreach (@{$unified_info{shared_sources}->{$lib}}) {
105 doobj($_, $lib, intent => "lib");
108 $OUT .= obj2lib(lib => $lib,
109 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
110 @{$unified_info{sources}->{$lib}} ]);
111 foreach (@{$unified_info{sources}->{$lib}}) {
112 doobj($_, $lib, intent => "lib");
117 # doengine is responsible for building engines. It will call
118 # obj2dso, and also makes sure all object files for the library
122 return "" if $cache{$lib};
123 $OUT .= obj2dso(lib => $lib,
124 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
125 (@{$unified_info{sources}->{$lib}},
126 @{$unified_info{shared_sources}->{$lib}}) ],
127 deps => [ resolvedepends($lib) ]);
128 foreach ((@{$unified_info{sources}->{$lib}},
129 @{$unified_info{shared_sources}->{$lib}})) {
130 doobj($_, $lib, intent => "dso");
135 # dobin is responsible for building programs. It will call obj2bin,
136 # and also makes sure all object files for the library are built.
139 return "" if $cache{$bin};
140 my $deps = [ reducedepends(resolvedepends($bin)) ];
141 $OUT .= obj2bin(bin => $bin,
142 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
143 @{$unified_info{sources}->{$bin}} ],
145 foreach (@{$unified_info{sources}->{$bin}}) {
146 doobj($_, $bin, intent => "bin");
151 # dobin is responsible for building scripts from templates. It will
155 return "" if $cache{$script};
156 $OUT .= in2script(script => $script,
157 sources => $unified_info{sources}->{$script});
161 # Start with populating the cache with all the overrides
162 %cache = map { $_ => 1 } @{$unified_info{overrides}};
164 # Build all known libraries, engines, programs and scripts.
165 # Everything else will be handled as a consequence.
166 foreach (@{$unified_info{libraries}}) { dolib($_); }
167 foreach (@{$unified_info{engines}}) { doengine($_); }
168 foreach (@{$unified_info{programs}}) { dobin($_); }
169 foreach (@{$unified_info{scripts}}) { doscript($_); }
171 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
172 # they are added here.
173 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};