]> git.ipfire.org Git - thirdparty/openssl.git/blame - configdata.pm.in
Move some OpenSSL perl utility functions to OpenSSL::Util
[thirdparty/openssl.git] / configdata.pm.in
CommitLineData
1f86b822
RL
1#! {- $config{HASHBANGPERL} -}
2# -*- mode: perl -*-
3{-
1f86b822
RL
4 # We must make sourcedir() return an absolute path, because configdata.pm
5 # may be loaded as a module from any script in any directory, making
6 # relative paths untrustable. Because the result is used with 'use lib',
7 # we must ensure that it returns a Unix style path. Cwd::abs_path does
8 # that (File::Spec::Functions::rel2abs return O/S specific paths)
9 use File::Spec::Functions;
10 use Cwd qw(abs_path);
11 sub sourcedir {
12 return abs_path(catdir($config{sourcedir}, @_));
13 }
14 sub sourcefile {
15 return abs_path(catfile($config{sourcedir}, @_));
16 }
da51dc5f
RL
17 use lib sourcedir('util', 'perl');
18 use OpenSSL::Util;
1f86b822
RL
19-}
20package configdata;
21
22use strict;
23use warnings;
24
25use Exporter;
26our @ISA = qw(Exporter);
27our @EXPORT = qw(
28 %config %target %disabled %withargs %unified_info
29 @disablables @disablables_int
30);
31
da51dc5f
RL
32our %config = ({- dump_data(\%config, indent => 0); -});
33our %target = ({- dump_data(\%target, indent => 0); -});
34our @disablables = ({- dump_data(\@disablables, indent => 0) -});
35our @disablables_int = ({- dump_data(\@disablables_int, indent => 0) -});
36our %disabled = ({- dump_data(\%disabled, indent => 0); -});
37our %withargs = ({- dump_data(\%withargs, indent => 0); -});
38our %unified_info = ({- dump_data(\%unified_info, indent => 0); -});
1f86b822
RL
39
40# Unexported, only used by OpenSSL::Test::Utils::available_protocols()
41our %available_protocols = (
da51dc5f
RL
42 tls => [{- dump_data(\@tls, indent => 0) -}],
43 dtls => [{- dump_data(\@dtls, indent => 0) -}],
1f86b822
RL
44);
45
46# The following data is only used when this files is use as a script
da51dc5f
RL
47my @makevars = ({- dump_data(\@makevars, indent => 0); -});
48my %disabled_info = ({- dump_data(\%disabled_info, indent => 0); -});
1f86b822
RL
49my @user_crossable = qw( {- join (' ', @user_crossable) -} );
50
51# If run directly, we can give some answers, and even reconfigure
52unless (caller) {
53 use Getopt::Long;
54 use File::Spec::Functions;
55 use File::Basename;
56 use Pod::Usage;
57
841a438c
RL
58 use lib '{- sourcedir('util', 'perl') -}';
59 use OpenSSL::fallback '{- sourcefile('external', 'perl', 'MODULES.txt') -}';
60
1f86b822
RL
61 my $here = dirname($0);
62
63 if (scalar @ARGV == 0) {
64 # With no arguments, re-create the build file
65
1f86b822
RL
66 use OpenSSL::Template;
67
09803e9c 68 my $prepend = <<'_____';
1f86b822
RL
69use File::Spec::Functions;
70use lib '{- sourcedir('util', 'perl') -}';
1f86b822
RL
71use lib '{- sourcedir('Configurations') -}';
72use lib '{- $config{builddir} -}';
73use platform;
74_____
75
76 my @autowarntext = (
77 'WARNING: do not edit!',
78 "Generated by configdata.pm from "
79 .join(", ", @{$config{build_file_templates}})
80 );
81
82 print 'Creating ',$target{build_file},"\n";
83 open BUILDFILE, ">$target{build_file}.new"
84 or die "Trying to create $target{build_file}.new: $!";
85 foreach (@{$config{build_file_templates}}) {
86 my $tmpl = OpenSSL::Template->new(TYPE => 'FILE',
87 SOURCE => $_);
88 $tmpl->fill_in(FILENAME => $_,
89 OUTPUT => \*BUILDFILE,
90 HASH => { config => \%config,
91 target => \%target,
92 disabled => \%disabled,
93 withargs => \%withargs,
94 unified_info => \%unified_info,
95 autowarntext => \@autowarntext },
96 PREPEND => $prepend,
97 # To ensure that global variables and functions
98 # defined in one template stick around for the
99 # next, making them combinable
100 PACKAGE => 'OpenSSL::safe')
101 or die $Text::Template::ERROR;
102 }
103 close BUILDFILE;
104 rename("$target{build_file}.new", $target{build_file})
105 or die "Trying to rename $target{build_file}.new to $target{build_file}: $!";
106
107 exit(0);
108 }
109
110 my $dump = undef;
111 my $cmdline = undef;
112 my $options = undef;
113 my $target = undef;
114 my $envvars = undef;
115 my $makevars = undef;
116 my $buildparams = undef;
117 my $reconf = undef;
118 my $verbose = undef;
841a438c 119 my $query = undef;
1f86b822
RL
120 my $help = undef;
121 my $man = undef;
122 GetOptions('dump|d' => \$dump,
123 'command-line|c' => \$cmdline,
124 'options|o' => \$options,
125 'target|t' => \$target,
126 'environment|e' => \$envvars,
127 'make-variables|m' => \$makevars,
128 'build-parameters|b' => \$buildparams,
129 'reconfigure|reconf|r' => \$reconf,
130 'verbose|v' => \$verbose,
841a438c 131 'query|q=s' => \$query,
1f86b822
RL
132 'help' => \$help,
133 'man' => \$man)
134 or die "Errors in command line arguments\n";
135
136 if (scalar @ARGV > 0) {
137 print STDERR <<"_____";
138Unrecognised arguments.
139For more information, do '$0 --help'
140_____
141 exit(2);
142 }
143
144 if ($help) {
145 pod2usage(-exitval => 0,
146 -verbose => 1);
147 }
148 if ($man) {
149 pod2usage(-exitval => 0,
150 -verbose => 2);
151 }
152 if ($dump || $cmdline) {
153 print "\nCommand line (with current working directory = $here):\n\n";
154 print ' ',join(' ',
155 $config{PERL},
156 catfile($config{sourcedir}, 'Configure'),
157 @{$config{perlargv}}), "\n";
158 print "\nPerl information:\n\n";
159 print ' ',$config{perl_cmd},"\n";
160 print ' ',$config{perl_version},' for ',$config{perl_archname},"\n";
161 }
162 if ($dump || $options) {
163 my $longest = 0;
164 my $longest2 = 0;
165 foreach my $what (@disablables) {
166 $longest = length($what) if $longest < length($what);
167 $longest2 = length($disabled{$what})
168 if $disabled{$what} && $longest2 < length($disabled{$what});
169 }
170 print "\nEnabled features:\n\n";
171 foreach my $what (@disablables) {
172 print " $what\n" unless $disabled{$what};
173 }
174 print "\nDisabled features:\n\n";
175 foreach my $what (@disablables) {
176 if ($disabled{$what}) {
177 print " $what", ' ' x ($longest - length($what) + 1),
178 "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1);
179 print $disabled_info{$what}->{macro}
180 if $disabled_info{$what}->{macro};
181 print ' (skip ',
182 join(', ', @{$disabled_info{$what}->{skipped}}),
183 ')'
184 if $disabled_info{$what}->{skipped};
185 print "\n";
186 }
187 }
188 }
189 if ($dump || $target) {
190 print "\nConfig target attributes:\n\n";
191 foreach (sort keys %target) {
192 next if $_ =~ m|^_| || $_ eq 'template';
193 my $quotify = sub {
278de77b
RL
194 map {
195 if (defined $_) {
196 (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""
197 } else {
198 "undef";
199 }
200 } @_;
1f86b822
RL
201 };
202 print ' ', $_, ' => ';
203 if (ref($target{$_}) eq "ARRAY") {
204 print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n";
205 } else {
206 print $quotify->($target{$_}), ",\n"
207 }
208 }
209 }
210 if ($dump || $envvars) {
211 print "\nRecorded environment:\n\n";
212 foreach (sort keys %{$config{perlenv}}) {
213 print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n";
214 }
215 }
216 if ($dump || $makevars) {
217 print "\nMakevars:\n\n";
218 foreach my $var (@makevars) {
219 my $prefix = '';
220 $prefix = $config{CROSS_COMPILE}
221 if grep { $var eq $_ } @user_crossable;
222 $prefix //= '';
223 print ' ',$var,' ' x (16 - length $var),'= ',
224 (ref $config{$var} eq 'ARRAY'
225 ? join(' ', @{$config{$var}})
226 : $prefix.$config{$var}),
227 "\n"
228 if defined $config{$var};
229 }
230
231 my @buildfile = ($config{builddir}, $config{build_file});
232 unshift @buildfile, $here
233 unless file_name_is_absolute($config{builddir});
234 my $buildfile = canonpath(catdir(@buildfile));
235 print <<"_____";
236
237NOTE: These variables only represent the configuration view. The build file
238template may have processed these variables further, please have a look at the
239build file for more exact data:
240 $buildfile
241_____
242 }
243 if ($dump || $buildparams) {
244 my @buildfile = ($config{builddir}, $config{build_file});
245 unshift @buildfile, $here
246 unless file_name_is_absolute($config{builddir});
247 print "\nbuild file:\n\n";
248 print " ", canonpath(catfile(@buildfile)),"\n";
249
250 print "\nbuild file templates:\n\n";
251 foreach (@{$config{build_file_templates}}) {
252 my @tmpl = ($_);
253 unshift @tmpl, $here
254 unless file_name_is_absolute($config{sourcedir});
255 print ' ',canonpath(catfile(@tmpl)),"\n";
256 }
257 }
258 if ($reconf) {
259 if ($verbose) {
260 print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n";
261 foreach (sort keys %{$config{perlenv}}) {
262 print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n";
263 }
264 }
265
266 chdir $here;
267 exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf';
268 }
841a438c
RL
269 if ($query) {
270 use OpenSSL::Config::Query;
271
272 my $confquery = OpenSSL::Config::Query->new(info => \%unified_info,
273 config => \%config);
274 my $result = eval "\$confquery->$query";
275
276 # We may need a result class with a printing function at some point.
277 # Until then, we assume that we get a scalar, or a list or a hash table
278 # with scalar values and simply print them in some orderly fashion.
279 if (ref $result eq 'ARRAY') {
280 print "$_\n" foreach @$result;
281 } elsif (ref $result eq 'HASH') {
282 print "$_ : \\\n ", join(" \\\n ", @{$result->{$_}}), "\n"
283 foreach sort keys %$result;
284 } elsif (ref $result eq 'SCALAR') {
285 print "$$result\n";
286 }
287 }
1f86b822
RL
288}
289
2901;
291
292__END__
293
294=head1 NAME
295
296configdata.pm - configuration data for OpenSSL builds
297
298=head1 SYNOPSIS
299
300Interactive:
301
302 perl configdata.pm [options]
303
304As data bank module:
305
306 use configdata;
307
308=head1 DESCRIPTION
309
310This module can be used in two modes, interactively and as a module containing
311all the data recorded by OpenSSL's Configure script.
312
313When used interactively, simply run it as any perl script.
314If run with no arguments, it will rebuild the build file (Makefile or
315corresponding).
316With at least one option, it will instead get the information you ask for, or
317re-run the configuration process.
318See L</OPTIONS> below for more information.
319
320When loaded as a module, you get a few databanks with useful information to
321perform build related tasks. The databanks are:
322
323 %config Configured things.
324 %target The OpenSSL config target with all inheritances
325 resolved.
326 %disabled The features that are disabled.
327 @disablables The list of features that can be disabled.
328 %withargs All data given through --with-THING options.
329 %unified_info All information that was computed from the build.info
330 files.
331
332=head1 OPTIONS
333
334=over 4
335
336=item B<--help>
337
338Print a brief help message and exit.
339
340=item B<--man>
341
342Print the manual page and exit.
343
344=item B<--dump> | B<-d>
345
346Print all relevant configuration data. This is equivalent to B<--command-line>
347B<--options> B<--target> B<--environment> B<--make-variables>
348B<--build-parameters>.
349
350=item B<--command-line> | B<-c>
351
352Print the current configuration command line.
353
354=item B<--options> | B<-o>
355
356Print the features, both enabled and disabled, and display defined macro and
357skipped directories where applicable.
358
359=item B<--target> | B<-t>
360
361Print the config attributes for this config target.
362
363=item B<--environment> | B<-e>
364
365Print the environment variables and their values at the time of configuration.
366
367=item B<--make-variables> | B<-m>
368
369Print the main make variables generated in the current configuration
370
371=item B<--build-parameters> | B<-b>
372
373Print the build parameters, i.e. build file and build file templates.
374
375=item B<--reconfigure> | B<--reconf> | B<-r>
376
377Re-run the configuration process.
378
379=item B<--verbose> | B<-v>
380
381Verbose output.
382
383=back
384
385=cut
386
387EOF