]> git.ipfire.org Git - thirdparty/openssl.git/blob - Configurations/common.tmpl
Implement support for AES-256-ECB in the default provider
[thirdparty/openssl.git] / Configurations / common.tmpl
1 {- # -*- Mode: perl -*-
2
3 use File::Basename;
4
5 # A cache of objects for which a recipe has already been generated
6 my %cache;
7
8 # resolvedepends and reducedepends work in tandem to make sure
9 # there are no duplicate dependencies and that they are in the
10 # right order. This is especially used to sort the list of
11 # libraries that a build depends on.
12 sub extensionlesslib {
13 my @result = map { $_ =~ /(\.a)?$/; $` } @_;
14 return @result if wantarray;
15 return $result[0];
16 }
17 sub resolvedepends {
18 my $thing = shift;
19 my $extensionlessthing = extensionlesslib($thing);
20 my @listsofar = @_; # to check if we're looping
21 my @list = @{$unified_info{depends}->{$thing} //
22 $unified_info{depends}->{$extensionlessthing}};
23 my @newlist = ();
24 if (scalar @list) {
25 foreach my $item (@list) {
26 my $extensionlessitem = extensionlesslib($item);
27 # It's time to break off when the dependency list starts looping
28 next if grep { extensionlesslib($_) eq $extensionlessitem } @listsofar;
29 push @newlist, $item, resolvedepends($item, @listsofar, $item);
30 }
31 }
32 @newlist;
33 }
34 sub reducedepends {
35 my @list = @_;
36 my @newlist = ();
37 my %replace = ();
38 while (@list) {
39 my $item = shift @list;
40 my $extensionlessitem = extensionlesslib($item);
41 if (grep { $extensionlessitem eq extensionlesslib($_) } @list) {
42 if ($item ne $extensionlessitem) {
43 # If this instance of the library is explicitly static, we
44 # prefer that to any shared library name, since it must have
45 # been done on purpose.
46 $replace{$extensionlessitem} = $item;
47 }
48 } else {
49 push @newlist, $item;
50 }
51 }
52 map { $replace{$_} // $_; } @newlist;
53 }
54
55 # dogenerate is responsible for producing all the recipes that build
56 # generated source files. It recurses in case a dependency is also a
57 # generated source file.
58 sub dogenerate {
59 my $src = shift;
60 return "" if $cache{$src};
61 my $obj = shift;
62 my $bin = shift;
63 my %opts = @_;
64 if ($unified_info{generate}->{$src}) {
65 die "$src is generated by Configure, should not appear in build file\n"
66 if ref $unified_info{generate}->{$src} eq "";
67 my $script = $unified_info{generate}->{$src}->[0];
68 $OUT .= generatesrc(src => $src,
69 product => $bin,
70 generator => $unified_info{generate}->{$src},
71 generator_incs => $unified_info{includes}->{$script},
72 generator_deps => $unified_info{depends}->{$script},
73 deps => $unified_info{depends}->{$src},
74 incs => [ @{$unified_info{includes}->{$obj}},
75 @{$unified_info{includes}->{$bin}} ],
76 defs => [ @{$unified_info{defines}->{$obj}},
77 @{$unified_info{defines}->{$bin}} ],
78 %opts);
79 foreach (@{$unified_info{depends}->{$src}}) {
80 dogenerate($_, $obj, $bin, %opts);
81 }
82 }
83 $cache{$src} = 1;
84 }
85
86 # doobj is responsible for producing all the recipes that build
87 # object files as well as dependency files.
88 sub doobj {
89 my $obj = shift;
90 return "" if $cache{$obj};
91 my $bin = shift;
92 my %opts = @_;
93 if (@{$unified_info{sources}->{$obj}}) {
94 $OUT .= src2obj(obj => $obj,
95 product => $bin,
96 srcs => $unified_info{sources}->{$obj},
97 deps => $unified_info{depends}->{$obj},
98 incs => [ @{$unified_info{includes}->{$obj}},
99 @{$unified_info{includes}->{$bin}} ],
100 defs => [ @{$unified_info{defines}->{$obj}},
101 @{$unified_info{defines}->{$bin}} ],
102 %opts);
103 foreach ((@{$unified_info{sources}->{$obj}},
104 @{$unified_info{depends}->{$obj}})) {
105 dogenerate($_, $obj, $bin, %opts);
106 }
107 }
108 $cache{$obj} = 1;
109 }
110
111 # dolib is responsible for building libraries. It will call
112 # obj2shlib is shared libraries are produced, and obj2lib in all
113 # cases. It also makes sure all object files for the library are
114 # built.
115 sub dolib {
116 my $lib = shift;
117 return "" if $cache{$lib};
118 unless ($disabled{shared} || $lib =~ /\.a$/) {
119 my $obj2shlib = defined &obj2shlib ? \&obj2shlib : \&libobj2shlib;
120 $OUT .= $obj2shlib->(lib => $lib,
121 attrs => $unified_info{attributes}->{$lib},
122 objs => $unified_info{shared_sources}->{$lib},
123 deps => [ reducedepends(resolvedepends($lib)) ]);
124 foreach ((@{$unified_info{shared_sources}->{$lib}},
125 @{$unified_info{sources}->{$lib}})) {
126 # If this is somehow a compiled object, take care of it that way
127 # Otherwise, it might simply be generated
128 if (defined $unified_info{sources}->{$_}) {
129 doobj($_, $lib, intent => "shlib",
130 attrs => $unified_info{attributes}->{$lib});
131 } else {
132 dogenerate($_, undef, undef, intent => "lib");
133 }
134 }
135 }
136 $OUT .= obj2lib(lib => $lib,
137 attrs => $unified_info{attributes}->{$lib},
138 objs => [ @{$unified_info{sources}->{$lib}} ]);
139 foreach (@{$unified_info{sources}->{$lib}}) {
140 doobj($_, $lib, intent => "lib",
141 attrs => $unified_info{attributes}->{$lib});
142 }
143 $cache{$lib} = 1;
144 }
145
146 # domodule is responsible for building modules. It will call
147 # obj2dso, and also makes sure all object files for the library
148 # are built.
149 sub domodule {
150 my $lib = shift;
151 return "" if $cache{$lib};
152 $OUT .= obj2dso(lib => $lib,
153 attrs => $unified_info{attributes}->{$lib},
154 objs => $unified_info{sources}->{$lib},
155 deps => [ resolvedepends($lib) ]);
156 foreach (@{$unified_info{sources}->{$lib}}) {
157 # If this is somehow a compiled object, take care of it that way
158 # Otherwise, it might simply be generated
159 if (defined $unified_info{sources}->{$_}) {
160 doobj($_, $lib, intent => "dso",
161 attrs => $unified_info{attributes}->{$lib});
162 } else {
163 dogenerate($_, undef, $lib, intent => "dso");
164 }
165 }
166 $cache{$lib} = 1;
167 }
168
169 # dobin is responsible for building programs. It will call obj2bin,
170 # and also makes sure all object files for the library are built.
171 sub dobin {
172 my $bin = shift;
173 return "" if $cache{$bin};
174 my $deps = [ reducedepends(resolvedepends($bin)) ];
175 $OUT .= obj2bin(bin => $bin,
176 attrs => $unified_info{attributes}->{$bin},
177 objs => [ @{$unified_info{sources}->{$bin}} ],
178 deps => $deps);
179 foreach (@{$unified_info{sources}->{$bin}}) {
180 doobj($_, $bin, intent => "bin",
181 attrs => $unified_info{attributes}->{$bin});
182 }
183 $cache{$bin} = 1;
184 }
185
186 # dobin is responsible for building scripts from templates. It will
187 # call in2script.
188 sub doscript {
189 my $script = shift;
190 return "" if $cache{$script};
191 $OUT .= in2script(script => $script,
192 attrs => $unified_info{attributes}->{$script},
193 sources => $unified_info{sources}->{$script});
194 $cache{$script} = 1;
195 }
196
197 sub dodir {
198 my $dir = shift;
199 return "" if !exists(&generatedir) or $cache{$dir};
200 $OUT .= generatedir(dir => $dir,
201 deps => $unified_info{dirinfo}->{$dir}->{deps},
202 %{$unified_info{dirinfo}->{$_}->{products}});
203 $cache{$dir} = 1;
204 }
205
206 # Start with populating the cache with all the overrides
207 %cache = map { $_ => 1 } @{$unified_info{overrides}};
208
209 # Build mandatory generated headers
210 foreach (@{$unified_info{depends}->{""}}) { dogenerate($_); }
211
212 # Build all known libraries, modules, programs and scripts.
213 # Everything else will be handled as a consequence.
214 foreach (@{$unified_info{libraries}}) { dolib($_); }
215 foreach (@{$unified_info{modules}}) { domodule($_); }
216 foreach (@{$unified_info{programs}}) { dobin($_); }
217 foreach (@{$unified_info{scripts}}) { doscript($_); }
218
219 foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); }
220 -}