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 $OUT .= generatesrc(src => $src,
46 generator => $unified_info{generate}->{$src},
47 deps => $unified_info{depends}->{$src},
48 incs => [ @{$unified_info{includes}->{$bin}},
49 @{$unified_info{includes}->{$obj}} ],
51 foreach (@{$unified_info{depends}->{$src}}) {
52 dogenerate($_, $obj, $bin, %opts);
58 # doobj is responsible for producing all the recipes that build
59 # object files as well as dependency files.
62 return "" if $cache{$obj};
63 (my $obj_no_o = $obj) =~ s|\.o$||;
66 if (@{$unified_info{sources}->{$obj}}) {
67 $OUT .= src2obj(obj => $obj_no_o,
68 srcs => $unified_info{sources}->{$obj},
69 deps => $unified_info{depends}->{$obj},
70 incs => [ @{$unified_info{includes}->{$bin}},
71 @{$unified_info{includes}->{$obj}} ],
73 foreach ((@{$unified_info{sources}->{$obj}},
74 @{$unified_info{depends}->{$obj}})) {
75 dogenerate($_, $obj, $bin, %opts);
81 # dolib is responsible for building libraries. It will call
82 # libobj2shlib is shared libraries are produced, and obj2lib in all
83 # cases. It also makes sure all object files for the library are
87 return "" if $cache{$lib};
88 unless ($disabled{shared}) {
90 $unified_info{ordinals}->{$lib}
91 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
92 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
94 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
95 @{$unified_info{sources}->{$lib}} ],
96 deps => [ reducedepends(resolvedepends($lib)) ],
99 $OUT .= obj2lib(lib => $lib,
100 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
101 @{$unified_info{sources}->{$lib}} ]);
102 map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
106 # doengine is responsible for building engines. It will call
107 # obj2dso, and also makes sure all object files for the library
111 return "" if $cache{$lib};
112 $OUT .= obj2dso(lib => $lib,
113 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
114 @{$unified_info{sources}->{$lib}} ],
115 deps => [ resolvedepends($lib) ]);
116 map { doobj($_, $lib, intent => "dso") } @{$unified_info{sources}->{$lib}};
120 # dobin is responsible for building programs. It will call obj2bin,
121 # and also makes sure all object files for the library are built.
124 return "" if $cache{$bin};
125 my $deps = [ reducedepends(resolvedepends($bin)) ];
126 $OUT .= obj2bin(bin => $bin,
127 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
128 @{$unified_info{sources}->{$bin}} ],
130 map { doobj($_, $bin, intent => "bin") } @{$unified_info{sources}->{$bin}};
134 # dobin is responsible for building scripts from templates. It will
138 return "" if $cache{$script};
139 $OUT .= in2script(script => $script,
140 sources => $unified_info{sources}->{$script});
144 # Start with populating the cache with all the overrides
145 %cache = map { $_ => 1 } @{$unified_info{overrides}};
147 # Build all known libraries, engines, programs and scripts.
148 # Everything else will be handled as a consequence.
149 map { dolib($_) } @{$unified_info{libraries}};
150 map { doengine($_) } @{$unified_info{engines}};
151 map { dobin($_) } @{$unified_info{programs}};
152 map { doscript($_) } @{$unified_info{scripts}};
154 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
155 # they are added here.
156 $OUT .= $_."\n" foreach(@{$unified_info{rawlines}});