]> git.ipfire.org Git - thirdparty/openssl.git/blob - Configurations/common.tmpl
e3f49e776ab0d1d187562ba6f4be174ad72c4305
[thirdparty/openssl.git] / Configurations / common.tmpl
1 {- # -*- Mode: perl -*-
2
3 # A cache of objects for which a recipe has already been generated
4 my %cache;
5
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.
10 sub resolvedepends {
11 my $thing = shift;
12 my @listsofar = @_; # to check if we're looping
13 my @list = @{$unified_info{depends}->{$thing}};
14 my @newlist = ();
15 if (scalar @list) {
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);
20 }
21 }
22 @newlist;
23 }
24 sub reducedepends {
25 my @list = @_;
26 my @newlist = ();
27 while (@list) {
28 my $item = shift @list;
29 push @newlist, $item
30 unless grep { $item eq $_ } @list;
31 }
32 @newlist;
33 }
34
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.
38 sub dogenerate {
39 my $src = shift;
40 return "" if $cache{$src};
41 my $obj = shift;
42 my $bin = shift;
43 my %opts = @_;
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}} ],
55 %opts);
56 foreach (@{$unified_info{depends}->{$src}}) {
57 dogenerate($_, $obj, $bin, %opts);
58 }
59 }
60 $cache{$src} = 1;
61 }
62
63 # doobj is responsible for producing all the recipes that build
64 # object files as well as dependency files.
65 sub doobj {
66 my $obj = shift;
67 return "" if $cache{$obj};
68 (my $obj_no_o = $obj) =~ s|\.o$||;
69 my $bin = shift;
70 my %opts = @_;
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}} ],
77 %opts);
78 foreach ((@{$unified_info{sources}->{$obj}},
79 @{$unified_info{depends}->{$obj}})) {
80 dogenerate($_, $obj, $bin, %opts);
81 }
82 }
83 $cache{$obj} = 1;
84 }
85
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
89 # built.
90 sub dolib {
91 my $lib = shift;
92 return "" if $cache{$lib};
93 unless ($disabled{shared}) {
94 my %ordinals =
95 $unified_info{ordinals}->{$lib}
96 ? (ordinals => $unified_info{ordinals}->{$lib}) : ();
97 $OUT .= libobj2shlib(shlib => $unified_info{sharednames}->{$lib},
98 lib => $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)) ],
103 %ordinals);
104 foreach (@{$unified_info{shared_sources}->{$lib}}) {
105 doobj($_, $lib, intent => "lib");
106 }
107 }
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");
113 }
114 $cache{$lib} = 1;
115 }
116
117 # doengine is responsible for building engines. It will call
118 # obj2dso, and also makes sure all object files for the library
119 # are built.
120 sub doengine {
121 my $lib = shift;
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");
131 }
132 $cache{$lib} = 1;
133 }
134
135 # dobin is responsible for building programs. It will call obj2bin,
136 # and also makes sure all object files for the library are built.
137 sub dobin {
138 my $bin = shift;
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}} ],
144 deps => $deps);
145 foreach (@{$unified_info{sources}->{$bin}}) {
146 doobj($_, $bin, intent => "bin");
147 }
148 $cache{$bin} = 1;
149 }
150
151 # dobin is responsible for building scripts from templates. It will
152 # call in2script.
153 sub doscript {
154 my $script = shift;
155 return "" if $cache{$script};
156 $OUT .= in2script(script => $script,
157 sources => $unified_info{sources}->{$script});
158 $cache{$script} = 1;
159 }
160
161 # Start with populating the cache with all the overrides
162 %cache = map { $_ => 1 } @{$unified_info{overrides}};
163
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($_); }
170
171 # Finally, should there be any applicable BEGINRAW/ENDRAW sections,
172 # they are added here.
173 $OUT .= $_."\n" foreach @{$unified_info{rawlines}};
174 -}