A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

432 lines
14 KiB

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