1 {- # -*- Mode: perl -*-
5 # resolvedepends and reducedepends work in tandem to make sure
6 # there are no duplicate dependencies and that they are in the
7 # right order. This is especially used to sort the list of
8 # libraries that a build depends on.
11 my @listsofar = @_; # to check if we're looping
12 my @list = @{$unified_info{depends}->{$thing}};
15 foreach my $item (@list) {
16 # It's time to break off when the dependency list starts looping
17 next if grep { $_ eq $item } @listsofar;
18 push @newlist, $item, resolvedepends($item, @listsofar, $item);
27 my $item = shift @list;
29 unless grep { $item eq $_ } @list;
34 # doobj is responsible for producing all the recipes that build
35 # object files as well as dependency files.
38 (my $obj_no_o = $obj) =~ s|\.o$||;
40 if (@{$unified_info{sources}->{$obj}}) {
41 $OUT .= src2obj(obj => $obj_no_o,
42 srcs => $unified_info{sources}->{$obj},
43 deps => [ reducedepends(resolvedepends($obj)) ],
44 incs => [ @{$unified_info{includes}->{$bin}},
45 @{$unified_info{includes}->{$obj}} ]);
46 $OUT .= src2dep(obj => $obj_no_o,
47 srcs => $unified_info{sources}->{$obj},
48 incs => [ @{$unified_info{includes}->{$bin}},
49 @{$unified_info{includes}->{$obj}} ]);
53 # dolib is responsible for building libraries. It will call
54 # libobj2shlib is shared libraries are produced, and obj2lib in all
55 # cases. It also makes sure all object files for the library are
59 if (!$config{no_shared}) {
61 $unified_info{ordinals}->{$lib}
62 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
63 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
65 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
66 @{$unified_info{sources}->{$lib}} ],
67 deps => [ reducedepends(resolvedepends($lib)) ],
70 $OUT .= obj2lib(lib => $lib,
71 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
72 @{$unified_info{sources}->{$lib}} ]);
73 map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
76 # doengine is responsible for building engines. It will call
77 # obj2dynlib, and also makes sure all object files for the library
81 $OUT .= obj2dynlib(lib => $lib,
82 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
83 @{$unified_info{sources}->{$lib}} ],
84 deps => [ resolvedepends($lib) ]);
85 map { doobj($_, $lib, intent => "lib") } @{$unified_info{sources}->{$lib}};
88 # dobin is responsible for building programs. It will call obj2bin,
89 # and also makes sure all object files for the library are built.
92 my $deps = [ reducedepends(resolvedepends($bin)) ];
93 $OUT .= obj2bin(bin => $bin,
94 objs => [ map { (my $x = $_) =~ s|\.o$||; $x }
95 @{$unified_info{sources}->{$bin}} ],
97 map { doobj($_, $bin, intent => "bin") } @{$unified_info{sources}->{$bin}};
100 # dobin is responsible for building scripts from templates. It will
104 $OUT .= in2script(script => $script,
105 sources => $unified_info{sources}->{$script});
108 # Build all known libraries, engines, programs and scripts.
109 # Everything else will be handled as a consequence.
110 map { dolib($_) } @{$unified_info{libraries}};
111 map { doengine($_) } @{$unified_info{engines}};
112 map { dobin($_) } @{$unified_info{programs}};
113 map { doscript($_) } @{$unified_info{scripts}};
115 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
116 # they are added here.
117 $OUT .= $_."\n" foreach(@{$unified_info{rawlines}});